libMesh::PltLoader Class Reference

#include <plt_loader.h>

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
Date
2004

Definition at line 42 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 135 of file plt_loader.h.

Enum defining the finite element types

Enumerator
TRI 
QUAD 
TET 
HEX 

Definition at line 145 of file plt_loader.h.

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 125 of file plt_loader.h.

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 116 of file plt_loader.h.

Constructor & Destructor Documentation

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

Constructor. Initializes data.

Definition at line 448 of file plt_loader.h.

448  :
449  _verbose (v),
450  _is_foreign (false),
451  _n_vars (0),
452  _n_zones (0)
453 {
454 }
const bool _verbose
Definition: plt_loader.h:366
unsigned int _n_vars
Definition: plt_loader.h:386
unsigned int _n_zones
Definition: plt_loader.h:402
libMesh::PltLoader::PltLoader ( const std::string &  name,
const bool  v = false 
)
inline

Constructor. Reads the file specified by name.

Definition at line 459 of file plt_loader.h.

References read().

459  :
460  _verbose (v),
461  _is_foreign (false),
462  _n_vars (0),
463  _n_zones (0)
464 {
465  this->read (name);
466 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
const bool _verbose
Definition: plt_loader.h:366
void read(const std::string &name)
unsigned int _n_vars
Definition: plt_loader.h:386
unsigned int _n_zones
Definition: plt_loader.h:402
libMesh::PltLoader::~PltLoader ( )
inline

Destructor.

Definition at line 471 of file plt_loader.h.

472 {
473 }

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.

35 {
36  // clear vectors & strings. Using .erase() for strings instead of .clear()
37  // since GCC 2.95.3 does not support .clear().
38  _version.erase();
39  _title.erase();
40 
41  _var_names.clear();
42  _var_types.clear();
43  _zone_types.clear();
44  _zone_names.clear();
45  _zone_pack.clear();
46  _imax.clear();
47  _jmax.clear();
48  _kmax.clear();
49  _data.clear();
50  _conn.clear();
51 
52  // reinitialize
53  _is_foreign = false;
54  _n_vars = 0;
55  _n_zones = 0;
56 }
std::vector< std::vector< int > > _conn
Definition: plt_loader.h:435
std::vector< std::string > _zone_names
Definition: plt_loader.h:412
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:429
std::vector< unsigned int > _zone_pack
Definition: plt_loader.h:417
std::vector< unsigned int > _kmax
Definition: plt_loader.h:424
std::vector< unsigned int > _var_types
Definition: plt_loader.h:397
std::vector< unsigned int > _zone_types
Definition: plt_loader.h:407
std::vector< unsigned int > _jmax
Definition: plt_loader.h:423
std::vector< unsigned int > _imax
Definition: plt_loader.h:422
std::vector< std::string > _var_names
Definition: plt_loader.h:391
std::string _title
Definition: plt_loader.h:381
unsigned int _n_vars
Definition: plt_loader.h:386
std::string _version
Definition: plt_loader.h:371
unsigned int _n_zones
Definition: plt_loader.h:402
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 690 of file plt_loader.h.

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

Referenced by n_zones().

691 {
692  libmesh_assert_less (z, this->n_zones());
693 
694  // Only for unstructured zones!
695  libmesh_assert_greater (this->zone_type(z), 1);
696 
697  return static_cast<FEType>(this->kmax(z));
698 }
unsigned int zone_type(const unsigned int z) const
Definition: plt_loader.h:526
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int kmax(const unsigned int z) const
Definition: plt_loader.h:642
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 703 of file plt_loader.h.

References _data.

Referenced by n_zones().

704 {
705  return _data;
706 }
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:429
unsigned int libMesh::PltLoader::imax ( const unsigned int  z) const
inline
Returns
imax for zone z.

Definition at line 598 of file plt_loader.h.

References _imax, and n_zones().

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

599 {
600  libmesh_assert_less (z, this->n_zones());
601  libmesh_assert_equal_to (_imax.size(), this->n_zones());
602 
603  return _imax[z];
604 }
std::vector< unsigned int > _imax
Definition: plt_loader.h:422
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int & libMesh::PltLoader::imax ( const unsigned int  z)
inlineprivate
Returns
imax for zone z.

Definition at line 609 of file plt_loader.h.

References _imax, and n_zones().

610 {
611  libmesh_assert_less (z, this->n_zones());
612  libmesh_assert_equal_to (_imax.size(), this->n_zones());
613 
614  return _imax[z];
615 }
std::vector< unsigned int > _imax
Definition: plt_loader.h:422
unsigned int n_zones() const
Definition: plt_loader.h:194
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 169 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().

169 { return _is_foreign; }
bool& libMesh::PltLoader::is_foreign ( )
inlineprivate
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 301 of file plt_loader.h.

References _is_foreign.

301 { return _is_foreign; }
unsigned int libMesh::PltLoader::jmax ( const unsigned int  z) const
inline
Returns
jmax for zone z.

Definition at line 620 of file plt_loader.h.

References _jmax, and n_zones().

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

621 {
622  libmesh_assert_less (z, this->n_zones());
623  libmesh_assert_equal_to (_jmax.size(), this->n_zones());
624 
625  return _jmax[z];
626 }
std::vector< unsigned int > _jmax
Definition: plt_loader.h:423
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int & libMesh::PltLoader::jmax ( const unsigned int  z)
inlineprivate
Returns
jmax for zone z.

Definition at line 631 of file plt_loader.h.

References _jmax, and n_zones().

632 {
633  libmesh_assert_less (z, this->n_zones());
634  libmesh_assert_equal_to (_jmax.size(), this->n_zones());
635 
636  return _jmax[z];
637 }
std::vector< unsigned int > _jmax
Definition: plt_loader.h:423
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int libMesh::PltLoader::kmax ( const unsigned int  z) const
inline
Returns
kmax for zone z.

Definition at line 642 of file plt_loader.h.

References _kmax, and n_zones().

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

643 {
644  libmesh_assert_less (z, this->n_zones());
645  libmesh_assert_equal_to (_kmax.size(), this->n_zones());
646 
647  return _kmax[z];
648 }
std::vector< unsigned int > _kmax
Definition: plt_loader.h:424
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int & libMesh::PltLoader::kmax ( const unsigned int  z)
inlineprivate
Returns
kmax for zone z.

Definition at line 653 of file plt_loader.h.

References _kmax, and n_zones().

654 {
655  libmesh_assert_less (z, this->n_zones());
656  libmesh_assert_equal_to (_kmax.size(), this->n_zones());
657 
658  return _kmax[z];
659 }
std::vector< unsigned int > _kmax
Definition: plt_loader.h:424
unsigned int n_zones() const
Definition: plt_loader.h:194
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 677 of file plt_loader.h.

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

Referenced by n_zones(), and read_header().

678 {
679  libmesh_assert_less (z, this->n_zones());
680 
681  // Only for unstructured zones!
682  libmesh_assert_greater (this->zone_type(z), 1);
683 
684  return this->jmax(z);
685 }
unsigned int jmax(const unsigned int z) const
Definition: plt_loader.h:620
unsigned int zone_type(const unsigned int z) const
Definition: plt_loader.h:526
unsigned int n_zones() const
Definition: plt_loader.h:194
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 664 of file plt_loader.h.

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

Referenced by n_zones(), and read_header().

665 {
666  libmesh_assert_less (z, this->n_zones());
667 
668  // Only for unstructured zones!
669  libmesh_assert_greater (this->zone_type(z), 1);
670 
671  return this->imax(z);
672 }
unsigned int imax(const unsigned int z) const
Definition: plt_loader.h:598
unsigned int zone_type(const unsigned int z) const
Definition: plt_loader.h:526
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int libMesh::PltLoader::n_vars ( ) const
inline
Returns
the number of variables in the data set.

Definition at line 179 of file plt_loader.h.

References _n_vars, var_name(), and var_type().

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().

179 { return _n_vars; }
unsigned int _n_vars
Definition: plt_loader.h:386
unsigned int libMesh::PltLoader::n_zones ( ) const
inline
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::out, read_data(), read_header(), and verbose().

Referenced by PltLoader(), and verbose().

35 {
36  std::ifstream in (name.c_str(), std::ios::in|std::ios::binary);
37 
38  if (!in.good())
39  libmesh_error_msg("Error reading input file " << name);
40 
41 
42  if (this->verbose())
43  libMesh::out << std::endl
44  << "Reading input file " << name
45  << std::endl
46  << "-------------------------------------------------------------------------"
47  << std::endl;
48 
49  this->read_header (in);
50  this->read_data (in);
51 
52  if (this->verbose())
53  libMesh::out << std::endl
54  << "-------------------------------------------------------------------------"
55  << std::endl;
56 
57 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
bool verbose() const
Definition: plt_loader.h:69
void read_header(std::istream &in)
OStreamProxy out(std::cout)
void read_data(std::istream &in)
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 833 of file plt_loader_read.C.

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

Referenced by read_data().

834 {
835  libmesh_assert (in.good());
836 
837 
838  // A byte-reverser in case the data is foreign
839  Utility::ReverseBytes rb(this->is_foreign());
840 
841 
842  for (unsigned int var=0; var<this->n_vars(); var++)
843  {
844 
845  switch (this->var_type(var))
846  {
847 
848  // Read a single-precision variable
849  case FLOAT:
850  {
851  std::vector<float> & data = _data[zone][var];
852 
853  data.clear();
854  data.resize (this->imax(zone)*
855  this->jmax(zone)*
856  this->kmax(zone));
857 
858  in.read ((char *) &data[0], LIBMESH_SIZEOF_FLOAT*data.size());
859 
860  for (std::size_t i=0; i<data.size(); i++)
861  rb(data[i]);
862 
863  break;
864  }
865 
866  // Read a double-precision variable
867  case DOUBLE:
868  {
869  std::vector<double> ddata;
870  std::vector<float> & data = _data[zone][var];
871 
872  data.clear();
873  data.resize (this->imax(zone)*
874  this->jmax(zone)*
875  this->kmax(zone));
876 
877  ddata.resize (this->imax(zone)*
878  this->jmax(zone)*
879  this->kmax(zone));
880 
881  in.read ((char *) &ddata[0], LIBMESH_SIZEOF_DOUBLE*ddata.size());
882 
883  for (std::size_t i=0; i<data.size(); i++)
884  data[i] = rb(ddata[i]);
885 
886  break;
887  }
888 
889  default:
890  libmesh_error_msg("ERROR: Unsupported data type: " << this->var_type(var));
891  }
892  }
893 }
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:429
unsigned int n_vars() const
Definition: plt_loader.h:179
unsigned int imax(const unsigned int z) const
Definition: plt_loader.h:598
unsigned int var_type(const unsigned int v) const
Definition: plt_loader.h:502
libmesh_assert(j)
unsigned int jmax(const unsigned int z) const
Definition: plt_loader.h:620
IterBase * data
unsigned int kmax(const unsigned int z) const
Definition: plt_loader.h:642
bool is_foreign() const
Definition: plt_loader.h:169
void libMesh::PltLoader::read_data ( std::istream &  in)
private

Read data from the binary file.

Definition at line 602 of file plt_loader_read.C.

References BLOCK, buf, FEBLOCK, FEPOINT, libMesh::BasicOStreamProxy< charT, traits >::flush(), imax(), is_foreign(), jmax(), kmax(), libMesh::libmesh_assert(), 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().

603 {
604  libmesh_assert (in.good());
605 
606  // A byte-reverser in case the data is foreign
607  Utility::ReverseBytes rb(this->is_foreign());
608 
609  //----------------------------------------------------
610  // Read the TECPLOT data for each zone
611  if (this->verbose())
612  {
613  libMesh::out << "Reading Zones";
615  }
616 
617 
618  for (unsigned int zone=0; zone<this->n_zones(); zone++)
619  {
620  if (this->verbose())
621  {
622  libMesh::out << ".";
624  }
625 
626 
627  //----------------------------------------------------
628  // Read plt files written by older versions of Tecplot
629  if (this->version().rfind("V7") < this->version().size())
630  {
631  float f = 0.;
632 
633  // Find the next Zone marker.
634  do
635  {
636  f = 0.;
637  in.read (buf, LIBMESH_SIZEOF_FLOAT);
638  std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT);
639  rb(f);
640  }
641  while ((f != 299.) && in.good());
642 
643  // Did we overrun the file?
644  if (!in.good())
645  libmesh_error_msg("ERROR: Unexpected end-of-file!");
646 
647  // Get the number of repeated vars.
648  unsigned int n_rep_vars=0;
649  std::vector<int> rep_vars;
650 
651  {
652  in.read (buf, LIBMESH_SIZEOF_INT);
653  std::memcpy (&n_rep_vars, buf, LIBMESH_SIZEOF_INT);
654  rb(n_rep_vars);
655 
656  rep_vars.resize (n_rep_vars);
657 
658  // Get the repeated variables number.
659  for (unsigned int v=0; v<n_rep_vars; v++)
660  {
661  libmesh_error_msg("ERROR: I don't understand repeated variables yet!");
662 
663  in.read (buf, LIBMESH_SIZEOF_INT);
664  std::memcpy (&rep_vars[v], buf, LIBMESH_SIZEOF_INT);
665  rb(rep_vars[v]);
666  }
667  }
668 
669  // Get the variable data type
670  //libMesh::out << "var_types=";
671  for (unsigned int v=0; v<this->n_vars(); v++)
672  {
673  in.read (buf, LIBMESH_SIZEOF_INT);
674  std::memcpy (&this->var_type(v), buf, LIBMESH_SIZEOF_INT);
675  rb(this->var_type(v));
676 
677  //libMesh::out << this->var_type(v) << " ";
678  }
679  //libMesh::out << std::endl;
680 
681 
682 
683  // Read the data.
684  switch (this->zone_type(zone) )
685  {
686  // Block-based data. Structured meshes.
687  case BLOCK:
688  {
689  this->read_block_data (in, zone);
690  break;
691  }
692 
693  // Point-based data. Structured meshes.
694  case POINT:
695  {
696  this->read_point_data (in, zone);
697  break;
698  }
699 
700  // FE block data. Unstructured meshes.
701  case FEBLOCK:
702  {
703  this->read_feblock_data (in, zone);
704 
705  if (this->verbose())
706 
707  libMesh::out << "Zone " << zone << ":" << std::endl
708  << " nnodes =" << this->imax(zone) << std::endl
709  << " nelem =" << this->jmax(zone) << std::endl
710  << " elem_type=" << this->kmax(zone) << std::endl
711  << std::endl;
712  break;
713  }
714 
715  // FE point data. Unstructured meshes.
716  case FEPOINT:
717  {
718  this->read_fepoint_data (in, zone);
719  break;
720  }
721 
722  default:
723  libmesh_error_msg("ERROR: Unsupported Zone type: " << this->zone_type(zone));
724  } // end switch on zone type
725  }
726 
727 
728  //----------------------------------------------------
729  // Read plt files written by newer versions of Tecplot
730  else if (this->version().rfind("V1") < this->version().size())
731  {
732  float f = 0.;
733 
734  // Find the next Zone marker.
735  do
736  {
737  f = 0.;
738  in.read (buf, LIBMESH_SIZEOF_FLOAT);
739  std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT);
740  rb(f);
741  }
742  while ((f != 299.) && in.good());
743 
744  // Did we overrun the file?
745  if (!in.good())
746  libmesh_error_msg("ERROR: Unexpected end-of-file!");
747 
748  // Get the variable data type
749  for (unsigned int v=0; v<this->n_vars(); v++)
750  {
751  in.read (buf, LIBMESH_SIZEOF_INT);
752  std::memcpy (&this->var_type(v), buf, LIBMESH_SIZEOF_INT);
753  rb(this->var_type(v));
754 
755  //libMesh::out << this->var_type(v) << " ";
756  }
757 
758  // Get the variable sharing flag
759  {
760  int vs=0;
761  int sv=0;
762 
763  in.read (buf, LIBMESH_SIZEOF_INT);
764  std::memcpy (&vs, buf, LIBMESH_SIZEOF_INT);
765  rb(vs);
766 
767  if (vs)
768  {
769  for (unsigned int v=0; v<this->n_vars(); v++)
770  {
771  in.read (buf, LIBMESH_SIZEOF_INT);
772  std::memcpy (&sv, buf, LIBMESH_SIZEOF_INT);
773  rb(sv);
774 
775  if (sv != -1)
776  libmesh_error_msg("ERROR: I don't understand variable sharing!");
777  }
778  }
779  }
780 
781  // Get zone to share connectivity with
782  {
783  int sc=0;
784  in.read (buf, LIBMESH_SIZEOF_INT);
785  std::memcpy (&sc, buf, LIBMESH_SIZEOF_INT);
786  rb(sc);
787 
788  libmesh_assert_equal_to (sc, -1);
789  }
790 
791 
792  // Read the data.
793  if (this->zone_type(zone) == ORDERED)
794  {
795  // Block-based data. Structured meshes.
796  if (this->zone_pack(zone) == 0)
797  this->read_block_data (in, zone);
798 
799  // Point-based data. Structured meshes.
800  else if (this->zone_pack(zone) == 1)
801  this->read_point_data (in, zone);
802 
803  else
804  libmesh_error_msg("Unrecognized zone_pack(zone) = " << this->zone_pack(zone));
805  }
806  else
807  {
808  // Block-based data. Unstructured meshes.
809  if (this->zone_pack(zone) == 0)
810  this->read_feblock_data (in, zone);
811 
812  // Point-based data. Unstructured meshes.
813  else if (this->zone_pack(zone) == 1)
814  this->read_fepoint_data (in, zone);
815 
816  else
817  libmesh_error_msg("Unrecognized zone_pack(zone) = " << this->zone_pack(zone));
818  }
819  }
820 
821 
822 
823  //----------------------------------------------------
824  // Unrecognized Tecplot Version!
825  else
826  libmesh_error_msg("ERROR: This plot file was written by an unrecognized version of Tecplot!:\n" << this->version());
827 
828  } // end loop on zones
829 }
unsigned int n_vars() const
Definition: plt_loader.h:179
void read_point_data(std::istream &in, const unsigned int zn)
unsigned int zone_pack(const unsigned int z) const
Definition: plt_loader.h:574
const std::string & version() const
Definition: plt_loader.h:162
unsigned int imax(const unsigned int z) const
Definition: plt_loader.h:598
unsigned int var_type(const unsigned int v) const
Definition: plt_loader.h:502
libmesh_assert(j)
bool verbose() const
Definition: plt_loader.h:69
unsigned int jmax(const unsigned int z) const
Definition: plt_loader.h:620
void read_fepoint_data(std::istream &in, const unsigned int zn)
BasicOStreamProxy & flush()
unsigned int zone_type(const unsigned int z) const
Definition: plt_loader.h:526
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int kmax(const unsigned int z) const
Definition: plt_loader.h:642
OStreamProxy out(std::cout)
void read_block_data(std::istream &in, const unsigned int zn)
void read_feblock_data(std::istream &in, const unsigned int zn)
bool is_foreign() const
Definition: plt_loader.h:169
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 950 of file plt_loader_read.C.

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

