simple_reading_example.cpp

This small example demonstrates how the main class Delphin5OutputData is used to read in an output file, extract data and write it in the old DIM3 format.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

#include <delphin5_output.h>
using namespace DELPHIN;

int main(int argc, char * argv[]) {

    // create data object for output data
    Delphin5OutputData data;
    // specify output file
    string outputfile = "../../data/single_mat_rect.results/temperature_field_bin.out";
    // read output file completely
    string errmsg;
    bool success = data.read(outputfile, false, errmsg);
    if (!success) {
        cerr << errmsg << endl;
        return EXIT_FAILURE;
    }
    
    // now we have all output data in the 'data' object.

    cout << "Nr. of time points = " << data.m_timepoints.size() << endl;
    double s_to_d = 1.0/(3600*24);
    cout << "From " << data.m_timepoints[0]*s_to_d << " to " << data.m_timepoints.back()*s_to_d << " d" << endl;

    int t_index = 10;

    // writing matrix in DIM3 format with values for time index 10
    ofstream dump("../../data/t10_matrix.txt");

    dump << setw(10) << right << data.m_timepoints.back()*s_to_d << " \t";
    // write all x-coordinates
    for (unsigned int i=0; i<data.m_grid.x_coords.size(); ++i)
        dump << data.m_grid.x_coords[i] << " \t";
    dump << endl;

    // write all y-coordinates and the values
    for (unsigned int j=0; j<data.m_grid.y_coords.size(); ++j) {
        dump << setw(10) << right << data.m_grid.y_coords[j] << " \t";
        // now loop over all elements and write the values
        for (unsigned int i=0; i<data.m_grid.x_coords.size(); ++i) {
            int num_idx = data.m_valueMapping[i][j];
            if (num_idx == -1)
                dump << setw(10) << right << "NaN";
            else {
                int e_idx = data.m_nums[num_idx];
                dump << setw(10) << right << data.m_values[t_index][e_idx];
            }
            dump << " \t";
        }
        dump << endl;
    }
    dump << endl;

    return EXIT_SUCCESS;
}



Generated on Tue Mar 24 18:12:02 2009 for Delphin 5 Outputs Library by  doxygen 1.5.5