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

Enum defining the finite element types

Enumerator
TRI 
QUAD 
TET 
HEX 

Definition at line 146 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 126 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 117 of file plt_loader.h.

Constructor & Destructor Documentation

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

Constructor. Initializes data.

Definition at line 449 of file plt_loader.h.

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

Constructor. Reads the file specified by name.

Definition at line 460 of file plt_loader.h.

References read().

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

Destructor.

Definition at line 472 of file plt_loader.h.

473 {
474 }

Member Function Documentation

void libMesh::PltLoader::clear ( )

Clear all data and return to a pristine state.

Definition at line 35 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.

36 {
37  // clear vectors & strings. Using .erase() for strings instead of .clear()
38  // since GCC 2.95.3 does not support .clear().
39  _version.erase();
40  _title.erase();
41 
42  _var_names.clear();
43  _var_types.clear();
44  _zone_types.clear();
45  _zone_names.clear();
46  _zone_pack.clear();
47  _imax.clear();
48  _jmax.clear();
49  _kmax.clear();
50  _data.clear();
51  _conn.clear();
52 
53  // reinitialize
54  _is_foreign = false;
55  _n_vars = 0;
56  _n_zones = 0;
57 }
std::vector< std::vector< int > > _conn
Definition: plt_loader.h:436
std::vector< std::string > _zone_names
Definition: plt_loader.h:413
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:430
std::vector< unsigned int > _zone_pack
Definition: plt_loader.h:418
std::vector< unsigned int > _kmax
Definition: plt_loader.h:425
std::vector< unsigned int > _var_types
Definition: plt_loader.h:398
std::vector< unsigned int > _zone_types
Definition: plt_loader.h:408
std::vector< unsigned int > _jmax
Definition: plt_loader.h:424
std::vector< unsigned int > _imax
Definition: plt_loader.h:423
std::vector< std::string > _var_names
Definition: plt_loader.h:392
std::string _title
Definition: plt_loader.h:382
unsigned int _n_vars
Definition: plt_loader.h:387
std::string _version
Definition: plt_loader.h:372
unsigned int _n_zones
Definition: plt_loader.h:403
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 691 of file plt_loader.h.

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

Referenced by n_zones().

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

References _data.

Referenced by n_zones().

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

Definition at line 599 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().

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

Definition at line 610 of file plt_loader.h.

References _imax, and n_zones().

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

170 { 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 302 of file plt_loader.h.

References _is_foreign.

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

Definition at line 621 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().

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

Definition at line 632 of file plt_loader.h.

References _jmax, and n_zones().

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

Definition at line 643 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().

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

Definition at line 654 of file plt_loader.h.

References _kmax, and n_zones().

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

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

Referenced by n_zones(), and read_header().

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

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

Referenced by n_zones(), and read_header().

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

Definition at line 180 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().

180 { return _n_vars; }
unsigned int _n_vars
Definition: plt_loader.h:387
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 35 of file plt_loader_read.C.

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

Referenced by PltLoader(), and verbose().

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

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

Read data from the binary file.

Definition at line 603 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().

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

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

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

Read the header of the binary file.

Definition at line 62 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().

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

899 {
900  libmesh_assert (in.good());
901 
902  // A byte-reverser in case the data is foreign
903  Utility::ReverseBytes rb(this->is_foreign());
904 
905  // First allocate space
906  for (unsigned int var=0; var<this->n_vars(); var++)
907  {
908  std::vector<float> & data = _data[zone][var];
909 
910  data.clear();
911  data.reserve (this->imax(zone)*
912  this->jmax(zone)*
913  this->kmax(zone));
914  }
915 
916 
917  for (unsigned int k=0; k<this->kmax(zone); k++)
918  for (unsigned int j=0; j<this->jmax(zone); j++)
919  for (unsigned int i=0; i<this->imax(zone); i++)
920  for (unsigned int var=0; var<this->n_vars(); var++)
921  if (this->var_type(var) == FLOAT)
922  {
923  float f = 0.;
924 
925  libmesh_assert (in.good());
926 
927  in.read (buf, LIBMESH_SIZEOF_FLOAT);
928  std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT);
929  rb(f);
930 
931  _data[zone][var].push_back(f);
932  }
933  else if (this->var_type(var) == DOUBLE)
934  {
935  double d = 0.;
936 
937  libmesh_assert (in.good());
938 
939  in.read (buf, LIBMESH_SIZEOF_DOUBLE);
940  std::memcpy (&d, buf, LIBMESH_SIZEOF_DOUBLE);
941  rb(d);
942 
943  _data[zone][var].push_back(d);
944  }
945  else
946  libmesh_error_msg("ERROR: unsupported data type: " << this->var_type(var));
947 }
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:430
unsigned int n_vars() const
Definition: plt_loader.h:180
unsigned int imax(const unsigned int z) const
Definition: plt_loader.h:599
unsigned int var_type(const unsigned int v) const
Definition: plt_loader.h:503
libmesh_assert(j)
unsigned int jmax(const unsigned int z) const
Definition: plt_loader.h:621
IterBase * data
unsigned int kmax(const unsigned int z) const
Definition: plt_loader.h:643
bool is_foreign() const
Definition: plt_loader.h:170
void libMesh::PltLoader::set_n_vars ( const unsigned int  nv)
private
Returns
The number of variables in the data set.

