This class implements a C++ interface to the XDR (eXternal Data Representation) format.
More...
|
| Xdr (const std::string &name="", const XdrMODE m=UNKNOWN) |
| Constructor. More...
|
|
| ~Xdr () |
| Destructor. More...
|
|
void | open (const std::string &name) |
| Opens the file. More...
|
|
void | close () |
| Closes the file if it is open. More...
|
|
bool | is_open () const |
|
bool | is_eof () |
|
bool | reading () const |
|
bool | writing () const |
|
XdrMODE | access_mode () const |
|
template<typename T > |
void | data (T &a, const char *comment="") |
| Inputs or outputs a single value. More...
|
|
template<typename T > |
Xdr & | operator<< (T &a) |
| Same, but provides an ostream like interface. More...
|
|
template<typename T > |
Xdr & | operator>> (T &a) |
| Same, but provides an istream like interface. More...
|
|
template<typename T > |
void | data_stream (T *val, const unsigned int len, const unsigned int line_break=libMesh::invalid_uint) |
| Inputs or outputs a raw data stream. More...
|
|
void | comment (std::string &) |
| Writes or reads (ignores) a comment line. More...
|
|
void | set_version (int ver) |
| Sets the version of the file that is being read. More...
|
|
int | version () const |
| Gets the version of the file that is being read. More...
|
|
template<> |
void | 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 (Real *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) |
|
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
XDR is useful for creating platform-independent binary files. This class was created to handle equation system output as a replacement for XdrIO since that is somewhat limited.
- Author
- Benjamin Kirk
- Date
- 2003
C++ interface for the XDR (eXternal Data Representation) format.
Definition at line 65 of file xdr_cxx.h.
void libMesh::Xdr::close |
( |
| ) |
|
Closes the file if it is open.
Definition at line 273 of file xdr_cxx.C.
280 #ifdef LIBMESH_HAVE_XDR
284 xdr_destroy (
xdrs.get());
296 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
297 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
298 <<
"The XDR interface is not available in this installation");
307 if (
in.get() !=
nullptr)
320 if (
out.get() !=
nullptr)
335 libmesh_error_msg(
"Invalid mode = " <<
mode);
References bzipped_file, libMesh::DECODE, libMesh::ENCODE, file_name, fp, in, mode, out, libMesh::READ, libMesh::WRITE, xdrs, and xzipped_file.
Referenced by libMesh::EquationSystems::_read_impl(), libMesh::RBEvaluation::legacy_read_offline_data_from_files(), libMesh::RBSCMEvaluation::legacy_read_offline_data_from_files(), libMesh::RBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBSCMEvaluation::legacy_write_offline_data_to_files(), libMesh::CheckpointIO::read(), libMesh::RBParametrized::read_parameter_ranges_from_file(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), libMesh::RBParametrized::write_parameter_ranges_to_file(), and ~Xdr().
void libMesh::Xdr::comment |
( |
std::string & |
comment_in | ) |
|
Writes or reads (ignores) a comment line.
Definition at line 1661 of file xdr_cxx.C.
1683 *
out <<
"\t " << comment_in <<
'\n';
1688 libmesh_error_msg(
"Invalid mode = " <<
mode);
References comm, comm_len, libMesh::DECODE, libMesh::ENCODE, in, libMesh::libmesh_assert(), mode, out, libMesh::READ, and libMesh::WRITE.
Referenced by libMesh::System::read_serialized_data(), and libMesh::System::write_serialized_data().
template<typename T >
template void libMesh::Xdr::data< Real > |
( |
T & |
a, |
|
|
const char * |
comment = "" |
|
) |
| |
Inputs or outputs a single value.
Definition at line 766 of file xdr_cxx.C.
773 #ifdef LIBMESH_HAVE_XDR
777 xdr_translate(
xdrs.get(), a);
781 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
782 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
783 <<
"The XDR interface is not available in this installation");
808 *
out << std::scientific
809 << std::setprecision(std::numeric_limits<T>::max_digits10);
815 if (std::string(comment_in) !=
"")
816 *
out <<
"\t " << comment_in;
825 libmesh_error_msg(
"Invalid mode = " <<
mode);
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(), do_read(), do_write(), operator<<(), operator>>(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_bc_names(), libMesh::CheckpointIO::read_bcs(), libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::CheckpointIO::read_integers_names(), libMesh::System::read_legacy_data(), libMesh::CheckpointIO::read_nodes(), libMesh::CheckpointIO::read_nodesets(), libMesh::System::read_parallel_data(), libMesh::CheckpointIO::read_remote_elem(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::CheckpointIO::read_subdomain_names(), libMesh::CheckpointIO::select_split_config(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), libMesh::EquationSystems::write(), libMesh::CheckpointIO::write_bc_names(), libMesh::CheckpointIO::write_bcs(), libMesh::CheckpointIO::write_connectivity(), libMesh::System::write_header(), libMesh::CheckpointIO::write_nodes(), libMesh::CheckpointIO::write_nodesets(), libMesh::System::write_parallel_data(), libMesh::CheckpointIO::write_remote_elem(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), and libMesh::CheckpointIO::write_subdomain_names().
template<>
void libMesh::Xdr::data_stream |
( |
double * |
val, |
|
|
const unsigned int |
len, |
|
|
const unsigned int |
line_break |
|
) |
| |
Definition at line 947 of file xdr_cxx.C.
954 #ifdef LIBMESH_HAVE_XDR
959 xdr_vector(
xdrs.get(),
963 (xdrproc_t) xdr_double);
967 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
968 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
969 <<
"The XDR interface is not available in this installation");
980 for (
unsigned int i=0; i<len; i++)
996 std::ios_base::fmtflags out_flags =
out->flags();
1002 *
out << std::scientific
1003 << std::setprecision(std::numeric_limits<double>::max_digits10);
1006 for (
unsigned int i=0; i<len; i++)
1010 *
out << val[i] <<
' ';
1014 const unsigned imax = std::min(line_break, len);
1018 for (
unsigned int i=0; i<imax; i++)
1035 out->flags(out_flags);
1041 libmesh_error_msg(
"Invalid mode = " <<
mode);
References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
template<>
void libMesh::Xdr::data_stream |
( |
float * |
val, |
|
|
const unsigned int |
len, |
|
|
const unsigned int |
line_break |
|
) |
| |
Definition at line 1047 of file xdr_cxx.C.
1054 #ifdef LIBMESH_HAVE_XDR
1059 xdr_vector(
xdrs.get(),
1063 (xdrproc_t) xdr_float);
1067 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
1068 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1069 <<
"The XDR interface is not available in this installation");
1080 for (
unsigned int i=0; i<len; i++)
1096 std::ios_base::fmtflags out_flags =
out->flags();
1102 *
out << std::scientific
1103 << std::setprecision(std::numeric_limits<float>::max_digits10);
1106 for (
unsigned int i=0; i<len; i++)
1110 *
out << val[i] <<
' ';
1114 const unsigned imax = std::min(line_break, len);
1118 for (
unsigned int i=0; i<imax; i++)
1135 out->flags(out_flags);
1141 libmesh_error_msg(
"Invalid mode = " <<
mode);
References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
template<>
void libMesh::Xdr::data_stream |
( |
long double * |
val, |
|
|
const unsigned int |
len, |
|
|
const unsigned int |
line_break |
|
) |
| |
Definition at line 1147 of file xdr_cxx.C.
1154 #ifdef LIBMESH_HAVE_XDR
1172 std::vector<double> io_buffer (len);
1176 for (
unsigned int i=0, cnt=0; i<len; i++)
1177 io_buffer[cnt++] =
double(val[i]);
1179 xdr_vector(
xdrs.get(),
1180 reinterpret_cast<char *>(io_buffer.data()),
1183 (xdrproc_t) xdr_double);
1187 for (
unsigned int i=0, cnt=0; i<len; i++)
1189 val[i] = io_buffer[cnt++];
1195 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
1196 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1197 <<
"The XDR interface is not available in this installation");
1208 for (
unsigned int i=0; i<len; i++)
1224 std::ios_base::fmtflags out_flags =
out->flags();
1230 *
out << std::scientific
1231 << std::setprecision(std::numeric_limits<long double>::max_digits10);
1234 for (
unsigned int i=0; i<len; i++)
1238 *
out << val[i] <<
' ';
1242 const unsigned imax = std::min(line_break, len);
1246 for (
unsigned int i=0; i<imax; i++)
1263 out->flags(out_flags);
1269 libmesh_error_msg(
"Invalid mode = " <<
mode);
References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
template<>
void libMesh::Xdr::data_stream |
( |
Real * |
val, |
|
|
const unsigned int |
len, |
|
|
const unsigned int |
line_break |
|
) |
| |
Definition at line 1276 of file xdr_cxx.C.
1283 #ifdef LIBMESH_HAVE_XDR
1300 std::vector<double> io_buffer (len);
1304 for (
unsigned int i=0, cnt=0; i<len; i++)
1305 io_buffer[cnt++] =
double(val[i]);
1307 xdr_vector(
xdrs.get(),
1308 reinterpret_cast<char *>(io_buffer.data()),
1311 (xdrproc_t) xdr_double);
1315 for (
unsigned int i=0, cnt=0; i<len; i++)
1317 val[i] = io_buffer[cnt++];
1323 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
1324 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1325 <<
"The XDR interface is not available in this installation");
1336 for (
unsigned int i=0; i<len; i++)
1352 std::ios_base::fmtflags out_flags =
out->flags();
1357 *
out << std::scientific
1358 << std::setprecision(36);
1361 for (
unsigned int i=0; i<len; i++)
1365 *
out << val[i] <<
' ';
1369 const unsigned imax = std::min(line_break, len);
1373 for (
unsigned int i=0; i<imax; i++)
1390 out->flags(out_flags);
1396 libmesh_error_msg(
"Invalid mode = " <<
mode);
References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
template<>
void libMesh::Xdr::data_stream |
( |
std::complex< double > * |
val, |
|
|
const unsigned int |
len, |
|
|
const unsigned int |
line_break |
|
) |
| |
Definition at line 1405 of file xdr_cxx.C.
1412 #ifdef LIBMESH_HAVE_XDR
1419 std::vector<double> io_buffer (2*len);
1423 for (
unsigned int i=0, cnt=0; i<len; i++)
1425 io_buffer[cnt++] = val[i].real();
1426 io_buffer[cnt++] = val[i].imag();
1429 xdr_vector(
xdrs.get(),
1430 reinterpret_cast<char *>(io_buffer.data()),
1433 (xdrproc_t) xdr_double);
1437 for (
unsigned int i=0, cnt=0; i<len; i++)
1439 double re = io_buffer[cnt++];
1440 double im = io_buffer[cnt++];
1441 val[i] = std::complex<double>(re,im);
1446 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
1447 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1448 <<
"The XDR interface is not available in this installation");
1459 for (
unsigned int i=0; i<len; i++)
1465 val[i] = std::complex<double>(re,im);
1477 std::ios_base::fmtflags out_flags =
out->flags();
1483 *
out << std::scientific
1484 << std::setprecision(std::numeric_limits<double>::max_digits10);
1487 for (
unsigned int i=0; i<len; i++)
1491 *
out << val[i].real() <<
' ';
1492 *
out << val[i].imag() <<
' ';
1496 const unsigned imax = std::min(line_break, len);
1500 for (
unsigned int i=0; i<imax; i++)
1504 *
out << val[cnt].real() <<
' ';
1505 *
out << val[cnt].imag();
1519 out->flags(out_flags);
1525 libmesh_error_msg(
"Invalid mode = " <<
mode);
References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
template<>
void libMesh::Xdr::data_stream |
( |
std::complex< long double > * |
val, |
|
|
const unsigned int |
len, |
|
|
const unsigned int |
line_break |
|
) |
| |
Definition at line 1530 of file xdr_cxx.C.
1537 #ifdef LIBMESH_HAVE_XDR
1549 std::vector<double> io_buffer (2*len);
1553 for (
unsigned int i=0, cnt=0; i<len; i++)
1555 io_buffer[cnt++] = val[i].real();
1556 io_buffer[cnt++] = val[i].imag();
1559 xdr_vector(
xdrs.get(),
1560 reinterpret_cast<char *>(io_buffer.data()),
1563 (xdrproc_t) xdr_double);
1567 for (
unsigned int i=0, cnt=0; i<len; i++)
1569 double re = io_buffer[cnt++];
1570 double im = io_buffer[cnt++];
1571 val[i] = std::complex<long double>(re, im);
1576 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
1577 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1578 <<
"The XDR interface is not available in this installation");
1589 for (
unsigned int i=0; i<len; i++)
1595 val[i] = std::complex<long double>(re,im);
1608 std::ios_base::fmtflags out_flags =
out->flags();
1616 *
out << std::scientific
1617 << std::setprecision(std::numeric_limits<long double>::max_digits10);
1620 for (
unsigned int i=0; i<len; i++)
1624 *
out << val[i].real() <<
' ' << val[i].imag() <<
' ';
1628 const unsigned imax = std::min(line_break, len);
1632 for (
unsigned int i=0; i<imax; i++)
1636 *
out << val[cnt].real() <<
' ' << val[cnt].imag();
1650 out->flags(out_flags);
1656 libmesh_error_msg(
"Invalid mode = " <<
mode);
References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
Inputs or outputs a raw data stream.
Definition at line 831 of file xdr_cxx.C.
837 #ifdef LIBMESH_HAVE_XDR
841 unsigned int size_of_type = cast_int<unsigned int>(
sizeof(T));
843 xdr_vector(
xdrs.get(),
847 xdr_translator<T>());
849 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
850 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
851 <<
"The XDR interface is not available in this installation");
859 #ifdef LIBMESH_HAVE_XDR
863 unsigned int size_of_type = cast_int<unsigned int>(
sizeof(T));
866 xdr_vector(
xdrs.get(),
870 xdr_translator<T>());
872 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
873 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
874 <<
"The XDR interface is not available in this installation");
885 for (
unsigned int i=0; i<len; i++)
904 *
out << std::scientific
905 << std::setprecision(std::numeric_limits<T>::max_digits10);
908 for (
unsigned int i=0; i<len; i++)
912 *
out << val[i] <<
" ";
916 const unsigned imax = std::min(line_break, len);
920 for (
unsigned int i=0; i<imax; i++)
940 libmesh_error_msg(
"Invalid mode = " <<
mode);
References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
Referenced by libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_nodes(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::CheckpointIO::write_connectivity(), libMesh::CheckpointIO::write_nodes(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().
bool libMesh::Xdr::is_open |
( |
| ) |
const |
- Returns
true
if the Xdr file is open, false if it is closed.
Definition at line 341 of file xdr_cxx.C.
348 #ifdef LIBMESH_HAVE_XDR
358 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
359 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
360 <<
"The XDR interface is not available in this installation");
370 if (
in.get() !=
nullptr)
377 if (
out.get() !=
nullptr)
383 libmesh_error_msg(
"Invalid mode = " <<
mode);
References libMesh::DECODE, libMesh::ENCODE, fp, in, mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
Referenced by data(), data_stream(), and libMesh::System::read_parallel_data().
void libMesh::Xdr::open |
( |
const std::string & |
name | ) |
|
Opens the file.
Definition at line 162 of file xdr_cxx.C.
174 #ifdef LIBMESH_HAVE_XDR
178 libmesh_file_error(
name.c_str());
179 xdrs = libmesh_make_unique<XDR>();
180 xdrstdio_create (
xdrs.get(),
fp, (
mode ==
ENCODE) ? XDR_ENCODE : XDR_DECODE);
183 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
184 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
185 <<
"The XDR interface is not available in this installation");
200 #ifdef LIBMESH_HAVE_GZSTREAM
201 igzstream * inf =
new igzstream;
204 inf->open(
name.c_str(), std::ios::in);
206 libmesh_error_msg(
"ERROR: need gzstream to handle .gz files!!!");
211 std::ifstream * inf =
new std::ifstream;
215 std::string new_name = unzip_file(
name);
217 inf->open(new_name.c_str(), std::ios::in);
223 libmesh_file_error(
name);
235 #ifdef LIBMESH_HAVE_GZSTREAM
236 ogzstream * outf =
new ogzstream;
241 libmesh_error_msg(
"ERROR: need gzstream to handle .gz files!!!");
246 std::ofstream * outf =
new std::ofstream;
250 std::string new_name =
name;
253 new_name.erase(new_name.end() - 4, new_name.end());
256 new_name.erase(new_name.end() - 3, new_name.end());
267 libmesh_error_msg(
"Invalid mode = " <<
mode);
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().