Input / ouput

Format Classes (for files)

Input / output operations (for files) are performed through dedicated classes. Thoses classes derive from class Format. There are six classes: FormatBinary, FormatText, FormatFormattedText, FormatGrib, FormatNetCDF and FormatChimere. The last one is not described here because it is too particular.

For the two first classes, two main methods are provided:

  template<class TD, int N, class TG>
  void Read(string FileName, Data<TD, N, TG>& D) const;

  template<class TD, int N, class TG>
  void Write(Data<TD, N, TG>& D, string FileName) const;

This enables to read a binary file or a text file easily. One has to declare an instance of the class FormatBinary and to call the Read method:

  int Nt = 13;
  int Nx = 25;
  int Ny = 25;
  int Nz = 9;

  RegularGrid<double> GridT(Nt), GridX(Nx), GridY(Ny), GridZ(Nz);
  Data<double, 4> D(GridT, GridZ, GridY, GridX);

  FormatBinary<float> FormatIn;
  FormatIn.Read("input.bin", D);

The previous example reads a single-precision binary file and put it in a double-precision Data instance. The size of the file is implicit: it is provided by D size.

This is the same for text files and for output operations.

FormatFormattedText reads text files with a given format. Refer to the class documentation for details.

FormatGrib and FormatNetCDF enable to read Grib files and NetCDF files. They don't allow output operations. Notice that methods 'Read' have an extra argument: the number of the variable to be read (for Grib files) or the name of the variable (NetCDF files). Finally, if a variable is read in a Grib file, it is required that all stored values for this variable are read.

To read Grib files with SeldonData, one has to define the dedicated flag: #define SELDONDATA_WITH_GRIB.

To read NetCDF files with SeldonData, one has to: (1) have the NetCDF C++ interface which is freely available (see http://www.unidata.ucar.edu/packages/netcdf/), (2) ensure that the makefile provides the path to "netcdfcpp.h" (part of the NetCDF C++ interface) and (3) define the dedicated macro: #define SELDONDATA_WITH_NETCDF.

On screen

To display the content of a Data or a Grid object A, A.Print() should be enough.

To help the user, three macros are provided:

  #define ERR(x) cout << "Hermes - " #x << endl
  #define DISP(x) cout << #x ": " << x << endl
  #define DISPLAY(x) cout << #x ": " << x << endl

They may be useful for quick debugging.