Definition at line 61 of file plt_loader.C.

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

Referenced by read_header(), and title().

62 {
63  _n_vars = nv;
64 
65  _var_types.resize (this->n_vars());
66  _var_names.resize (this->n_vars());
67 
68  // Default to float data
69  std::fill (_var_types.begin(), _var_types.end(), 1);
70 
71  // If the number of zones is set, resize the data.
72  if (this->n_zones())
73  {
74  _data.resize (this->n_zones());
75 
76  for (unsigned int z=0; z<this->n_zones(); z++)
77  _data[z].resize (this->n_vars());
78  }
79 }
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:430
unsigned int n_vars() const
Definition: plt_loader.h:180
std::vector< unsigned int > _var_types
Definition: plt_loader.h:398
std::vector< std::string > _var_names
Definition: plt_loader.h:392
unsigned int _n_vars
Definition: plt_loader.h:387
unsigned int n_zones() const
Definition: plt_loader.h:195
void libMesh::PltLoader::set_n_zones ( const unsigned int  nz)
private
Returns
The number of zones.

Definition at line 83 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().

84 {
85  _n_zones = nz;
86 
87  _zone_types.resize (this->n_zones());
88  _zone_names.resize (this->n_zones());
89  _zone_pack.resize (this->n_zones());
90 
91  _imax.resize (this->n_zones());
92  _jmax.resize (this->n_zones());
93  _kmax.resize (this->n_zones());
94 
95  _data.resize (this->n_zones());
96  _conn.resize (this->n_zones());
97 
98  // If the number of variables are set, resize the data.
99  if (this->n_vars())
100  for (unsigned int z=0; z<this->n_zones(); z++)
101  _data[z].resize (this->n_vars());
102 }
std::vector< std::vector< int > > _conn
Definition: plt_loader.h:436
std::vector< std::string > _zone_names
Definition: plt_loader.h:413
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:430
std::vector< unsigned int > _zone_pack
Definition: plt_loader.h:418
unsigned int n_vars() const
Definition: plt_loader.h:180
std::vector< unsigned int > _kmax
Definition: plt_loader.h:425
std::vector< unsigned int > _zone_types
Definition: plt_loader.h:408
std::vector< unsigned int > _jmax
Definition: plt_loader.h:424
std::vector< unsigned int > _imax
Definition: plt_loader.h:423
unsigned int n_zones() const
Definition: plt_loader.h:195
unsigned int _n_zones
Definition: plt_loader.h:403
const std::string& libMesh::PltLoader::title ( ) const
inline
Returns
The data set title

Definition at line 175 of file plt_loader.h.

References _title.

Referenced by read_header(), and write_dat().

175 { return _title; }
std::string _title
Definition: plt_loader.h:382
std::string& libMesh::PltLoader::title ( )
inlineprivate
Returns
The data set title

Definition at line 307 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().

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

Definition at line 479 of file plt_loader.h.

References _var_names, and n_vars().

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

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

Definition at line 491 of file plt_loader.h.

References _var_names, and n_vars().

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

Definition at line 503 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().

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

Definition at line 515 of file plt_loader.h.

References _var_types, and n_vars().

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

Definition at line 70 of file plt_loader.h.

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

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

70 { return _verbose; }
const bool _verbose
Definition: plt_loader.h:367
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 163 of file plt_loader.h.

References _version.

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

163 { return _version; }
std::string _version
Definition: plt_loader.h:372
std::string& libMesh::PltLoader::version ( )
inlineprivate
Returns
The Tecplot version number string.

Definition at line 295 of file plt_loader.h.

References _version.

295 { return _version; }
std::string _version
Definition: plt_loader.h:372
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 451 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().

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

Definition at line 551 of file plt_loader.h.

References _zone_names, and n_zones().

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

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

Definition at line 563 of file plt_loader.h.

References _zone_names, and n_zones().

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

Definition at line 575 of file plt_loader.h.

References _zone_pack, and n_zones().

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

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

Definition at line 587 of file plt_loader.h.

References _zone_pack, and n_zones().

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

Definition at line 527 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().

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

Definition at line 539 of file plt_loader.h.

References _zone_types, and n_zones().

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

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 436 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 423 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 377 of file plt_loader.h.

Referenced by clear(), and is_foreign().

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

Definition at line 424 of file plt_loader.h.

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

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

Definition at line 425 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 387 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 403 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 382 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 392 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 398 of file plt_loader.h.

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

const bool libMesh::PltLoader::_verbose
private

Verbosity

Definition at line 367 of file plt_loader.h.

Referenced by verbose().

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

The Tecplot Version number string.

Definition at line 372 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 413 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 418 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 408 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 441 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 250 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: