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
 
UniquePtr< XDR > xdrs
 
FILE * fp
 
UniquePtr< std::istream > in
 
UniquePtr< 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 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)
Definition: elem_quality.C:39
FILE * fp
Definition: xdr_cxx.h:221
const int comm_len
Definition: xdr_cxx.h:238
std::string file_name
Definition: xdr_cxx.h:208
const unsigned int xdr_MAX_STRING_LENGTH
Definition: xdr_cxx.h:46
UniquePtr< std::istream > in
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
Definition: xdr_cxx.h:203
bool gzipped_file
Definition: xdr_cxx.h:244
UniquePtr< std::ostream > out
Definition: xdr_cxx.h:233
void open(const std::string &name)
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()
Definition: xdr_cxx.C:271

Member Function Documentation

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

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

125 { return mode; }
const XdrMODE mode
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::XdrIO::write(), 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
Definition: xdr_cxx.h:221
std::string file_name
Definition: xdr_cxx.h:208
UniquePtr< std::istream > in
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
Definition: xdr_cxx.h:203
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
Definition: xdr_cxx.h:233
void libMesh::Xdr::comment ( std::string &  comment_in)

Writes or reads (ignores) a comment line.

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

1468 {
1469  switch (mode)
1470  {
1471  case ENCODE:
1472  case DECODE:
1473  {
1474  return;
1475  }
1476 
1477  case READ:
1478  {
1479  libmesh_assert(in.get());
1480  libmesh_assert (in->good());
1481  in->getline(comm, comm_len);
1482  return;
1483  }
1484 
1485  case WRITE:
1486  {
1487  libmesh_assert(out.get());
1488  libmesh_assert (out->good());
1489  *out << "\t " << comment_in << '\n';
1490  return;
1491  }
1492 
1493  default:
1494  libmesh_error_msg("Invalid mode = " << mode);
1495  }
1496 }
const int comm_len
Definition: xdr_cxx.h:238
UniquePtr< std::istream > in
Definition: xdr_cxx.h:228
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:239
const XdrMODE mode
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< std::ostream > out
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 709 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::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::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().

710 {
711  switch (mode)
712  {
713  case ENCODE:
714  case DECODE:
715  {
716 #ifdef LIBMESH_HAVE_XDR
717 
719 
720  xdr_translate(xdrs.get(), a);
721 
722 #else
723 
724  libmesh_error_msg("ERROR: Functionality is not available.\n" \
725  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
726  << "The XDR interface is not available in this installation");
727 
728 #endif
729  return;
730  }
731 
732  case READ:
733  {
734  libmesh_assert(in.get());
735  libmesh_assert (in->good());
736 
737  this->do_read(a);
738 
739  return;
740  }
741 
742  case WRITE:
743  {
744  libmesh_assert(out.get());
745  libmesh_assert (out->good());
746 
747  // We will use scientific notation with a precision of 16
748  // digits in the following output. The desired precision and
749  // format will automatically determine the width.
750  *out << std::scientific
751  << std::setprecision(16);
752 
753  this->do_write(a);
754 
755  // If there's a comment provided, write a tab character and
756  // then the comment.
757  if (std::string(comment_in) != "")
758  *out << "\t " << comment_in;
759 
760  // Go to the next line.
761  *out << '\n';
762 
763  return;
764  }
765 
766  default:
767  libmesh_error_msg("Invalid mode = " << mode);
768  }
769 }
void do_write(T &a)
Definition: xdr_cxx.C:668
UniquePtr< std::istream > in
Definition: xdr_cxx.h:228
const XdrMODE mode
Definition: xdr_cxx.h:203
void do_read(T &a)
Definition: xdr_cxx.C:603
libmesh_assert(j)
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
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 773 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().

774 {
775  switch (mode)
776  {
777  case ENCODE:
778  {
779 #ifdef LIBMESH_HAVE_XDR
780 
781  libmesh_assert (this->is_open());
782 
783  unsigned int size_of_type = cast_int<unsigned int>(sizeof(T));
784 
785  xdr_vector(xdrs.get(),
786  (char *) val,
787  len,
788  size_of_type,
789  xdr_translator<T>());
790 #else
791  libmesh_error_msg("ERROR: Functionality is not available.\n" \
792  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
793  << "The XDR interface is not available in this installation");
794 
795 #endif
796  return;
797  }
798 
799  case DECODE:
800  {
801 #ifdef LIBMESH_HAVE_XDR
802 
803  libmesh_assert (this->is_open());
804 
805  unsigned int size_of_type = cast_int<unsigned int>(sizeof(T));
806 
807  if (len > 0)
808  xdr_vector(xdrs.get(),
809  (char *) val,
810  len,
811  size_of_type,
812  xdr_translator<T>());
813 #else
814  libmesh_error_msg("ERROR: Functionality is not available.\n" \
815  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
816  << "The XDR interface is not available in this installation");
817 
818 #endif
819  return;
820  }
821 
822  case READ:
823  {
824  libmesh_assert(in.get());
825  libmesh_assert (in->good());
826 
827  for (unsigned int i=0; i<len; i++)
828  {
829  libmesh_assert(in.get());
830  libmesh_assert (in->good());
831  *in >> val[i];
832  }
833 
834  return;
835  }
836 
837  case WRITE:
838  {
839  libmesh_assert(out.get());
840  libmesh_assert (out->good());
841 
842  // We will use scientific notation with a precision of 16
843  // digits in the following output. The desired precision and
844  // format will automatically determine the width.
845  *out << std::scientific
846  << std::setprecision(16);
847 
848  if (line_break == libMesh::invalid_uint)
849  for (unsigned int i=0; i<len; i++)
850  {
851  libmesh_assert(out.get());
852  libmesh_assert (out->good());
853  *out << val[i] << " ";
854  }
855  else
856  {
857  const unsigned imax = std::min(line_break, len);
858  unsigned int cnt=0;
859  while (cnt < len)
860  {
861  for (unsigned int i=0; i<imax; i++)
862  {
863  libmesh_assert(out.get());
864  libmesh_assert (out->good());
865  *out << val[cnt++];
866 
867  // Write a space unless this is the last character on the current line.
868  if (i+1 != imax)
869  *out << " ";
870  }
871  libmesh_assert(out.get());
872  libmesh_assert (out->good());
873  *out << '\n';
874  }
875  }
876 
877  return;
878  }
879 
880  default:
881  libmesh_error_msg("Invalid mode = " << mode);
882  }
883 }
const unsigned int invalid_uint
Definition: libmesh.h:184
UniquePtr< std::istream > in
Definition: xdr_cxx.h:228
const XdrMODE mode
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
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 888 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.

889 {
890  switch (mode)
891  {
892  case ENCODE:
893  case DECODE:
894  {
895 #ifdef LIBMESH_HAVE_XDR
896 
897  libmesh_assert (this->is_open());
898 
899  if (len > 0)
900  xdr_vector(xdrs.get(),
901  (char *) val,
902  len,
903  sizeof(double),
904  (xdrproc_t) xdr_double);
905 
906 #else
907 
908  libmesh_error_msg("ERROR: Functionality is not available.\n" \
909  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
910  << "The XDR interface is not available in this installation");
911 
912 #endif
913  return;
914  }
915 
916  case READ:
917  {
918  libmesh_assert(in.get());
919  libmesh_assert (in->good());
920 
921  for (unsigned int i=0; i<len; i++)
922  {
923  libmesh_assert(in.get());
924  libmesh_assert (in->good());
925  *in >> val[i];
926  }
927 
928  return;
929  }
930 
931  case WRITE:
932  {
933  libmesh_assert(out.get());
934  libmesh_assert (out->good());
935 
936  // Save stream flags
937  std::ios_base::fmtflags out_flags = out->flags();
938 
939  // We will use scientific notation with a precision of 16
940  // digits in the following output. The desired precision and
941  // format will automatically determine the width.
942  *out << std::scientific
943  << std::setprecision(16);
944 
945  if (line_break == libMesh::invalid_uint)
946  for (unsigned int i=0; i<len; i++)
947  {
948  libmesh_assert(out.get());
949  libmesh_assert (out->good());
950  *out << val[i] << ' ';
951  }
952  else
953  {
954  const unsigned imax = std::min(line_break, len);
955  unsigned int cnt=0;
956  while (cnt < len)
957  {
958  for (unsigned int i=0; i<imax; i++)
959  {
960  libmesh_assert(out.get());
961  libmesh_assert (out->good());
962  *out << val[cnt++];
963 
964  // Write a space unless this is the last character on the current line.
965  if (i+1 != imax)
966  *out << " ";
967  }
968  libmesh_assert(out.get());
969  libmesh_assert (out->good());
970  *out << '\n';
971  }
972  }
973 
974  // Restore stream flags
975  out->flags(out_flags);
976 
977  return;
978  }
979 
980  default:
981  libmesh_error_msg("Invalid mode = " << mode);
982  }
983 }
const unsigned int invalid_uint
Definition: libmesh.h:184
UniquePtr< std::istream > in
Definition: xdr_cxx.h:228
const XdrMODE mode
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
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 987 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.

988 {
989  switch (mode)
990  {
991  case ENCODE:
992  case DECODE:
993  {
994 #ifdef LIBMESH_HAVE_XDR
995 
996  libmesh_assert (this->is_open());
997 
998  if (len > 0)
999  xdr_vector(xdrs.get(),
1000  (char *) val,
1001  len,
1002  sizeof(float),
1003  (xdrproc_t) xdr_float);
1004 
1005 #else
1006 
1007  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1008  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1009  << "The XDR interface is not available in this installation");
1010 
1011 #endif
1012  return;
1013  }
1014 
1015  case READ:
1016  {
1017  libmesh_assert(in.get());
1018  libmesh_assert (in->good());
1019 
1020  for (unsigned int i=0; i<len; i++)
1021  {
1022  libmesh_assert(in.get());
1023  libmesh_assert (in->good());
1024  *in >> val[i];
1025  }
1026 
1027  return;
1028  }
1029 
1030  case WRITE:
1031  {
1032  libmesh_assert(out.get());
1033  libmesh_assert (out->good());
1034 
1035  // Save stream flags
1036  std::ios_base::fmtflags out_flags = out->flags();
1037 
1038  // We will use scientific notation with a precision of 16
1039  // digits in the following output. The desired precision and
1040  // format will automatically determine the width.
1041  *out << std::scientific
1042  << std::setprecision(16);
1043 
1044  if (line_break == libMesh::invalid_uint)
1045  for (unsigned int i=0; i<len; i++)
1046  {
1047  libmesh_assert(out.get());
1048  libmesh_assert (out->good());
1049  *out << val[i] << ' ';
1050  }
1051  else
1052  {
1053  const unsigned imax = std::min(line_break, len);
1054  unsigned int cnt=0;
1055  while (cnt < len)
1056  {
1057  for (unsigned int i=0; i<imax; i++)
1058  {
1059  libmesh_assert(out.get());
1060  libmesh_assert (out->good());
1061  *out << val[cnt++];
1062 
1063  // Write a space unless this is the last character on the current line.
1064  if (i+1 != imax)
1065  *out << " ";
1066  }
1067  libmesh_assert(out.get());
1068  libmesh_assert (out->good());
1069  *out << '\n';
1070  }
1071  }
1072 
1073  // Restore stream flags
1074  out->flags(out_flags);
1075 
1076  return;
1077  }
1078 
1079  default:
1080  libmesh_error_msg("Invalid mode = " << mode);
1081  }
1082 }
const unsigned int invalid_uint
Definition: libmesh.h:184
UniquePtr< std::istream > in
Definition: xdr_cxx.h:228
const XdrMODE mode
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
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 1084 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.

