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[]) {
Delphin5OutputData data;
string outputfile = "../../data/single_mat_rect.results/temperature_field_bin.out";
string errmsg;
bool success = data.read(outputfile, false, errmsg);
if (!success) {
cerr << errmsg << endl;
return EXIT_FAILURE;
}
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;
ofstream dump("../../data/t10_matrix.txt");
dump << setw(10) << right << data.m_timepoints.back()*s_to_d << " \t";
for (unsigned int i=0; i<data.m_grid.x_coords.size(); ++i)
dump << data.m_grid.x_coords[i] << " \t";
dump << endl;
for (unsigned int j=0; j<data.m_grid.y_coords.size(); ++j) {
dump << setw(10) << right << data.m_grid.y_coords[j] << " \t";
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;
}