![]() |
Gowdy solver
|
A wrapper for GridPoint so that GridPoint's array of fields can be treated as a compound object when reading/writing. More...
#include <gridPoint.h>
Public Member Functions | |
IORecord (GridPoint &gp) | |
void | clear (Real value=NAN) |
Resets all the variables to a specific value (by default NAN). | |
bool | read (FILE *inf, bool isBinary, const std::vector< Int > &input) |
Reads the variable values from a file stream. | |
void | write (FILE *outf, bool isBinary, const std::vector< Int > output) |
Writes the variable values to a file stream. | |
Private Attributes | |
Real * | gridSlice |
The array of fields values at the grid point. |
A wrapper for GridPoint so that GridPoint's array of fields can be treated as a compound object when reading/writing.
Definition at line 19 of file gridPoint.h.
IORecord::IORecord | ( | GridPoint & | gp | ) | [inline] |
Definition at line 24 of file gridPoint.h.
: gridSlice( gp ) {}
void IORecord::clear | ( | Real | value = NAN | ) | [inline] |
Resets all the variables to a specific value (by default NAN).
Definition at line 30 of file gridPoint.h.
References gridSlice.
Referenced by read().
bool IORecord::read | ( | FILE * | inf, |
bool | isBinary, | ||
const std::vector< Int > & | input | ||
) | [inline] |
Reads the variable values from a file stream.
Definition at line 41 of file gridPoint.h.
References clear(), gridSlice, and sscanf_Real().
Referenced by GridInitialData::load().
{ clear (); auto len = input.size(); Real data[ len ]; if( isBinary ) { if( len != fread( data, sizeof(data[0]), len, inf ) ) { std::cerr << "Error: Premature end of grid." << std::endl; return false; } } else { char line[ input.size() * 80 ] = {0}; do { if( ! fgets( line, sizeof(line)-1, inf ) ) { std::cerr << "Error: Premature end of grid." << std::endl; return false; } } while( line[0] == '*' ); // Ignore comments (starting with '*') size_t count = sscanf_Real( line, data, len ); if( count != len ) { std::cerr << "Error: Wrong number of variables." << std::endl; return false; } } for( size_t i = 0; i < len; ++i ) { gridSlice[ input[i] ] = data[i]; } return true; }
void IORecord::write | ( | FILE * | outf, |
bool | isBinary, | ||
const std::vector< Int > | output | ||
) | [inline] |
Writes the variable values to a file stream.
Definition at line 83 of file gridPoint.h.
References fputReal(), and gridSlice.
Referenced by GridOutputWriter::write().
{ auto len = output.size(); /// @todo fld::output should be dynamic in ID class Real data[ len ]; for( size_t i = 0; i < len; ++i ) { data[i] = gridSlice[ output[i] ]; } if( isBinary ) { fwrite( data, sizeof(data[0]), len, outf ); } else { for( size_t i = 0; i < len; ++i ) { if ( i > 0 ) fputs( "\t", outf ); fputReal( outf, data[i] ); } fputs( "\n", outf ); } }
Real* IORecord::gridSlice [private] |
The array of fields values at the grid point.
Definition at line 21 of file gridPoint.h.