Referenced by read_data().

951 {
952  libmesh_assert (in.good());
953 
954  // A byte-reverser in case the data is foreign
955  Utility::ReverseBytes rb(this->is_foreign());
956 
957  // Read the variable values at each node.
958  for (unsigned int var=0; var<this->n_vars(); var++)
959  {
960  switch (this->var_type(var))
961  {
962 
963  // Read a single-precision variable
964  case FLOAT:
965  {
966  std::vector<float> & data = _data[zone][var];
967 
968  data.clear();
969  data.resize (this->imax(zone));
970 
971  in.read ((char *) &data[0], LIBMESH_SIZEOF_FLOAT*data.size());
972 
973  for (std::size_t i=0; i<data.size(); i++)
974  rb(data[i]);
975 
976  break;
977  }
978 
979  // Read a double-precision variable
980  case DOUBLE:
981  {
982  std::vector<double> ddata;
983  std::vector<float> & data = _data[zone][var];
984 
985  data.clear();
986  data.resize (this->imax(zone));
987  ddata.resize (this->imax(zone));
988 
989  in.read ((char *) &ddata[0], LIBMESH_SIZEOF_DOUBLE*ddata.size());
990 
991  for (std::size_t i=0; i<data.size(); i++)
992  data[i] = rb(ddata[i]);
993 
994  break;
995  }
996 
997  default:
998  libmesh_error_msg("ERROR: Unsupported data type: " << this->var_type(var));
999  }
1000  }
1001 
1002  // Read the connectivity
1003  {
1004  // Get the connectivity repetition flag
1005  int rep=0;
1006  in.read ((char *) &rep, LIBMESH_SIZEOF_INT);
1007  rb(rep);
1008 
1009  if (rep == 1 && this->n_zones() > 1)
1010  libmesh_error_msg("ERROR: Repeated connectivity not supported!");
1011 
1012  // Read the connectivity
1013  else
1014  {
1015  libmesh_assert_less (zone, _conn.size());
1016  libmesh_assert_less (this->kmax(zone), 4);
1017 
1018  _conn[zone].resize (this->jmax(zone)*NNodes[this->kmax(zone)]);
1019 
1020  in.read ((char *) &_conn[zone][0], LIBMESH_SIZEOF_INT*_conn[zone].size());
1021 
1022  for (std::size_t i=0; i<_conn[zone].size(); i++)
1023  rb(_conn[zone][i]);
1024  }
1025  }
1026 }
std::vector< std::vector< int > > _conn
Definition: plt_loader.h:435
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:429
unsigned int n_vars() const
Definition: plt_loader.h:179
unsigned int imax(const unsigned int z) const
Definition: plt_loader.h:598
unsigned int var_type(const unsigned int v) const
Definition: plt_loader.h:502
libmesh_assert(j)
static const unsigned int NNodes[4]
Definition: plt_loader.h:249
unsigned int jmax(const unsigned int z) const
Definition: plt_loader.h:620
unsigned int n_zones() const
Definition: plt_loader.h:194
IterBase * data
unsigned int kmax(const unsigned int z) const
Definition: plt_loader.h:642
bool is_foreign() const
Definition: plt_loader.h:169
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 1030 of file plt_loader_read.C.

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

Referenced by read_data().

1031 {
1032  libmesh_assert (in.good());
1033 
1034  // A byte-reverser in case the data is foreign
1035  Utility::ReverseBytes rb(this->is_foreign());
1036 
1037  // First allocate space
1038  for (unsigned int var=0; var<this->n_vars(); var++)
1039  {
1040  std::vector<float> & data = _data[zone][var];
1041 
1042  data.clear();
1043  data.reserve (this->imax(zone));
1044  }
1045 
1046 
1047  for (unsigned int i=0; i<this->imax(zone); i++)
1048  for (unsigned int var=0; var<this->n_vars(); var++)
1049  if (this->var_type(var) == FLOAT)
1050  {
1051  float f = 0.;
1052 
1053  libmesh_assert (in.good());
1054 
1055  in.read (buf, LIBMESH_SIZEOF_FLOAT);
1056  std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT);
1057  rb(f);
1058 
1059  _data[zone][var].push_back(f);
1060  }
1061  else if (this->var_type(var) == DOUBLE)
1062  {
1063  double d = 0.;
1064 
1065  libmesh_assert (in.good());
1066 
1067  in.read (buf, LIBMESH_SIZEOF_DOUBLE);
1068  std::memcpy (&d, buf, LIBMESH_SIZEOF_DOUBLE);
1069  rb(d);
1070 
1071  _data[zone][var].push_back(d);
1072  }
1073  else
1074  libmesh_error_msg("ERROR: unsupported data type: " << this->var_type(var));
1075 
1076  // Read the connectivity
1077  {
1078  // Get the connectivity repetition flag
1079  int rep=0;
1080 
1081  in.read ((char *) &rep, LIBMESH_SIZEOF_INT);
1082  rb(rep);
1083 
1084  if (rep == 1)
1085  libmesh_error_msg("ERROR: Repeated connectivity not supported!");
1086 
1087  // Read the connectivity
1088  else
1089  {
1090  libmesh_assert_less (zone, _conn.size());
1091  libmesh_assert_less (this->kmax(zone), 4);
1092 
1093  _conn[zone].resize (this->jmax(zone)*NNodes[this->kmax(zone)]);
1094 
1095  in.read ((char *) &_conn[zone][0], LIBMESH_SIZEOF_INT*_conn[zone].size());
1096 
1097  for (std::size_t i=0; i<_conn[zone].size(); i++)
1098  rb(_conn[zone][i]);
1099  }
1100  }
1101 }
std::vector< std::vector< int > > _conn
Definition: plt_loader.h:435
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:429
unsigned int n_vars() const
Definition: plt_loader.h:179
unsigned int imax(const unsigned int z) const
Definition: plt_loader.h:598
unsigned int var_type(const unsigned int v) const
Definition: plt_loader.h:502
libmesh_assert(j)
static const unsigned int NNodes[4]
Definition: plt_loader.h:249
unsigned int jmax(const unsigned int z) const
Definition: plt_loader.h:620
IterBase * data
unsigned int kmax(const unsigned int z) const
Definition: plt_loader.h:642
bool is_foreign() const
Definition: plt_loader.h:169
void libMesh::PltLoader::read_header ( std::istream &  in)
private