1085 {
1086  switch (mode)
1087  {
1088  case ENCODE:
1089  case DECODE:
1090  {
1091 #ifdef LIBMESH_HAVE_XDR
1092 
1093  libmesh_assert (this->is_open());
1094 
1095  // FIXME[JWP]: How to implement this for long double? Mac OS
1096  // X defines 'xdr_quadruple' but AFAICT, it does not exist for
1097  // Linux... for now, reading/writing XDR files with long
1098  // doubles drops back to double precision, but you can still
1099  // write long double ASCII files of course.
1100  // if (len > 0)
1101  // xdr_vector(xdrs.get(),
1102  // (char *) val,
1103  // len,
1104  // sizeof(double),
1105  // (xdrproc_t) xdr_quadruple);
1106 
1107  if (len > 0)
1108  {
1109  std::vector<double> io_buffer (len);
1110 
1111  // Fill io_buffer if we are writing.
1112  if (mode == ENCODE)
1113  for (unsigned int i=0, cnt=0; i<len; i++)
1114  io_buffer[cnt++] = val[i];
1115 
1116  xdr_vector(xdrs.get(),
1117  (char *) &io_buffer[0],
1118  len,
1119  sizeof(double),
1120  (xdrproc_t) xdr_double);
1121 
1122  // Fill val array if we are reading.
1123  if (mode == DECODE)
1124  for (unsigned int i=0, cnt=0; i<len; i++)
1125  {
1126  val[i] = io_buffer[cnt++];
1127  }
1128  }
1129 
1130 #else
1131 
1132  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1133  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1134  << "The XDR interface is not available in this installation");
1135 
1136 #endif
1137  return;
1138  }
1139 
1140  case READ:
1141  {
1142  libmesh_assert(in.get());
1143  libmesh_assert (in->good());
1144 
1145  for (unsigned int i=0; i<len; i++)
1146  {
1147  libmesh_assert(in.get());
1148  libmesh_assert (in->good());
1149  *in >> val[i];
1150  }
1151 
1152  return;
1153  }
1154 
1155  case WRITE:
1156  {
1157  libmesh_assert(out.get());
1158  libmesh_assert (out->good());
1159 
1160  // Save stream flags
1161  std::ios_base::fmtflags out_flags = out->flags();
1162 
1163  // We will use scientific notation with a precision of 16
1164  // digits in the following output. The desired precision and
1165  // format will automatically determine the width.
1166  *out << std::scientific
1167  << std::setprecision(16);
1168 
1169  if (line_break == libMesh::invalid_uint)
1170  for (unsigned int i=0; i<len; i++)
1171  {
1172  libmesh_assert(out.get());
1173  libmesh_assert (out->good());
1174  *out << val[i] << ' ';
1175  }
1176  else
1177  {
1178  const unsigned imax = std::min(line_break, len);
1179  unsigned int cnt=0;
1180  while (cnt < len)
1181  {
1182  for (unsigned int i=0; i<imax; i++)
1183  {
1184  libmesh_assert(out.get());
1185  libmesh_assert (out->good());
1186  *out << val[cnt++];
1187 
1188  // Write a space unless this is the last character on the current line.
1189  if (i+1 != imax)
1190  *out << " ";
1191  }
1192  libmesh_assert(out.get());
1193  libmesh_assert (out->good());
1194  *out << '\n';
1195  }
1196  }
1197 
1198  // Restore stream flags
1199  out->flags(out_flags);
1200 
1201  return;
1202  }
1203 
1204  default:
1205  libmesh_error_msg("Invalid mode = " << mode);
1206  }
1207 }
const unsigned int invalid_uint
Definition: libmesh.h:184
UniquePtr< std::istream > in
Definition: xdr_cxx.h:228
const XdrMODE mode
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
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 1212 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.

1213 {
1214  switch (mode)
1215  {
1216  case ENCODE:
1217  case DECODE:
1218  {
1219 #ifdef LIBMESH_HAVE_XDR
1220 
1221  libmesh_assert (this->is_open());
1222 
1223 
1224  if (len > 0)
1225  {
1226  std::vector<double> io_buffer (2*len);
1227 
1228  // Fill io_buffer if we are writing.
1229  if (mode == ENCODE)
1230  for (unsigned int i=0, cnt=0; i<len; i++)
1231  {
1232  io_buffer[cnt++] = val[i].real();
1233  io_buffer[cnt++] = val[i].imag();
1234  }
1235 
1236  xdr_vector(xdrs.get(),
1237  (char *) &io_buffer[0],
1238  2*len,
1239  sizeof(double),
1240  (xdrproc_t) xdr_double);
1241 
1242  // Fill val array if we are reading.
1243  if (mode == DECODE)
1244  for (unsigned int i=0, cnt=0; i<len; i++)
1245  {
1246  double re = io_buffer[cnt++];
1247  double im = io_buffer[cnt++];
1248  val[i] = std::complex<double>(re,im);
1249  }
1250  }
1251 #else
1252 
1253  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1254  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1255  << "The XDR interface is not available in this installation");
1256 
1257 #endif
1258  return;
1259  }
1260 
1261  case READ:
1262  {
1263  libmesh_assert(in.get());
1264  libmesh_assert (in->good());
1265 
1266  for (unsigned int i=0; i<len; i++)
1267  {
1268  libmesh_assert(in.get());
1269  libmesh_assert (in->good());
1270  double re, im;
1271  *in >> re >> im;
1272  val[i] = std::complex<double>(re,im);
1273  }
1274 
1275  return;
1276  }
1277 
1278  case WRITE:
1279  {
1280  libmesh_assert(out.get());
1281  libmesh_assert (out->good());
1282 
1283  // Save stream flags
1284  std::ios_base::fmtflags out_flags = out->flags();
1285 
1286  // We will use scientific notation with a precision of 16
1287  // digits in the following output. The desired precision and
1288  // format will automatically determine the width.
1289  *out << std::scientific
1290  << std::setprecision(16);
1291 
1292  if (line_break == libMesh::invalid_uint)
1293  for (unsigned int i=0; i<len; i++)
1294  {
1295  libmesh_assert(out.get());
1296  libmesh_assert (out->good());
1297  *out << val[i].real() << ' ';
1298  *out << val[i].imag() << ' ';
1299  }
1300  else
1301  {
1302  const unsigned imax = std::min(line_break, len);
1303  unsigned int cnt=0;
1304  while (cnt < len)
1305  {
1306  for (unsigned int i=0; i<imax; i++)
1307  {
1308  libmesh_assert(out.get());
1309  libmesh_assert (out->good());
1310  *out << val[cnt].real() << ' ';
1311  *out << val[cnt].imag();
1312  cnt++;
1313 
1314  // Write a space unless this is the last character on the current line.
1315  if (i+1 != imax)
1316  *out << " ";
1317  }
1318  libmesh_assert(out.get());
1319  libmesh_assert (out->good());
1320  *out << '\n';
1321  }
1322  }
1323 
1324  // Restore stream flags
1325  out->flags(out_flags);
1326 
1327  return;
1328  }
1329 
1330  default:
1331  libmesh_error_msg("Invalid mode = " << mode);
1332  }
1333 }
const unsigned int invalid_uint
Definition: libmesh.h:184
UniquePtr< std::istream > in
Definition: xdr_cxx.h:228
const XdrMODE mode
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
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 1336 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.

