Gowdy solver
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
IORecord Class Reference

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

RealgridSlice
 The array of fields values at the grid point.

Detailed Description

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.


Constructor & Destructor Documentation

IORecord::IORecord ( GridPoint gp) [inline]

Definition at line 24 of file gridPoint.h.

        : gridSlice( gp )
    {}

Member Function Documentation

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().

    {
        // We assume that Reals are tightly packed in the struture.
        auto len = sizeof(GridPoint) / sizeof(Real);
        for( Real* fp = gridSlice; len > 0; --len, ++fp ) {
            *fp = value;
        }
    }
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.

Warning:
The order of fields in data[] (output data record) should match the Mathematica notebook!
Todo:
fld::output should be dynamic in ID class

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 );
        }
    }

Field Documentation

The array of fields values at the grid point.

Definition at line 21 of file gridPoint.h.

Referenced by clear(), read(), and write().


The documentation for this class was generated from the following file: