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:222
const int comm_len
Definition: xdr_cxx.h:239
std::string file_name
Definition: xdr_cxx.h:207
const unsigned int xdr_MAX_STRING_LENGTH
Definition: xdr_cxx.h:46
UniquePtr< std::istream > in
Definition: xdr_cxx.h:229
const class libmesh_nullptr_t libmesh_nullptr
bool xzipped_file
Definition: xdr_cxx.h:245
bool bzipped_file
Definition: xdr_cxx.h:245
const XdrMODE mode
Definition: xdr_cxx.h:202
bool gzipped_file
Definition: xdr_cxx.h:245
UniquePtr< std::ostream > out
Definition: xdr_cxx.h:234
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 124 of file xdr_cxx.h.

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

124 { return mode; }
const XdrMODE mode
Definition: xdr_cxx.h:202
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:222
std::string file_name
Definition: xdr_cxx.h:207
UniquePtr< std::istream > in
Definition: xdr_cxx.h:229
const class libmesh_nullptr_t libmesh_nullptr
bool xzipped_file
Definition: xdr_cxx.h:245
bool bzipped_file
Definition: xdr_cxx.h:245
const XdrMODE mode
Definition: xdr_cxx.h:202
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:217
UniquePtr< std::ostream > out
Definition: xdr_cxx.h:234
void libMesh::Xdr::comment ( std::string &  comment_in)

Writes or reads (ignores) a comment line.

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

1493 {
1494  switch (mode)
1495  {
1496  case ENCODE:
1497  case DECODE:
1498  {
1499  return;
1500  }
1501 
1502  case READ:
1503  {
1504  libmesh_assert(in.get());
1505  libmesh_assert (in->good());
1506  in->getline(comm, comm_len);
1507  return;
1508  }
1509 
1510  case WRITE:
1511  {
1512  libmesh_assert(out.get());
1513  libmesh_assert (out->good());
1514  *out << "\t " << comment_in << '\n';
1515  return;
1516  }
1517 
1518  default:
1519  libmesh_error_msg("Invalid mode = " << mode);
1520  }
1521 }
const int comm_len
Definition: xdr_cxx.h:239
UniquePtr< std::istream > in
Definition: xdr_cxx.h:229
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:240
const XdrMODE mode
Definition: xdr_cxx.h:202
libmesh_assert(j)
UniquePtr< std::ostream > out
Definition: xdr_cxx.h:234
template<typename T >
template void libMesh::Xdr::data< long double > ( T &  a,
const char *  comment = "" 
)

Inputs or outputs a single value.

Definition at line 706 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::System::read_header(), libMesh::System::read_legacy_data(), libMesh::CheckpointIO::read_nodes(), libMesh::CheckpointIO::read_nodesets(), libMesh::System::read_parallel_data(), 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::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().

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

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

914 {
915  switch (mode)
916  {
917  case ENCODE:
918  case DECODE:
919  {
920 #ifdef LIBMESH_HAVE_XDR
921 
922  libmesh_assert (this->is_open());
923 
924  if (len > 0)
925  xdr_vector(xdrs.get(),
926  (char *) val,
927  len,
928  sizeof(double),
929  (xdrproc_t) xdr_double);
930 
931 #else
932 
933  libmesh_error_msg("ERROR: Functionality is not available.\n" \
934  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
935  << "The XDR interface is not available in this installation");
936 
937 #endif
938  return;
939  }
940 
941  case READ:
942  {
943  libmesh_assert(in.get());
944  libmesh_assert (in->good());
945 
946  for (unsigned int i=0; i<len; i++)
947  {
948  libmesh_assert(in.get());
949  libmesh_assert (in->good());
950  *in >> val[i];
951  }
952 
953  return;
954  }
955 
956  case WRITE:
957  {
958  libmesh_assert(out.get());
959  libmesh_assert (out->good());
960 
961  // Save stream flags
962  std::ios_base::fmtflags out_flags = out->flags();
963 
964  // We will use scientific notation with a precision of 16
965  // digits in the following output. The desired precision and
966  // format will automatically determine the width.
967  *out << std::scientific
968  << std::setprecision(16);
969 
970  if (line_break == libMesh::invalid_uint)
971  for (unsigned int i=0; i<len; i++)
972  {
973  libmesh_assert(out.get());
974  libmesh_assert (out->good());
975  *out << val[i] << ' ';
976  }
977  else
978  {
979  const unsigned imax = std::min(line_break, len);
980  unsigned int cnt=0;
981  while (cnt < len)
982  {
983  for (unsigned int i=0; i<imax; i++)
984  {
985  libmesh_assert(out.get());
986  libmesh_assert (out->good());
987  *out << val[cnt++];
988 
989  // Write a space unless this is the last character on the current line.
990  if (i+1 != imax)
991  *out << " ";
992  }
993  libmesh_assert(out.get());
994  libmesh_assert (out->good());
995  *out << '\n';
996  }
997  }
998 
999  // Restore stream flags
1000  out->flags(out_flags);
1001 
1002  return;
1003  }
1004 
1005  default:
1006  libmesh_error_msg("Invalid mode = " << mode);
1007  }
1008 }
const unsigned int invalid_uint
Definition: libmesh.h:184
UniquePtr< std::istream > in
Definition: xdr_cxx.h:229
const XdrMODE mode
Definition: xdr_cxx.h:202
libmesh_assert(j)
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:217
UniquePtr< std::ostream > out
Definition: xdr_cxx.h:234
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 1012 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.

1013 {
1014  switch (mode)
1015  {
1016  case ENCODE:
1017  case DECODE:
1018  {
1019 #ifdef LIBMESH_HAVE_XDR
1020 
1021  libmesh_assert (this->is_open());
1022 
1023  if (len > 0)
1024  xdr_vector(xdrs.get(),
1025  (char *) val,
1026  len,
1027  sizeof(float),
1028  (xdrproc_t) xdr_float);
1029 
1030 #else
1031 
1032  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1033  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1034  << "The XDR interface is not available in this installation");
1035 
1036 #endif
1037  return;
1038  }
1039 
1040  case READ:
1041  {
1042  libmesh_assert(in.get());
1043  libmesh_assert (in->good());
1044 
1045  for (unsigned int i=0; i<len; i++)
1046  {
1047  libmesh_assert(in.get());
1048  libmesh_assert (in->good());
1049  *in >> val[i];
1050  }
1051 
1052  return;
1053  }
1054 
1055  case WRITE:
1056  {
1057  libmesh_assert(out.get());
1058  libmesh_assert (out->good());
1059 
1060  // Save stream flags
1061  std::ios_base::fmtflags out_flags = out->flags();
1062 
1063  // We will use scientific notation with a precision of 16
1064  // digits in the following output. The desired precision and
1065  // format will automatically determine the width.
1066  *out << std::scientific
1067  << std::setprecision(16);
1068 
1069  if (line_break == libMesh::invalid_uint)
1070  for (unsigned int i=0; i<len; i++)
1071  {
1072  libmesh_assert(out.get());
1073  libmesh_assert (out->good());
1074  *out << val[i] << ' ';
1075  }
1076  else
1077  {
1078  const unsigned imax = std::min(line_break, len);
1079  unsigned int cnt=0;
1080  while (cnt < len)
1081  {
1082  for (unsigned int i=0; i<imax; i++)
1083  {
1084  libmesh_assert(out.get());
1085  libmesh_assert (out->good());
1086  *out << val[cnt++];
1087 
1088  // Write a space unless this is the last character on the current line.
1089  if (i+1 != imax)
1090  *out << " ";
1091  }
1092  libmesh_assert(out.get());
1093  libmesh_assert (out->good());
1094  *out << '\n';
1095  }
1096  }
1097 
1098  // Restore stream flags
1099  out->flags(out_flags);
1100 
1101  return;
1102  }
1103 
1104  default:
1105  libmesh_error_msg("Invalid mode = " << mode);
1106  }
1107 }
const unsigned int invalid_uint
Definition: libmesh.h:184
UniquePtr< std::istream > in
Definition: xdr_cxx.h:229
const XdrMODE mode
Definition: xdr_cxx.h:202
libmesh_assert(j)
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:217
UniquePtr< std::ostream > out
Definition: xdr_cxx.h:234
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 1109 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.

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

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

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

References comm, comm_len, and in.

Referenced by data(), and version().

601 {
602  *in >> a;
603  in->getline(comm, comm_len);
604 }
const int comm_len
Definition: xdr_cxx.h:239
UniquePtr< std::istream > in
Definition: xdr_cxx.h:229
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:240
template<typename T >
void libMesh::Xdr::do_read ( std::complex< T > &  a)
private

Definition at line 607 of file xdr_cxx.C.

References comm, comm_len, and in.

608 {
609  T r, i;
610  *in >> r >> i;
611  a = std::complex<T>(r,i);
612  in->getline(comm, comm_len);
613 }
const int comm_len
Definition: xdr_cxx.h:239
UniquePtr< std::istream > in
Definition: xdr_cxx.h:229
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:240
template<typename T >
void libMesh::Xdr::do_read ( std::vector< T > &  a)
private

Definition at line 631 of file xdr_cxx.C.

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

632 {
633  unsigned int length=0;
634  data(length, "# vector length");
635  a.resize(length);
636 
637  for (std::size_t i=0; i<a.size(); i++)
638  {
639  libmesh_assert(in.get());
640  libmesh_assert (in->good());
641  *in >> a[i];
642  }
643  in->getline(comm, comm_len);
644 }
const int comm_len
Definition: xdr_cxx.h:239
void data(T &a, const char *comment="")
Definition: xdr_cxx.C:706
UniquePtr< std::istream > in
Definition: xdr_cxx.h:229
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:240
libmesh_assert(j)
template<typename T >
void libMesh::Xdr::do_read ( std::vector< std::complex< T > > &  a)
private

Definition at line 647 of file xdr_cxx.C.

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

