libMesh
Public Member Functions | Private Member Functions | Private Attributes | List of all members
libMesh::Xdr Class Reference

This class implements a C++ interface to the XDR (eXternal Data Representation) format. More...

#include <xdr_cxx.h>

Public Member Functions

 Xdr (const std::string &name="", const XdrMODE m=UNKNOWN)
 Constructor. More...
 
 ~Xdr ()
 Destructor. More...
 
void open (const std::string &name)
 Opens the file. More...
 
void close ()
 Closes the file if it is open. More...
 
bool is_open () const
 
bool is_eof ()
 
bool reading () const
 
bool writing () const
 
XdrMODE access_mode () const
 
template<typename T >
void data (T &a, const char *comment="")
 Inputs or outputs a single value. More...
 
template<typename T >
Xdroperator<< (T &a)
 Same, but provides an ostream like interface. More...
 
template<typename T >
Xdroperator>> (T &a)
 Same, but provides an istream like interface. More...
 
template<typename T >
void data_stream (T *val, const unsigned int len, const unsigned int line_break=libMesh::invalid_uint)
 Inputs or outputs a raw data stream. More...
 
void comment (std::string &)
 Writes or reads (ignores) a comment line. More...
 
void set_version (int ver)
 Sets the version of the file that is being read. More...
 
int version () const
 Gets the version of the file that is being read. More...
 
template<>
void do_read (std::string &a)
 
template<>
void data_stream (double *val, const unsigned int len, const unsigned int line_break)
 
template<>
void data_stream (float *val, const unsigned int len, const unsigned int line_break)
 
template<>
void data_stream (long double *val, const unsigned int len, const unsigned int line_break)
 
template<>
void data_stream (std::complex< double > *val, const unsigned int len, const unsigned int line_break)
 
template<>
void data_stream (std::complex< long double > *val, const unsigned int len, const unsigned int line_break)
 

Private Member Functions

template<typename T >
void do_read (T &a)
 Helper method for reading different data types. More...
 
template<typename T >
void do_read (std::complex< T > &a)
 
template<typename T >
void do_read (std::vector< T > &a)
 
template<typename T >
void do_read (std::vector< std::complex< T >> &a)
 
template<typename T >
void do_write (T &a)
 Helper method for writing different data types. More...
 
template<typename T >
void do_write (std::complex< T > &a)
 
template<typename T >
void do_write (std::vector< T > &a)
 
template<typename T >
void do_write (std::vector< std::complex< T >> &a)
 

Private Attributes

const XdrMODE mode
 The mode used for accessing the file. More...
 
std::string file_name
 The file name. More...
 
UniquePtr< XDR > xdrs
 Pointer to the standard XDR struct. More...
 
FILE * fp
 File pointer. More...
 
UniquePtr< std::istream > in
 The input file stream. More...
 
UniquePtr< std::ostream > out
 The output file stream. More...
 
const int comm_len
 A buffer to put comment strings into. More...
 
char comm [xdr_MAX_STRING_LENGTH]
 
bool gzipped_file
 Are we reading/writing zipped files? More...
 
bool bzipped_file
 
bool xzipped_file
 
int version_number
 Version of the file being read. More...
 

Detailed Description

This class implements a C++ interface to the XDR (eXternal Data Representation) format.

XDR is useful for creating platform-independent binary files. This class was created to handle equation system output as a replacement for XdrIO since that is somewhat limited.

Author
Benjamin Kirk
Date
2003 C++ interface for the XDR (eXternal Data Representation) format.

Definition at line 68 of file xdr_cxx.h.

Constructor & Destructor Documentation

libMesh::Xdr::Xdr ( const std::string &  name = "",
const XdrMODE  m = UNKNOWN 
)

Constructor.

Takes the filename and the mode. Valid modes are ENCODE, DECODE, READ, and WRITE.

Definition at line 134 of file xdr_cxx.C.

References open().

135  :
136  mode(m),
137  file_name(name),
138 #ifdef LIBMESH_HAVE_XDR
140 #endif
141  in(),
142  out(),
144  gzipped_file(false),
145  bzipped_file(false),
146  xzipped_file(false)
147 {
148  this->open(name);
149 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
FILE * fp
File pointer.
Definition: xdr_cxx.h:221
const int comm_len
A buffer to put comment strings into.
Definition: xdr_cxx.h:238
std::string file_name
The file name.
Definition: xdr_cxx.h:208
const unsigned int xdr_MAX_STRING_LENGTH
Definition: xdr_cxx.h:46
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
const class libmesh_nullptr_t libmesh_nullptr
bool xzipped_file
Definition: xdr_cxx.h:244
bool bzipped_file
Definition: xdr_cxx.h:244
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
bool gzipped_file
Are we reading/writing zipped files?
Definition: xdr_cxx.h:244
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
void open(const std::string &name)
Opens the file.
Definition: xdr_cxx.C:160
libMesh::Xdr::~Xdr ( )

Destructor.

Closes the file if it is open.

Definition at line 153 of file xdr_cxx.C.

References close().

154 {
155  this->close();
156 }
void close()
Closes the file if it is open.
Definition: xdr_cxx.C:271

Member Function Documentation

XdrMODE libMesh::Xdr::access_mode ( ) const
Returns
The mode used to access the file. Valid modes are ENCODE, DECODE, READ, or WRITE.

Definition at line 125 of file xdr_cxx.h.

References comment(), data(), and mode.

125 { return mode; }
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
void libMesh::Xdr::close ( )

Closes the file if it is open.

Definition at line 271 of file xdr_cxx.C.

References bzipped_file, libMesh::DECODE, libMesh::ENCODE, file_name, fp, in, libmesh_nullptr, mode, out, libMesh::READ, libMesh::WRITE, xdrs, and xzipped_file.

Referenced by libMesh::EquationSystems::_read_impl(), libMesh::RBEvaluation::legacy_read_offline_data_from_files(), libMesh::RBSCMEvaluation::legacy_read_offline_data_from_files(), libMesh::RBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBParametrized::read_parameter_ranges_from_file(), libMesh::XdrIO::write(), libMesh::RBParametrized::write_parameter_ranges_to_file(), and ~Xdr().

272 {
273  switch (mode)
274  {
275  case ENCODE:
276  case DECODE:
277  {
278 #ifdef LIBMESH_HAVE_XDR
279 
280  if (xdrs)
281  {
282  xdr_destroy (xdrs.get());
283  xdrs.reset();
284  }
285 
286  if (fp)
287  {
288  fflush(fp);
289  fclose(fp);
291  }
292 #else
293 
294  libmesh_error_msg("ERROR: Functionality is not available.\n" \
295  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
296  << "The XDR interface is not available in this installation");
297 
298 #endif
299  file_name = "";
300  return;
301  }
302 
303  case READ:
304  {
305  if (in.get() != libmesh_nullptr)
306  {
307  in.reset();
308 
309  if (bzipped_file || xzipped_file)
310  remove_unzipped_file(file_name);
311  }
312  file_name = "";
313  return;
314  }
315 
316  case WRITE:
317  {
318  if (out.get() != libmesh_nullptr)
319  {
320  out.reset();
321 
322  if (bzipped_file)
323  bzip_file(std::string(file_name.begin(), file_name.end()-4));
324 
325  else if (xzipped_file)
326  xzip_file(std::string(file_name.begin(), file_name.end()-3));
327  }
328  file_name = "";
329  return;
330  }
331 
332  default:
333  libmesh_error_msg("Invalid mode = " << mode);
334  }
335 }
FILE * fp
File pointer.
Definition: xdr_cxx.h:221
std::string file_name
The file name.
Definition: xdr_cxx.h:208
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
const class libmesh_nullptr_t libmesh_nullptr
bool xzipped_file
Definition: xdr_cxx.h:244
bool bzipped_file
Definition: xdr_cxx.h:244
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
UniquePtr< XDR > xdrs
Pointer to the standard XDR struct.
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
void libMesh::Xdr::comment ( std::string &  comment_in)

Writes or reads (ignores) a comment line.

Definition at line 1519 of file xdr_cxx.C.

References comm, comm_len, libMesh::DECODE, libMesh::ENCODE, in, libMesh::libmesh_assert(), mode, out, libMesh::READ, and libMesh::WRITE.

Referenced by access_mode(), operator>>(), and libMesh::System::write_serialized_data().

1520 {
1521  switch (mode)
1522  {
1523  case ENCODE:
1524  case DECODE:
1525  {
1526  return;
1527  }
1528 
1529  case READ:
1530  {
1531  libmesh_assert(in.get());
1532  libmesh_assert (in->good());
1533  in->getline(comm, comm_len);
1534  return;
1535  }
1536 
1537  case WRITE:
1538  {
1539  libmesh_assert(out.get());
1540  libmesh_assert (out->good());
1541  *out << "\t " << comment_in << '\n';
1542  return;
1543  }
1544 
1545  default:
1546  libmesh_error_msg("Invalid mode = " << mode);
1547  }
1548 }
const int comm_len
A buffer to put comment strings into.
Definition: xdr_cxx.h:238
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:239
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
template<typename T >
template void libMesh::Xdr::data< long double > ( T &  a,
const char *  comment = "" 
)

Inputs or outputs a single value.

Definition at line 761 of file xdr_cxx.C.

References libMesh::DECODE, do_read(), do_write(), libMesh::ENCODE, in, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

Referenced by libMesh::EquationSystems::_read_impl(), access_mode(), do_read(), do_write(), operator<<(), operator>>(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_bc_names(), libMesh::CheckpointIO::read_bcs(), libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::System::read_legacy_data(), libMesh::CheckpointIO::read_nodes(), libMesh::CheckpointIO::read_nodesets(), libMesh::System::read_parallel_data(), libMesh::CheckpointIO::read_remote_elem(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::CheckpointIO::read_subdomain_names(), libMesh::CheckpointIO::write(), libMesh::XdrIO::write(), libMesh::EquationSystems::write(), libMesh::CheckpointIO::write_bc_names(), libMesh::CheckpointIO::write_bcs(), libMesh::CheckpointIO::write_connectivity(), libMesh::System::write_header(), libMesh::CheckpointIO::write_nodes(), libMesh::CheckpointIO::write_nodesets(), libMesh::System::write_parallel_data(), libMesh::CheckpointIO::write_remote_elem(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), and libMesh::CheckpointIO::write_subdomain_names().

762 {
763  switch (mode)
764  {
765  case ENCODE:
766  case DECODE:
767  {
768 #ifdef LIBMESH_HAVE_XDR
769 
771 
772  xdr_translate(xdrs.get(), a);
773 
774 #else
775 
776  libmesh_error_msg("ERROR: Functionality is not available.\n" \
777  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
778  << "The XDR interface is not available in this installation");
779 
780 #endif
781  return;
782  }
783 
784  case READ:
785  {
786  libmesh_assert(in.get());
787  libmesh_assert (in->good());
788 
789  this->do_read(a);
790 
791  return;
792  }
793 
794  case WRITE:
795  {
796  libmesh_assert(out.get());
797  libmesh_assert (out->good());
798 
799  // We will use scientific notation with a precision of 16
800  // digits in the following output. The desired precision and
801  // format will automatically determine the width.
802  *out << std::scientific
803  << std::setprecision(16);
804 
805  this->do_write(a);
806 
807  // If there's a comment provided, write a tab character and
808  // then the comment.
809  if (std::string(comment_in) != "")
810  *out << "\t " << comment_in;
811 
812  // Go to the next line.
813  *out << '\n';
814 
815  return;
816  }
817 
818  default:
819  libmesh_error_msg("Invalid mode = " << mode);
820  }
821 }
void do_write(T &a)
Helper method for writing different data types.
Definition: xdr_cxx.C:720
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
void do_read(T &a)
Helper method for reading different data types.
Definition: xdr_cxx.C:655
libmesh_assert(j)
UniquePtr< XDR > xdrs
Pointer to the standard XDR struct.
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
bool is_open() const
Definition: xdr_cxx.C:339
template<typename T >
void libMesh::Xdr::data_stream ( T *  val,
const unsigned int  len,
const unsigned int  line_break = libMesh::invalid_uint 
)

Inputs or outputs a raw data stream.

Definition at line 825 of file xdr_cxx.C.

References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), std::min(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

Referenced by operator>>(), libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_nodes(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::CheckpointIO::write_connectivity(), libMesh::CheckpointIO::write_nodes(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

826 {
827  switch (mode)
828  {
829  case ENCODE:
830  {
831 #ifdef LIBMESH_HAVE_XDR
832 
833  libmesh_assert (this->is_open());
834 
835  unsigned int size_of_type = cast_int<unsigned int>(sizeof(T));
836 
837  xdr_vector(xdrs.get(),
838  (char *) val,
839  len,
840  size_of_type,
841  xdr_translator<T>());
842 #else
843  libmesh_error_msg("ERROR: Functionality is not available.\n" \
844  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
845  << "The XDR interface is not available in this installation");
846 
847 #endif
848  return;
849  }
850 
851  case DECODE:
852  {
853 #ifdef LIBMESH_HAVE_XDR
854 
855  libmesh_assert (this->is_open());
856 
857  unsigned int size_of_type = cast_int<unsigned int>(sizeof(T));
858 
859  if (len > 0)
860  xdr_vector(xdrs.get(),
861  (char *) val,
862  len,
863  size_of_type,
864  xdr_translator<T>());
865 #else
866  libmesh_error_msg("ERROR: Functionality is not available.\n" \
867  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
868  << "The XDR interface is not available in this installation");
869 
870 #endif
871  return;
872  }
873 
874  case READ:
875  {
876  libmesh_assert(in.get());
877  libmesh_assert (in->good());
878 
879  for (unsigned int i=0; i<len; i++)
880  {
881  libmesh_assert(in.get());
882  libmesh_assert (in->good());
883  *in >> val[i];
884  }
885 
886  return;
887  }
888 
889  case WRITE:
890  {
891  libmesh_assert(out.get());
892  libmesh_assert (out->good());
893 
894  // We will use scientific notation with a precision of 16
895  // digits in the following output. The desired precision and
896  // format will automatically determine the width.
897  *out << std::scientific
898  << std::setprecision(16);
899 
900  if (line_break == libMesh::invalid_uint)
901  for (unsigned int i=0; i<len; i++)
902  {
903  libmesh_assert(out.get());
904  libmesh_assert (out->good());
905  *out << val[i] << " ";
906  }
907  else
908  {
909  const unsigned imax = std::min(line_break, len);
910  unsigned int cnt=0;
911  while (cnt < len)
912  {
913  for (unsigned int i=0; i<imax; i++)
914  {
915  libmesh_assert(out.get());
916  libmesh_assert (out->good());
917  *out << val[cnt++];
918 
919  // Write a space unless this is the last character on the current line.
920  if (i+1 != imax)
921  *out << " ";
922  }
923  libmesh_assert(out.get());
924  libmesh_assert (out->good());
925  *out << '\n';
926  }
927  }
928 
929  return;
930  }
931 
932  default:
933  libmesh_error_msg("Invalid mode = " << mode);
934  }
935 }
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< XDR > xdrs
Pointer to the standard XDR struct.
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
bool is_open() const
Definition: xdr_cxx.C:339
long double min(long double a, double b)
template<>
void libMesh::Xdr::data_stream ( double *  val,
const unsigned int  len,
const unsigned int  line_break 
)

Definition at line 940 of file xdr_cxx.C.

References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), std::min(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

941 {
942  switch (mode)
943  {
944  case ENCODE:
945  case DECODE:
946  {
947 #ifdef LIBMESH_HAVE_XDR
948 
949  libmesh_assert (this->is_open());
950 
951  if (len > 0)
952  xdr_vector(xdrs.get(),
953  (char *) val,
954  len,
955  sizeof(double),
956  (xdrproc_t) xdr_double);
957 
958 #else
959 
960  libmesh_error_msg("ERROR: Functionality is not available.\n" \
961  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
962  << "The XDR interface is not available in this installation");
963 
964 #endif
965  return;
966  }
967 
968  case READ:
969  {
970  libmesh_assert(in.get());
971  libmesh_assert (in->good());
972 
973  for (unsigned int i=0; i<len; i++)
974  {
975  libmesh_assert(in.get());
976  libmesh_assert (in->good());
977  *in >> val[i];
978  }
979 
980  return;
981  }
982 
983  case WRITE:
984  {
985  libmesh_assert(out.get());
986  libmesh_assert (out->good());
987 
988  // Save stream flags
989  std::ios_base::fmtflags out_flags = out->flags();
990 
991  // We will use scientific notation with a precision of 16
992  // digits in the following output. The desired precision and
993  // format will automatically determine the width.
994  *out << std::scientific
995  << std::setprecision(16);
996 
997  if (line_break == libMesh::invalid_uint)
998  for (unsigned int i=0; i<len; i++)
999  {
1000  libmesh_assert(out.get());
1001  libmesh_assert (out->good());
1002  *out << val[i] << ' ';
1003  }
1004  else
1005  {
1006  const unsigned imax = std::min(line_break, len);
1007  unsigned int cnt=0;
1008  while (cnt < len)
1009  {
1010  for (unsigned int i=0; i<imax; i++)
1011  {
1012  libmesh_assert(out.get());
1013  libmesh_assert (out->good());
1014  *out << val[cnt++];
1015 
1016  // Write a space unless this is the last character on the current line.
1017  if (i+1 != imax)
1018  *out << " ";
1019  }
1020  libmesh_assert(out.get());
1021  libmesh_assert (out->good());
1022  *out << '\n';
1023  }
1024  }
1025 
1026  // Restore stream flags
1027  out->flags(out_flags);
1028 
1029  return;
1030  }
1031 
1032  default:
1033  libmesh_error_msg("Invalid mode = " << mode);
1034  }
1035 }
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< XDR > xdrs
Pointer to the standard XDR struct.
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
bool is_open() const
Definition: xdr_cxx.C:339
long double min(long double a, double b)
template<>
void libMesh::Xdr::data_stream ( float *  val,
const unsigned int  len,
const unsigned int  line_break 
)

Definition at line 1039 of file xdr_cxx.C.

References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), std::min(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

1040 {
1041  switch (mode)
1042  {
1043  case ENCODE:
1044  case DECODE:
1045  {
1046 #ifdef LIBMESH_HAVE_XDR
1047 
1048  libmesh_assert (this->is_open());
1049 
1050  if (len > 0)
1051  xdr_vector(xdrs.get(),
1052  (char *) val,
1053  len,
1054  sizeof(float),
1055  (xdrproc_t) xdr_float);
1056 
1057 #else
1058 
1059  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1060  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1061  << "The XDR interface is not available in this installation");
1062 
1063 #endif
1064  return;
1065  }
1066 
1067  case READ:
1068  {
1069  libmesh_assert(in.get());
1070  libmesh_assert (in->good());
1071 
1072  for (unsigned int i=0; i<len; i++)
1073  {
1074  libmesh_assert(in.get());
1075  libmesh_assert (in->good());
1076  *in >> val[i];
1077  }
1078 
1079  return;
1080  }
1081 
1082  case WRITE:
1083  {
1084  libmesh_assert(out.get());
1085  libmesh_assert (out->good());
1086 
1087  // Save stream flags
1088  std::ios_base::fmtflags out_flags = out->flags();
1089 
1090  // We will use scientific notation with a precision of 16
1091  // digits in the following output. The desired precision and
1092  // format will automatically determine the width.
1093  *out << std::scientific
1094  << std::setprecision(16);
1095 
1096  if (line_break == libMesh::invalid_uint)
1097  for (unsigned int i=0; i<len; i++)
1098  {
1099  libmesh_assert(out.get());
1100  libmesh_assert (out->good());
1101  *out << val[i] << ' ';
1102  }
1103  else
1104  {
1105  const unsigned imax = std::min(line_break, len);
1106  unsigned int cnt=0;
1107  while (cnt < len)
1108  {
1109  for (unsigned int i=0; i<imax; i++)
1110  {
1111  libmesh_assert(out.get());
1112  libmesh_assert (out->good());
1113  *out << val[cnt++];
1114 
1115  // Write a space unless this is the last character on the current line.
1116  if (i+1 != imax)
1117  *out << " ";
1118  }
1119  libmesh_assert(out.get());
1120  libmesh_assert (out->good());
1121  *out << '\n';
1122  }
1123  }
1124 
1125  // Restore stream flags
1126  out->flags(out_flags);
1127 
1128  return;
1129  }
1130 
1131  default:
1132  libmesh_error_msg("Invalid mode = " << mode);
1133  }
1134 }
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< XDR > xdrs
Pointer to the standard XDR struct.
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
bool is_open() const
Definition: xdr_cxx.C:339
long double min(long double a, double b)
template<>
void libMesh::Xdr::data_stream ( long double *  val,
const unsigned int  len,
const unsigned int  line_break 
)

Definition at line 1136 of file xdr_cxx.C.

References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), std::min(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

1137 {
1138  switch (mode)
1139  {
1140  case ENCODE:
1141  case DECODE:
1142  {
1143 #ifdef LIBMESH_HAVE_XDR
1144 
1145  libmesh_assert (this->is_open());
1146 
1147  // FIXME[JWP]: How to implement this for long double? Mac OS
1148  // X defines 'xdr_quadruple' but AFAICT, it does not exist for
1149  // Linux... for now, reading/writing XDR files with long
1150  // doubles drops back to double precision, but you can still
1151  // write long double ASCII files of course.
1152  // if (len > 0)
1153  // xdr_vector(xdrs.get(),
1154  // (char *) val,
1155  // len,
1156  // sizeof(double),
1157  // (xdrproc_t) xdr_quadruple);
1158 
1159  if (len > 0)
1160  {
1161  std::vector<double> io_buffer (len);
1162 
1163  // Fill io_buffer if we are writing.
1164  if (mode == ENCODE)
1165  for (unsigned int i=0, cnt=0; i<len; i++)
1166  io_buffer[cnt++] = val[i];
1167 
1168  xdr_vector(xdrs.get(),
1169  (char *) &io_buffer[0],
1170  len,
1171  sizeof(double),
1172  (xdrproc_t) xdr_double);
1173 
1174  // Fill val array if we are reading.
1175  if (mode == DECODE)
1176  for (unsigned int i=0, cnt=0; i<len; i++)
1177  {
1178  val[i] = io_buffer[cnt++];
1179  }
1180  }
1181 
1182 #else
1183 
1184  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1185  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1186  << "The XDR interface is not available in this installation");
1187 
1188 #endif
1189  return;
1190  }
1191 
1192  case READ:
1193  {
1194  libmesh_assert(in.get());
1195  libmesh_assert (in->good());
1196 
1197  for (unsigned int i=0; i<len; i++)
1198  {
1199  libmesh_assert(in.get());
1200  libmesh_assert (in->good());
1201  *in >> val[i];
1202  }
1203 
1204  return;
1205  }
1206 
1207  case WRITE:
1208  {
1209  libmesh_assert(out.get());
1210  libmesh_assert (out->good());
1211 
1212  // Save stream flags
1213  std::ios_base::fmtflags out_flags = out->flags();
1214 
1215  // We will use scientific notation with a precision of 16
1216  // digits in the following output. The desired precision and
1217  // format will automatically determine the width.
1218  *out << std::scientific
1219  << std::setprecision(16);
1220 
1221  if (line_break == libMesh::invalid_uint)
1222  for (unsigned int i=0; i<len; i++)
1223  {
1224  libmesh_assert(out.get());
1225  libmesh_assert (out->good());
1226  *out << val[i] << ' ';
1227  }
1228  else
1229  {
1230  const unsigned imax = std::min(line_break, len);
1231  unsigned int cnt=0;
1232  while (cnt < len)
1233  {
1234  for (unsigned int i=0; i<imax; i++)
1235  {
1236  libmesh_assert(out.get());
1237  libmesh_assert (out->good());
1238  *out << val[cnt++];
1239 
1240  // Write a space unless this is the last character on the current line.
1241  if (i+1 != imax)
1242  *out << " ";
1243  }
1244  libmesh_assert(out.get());
1245  libmesh_assert (out->good());
1246  *out << '\n';
1247  }
1248  }
1249 
1250  // Restore stream flags
1251  out->flags(out_flags);
1252 
1253  return;
1254  }
1255 
1256  default:
1257  libmesh_error_msg("Invalid mode = " << mode);
1258  }
1259 }
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< XDR > xdrs
Pointer to the standard XDR struct.
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
bool is_open() const
Definition: xdr_cxx.C:339
long double min(long double a, double b)
template<>
void libMesh::Xdr::data_stream ( std::complex< double > *  val,
const unsigned int  len,
const unsigned int  line_break 
)

Definition at line 1264 of file xdr_cxx.C.

References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), std::min(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

1265 {
1266  switch (mode)
1267  {
1268  case ENCODE:
1269  case DECODE:
1270  {
1271 #ifdef LIBMESH_HAVE_XDR
1272 
1273  libmesh_assert (this->is_open());
1274 
1275 
1276  if (len > 0)
1277  {
1278  std::vector<double> io_buffer (2*len);
1279 
1280  // Fill io_buffer if we are writing.
1281  if (mode == ENCODE)
1282  for (unsigned int i=0, cnt=0; i<len; i++)
1283  {
1284  io_buffer[cnt++] = val[i].real();
1285  io_buffer[cnt++] = val[i].imag();
1286  }
1287 
1288  xdr_vector(xdrs.get(),
1289  (char *) &io_buffer[0],
1290  2*len,
1291  sizeof(double),
1292  (xdrproc_t) xdr_double);
1293 
1294  // Fill val array if we are reading.
1295  if (mode == DECODE)
1296  for (unsigned int i=0, cnt=0; i<len; i++)
1297  {
1298  double re = io_buffer[cnt++];
1299  double im = io_buffer[cnt++];
1300  val[i] = std::complex<double>(re,im);
1301  }
1302  }
1303 #else
1304 
1305  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1306  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1307  << "The XDR interface is not available in this installation");
1308 
1309 #endif
1310  return;
1311  }
1312 
1313  case READ:
1314  {
1315  libmesh_assert(in.get());
1316  libmesh_assert (in->good());
1317 
1318  for (unsigned int i=0; i<len; i++)
1319  {
1320  libmesh_assert(in.get());
1321  libmesh_assert (in->good());
1322  double re, im;
1323  *in >> re >> im;
1324  val[i] = std::complex<double>(re,im);
1325  }
1326 
1327  return;
1328  }
1329 
1330  case WRITE:
1331  {
1332  libmesh_assert(out.get());
1333  libmesh_assert (out->good());
1334 
1335  // Save stream flags
1336  std::ios_base::fmtflags out_flags = out->flags();
1337 
1338  // We will use scientific notation with a precision of 16
1339  // digits in the following output. The desired precision and
1340  // format will automatically determine the width.
1341  *out << std::scientific
1342  << std::setprecision(16);
1343 
1344  if (line_break == libMesh::invalid_uint)
1345  for (unsigned int i=0; i<len; i++)
1346  {
1347  libmesh_assert(out.get());
1348  libmesh_assert (out->good());
1349  *out << val[i].real() << ' ';
1350  *out << val[i].imag() << ' ';
1351  }
1352  else
1353  {
1354  const unsigned imax = std::min(line_break, len);
1355  unsigned int cnt=0;
1356  while (cnt < len)
1357  {
1358  for (unsigned int i=0; i<imax; i++)
1359  {
1360  libmesh_assert(out.get());
1361  libmesh_assert (out->good());
1362  *out << val[cnt].real() << ' ';
1363  *out << val[cnt].imag();
1364  cnt++;
1365 
1366  // Write a space unless this is the last character on the current line.
1367  if (i+1 != imax)
1368  *out << " ";
1369  }
1370  libmesh_assert(out.get());
1371  libmesh_assert (out->good());
1372  *out << '\n';
1373  }
1374  }
1375 
1376  // Restore stream flags
1377  out->flags(out_flags);
1378 
1379  return;
1380  }
1381 
1382  default:
1383  libmesh_error_msg("Invalid mode = " << mode);
1384  }
1385 }
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< XDR > xdrs
Pointer to the standard XDR struct.
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
bool is_open() const
Definition: xdr_cxx.C:339
long double min(long double a, double b)
template<>
void libMesh::Xdr::data_stream ( std::complex< long double > *  val,
const unsigned int  len,
const unsigned int  line_break 
)

Definition at line 1388 of file xdr_cxx.C.

References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), std::min(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

1389 {
1390  switch (mode)
1391  {
1392  case ENCODE:
1393  case DECODE:
1394  {
1395 #ifdef LIBMESH_HAVE_XDR
1396 
1397  libmesh_assert (this->is_open());
1398 
1399  // FIXME[JWP]: How to implement this for long double? Mac OS
1400  // X defines 'xdr_quadruple' but AFAICT, it does not exist for
1401  // Linux... for now, reading/writing XDR files with long
1402  // doubles drops back to double precision, but you can still
1403  // write long double ASCII files of course.
1404 
1405  if (len > 0)
1406  {
1407  std::vector<double> io_buffer (2*len);
1408 
1409  // Fill io_buffer if we are writing.
1410  if (mode == ENCODE)
1411  for (unsigned int i=0, cnt=0; i<len; i++)
1412  {
1413  io_buffer[cnt++] = val[i].real();
1414  io_buffer[cnt++] = val[i].imag();
1415  }
1416 
1417  xdr_vector(xdrs.get(),
1418  (char *) &io_buffer[0],
1419  2*len,
1420  sizeof(double),
1421  (xdrproc_t) xdr_double);
1422 
1423  // Fill val array if we are reading.
1424  if (mode == DECODE)
1425  for (unsigned int i=0, cnt=0; i<len; i++)
1426  {
1427  double re = io_buffer[cnt++];
1428  double im = io_buffer[cnt++];
1429  val[i] = std::complex<long double>(re, im);
1430  }
1431  }
1432 #else
1433 
1434  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1435  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1436  << "The XDR interface is not available in this installation");
1437 
1438 #endif
1439  return;
1440  }
1441 
1442  case READ:
1443  {
1444  libmesh_assert(in.get());
1445  libmesh_assert (in->good());
1446 
1447  for (unsigned int i=0; i<len; i++)
1448  {
1449  libmesh_assert(in.get());
1450  libmesh_assert (in->good());
1451  long double re, im;
1452  *in >> re >> im;
1453  val[i] = std::complex<long double>(re,im);
1454  }
1455 
1456  return;
1457  }
1458 
1459  case WRITE:
1460  {
1461  libmesh_assert(out.get());
1462  libmesh_assert (out->good());
1463 
1464 
1465  // Save stream flags
1466  std::ios_base::fmtflags out_flags = out->flags();
1467 
1468  // We will use scientific notation with a precision of
1469  // 'digits10' digits in the following output. The desired
1470  // precision and format will automatically determine the
1471  // width. Note: digit10 is the number of digits (in decimal
1472  // base) that can be represented without change. Equivalent
1473  // to FLT_DIG, DBL_DIG or LDBL_DIG for floating types.
1474  *out << std::scientific
1475  << std::setprecision(std::numeric_limits<long double>::digits10);
1476 
1477  if (line_break == libMesh::invalid_uint)
1478  for (unsigned int i=0; i<len; i++)
1479  {
1480  libmesh_assert(out.get());
1481  libmesh_assert (out->good());
1482  *out << val[i].real() << ' ' << val[i].imag() << ' ';
1483  }
1484  else
1485  {
1486  const unsigned imax = std::min(line_break, len);
1487  unsigned int cnt=0;
1488  while (cnt < len)
1489  {
1490  for (unsigned int i=0; i<imax; i++)
1491  {
1492  libmesh_assert(out.get());
1493  libmesh_assert (out->good());
1494  *out << val[cnt].real() << ' ' << val[cnt].imag();
1495  cnt++;
1496 
1497  // Write a space unless this is the last character on the current line.
1498  if (i+1 != imax)
1499  *out << " ";
1500  }
1501  libmesh_assert(out.get());
1502  libmesh_assert (out->good());
1503  *out << '\n';
1504  }
1505  }
1506 
1507  // Restore stream flags
1508  out->flags(out_flags);
1509 
1510  return;
1511  }
1512 
1513  default:
1514  libmesh_error_msg("Invalid mode = " << mode);
1515  }
1516 }
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< XDR > xdrs
Pointer to the standard XDR struct.
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
bool is_open() const
Definition: xdr_cxx.C:339
long double min(long double a, double b)
template<typename T >
void libMesh::Xdr::do_read ( T &  a)
private

Helper method for reading different data types.

Definition at line 655 of file xdr_cxx.C.

References comm, comm_len, and in.

Referenced by data(), and version().

656 {
657  *in >> a;
658  in->getline(comm, comm_len);
659 }
const int comm_len
A buffer to put comment strings into.
Definition: xdr_cxx.h:238
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:239
template<typename T >
void libMesh::Xdr::do_read ( std::complex< T > &  a)
private

Definition at line 662 of file xdr_cxx.C.

References comm, comm_len, and in.

663 {
664  T r, i;
665  *in >> r >> i;
666  a = std::complex<T>(r,i);
667  in->getline(comm, comm_len);
668 }
const int comm_len
A buffer to put comment strings into.
Definition: xdr_cxx.h:238
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:239
template<typename T >
void libMesh::Xdr::do_read ( std::vector< T > &  a)
private

Definition at line 686 of file xdr_cxx.C.

References comm, comm_len, data(), in, and libMesh::libmesh_assert().

687 {
688  unsigned int length=0;
689  data(length, "# vector length");
690  a.resize(length);
691 
692  for (std::size_t i=0; i<a.size(); i++)
693  {
694  libmesh_assert(in.get());
695  libmesh_assert (in->good());
696  *in >> a[i];
697  }
698  in->getline(comm, comm_len);
699 }
const int comm_len
A buffer to put comment strings into.
Definition: xdr_cxx.h:238
void data(T &a, const char *comment="")
Inputs or outputs a single value.
Definition: xdr_cxx.C:761
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:239
libmesh_assert(j)
template<typename T >
void libMesh::Xdr::do_read ( std::vector< std::complex< T >> &  a)
private

Definition at line 702 of file xdr_cxx.C.

References comm, comm_len, data(), in, and libMesh::libmesh_assert().

703 {
704  unsigned int length=0;
705  data(length, "# vector length x 2 (complex)");
706  a.resize(length);
707 
708  for (std::size_t i=0; i<a.size(); i++)
709  {
710  T r, im;
711  libmesh_assert(in.get());
712  libmesh_assert (in->good());
713  *in >> r >> im;
714  a[i] = std::complex<T>(r,im);
715  }
716  in->getline(comm, comm_len);
717 }
const int comm_len
A buffer to put comment strings into.
Definition: xdr_cxx.h:238
void data(T &a, const char *comment="")
Inputs or outputs a single value.
Definition: xdr_cxx.C:761
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:239
libmesh_assert(j)
template<>
void libMesh::Xdr::do_read ( std::string &  a)

Definition at line 671 of file xdr_cxx.C.

References comm, comm_len, and in.

672 {
673  in->getline(comm, comm_len);
674 
675  a = "";
676 
677  for (unsigned int c=0; c<std::strlen(comm); c++)
678  {
679  if (comm[c] == '\t')
680  break;
681  a.push_back(comm[c]);
682  }
683 }
const int comm_len
A buffer to put comment strings into.
Definition: xdr_cxx.h:238
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:239
template<typename T >
void libMesh::Xdr::do_write ( T &  a)
private

Helper method for writing different data types.

Definition at line 720 of file xdr_cxx.C.

References out.

Referenced by data(), do_write(), and version().

720 { *out << a; }
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
template<typename T >
void libMesh::Xdr::do_write ( std::complex< T > &  a)
private

Definition at line 723 of file xdr_cxx.C.

References out.

724 {
725  *out << a.real() << "\t " << a.imag();
726 }
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
template<typename T >
void libMesh::Xdr::do_write ( std::vector< T > &  a)
private

Definition at line 729 of file xdr_cxx.C.

References data(), do_write(), libMesh::libmesh_assert(), and out.

730 {
731  std::size_t length = a.size();
732  data(length, "# vector length");
733 
734  for (std::size_t i=0; i<a.size(); i++)
735  {
736  libmesh_assert(out.get());
737  libmesh_assert (out->good());
738  this->do_write(a[i]);
739  *out << "\t ";
740  }
741 }
void data(T &a, const char *comment="")
Inputs or outputs a single value.
Definition: xdr_cxx.C:761
void do_write(T &a)
Helper method for writing different data types.
Definition: xdr_cxx.C:720
libmesh_assert(j)
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
template<typename T >
void libMesh::Xdr::do_write ( std::vector< std::complex< T >> &  a)
private

Definition at line 744 of file xdr_cxx.C.

References data(), do_write(), libMesh::libmesh_assert(), and out.

745 {
746  std::size_t length=a.size();
747  data(length, "# vector length x 2 (complex)");
748 
749  for (std::size_t i=0; i<a.size(); i++)
750  {
751  libmesh_assert(out.get());
752  libmesh_assert (out->good());
753  this->do_write(a[i]);
754  *out << "\t ";
755  }
756 }
void data(T &a, const char *comment="")
Inputs or outputs a single value.
Definition: xdr_cxx.C:761
void do_write(T &a)
Helper method for writing different data types.
Definition: xdr_cxx.C:720
libmesh_assert(j)
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
bool libMesh::Xdr::is_eof ( )
Returns
true if the Xdr file being read is at End-Of-File.
Note
This is not a const method - the only portable way to test for an impending EOF is to peek at the next byte of the file first, which may set the eof flag on the istream.

Definition at line 389 of file xdr_cxx.C.

References libMesh::DECODE, libMesh::ENCODE, fp, in, libMesh::libmesh_assert(), mode, libMesh::MeshTools::Subdivision::next, libMesh::READ, libMesh::x, and xdr_MAX_STRING_LENGTH.

390 {
391  switch (mode)
392  {
393  case ENCODE:
394  case DECODE:
395  {
396 #ifdef LIBMESH_HAVE_XDR
398 
399  // Are we already at eof?
400  if (feof(fp))
401  return true;
402 
403  // Or about to reach eof?
404  int next = fgetc(fp);
405  if (next == EOF)
406  {
407  // We should *only* be at EOF, not otherwise broken
408  libmesh_assert(feof(fp));
409  libmesh_assert(!ferror(fp));
410 
411  // Reset the EOF indicator
412  clearerr(fp);
413  libmesh_assert(!ferror(fp));
414 
415  // We saw EOF
416  return true;
417  }
418 
419  // We didn't see EOF; restore whatever we did see.
420  ungetc(next, fp);
421  break;
422 #else
423 
424  libmesh_error_msg("ERROR: Functionality is not available.\n" \
425  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
426  << "The XDR interface is not available in this installation");
427 
428  return false;
429 
430 #endif
431 
432  }
433  case READ:
434  {
435  libmesh_assert(in.get());
436 
437  // Are we already at eof?
438  if (in->eof())
439  return true;
440 
441  // Or about to reach eof?
442  int next = in->peek();
443  if (next == EOF)
444  {
445  // We should *only* be at EOF, not otherwise broken
446  libmesh_assert(in->eof());
447  libmesh_assert(!in->fail());
448 
449  // Reset the EOF indicator
450  in->clear();
451  libmesh_assert(in->good());
452 
453  // We saw EOF
454  return true;
455  }
456  break;
457  }
458  default:
459  libmesh_error();
460  }
461 
462  return false;
463 }
FILE * fp
File pointer.
Definition: xdr_cxx.h:221
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
libmesh_assert(j)
static const unsigned int next[3]
A lookup table for the increment modulo 3 operation, for iterating through the three nodes per elemen...
bool libMesh::Xdr::is_open ( ) const
Returns
true if the Xdr file is open, false if it is closed.

Definition at line 339 of file xdr_cxx.C.

References libMesh::DECODE, libMesh::ENCODE, fp, in, libmesh_nullptr, mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

Referenced by data(), data_stream(), and libMesh::System::read_parallel_data().

340 {
341  switch (mode)
342  {
343  case ENCODE:
344  case DECODE:
345  {
346 #ifdef LIBMESH_HAVE_XDR
347 
348  if (fp)
349  if (xdrs)
350  return true;
351 
352  return false;
353 
354 #else
355 
356  libmesh_error_msg("ERROR: Functionality is not available.\n" \
357  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
358  << "The XDR interface is not available in this installation");
359 
360  return false;
361 
362 #endif
363 
364  }
365 
366  case READ:
367  {
368  if (in.get() != libmesh_nullptr)
369  return in->good();
370  return false;
371  }
372 
373  case WRITE:
374  {
375  if (out.get() != libmesh_nullptr)
376  return out->good();
377  return false;
378  }
379 
380  default:
381  libmesh_error_msg("Invalid mode = " << mode);
382  }
383 
384  return false;
385 }
FILE * fp
File pointer.
Definition: xdr_cxx.h:221
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
const class libmesh_nullptr_t libmesh_nullptr
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
UniquePtr< XDR > xdrs
Pointer to the standard XDR struct.
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
void libMesh::Xdr::open ( const std::string &  name)

Opens the file.

Definition at line 160 of file xdr_cxx.C.

References bzipped_file, libMesh::DECODE, libMesh::ENCODE, file_name, fp, gzipped_file, in, libMesh::libmesh_assert(), mode, libMesh::Quality::name(), out, libMesh::out, libMesh::READ, libMesh::WRITE, xdrs, and xzipped_file.

Referenced by Xdr().

161 {
162  file_name = name;
163 
164  if (name == "")
165  return;
166 
167  switch (mode)
168  {
169  case ENCODE:
170  case DECODE:
171  {
172 #ifdef LIBMESH_HAVE_XDR
173 
174  fp = fopen(name.c_str(), (mode == ENCODE) ? "w" : "r");
175  if (!fp)
176  libmesh_file_error(name.c_str());
177  xdrs.reset(new XDR);
178  xdrstdio_create (xdrs.get(), fp, (mode == ENCODE) ? XDR_ENCODE : XDR_DECODE);
179 #else
180 
181  libmesh_error_msg("ERROR: Functionality is not available.\n" \
182  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
183  << "The XDR interface is not available in this installation");
184 
185 #endif
186  return;
187 
188  }
189 
190  case READ:
191  {
192  gzipped_file = (name.size() - name.rfind(".gz") == 3);
193  bzipped_file = (name.size() - name.rfind(".bz2") == 4);
194  xzipped_file = (name.size() - name.rfind(".xz") == 3);
195 
196  if (gzipped_file)
197  {
198 #ifdef LIBMESH_HAVE_GZSTREAM
199  igzstream * inf = new igzstream;
200  libmesh_assert(inf);
201  in.reset(inf);
202  inf->open(name.c_str(), std::ios::in);
203 #else
204  libmesh_error_msg("ERROR: need gzstream to handle .gz files!!!");
205 #endif
206  }
207  else
208  {
209  std::ifstream * inf = new std::ifstream;
210  libmesh_assert(inf);
211  in.reset(inf);
212 
213  std::string new_name = unzip_file(name);
214 
215  inf->open(new_name.c_str(), std::ios::in);
216  }
217 
218  libmesh_assert(in.get());
219 
220  if (!in->good())
221  libmesh_file_error(name);
222  return;
223  }
224 
225  case WRITE:
226  {
227  gzipped_file = (name.size() - name.rfind(".gz") == 3);
228  bzipped_file = (name.size() - name.rfind(".bz2") == 4);
229  xzipped_file = (name.size() - name.rfind(".xz") == 3);
230 
231  if (gzipped_file)
232  {
233 #ifdef LIBMESH_HAVE_GZSTREAM
234  ogzstream * outf = new ogzstream;
235  libmesh_assert(outf);
236  out.reset(outf);
237  outf->open(name.c_str(), std::ios::out);
238 #else
239  libmesh_error_msg("ERROR: need gzstream to handle .gz files!!!");
240 #endif
241  }
242  else
243  {
244  std::ofstream * outf = new std::ofstream;
245  libmesh_assert(outf);
246  out.reset(outf);
247 
248  std::string new_name = name;
249 
250  if (bzipped_file)
251  new_name.erase(new_name.end() - 4, new_name.end());
252 
253  if (xzipped_file)
254  new_name.erase(new_name.end() - 3, new_name.end());
255 
256  outf->open(new_name.c_str(), std::ios::out);
257  }
258 
259  libmesh_assert(out.get());
260  libmesh_assert (out->good());
261  return;
262  }
263 
264  default:
265  libmesh_error_msg("Invalid mode = " << mode);
266  }
267 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
FILE * fp
File pointer.
Definition: xdr_cxx.h:221
std::string file_name
The file name.
Definition: xdr_cxx.h:208
UniquePtr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:228
bool xzipped_file
Definition: xdr_cxx.h:244
bool bzipped_file
Definition: xdr_cxx.h:244
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:203
bool gzipped_file
Are we reading/writing zipped files?
Definition: xdr_cxx.h:244
libmesh_assert(j)
UniquePtr< XDR > xdrs
Pointer to the standard XDR struct.
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:233
OStreamProxy out
template<typename T >
Xdr& libMesh::Xdr::operator<< ( T &  a)

Same, but provides an ostream like interface.

Definition at line 139 of file xdr_cxx.h.

References data(), libMesh::libmesh_assert(), and writing().

139 { libmesh_assert (writing()); data(a); return *this; }
void data(T &a, const char *comment="")
Inputs or outputs a single value.
Definition: xdr_cxx.C:761
libmesh_assert(j)
bool writing() const
Definition: xdr_cxx.h:119
template<typename T >
Xdr& libMesh::Xdr::operator>> ( T &  a)

Same, but provides an istream like interface.

Definition at line 145 of file xdr_cxx.h.

References comment(), data(), data_stream(), libMesh::invalid_uint, libMesh::libmesh_assert(), and reading().

145 { libmesh_assert (reading()); data(a); return *this; }
void data(T &a, const char *comment="")
Inputs or outputs a single value.
Definition: xdr_cxx.C:761
libmesh_assert(j)
bool reading() const
Definition: xdr_cxx.h:113
bool libMesh::Xdr::reading ( ) const
void libMesh::Xdr::set_version ( int  ver)

Sets the version of the file that is being read.

Definition at line 161 of file xdr_cxx.h.

References version_number.

Referenced by libMesh::EquationSystems::_read_impl(), and libMesh::EquationSystems::write().

161 { version_number = ver; }
int version_number
Version of the file being read.
Definition: xdr_cxx.h:249
int libMesh::Xdr::version ( ) const

Gets the version of the file that is being read.

Definition at line 166 of file xdr_cxx.h.

References do_read(), do_write(), and version_number.

Referenced by libMesh::System::read_header(), and libMesh::System::read_serialized_vector().

166 { return version_number; }
int version_number
Version of the file being read.
Definition: xdr_cxx.h:249
bool libMesh::Xdr::writing ( ) const

Member Data Documentation

bool libMesh::Xdr::bzipped_file
private

Definition at line 244 of file xdr_cxx.h.

Referenced by close(), and open().

char libMesh::Xdr::comm[xdr_MAX_STRING_LENGTH]
private

Definition at line 239 of file xdr_cxx.h.

Referenced by comment(), and do_read().

const int libMesh::Xdr::comm_len
private

A buffer to put comment strings into.

Definition at line 238 of file xdr_cxx.h.

Referenced by comment(), and do_read().

std::string libMesh::Xdr::file_name
private

The file name.

Definition at line 208 of file xdr_cxx.h.

Referenced by close(), and open().

FILE* libMesh::Xdr::fp
private

File pointer.

Definition at line 221 of file xdr_cxx.h.

Referenced by close(), is_eof(), is_open(), and open().

bool libMesh::Xdr::gzipped_file
private

Are we reading/writing zipped files?

Definition at line 244 of file xdr_cxx.h.

Referenced by open().

UniquePtr<std::istream> libMesh::Xdr::in
private

The input file stream.

Definition at line 228 of file xdr_cxx.h.

Referenced by close(), comment(), data(), data_stream(), do_read(), is_eof(), is_open(), and open().

const XdrMODE libMesh::Xdr::mode
private

The mode used for accessing the file.

Definition at line 203 of file xdr_cxx.h.

Referenced by access_mode(), close(), comment(), data(), data_stream(), is_eof(), is_open(), open(), reading(), and writing().

UniquePtr<std::ostream> libMesh::Xdr::out
private

The output file stream.

Definition at line 233 of file xdr_cxx.h.

Referenced by close(), comment(), data(), data_stream(), do_write(), is_open(), and open().

int libMesh::Xdr::version_number
private

Version of the file being read.

Definition at line 249 of file xdr_cxx.h.

Referenced by set_version(), and version().

UniquePtr<XDR> libMesh::Xdr::xdrs
private

Pointer to the standard XDR struct.

See the standard header file rpc/rpc.h for more information.

Definition at line 216 of file xdr_cxx.h.

Referenced by close(), data(), data_stream(), is_open(), and open().

bool libMesh::Xdr::xzipped_file
private

Definition at line 244 of file xdr_cxx.h.

Referenced by close(), and open().


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