1337 {
1338  switch (mode)
1339  {
1340  case ENCODE:
1341  case DECODE:
1342  {
1343 #ifdef LIBMESH_HAVE_XDR
1344 
1345  libmesh_assert (this->is_open());
1346 
1347  // FIXME[JWP]: How to implement this for long double? Mac OS
1348  // X defines 'xdr_quadruple' but AFAICT, it does not exist for
1349  // Linux... for now, reading/writing XDR files with long
1350  // doubles drops back to double precision, but you can still
1351  // write long double ASCII files of course.
1352 
1353  if (len > 0)
1354  {
1355  std::vector<double> io_buffer (2*len);
1356 
1357  // Fill io_buffer if we are writing.
1358  if (mode == ENCODE)
1359  for (unsigned int i=0, cnt=0; i<len; i++)
1360  {
1361  io_buffer[cnt++] = val[i].real();
1362  io_buffer[cnt++] = val[i].imag();
1363  }
1364 
1365  xdr_vector(xdrs.get(),
1366  (char *) &io_buffer[0],
1367  2*len,
1368  sizeof(double),
1369  (xdrproc_t) xdr_double);
1370 
1371  // Fill val array if we are reading.
1372  if (mode == DECODE)
1373  for (unsigned int i=0, cnt=0; i<len; i++)
1374  {
1375  double re = io_buffer[cnt++];
1376  double im = io_buffer[cnt++];
1377  val[i] = std::complex<long double>(re, im);
1378  }
1379  }
1380 #else
1381 
1382  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1383  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1384  << "The XDR interface is not available in this installation");
1385 
1386 #endif
1387  return;
1388  }
1389 
1390  case READ:
1391  {
1392  libmesh_assert(in.get());
1393  libmesh_assert (in->good());
1394 
1395  for (unsigned int i=0; i<len; i++)
1396  {
1397  libmesh_assert(in.get());
1398  libmesh_assert (in->good());
1399  long double re, im;
1400  *in >> re >> im;
1401  val[i] = std::complex<long double>(re,im);
1402  }
1403 
1404  return;
1405  }
1406 
1407  case WRITE:
1408  {
1409  libmesh_assert(out.get());
1410  libmesh_assert (out->good());
1411 
1412 
1413  // Save stream flags
1414  std::ios_base::fmtflags out_flags = out->flags();
1415 
1416  // We will use scientific notation with a precision of
1417  // 'digits10' digits in the following output. The desired
1418  // precision and format will automatically determine the
1419  // width. Note: digit10 is the number of digits (in decimal
1420  // base) that can be represented without change. Equivalent
1421  // to FLT_DIG, DBL_DIG or LDBL_DIG for floating types.
1422  *out << std::scientific
1423  << std::setprecision(std::numeric_limits<long double>::digits10);
1424 
1425  if (line_break == libMesh::invalid_uint)
1426  for (unsigned int i=0; i<len; i++)
1427  {
1428  libmesh_assert(out.get());
1429  libmesh_assert (out->good());
1430  *out << val[i].real() << ' ' << val[i].imag() << ' ';
1431  }
1432  else
1433  {
1434  const unsigned imax = std::min(line_break, len);
1435  unsigned int cnt=0;
1436  while (cnt < len)
1437  {
1438  for (unsigned int i=0; i<imax; i++)
1439  {
1440  libmesh_assert(out.get());
1441  libmesh_assert (out->good());
1442  *out << val[cnt].real() << ' ' << val[cnt].imag();
1443  cnt++;
1444 
1445  // Write a space unless this is the last character on the current line.
1446  if (i+1 != imax)
1447  *out << " ";
1448  }
1449  libmesh_assert(out.get());
1450  libmesh_assert (out->good());
1451  *out << '\n';
1452  }
1453  }
1454 
1455  // Restore stream flags
1456  out->flags(out_flags);
1457 
1458  return;
1459  }
1460 
1461  default:
1462  libmesh_error_msg("Invalid mode = " << mode);
1463  }
1464 }
const unsigned int invalid_uint
Definition: libmesh.h:184
UniquePtr< std::istream > in
Definition: xdr_cxx.h:228
const XdrMODE mode
Definition: xdr_cxx.h:203
libmesh_assert(j)
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
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 603 of file xdr_cxx.C.

References comm, comm_len, and in.

Referenced by data(), and version().

604 {
605  *in >> a;
606  in->getline(comm, comm_len);
607 }
const int comm_len
Definition: xdr_cxx.h:238
UniquePtr< std::istream > in
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 610 of file xdr_cxx.C.

References comm, comm_len, and in.

611 {
612  T r, i;
613  *in >> r >> i;
614  a = std::complex<T>(r,i);
615  in->getline(comm, comm_len);
616 }
const int comm_len
Definition: xdr_cxx.h:238
UniquePtr< std::istream > in
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 634 of file xdr_cxx.C.

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

635 {
636  unsigned int length=0;
637  data(length, "# vector length");
638  a.resize(length);
639 
640  for (std::size_t i=0; i<a.size(); i++)
641  {
642  libmesh_assert(in.get());
643  libmesh_assert (in->good());
644  *in >> a[i];
645  }
646  in->getline(comm, comm_len);
647 }
const int comm_len
Definition: xdr_cxx.h:238
void data(T &a, const char *comment="")
Definition: xdr_cxx.C:709
UniquePtr< std::istream > in
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 650 of file xdr_cxx.C.

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

651 {
652  unsigned int length=0;
653  data(length, "# vector length x 2 (complex)");
654  a.resize(length);
655 
656  for (std::size_t i=0; i<a.size(); i++)
657  {
658  T r, im;
659  libmesh_assert(in.get());
660  libmesh_assert (in->good());
661  *in >> r >> im;
662  a[i] = std::complex<T>(r,im);
663  }
664  in->getline(comm, comm_len);
665 }
const int comm_len
Definition: xdr_cxx.h:238
void data(T &a, const char *comment="")
Definition: xdr_cxx.C:709
UniquePtr< std::istream > in
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 619 of file xdr_cxx.C.

References comm, comm_len, and in.

620 {
621  in->getline(comm, comm_len);
622 
623  a = "";
624 
625  for (unsigned int c=0; c<std::strlen(comm); c++)
626  {
627  if (comm[c] == '\t')
628  break;
629  a.push_back(comm[c]);
630  }
631 }
const int comm_len
Definition: xdr_cxx.h:238
UniquePtr< std::istream > in
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 668 of file xdr_cxx.C.

References out.

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

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

Definition at line 671 of file xdr_cxx.C.

References out.

672 {
673  *out << a.real() << "\t " << a.imag();
674 }
UniquePtr< std::ostream > out
Definition: xdr_cxx.h:233
template<typename T >
void libMesh::Xdr::do_write ( std::vector< T > &  a)
private

Definition at line 677 of file xdr_cxx.C.

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

678 {
679  std::size_t length = a.size();
680  data(length, "# vector length");
681 
682  for (std::size_t i=0; i<a.size(); i++)
683  {
684  libmesh_assert(out.get());
685  libmesh_assert (out->good());
686  this->do_write(a[i]);
687  *out << "\t ";
688  }
689 }
void data(T &a, const char *comment="")
Definition: xdr_cxx.C:709
void do_write(T &a)
Definition: xdr_cxx.C:668
libmesh_assert(j)
UniquePtr< std::ostream > out
Definition: xdr_cxx.h:233
template<typename T >
void libMesh::Xdr::do_write ( std::vector< std::complex< T > > &  a)
private

Definition at line 692 of file xdr_cxx.C.

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

693 {
694  std::size_t length=a.size();
695  data(length, "# vector length x 2 (complex)");
696 
697  for (std::size_t i=0; i<a.size(); i++)
698  {
699  libmesh_assert(out.get());
700  libmesh_assert (out->good());
701  this->do_write(a[i]);
702  *out << "\t ";
703  }
704 }
void data(T &a, const char *comment="")
Definition: xdr_cxx.C:709
void do_write(T &a)
Definition: xdr_cxx.C:668
libmesh_assert(j)
UniquePtr< std::ostream > out
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
Definition: xdr_cxx.h:221
UniquePtr< std::istream > in
Definition: xdr_cxx.h:228
const XdrMODE mode
Definition: xdr_cxx.h:203
libmesh_assert(j)
static const unsigned int next[3]
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
Definition: xdr_cxx.h:221
UniquePtr< std::istream > in
Definition: xdr_cxx.h:228
const class libmesh_nullptr_t libmesh_nullptr
const XdrMODE mode
Definition: xdr_cxx.h:203
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
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(), libMesh::out, 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)
Definition: elem_quality.C:39
FILE * fp
Definition: xdr_cxx.h:221
std::string file_name
Definition: xdr_cxx.h:208
UniquePtr< std::istream > in
Definition: xdr_cxx.h:228
bool xzipped_file
Definition: xdr_cxx.h:244
bool bzipped_file
Definition: xdr_cxx.h:244
const XdrMODE mode
Definition: xdr_cxx.h:203
bool gzipped_file
Definition: xdr_cxx.h:244
libmesh_assert(j)
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:216
UniquePtr< std::ostream > out
Definition: xdr_cxx.h:233
OStreamProxy out(std::cout)
template<typename T >
Xdr& libMesh::Xdr::operator<< ( T &  a)
inline

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="")
Definition: xdr_cxx.C:709
libmesh_assert(j)
bool writing() const
Definition: xdr_cxx.h:119
template<typename T >
Xdr& libMesh::Xdr::operator>> ( T &  a)
inline

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="")
Definition: xdr_cxx.C:709
libmesh_assert(j)
bool reading() const
Definition: xdr_cxx.h:113
void libMesh::Xdr::set_version ( int  ver)
inline

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
Definition: xdr_cxx.h:249
int libMesh::Xdr::version ( ) const
inline

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
Definition: xdr_cxx.h:249

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: