xmsgrid  1.0
UGrid File IO Tutorial

UGrid File IO Tutorial

Introduction

The purpose of this tutorial is to provide explanation on how to use File IO with xmsgrid. The XmUGrid class does not have file IO members. Functions are available in the files named XmUGridUtils to provide File IO.

Example - Writing UGrid data to ASCII file format

This example shows how to write an exisiting UGrid to an ASCII file using function xms::XmWriteUGridToAsciiFile(). This function takes a XmUGrid and filename with path. The testing code for this example is XmUGridUtilsTests::testWriteThenReadUGridFileToAscii.

Example - Reading a UGrid from ASCII file format

This example shows how to read a UGrid from an ASCII file using function xms::XmReadUGridFromAsciiFile. This function takes a filename with path and returns an XmUGrid. The testing code for this example is XmUGridUtilsTests::testWriteThenReadUGridFileToAscii.

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
{
std::shared_ptr<XmUGrid> ugridBase = TEST_XmUGrid3dLinear();
// write
std::string outFileName(TestFilesPath() + "3d_grid_linear.xmugrid");
XmWriteUGridToAsciiFile(ugridBase, outFileName);
// read
std::string input(TestFilesPath() + "3d_grid_linear.xmugrid");
std::shared_ptr<XmUGrid> ugridOut = XmReadUGridFromAsciiFile(input);
TS_ASSERT_EQUALS(ugridBase->GetLocations(), ugridOut->GetLocations());
TS_ASSERT_EQUALS(ugridBase->GetCellstream(), ugridOut->GetCellstream());
} // XmUGridUtilsTests::testWriteThenReadUGridFile