648 {
649  unsigned int length=0;
650  data(length, "# vector length x 2 (complex)");
651  a.resize(length);
652 
653  for (std::size_t i=0; i<a.size(); i++)
654  {
655  T r, im;
656  libmesh_assert(in.get());
657  libmesh_assert (in->good());
658  *in >> r >> im;
659  a[i] = std::complex<T>(r,im);
660  }
661  in->getline(comm, comm_len);
662 }
const int comm_len
Definition: xdr_cxx.h:239
void data(T &a, const char *comment="")
Definition: xdr_cxx.C:706
UniquePtr< std::istream > in
Definition: xdr_cxx.h:229
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:240
libmesh_assert(j)
template<>
void libMesh::Xdr::do_read ( std::string &  a)

Definition at line 616 of file xdr_cxx.C.

References comm, comm_len, and in.

617 {
618  in->getline(comm, comm_len);
619 
620  a = "";
621 
622  for (unsigned int c=0; c<std::strlen(comm); c++)
623  {
624  if (comm[c] == '\t')
625  break;
626  a.push_back(comm[c]);
627  }
628 }
const int comm_len
Definition: xdr_cxx.h:239
UniquePtr< std::istream > in
Definition: xdr_cxx.h:229
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:240
template<typename T >
void libMesh::Xdr::do_write ( T &  a)
private

Helper method for writing different data types

Definition at line 665 of file xdr_cxx.C.

References out.

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

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

Definition at line 668 of file xdr_cxx.C.

References out.

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

Definition at line 674 of file xdr_cxx.C.

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

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

Definition at line 689 of file xdr_cxx.C.

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

690 {
691  std::size_t length=a.size();
692  data(length, "# vector length x 2 (complex)");
693 
694  for (std::size_t i=0; i<a.size(); i++)
695  {
696  libmesh_assert(out.get());
697  libmesh_assert (out->good());
698  this->do_write(a[i]);
699  *out << "\t ";
700  }
701 }
void data(T &a, const char *comment="")
Definition: xdr_cxx.C:706
void do_write(T &a)
Definition: xdr_cxx.C:665
libmesh_assert(j)
UniquePtr< std::ostream > out
Definition: xdr_cxx.h:234
bool libMesh::Xdr::is_eof ( )

Returns true if the Xdr file being read is at End-Of-File. Note that 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:222
UniquePtr< std::istream > in
Definition: xdr_cxx.h:229
const XdrMODE mode
Definition: xdr_cxx.h:202
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:222
UniquePtr< std::istream > in
Definition: xdr_cxx.h:229
const class libmesh_nullptr_t libmesh_nullptr
const XdrMODE mode
Definition: xdr_cxx.h:202
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:217
UniquePtr< std::ostream > out
Definition: xdr_cxx.h:234
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:222
std::string file_name
Definition: xdr_cxx.h:207
UniquePtr< std::istream > in
Definition: xdr_cxx.h:229
bool xzipped_file
Definition: xdr_cxx.h:245
bool bzipped_file
Definition: xdr_cxx.h:245
const XdrMODE mode
Definition: xdr_cxx.h:202
bool gzipped_file
Definition: xdr_cxx.h:245
libmesh_assert(j)
UniquePtr< XDR > xdrs
Definition: xdr_cxx.h:217
UniquePtr< std::ostream > out
Definition: xdr_cxx.h:234
OStreamProxy out(std::cout)
template<typename T >
Xdr& libMesh::Xdr::operator<< ( T &  a)
inline

Same, but provides an ostream like interface.

Definition at line 138 of file xdr_cxx.h.

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

138 { libmesh_assert (writing()); data(a); return *this; }
void data(T &a, const char *comment="")
Definition: xdr_cxx.C:706
libmesh_assert(j)
bool writing() const
Definition: xdr_cxx.h:118
template<typename T >
Xdr& libMesh::Xdr::operator>> ( T &  a)
inline

Same, but provides an istream like interface.

Definition at line 144 of file xdr_cxx.h.

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

144 { libmesh_assert (reading()); data(a); return *this; }
void data(T &a, const char *comment="")
Definition: xdr_cxx.C:706
libmesh_assert(j)
bool reading() const
Definition: xdr_cxx.h:112
void libMesh::Xdr::set_version ( int  ver)
inline

Sets the version of the file that is being read

Definition at line 160 of file xdr_cxx.h.

References version_number.

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

160 { version_number = ver; }
int version_number
Definition: xdr_cxx.h:250
int libMesh::Xdr::version ( ) const
inline

Gets the version of the file that is being read

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

165 { return version_number; }
int version_number
Definition: xdr_cxx.h:250

Member Data Documentation

bool libMesh::Xdr::bzipped_file
private

Definition at line 245 of file xdr_cxx.h.

Referenced by close(), and open().

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

Definition at line 240 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 239 of file xdr_cxx.h.

Referenced by comment(), and do_read().

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

The file name

Definition at line 207 of file xdr_cxx.h.

Referenced by close(), and open().

FILE* libMesh::Xdr::fp
private

File pointer.

Definition at line 222 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 245 of file xdr_cxx.h.

Referenced by open().

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

The input file stream.

Definition at line 229 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 202 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 234 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 250 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 217 of file xdr_cxx.h.

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

bool libMesh::Xdr::xzipped_file
private

Definition at line 245 of file xdr_cxx.h.

Referenced by close(), and open().


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