libMesh::Xdr Class Reference

C++ interface for the XDR (eXternal Data Representation) format. More...

#include <xdr_cxx.h>

Public Member Functions

 Xdr (const std::string &name="", const XdrMODE m=UNKNOWN)
 
 ~Xdr ()
 
void open (const std::string &name)
 
void close ()
 
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="")
 
template<typename T >
Xdroperator<< (T &a)
 
template<typename T >
Xdroperator>> (T &a)
 
template<typename T >
void data_stream (T *val, const unsigned int len, const unsigned int line_break=libMesh::invalid_uint)
 
void comment (std::string &)
 
void set_version (int ver)
 
int version () const
 
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)
 
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)
 
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
 
std::string file_name
 
std::unique_ptr< XDR > xdrs
 
FILE * fp
 
std::unique_ptr< std::istream > in
 
std::unique_ptr< std::ostream > out
 
const int comm_len
 
char comm [xdr_MAX_STRING_LENGTH]
 
bool gzipped_file
 
bool bzipped_file
 
bool xzipped_file
 
int version_number
 

Detailed Description

C++ interface for the XDR (eXternal Data Representation) format.

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

Definition at line 66 of file xdr_cxx.h.

Constructor & Destructor Documentation

◆ Xdr()

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 136 of file xdr_cxx.C.

References open().

137  :
138  mode(m),
139  file_name(name),
140 #ifdef LIBMESH_HAVE_XDR
141  fp(nullptr),
142 #endif
143  in(),
144  out(),
146  gzipped_file(false),
147  bzipped_file(false),
148  xzipped_file(false)
149 {
150  this->open(name);
151 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
FILE * fp
Definition: xdr_cxx.h:219
const int comm_len
Definition: xdr_cxx.h:236
std::string file_name
Definition: xdr_cxx.h:206
const unsigned int xdr_MAX_STRING_LENGTH
Definition: xdr_cxx.h:44
bool xzipped_file
Definition: xdr_cxx.h:242
bool bzipped_file
Definition: xdr_cxx.h:242
const XdrMODE mode
Definition: xdr_cxx.h:201
bool gzipped_file
Definition: xdr_cxx.h:242
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231
void open(const std::string &name)
Definition: xdr_cxx.C:162

◆ ~Xdr()

libMesh::Xdr::~Xdr ( )

Destructor. Closes the file if it is open.

Definition at line 155 of file xdr_cxx.C.

References close().

156 {
157  this->close();
158 }
void close()
Definition: xdr_cxx.C:273

Member Function Documentation

◆ access_mode()

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

Definition at line 123 of file xdr_cxx.h.

References mode.

123 { return mode; }
const XdrMODE mode
Definition: xdr_cxx.h:201

◆ close()

void libMesh::Xdr::close ( )

Closes the file if it is open.

Definition at line 273 of file xdr_cxx.C.

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

Referenced by libMesh::EquationSystems::_read_impl(), libMesh::CheckpointIO::read(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), and ~Xdr().

274 {
275  switch (mode)
276  {
277  case ENCODE:
278  case DECODE:
279  {
280 #ifdef LIBMESH_HAVE_XDR
281 
282  if (xdrs)
283  {
284  xdr_destroy (xdrs.get());
285  xdrs.reset();
286  }
287 
288  if (fp)
289  {
290  fflush(fp);
291  fclose(fp);
292  fp = nullptr;
293  }
294 #else
295 
296  libmesh_error_msg("ERROR: Functionality is not available.\n" \
297  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
298  << "The XDR interface is not available in this installation");
299 
300 #endif
301  file_name = "";
302  return;
303  }
304 
305  case READ:
306  {
307  if (in.get() != nullptr)
308  {
309  in.reset();
310 
311  if (bzipped_file || xzipped_file)
312  remove_unzipped_file(file_name);
313  }
314  file_name = "";
315  return;
316  }
317 
318  case WRITE:
319  {
320  if (out.get() != nullptr)
321  {
322  out.reset();
323 
324  if (bzipped_file)
325  bzip_file(std::string(file_name.begin(), file_name.end()-4));
326 
327  else if (xzipped_file)
328  xzip_file(std::string(file_name.begin(), file_name.end()-3));
329  }
330  file_name = "";
331  return;
332  }
333 
334  default:
335  libmesh_error_msg("Invalid mode = " << mode);
336  }
337 }
FILE * fp
Definition: xdr_cxx.h:219
std::string file_name
Definition: xdr_cxx.h:206
bool xzipped_file
Definition: xdr_cxx.h:242
bool bzipped_file
Definition: xdr_cxx.h:242
const XdrMODE mode
Definition: xdr_cxx.h:201
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231
std::unique_ptr< XDR > xdrs
Definition: xdr_cxx.h:214

◆ comment()

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, mode, out, libMesh::READ, and libMesh::WRITE.

Referenced by 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
Definition: xdr_cxx.h:236
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:237
const XdrMODE mode
Definition: xdr_cxx.h:201
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231

◆ data()

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(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

Referenced by libMesh::EquationSystems::_read_impl(), do_read(), do_write(), operator<<(), operator>>(), 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::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::select_split_config(), libMesh::XdrIO::write(), libMesh::CheckpointIO::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 
770  libmesh_assert (is_open());
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)
Definition: xdr_cxx.C:720
const XdrMODE mode
Definition: xdr_cxx.h:201
void do_read(T &a)
Definition: xdr_cxx.C:655
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231
std::unique_ptr< XDR > xdrs
Definition: xdr_cxx.h:214
bool is_open() const
Definition: xdr_cxx.C:341

◆ data_stream() [1/6]

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(), std::min(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

Referenced by 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
Definition: libmesh.h:245
const XdrMODE mode
Definition: xdr_cxx.h:201
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231
std::unique_ptr< XDR > xdrs
Definition: xdr_cxx.h:214
bool is_open() const
Definition: xdr_cxx.C:341
long double min(long double a, double b)

◆ data_stream() [2/6]

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(), 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
Definition: libmesh.h:245
const XdrMODE mode
Definition: xdr_cxx.h:201
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231
std::unique_ptr< XDR > xdrs
Definition: xdr_cxx.h:214
bool is_open() const
Definition: xdr_cxx.C:341
long double min(long double a, double b)

◆ data_stream() [3/6]

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(), 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
Definition: libmesh.h:245
const XdrMODE mode
Definition: xdr_cxx.h:201
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231
std::unique_ptr< XDR > xdrs
Definition: xdr_cxx.h:214
bool is_open() const
Definition: xdr_cxx.C:341
long double min(long double a, double b)

◆ data_stream() [4/6]

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(), 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++] = double(val[i]);
1167 
1168  xdr_vector(xdrs.get(),
1169  reinterpret_cast<char *>(io_buffer.data()),
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
Definition: libmesh.h:245
const XdrMODE mode
Definition: xdr_cxx.h:201
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231
std::unique_ptr< XDR > xdrs
Definition: xdr_cxx.h:214
bool is_open() const
Definition: xdr_cxx.C:341
long double min(long double a, double b)

◆ data_stream() [5/6]

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(), 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  reinterpret_cast<char *>(io_buffer.data()),
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
Definition: libmesh.h:245
const XdrMODE mode
Definition: xdr_cxx.h:201
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231
std::unique_ptr< XDR > xdrs
Definition: xdr_cxx.h:214
bool is_open() const
Definition: xdr_cxx.C:341
long double min(long double a, double b)

◆ data_stream() [6/6]

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(), 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  reinterpret_cast<char *>(io_buffer.data()),
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
Definition: libmesh.h:245
const XdrMODE mode
Definition: xdr_cxx.h:201
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231
std::unique_ptr< XDR > xdrs
Definition: xdr_cxx.h:214
bool is_open() const
Definition: xdr_cxx.C:341
long double min(long double a, double b)

◆ do_read() [1/5]

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

656 {
657  *in >> a;
658  in->getline(comm, comm_len);
659 }
const int comm_len
Definition: xdr_cxx.h:236
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:237
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226

◆ do_read() [2/5]

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
Definition: xdr_cxx.h:236
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:237
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226

◆ do_read() [3/5]

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(), and in.

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
Definition: xdr_cxx.h:236
void data(T &a, const char *comment="")
Definition: xdr_cxx.C:761
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:237
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226

◆ do_read() [4/5]

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(), and in.

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
Definition: xdr_cxx.h:236
void data(T &a, const char *comment="")
Definition: xdr_cxx.C:761
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:237
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226

◆ do_read() [5/5]

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
Definition: xdr_cxx.h:236
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:237
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226

◆ do_write() [1/4]

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(), and do_write().

720 { *out << a; }
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231

◆ do_write() [2/4]

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 }
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231

◆ do_write() [3/4]

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(), 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="")
Definition: xdr_cxx.C:761
void do_write(T &a)
Definition: xdr_cxx.C:720
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231

◆ do_write() [4/4]

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(), 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="")
Definition: xdr_cxx.C:761
void do_write(T &a)
Definition: xdr_cxx.C:720
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231

◆ is_eof()

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 391 of file xdr_cxx.C.

References libMesh::DECODE, libMesh::ENCODE, fp, in, mode, libMesh::MeshTools::Subdivision::next, and libMesh::READ.

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

◆ is_open()

bool libMesh::Xdr::is_open ( ) const
Returns
true if the Xdr file is open, false if it is closed.

Definition at line 341 of file xdr_cxx.C.

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

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

342 {
343  switch (mode)
344  {
345  case ENCODE:
346  case DECODE:
347  {
348 #ifdef LIBMESH_HAVE_XDR
349 
350  if (fp)
351  if (xdrs)
352  return true;
353 
354  return false;
355 
356 #else
357 
358  libmesh_error_msg("ERROR: Functionality is not available.\n" \
359  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
360  << "The XDR interface is not available in this installation");
361 
362  return false;
363 
364 #endif
365 
366  }
367 
368  case READ:
369  {
370  if (in.get() != nullptr)
371  return in->good();
372  return false;
373  }
374 
375  case WRITE:
376  {
377  if (out.get() != nullptr)
378  return out->good();
379  return false;
380  }
381 
382  default:
383  libmesh_error_msg("Invalid mode = " << mode);
384  }
385 
386  return false;
387 }
FILE * fp
Definition: xdr_cxx.h:219
const XdrMODE mode
Definition: xdr_cxx.h:201
std::unique_ptr< std::istream > in
Definition: xdr_cxx.h:226
std::unique_ptr< std::ostream > out
Definition: xdr_cxx.h:231
std::unique_ptr< XDR > xdrs
Definition: xdr_cxx.h:214

◆ open()

void libMesh::Xdr::open ( const std::string &  name)

Opens the file.

Definition at line 162 of file xdr_cxx.C.

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

Referenced by Xdr().

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

◆ operator<<()

template<typename T >
Xdr& libMesh::Xdr::operator<< ( T &  a)
inline

Same, but provides an ostream like interface.

Definition at line 137 of file xdr_cxx.h.

References data(), and writing().

137 { libmesh_assert (writing()); data(a); return *this; }
bool writing() const
Definition: xdr_cxx.h:117
void data(T &a, const char *comment="")
Definition: xdr_cxx.C:761

◆ operator>>()

template<typename T >
Xdr& libMesh::Xdr::operator>> ( T &  a)
inline

Same, but provides an istream like interface.

Definition at line 143 of file xdr_cxx.h.

References data(), and reading().

143 { libmesh_assert (reading()); data(a); return *this; }
void data(T &a, const char *comment="")
Definition: xdr_cxx.C:761
bool reading() const
Definition: xdr_cxx.h:111

◆ reading()

◆ set_version()

void libMesh::Xdr::set_version ( int  ver)
inline

Sets the version of the file that is being read

Definition at line 159 of file xdr_cxx.h.

References version_number.

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

159 { version_number = ver; }
int version_number
Definition: xdr_cxx.h:247

◆ version()

int libMesh::Xdr::version ( ) const
inline

Gets the version of the file that is being read

Definition at line 164 of file xdr_cxx.h.

References version_number.

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

164 { return version_number; }
int version_number
Definition: xdr_cxx.h:247

◆ writing()

Member Data Documentation

◆ bzipped_file

bool libMesh::Xdr::bzipped_file
private

Definition at line 242 of file xdr_cxx.h.

Referenced by close(), and open().

◆ comm

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

Definition at line 237 of file xdr_cxx.h.

Referenced by comment(), and do_read().

◆ comm_len

const int libMesh::Xdr::comm_len
private

A buffer to put comment strings into.

Definition at line 236 of file xdr_cxx.h.

Referenced by comment(), and do_read().

◆ file_name

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

The file name

Definition at line 206 of file xdr_cxx.h.

Referenced by close(), and open().

◆ fp

FILE* libMesh::Xdr::fp
private

File pointer.

Definition at line 219 of file xdr_cxx.h.

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

◆ gzipped_file

bool libMesh::Xdr::gzipped_file
private

Are we reading/writing zipped files?

Definition at line 242 of file xdr_cxx.h.

Referenced by open().

◆ in

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

The input file stream.

Definition at line 226 of file xdr_cxx.h.

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

◆ mode

const XdrMODE libMesh::Xdr::mode
private

The mode used for accessing the file.

Definition at line 201 of file xdr_cxx.h.

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

◆ out

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

The output file stream.

Definition at line 231 of file xdr_cxx.h.

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

◆ version_number

int libMesh::Xdr::version_number
private

Version of the file being read

Definition at line 247 of file xdr_cxx.h.

Referenced by set_version(), and version().

◆ xdrs

std::unique_ptr<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 214 of file xdr_cxx.h.

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

◆ xzipped_file

bool libMesh::Xdr::xzipped_file
private

Definition at line 242 of file xdr_cxx.h.

Referenced by close(), and open().


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