|
| 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 > |
Xdr & | operator<< (T &a) |
|
template<typename T > |
Xdr & | operator>> (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) |
|
C++ interface for the XDR (eXternal Data Representation) format.
This class implements a C++ interface to the XDR (eXternal Data Representation) format. XDR is useful for creating platform-independent binary files. This class was created to handle equation system output as a replacement for XdrIO since that is somewhat limited.
- Author
- Benjamin Kirk
- Date
- 2003
Definition at line 66 of file xdr_cxx.h.
void libMesh::Xdr::close |
( |
| ) |
|
Closes the file if it is open.
Definition at line 273 of file xdr_cxx.C.
References bzipped_file, libMesh::DECODE, libMesh::ENCODE, file_name, fp, in, mode, out, libMesh::READ, libMesh::WRITE, xdrs, and xzipped_file.
Referenced by libMesh::EquationSystems::_read_impl(), libMesh::CheckpointIO::read(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), and ~Xdr().
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);
std::unique_ptr< std::istream > in
std::unique_ptr< std::ostream > out
std::unique_ptr< XDR > xdrs
template<typename T >
template void libMesh::Xdr::data< long double > |
( |
T & |
a, |
|
|
const char * |
comment = "" |
|
) |
| |
Inputs or outputs a single value.
Definition at line 761 of file xdr_cxx.C.
References libMesh::DECODE, do_read(), do_write(), libMesh::ENCODE, in, is_open(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
Referenced by libMesh::EquationSystems::_read_impl(), do_read(), do_write(), operator<<(), operator>>(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_bc_names(), libMesh::CheckpointIO::read_bcs(), libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), libMesh::CheckpointIO::read_nodes(), libMesh::CheckpointIO::read_nodesets(), libMesh::System::read_parallel_data(), libMesh::CheckpointIO::read_remote_elem(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::CheckpointIO::read_subdomain_names(), libMesh::CheckpointIO::select_split_config(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), libMesh::EquationSystems::write(), libMesh::CheckpointIO::write_bc_names(), libMesh::CheckpointIO::write_bcs(), libMesh::CheckpointIO::write_connectivity(), libMesh::System::write_header(), libMesh::CheckpointIO::write_nodes(), libMesh::CheckpointIO::write_nodesets(), libMesh::System::write_parallel_data(), libMesh::CheckpointIO::write_remote_elem(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), and libMesh::CheckpointIO::write_subdomain_names().
768 #ifdef LIBMESH_HAVE_XDR 772 xdr_translate(
xdrs.get(), a);
776 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
777 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
778 <<
"The XDR interface is not available in this installation");
786 libmesh_assert(
in.get());
787 libmesh_assert (
in->good());
796 libmesh_assert(
out.get());
797 libmesh_assert (
out->good());
802 *
out << std::scientific
803 << std::setprecision(16);
809 if (std::string(comment_in) !=
"")
810 *
out <<
"\t " << comment_in;
819 libmesh_error_msg(
"Invalid mode = " <<
mode);
std::unique_ptr< std::istream > in
std::unique_ptr< std::ostream > out
std::unique_ptr< XDR > xdrs
template<typename T >
void libMesh::Xdr::data_stream |
( |
T * |
val, |
|
|
const unsigned int |
len, |
|
|
const unsigned int |
line_break = libMesh::invalid_uint |
|
) |
| |
Inputs or outputs a raw data stream.
Definition at line 825 of file xdr_cxx.C.
References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), std::min(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
Referenced by libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_nodes(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::CheckpointIO::write_connectivity(), libMesh::CheckpointIO::write_nodes(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().
831 #ifdef LIBMESH_HAVE_XDR 833 libmesh_assert (this->
is_open());
835 unsigned int size_of_type = cast_int<unsigned int>(
sizeof(T));
837 xdr_vector(
xdrs.get(),
841 xdr_translator<T>());
843 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
844 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
845 <<
"The XDR interface is not available in this installation");
853 #ifdef LIBMESH_HAVE_XDR 855 libmesh_assert (this->
is_open());
857 unsigned int size_of_type = cast_int<unsigned int>(
sizeof(T));
860 xdr_vector(
xdrs.get(),
864 xdr_translator<T>());
866 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
867 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
868 <<
"The XDR interface is not available in this installation");
876 libmesh_assert(
in.get());
877 libmesh_assert (
in->good());
879 for (
unsigned int i=0; i<len; i++)
881 libmesh_assert(
in.get());
882 libmesh_assert (
in->good());
891 libmesh_assert(
out.get());
892 libmesh_assert (
out->good());
897 *
out << std::scientific
898 << std::setprecision(16);
901 for (
unsigned int i=0; i<len; i++)
903 libmesh_assert(
out.get());
904 libmesh_assert (
out->good());
905 *
out << val[i] <<
" ";
909 const unsigned imax =
std::min(line_break, len);
913 for (
unsigned int i=0; i<imax; i++)
915 libmesh_assert(
out.get());
916 libmesh_assert (
out->good());
923 libmesh_assert(
out.get());
924 libmesh_assert (
out->good());
933 libmesh_error_msg(
"Invalid mode = " <<
mode);
const unsigned int invalid_uint
std::unique_ptr< std::istream > in
std::unique_ptr< std::ostream > out
std::unique_ptr< XDR > xdrs
long double min(long double a, double b)
template<>
void libMesh::Xdr::data_stream |
( |
double * |
val, |
|
|
const unsigned int |
len, |
|
|
const unsigned int |
line_break |
|
) |
| |
Definition at line 940 of file xdr_cxx.C.
References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), std::min(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
947 #ifdef LIBMESH_HAVE_XDR 949 libmesh_assert (this->
is_open());
952 xdr_vector(
xdrs.get(),
956 (xdrproc_t) xdr_double);
960 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
961 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
962 <<
"The XDR interface is not available in this installation");
970 libmesh_assert(
in.get());
971 libmesh_assert (
in->good());
973 for (
unsigned int i=0; i<len; i++)
975 libmesh_assert(
in.get());
976 libmesh_assert (
in->good());
985 libmesh_assert(
out.get());
986 libmesh_assert (
out->good());
989 std::ios_base::fmtflags out_flags =
out->flags();
994 *
out << std::scientific
995 << std::setprecision(16);
998 for (
unsigned int i=0; i<len; i++)
1000 libmesh_assert(
out.get());
1001 libmesh_assert (
out->good());
1002 *
out << val[i] <<
' ';
1006 const unsigned imax =
std::min(line_break, len);
1010 for (
unsigned int i=0; i<imax; i++)
1012 libmesh_assert(
out.get());
1013 libmesh_assert (
out->good());
1020 libmesh_assert(
out.get());
1021 libmesh_assert (
out->good());
1027 out->flags(out_flags);
1033 libmesh_error_msg(
"Invalid mode = " <<
mode);
const unsigned int invalid_uint
std::unique_ptr< std::istream > in
std::unique_ptr< std::ostream > out
std::unique_ptr< XDR > xdrs
long double min(long double a, double b)
template<>
void libMesh::Xdr::data_stream |
( |
float * |
val, |
|
|
const unsigned int |
len, |
|
|
const unsigned int |
line_break |
|
) |
| |
Definition at line 1039 of file xdr_cxx.C.
References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), std::min(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
1046 #ifdef LIBMESH_HAVE_XDR 1048 libmesh_assert (this->
is_open());
1051 xdr_vector(
xdrs.get(),
1055 (xdrproc_t) xdr_float);
1059 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
1060 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1061 <<
"The XDR interface is not available in this installation");
1069 libmesh_assert(
in.get());
1070 libmesh_assert (
in->good());
1072 for (
unsigned int i=0; i<len; i++)
1074 libmesh_assert(
in.get());
1075 libmesh_assert (
in->good());
1084 libmesh_assert(
out.get());
1085 libmesh_assert (
out->good());
1088 std::ios_base::fmtflags out_flags =
out->flags();
1093 *
out << std::scientific
1094 << std::setprecision(16);
1097 for (
unsigned int i=0; i<len; i++)
1099 libmesh_assert(
out.get());
1100 libmesh_assert (
out->good());
1101 *
out << val[i] <<
' ';
1105 const unsigned imax =
std::min(line_break, len);
1109 for (
unsigned int i=0; i<imax; i++)
1111 libmesh_assert(
out.get());
1112 libmesh_assert (
out->good());
1119 libmesh_assert(
out.get());
1120 libmesh_assert (
out->good());
1126 out->flags(out_flags);
1132 libmesh_error_msg(
"Invalid mode = " <<
mode);
const unsigned int invalid_uint
std::unique_ptr< std::istream > in
std::unique_ptr< std::ostream > out
std::unique_ptr< XDR > xdrs
long double min(long double a, double b)
template<>
void libMesh::Xdr::data_stream |
( |
long double * |
val, |
|
|
const unsigned int |
len, |
|
|
const unsigned int |
line_break |
|
) |
| |
Definition at line 1136 of file xdr_cxx.C.
References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), std::min(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
1143 #ifdef LIBMESH_HAVE_XDR 1145 libmesh_assert (this->
is_open());
1161 std::vector<double> io_buffer (len);
1165 for (
unsigned int i=0, cnt=0; i<len; i++)
1166 io_buffer[cnt++] =
double(val[i]);
1168 xdr_vector(
xdrs.get(),
1169 reinterpret_cast<char *
>(io_buffer.data()),
1172 (xdrproc_t) xdr_double);
1176 for (
unsigned int i=0, cnt=0; i<len; i++)
1178 val[i] = io_buffer[cnt++];
1184 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
1185 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1186 <<
"The XDR interface is not available in this installation");
1194 libmesh_assert(
in.get());
1195 libmesh_assert (
in->good());
1197 for (
unsigned int i=0; i<len; i++)
1199 libmesh_assert(
in.get());
1200 libmesh_assert (
in->good());
1209 libmesh_assert(
out.get());
1210 libmesh_assert (
out->good());
1213 std::ios_base::fmtflags out_flags =
out->flags();
1218 *
out << std::scientific
1219 << std::setprecision(16);
1222 for (
unsigned int i=0; i<len; i++)
1224 libmesh_assert(
out.get());
1225 libmesh_assert (
out->good());
1226 *
out << val[i] <<
' ';
1230 const unsigned imax =
std::min(line_break, len);
1234 for (
unsigned int i=0; i<imax; i++)
1236 libmesh_assert(
out.get());
1237 libmesh_assert (
out->good());
1244 libmesh_assert(
out.get());
1245 libmesh_assert (
out->good());
1251 out->flags(out_flags);
1257 libmesh_error_msg(
"Invalid mode = " <<
mode);
const unsigned int invalid_uint
std::unique_ptr< std::istream > in
std::unique_ptr< std::ostream > out
std::unique_ptr< XDR > xdrs
long double min(long double a, double b)
template<>
void libMesh::Xdr::data_stream |
( |
std::complex< double > * |
val, |
|
|
const unsigned int |
len, |
|
|
const unsigned int |
line_break |
|
) |
| |
Definition at line 1264 of file xdr_cxx.C.
References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), std::min(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
1271 #ifdef LIBMESH_HAVE_XDR 1273 libmesh_assert (this->
is_open());
1278 std::vector<double> io_buffer (2*len);
1282 for (
unsigned int i=0, cnt=0; i<len; i++)
1284 io_buffer[cnt++] = val[i].real();
1285 io_buffer[cnt++] = val[i].imag();
1288 xdr_vector(
xdrs.get(),
1289 reinterpret_cast<char *
>(io_buffer.data()),
1292 (xdrproc_t) xdr_double);
1296 for (
unsigned int i=0, cnt=0; i<len; i++)
1298 double re = io_buffer[cnt++];
1299 double im = io_buffer[cnt++];
1300 val[i] = std::complex<double>(re,im);
1305 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
1306 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1307 <<
"The XDR interface is not available in this installation");
1315 libmesh_assert(
in.get());
1316 libmesh_assert (
in->good());
1318 for (
unsigned int i=0; i<len; i++)
1320 libmesh_assert(
in.get());
1321 libmesh_assert (
in->good());
1324 val[i] = std::complex<double>(re,im);
1332 libmesh_assert(
out.get());
1333 libmesh_assert (
out->good());
1336 std::ios_base::fmtflags out_flags =
out->flags();
1341 *
out << std::scientific
1342 << std::setprecision(16);
1345 for (
unsigned int i=0; i<len; i++)
1347 libmesh_assert(
out.get());
1348 libmesh_assert (
out->good());
1349 *
out << val[i].real() <<
' ';
1350 *
out << val[i].imag() <<
' ';
1354 const unsigned imax =
std::min(line_break, len);
1358 for (
unsigned int i=0; i<imax; i++)
1360 libmesh_assert(
out.get());
1361 libmesh_assert (
out->good());
1362 *
out << val[cnt].real() <<
' ';
1363 *
out << val[cnt].imag();
1370 libmesh_assert(
out.get());
1371 libmesh_assert (
out->good());
1377 out->flags(out_flags);
1383 libmesh_error_msg(
"Invalid mode = " <<
mode);
const unsigned int invalid_uint
std::unique_ptr< std::istream > in
std::unique_ptr< std::ostream > out
std::unique_ptr< XDR > xdrs
long double min(long double a, double b)
template<>
void libMesh::Xdr::data_stream |
( |
std::complex< long double > * |
val, |
|
|
const unsigned int |
len, |
|
|
const unsigned int |
line_break |
|
) |
| |
Definition at line 1388 of file xdr_cxx.C.
References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), std::min(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.
1395 #ifdef LIBMESH_HAVE_XDR 1397 libmesh_assert (this->
is_open());
1407 std::vector<double> io_buffer (2*len);
1411 for (
unsigned int i=0, cnt=0; i<len; i++)
1413 io_buffer[cnt++] = val[i].real();
1414 io_buffer[cnt++] = val[i].imag();
1417 xdr_vector(
xdrs.get(),
1418 reinterpret_cast<char *
>(io_buffer.data()),
1421 (xdrproc_t) xdr_double);
1425 for (
unsigned int i=0, cnt=0; i<len; i++)
1427 double re = io_buffer[cnt++];
1428 double im = io_buffer[cnt++];
1429 val[i] = std::complex<long double>(re, im);
1434 libmesh_error_msg(
"ERROR: Functionality is not available.\n" \
1435 <<
"Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1436 <<
"The XDR interface is not available in this installation");
1444 libmesh_assert(
in.get());
1445 libmesh_assert (
in->good());
1447 for (
unsigned int i=0; i<len; i++)
1449 libmesh_assert(
in.get());
1450 libmesh_assert (
in->good());
1453 val[i] = std::complex<long double>(re,im);
1461 libmesh_assert(
out.get());
1462 libmesh_assert (
out->good());
1466 std::ios_base::fmtflags out_flags =
out->flags();
1474 *
out << std::scientific
1475 << std::setprecision(std::numeric_limits<long double>::digits10);
1478 for (
unsigned int i=0; i<len; i++)
1480 libmesh_assert(
out.get());
1481 libmesh_assert (
out->good());
1482 *
out << val[i].real() <<
' ' << val[i].imag() <<
' ';
1486 const unsigned imax =
std::min(line_break, len);
1490 for (
unsigned int i=0; i<imax; i++)
1492 libmesh_assert(
out.get());
1493 libmesh_assert (
out->good());
1494 *
out << val[cnt].real() <<
' ' << val[cnt].imag();
1501 libmesh_assert(
out.get());
1502 libmesh_assert (
out->good());
1508 out->flags(out_flags);
1514 libmesh_error_msg(
"Invalid mode = " <<
mode);
const unsigned int invalid_uint
std::unique_ptr< std::istream > in
std::unique_ptr< std::ostream > out
std::unique_ptr< XDR > xdrs
long double min(long double a, double b)
void libMesh::Xdr::open |
( |
const std::string & |
name | ) |
|
Opens the file.
Definition at line 162 of file xdr_cxx.C.
References bzipped_file, libMesh::DECODE, libMesh::ENCODE, file_name, fp, gzipped_file, in, mode, libMesh::Quality::name(), libMesh::out, out, libMesh::READ, libMesh::WRITE, xdrs, and xzipped_file.
Referenced by Xdr().
174 #ifdef LIBMESH_HAVE_XDR 178 libmesh_file_error(
name.c_str());
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);
220 libmesh_assert(
in.get());
223 libmesh_file_error(
name);
235 #ifdef LIBMESH_HAVE_GZSTREAM 236 ogzstream * outf =
new ogzstream;
237 libmesh_assert(outf);
241 libmesh_error_msg(
"ERROR: need gzstream to handle .gz files!!!");
246 std::ofstream * outf =
new std::ofstream;
247 libmesh_assert(outf);
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());
261 libmesh_assert(
out.get());
262 libmesh_assert (
out->good());
267 libmesh_error_msg(
"Invalid mode = " <<
mode);
std::string name(const ElemQuality q)
std::unique_ptr< std::istream > in
std::unique_ptr< std::ostream > out
std::unique_ptr< XDR > xdrs
OStreamProxy out(std::cout)