Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tecplot_data Class Reference

Base class for tecplot files Implements useful functions for tecplot file parsing. More...

#include <file.h>

Inheritance diagram for tecplot_data:
Collaboration diagram for tecplot_data:

Public Member Functions

virtual string get_mod_name ()
 Get the name of the class (tecplot_data) More...
 
 tecplot_data (ifstream &infile, ofstream &outfile, bool loud, string filename, int dim, std::vector< std::vector< int > > rFieldMappings, std::vector< index_order > rIndexOrder, std::vector< adj_map > conv_factor, std::vector< adj_map > norm_val)
 Constructor that initializes values. More...
 
virtual ~tecplot_data ()
 Destructor. More...
 
virtual void parse ()
 Parse the tecplot file. More...
 
- Public Member Functions inherited from datafile
 datafile (ifstream &infile, ofstream &outfile, bool loud, string filename, int dim, std::vector< std::vector< int > > rFieldMappings, std::vector< index_order > rIndexOrder, std::vector< adj_map > conv_factor, std::vector< adj_map > norm_val)
 Construct data file object using specified information. More...
 
virtual ~datafile ()
 Free used data, delete the object. More...
 
 datafile (const datafile &d)
 Deep copy constructor. More...
 
int partition_layout (int partition, int n)
 Get the size of n dimension of the specified partition. More...
 
pointsget_points (int partition)
 Get a partitions' points. More...
 
pnt get_point (int n)
 Get the nth point of the file. More...
 
pnt get_point (int n, int partition)
 Get the nth point of the specified partition. More...
 
int get_num_points ()
 Get the number of points in the file. More...
 
int get_num_points (int partition)
 Get the number of points in the specified partition. More...
 
int get_num_vars ()
 Get the number of variables in the file. More...
 
string get_title ()
 Get file title if specified in file header. More...
 
int get_num_partitions ()
 Get number of partition in the file. More...
 

Protected Member Functions

void read_header ()
 Read the tecplot header from the file and retrieve the title, variable names, and number of variables. More...
 
int count_zones ()
 Count the number of zones in the tecplot file, starting from the current location of the file stream. More...
 
void seek_to_zone ()
 Seek to the next zone in the file. More...
 
string * get_zone_header (int zone)
 Read the zone header. More...
 
string * get_zone_nodes (int zone)
 Retrieve zone point data from the zone body. More...
 
void zone_error_out (int zone, string zs_err)
 Log an error message with appended zone information so the error can be located. More...
 
void zone_status_out (int zone, string zs_out)
 Log a status message with appended zone information. More...
 
tpzonezone_detect (int zone)
 Read the header information for the specified zone, then create a new zone object based on the type of zone detected. More...
 
- Protected Member Functions inherited from datafile
void error_out (string err_ps)
 Log the string specified as an error event. More...
 
void status_out (string st_ps)
 Log the string specified as a status event. More...
 
void LogFieldMappings ()
 Log the field mapping data from the command line and stored in mFieldMappings. More...
 
int get_num_dep_vars ()
 Get number of dependent variables. More...
 
index_order get_index_order (int partition)
 

Static Private Attributes

static const int BUFFER_SIZE = 512
 

Additional Inherited Members

- Protected Attributes inherited from datafile
string filename
 
ifstream & infile
 
ofstream & outfile
 
bool loud
 
partition ** data_part
 
int num_partitions
 
std::vector< string > var_names
 
string title
 
int dimensions
 
std::vector< adj_mapconv_factor
 
std::vector< adj_mapnorm_val
 
std::vector< std::vector< int > > mFieldMappings
 
std::vector< index_ordermIndexOrder
 

Detailed Description

Base class for tecplot files Implements useful functions for tecplot file parsing.

Definition at line 206 of file file.h.

Constructor & Destructor Documentation

tecplot_data ( ifstream &  infile,
ofstream &  outfile,
bool  loud,
string  filename,
int  dim,
std::vector< std::vector< int > >  rFieldMappings,
std::vector< index_order rIndexOrder,
std::vector< adj_map conv_factor,
std::vector< adj_map norm_val 
)

Constructor that initializes values.

Definition at line 186 of file file.cpp.

189  : datafile(infile, outfile, loud, filename, dim, rFieldMappings, rIndexOrder, conv_factor, norm_val){
190 
191  return;
192 }
datafile(ifstream &infile, ofstream &outfile, bool loud, string filename, int dim, std::vector< std::vector< int > > rFieldMappings, std::vector< index_order > rIndexOrder, std::vector< adj_map > conv_factor, std::vector< adj_map > norm_val)
Construct data file object using specified information.
Definition: file.cpp:5
ofstream & outfile
Definition: file.h:142
bool loud
Definition: file.h:143
ifstream & infile
Definition: file.h:141
string filename
Definition: file.h:138
~tecplot_data ( )
virtual

Destructor.

Definition at line 182 of file file.cpp.

182  {
183  return;
184 }

Member Function Documentation

int count_zones ( )
protected

Count the number of zones in the tecplot file, starting from the current location of the file stream.

For count of all zones, seek to beginning of file then call.

Returns
Number of zones from the current location.

Definition at line 262 of file file.cpp.

References datafile::infile, and seek_to_zone().

Referenced by parse().

262  {
263 
264  int zones = 0;
265 
266  //Seek to the next zone until
267  //end of file is reached
268  seek_to_zone();
269  while(!infile.eof()){
270  zones++;
271  seek_to_zone();
272  }
273 
274  infile.clear();
275  infile.seekg(0, std::ios::beg);
276 
277  return zones;
278 
279 }
ifstream & infile
Definition: file.h:141
void seek_to_zone()
Seek to the next zone in the file.
Definition: file.cpp:198

Here is the call graph for this function:

Here is the caller graph for this function:

string get_mod_name ( )
virtual

Get the name of the class (tecplot_data)

Returns
Name of the class

Reimplemented from datafile.

Definition at line 194 of file file.cpp.

194  {
195  return string("Tecplot File");
196 }
string * get_zone_header ( int  zone)
protected

Read the zone header.

Returns
String of zone header

Definition at line 373 of file file.cpp.

References i, datafile::infile, and seek_to_zone().

Referenced by zone_detect().

373  {
374 
375  //Seek to beginning
376  infile.clear();
377  infile.seekg(0, std::ios::beg);
378 
379  //Seek to specified zone
380  for(int i=0; i<=zone; i++){
381  seek_to_zone();
382  }
383 
384  string temp;
385  infile >> temp;
386 
387  string *header = new string;
388 
389  //TODO
390  //Make finding the end of the header
391  //more robust
392  while( (temp.find("DT=") == string::npos || temp.find("\"") != string::npos) && !infile.eof()){
393 
394  *header += temp;
395  *header += " ";
396 
397  infile >> temp;
398  }
399 
400  *header += temp;
401 
402  //Get the last line
403  char c;
404  infile.get(c);
405  while(c != '\n'){
406  *header += c;
407  infile.get(c);
408  }
409 
410  return header;
411 
412 }
blockLoc i
Definition: read.cpp:79
ifstream & infile
Definition: file.h:141
void seek_to_zone()
Seek to the next zone in the file.
Definition: file.cpp:198

Here is the call graph for this function:

Here is the caller graph for this function:

string * get_zone_nodes ( int  zone)
protected

Retrieve zone point data from the zone body.

Returns
String of zone data points.

Definition at line 414 of file file.cpp.

References BUFFER_SIZE, i, datafile::infile, datafile::num_partitions, and seek_to_zone().

Referenced by zone_detect().

414  {
415 
416  string *ret = new string;
417 
418  //Seek to beginning
419  infile.clear();
420  infile.seekg(0, std::ios::beg);
421 
422  //Check valid zone number
423  if(zone+1 > num_partitions)
424  return NULL;
425 
426  //Seek to specified zone
427  for(int i=0; i<=zone; i++){
428  seek_to_zone();
429  }
430 
431  char line[BUFFER_SIZE];
432  string curr_line;
433 
434  infile.getline(line, BUFFER_SIZE-1);
435  curr_line = line;
436 
437  //Skip through the zone header
438  while( (curr_line.find("DT=") == string::npos || curr_line.find("\"") != string::npos)
439  && !infile.eof() ){
440 
441  infile.getline(line, 511);
442  curr_line = line;
443  }
444 
445  //Read zone point data
446  infile.getline(line, 511);
447  curr_line = line;
448 
449  //Stop when the next zone is reached, or eof
450  while( (curr_line.find("ZONE") == string::npos) && !infile.eof() ){
451 
452  *ret += curr_line;
453 
454  infile.getline(line, 511);
455  curr_line = line;
456  }
457 
458  if(infile.eof()){
459  infile.clear();
460  infile.seekg(0, std::ios::beg);
461  }
462 
463  return ret;
464 
465 }
static const int BUFFER_SIZE
Definition: file.h:293
int num_partitions
Definition: file.h:167
blockLoc i
Definition: read.cpp:79
ifstream & infile
Definition: file.h:141
void seek_to_zone()
Seek to the next zone in the file.
Definition: file.cpp:198

Here is the call graph for this function:

Here is the caller graph for this function:

void parse ( )
virtual

Parse the tecplot file.

Read the header using read_header(), iterate through each zone and retrieve the zone header and zone body. Create a new partition object and have that object parse the zone. Log and error output.

Reimplemented from datafile.

Definition at line 281 of file file.cpp.

References CGAL::compare(), datafile::conv_factor, count_zones(), datafile::data_part, datafile::error_out(), datafile::get_index_order(), datafile::get_num_dep_vars(), datafile::get_num_vars(), i, datafile::infile, itoa(), datafile::mFieldMappings, datafile::norm_val, datafile::num_partitions, partition::parse_layout(), read_header(), datafile::status_out(), zone_detect(), zone_error_out(), and zone_status_out().

281  {
282 
283  //Get header information
284  // - Sets num_vars
285  // - Sets title
286  read_header();
287 
288  int zone_count = count_zones();
289 
290  if(zone_count == 0){
291  string err_ps("No Zones Found");
292  error_out(err_ps);
293  return;
294  }
295 
296  status_out(itoa(zone_count) + " Zone(s) Detected");
297 
298  //Seek to beginning
299  infile.clear();
300  infile.seekg(0, std::ios::beg);
301 
302  this->num_partitions = zone_count;
303  this->data_part = new partition*[this->num_partitions];
304 
305  for(int i=0; i<zone_count; i++){
306 
307  //Detect zone
308  //Create proper zone object
309  data_part[i] = zone_detect(i);
310 
311  //Parse zone header
312  if(data_part[i] != NULL){
314  if( data_part[i]->get_error().compare("") != 0)
315  zone_error_out(i, data_part[i]->get_error());
316  else
317  zone_status_out(i, data_part[i]->get_status());
318  }
319  else{
320  string err_ps("Invalid Zone");
321  zone_error_out(i, err_ps);
322  }
323  }
324 
325  //Parse zone data
326  for(int i=0; i<zone_count; i++){
327 
328  if(data_part[i] != NULL){
329  if(data_part[i]->parse_data(get_num_dep_vars(), get_num_vars(), mFieldMappings,
331  zone_status_out(i, data_part[i]->get_status());
332  else
333  zone_error_out(i, data_part[i]->get_error());
334  }
335  }
336 
337  return;
338 }
void zone_error_out(int zone, string zs_err)
Log an error message with appended zone information so the error can be located.
Definition: file.cpp:252
int get_num_dep_vars()
Get number of dependent variables.
Definition: file.cpp:163
void status_out(string st_ps)
Log the string specified as a status event.
Definition: file.cpp:70
partition ** data_part
Definition: file.h:164
int get_num_vars()
Get the number of variables in the file.
Definition: file.cpp:159
string itoa(int n)
Convert an int to a string.
int count_zones()
Count the number of zones in the tecplot file, starting from the current location of the file stream...
Definition: file.cpp:262
void read_header()
Read the tecplot header from the file and retrieve the title, variable names, and number of variables...
Definition: file.cpp:207
std::vector< std::vector< int > > mFieldMappings
Definition: file.h:186
int num_partitions
Definition: file.h:167
virtual void parse_layout()
Definition: partition.cpp:25
blockLoc i
Definition: read.cpp:79
ifstream & infile
Definition: file.h:141
std::vector< adj_map > norm_val
Definition: file.h:183
tpzone * zone_detect(int zone)
Read the header information for the specified zone, then create a new zone object based on the type o...
Definition: file.cpp:340
void zone_status_out(int zone, string zs_out)
Log a status message with appended zone information.
Definition: file.cpp:245
index_order get_index_order(int partition)
Definition: file.cpp:167
CGAL_KERNEL_INLINE Comparison_result compare(const NT &n1, const NT &n2)
Definition: number_utils.h:143
std::vector< adj_map > conv_factor
Definition: file.h:182
void error_out(string err_ps)
Log the string specified as an error event.
Definition: file.cpp:65

Here is the call graph for this function:

void read_header ( )
protected

Read the tecplot header from the file and retrieve the title, variable names, and number of variables.

Log the information as a status event.

Definition at line 207 of file file.cpp.

References datafile::infile, itoa(), datafile::LogFieldMappings(), readQuoteExpression(), datafile::status_out(), datafile::title, and datafile::var_names.

Referenced by parse().

207  {
208 
209  //Seek to beginning
210  infile.clear();
211  infile.seekg(0, std::ios::beg);
212 
213  string temp;
214  string header;
215 
216  infile >> temp;
217 
218  //Read until a Zone header is reached
219  while(temp.compare(string("ZONE")) != 0){
220  header += temp;
221  header += " ";
222  infile >> temp;
223  }
224 
225  //Parse the file title
226  std::vector<string> title_parse = readQuoteExpression(header, string("TITLE"));
227  if(title_parse.size() == 1){
228  this->title = title_parse[0];
229  }
230 
231  //Parse variable names
232  this->var_names = readQuoteExpression(header, string("VARIABLES"));
233 
234  status_out(itoa(this->var_names.size()) + " Variable(s) Detected");
235 
236  //Log Field Mapping
238 
239  //Seek to beginning
240  infile.clear();
241  infile.seekg(0, std::ios::beg);
242 
243 }
std::vector< string > var_names
Definition: file.h:168
void status_out(string st_ps)
Log the string specified as a status event.
Definition: file.cpp:70
string itoa(int n)
Convert an int to a string.
ifstream & infile
Definition: file.h:141
std::vector< string > readQuoteExpression(string rStack, string rNeedle)
Read expressions of the form x = &quot;test&quot; &quot;100&quot; &quot;another test&quot;.
string title
Definition: file.h:169
void LogFieldMappings()
Log the field mapping data from the command line and stored in mFieldMappings.
Definition: file.cpp:79

Here is the call graph for this function:

Here is the caller graph for this function:

void seek_to_zone ( )
protected

Seek to the next zone in the file.

Starting position is the current location of the infile object.

Definition at line 198 of file file.cpp.

References datafile::infile.

Referenced by count_zones(), get_zone_header(), and get_zone_nodes().

198  {
199 
200  string tmp("");
201 
202  while(!infile.eof() && tmp.compare(string("ZONE")) != 0)
203  infile >> tmp;
204 
205 }
ifstream & infile
Definition: file.h:141

Here is the caller graph for this function:

tpzone * zone_detect ( int  zone)
protected

Read the header information for the specified zone, then create a new zone object based on the type of zone detected.

Parameters
zoneZone number
Returns
Zone object

Definition at line 340 of file file.cpp.

References CGAL::compare(), get_zone_header(), get_zone_nodes(), readCommaExpression(), and zone_status_out().

Referenced by parse().

340  {
341 
342  //Retrieve zone header and read zone type
343  string *zheader = get_zone_header(zone);
344  std::vector<string> ztype = readCommaExpression(*zheader, string("ZONETYPE"));
345 
346  tpzone *retzone = NULL;
347 
348  if(ztype.size() == 1){
349 
350  //Get zone data
351  string *zdata = get_zone_nodes(zone);
352 
353  //If the zone is an ordered zone, create a new ordered zone object
354  if(ztype[0].compare(string("Ordered")) == 0){
355  retzone = new tpz_ordered( zheader, zdata );
356 
357  string zone_st("Ordered Zone Detected");
358  zone_status_out(zone, zone_st);
359  }
360  //If the zone is FEQuad, create a new FEQuad object
361  else if(ztype[0].compare(string("FEQuadrilateral")) == 0){
362  retzone = new tpz_fequad( zheader, zdata );
363 
364  string zone_st("FEQuadrilateral Zone Detected");
365  zone_status_out(zone, zone_st);
366  }
367 
368  }
369 
370  return retzone;
371 }
string * get_zone_header(int zone)
Read the zone header.
Definition: file.cpp:373
string * get_zone_nodes(int zone)
Retrieve zone point data from the zone body.
Definition: file.cpp:414
std::vector< string > readCommaExpression(string rStack, string rNeedle)
void zone_status_out(int zone, string zs_out)
Log a status message with appended zone information.
Definition: file.cpp:245
CGAL_KERNEL_INLINE Comparison_result compare(const NT &n1, const NT &n2)
Definition: number_utils.h:143

Here is the call graph for this function:

Here is the caller graph for this function:

void zone_error_out ( int  zone,
string  zs_err 
)
protected

Log an error message with appended zone information so the error can be located.

Parameters
zoneZone number affected.
zs_errError message.

Definition at line 252 of file file.cpp.

References datafile::error_out(), and itoa().

Referenced by parse().

252  {
253  string err_ps("Zone ");
254  err_ps = err_ps + itoa(zone) + " | " + zs_err;
255 
256  error_out(err_ps);
257 }
string itoa(int n)
Convert an int to a string.
void error_out(string err_ps)
Log the string specified as an error event.
Definition: file.cpp:65

Here is the call graph for this function:

Here is the caller graph for this function:

void zone_status_out ( int  zone,
string  zs_out 
)
protected

Log a status message with appended zone information.

Parameters
zoneZone number affected.
zs_outStatus message.

Definition at line 245 of file file.cpp.

References itoa(), and datafile::status_out().

Referenced by parse(), and zone_detect().

245  {
246  string st_ps("Zone ");
247  st_ps = st_ps + itoa(zone) + " | " + zs_out;
248 
249  status_out(st_ps);
250 }
void status_out(string st_ps)
Log the string specified as a status event.
Definition: file.cpp:70
string itoa(int n)
Convert an int to a string.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

const int BUFFER_SIZE = 512
staticprivate

Definition at line 293 of file file.h.

Referenced by get_zone_nodes().


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