Read the header of the binary file.

Definition at line 61 of file plt_loader_read.C.

References buf, libMesh::err, imax(), is_foreign(), jmax(), kmax(), libMesh::libmesh_assert(), 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().

62 {
63  libmesh_assert (in.good());
64 
65  //----------------------------------------------------
66  // Read the TECPLOT header
67 
68  // Read the version number
69  {
70  in.read (buf, 8);
71 
72  // Using erase for GCC 2.95.3
73  this->version().erase();
74 
75  for (unsigned int i=0; i<8; i++)
76  this->version() += buf[i];
77 
78  if (this->verbose())
79  libMesh::out << "Tecplot Version: "
80  << this->version()
81  << std::endl;
82  }
83 
84 
85  //----------------------------------------------------
86  // Read plt files written by older versions of Tecplot
87  if (this->version().rfind("V7") < this->version().size())
88  {
89  if (this->verbose())
90  libMesh::out << "Reading legacy .plt format (<= v9) ..."
91  << std::endl;
92 
93  // Read the value of 1 to determine byte ordering
94  {
95  int one = 0;
96  in.read (buf, LIBMESH_SIZEOF_INT);
97  std::memcpy (&one, buf, LIBMESH_SIZEOF_INT);
98 
99  if (one != 1)
100  {
101  if (this->verbose())
102  libMesh::out << "Tecplot data is Foreign!"
103  << std::endl;
104  this->is_foreign() = true;
105 
106  // Make sure one reversed is one
107  Utility::ReverseBytes rb(this->is_foreign());
108  libmesh_assert_equal_to (rb(one), 1);
109  }
110  }
111 
112  // A byte-reverser in case the data is foreign
113  Utility::ReverseBytes rb(this->is_foreign());
114 
115  // Read the title
116  {
117  int i=0;
118 
119  // Using erase for GCC 2.95.3
120  this->title().erase();
121 
122  do
123  {
124  in.read (buf, LIBMESH_SIZEOF_INT);
125  std::memcpy (&i, buf, LIBMESH_SIZEOF_INT);
126  rb(i);
127 
128  // Don't add trailing \0
129  if (i)
130  this->title() += static_cast<char>(i);
131  }
132  while (i);
133  }
134 
135  // Read the number of variables in the data set
136  {
137  int nv;
138  in.read (buf, LIBMESH_SIZEOF_INT);
139  std::memcpy (&nv, buf, LIBMESH_SIZEOF_INT);
140  rb(nv);
141 
142  this->set_n_vars (nv);
143  }
144 
145  // Read the variable names
146  for (unsigned int v=0; v<this->n_vars(); v++)
147  {
148  int i=0;
149 
150  // Using erase for GCC 2.95.3
151  this->var_name(v).erase();
152 
153  do
154  {
155  in.read (buf, LIBMESH_SIZEOF_INT);
156  std::memcpy (&i, buf, LIBMESH_SIZEOF_INT);
157  rb(i);
158 
159  // Don't add trailing \0
160  if (i)
161  this->var_name(v) += static_cast<char>(i);
162  }
163  while (i);
164  }
165 
166 
167 
168  // Read zones from the header.
169  // Continue reading until the end-of-header
170  // marker (357.) is found.
171  int nz=0;
172  std::vector<std::string> zname;
173  std::vector<int> ztype, zimax, zjmax, zkmax;
174 
175  {
176  float f=0.;
177 
178  do
179  {
180  // find the next Zone marker
181  do
182  {
183  f = 0.;
184  in.read (buf, LIBMESH_SIZEOF_FLOAT);
185  std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT);
186  rb(f);
187  }
188  while ((f != 299.) &&
189  (f != 357.) &&
190  in.good());
191 
192 
193  // Did we overrun the file?
194  if (!in.good())
195  libmesh_error_msg("ERROR: Unexpected end-of-file!");
196 
197  // Found a Zone marker
198  else if (f == 299.)
199  {
200  // Incriment the Zone counter
201  nz++;
202 
203  // Read the zone name
204  {
205  int i=0;
206  std::string name;
207 
208  do
209  {
210  in.read (buf, LIBMESH_SIZEOF_INT);
211  std::memcpy (&i, buf, LIBMESH_SIZEOF_INT);
212  rb(i);
213 
214  // Don't add trailing \0
215  if (i)
216  name += static_cast<char>(i);
217  }
218  while (i);
219 
220  zname.push_back(name);
221  }
222 
223  // Read the zone format
224  {
225  int zt;
226  in.read (buf, LIBMESH_SIZEOF_INT);
227  std::memcpy (&zt, buf, LIBMESH_SIZEOF_INT);
228  rb(zt);
229 
230  ztype.push_back(zt);
231  //libMesh::out << "zone type=" << ztype.back() << std::endl;
232  }
233 
234  // Read the zone color
235  {
236  int zc=0;
237 
238  in.read (buf, LIBMESH_SIZEOF_INT);
239  std::memcpy (&zc, buf, LIBMESH_SIZEOF_INT);
240  rb(zc);
241 
242  //libMesh::out << "zone color=" << zc << std::endl;
243  }
244 
245  // Read in the block dimensions
246  {
247  int
248  i_max=0,
249  j_max=0,
250  k_max=0;
251 
252  in.read (buf, LIBMESH_SIZEOF_INT);
253  std::memcpy (&i_max, buf, LIBMESH_SIZEOF_INT);
254  rb(i_max);
255 
256  in.read (buf, LIBMESH_SIZEOF_INT);
257  std::memcpy (&j_max, buf, LIBMESH_SIZEOF_INT);
258  rb(j_max);
259 
260  in.read (buf, LIBMESH_SIZEOF_INT);
261  std::memcpy (&k_max, buf, LIBMESH_SIZEOF_INT);
262  rb(k_max);
263 
264  zimax.push_back (i_max);
265  zjmax.push_back (j_max);
266  zkmax.push_back (k_max);
267  }
268  } // else if (f == 299.)
269  }
270  while ((f != 357.) && in.good());
271  }
272 
273  // Set the header data
274  this->set_n_zones (nz);
275 
276  for (unsigned int z=0; z<this->n_zones(); z++)
277  {
278  this->zone_type(z) = ztype[z];
279  this->zone_name(z) = zname[z];
280  this->imax(z) = zimax[z];
281  this->jmax(z) = zjmax[z];
282  this->kmax(z) = zkmax[z];
283  }
284  }
285 
286 
287  //----------------------------------------------------
288  // Read plt files written by newer versions of Tecplot
289  else if (this->version().rfind("V1") < this->version().size())
290  {
291  if (this->verbose())
292  libMesh::out << "Reading new .plt format (>= v10)..."
293  << std::endl;
294 
295  // Read the value of 1 to determine byte ordering
296  {
297  int one = 0;
298 
299  in.read (buf, LIBMESH_SIZEOF_INT);
300  std::memcpy (&one, buf, LIBMESH_SIZEOF_INT);
301 
302  if (one != 1)
303  {
304  if (this->verbose())
305  libMesh::err << "Tecplot data is Foreign!"
306  << std::endl;
307  this->is_foreign() = true;
308 
309  // Make sure one reversed is one
310  Utility::ReverseBytes rb(this->is_foreign());
311  libmesh_assert_equal_to (rb(one), 1);
312  }
313  }
314 
315  // A byte-reverser in case the data is foreign
316  Utility::ReverseBytes rb(this->is_foreign());
317 
318  // Read the title
319  {
320  int i=0;
321 
322  // Using erase() for GCC 2.95.3
323  this->title().erase();
324  do
325  {
326  in.read (buf, LIBMESH_SIZEOF_INT);
327  std::memcpy (&i, buf, LIBMESH_SIZEOF_INT);
328  rb(i);
329 
330  // Don't add trailing \0
331  if (i)
332  this->title() += static_cast<char>(i);
333  }
334  while (i);
335  }
336 
337  // Read the number of variables in the data set
338  {
339  int nv;
340  in.read (buf, LIBMESH_SIZEOF_INT);
341  std::memcpy (&nv, buf, LIBMESH_SIZEOF_INT);
342  rb(nv);
343 
344  this->set_n_vars (nv);
345  }
346 
347  // Read the variable names
348  for (unsigned int v=0; v<this->n_vars(); v++)
349  {
350  int i=0;
351 
352  // Using erase() for GCC 2.95.3
353  this->var_name(v).erase();
354 
355  do
356  {
357  in.read (buf, LIBMESH_SIZEOF_INT);
358  std::memcpy (&i, buf, LIBMESH_SIZEOF_INT);
359  rb(i);
360 
361  // Don't add trailing \0
362  if (i)
363  this->var_name(v) += static_cast<char>(i);
364  }
365  while (i);
366  }
367 
368 
369 
370  // Read zones from the header.
371  // Continue reading until the end-of-header
372  // marker (357.) is found.
373  int nz=0;
374  std::vector<std::string> zname;
375  std::vector<int> zpack, ztype, zimax, zjmax, zkmax;
376 
377  {
378  float f=0.;
379 
380  do
381  {
382  // find the next Zone marker
383  do
384  {
385  f = 0.;
386  in.read (buf, LIBMESH_SIZEOF_FLOAT);
387  std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT);
388  rb(f);
389  }
390  while ((f != 299.) &&
391  (f != 357.) &&
392  in.good());
393 
394 
395  // Did we overrun the file?
396  if (!in.good())
397  libmesh_error_msg("ERROR: Unexpected end-of-file!");
398 
399  // Found a Zone marker
400  else if (f == 299.)
401  {
402  // Incriment the Zone counter
403  nz++;
404 
405  // Read the zone name
406  {
407  int i=0;
408  std::string name;
409 
410  do
411  {
412  in.read (buf, LIBMESH_SIZEOF_INT);
413  std::memcpy (&i, buf, LIBMESH_SIZEOF_INT);
414  rb(i);
415 
416  // Don't add trailing \0
417  if (i)
418  name += static_cast<char>(i);
419  }
420  while (i);
421 
422  zname.push_back(name);
423  }
424 
425  // Read the zone color
426  {
427  int zc=0;
428  in.read (buf, LIBMESH_SIZEOF_INT);
429  std::memcpy (&zc, buf, LIBMESH_SIZEOF_INT);
430  rb(zc);
431  }
432 
433  // Read the zone format
434  {
435  int zt;
436  in.read (buf, LIBMESH_SIZEOF_INT);
437  std::memcpy (&zt, buf, LIBMESH_SIZEOF_INT);
438  rb(zt);
439 
440  ztype.push_back(zt);
441  }
442 
443  // Read the data packing flag
444  {
445  int dp=0;
446  in.read (buf, LIBMESH_SIZEOF_INT);
447  std::memcpy (&dp, buf, LIBMESH_SIZEOF_INT);
448  rb(dp);
449 
450  zpack.push_back (dp);
451  }
452 
453  // Will we specify the variable location?
454  {
455  int svl=0;
456  int vl=0;
457  in.read (buf, LIBMESH_SIZEOF_INT);
458  std::memcpy (&svl, buf, LIBMESH_SIZEOF_INT);
459  rb(svl);
460 
461  if (svl)
462  for (unsigned int v=0; v<this->n_vars(); v++)
463  {
464  in.read (buf, LIBMESH_SIZEOF_INT);
465  std::memcpy (&vl, buf, LIBMESH_SIZEOF_INT);
466  rb(vl);
467  libmesh_assert_equal_to (vl, 0); // Only know about node-based data
468  // right now
469  }
470 
471  }
472 
473  // Get the number of user-defined face-neighbors
474  {
475  int fn=0;
476  in.read (buf, LIBMESH_SIZEOF_INT);
477  std::memcpy (&fn, buf, LIBMESH_SIZEOF_INT);
478  rb(fn);
479  }
480 
481  // Read in the block dimensions
482  {
483  if (ztype.back() != ORDERED)
484  {
485  int np=0, ne=0;
486 
487  in.read (buf, LIBMESH_SIZEOF_INT);
488  std::memcpy (&np, buf, LIBMESH_SIZEOF_INT);
489  rb(np);
490 
491  in.read (buf, LIBMESH_SIZEOF_INT);
492  std::memcpy (&ne, buf, LIBMESH_SIZEOF_INT);
493  rb(ne);
494 
495  zimax.push_back (np);
496  zjmax.push_back (ne);
497  zjmax.push_back (0);
498  }
499 
500  int
501  i_max=0,
502  j_max=0,
503  k_max=0;
504 
505  in.read (buf, LIBMESH_SIZEOF_INT);
506  std::memcpy (&i_max, buf, LIBMESH_SIZEOF_INT);
507  rb(i_max);
508 
509  in.read (buf, LIBMESH_SIZEOF_INT);
510  std::memcpy (&j_max, buf, LIBMESH_SIZEOF_INT);
511  rb(j_max);
512 
513  in.read (buf, LIBMESH_SIZEOF_INT);
514  std::memcpy (&k_max, buf, LIBMESH_SIZEOF_INT);
515  rb(k_max);
516 
517  // These are only useful for orderd data. Otherwise
518  // we grabbed the relevant values above.
519  if (ztype.back() != ORDERED)
520  {
521  zimax.push_back (i_max);
522  zjmax.push_back (j_max);
523  zkmax.push_back (k_max);
524  }
525  }
526  } // else if (f == 299.)
527  }
528  while ((f != 357.) && in.good());
529  }
530 
531  // Set the header data
532  this->set_n_zones (nz);
533 
534  for (unsigned int z=0; z<this->n_zones(); z++)
535  {
536  this->zone_type(z) = ztype[z];
537  this->zone_name(z) = zname[z];
538  this->zone_pack(z) = zpack[z];
539  this->imax(z) = zimax[z];
540  this->jmax(z) = zjmax[z];
541  this->kmax(z) = zkmax[z];
542  }
543  }
544 
545 
546 
547  //----------------------------------------------------
548  // Unrecognized Tecplot Version!
549  else
550  libmesh_error_msg("ERROR: This plot file was written by an unrecognized version of Tecplot!:\n" << this->version());
551 
552 
553 
554 
555 
556 
557 
558 
559  // Print the data to the screen.
560  if (this->verbose())
561  {
562  libMesh::out << "Tecplot Header: "
563  << this->title() << std::endl;
564 
565  libMesh::out << "Variables: ";
566  for (unsigned int v=0; v<this->n_vars(); v++)
567  libMesh::out << "\"" << this->var_name (v) << "\"" << " ";
568  libMesh::out << std::endl;
569 
570  libMesh::out << "Variable Types: ";
571  for (unsigned int v=0; v<this->n_vars(); v++)
572  libMesh::out << this->var_type (v) << " ";
573  libMesh::out << std::endl;
574 
575  libMesh::out << "Zone Names: ";
576  for (unsigned int z=0; z<this->n_zones(); z++)
577  libMesh::out << "\"" << this->zone_name (z) << "\"" << " ";
578  libMesh::out << std::endl;
579 
580  libMesh::out << "Zone Types: ";
581  for (unsigned int z=0; z<this->n_zones(); z++)
582  {
583  libMesh::out << this->zone_type (z) << " ";
584 
585  if (this->zone_type (z) != ORDERED)
586  libMesh::out << "(" << this->n_nodes(z) << "," << this->n_elem(z) << ") ";
587  }
588  libMesh::out << std::endl;
589 
590  libMesh::out << "Zone Dimensions: " << std::endl;
591  for (unsigned int z=0; z<this->n_zones(); z++)
592  libMesh::out << " ("
593  << this->imax(z) << ","
594  << this->jmax(z) << ","
595  << this->kmax(z) << ")"
596  << std::endl;
597  }
598 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
void set_n_zones(const unsigned int nz)
Definition: plt_loader.C:82
const std::string & zone_name(const unsigned int z) const
Definition: plt_loader.h:550
unsigned int n_vars() const
Definition: plt_loader.h:179
void set_n_vars(const unsigned int nv)
Definition: plt_loader.C:60
unsigned int zone_pack(const unsigned int z) const
Definition: plt_loader.h:574
const std::string & version() const
Definition: plt_loader.h:162
unsigned int imax(const unsigned int z) const
Definition: plt_loader.h:598
unsigned int var_type(const unsigned int v) const
Definition: plt_loader.h:502
libmesh_assert(j)
unsigned int n_elem(const unsigned int z) const
Definition: plt_loader.h:677
const std::string & title() const
Definition: plt_loader.h:174
bool verbose() const
Definition: plt_loader.h:69
const std::string & var_name(const unsigned int v) const
Definition: plt_loader.h:478
OStreamProxy err(std::cerr)
unsigned int jmax(const unsigned int z) const
Definition: plt_loader.h:620
unsigned int zone_type(const unsigned int z) const
Definition: plt_loader.h:526
unsigned int n_nodes(const unsigned int z) const
Definition: plt_loader.h:664
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int kmax(const unsigned int z) const
Definition: plt_loader.h:642
OStreamProxy out(std::cout)
bool is_foreign() const
Definition: plt_loader.h:169
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 897 of file plt_loader_read.C.

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

Referenced by read_data().

898 {
899  libmesh_assert (in.good());
900 
901  // A byte-reverser in case the data is foreign
902  Utility::ReverseBytes rb(this->is_foreign());
903 
904  // First allocate space
905  for (unsigned int var=0; var<this->n_vars(); var++)
906  {
907  std::vector<float> & data = _data[zone][var];
908 
909  data.clear();
910  data.reserve (this->imax(zone)*
911  this->jmax(zone)*
912  this->kmax(zone));
913  }
914 
915 
916  for (unsigned int k=0; k<this->kmax(zone); k++)
917  for (unsigned int j=0; j<this->jmax(zone); j++)
918  for (unsigned int i=0; i<this->imax(zone); i++)
919  for (unsigned int var=0; var<this->n_vars(); var++)
920  if (this->var_type(var) == FLOAT)
921  {
922  float f = 0.;
923 
924  libmesh_assert (in.good());
925 
926  in.read (buf, LIBMESH_SIZEOF_FLOAT);
927  std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT);
928  rb(f);
929 
930  _data[zone][var].push_back(f);
931  }
932  else if (this->var_type(var) == DOUBLE)
933  {
934  double d = 0.;
935 
936  libmesh_assert (in.good());
937 
938  in.read (buf, LIBMESH_SIZEOF_DOUBLE);
939  std::memcpy (&d, buf, LIBMESH_SIZEOF_DOUBLE);
940  rb(d);
941 
942  _data[zone][var].push_back(d);
943  }
944  else
945  libmesh_error_msg("ERROR: unsupported data type: " << this->var_type(var));
946 }
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:429
unsigned int n_vars() const
Definition: plt_loader.h:179
unsigned int imax(const unsigned int z) const
Definition: plt_loader.h:598
unsigned int var_type(const unsigned int v) const
Definition: plt_loader.h:502
libmesh_assert(j)
unsigned int jmax(const unsigned int z) const
Definition: plt_loader.h:620
IterBase * data
unsigned int kmax(const unsigned int z) const
Definition: plt_loader.h:642
bool is_foreign() const
Definition: plt_loader.h:169
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(), and title().

61 {
62  _n_vars = nv;
63 
64  _var_types.resize (this->n_vars());
65  _var_names.resize (this->n_vars());
66 
67  // Default to float data
68  std::fill (_var_types.begin(), _var_types.end(), 1);
69 
70  // If the number of zones is set, resize the data.
71  if (this->n_zones())
72  {
73  _data.resize (this->n_zones());
74 
75  for (unsigned int z=0; z<this->n_zones(); z++)
76  _data[z].resize (this->n_vars());
77  }
78 }
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:429
unsigned int n_vars() const
Definition: plt_loader.h:179
std::vector< unsigned int > _var_types
Definition: plt_loader.h:397
std::vector< std::string > _var_names
Definition: plt_loader.h:391
unsigned int _n_vars
Definition: plt_loader.h:386
unsigned int n_zones() const
Definition: plt_loader.h:194
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(), and title().

83 {
84  _n_zones = nz;
85 
86  _zone_types.resize (this->n_zones());
87  _zone_names.resize (this->n_zones());
88  _zone_pack.resize (this->n_zones());
89 
90  _imax.resize (this->n_zones());
91  _jmax.resize (this->n_zones());
92  _kmax.resize (this->n_zones());
93 
94  _data.resize (this->n_zones());
95  _conn.resize (this->n_zones());
96 
97  // If the number of variables are set, resize the data.
98  if (this->n_vars())
99  for (unsigned int z=0; z<this->n_zones(); z++)
100  _data[z].resize (this->n_vars());
101 }
std::vector< std::vector< int > > _conn
Definition: plt_loader.h:435
std::vector< std::string > _zone_names
Definition: plt_loader.h:412
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:429
std::vector< unsigned int > _zone_pack
Definition: plt_loader.h:417
unsigned int n_vars() const
Definition: plt_loader.h:179
std::vector< unsigned int > _kmax
Definition: plt_loader.h:424
std::vector< unsigned int > _zone_types
Definition: plt_loader.h:407
std::vector< unsigned int > _jmax
Definition: plt_loader.h:423
std::vector< unsigned int > _imax
Definition: plt_loader.h:422
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int _n_zones
Definition: plt_loader.h:402
const std::string& libMesh::PltLoader::title ( ) const
inline
Returns
the data set title

Definition at line 174 of file plt_loader.h.

References _title.

Referenced by read_header(), and write_dat().

174 { return _title; }
std::string _title
Definition: plt_loader.h:381
std::string& libMesh::PltLoader::title ( )
inlineprivate
Returns
the data set title

Definition at line 306 of file plt_loader.h.

References _title, imax(), jmax(), kmax(), set_n_vars(), set_n_zones(), var_name(), var_type(), zone_name(), zone_pack(), and zone_type().

306 { return _title; }
std::string _title
Definition: plt_loader.h:381
const std::string & libMesh::PltLoader::var_name ( const unsigned int  v) const
inline
Returns
the name of variable v.

Definition at line 478 of file plt_loader.h.

References _var_names, and n_vars().

Referenced by n_vars(), read_header(), title(), and write_dat().

479 {
480  libmesh_assert_less (v, this->n_vars());
481  libmesh_assert_less (v, _var_names.size());
482  libmesh_assert_equal_to (this->n_vars(), _var_names.size());
483 
484  return _var_names[v];
485 }
unsigned int n_vars() const
Definition: plt_loader.h:179
std::vector< std::string > _var_names
Definition: plt_loader.h:391
std::string & libMesh::PltLoader::var_name ( const unsigned int  v)
inlineprivate
Returns
the name of variable v.

Definition at line 490 of file plt_loader.h.

References _var_names, and n_vars().

491 {
492  libmesh_assert_less (v, this->n_vars());
493  libmesh_assert_less (v, _var_names.size());
494  libmesh_assert_equal_to (this->n_vars(), _var_names.size());
495 
496  return _var_names[v];
497 }
unsigned int n_vars() const
Definition: plt_loader.h:179
std::vector< std::string > _var_names
Definition: plt_loader.h:391
unsigned int libMesh::PltLoader::var_type ( const unsigned int  v) const
inline
Returns
the type of variable v

Definition at line 502 of file plt_loader.h.

References _var_types, and n_vars().

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

503 {
504  libmesh_assert_less (v, this->n_vars());
505  libmesh_assert_less (v, _var_types.size());
506  libmesh_assert_equal_to (this->n_vars(), _var_types.size());
507 
508  return _var_types[v];
509 }
unsigned int n_vars() const
Definition: plt_loader.h:179
std::vector< unsigned int > _var_types
Definition: plt_loader.h:397
unsigned int & libMesh::PltLoader::var_type ( const unsigned int  v)
inlineprivate
Returns
the type of variable v

Definition at line 514 of file plt_loader.h.

References _var_types, and n_vars().

515 {
516  libmesh_assert_less (v, this->n_vars());
517  libmesh_assert_less (v, _var_types.size());
518  libmesh_assert_equal_to (this->n_vars(), _var_types.size());
519 
520  return _var_types[v];
521 }
unsigned int n_vars() const
Definition: plt_loader.h:179
std::vector< unsigned int > _var_types
Definition: plt_loader.h:397
bool libMesh::PltLoader::verbose ( ) const
inline

Returns the verbosity.

Definition at line 69 of file plt_loader.h.

References _verbose, read(), version(), and write_dat().

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

69 { return _verbose; }
const bool _verbose
Definition: plt_loader.h:366
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 162 of file plt_loader.h.

References _version.

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

162 { return _version; }
std::string _version
Definition: plt_loader.h:371
std::string& libMesh::PltLoader::version ( )
inlineprivate
Returns
the Tecplot version number string.

Definition at line 294 of file plt_loader.h.

References _version.

294 { return _version; }
std::string _version
Definition: plt_loader.h:371
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, imax(), jmax(), kmax(), n_vars(), n_zones(), POINT, title(), var_name(), zone_name(), and zone_type().

Referenced by verbose().

452 {
453  std::ofstream out_stream (name.c_str());
454 
455  out_stream << "TITLE=\""
456  << this->title()
457  << "\""
458  << '\n';
459 
460  out_stream << "VARIABLES = ";
461 
462  for (unsigned int v=0; v<this->n_vars(); v++)
463  out_stream << "\"" << this->var_name(v) << "\"\n";
464 
465  for (unsigned int z=0; z<this->n_zones(); z++)
466  {
467  out_stream << "ZONE T=\"" << this->zone_name(z) << "\"\n";
468  out_stream << " I=" << this->imax(z)
469  << ", J=" << this->jmax(z)
470  << ", K=" << this->kmax(z);
471 
472  // Write BLOCK data for this zone
473  if (this->zone_type(z) == BLOCK)
474  {
475  if (version_in < 10)
476  {
477  out_stream << ", F=BLOCK\n";
478  }
479  else
480  {
481  out_stream << ", ZONETYPE=Ordered\n"
482  << "DATAPACKING=BLOCK\n";
483  }
484 
485  out_stream << "DT=(";
486  for (unsigned int v=0; v<this->n_vars(); v++)
487  out_stream << "SINGLE ";
488  out_stream << ")\n";
489 
490  out_stream.precision(9);
491 
492  for (unsigned int v=0; v<this->n_vars(); v++)
493  {
494  unsigned int l=0;
495 
496  for (unsigned int k=0; k<this->kmax(z); k++)
497  for (unsigned int j=0; j<this->jmax(z); j++)
498  for (unsigned int i=0; i<this->imax(z); i++)
499  {
500  // GCC 2.95.3 has scientific in the ios class instead
501  // of in namespace std::
502 #ifndef LIBMESH_BROKEN_IOSTREAM
503  out_stream << std::scientific
504  << _data[z][v][l++] << " ";
505 #else
506  out_stream << std::ios::scientific
507  << _data[z][v][l++] << " ";
508 #endif
509  // Throw in a newline every 5 entries to
510  // avoid really long lines.
511  if (l%5 == 0)
512  out_stream << '\n';
513  }
514 
515  if (l%5 != 0)
516  out_stream << '\n';
517  }
518  } // end if (this->zone_type(z) == BLOCK)
519 
520  // Write POINT data for this zone
521  else if (this->zone_type(z) == POINT)
522  {
523  if (version_in < 10)
524  {
525  out_stream << ", F=POINT\n";
526  }
527  else
528  {
529  out_stream << ", ZONETYPE=Ordered\n"
530  << "DATAPACKING=POINT\n";
531  }
532 
533  out_stream << "DT=(";
534  for (unsigned int v=0; v<this->n_vars(); v++)
535  out_stream << "SINGLE ";
536  out_stream << ")\n";
537 
538  out_stream.precision(9);
539 
540  {
541  unsigned int l=0;
542 
543  for (unsigned int k=0; k<this->kmax(z); k++)
544  for (unsigned int j=0; j<this->jmax(z); j++)
545  for (unsigned int i=0; i<this->imax(z); i++)
546  {
547  for (unsigned int v=0; v<this->n_vars(); v++)
548 
549  // GCC 2.95.3 has scientific in the ios class instead
550  // of in namespace std::
551 #ifndef LIBMESH_BROKEN_IOSTREAM
552  out_stream << std::scientific
553  << _data[z][v][l] << " ";
554 #else
555  out_stream << std::ios::scientific
556  << _data[z][v][l] << " ";
557 #endif
558  out_stream << '\n';
559 
560  l++;
561  }
562  }
563  } // end else if (this->zone_type(z) == POINT)
564 
565  // Otherwise, unrecognized zone type
566  else
567  libmesh_error_msg("Unrecognized zone type: this->zone_type(z)==" << this->zone_type(z));
568  }
569 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:429
const std::string & zone_name(const unsigned int z) const
Definition: plt_loader.h:550
unsigned int n_vars() const
Definition: plt_loader.h:179
unsigned int imax(const unsigned int z) const
Definition: plt_loader.h:598
const std::string & title() const
Definition: plt_loader.h:174
const std::string & var_name(const unsigned int v) const
Definition: plt_loader.h:478
unsigned int jmax(const unsigned int z) const
Definition: plt_loader.h:620
unsigned int zone_type(const unsigned int z) const
Definition: plt_loader.h:526
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int kmax(const unsigned int z) const
Definition: plt_loader.h:642
const std::string & libMesh::PltLoader::zone_name ( const unsigned int  z) const
inline
Returns
the name of zone z.

Definition at line 550 of file plt_loader.h.

References _zone_names, and n_zones().

Referenced by n_zones(), read_header(), title(), and write_dat().

551 {
552  libmesh_assert_less (z, this->n_zones());
553  libmesh_assert_less (z, _zone_names.size());
554  libmesh_assert_equal_to (this->n_zones(), _zone_names.size());
555 
556  return _zone_names[z];
557 }
std::vector< std::string > _zone_names
Definition: plt_loader.h:412
unsigned int n_zones() const
Definition: plt_loader.h:194
std::string & libMesh::PltLoader::zone_name ( const unsigned int  z)
inlineprivate
Returns
the name of zone z.

Definition at line 562 of file plt_loader.h.

References _zone_names, and n_zones().

563 {
564  libmesh_assert_less (z, this->n_zones());
565  libmesh_assert_less (z, _zone_names.size());
566  libmesh_assert_equal_to (this->n_zones(), _zone_names.size());
567 
568  return _zone_names[z];
569 }
std::vector< std::string > _zone_names
Definition: plt_loader.h:412
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int libMesh::PltLoader::zone_pack ( const unsigned int  z) const
inline
Returns
the data packing flag for zone z.

Definition at line 574 of file plt_loader.h.

References _zone_pack, and n_zones().

Referenced by n_zones(), read_data(), read_header(), and title().

575 {
576  libmesh_assert_less (z, this->n_zones());
577  libmesh_assert_less (z, _zone_pack.size());
578  libmesh_assert_equal_to (this->n_zones(), _zone_pack.size());
579 
580  return _zone_pack[z];
581 }
std::vector< unsigned int > _zone_pack
Definition: plt_loader.h:417
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int & libMesh::PltLoader::zone_pack ( const unsigned int  z)
inlineprivate
Returns
the data pack flag for zone z.

Definition at line 586 of file plt_loader.h.

References _zone_pack, and n_zones().

587 {
588  libmesh_assert_less (z, this->n_zones());
589  libmesh_assert_less (z, _zone_pack.size());
590  libmesh_assert_equal_to (this->n_zones(), _zone_pack.size());
591 
592  return _zone_pack[z];
593 }
std::vector< unsigned int > _zone_pack
Definition: plt_loader.h:417
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int libMesh::PltLoader::zone_type ( const unsigned int  z) const
inline
Returns
the type of zone z

Definition at line 526 of file plt_loader.h.

References _zone_types, and n_zones().

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

527 {
528  libmesh_assert_less (z, this->n_zones());
529  libmesh_assert_less (z, _zone_types.size());
530  libmesh_assert_equal_to (this->n_zones(), _zone_types.size());
531 
532  return _zone_types[z];
533 }
std::vector< unsigned int > _zone_types
Definition: plt_loader.h:407
unsigned int n_zones() const
Definition: plt_loader.h:194
unsigned int & libMesh::PltLoader::zone_type ( const unsigned int  z)
inlineprivate
Returns
the type of zone z

Definition at line 538 of file plt_loader.h.

References _zone_types, and n_zones().

539 {
540  libmesh_assert_less (z, this->n_zones());
541  libmesh_assert_less (z, _zone_types.size());
542  libmesh_assert_equal_to (this->n_zones(), _zone_types.size());
543 
544  return _zone_types[z];
545 }
std::vector< unsigned int > _zone_types
Definition: plt_loader.h:407
unsigned int n_zones() const
Definition: plt_loader.h:194

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 435 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 422 of file plt_loader.h.

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

bool libMesh::PltLoader::_is_foreign
private

Is the data foreign?

Definition at line 376 of file plt_loader.h.

Referenced by clear(), and is_foreign().

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

Definition at line 423 of file plt_loader.h.

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

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

Definition at line 424 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 386 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 402 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 381 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 391 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 397 of file plt_loader.h.

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

const bool libMesh::PltLoader::_verbose
private

Verbosity

Definition at line 366 of file plt_loader.h.

Referenced by verbose().

std::string libMesh::PltLoader::_version
private

The Tecplot Version number string.

Definition at line 371 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 412 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 417 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 407 of file plt_loader.h.

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

char libMesh::PltLoader::buf[512]
mutableprivate

Scratch data & relevant sizes.

Definition at line 440 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 249 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: