libMesh::PltLoader Class Reference

#include <plt_loader.h>

List of all members.

Public Types

enum  OldZoneType { BLOCK = 0, POINT, FEBLOCK, FEPOINT }
enum  NewZoneType {
  ORDERED = 0, FELINESEG, FETRIANGLE, FEQUADRILATERAL,
  FETETRAHEDRON, FEBRICK
}
enum  DataType {
  FLOAT = 1, DOUBLE, LONGINT, SHORTINT,
  BYTE, BIT
}
enum  FEType { TRI = 0, QUAD, TET, HEX }

Public Member Functions

 PltLoader (const bool v=false)
 PltLoader (const std::string &name, const bool v=false)
 ~PltLoader ()
void clear ()
bool verbose () const
void read (const std::string &name)
void write_dat (const std::string &name, const unsigned int version=10) const
const std::string & version () const
bool is_foreign () const
const std::string & title () const
unsigned int n_vars () const
const std::string & var_name (const unsigned int v) const
unsigned int var_type (const unsigned int v) const
unsigned int n_zones () const
unsigned int zone_type (const unsigned int z) const
const std::string & zone_name (const unsigned int z) const
unsigned int zone_pack (const unsigned int z) const
unsigned int imax (const unsigned int z) const
unsigned int jmax (const unsigned int z) const
unsigned int kmax (const unsigned int z) const
unsigned int n_nodes (const unsigned int z) const
unsigned int n_elem (const unsigned int z) const
FEType elem_type (const unsigned int z) const
const std::vector< std::vector
< std::vector< float > > > & 
get_data () const

Static Public Attributes

static const unsigned int NNodes [4] = {3, 4, 4, 8}

Private Member Functions

void read_header (std::istream &in)
void read_data (std::istream &in)
void read_block_data (std::istream &in, const unsigned int zn)
void read_point_data (std::istream &in, const unsigned int zn)
void read_feblock_data (std::istream &in, const unsigned int zn)
void read_fepoint_data (std::istream &in, const unsigned int zn)
std::string & version ()
bool & is_foreign ()
std::string & title ()
void set_n_vars (const unsigned int nv)
std::string & var_name (const unsigned int v)
unsigned int & var_type (const unsigned int v)
void set_n_zones (const unsigned int nz)
unsigned int & zone_type (const unsigned int z)
std::string & zone_name (const unsigned int z)
unsigned int & zone_pack (const unsigned int z)
unsigned int & imax (const unsigned int z)
unsigned int & jmax (const unsigned int z)
unsigned int & kmax (const unsigned int z)

Private Attributes

const bool _verbose
std::string _version
bool _is_foreign
std::string _title
unsigned int _n_vars
std::vector< std::string > _var_names
std::vector< unsigned int > _var_types
unsigned int _n_zones
std::vector< unsigned int > _zone_types
std::vector< std::string > _zone_names
std::vector< unsigned int > _zone_pack
std::vector< unsigned int > _imax
std::vector< unsigned int > _jmax
std::vector< unsigned int > _kmax
std::vector< std::vector
< std::vector< float > > > 
_data
std::vector< std::vector< int > > _conn
char buf [512]

Detailed Description

This class will read a binary .plt file. These types of files are for use with Amtec's Tecplot visualization package.

Author:
Benjamin S. Kirk, 2004.

Definition at line 41 of file plt_loader.h.


Member Enumeration Documentation

Enum defining the data type of each variable.

Enumerator:
FLOAT 
DOUBLE 
LONGINT 
SHORTINT 
BYTE 
BIT 

Definition at line 134 of file plt_loader.h.

00134                 { FLOAT=1,
00135                   DOUBLE,
00136                   LONGINT,
00137                   SHORTINT,
00138                   BYTE,
00139                   BIT};

Enum defining the finite element types

Enumerator:
TRI 
QUAD 
TET 
HEX 

Definition at line 144 of file plt_loader.h.

00144               { TRI=0,
00145                 QUAD,
00146                 TET,
00147                 HEX };

Enum defining the zone type in the Tecplot binary file, for use with the new .plt format.

Enumerator:
ORDERED 
FELINESEG 
FETRIANGLE 
FEQUADRILATERAL 
FETETRAHEDRON 
FEBRICK 

Definition at line 124 of file plt_loader.h.

00124                    { ORDERED=0,
00125                      FELINESEG,
00126                      FETRIANGLE,
00127                      FEQUADRILATERAL,
00128                      FETETRAHEDRON,
00129                      FEBRICK };

Writes a plot3d files. The grid will be in basename.g and the solution will be in basename.q. It is assumed that the first three variables from the .plt file are the (x,y,z) locations of the grid points. The optional parameter reverse specifies if the output file will have reversed byte ordering. Writes a Cart3D .tri component file. The number of components will be the number of zones in the .plt file. Enum defining the zone type in the Tecplot binary file, for use with the old .plt format.

Enumerator:
BLOCK 
POINT 
FEBLOCK 
FEPOINT 

Definition at line 115 of file plt_loader.h.

00115                    { BLOCK=0,
00116                      POINT,
00117                      FEBLOCK,
00118                      FEPOINT };


Constructor & Destructor Documentation

libMesh::PltLoader::PltLoader ( const bool  v = false  )  [inline]

Constructor. Initializes data.

Definition at line 447 of file plt_loader.h.

00447                                   :
00448   _verbose      (v),
00449   _is_foreign   (false),
00450   _n_vars       (0),
00451   _n_zones      (0)
00452 {
00453 }

libMesh::PltLoader::PltLoader ( const std::string &  name,
const bool  v = false 
) [inline]

Constructor. Reads the file specified by name.

Definition at line 458 of file plt_loader.h.

References read().

00458                                                          :
00459   _verbose      (v),
00460   _is_foreign   (false),
00461   _n_vars       (0),
00462   _n_zones      (0)
00463 {
00464   this->read (name);
00465 }

libMesh::PltLoader::~PltLoader (  )  [inline]

Destructor.

Definition at line 470 of file plt_loader.h.

00471 {
00472 }


Member Function Documentation

void libMesh::PltLoader::clear (  ) 

Clear all data and return to a pristine state.

Definition at line 34 of file plt_loader.C.

References _conn, _data, _imax, _is_foreign, _jmax, _kmax, _n_vars, _n_zones, _title, _var_names, _var_types, _version, _zone_names, _zone_pack, and _zone_types.

00035 {
00036   // clear vectors & strings.  Using .erase() for strings instead of .clear()
00037   // since GCC 2.95.3 does not support .clear().
00038   _version.erase();
00039   _title.erase();
00040 
00041   _var_names.clear();
00042   _var_types.clear();
00043   _zone_types.clear();
00044   _zone_names.clear();
00045   _zone_pack.clear();
00046   _imax.clear();
00047   _jmax.clear();
00048   _kmax.clear();
00049   _data.clear();
00050   _conn.clear();
00051 
00052   // reinitialize
00053   _is_foreign = false;
00054   _n_vars     = 0;
00055   _n_zones    = 0;
00056 }

PltLoader::FEType libMesh::PltLoader::elem_type ( const unsigned int  z  )  const [inline]
Returns:
the element type for the zth zone (for unstructured meshes).

Definition at line 689 of file plt_loader.h.

References kmax(), n_zones(), and zone_type().

00690 {
00691   libmesh_assert_less (z, this->n_zones());
00692 
00693   // Only for unstructured zones!
00694   libmesh_assert_greater (this->zone_type(z), 1);
00695 
00696   return static_cast<FEType>(this->kmax(z));
00697 }

const std::vector< std::vector< std::vector< float > > > & libMesh::PltLoader::get_data (  )  const [inline]
Returns:
a reference to the data read from the file

Definition at line 702 of file plt_loader.h.

References _data.

00703 {
00704   return _data;
00705 }

unsigned int & libMesh::PltLoader::imax ( const unsigned int  z  )  [inline, private]
Returns:
imax for zone z.

Definition at line 608 of file plt_loader.h.

References _imax, and n_zones().

00609 {
00610   libmesh_assert_less (z, this->n_zones());
00611   libmesh_assert_equal_to (_imax.size(), this->n_zones());
00612 
00613   return _imax[z];
00614 }

unsigned int libMesh::PltLoader::imax ( const unsigned int  z  )  const [inline]
Returns:
imax for zone z.

Definition at line 597 of file plt_loader.h.

References _imax, and n_zones().

Referenced by n_nodes(), read_block_data(), read_data(), read_feblock_data(), read_fepoint_data(), read_header(), read_point_data(), and write_dat().

00598 {
00599   libmesh_assert_less (z, this->n_zones());
00600   libmesh_assert_equal_to (_imax.size(), this->n_zones());
00601 
00602   return _imax[z];
00603 }

bool& libMesh::PltLoader::is_foreign (  )  [inline, private]
Returns:
true if the binary type of the file is different than the machine that is reading it. If this is the case we must perform an endian-swap on all input data.

Definition at line 300 of file plt_loader.h.

References _is_foreign.

00300 { return _is_foreign; }

bool libMesh::PltLoader::is_foreign (  )  const [inline]
Returns:
true if the binary type of the file is different than the machine that is reading it. If this is the case we must perform an endian-swap on all input data.

Definition at line 168 of file plt_loader.h.

References _is_foreign.

Referenced by read_block_data(), read_data(), read_feblock_data(), read_fepoint_data(), read_header(), and read_point_data().

00168 { return _is_foreign; }

unsigned int & libMesh::PltLoader::jmax ( const unsigned int  z  )  [inline, private]
Returns:
jmax for zone z.

Definition at line 630 of file plt_loader.h.

References _jmax, and n_zones().

00631 {
00632   libmesh_assert_less (z, this->n_zones());
00633   libmesh_assert_equal_to (_jmax.size(), this->n_zones());
00634 
00635   return _jmax[z];
00636 }

unsigned int libMesh::PltLoader::jmax ( const unsigned int  z  )  const [inline]
Returns:
jmax for zone z.

Definition at line 619 of file plt_loader.h.

References _jmax, and n_zones().

Referenced by n_elem(), read_block_data(), read_data(), read_feblock_data(), read_fepoint_data(), read_header(), read_point_data(), and write_dat().

00620 {
00621   libmesh_assert_less (z, this->n_zones());
00622   libmesh_assert_equal_to (_jmax.size(), this->n_zones());
00623 
00624   return _jmax[z];
00625 }

unsigned int & libMesh::PltLoader::kmax ( const unsigned int  z  )  [inline, private]
Returns:
kmax for zone z.

Definition at line 652 of file plt_loader.h.

References _kmax, and n_zones().

00653 {
00654   libmesh_assert_less (z, this->n_zones());
00655   libmesh_assert_equal_to (_kmax.size(), this->n_zones());
00656 
00657   return _kmax[z];
00658 }

unsigned int libMesh::PltLoader::kmax ( const unsigned int  z  )  const [inline]
Returns:
kmax for zone z.

Definition at line 641 of file plt_loader.h.

References _kmax, and n_zones().

Referenced by elem_type(), read_block_data(), read_data(), read_feblock_data(), read_fepoint_data(), read_header(), read_point_data(), and write_dat().

00642 {
00643   libmesh_assert_less (z, this->n_zones());
00644   libmesh_assert_equal_to (_kmax.size(), this->n_zones());
00645 
00646   return _kmax[z];
00647 }

unsigned int libMesh::PltLoader::n_elem ( const unsigned int  z  )  const [inline]
Returns:
the number of elements in the mesh (for unstructured meshes).

Definition at line 676 of file plt_loader.h.

References jmax(), n_zones(), and zone_type().

Referenced by read_header().

00677 {
00678   libmesh_assert_less (z, this->n_zones());
00679 
00680   // Only for unstructured zones!
00681   libmesh_assert_greater (this->zone_type(z), 1);
00682 
00683   return this->jmax(z);
00684 }

unsigned int libMesh::PltLoader::n_nodes ( const unsigned int  z  )  const [inline]
Returns:
the number of nodes in the mesh (for unstructured meshes).

Definition at line 663 of file plt_loader.h.

References imax(), n_zones(), and zone_type().

Referenced by read_header().

00664 {
00665   libmesh_assert_less (z, this->n_zones());
00666 
00667   // Only for unstructured zones!
00668   libmesh_assert_greater (this->zone_type(z), 1);
00669 
00670   return this->imax(z);
00671 }

unsigned int libMesh::PltLoader::n_vars (  )  const [inline]
Returns:
the number of variables in the data set.

Definition at line 178 of file plt_loader.h.

References _n_vars.

Referenced by read_block_data(), read_data(), read_feblock_data(), read_fepoint_data(), read_header(), read_point_data(), set_n_vars(), set_n_zones(), var_name(), var_type(), and write_dat().

00178 { return _n_vars; }

unsigned int libMesh::PltLoader::n_zones (  )  const [inline]
Returns:
the number of zones.

Definition at line 193 of file plt_loader.h.

References _n_zones.

Referenced by elem_type(), imax(), jmax(), kmax(), n_elem(), n_nodes(), read_data(), read_feblock_data(), read_header(), set_n_vars(), set_n_zones(), write_dat(), zone_name(), zone_pack(), and zone_type().

00193 { return _n_zones; }

void libMesh::PltLoader::read ( const std::string &  name  ) 

Reads the .plt file specified by name.

Definition at line 34 of file plt_loader_read.C.

References libMesh::err, libMesh::out, read_data(), read_header(), and verbose().

Referenced by PltLoader().

00035 {
00036   std::ifstream in (name.c_str(), std::ios::in|std::ios::binary);
00037 
00038   if (!in.good())
00039     {
00040       libMesh::err << "Error reading input file " << name
00041                     << std::endl;
00042 
00043       libmesh_error();
00044     }
00045 
00046 
00047   if (this->verbose())
00048     libMesh::out << std::endl
00049                   << "Reading input file " << name
00050                   << std::endl
00051                   << "-------------------------------------------------------------------------"
00052                   << std::endl;
00053 
00054   this->read_header (in);
00055   this->read_data   (in);
00056 
00057   if (this->verbose())
00058     libMesh::out << std::endl
00059                   << "-------------------------------------------------------------------------"
00060                   << std::endl;
00061 
00062 }

void libMesh::PltLoader::read_block_data ( std::istream &  in,
const unsigned int  zn 
) [private]

Read data for the zth zone in BLOCK structured format.

Definition at line 877 of file plt_loader_read.C.

References _data, data, DOUBLE, libMesh::err, FLOAT, imax(), is_foreign(), jmax(), kmax(), n_vars(), and var_type().

Referenced by read_data().

00878 {
00879   libmesh_assert (in.good());
00880 
00881 
00882   // A byte-reverser in case the data is foreign
00883   Utility::ReverseBytes rb(this->is_foreign());
00884 
00885 
00886   for (unsigned int var=0; var<this->n_vars(); var++)
00887     {
00888 
00889       switch (this->var_type(var))
00890         {
00891 
00892           // Read a single-precision variable
00893         case FLOAT:
00894           {
00895             std::vector<float> & data = _data[zone][var];
00896 
00897             data.clear();
00898             data.resize (this->imax(zone)*
00899                          this->jmax(zone)*
00900                          this->kmax(zone));
00901 
00902             in.read ((char*) &data[0], LIBMESH_SIZEOF_FLOAT*data.size());
00903 
00904             for (unsigned int i=0; i<data.size(); i++)
00905               rb(data[i]);
00906 
00907             break;
00908           }
00909 
00910           // Read a double-precision variable
00911         case DOUBLE:
00912           {
00913             std::vector<double> ddata;
00914             std::vector<float> & data = _data[zone][var];
00915 
00916             data.clear();
00917             data.resize (this->imax(zone)*
00918                          this->jmax(zone)*
00919                          this->kmax(zone));
00920 
00921             ddata.resize (this->imax(zone)*
00922                           this->jmax(zone)*
00923                           this->kmax(zone));
00924 
00925             in.read ((char*) &ddata[0], LIBMESH_SIZEOF_DOUBLE*ddata.size());
00926 
00927             for (unsigned int i=0; i<data.size(); i++)
00928               data[i] = rb(ddata[i]);
00929 
00930             break;
00931           }
00932 
00933         default:
00934           {
00935             libMesh::err << "ERROR: Unsupported data type: "
00936                           << this->var_type(var)
00937                           << std::endl;
00938             libmesh_error();
00939           }
00940         }
00941     }
00942 }

void libMesh::PltLoader::read_data ( std::istream &  in  )  [private]

Read data from the binary file.

Definition at line 621 of file plt_loader_read.C.

References BLOCK, buf, libMesh::err, FEBLOCK, FEPOINT, libMesh::BasicOStreamProxy< charT, traits >::flush(), imax(), is_foreign(), jmax(), kmax(), n_vars(), n_zones(), ORDERED, libMesh::out, POINT, read_block_data(), read_feblock_data(), read_fepoint_data(), read_point_data(), var_type(), verbose(), version(), zone_pack(), and zone_type().

Referenced by read().

00622 {
00623   libmesh_assert (in.good());
00624 
00625   // A byte-reverser in case the data is foreign
00626   Utility::ReverseBytes rb(this->is_foreign());
00627 
00628   //----------------------------------------------------
00629   // Read the TECPLOT data for each zone
00630   if (this->verbose())
00631     {
00632       libMesh::out << "Reading Zones";
00633       libMesh::out.flush();
00634     }
00635 
00636 
00637   for (unsigned int zone=0; zone<this->n_zones(); zone++)
00638     {
00639       if (this->verbose())
00640         {
00641           libMesh::out << ".";
00642           libMesh::out.flush();
00643         }
00644 
00645 
00646       //----------------------------------------------------
00647       // Read plt files written by older versions of Tecplot
00648       if (this->version().rfind("V7") < this->version().size())
00649         {
00650           float f = 0.;
00651 
00652           // Find the next Zone marker.
00653           do
00654             {
00655               f = 0.;
00656               in.read (buf, LIBMESH_SIZEOF_FLOAT);
00657               std::memcpy  (&f, buf, LIBMESH_SIZEOF_FLOAT);
00658               rb(f);
00659             }
00660           while ((f != 299.) && in.good());
00661 
00662           // Did we overrun the file?
00663           if (!in.good())
00664             {
00665               libMesh::err << "ERROR: Unexpected end-of-file!"
00666                             << std::endl;
00667               libmesh_error();
00668             }
00669 
00670           // Get the number of repeated vars.
00671           unsigned int n_rep_vars=0;
00672           std::vector<int> rep_vars;
00673 
00674           {
00675             in.read (buf, LIBMESH_SIZEOF_INT);
00676             std::memcpy  (&n_rep_vars, buf, LIBMESH_SIZEOF_INT);
00677             rb(n_rep_vars);
00678 
00679             rep_vars.resize (n_rep_vars);
00680 
00681             // Get the repeated variables number.
00682             for (unsigned int v=0; v<n_rep_vars; v++)
00683               {
00684                 libMesh::err << "ERROR:  I don't understand repeated variables yet!"
00685                               << std::endl;
00686                 libmesh_error();
00687 
00688                 in.read (buf, LIBMESH_SIZEOF_INT);
00689                 std::memcpy  (&rep_vars[v], buf, LIBMESH_SIZEOF_INT);
00690                 rb(rep_vars[v]);
00691               }
00692           }
00693 
00694           // Get the variable data type
00695           //libMesh::out << "var_types=";
00696           for (unsigned int v=0; v<this->n_vars(); v++)
00697             {
00698               in.read (buf, LIBMESH_SIZEOF_INT);
00699               std::memcpy  (&this->var_type(v), buf, LIBMESH_SIZEOF_INT);
00700               rb(this->var_type(v));
00701 
00702               //libMesh::out << this->var_type(v) << " ";
00703             }
00704           //libMesh::out << std::endl;
00705 
00706 
00707 
00708           // Read the data.
00709           switch (this->zone_type(zone) )
00710             {
00711               // Block-based data.  Structured meshes.
00712             case BLOCK:
00713               {
00714                 this->read_block_data (in, zone);
00715                 break;
00716               }
00717 
00718               // Point-based data.  Structured meshes.
00719             case POINT:
00720               {
00721                 this->read_point_data (in, zone);
00722                 break;
00723               }
00724 
00725               // FE block data.  Unstructured meshes.
00726             case FEBLOCK:
00727               {
00728                 this->read_feblock_data (in, zone);
00729 
00730                 if (this->verbose())
00731 
00732                   libMesh::out << "Zone " << zone << ":" << std::endl
00733                             << "  nnodes   =" << this->imax(zone) << std::endl
00734                             << "  nelem    =" << this->jmax(zone) << std::endl
00735                             << "  elem_type=" << this->kmax(zone) << std::endl
00736                             << std::endl;
00737                 break;
00738               }
00739 
00740               // FE point data.  Unstructured meshes.
00741             case FEPOINT:
00742               {
00743                 this->read_fepoint_data (in, zone);
00744                 break;
00745               }
00746 
00747             default:
00748               {
00749                 libMesh::err << "ERROR: Unsupported Zone type: "
00750                               << this->zone_type(zone)
00751                               << std::endl;
00752                 libmesh_error();
00753               }
00754             } // end switch on zone type
00755         }
00756 
00757 
00758       //----------------------------------------------------
00759       // Read plt files written by newer versions of Tecplot
00760       else if (this->version().rfind("V1") < this->version().size())
00761         {
00762           float f = 0.;
00763 
00764           // Find the next Zone marker.
00765           do
00766             {
00767               f = 0.;
00768               in.read (buf, LIBMESH_SIZEOF_FLOAT);
00769               std::memcpy  (&f, buf, LIBMESH_SIZEOF_FLOAT);
00770               rb(f);
00771             }
00772           while ((f != 299.) && in.good());
00773 
00774           // Did we overrun the file?
00775           if (!in.good())
00776             {
00777               libMesh::err << "ERROR: Unexpected end-of-file!"
00778                             << std::endl;
00779               libmesh_error();
00780             }
00781 
00782           // Get the variable data type
00783           for (unsigned int v=0; v<this->n_vars(); v++)
00784             {
00785               in.read (buf, LIBMESH_SIZEOF_INT);
00786               std::memcpy  (&this->var_type(v), buf, LIBMESH_SIZEOF_INT);
00787               rb(this->var_type(v));
00788 
00789               //libMesh::out << this->var_type(v) << " ";
00790             }
00791 
00792           // Get the variable sharing flag
00793           {
00794             int vs=0;
00795             int sv=0;
00796 
00797             in.read (buf, LIBMESH_SIZEOF_INT);
00798             std::memcpy  (&vs, buf, LIBMESH_SIZEOF_INT);
00799             rb(vs);
00800 
00801             if (vs)
00802               {
00803                 for (unsigned int v=0; v<this->n_vars(); v++)
00804                   {
00805                     in.read (buf, LIBMESH_SIZEOF_INT);
00806                     std::memcpy  (&sv, buf, LIBMESH_SIZEOF_INT);
00807                     rb(sv);
00808 
00809                     if (sv != -1)
00810                       {
00811                         libMesh::err << "ERROR:  I don't understand variable sharing!"
00812                                       << std::endl;
00813                         libmesh_error();
00814                       }
00815                   }
00816               }
00817           }
00818 
00819           // Get zone to share connectivity with
00820           {
00821             int sc=0;
00822             in.read (buf, LIBMESH_SIZEOF_INT);
00823             std::memcpy  (&sc, buf, LIBMESH_SIZEOF_INT);
00824             rb(sc);
00825 
00826             libmesh_assert_equal_to (sc, -1);
00827           }
00828 
00829 
00830           // Read the data.
00831           if (this->zone_type(zone) == ORDERED)
00832             {
00833                 // Block-based data.  Structured meshes.
00834               if (this->zone_pack(zone) == 0)
00835                 this->read_block_data (in, zone);
00836 
00837               // Point-based data.  Structured meshes.
00838               else if (this->zone_pack(zone) == 1)
00839                 this->read_point_data (in, zone);
00840 
00841               else
00842                 libmesh_error();
00843             }
00844           else
00845             {
00846               // Block-based data.  Unstructured meshes.
00847               if (this->zone_pack(zone) == 0)
00848                 this->read_feblock_data (in, zone);
00849 
00850               // Point-based data.  Unstructured meshes.
00851               else if (this->zone_pack(zone) == 1)
00852                 this->read_fepoint_data (in, zone);
00853 
00854               else
00855                 libmesh_error();
00856             }
00857         }
00858 
00859 
00860 
00861       //----------------------------------------------------
00862       // Unrecognized Tecplot Version!
00863       else
00864         {
00865           libMesh::err << "ERROR:  This plot file was written by an unrecognized version of Tecplot!:"
00866                         << std::endl
00867                         << this->version()
00868                         << std::endl;
00869           libmesh_error();
00870         }
00871 
00872     } // end loop on zones
00873 }

void libMesh::PltLoader::read_feblock_data ( std::istream &  in,
const unsigned int  zn 
) [private]

Read data for the zth zone in FEBLOCK unstructured format.

Definition at line 1004 of file plt_loader_read.C.

References _conn, _data, data, DOUBLE, libMesh::err, FLOAT, imax(), is_foreign(), jmax(), kmax(), n_vars(), n_zones(), NNodes, and var_type().

Referenced by read_data().

01005 {
01006   libmesh_assert (in.good());
01007 
01008   // A byte-reverser in case the data is foreign
01009   Utility::ReverseBytes rb(this->is_foreign());
01010 
01011   // Read the variable values at each node.
01012   for (unsigned int var=0; var<this->n_vars(); var++)
01013     {
01014       switch (this->var_type(var))
01015         {
01016 
01017           // Read a single-precision variable
01018         case FLOAT:
01019           {
01020             std::vector<float> & data = _data[zone][var];
01021 
01022             data.clear();
01023             data.resize (this->imax(zone));
01024 
01025             in.read ((char*) &data[0], LIBMESH_SIZEOF_FLOAT*data.size());
01026 
01027             for (unsigned int i=0; i<data.size(); i++)
01028               rb(data[i]);
01029 
01030             break;
01031           }
01032 
01033           // Read a double-precision variable
01034         case DOUBLE:
01035           {
01036             std::vector<double> ddata;
01037             std::vector<float> & data = _data[zone][var];
01038 
01039             data.clear();
01040             data.resize (this->imax(zone));
01041             ddata.resize (this->imax(zone));
01042 
01043             in.read ((char*) &ddata[0], LIBMESH_SIZEOF_DOUBLE*ddata.size());
01044 
01045             for (unsigned int i=0; i<data.size(); i++)
01046               data[i] = rb(ddata[i]);
01047 
01048             break;
01049           }
01050 
01051         default:
01052           {
01053             libMesh::err << "ERROR: Unsupported data type: "
01054                           << this->var_type(var)
01055                           << std::endl;
01056             libmesh_error();
01057           }
01058         }
01059     }
01060 
01061   // Read the connectivity
01062   {
01063     // Get the connectivity repetition flag
01064     int rep=0;
01065     in.read ((char*) &rep, LIBMESH_SIZEOF_INT);
01066     rb(rep);
01067 
01068     if (rep == 1 && this->n_zones() > 1)
01069       {
01070         libMesh::err << "ERROR:  Repeated connectivity not supported!"
01071                       << std::endl;
01072         libmesh_error();
01073       }
01074 
01075     // Read the connectivity
01076     else
01077       {
01078         libmesh_assert_less (zone, _conn.size());
01079         libmesh_assert_less (this->kmax(zone), 4);
01080 
01081         _conn[zone].resize (this->jmax(zone)*NNodes[this->kmax(zone)]);
01082 
01083         in.read ((char*) &_conn[zone][0], LIBMESH_SIZEOF_INT*_conn[zone].size());
01084 
01085         for (unsigned int i=0; i<_conn[zone].size(); i++)
01086           rb(_conn[zone][i]);
01087       }
01088   }
01089 }

void libMesh::PltLoader::read_fepoint_data ( std::istream &  in,
const unsigned int  zn 
) [private]

Read data for the zth zone in FEPOINT unstructured format.

Definition at line 1093 of file plt_loader_read.C.

References _conn, _data, buf, data, DOUBLE, libMesh::err, FLOAT, imax(), is_foreign(), jmax(), kmax(), n_vars(), NNodes, and var_type().

Referenced by read_data().

01094 {
01095   libmesh_assert (in.good());
01096 
01097   // A byte-reverser in case the data is foreign
01098   Utility::ReverseBytes rb(this->is_foreign());
01099 
01100   // First allocate space
01101   for (unsigned int var=0; var<this->n_vars(); var++)
01102     {
01103       std::vector<float> & data = _data[zone][var];
01104 
01105       data.clear();
01106       data.reserve (this->imax(zone));
01107     }
01108 
01109 
01110   for (unsigned int i=0; i<this->imax(zone); i++)
01111     for (unsigned int var=0; var<this->n_vars(); var++)
01112       if (this->var_type(var) == FLOAT)
01113         {
01114           float f = 0.;
01115 
01116           libmesh_assert (in.good());
01117 
01118           in.read (buf, LIBMESH_SIZEOF_FLOAT);
01119           std::memcpy  (&f, buf, LIBMESH_SIZEOF_FLOAT);
01120           rb(f);
01121 
01122           _data[zone][var].push_back(f);
01123         }
01124       else if (this->var_type(var) == DOUBLE)
01125         {
01126           double d = 0.;
01127 
01128           libmesh_assert (in.good());
01129 
01130           in.read (buf, LIBMESH_SIZEOF_DOUBLE);
01131           std::memcpy  (&d, buf, LIBMESH_SIZEOF_DOUBLE);
01132           rb(d);
01133 
01134           _data[zone][var].push_back(d);
01135         }
01136       else
01137         {
01138           libMesh::err << "ERROR: unsupported data type: "
01139                         << this->var_type(var)
01140                         << std::endl;
01141           libmesh_error();
01142         }
01143 
01144   // Read the connectivity
01145   {
01146     // Get the connectivity repetition flag
01147     int rep=0;
01148 
01149     in.read ((char*) &rep, LIBMESH_SIZEOF_INT);
01150     rb(rep);
01151 
01152     if (rep == 1)
01153       {
01154         libMesh::err << "ERROR:  Repeated connectivity not supported!"
01155                       << std::endl;
01156         libmesh_error();
01157       }
01158 
01159     // Read the connectivity
01160     else
01161       {
01162         libmesh_assert_less (zone, _conn.size());
01163         libmesh_assert_less (this->kmax(zone), 4);
01164 
01165         _conn[zone].resize (this->jmax(zone)*NNodes[this->kmax(zone)]);
01166 
01167         in.read ((char*) &_conn[zone][0], LIBMESH_SIZEOF_INT*_conn[zone].size());
01168 
01169         for (unsigned int i=0; i<_conn[zone].size(); i++)
01170           rb(_conn[zone][i]);
01171       }
01172   }
01173 }

void libMesh::PltLoader::read_header ( std::istream &  in  )  [private]

Read the header of the binary file.

Definition at line 66 of file plt_loader_read.C.

References buf, libMesh::err, imax(), is_foreign(), jmax(), kmax(), n_elem(), n_nodes(), n_vars(), n_zones(), libMesh::Quality::name(), ORDERED, libMesh::out, set_n_vars(), set_n_zones(), title(), var_name(), var_type(), verbose(), version(), zone_name(), zone_pack(), and zone_type().

Referenced by read().

00067 {
00068   libmesh_assert (in.good());
00069 
00070   //----------------------------------------------------
00071   // Read the TECPLOT header
00072 
00073   // Read the version number
00074   {
00075     in.read (buf, 8);
00076 
00077     // Using erase for GCC 2.95.3
00078     this->version().erase();
00079 
00080     for (unsigned int i=0; i<8; i++)
00081       this->version() += buf[i];
00082 
00083     if (this->verbose())
00084       libMesh::out << "Tecplot Version: "
00085                     << this->version()
00086                     << std::endl;
00087   }
00088 
00089 
00090   //----------------------------------------------------
00091   // Read plt files written by older versions of Tecplot
00092   if (this->version().rfind("V7") < this->version().size())
00093     {
00094       if (this->verbose())
00095         libMesh::out << "Reading legacy .plt format (<= v9) ..."
00096                       << std::endl;
00097 
00098       // Read the value of 1 to determine byte ordering
00099       {
00100         int one = 0;
00101         in.read (buf, LIBMESH_SIZEOF_INT);
00102         std::memcpy  (&one, buf, LIBMESH_SIZEOF_INT);
00103 
00104         if (one != 1)
00105           {
00106             if (this->verbose())
00107               libMesh::out << "Tecplot data is Foreign!"
00108                             << std::endl;
00109             this->is_foreign() = true;
00110 
00111             // Make sure one reversed is one
00112             Utility::ReverseBytes rb(this->is_foreign());
00113             libmesh_assert_equal_to (rb(one), 1);
00114           }
00115       }
00116 
00117       // A byte-reverser in case the data is foreign
00118       Utility::ReverseBytes rb(this->is_foreign());
00119 
00120       // Read the title
00121       {
00122         int i=0;
00123 
00124         // Using erase for GCC 2.95.3
00125         this->title().erase();
00126 
00127         do
00128           {
00129             in.read (buf, LIBMESH_SIZEOF_INT);
00130             std::memcpy  (&i, buf, LIBMESH_SIZEOF_INT);
00131             rb(i);
00132 
00133             // Don't add trailing \0
00134             if (i)
00135               this->title() += static_cast<char>(i);
00136           }
00137         while (i);
00138       }
00139 
00140       // Read the number of variables in the data set
00141       {
00142         int nv;
00143         in.read (buf, LIBMESH_SIZEOF_INT);
00144         std::memcpy  (&nv, buf, LIBMESH_SIZEOF_INT);
00145         rb(nv);
00146 
00147         this->set_n_vars (nv);
00148       }
00149 
00150       // Read the variable names
00151       for (unsigned int v=0; v<this->n_vars(); v++)
00152         {
00153           int i=0;
00154 
00155           // Using erase for GCC 2.95.3
00156           this->var_name(v).erase();
00157 
00158           do
00159             {
00160               in.read (buf, LIBMESH_SIZEOF_INT);
00161               std::memcpy  (&i, buf, LIBMESH_SIZEOF_INT);
00162               rb(i);
00163 
00164               // Don't add trailing \0
00165               if (i)
00166                 this->var_name(v) += static_cast<char>(i);
00167             }
00168           while (i);
00169         }
00170 
00171 
00172 
00173       // Read zones from the header.
00174       // Continue reading until the end-of-header
00175       // marker (357.) is found.
00176       int nz=0;
00177       std::vector<std::string> zname;
00178       std::vector<int>         ztype, zimax, zjmax, zkmax;
00179 
00180       {
00181         float f=0.;
00182 
00183         do
00184           {
00185             // find the next Zone marker
00186             do
00187               {
00188                 f = 0.;
00189                 in.read (buf, LIBMESH_SIZEOF_FLOAT);
00190                 std::memcpy  (&f, buf, LIBMESH_SIZEOF_FLOAT);
00191                 rb(f);
00192               }
00193             while ((f != 299.) &&
00194                    (f != 357.) &&
00195                    in.good());
00196 
00197 
00198             // Did we overrun the file?
00199             if (!in.good())
00200               {
00201                 libMesh::err << "ERROR: Unexpected end-of-file!"
00202                               << std::endl;
00203                 libmesh_error();
00204               }
00205 
00206             // Found a Zone marker
00207             else if (f == 299.)
00208               {
00209                 // Incriment the Zone counter
00210                 nz++;
00211 
00212                 // Read the zone name
00213                 {
00214                   int i=0;
00215                   std::string name;
00216 
00217                   do
00218                     {
00219                       in.read (buf, LIBMESH_SIZEOF_INT);
00220                       std::memcpy  (&i, buf, LIBMESH_SIZEOF_INT);
00221                       rb(i);
00222 
00223                       // Don't add trailing \0
00224                       if (i)
00225                         name += static_cast<char>(i);
00226                     }
00227                   while (i);
00228 
00229                   zname.push_back(name);
00230                 }
00231 
00232                 // Read the zone format
00233                 {
00234                   int zt;
00235                   in.read (buf, LIBMESH_SIZEOF_INT);
00236                   std::memcpy  (&zt, buf, LIBMESH_SIZEOF_INT);
00237                   rb(zt);
00238 
00239                   ztype.push_back(zt);
00240                   //libMesh::out << "zone type=" << ztype.back() << std::endl;
00241                 }
00242 
00243                 // Read the zone color
00244                 {
00245                   int zc=0;
00246 
00247                   in.read (buf, LIBMESH_SIZEOF_INT);
00248                   std::memcpy  (&zc, buf, LIBMESH_SIZEOF_INT);
00249                   rb(zc);
00250 
00251                   //libMesh::out << "zone color=" << zc << std::endl;
00252                 }
00253 
00254                 // Read in the block dimensions
00255                 {
00256                   int
00257                     i_max=0,
00258                     j_max=0,
00259                     k_max=0;
00260 
00261                   in.read (buf, LIBMESH_SIZEOF_INT);
00262                   std::memcpy  (&i_max, buf, LIBMESH_SIZEOF_INT);
00263                   rb(i_max);
00264 
00265                   in.read (buf, LIBMESH_SIZEOF_INT);
00266                   std::memcpy  (&j_max, buf, LIBMESH_SIZEOF_INT);
00267                   rb(j_max);
00268 
00269                   in.read (buf, LIBMESH_SIZEOF_INT);
00270                   std::memcpy  (&k_max, buf, LIBMESH_SIZEOF_INT);
00271                   rb(k_max);
00272 
00273                   zimax.push_back (i_max);
00274                   zjmax.push_back (j_max);
00275                   zkmax.push_back (k_max);
00276                 }
00277               } // else if (f == 299.)
00278           }
00279         while ((f != 357.) && in.good());
00280       }
00281 
00282       // Set the header data
00283       this->set_n_zones (nz);
00284 
00285       for (unsigned int z=0; z<this->n_zones(); z++)
00286         {
00287           this->zone_type(z) = ztype[z];
00288           this->zone_name(z) = zname[z];
00289           this->imax(z)      = zimax[z];
00290           this->jmax(z)      = zjmax[z];
00291           this->kmax(z)      = zkmax[z];
00292         }
00293     }
00294 
00295 
00296   //----------------------------------------------------
00297   // Read plt files written by newer versions of Tecplot
00298   else if (this->version().rfind("V1") < this->version().size())
00299     {
00300       if (this->verbose())
00301         libMesh::out << "Reading new .plt format (>= v10)..."
00302                       << std::endl;
00303 
00304       // Read the value of 1 to determine byte ordering
00305       {
00306         int one = 0;
00307 
00308         in.read (buf, LIBMESH_SIZEOF_INT);
00309         std::memcpy  (&one, buf, LIBMESH_SIZEOF_INT);
00310 
00311         if (one != 1)
00312           {
00313             if (this->verbose())
00314               libMesh::err << "Tecplot data is Foreign!"
00315                             << std::endl;
00316             this->is_foreign() = true;
00317 
00318             // Make sure one reversed is one
00319             Utility::ReverseBytes rb(this->is_foreign());
00320             libmesh_assert_equal_to (rb(one), 1);
00321           }
00322       }
00323 
00324       // A byte-reverser in case the data is foreign
00325       Utility::ReverseBytes rb(this->is_foreign());
00326 
00327       // Read the title
00328       {
00329         int i=0;
00330 
00331         // Using erase() for GCC 2.95.3
00332         this->title().erase();
00333         do
00334           {
00335             in.read (buf, LIBMESH_SIZEOF_INT);
00336             std::memcpy  (&i, buf, LIBMESH_SIZEOF_INT);
00337             rb(i);
00338 
00339             // Don't add trailing \0
00340             if (i)
00341               this->title() += static_cast<char>(i);
00342           }
00343         while (i);
00344       }
00345 
00346       // Read the number of variables in the data set
00347       {
00348         int nv;
00349         in.read (buf, LIBMESH_SIZEOF_INT);
00350         std::memcpy  (&nv, buf, LIBMESH_SIZEOF_INT);
00351         rb(nv);
00352 
00353         this->set_n_vars (nv);
00354       }
00355 
00356       // Read the variable names
00357       for (unsigned int v=0; v<this->n_vars(); v++)
00358         {
00359           int i=0;
00360 
00361           // Using erase() for GCC 2.95.3
00362           this->var_name(v).erase();
00363 
00364           do
00365             {
00366               in.read (buf, LIBMESH_SIZEOF_INT);
00367               std::memcpy  (&i, buf, LIBMESH_SIZEOF_INT);
00368               rb(i);
00369 
00370               // Don't add trailing \0
00371               if (i)
00372                 this->var_name(v) += static_cast<char>(i);
00373             }
00374           while (i);
00375         }
00376 
00377 
00378 
00379       // Read zones from the header.
00380       // Continue reading until the end-of-header
00381       // marker (357.) is found.
00382       int nz=0;
00383       std::vector<std::string> zname;
00384       std::vector<int>         zpack, ztype, zimax, zjmax, zkmax, znelem, znnodes;
00385 
00386       {
00387         float f=0.;
00388 
00389         do
00390           {
00391             // find the next Zone marker
00392             do
00393               {
00394                 f = 0.;
00395                 in.read (buf, LIBMESH_SIZEOF_FLOAT);
00396                 std::memcpy  (&f, buf, LIBMESH_SIZEOF_FLOAT);
00397                 rb(f);
00398               }
00399             while ((f != 299.) &&
00400                    (f != 357.) &&
00401                    in.good());
00402 
00403 
00404             // Did we overrun the file?
00405             if (!in.good())
00406               {
00407                 libMesh::err << "ERROR: Unexpected end-of-file!"
00408                               << std::endl;
00409                 libmesh_error();
00410               }
00411 
00412             // Found a Zone marker
00413             else if (f == 299.)
00414               {
00415                 // Incriment the Zone counter
00416                 nz++;
00417 
00418                 // Read the zone name
00419                 {
00420                   int i=0;
00421                   std::string name;
00422 
00423                   do
00424                     {
00425                       in.read (buf, LIBMESH_SIZEOF_INT);
00426                       std::memcpy  (&i, buf, LIBMESH_SIZEOF_INT);
00427                       rb(i);
00428 
00429                       // Don't add trailing \0
00430                       if (i)
00431                         name += static_cast<char>(i);
00432                     }
00433                   while (i);
00434 
00435                   zname.push_back(name);
00436                 }
00437 
00438                 // Read the zone color
00439                 {
00440                   int zc=0;
00441                   in.read (buf, LIBMESH_SIZEOF_INT);
00442                   std::memcpy  (&zc, buf, LIBMESH_SIZEOF_INT);
00443                   rb(zc);
00444                 }
00445 
00446                 // Read the zone format
00447                 {
00448                   int zt;
00449                   in.read (buf, LIBMESH_SIZEOF_INT);
00450                   std::memcpy  (&zt, buf, LIBMESH_SIZEOF_INT);
00451                   rb(zt);
00452 
00453                   ztype.push_back(zt);
00454                 }
00455 
00456                 // Read the data packing flag
00457                 {
00458                   int dp=0;
00459                   in.read (buf, LIBMESH_SIZEOF_INT);
00460                   std::memcpy (&dp, buf, LIBMESH_SIZEOF_INT);
00461                   rb(dp);
00462 
00463                   zpack.push_back (dp);
00464                 }
00465 
00466                 // Will we specify the variable location?
00467                 {
00468                   int svl=0;
00469                   int  vl=0;
00470                   in.read (buf, LIBMESH_SIZEOF_INT);
00471                   std::memcpy  (&svl, buf, LIBMESH_SIZEOF_INT);
00472                   rb(svl);
00473 
00474                   if (svl)
00475                     for (unsigned int v=0; v<this->n_vars(); v++)
00476                       {
00477                         in.read (buf, LIBMESH_SIZEOF_INT);
00478                         std::memcpy  (&vl, buf, LIBMESH_SIZEOF_INT);
00479                         rb(vl);
00480                         libmesh_assert_equal_to (vl, 0); // Only know about node-based data
00481                                           // right now
00482                       }
00483 
00484                 }
00485 
00486                 // Get the number of user-defined face-neighbors
00487                 {
00488                   int fn=0;
00489                   in.read (buf, LIBMESH_SIZEOF_INT);
00490                   std::memcpy  (&fn, buf, LIBMESH_SIZEOF_INT);
00491                   rb(fn);
00492                 }
00493 
00494                 // Read in the block dimensions
00495                 {
00496                   if (ztype.back() != ORDERED)
00497                     {
00498                       int np=0, ne=0;
00499 
00500                       in.read (buf, LIBMESH_SIZEOF_INT);
00501                       std::memcpy  (&np, buf, LIBMESH_SIZEOF_INT);
00502                       rb(np);
00503 
00504                       in.read (buf, LIBMESH_SIZEOF_INT);
00505                       std::memcpy  (&ne, buf, LIBMESH_SIZEOF_INT);
00506                       rb(ne);
00507 
00508                       zimax.push_back (np);
00509                       zjmax.push_back (ne);
00510                       zjmax.push_back (0);
00511                     }
00512 
00513                   int
00514                     i_max=0,
00515                     j_max=0,
00516                     k_max=0;
00517 
00518                   in.read (buf, LIBMESH_SIZEOF_INT);
00519                   std::memcpy  (&i_max, buf, LIBMESH_SIZEOF_INT);
00520                   rb(i_max);
00521 
00522                   in.read (buf, LIBMESH_SIZEOF_INT);
00523                   std::memcpy  (&j_max, buf, LIBMESH_SIZEOF_INT);
00524                   rb(j_max);
00525 
00526                   in.read (buf, LIBMESH_SIZEOF_INT);
00527                   std::memcpy  (&k_max, buf, LIBMESH_SIZEOF_INT);
00528                   rb(k_max);
00529 
00530                   // These are only useful for orderd data.  Otherwise
00531                   // we grabbed the relevant values above.
00532                   if (ztype.back() != ORDERED)
00533                     {
00534                       zimax.push_back (i_max);
00535                       zjmax.push_back (j_max);
00536                       zkmax.push_back (k_max);
00537                     }
00538                 }
00539               } // else if (f == 299.)
00540           }
00541         while ((f != 357.) && in.good());
00542       }
00543 
00544       // Set the header data
00545       this->set_n_zones (nz);
00546 
00547       for (unsigned int z=0; z<this->n_zones(); z++)
00548         {
00549           this->zone_type(z) = ztype[z];
00550           this->zone_name(z) = zname[z];
00551           this->zone_pack(z) = zpack[z];
00552           this->imax(z)      = zimax[z];
00553           this->jmax(z)      = zjmax[z];
00554           this->kmax(z)      = zkmax[z];
00555         }
00556     }
00557 
00558 
00559 
00560   //----------------------------------------------------
00561   // Unrecognized Tecplot Version!
00562   else
00563     {
00564       libMesh::err << "ERROR:  This plot file was written by an unrecognized version of Tecplot!:"
00565                     << std::endl
00566                     << this->version()
00567                     << std::endl;
00568       libmesh_error();
00569     }
00570 
00571 
00572 
00573 
00574 
00575 
00576 
00577 
00578   // Print the data to the screen.
00579   if (this->verbose())
00580     {
00581       libMesh::out << "Tecplot Header: "
00582                     << this->title() << std::endl;
00583 
00584       libMesh::out << "Variables: ";
00585       for (unsigned int v=0; v<this->n_vars(); v++)
00586         libMesh::out << "\"" << this->var_name (v) << "\"" << " ";
00587       libMesh::out << std::endl;
00588 
00589       libMesh::out << "Variable Types: ";
00590       for (unsigned int v=0; v<this->n_vars(); v++)
00591         libMesh::out << this->var_type (v) << " ";
00592       libMesh::out << std::endl;
00593 
00594       libMesh::out << "Zone Names: ";
00595       for (unsigned int z=0; z<this->n_zones(); z++)
00596         libMesh::out << "\"" << this->zone_name (z) << "\"" << " ";
00597       libMesh::out << std::endl;
00598 
00599       libMesh::out << "Zone Types: ";
00600       for (unsigned int z=0; z<this->n_zones(); z++)
00601         {
00602           libMesh::out << this->zone_type (z) << " ";
00603 
00604           if (this->zone_type (z) != ORDERED)
00605             libMesh::out << "(" << this->n_nodes(z) << "," << this->n_elem(z) << ") ";
00606         }
00607       libMesh::out << std::endl;
00608 
00609       libMesh::out << "Zone Dimensions: " << std::endl;
00610       for (unsigned int z=0; z<this->n_zones(); z++)
00611         libMesh::out << "  ("
00612                   << this->imax(z) << ","
00613                   << this->jmax(z) << ","
00614                   << this->kmax(z) << ")"
00615                   << std::endl;
00616     }
00617 }

void libMesh::PltLoader::read_point_data ( std::istream &  in,
const unsigned int  zn 
) [private]

Read data for the zth zone in POINT structured format.

Definition at line 946 of file plt_loader_read.C.

References _data, buf, data, DOUBLE, libMesh::err, FLOAT, imax(), is_foreign(), jmax(), kmax(), n_vars(), and var_type().

Referenced by read_data().

00947 {
00948   libmesh_assert (in.good());
00949 
00950   // A byte-reverser in case the data is foreign
00951   Utility::ReverseBytes rb(this->is_foreign());
00952 
00953   // First allocate space
00954   for (unsigned int var=0; var<this->n_vars(); var++)
00955     {
00956       std::vector<float> & data = _data[zone][var];
00957 
00958       data.clear();
00959       data.reserve (this->imax(zone)*
00960                     this->jmax(zone)*
00961                     this->kmax(zone));
00962     }
00963 
00964 
00965   for (unsigned int k=0; k<this->kmax(zone); k++)
00966     for (unsigned int j=0; j<this->jmax(zone); j++)
00967       for (unsigned int i=0; i<this->imax(zone); i++)
00968         for (unsigned int var=0; var<this->n_vars(); var++)
00969           if (this->var_type(var) == FLOAT)
00970             {
00971               float f = 0.;
00972 
00973               libmesh_assert (in.good());
00974 
00975               in.read (buf, LIBMESH_SIZEOF_FLOAT);
00976               std::memcpy  (&f, buf, LIBMESH_SIZEOF_FLOAT);
00977               rb(f);
00978 
00979               _data[zone][var].push_back(f);
00980             }
00981           else if (this->var_type(var) == DOUBLE)
00982             {
00983               double d = 0.;
00984 
00985               libmesh_assert (in.good());
00986 
00987               in.read (buf, LIBMESH_SIZEOF_DOUBLE);
00988               std::memcpy  (&d, buf, LIBMESH_SIZEOF_DOUBLE);
00989               rb(d);
00990 
00991               _data[zone][var].push_back(d);
00992             }
00993           else
00994             {
00995               libMesh::err << "ERROR: unsupported data type: "
00996                             << this->var_type(var)
00997                             << std::endl;
00998               libmesh_error();
00999             }
01000 }

void libMesh::PltLoader::set_n_vars ( const unsigned int  nv  )  [private]
Returns:
the number of variables in the data set.

Definition at line 60 of file plt_loader.C.

References _data, _n_vars, _var_names, _var_types, n_vars(), and n_zones().

Referenced by read_header().

00061 {
00062   _n_vars = nv;
00063 
00064   _var_types.resize (this->n_vars());
00065   _var_names.resize (this->n_vars());
00066 
00067   // Default to float data
00068   std::fill (_var_types.begin(), _var_types.end(), 1);
00069 
00070   // If the number of zones is set, resize the data.
00071   if (this->n_zones())
00072     {
00073       _data.resize  (this->n_zones());
00074 
00075       for (unsigned int z=0; z<this->n_zones(); z++)
00076         _data[z].resize  (this->n_vars());
00077     }
00078 }

void libMesh::PltLoader::set_n_zones ( const unsigned int  nz  )  [private]
Returns:
the number of zones.

Definition at line 82 of file plt_loader.C.

References _conn, _data, _imax, _jmax, _kmax, _n_zones, _zone_names, _zone_pack, _zone_types, n_vars(), and n_zones().

Referenced by read_header().

00083 {
00084   _n_zones = nz;
00085 
00086   _zone_types.resize (this->n_zones());
00087   _zone_names.resize (this->n_zones());
00088   _zone_pack.resize  (this->n_zones());
00089 
00090   _imax.resize (this->n_zones());
00091   _jmax.resize (this->n_zones());
00092   _kmax.resize (this->n_zones());
00093 
00094   _data.resize (this->n_zones());
00095   _conn.resize        (this->n_zones());
00096 
00097   // If the number of variables are set, resize the data.
00098   if (this->n_vars())
00099     for (unsigned int z=0; z<this->n_zones(); z++)
00100       _data[z].resize (this->n_vars());
00101 }

std::string& libMesh::PltLoader::title (  )  [inline, private]
Returns:
the data set title

Definition at line 305 of file plt_loader.h.

References _title.

00305 { return _title; }

const std::string& libMesh::PltLoader::title (  )  const [inline]
Returns:
the data set title

Definition at line 173 of file plt_loader.h.

References _title.

Referenced by read_header(), and write_dat().

00173 { return _title; }

std::string & libMesh::PltLoader::var_name ( const unsigned int  v  )  [inline, private]
Returns:
the name of variable v.

Definition at line 489 of file plt_loader.h.

References _var_names, and n_vars().

00490 {
00491   libmesh_assert_less (v, this->n_vars());
00492   libmesh_assert_less (v, _var_names.size());
00493   libmesh_assert_equal_to (this->n_vars(), _var_names.size());
00494 
00495   return _var_names[v];
00496 }

const std::string & libMesh::PltLoader::var_name ( const unsigned int  v  )  const [inline]
Returns:
the name of variable v.

Definition at line 477 of file plt_loader.h.

References _var_names, and n_vars().

Referenced by read_header(), and write_dat().

00478 {
00479   libmesh_assert_less (v, this->n_vars());
00480   libmesh_assert_less (v, _var_names.size());
00481   libmesh_assert_equal_to (this->n_vars(), _var_names.size());
00482 
00483   return _var_names[v];
00484 }

unsigned int & libMesh::PltLoader::var_type ( const unsigned int  v  )  [inline, private]
Returns:
the type of variable v

Definition at line 513 of file plt_loader.h.

References _var_types, and n_vars().

00514 {
00515   libmesh_assert_less (v, this->n_vars());
00516   libmesh_assert_less (v, _var_types.size());
00517   libmesh_assert_equal_to (this->n_vars(), _var_types.size());
00518 
00519   return _var_types[v];
00520 }

unsigned int libMesh::PltLoader::var_type ( const unsigned int  v  )  const [inline]
Returns:
the type of variable v

Definition at line 501 of file plt_loader.h.

References _var_types, and n_vars().

Referenced by read_block_data(), read_data(), read_feblock_data(), read_fepoint_data(), read_header(), and read_point_data().

00502 {
00503   libmesh_assert_less (v, this->n_vars());
00504   libmesh_assert_less (v, _var_types.size());
00505   libmesh_assert_equal_to (this->n_vars(), _var_types.size());
00506 
00507   return _var_types[v];
00508 }

bool libMesh::PltLoader::verbose (  )  const [inline]

Returns the verbosity.

Definition at line 68 of file plt_loader.h.

References _verbose.

Referenced by read(), read_data(), and read_header().

00068 { return _verbose; }

std::string& libMesh::PltLoader::version (  )  [inline, private]
Returns:
the Tecplot version number string.

Definition at line 293 of file plt_loader.h.

References _version.

00293 { return _version; }

const std::string& libMesh::PltLoader::version (  )  const [inline]
Returns:
the Tecplot version number string. This identifies the version of Tecplot (or preplot) that wrote the binary file. Currently, PltLoader understands versions "#!TDV7X " and "#!TDV1XX"

Definition at line 161 of file plt_loader.h.

References _version.

Referenced by read_data(), and read_header().

00161 { return _version; }

void libMesh::PltLoader::write_dat ( const std::string &  name,
const unsigned int  version = 10 
) const

Writes an ASCII Tecplot file. The optional parameter version specifies the version format to write.

Definition at line 450 of file plt_loader_write.C.

References _data, BLOCK, libMesh::err, imax(), jmax(), kmax(), n_vars(), n_zones(), POINT, title(), var_name(), zone_name(), and zone_type().

00452 {
00453   std::ofstream out_stream (name.c_str());
00454 
00455   out_stream << "TITLE=\""
00456       << this->title()
00457       << "\""
00458       << '\n';
00459 
00460   out_stream << "VARIABLES = ";
00461 
00462   for (unsigned int v=0; v<this->n_vars(); v++)
00463     out_stream << "\"" << this->var_name(v) << "\"\n";
00464 
00465   for (unsigned int z=0; z<this->n_zones(); z++)
00466     {
00467       out_stream << "ZONE T=\"" << this->zone_name(z) << "\"\n";
00468       out_stream << " I="  << this->imax(z)
00469           << ", J=" << this->jmax(z)
00470           << ", K=" << this->kmax(z);
00471 
00472       // Write BLOCK data for this zone
00473       if (this->zone_type(z) == BLOCK)
00474         {
00475           if (version_in < 10)
00476             {
00477               out_stream << ", F=BLOCK\n";
00478             }
00479           else
00480             {
00481               out_stream << ", ZONETYPE=Ordered\n"
00482                   << "DATAPACKING=BLOCK\n";
00483             }
00484 
00485           out_stream << "DT=(";
00486           for (unsigned int v=0; v<this->n_vars(); v++)
00487             out_stream << "SINGLE ";
00488           out_stream << ")\n";
00489 
00490           out_stream.precision(9);
00491 
00492           for (unsigned int v=0; v<this->n_vars(); v++)
00493             {
00494               unsigned int l=0;
00495 
00496               for (unsigned int k=0; k<this->kmax(z); k++)
00497                 for (unsigned int j=0; j<this->jmax(z); j++)
00498                   for (unsigned int i=0; i<this->imax(z); i++)
00499                     {
00500                       // GCC 2.95.3 has scientific in the ios class instead
00501                       // of in namespace std::
00502 #ifndef LIBMESH_BROKEN_IOSTREAM
00503                       out_stream << std::scientific
00504                           << _data[z][v][l++] << " ";
00505 #else
00506                       out_stream << std::ios::scientific
00507                           << _data[z][v][l++] << " ";
00508 #endif
00509                       // Throw in a newline every 5 entries to
00510                       // avoid really long lines.
00511                       if (l%5 == 0)
00512                         out_stream << '\n';
00513                     }
00514 
00515               if (l%5 != 0)
00516                 out_stream << '\n';
00517             }
00518         } // end if (this->zone_type(z) == BLOCK)
00519 
00520       // Write POINT data for this zone
00521       else if (this->zone_type(z) == POINT)
00522         {
00523           if (version_in < 10)
00524             {
00525               out_stream << ", F=POINT\n";
00526             }
00527           else
00528             {
00529               out_stream << ", ZONETYPE=Ordered\n"
00530                   << "DATAPACKING=POINT\n";
00531             }
00532 
00533           out_stream << "DT=(";
00534           for (unsigned int v=0; v<this->n_vars(); v++)
00535             out_stream << "SINGLE ";
00536           out_stream << ")\n";
00537 
00538           out_stream.precision(9);
00539 
00540           {
00541             unsigned int l=0;
00542 
00543             for (unsigned int k=0; k<this->kmax(z); k++)
00544               for (unsigned int j=0; j<this->jmax(z); j++)
00545                 for (unsigned int i=0; i<this->imax(z); i++)
00546                   {
00547                     for (unsigned int v=0; v<this->n_vars(); v++)
00548 
00549                       // GCC 2.95.3 has scientific in the ios class instead
00550                       // of in namespace std::
00551 #ifndef LIBMESH_BROKEN_IOSTREAM
00552                       out_stream << std::scientific
00553                           << _data[z][v][l] << " ";
00554 #else
00555                       out_stream << std::ios::scientific
00556                           << _data[z][v][l] << " ";
00557 #endif
00558                     out_stream << '\n';
00559 
00560                     l++;
00561                   }
00562           }
00563         } // end else if (this->zone_type(z) == POINT)
00564 
00565       // Otherwise, unrecognized zone type
00566       else
00567         {
00568           libMesh::err << "Unrecognized zone type: ";
00569           libMesh::err << "this->zone_type(z)==" << this->zone_type(z) << std::endl;
00570           libmesh_error();
00571         }
00572     }
00573 }

std::string & libMesh::PltLoader::zone_name ( const unsigned int  z  )  [inline, private]
Returns:
the name of zone z.

Definition at line 561 of file plt_loader.h.

References _zone_names, and n_zones().

00562 {
00563   libmesh_assert_less (z, this->n_zones());
00564   libmesh_assert_less (z, _zone_names.size());
00565   libmesh_assert_equal_to (this->n_zones(), _zone_names.size());
00566 
00567   return _zone_names[z];
00568 }

const std::string & libMesh::PltLoader::zone_name ( const unsigned int  z  )  const [inline]
Returns:
the name of zone z.

Definition at line 549 of file plt_loader.h.

References _zone_names, and n_zones().

Referenced by read_header(), and write_dat().

00550 {
00551   libmesh_assert_less (z, this->n_zones());
00552   libmesh_assert_less (z, _zone_names.size());
00553   libmesh_assert_equal_to (this->n_zones(), _zone_names.size());
00554 
00555   return _zone_names[z];
00556 }

unsigned int & libMesh::PltLoader::zone_pack ( const unsigned int  z  )  [inline, private]
Returns:
the data pack flag for zone z.

Definition at line 585 of file plt_loader.h.

References _zone_pack, and n_zones().

00586 {
00587   libmesh_assert_less (z, this->n_zones());
00588   libmesh_assert_less (z, _zone_pack.size());
00589   libmesh_assert_equal_to (this->n_zones(), _zone_pack.size());
00590 
00591   return _zone_pack[z];
00592 }

unsigned int libMesh::PltLoader::zone_pack ( const unsigned int  z  )  const [inline]
Returns:
the data packing flag for zone z.

Definition at line 573 of file plt_loader.h.

References _zone_pack, and n_zones().

Referenced by read_data(), and read_header().

00574 {
00575   libmesh_assert_less (z, this->n_zones());
00576   libmesh_assert_less (z, _zone_pack.size());
00577   libmesh_assert_equal_to (this->n_zones(), _zone_pack.size());
00578 
00579   return _zone_pack[z];
00580 }

unsigned int & libMesh::PltLoader::zone_type ( const unsigned int  z  )  [inline, private]
Returns:
the type of zone z

Definition at line 537 of file plt_loader.h.

References _zone_types, and n_zones().

00538 {
00539   libmesh_assert_less (z, this->n_zones());
00540   libmesh_assert_less (z, _zone_types.size());
00541   libmesh_assert_equal_to (this->n_zones(), _zone_types.size());
00542 
00543   return _zone_types[z];
00544 }

unsigned int libMesh::PltLoader::zone_type ( const unsigned int  z  )  const [inline]
Returns:
the type of zone z

Definition at line 525 of file plt_loader.h.

References _zone_types, and n_zones().

Referenced by elem_type(), n_elem(), n_nodes(), read_data(), read_header(), and write_dat().

00526 {
00527   libmesh_assert_less (z, this->n_zones());
00528   libmesh_assert_less (z, _zone_types.size());
00529   libmesh_assert_equal_to (this->n_zones(), _zone_types.size());
00530 
00531   return _zone_types[z];
00532 }


Member Data Documentation

std::vector<std::vector<int> > libMesh::PltLoader::_conn [private]

Vectors to hold the connectivity for each zone (only for unstructured files).

Definition at line 434 of file plt_loader.h.

Referenced by clear(), read_feblock_data(), read_fepoint_data(), and set_n_zones().

std::vector<std::vector<std::vector<float> > > libMesh::PltLoader::_data [private]
std::vector<unsigned int> libMesh::PltLoader::_imax [private]

The (imax,jmax,kmax) value for each zone.

Definition at line 421 of file plt_loader.h.

Referenced by clear(), imax(), and set_n_zones().

Is the data foreign?

Definition at line 375 of file plt_loader.h.

Referenced by clear(), and is_foreign().

std::vector<unsigned int> libMesh::PltLoader::_jmax [private]

Definition at line 422 of file plt_loader.h.

Referenced by clear(), jmax(), and set_n_zones().

std::vector<unsigned int> libMesh::PltLoader::_kmax [private]

Definition at line 423 of file plt_loader.h.

Referenced by clear(), kmax(), and set_n_zones().

unsigned int libMesh::PltLoader::_n_vars [private]

The number of variables in the data set.

Definition at line 385 of file plt_loader.h.

Referenced by clear(), n_vars(), and set_n_vars().

unsigned int libMesh::PltLoader::_n_zones [private]

The number of zones.

Definition at line 401 of file plt_loader.h.

Referenced by clear(), n_zones(), and set_n_zones().

std::string libMesh::PltLoader::_title [private]

The Tecplot data set title.

Definition at line 380 of file plt_loader.h.

Referenced by clear(), and title().

std::vector<std::string> libMesh::PltLoader::_var_names [private]

The name for each variable.

Definition at line 390 of file plt_loader.h.

Referenced by clear(), set_n_vars(), and var_name().

std::vector<unsigned int> libMesh::PltLoader::_var_types [private]

The type of each variable. Must be one of the enumerated DataType types.

Definition at line 396 of file plt_loader.h.

Referenced by clear(), set_n_vars(), and var_type().

const bool libMesh::PltLoader::_verbose [private]

Verbosity

Definition at line 365 of file plt_loader.h.

Referenced by verbose().

std::string libMesh::PltLoader::_version [private]

The Tecplot Version number string.

Definition at line 370 of file plt_loader.h.

Referenced by clear(), and version().

std::vector<std::string> libMesh::PltLoader::_zone_names [private]

The name of each zone.

Definition at line 411 of file plt_loader.h.

Referenced by clear(), set_n_zones(), and zone_name().

std::vector<unsigned int> libMesh::PltLoader::_zone_pack [private]

The data packing for each zone (new version only)

Definition at line 416 of file plt_loader.h.

Referenced by clear(), set_n_zones(), and zone_pack().

std::vector<unsigned int> libMesh::PltLoader::_zone_types [private]

The type of each zone.

Definition at line 406 of file plt_loader.h.

Referenced by clear(), set_n_zones(), and zone_type().

char libMesh::PltLoader::buf[512] [mutable, private]

Scratch data & relevant sizes.

Definition at line 439 of file plt_loader.h.

Referenced by read_data(), read_fepoint_data(), read_header(), and read_point_data().

const unsigned int libMesh::PltLoader::NNodes = {3, 4, 4, 8} [static]

Enum defining the number of nodes for each element type.

Definition at line 248 of file plt_loader.h.

Referenced by read_feblock_data(), and read_fepoint_data().


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

Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:34 UTC

Hosted By:
SourceForge.net Logo