/*
Copyright (C) 2015 Philippe Miron
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "tecplotread.hpp"
tecplotread::tecplotread(string filename) :
validation_marker(0.0),
version(""),
byte_order(0),
file_type(0),
title("")
{
// open the file
file.open(filename.c_str(), ifstream::binary);
// validate opening of file
assert(file.good());
// Header section
// section i
char buffer[9];
file.read (buffer, 8);
buffer[8] = '\0';
version = string(buffer);
if (version != "#!TDV112")
cout solution_time);
readbin(z->not_used);
readbin(z->zone_type);
readbin(z->data_packing);
readbin(z->var_location);
if (z->var_location == 1)
{
z->vars_location.resize(number_variables);
for (int i(0); ivars_location[i]);
}
// face neighbors
readbin(z->face_neighbors);
if (z->face_neighbors == 1)
{
readbin(z->number_face_neighbors);
if (z->number_face_neighbors != 0)
{
readbin(z->face_neighbors_mode);
if (z->zone_type >= 1 and z->zone_type fe_face_neighbors);
}
}
// ordered zone
if (z->zone_type == 0)
{
readbin(z->imax);
readbin(z->jmax);
readbin(z->kmax);
if (z->jmax == 1 and z->kmax == 1) // 1D data
z->number_elements = (z->imax-1);
else if (z->kmax == 1) // 2D data
z->number_elements = (z->imax-1) * (z->jmax-1);
else
z->number_elements = (z->imax-1) * (z->jmax-1) * (z->kmax-1);
z->number_points = z->imax * z->jmax * z->kmax;
}
// finite element zone
if (z->zone_type >= 1 and z->zone_type number_points);
// only for FEPOLYGON or FEPOLYHEDRON
if (z->zone_type == 6 or z->zone_type == 7)
{
readbin(z->number_faces);
readbin(z->total_faces);
readbin(z->boundary_faces);
readbin(z->total_boundary_connections);
}
readbin(z->number_elements);
readbin(z->icell); // for future used, set to zero
readbin(z->jcell); // for future used, set to zero
readbin(z->kcell); // for future used, set to zero
}
// todo create an auxiliary structure
// add all the structures to a vector
readbin(validation_marker);
while (validation_marker == 1)
{
auxiliary* temp = new auxiliary;
temp->auxiliary_name = ascii_to_string();
readbin(temp->auxiliary_format); // only allow 0
temp->auxiliary_value = ascii_to_string();
z->auxiliaries.emplace_back(temp);
}
zones.emplace_back(z);
// read the next marker to check if
// there is more than one zone
readbin(validation_marker);
} // end of zone section
// section v
if (validation_marker == 399)
{
// read geometries
cout passive_variables.resize(number_variables, 0);
if (zones[index]->has_passive_variables)
{
for (int i(0); ipassive_variables[i]);
}
readbin(zones[index]->has_variable_sharing);
if (zones[index]->has_variable_sharing)
{
zones[index]->variable_sharing.resize(number_variables);
for (int i(0); ivariable_sharing[i]);
}
readbin(zones[index]->zone_share_connectivity); // if -1 no sharing
zones[index]->min_value.resize(number_variables);
zones[index]->max_value.resize(number_variables);
for (int i(0); imin_value[i]);
readbin(zones[index]->max_value[i]);
}
// read the data tables
zones[index]->variable_index.resize(4);
for (int i(0); ipassive_variables[i])
{
switch (zones[index]->variable_format[i])
{
case 1:
{
vector tempvalues;
read_zone_data(tempvalues, index, i);
zones[index]->data_float.emplace_back(tempvalues);
zones[index]->variable_index[0].emplace_back(i);
break;
}
case 2:
{
vector tempvalues;
read_zone_data(tempvalues, index, i);
zones[index]->data_double.emplace_back(tempvalues);
zones[index]->variable_index[1].emplace_back(i);
break;
}
case 3:
{
vector tempvalues;
read_zone_data(tempvalues, index, i);
zones[index]->data_longint.emplace_back(tempvalues);
zones[index]->variable_index[2].emplace_back(i);
break;
}
case 4:
{
vector tempvalues;
read_zone_data(tempvalues, index, i);
zones[index]->data_int.emplace_back(tempvalues);
zones[index]->variable_index[3].emplace_back(i);
break;
}
default:
{
cout