libMesh::Xdr Class Reference
#include <xdr_cxx.h>
Public Member Functions | |
| Xdr (const std::string &name="", const libMeshEnums::XdrMODE m=UNKNOWN) | |
| ~Xdr () | |
| void | open (const std::string &name) |
| void | close () |
| bool | is_open () const |
| 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) |
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 |
| XDR * | xdrs |
| FILE * | fp |
| AutoPtr< std::istream > | in |
| AutoPtr< 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
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.
Definition at line 65 of file xdr_cxx.h.
Constructor & Destructor Documentation
| libMesh::Xdr::Xdr | ( | const std::string & | name = "", |
|
| const libMeshEnums::XdrMODE | m = UNKNOWN | |||
| ) |
Constructor. Takes the filename and the mode. Valid modes are ENCODE, DECODE, READ, and WRITE.
| libMesh::Xdr::~Xdr | ( | ) |
Member Function Documentation
| XdrMODE libMesh::Xdr::access_mode | ( | ) | const [inline] |
| void libMesh::Xdr::close | ( | ) |
Closes the file if it is open.
Definition at line 302 of file xdr_cxx.C.
References bzipped_file, libMeshEnums::DECODE, libMeshEnums::ENCODE, libMesh::err, file_name, fp, libMesh::AutoPtr< Tp >::get(), in, mode, out, libMeshEnums::READ, libMesh::AutoPtr< Tp >::reset(), libMeshEnums::WRITE, xdrs, and xzipped_file.
Referenced by libMesh::EquationSystems::_read_impl(), libMesh::XdrIO::read(), libMesh::XdrIO::write(), and ~Xdr().
00303 { 00304 switch (mode) 00305 { 00306 case ENCODE: 00307 case DECODE: 00308 { 00309 #ifdef LIBMESH_HAVE_XDR 00310 00311 if (xdrs) 00312 { 00313 xdr_destroy (xdrs); 00314 delete xdrs; 00315 xdrs = NULL; 00316 } 00317 00318 if (fp) 00319 { 00320 fflush(fp); 00321 fclose(fp); 00322 fp = NULL; 00323 } 00324 #else 00325 00326 libMesh::err << "ERROR: Functionality is not available." << std::endl 00327 << "Make sure LIBMESH_HAVE_XDR is defined at build time" 00328 << std::endl 00329 << "The XDR interface is not available in this installation" 00330 << std::endl; 00331 00332 libmesh_error(); 00333 00334 #endif 00335 file_name = ""; 00336 return; 00337 } 00338 00339 case READ: 00340 { 00341 if (in.get() != NULL) 00342 { 00343 in.reset(); 00344 00345 if (bzipped_file || xzipped_file) 00346 remove_unzipped_file(file_name); 00347 } 00348 file_name = ""; 00349 return; 00350 } 00351 00352 case WRITE: 00353 { 00354 if (out.get() != NULL) 00355 { 00356 out.reset(); 00357 00358 if (bzipped_file) 00359 bzip_file(std::string(file_name.begin(), file_name.end()-4)); 00360 00361 else if (xzipped_file) 00362 xzip_file(std::string(file_name.begin(), file_name.end()-3)); 00363 } 00364 file_name = ""; 00365 return; 00366 } 00367 00368 default: 00369 libmesh_error(); 00370 } 00371 }
| void libMesh::Xdr::comment | ( | std::string & | comment_in | ) |
Writes or reads (ignores) a comment line.
Definition at line 1374 of file xdr_cxx.C.
References comm, comm_len, libMeshEnums::DECODE, libMeshEnums::ENCODE, libMesh::AutoPtr< Tp >::get(), in, mode, out, libMeshEnums::READ, and libMeshEnums::WRITE.
Referenced by libMesh::System::read_serialized_data(), and libMesh::System::write_serialized_data().
01375 { 01376 switch (mode) 01377 { 01378 case ENCODE: 01379 case DECODE: 01380 { 01381 return; 01382 } 01383 01384 case READ: 01385 { 01386 libmesh_assert(in.get()); 01387 libmesh_assert (in->good()); 01388 in->getline(comm, comm_len); 01389 return; 01390 } 01391 01392 case WRITE: 01393 { 01394 libmesh_assert(out.get()); 01395 libmesh_assert (out->good()); 01396 *out << "\t " << comment_in << '\n'; 01397 return; 01398 } 01399 01400 default: 01401 libmesh_error(); 01402 } 01403 }
| void libMesh::Xdr::data | ( | T & | a, | |
| const char * | comment = "" | |||
| ) | [inline] |
Inputs or outputs a single value.
Definition at line 632 of file xdr_cxx.C.
References libMeshEnums::DECODE, do_read(), do_write(), libMeshEnums::ENCODE, libMesh::err, libMesh::AutoPtr< Tp >::get(), in, is_open(), mode, out, libMeshEnums::READ, libMeshEnums::WRITE, and xdrs.
Referenced by libMesh::EquationSystems::_read_impl(), do_read(), do_write(), operator<<(), operator>>(), libMesh::XdrIO::read(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), libMesh::System::read_parallel_data(), libMesh::XdrIO::read_serialized_bcs(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::MeshData::read_xdr(), libMesh::XdrIO::write(), libMesh::EquationSystems::write(), libMesh::System::write_header(), libMesh::System::write_parallel_data(), libMesh::XdrIO::write_serialized_bcs(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), and libMesh::MeshData::write_xdr().
00633 { 00634 switch (mode) 00635 { 00636 case ENCODE: 00637 case DECODE: 00638 { 00639 #ifdef LIBMESH_HAVE_XDR 00640 00641 libmesh_assert (is_open()); 00642 00643 xdr_translate(xdrs, a); 00644 00645 #else 00646 00647 libMesh::err << "ERROR: Functionality is not available." << std::endl 00648 << "Make sure LIBMESH_HAVE_XDR is defined at build time" 00649 << std::endl 00650 << "The XDR interface is not available in this installation" 00651 << std::endl; 00652 00653 libmesh_error(); 00654 00655 #endif 00656 return; 00657 } 00658 00659 case READ: 00660 { 00661 libmesh_assert(in.get()); 00662 libmesh_assert (in->good()); 00663 00664 this->do_read(a); 00665 00666 return; 00667 } 00668 00669 case WRITE: 00670 { 00671 libmesh_assert(out.get()); 00672 libmesh_assert (out->good()); 00673 00674 this->do_write(a); 00675 *out << "\t " << comment_in << '\n'; 00676 00677 return; 00678 } 00679 00680 default: 00681 libmesh_error(); 00682 } 00683 }
| void libMesh::Xdr::data_stream | ( | std::complex< long double > * | val, | |
| const unsigned int | len, | |||
| const unsigned int | line_break | |||
| ) | [inline] |
Definition at line 1244 of file xdr_cxx.C.
References libMeshEnums::DECODE, libMeshEnums::ENCODE, libMesh::err, libMesh::AutoPtr< Tp >::get(), in, libMesh::invalid_uint, is_open(), std::min(), mode, out, libMeshEnums::READ, libMeshEnums::WRITE, and xdrs.
01245 { 01246 switch (mode) 01247 { 01248 case ENCODE: 01249 case DECODE: 01250 { 01251 #ifdef LIBMESH_HAVE_XDR 01252 01253 libmesh_assert (this->is_open()); 01254 01255 // FIXME[JWP]: How to implement this for long double? Mac OS 01256 // X defines 'xdr_quadruple' but AFAICT, it does not exist for 01257 // Linux... for now, reading/writing XDR files with long 01258 // doubles drops back to double precision, but you can still 01259 // write long double ASCII files of course. 01260 01261 if (len > 0) 01262 { 01263 std::vector<double> io_buffer (2*len); 01264 01265 // Fill io_buffer if we are writing. 01266 if (mode == ENCODE) 01267 for (unsigned int i=0, cnt=0; i<len; i++) 01268 { 01269 io_buffer[cnt++] = val[i].real(); 01270 io_buffer[cnt++] = val[i].imag(); 01271 } 01272 01273 xdr_vector(xdrs, 01274 (char*) &io_buffer[0], 01275 2*len, 01276 sizeof(double), 01277 (xdrproc_t) xdr_double); 01278 01279 // Fill val array if we are reading. 01280 if (mode == DECODE) 01281 for (unsigned int i=0, cnt=0; i<len; i++) 01282 { 01283 double re = io_buffer[cnt++]; 01284 double im = io_buffer[cnt++]; 01285 val[i] = std::complex<long double>(re, im); 01286 } 01287 } 01288 #else 01289 01290 libMesh::err << "ERROR: Functionality is not available." << std::endl 01291 << "Make sure LIBMESH_HAVE_XDR is defined at build time" 01292 << std::endl 01293 << "The XDR interface is not available in this installation" 01294 << std::endl; 01295 01296 libmesh_error(); 01297 01298 #endif 01299 return; 01300 } 01301 01302 case READ: 01303 { 01304 libmesh_assert(in.get()); 01305 libmesh_assert (in->good()); 01306 01307 for (unsigned int i=0; i<len; i++) 01308 { 01309 libmesh_assert(in.get()); 01310 libmesh_assert (in->good()); 01311 long double re, im; 01312 *in >> re >> im; 01313 val[i] = std::complex<long double>(re,im); 01314 } 01315 01316 return; 01317 } 01318 01319 case WRITE: 01320 { 01321 libmesh_assert(out.get()); 01322 libmesh_assert (out->good()); 01323 01324 01325 // Save stream flags 01326 std::ios_base::fmtflags out_flags = out->flags(); 01327 01328 // We will use scientific notation with a precision of 01329 // 'digits10' digits in the following output. The desired 01330 // precision and format will automatically determine the 01331 // width. Note: digit10 is the number of digits (in decimal 01332 // base) that can be represented without change. Equivalent 01333 // to FLT_DIG, DBL_DIG or LDBL_DIG for floating types. 01334 *out << std::scientific 01335 << std::setprecision(std::numeric_limits<long double>::digits10); 01336 01337 if (line_break == libMesh::invalid_uint) 01338 for (unsigned int i=0; i<len; i++) 01339 { 01340 libmesh_assert(out.get()); 01341 libmesh_assert (out->good()); 01342 *out << val[i].real() << ' ' << val[i].imag() << ' '; 01343 } 01344 else 01345 { 01346 unsigned int cnt=0; 01347 while (cnt < len) 01348 { 01349 for (unsigned int i=0; i<std::min(line_break,len); i++) 01350 { 01351 libmesh_assert(out.get()); 01352 libmesh_assert (out->good()); 01353 *out << val[cnt].real() << ' ' << val[cnt].imag() << ' '; 01354 cnt++; 01355 } 01356 libmesh_assert(out.get()); 01357 libmesh_assert (out->good()); 01358 *out << '\n'; 01359 } 01360 } 01361 01362 // Restore stream flags 01363 out->flags(out_flags); 01364 01365 return; 01366 } 01367 01368 default: 01369 libmesh_error(); 01370 } 01371 }
| void libMesh::Xdr::data_stream | ( | std::complex< double > * | val, | |
| const unsigned int | len, | |||
| const unsigned int | line_break | |||
| ) | [inline] |
Definition at line 1121 of file xdr_cxx.C.
References libMeshEnums::DECODE, libMeshEnums::ENCODE, libMesh::err, libMesh::AutoPtr< Tp >::get(), in, libMesh::invalid_uint, is_open(), std::min(), mode, out, libMeshEnums::READ, libMeshEnums::WRITE, and xdrs.
01122 { 01123 switch (mode) 01124 { 01125 case ENCODE: 01126 case DECODE: 01127 { 01128 #ifdef LIBMESH_HAVE_XDR 01129 01130 libmesh_assert (this->is_open()); 01131 01132 01133 if (len > 0) 01134 { 01135 std::vector<double> io_buffer (2*len); 01136 01137 // Fill io_buffer if we are writing. 01138 if (mode == ENCODE) 01139 for (unsigned int i=0, cnt=0; i<len; i++) 01140 { 01141 io_buffer[cnt++] = val[i].real(); 01142 io_buffer[cnt++] = val[i].imag(); 01143 } 01144 01145 xdr_vector(xdrs, 01146 (char*) &io_buffer[0], 01147 2*len, 01148 sizeof(double), 01149 (xdrproc_t) xdr_double); 01150 01151 // Fill val array if we are reading. 01152 if (mode == DECODE) 01153 for (unsigned int i=0, cnt=0; i<len; i++) 01154 { 01155 double re = io_buffer[cnt++]; 01156 double im = io_buffer[cnt++]; 01157 val[i] = std::complex<double>(re,im); 01158 } 01159 } 01160 #else 01161 01162 libMesh::err << "ERROR: Functionality is not available." << std::endl 01163 << "Make sure LIBMESH_HAVE_XDR is defined at build time" 01164 << std::endl 01165 << "The XDR interface is not available in this installation" 01166 << std::endl; 01167 01168 libmesh_error(); 01169 01170 #endif 01171 return; 01172 } 01173 01174 case READ: 01175 { 01176 libmesh_assert(in.get()); 01177 libmesh_assert (in->good()); 01178 01179 for (unsigned int i=0; i<len; i++) 01180 { 01181 libmesh_assert(in.get()); 01182 libmesh_assert (in->good()); 01183 double re, im; 01184 *in >> re >> im; 01185 val[i] = std::complex<double>(re,im); 01186 } 01187 01188 return; 01189 } 01190 01191 case WRITE: 01192 { 01193 libmesh_assert(out.get()); 01194 libmesh_assert (out->good()); 01195 01196 // Save stream flags 01197 std::ios_base::fmtflags out_flags = out->flags(); 01198 01199 // We will use scientific notation with a precision of 16 01200 // digits in the following output. The desired precision and 01201 // format will automatically determine the width. 01202 *out << std::scientific 01203 << std::setprecision(16); 01204 01205 if (line_break == libMesh::invalid_uint) 01206 for (unsigned int i=0; i<len; i++) 01207 { 01208 libmesh_assert(out.get()); 01209 libmesh_assert (out->good()); 01210 *out << val[i].real() << ' '; 01211 *out << val[i].imag() << ' '; 01212 } 01213 else 01214 { 01215 unsigned int cnt=0; 01216 while (cnt < len) 01217 { 01218 for (unsigned int i=0; i<std::min(line_break,len); i++) 01219 { 01220 libmesh_assert(out.get()); 01221 libmesh_assert (out->good()); 01222 *out << val[cnt].real() << ' '; 01223 *out << val[cnt].imag() << ' '; 01224 cnt++; 01225 } 01226 libmesh_assert(out.get()); 01227 libmesh_assert (out->good()); 01228 *out << '\n'; 01229 } 01230 } 01231 01232 // Restore stream flags 01233 out->flags(out_flags); 01234 01235 return; 01236 } 01237 01238 default: 01239 libmesh_error(); 01240 } 01241 }
| void libMesh::Xdr::data_stream | ( | long double * | val, | |
| const unsigned int | len, | |||
| const unsigned int | line_break | |||
| ) | [inline] |
Definition at line 994 of file xdr_cxx.C.
References libMeshEnums::DECODE, libMeshEnums::ENCODE, libMesh::err, libMesh::AutoPtr< Tp >::get(), in, libMesh::invalid_uint, is_open(), std::min(), mode, out, libMeshEnums::READ, libMeshEnums::WRITE, and xdrs.
00995 { 00996 switch (mode) 00997 { 00998 case ENCODE: 00999 case DECODE: 01000 { 01001 #ifdef LIBMESH_HAVE_XDR 01002 01003 libmesh_assert (this->is_open()); 01004 01005 // FIXME[JWP]: How to implement this for long double? Mac OS 01006 // X defines 'xdr_quadruple' but AFAICT, it does not exist for 01007 // Linux... for now, reading/writing XDR files with long 01008 // doubles drops back to double precision, but you can still 01009 // write long double ASCII files of course. 01010 // if (len > 0) 01011 // xdr_vector(xdrs, 01012 // (char*) val, 01013 // len, 01014 // sizeof(double), 01015 // (xdrproc_t) xdr_quadruple); 01016 01017 if (len > 0) 01018 { 01019 std::vector<double> io_buffer (len); 01020 01021 // Fill io_buffer if we are writing. 01022 if (mode == ENCODE) 01023 for (unsigned int i=0, cnt=0; i<len; i++) 01024 io_buffer[cnt++] = val[i]; 01025 01026 xdr_vector(xdrs, 01027 (char*) &io_buffer[0], 01028 len, 01029 sizeof(double), 01030 (xdrproc_t) xdr_double); 01031 01032 // Fill val array if we are reading. 01033 if (mode == DECODE) 01034 for (unsigned int i=0, cnt=0; i<len; i++) 01035 { 01036 val[i] = io_buffer[cnt++]; 01037 } 01038 } 01039 01040 #else 01041 01042 libMesh::err << "ERROR: Functionality is not available." << std::endl 01043 << "Make sure LIBMESH_HAVE_XDR is defined at build time" 01044 << std::endl 01045 << "The XDR interface is not available in this installation" 01046 << std::endl; 01047 01048 libmesh_error(); 01049 01050 #endif 01051 return; 01052 } 01053 01054 case READ: 01055 { 01056 libmesh_assert(in.get()); 01057 libmesh_assert (in->good()); 01058 01059 for (unsigned int i=0; i<len; i++) 01060 { 01061 libmesh_assert(in.get()); 01062 libmesh_assert (in->good()); 01063 *in >> val[i]; 01064 } 01065 01066 return; 01067 } 01068 01069 case WRITE: 01070 { 01071 libmesh_assert(out.get()); 01072 libmesh_assert (out->good()); 01073 01074 // Save stream flags 01075 std::ios_base::fmtflags out_flags = out->flags(); 01076 01077 // We will use scientific notation with a precision of 16 01078 // digits in the following output. The desired precision and 01079 // format will automatically determine the width. 01080 *out << std::scientific 01081 << std::setprecision(16); 01082 01083 if (line_break == libMesh::invalid_uint) 01084 for (unsigned int i=0; i<len; i++) 01085 { 01086 libmesh_assert(out.get()); 01087 libmesh_assert (out->good()); 01088 *out << val[i] << ' '; 01089 } 01090 else 01091 { 01092 unsigned int cnt=0; 01093 while (cnt < len) 01094 { 01095 for (unsigned int i=0; i<std::min(line_break,len); i++) 01096 { 01097 libmesh_assert(out.get()); 01098 libmesh_assert (out->good()); 01099 *out << val[cnt++] << ' '; 01100 } 01101 libmesh_assert(out.get()); 01102 libmesh_assert (out->good()); 01103 *out << '\n'; 01104 } 01105 } 01106 01107 // Restore stream flags 01108 out->flags(out_flags); 01109 01110 return; 01111 } 01112 01113 default: 01114 libmesh_error(); 01115 } 01116 }
| void libMesh::Xdr::data_stream | ( | float * | val, | |
| const unsigned int | len, | |||
| const unsigned int | line_break | |||
| ) | [inline] |
Definition at line 898 of file xdr_cxx.C.
References libMeshEnums::DECODE, libMeshEnums::ENCODE, libMesh::err, libMesh::AutoPtr< Tp >::get(), in, libMesh::invalid_uint, is_open(), std::min(), mode, out, libMeshEnums::READ, libMeshEnums::WRITE, and xdrs.
00899 { 00900 switch (mode) 00901 { 00902 case ENCODE: 00903 case DECODE: 00904 { 00905 #ifdef LIBMESH_HAVE_XDR 00906 00907 libmesh_assert (this->is_open()); 00908 00909 if (len > 0) 00910 xdr_vector(xdrs, 00911 (char*) val, 00912 len, 00913 sizeof(float), 00914 (xdrproc_t) xdr_float); 00915 00916 #else 00917 00918 libMesh::err << "ERROR: Functionality is not available." << std::endl 00919 << "Make sure LIBMESH_HAVE_XDR is defined at build time" 00920 << std::endl 00921 << "The XDR interface is not available in this installation" 00922 << std::endl; 00923 00924 libmesh_error(); 00925 00926 #endif 00927 return; 00928 } 00929 00930 case READ: 00931 { 00932 libmesh_assert(in.get()); 00933 libmesh_assert (in->good()); 00934 00935 for (unsigned int i=0; i<len; i++) 00936 { 00937 libmesh_assert(in.get()); 00938 libmesh_assert (in->good()); 00939 *in >> val[i]; 00940 } 00941 00942 return; 00943 } 00944 00945 case WRITE: 00946 { 00947 libmesh_assert(out.get()); 00948 libmesh_assert (out->good()); 00949 00950 // Save stream flags 00951 std::ios_base::fmtflags out_flags = out->flags(); 00952 00953 // We will use scientific notation with a precision of 16 00954 // digits in the following output. The desired precision and 00955 // format will automatically determine the width. 00956 *out << std::scientific 00957 << std::setprecision(16); 00958 00959 if (line_break == libMesh::invalid_uint) 00960 for (unsigned int i=0; i<len; i++) 00961 { 00962 libmesh_assert(out.get()); 00963 libmesh_assert (out->good()); 00964 *out << val[i] << ' '; 00965 } 00966 else 00967 { 00968 unsigned int cnt=0; 00969 while (cnt < len) 00970 { 00971 for (unsigned int i=0; i<std::min(line_break,len); i++) 00972 { 00973 libmesh_assert(out.get()); 00974 libmesh_assert (out->good()); 00975 *out << val[cnt++] << ' '; 00976 } 00977 libmesh_assert(out.get()); 00978 libmesh_assert (out->good()); 00979 *out << '\n'; 00980 } 00981 } 00982 00983 // Restore stream flags 00984 out->flags(out_flags); 00985 00986 return; 00987 } 00988 00989 default: 00990 libmesh_error(); 00991 } 00992 }
| void libMesh::Xdr::data_stream | ( | double * | val, | |
| const unsigned int | len, | |||
| const unsigned int | line_break | |||
| ) | [inline] |
Definition at line 800 of file xdr_cxx.C.
References libMeshEnums::DECODE, libMeshEnums::ENCODE, libMesh::err, libMesh::AutoPtr< Tp >::get(), in, libMesh::invalid_uint, is_open(), std::min(), mode, out, libMeshEnums::READ, libMeshEnums::WRITE, and xdrs.
00801 { 00802 switch (mode) 00803 { 00804 case ENCODE: 00805 case DECODE: 00806 { 00807 #ifdef LIBMESH_HAVE_XDR 00808 00809 libmesh_assert (this->is_open()); 00810 00811 if (len > 0) 00812 xdr_vector(xdrs, 00813 (char*) val, 00814 len, 00815 sizeof(double), 00816 (xdrproc_t) xdr_double); 00817 00818 #else 00819 00820 libMesh::err << "ERROR: Functionality is not available." << std::endl 00821 << "Make sure LIBMESH_HAVE_XDR is defined at build time" 00822 << std::endl 00823 << "The XDR interface is not available in this installation" 00824 << std::endl; 00825 00826 libmesh_error(); 00827 00828 #endif 00829 return; 00830 } 00831 00832 case READ: 00833 { 00834 libmesh_assert(in.get()); 00835 libmesh_assert (in->good()); 00836 00837 for (unsigned int i=0; i<len; i++) 00838 { 00839 libmesh_assert(in.get()); 00840 libmesh_assert (in->good()); 00841 *in >> val[i]; 00842 } 00843 00844 return; 00845 } 00846 00847 case WRITE: 00848 { 00849 libmesh_assert(out.get()); 00850 libmesh_assert (out->good()); 00851 00852 // Save stream flags 00853 std::ios_base::fmtflags out_flags = out->flags(); 00854 00855 // We will use scientific notation with a precision of 16 00856 // digits in the following output. The desired precision and 00857 // format will automatically determine the width. 00858 *out << std::scientific 00859 << std::setprecision(16); 00860 00861 if (line_break == libMesh::invalid_uint) 00862 for (unsigned int i=0; i<len; i++) 00863 { 00864 libmesh_assert(out.get()); 00865 libmesh_assert (out->good()); 00866 *out << val[i] << ' '; 00867 } 00868 else 00869 { 00870 unsigned int cnt=0; 00871 while (cnt < len) 00872 { 00873 for (unsigned int i=0; i<std::min(line_break,len); i++) 00874 { 00875 libmesh_assert(out.get()); 00876 libmesh_assert (out->good()); 00877 *out << val[cnt++] << ' '; 00878 } 00879 libmesh_assert(out.get()); 00880 libmesh_assert (out->good()); 00881 *out << '\n'; 00882 } 00883 } 00884 00885 // Restore stream flags 00886 out->flags(out_flags); 00887 00888 return; 00889 } 00890 00891 default: 00892 libmesh_error(); 00893 } 00894 }
| void libMesh::Xdr::data_stream | ( | T * | val, | |
| const unsigned int | len, | |||
| const unsigned int | line_break = libMesh::invalid_uint | |||
| ) | [inline] |
Inputs or outputs a raw data stream.
Definition at line 687 of file xdr_cxx.C.
References libMeshEnums::DECODE, libMeshEnums::ENCODE, libMesh::err, libMesh::AutoPtr< Tp >::get(), in, libMesh::invalid_uint, is_open(), std::min(), mode, out, libMeshEnums::READ, libMeshEnums::WRITE, and xdrs.
Referenced by libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bcs(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs(), and libMesh::XdrIO::write_serialized_nodes().
00688 { 00689 switch (mode) 00690 { 00691 case ENCODE: 00692 { 00693 #ifdef LIBMESH_HAVE_XDR 00694 00695 libmesh_assert (this->is_open()); 00696 00697 00698 xdr_vector(xdrs, 00699 (char*) val, 00700 len, 00701 sizeof(unsigned int), 00702 (xdrproc_t) xdr_u_int); 00703 00704 #else 00705 00706 libMesh::err << "ERROR: Functionality is not available." << std::endl 00707 << "Make sure LIBMESH_HAVE_XDR is defined at build time" 00708 << std::endl 00709 << "The XDR interface is not available in this installation" 00710 << std::endl; 00711 00712 libmesh_error(); 00713 00714 #endif 00715 return; 00716 } 00717 00718 case DECODE: 00719 { 00720 #ifdef LIBMESH_HAVE_XDR 00721 00722 libmesh_assert (this->is_open()); 00723 00724 if (len > 0) 00725 xdr_vector(xdrs, 00726 (char*) val, 00727 len, 00728 sizeof(unsigned int), 00729 (xdrproc_t) xdr_u_int); 00730 00731 #else 00732 00733 libMesh::err << "ERROR: Functionality is not available." << std::endl 00734 << "Make sure LIBMESH_HAVE_XDR is defined at build time" 00735 << std::endl 00736 << "The XDR interface is not available in this installation" 00737 << std::endl; 00738 00739 libmesh_error(); 00740 00741 #endif 00742 return; 00743 } 00744 00745 case READ: 00746 { 00747 libmesh_assert(in.get()); 00748 libmesh_assert (in->good()); 00749 00750 for (unsigned int i=0; i<len; i++) 00751 { 00752 libmesh_assert(in.get()); 00753 libmesh_assert (in->good()); 00754 *in >> val[i]; 00755 } 00756 00757 return; 00758 } 00759 00760 case WRITE: 00761 { 00762 libmesh_assert(out.get()); 00763 libmesh_assert (out->good()); 00764 00765 if (line_break == libMesh::invalid_uint) 00766 for (unsigned int i=0; i<len; i++) 00767 { 00768 libmesh_assert(out.get()); 00769 libmesh_assert (out->good()); 00770 *out << val[i] << " "; 00771 } 00772 else 00773 { 00774 unsigned int cnt=0; 00775 while (cnt < len) 00776 { 00777 for (unsigned int i=0; i<std::min(line_break,len); i++) 00778 { 00779 libmesh_assert(out.get()); 00780 libmesh_assert (out->good()); 00781 *out << val[cnt++] << " "; 00782 } 00783 libmesh_assert(out.get()); 00784 libmesh_assert (out->good()); 00785 *out << '\n'; 00786 } 00787 } 00788 00789 return; 00790 } 00791 00792 default: 00793 libmesh_error(); 00794 } 00795 }
| void libMesh::Xdr::do_read | ( | std::string & | a | ) | [inline] |
| void libMesh::Xdr::do_read | ( | std::vector< std::complex< T > > & | a | ) | [inline, private] |
Definition at line 577 of file xdr_cxx.C.
References comm, comm_len, data(), libMesh::AutoPtr< Tp >::get(), and in.
00577 { 00578 unsigned int length=0; 00579 data(length, "# vector length x 2 (complex)"); 00580 a.resize(length); 00581 00582 for (unsigned int i=0; i<a.size(); i++) 00583 { 00584 T r, im; 00585 libmesh_assert(in.get()); 00586 libmesh_assert (in->good()); 00587 *in >> r >> im; 00588 a[i] = std::complex<T>(r,im); 00589 } 00590 in->getline(comm, comm_len); 00591 }
| void libMesh::Xdr::do_read | ( | std::vector< T > & | a | ) | [inline, private] |
| void libMesh::Xdr::do_read | ( | std::complex< T > & | a | ) | [inline, private] |
| void libMesh::Xdr::do_read | ( | T & | a | ) | [inline, private] |
| void libMesh::Xdr::do_write | ( | std::vector< std::complex< T > > & | a | ) | [inline, private] |
Definition at line 616 of file xdr_cxx.C.
References data(), do_write(), libMesh::AutoPtr< Tp >::get(), and out.
| void libMesh::Xdr::do_write | ( | std::vector< T > & | a | ) | [inline, private] |
Definition at line 602 of file xdr_cxx.C.
References data(), do_write(), libMesh::AutoPtr< Tp >::get(), and out.
| void libMesh::Xdr::do_write | ( | std::complex< T > & | a | ) | [inline, private] |
| void libMesh::Xdr::do_write | ( | T & | a | ) | [inline, private] |
| bool libMesh::Xdr::is_open | ( | ) | const |
Returns true if the Xdr file is open, false if it is closed.
Definition at line 375 of file xdr_cxx.C.
References libMeshEnums::DECODE, libMeshEnums::ENCODE, libMesh::err, fp, libMesh::AutoPtr< Tp >::get(), in, mode, out, libMeshEnums::READ, libMeshEnums::WRITE, and xdrs.
Referenced by data(), data_stream(), and libMesh::System::read_parallel_data().
00376 { 00377 switch (mode) 00378 { 00379 case ENCODE: 00380 case DECODE: 00381 { 00382 #ifdef LIBMESH_HAVE_XDR 00383 00384 if (fp) 00385 if (xdrs) 00386 return true; 00387 00388 return false; 00389 00390 #else 00391 00392 libMesh::err << "ERROR: Functionality is not available." << std::endl 00393 << "Make sure LIBMESH_HAVE_XDR is defined at build time" 00394 << std::endl 00395 << "The XDR interface is not available in this installation" 00396 << std::endl; 00397 00398 libmesh_error(); 00399 00400 return false; 00401 00402 #endif 00403 00404 } 00405 00406 case READ: 00407 { 00408 if (in.get() != NULL) 00409 return in->good(); 00410 return false; 00411 } 00412 00413 case WRITE: 00414 { 00415 if (out.get() != NULL) 00416 return out->good(); 00417 return false; 00418 } 00419 00420 default: 00421 libmesh_error(); 00422 } 00423 00424 return false; 00425 }
| void libMesh::Xdr::open | ( | const std::string & | name | ) |
Opens the file.
Definition at line 185 of file xdr_cxx.C.
References bzipped_file, libMeshEnums::DECODE, libMeshEnums::ENCODE, libMesh::err, file_name, fp, libMesh::AutoPtr< Tp >::get(), gzipped_file, in, mode, libMesh::out, out, libMeshEnums::READ, libMesh::AutoPtr< Tp >::reset(), libMeshEnums::WRITE, xdrs, and xzipped_file.
00186 { 00187 file_name = name; 00188 00189 if (name == "") 00190 return; 00191 00192 switch (mode) 00193 { 00194 case ENCODE: 00195 case DECODE: 00196 { 00197 #ifdef LIBMESH_HAVE_XDR 00198 00199 fp = fopen(name.c_str(), (mode == ENCODE) ? "w" : "r"); 00200 if (!fp) 00201 libmesh_file_error(name.c_str()); 00202 xdrs = new XDR; 00203 xdrstdio_create (xdrs, fp, (mode == ENCODE) ? XDR_ENCODE : XDR_DECODE); 00204 #else 00205 00206 libMesh::err << "ERROR: Functionality is not available." << std::endl 00207 << "Make sure LIBMESH_HAVE_XDR is defined at build time" 00208 << std::endl 00209 << "The XDR interface is not available in this installation" 00210 << std::endl; 00211 00212 libmesh_error(); 00213 00214 #endif 00215 return; 00216 00217 } 00218 00219 case READ: 00220 { 00221 gzipped_file = (name.size() - name.rfind(".gz") == 3); 00222 bzipped_file = (name.size() - name.rfind(".bz2") == 4); 00223 xzipped_file = (name.size() - name.rfind(".xz") == 3); 00224 00225 if (gzipped_file) 00226 { 00227 #ifdef LIBMESH_HAVE_GZSTREAM 00228 igzstream *inf = new igzstream; 00229 libmesh_assert(inf); 00230 in.reset(inf); 00231 inf->open(name.c_str(), std::ios::in); 00232 #else 00233 libMesh::err << "ERROR: need gzstream to handle .gz files!!!" 00234 << std::endl; 00235 libmesh_error(); 00236 #endif 00237 } 00238 else 00239 { 00240 std::ifstream *inf = new std::ifstream; 00241 libmesh_assert(inf); 00242 in.reset(inf); 00243 00244 std::string new_name = unzip_file(name); 00245 00246 inf->open(new_name.c_str(), std::ios::in); 00247 } 00248 00249 libmesh_assert(in.get()); 00250 libmesh_assert (in->good()); 00251 return; 00252 } 00253 00254 case WRITE: 00255 { 00256 gzipped_file = (name.size() - name.rfind(".gz") == 3); 00257 bzipped_file = (name.size() - name.rfind(".bz2") == 4); 00258 xzipped_file = (name.size() - name.rfind(".xz") == 3); 00259 00260 if (gzipped_file) 00261 { 00262 #ifdef LIBMESH_HAVE_GZSTREAM 00263 ogzstream *outf = new ogzstream; 00264 libmesh_assert(outf); 00265 out.reset(outf); 00266 outf->open(name.c_str(), std::ios::out); 00267 #else 00268 libMesh::err << "ERROR: need gzstream to handle .gz files!!!" 00269 << std::endl; 00270 libmesh_error(); 00271 #endif 00272 } 00273 else 00274 { 00275 std::ofstream *outf = new std::ofstream; 00276 libmesh_assert(outf); 00277 out.reset(outf); 00278 00279 std::string new_name = name; 00280 00281 if (bzipped_file) 00282 new_name.erase(new_name.end() - 4, new_name.end()); 00283 00284 if (xzipped_file) 00285 new_name.erase(new_name.end() - 3, new_name.end()); 00286 00287 outf->open(new_name.c_str(), std::ios::out); 00288 } 00289 00290 libmesh_assert(out.get()); 00291 libmesh_assert (out->good()); 00292 return; 00293 } 00294 00295 default: 00296 libmesh_error(); 00297 } 00298 }
| Xdr& libMesh::Xdr::operator<< | ( | T & | a | ) | [inline] |
| Xdr& libMesh::Xdr::operator>> | ( | T & | a | ) | [inline] |
| bool libMesh::Xdr::reading | ( | ) | const [inline] |
Returns true if the file is opened in a reading state, false otherwise.
Definition at line 101 of file xdr_cxx.h.
References libMeshEnums::DECODE, mode, and libMeshEnums::READ.
Referenced by libMesh::EquationSystems::_read_impl(), operator>>(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), libMesh::System::read_parallel_data(), libMesh::XdrIO::read_serialized_bcs(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::System::read_serialized_vector(), and libMesh::System::read_serialized_vectors().
| void libMesh::Xdr::set_version | ( | int | ver | ) | [inline] |
Sets the version of the file that is being read
Definition at line 149 of file xdr_cxx.h.
References version_number.
Referenced by libMesh::EquationSystems::_read_impl(), and libMesh::EquationSystems::write().
00149 { version_number = ver; }
| int libMesh::Xdr::version | ( | ) | const [inline] |
Gets the version of the file that is being read
Definition at line 154 of file xdr_cxx.h.
References version_number.
Referenced by libMesh::System::read_header(), and libMesh::System::read_serialized_vector().
00154 { return version_number; }
| bool libMesh::Xdr::writing | ( | ) | const [inline] |
Returns true if the file is opened in a writing state, false otherwise.
Definition at line 107 of file xdr_cxx.h.
References libMeshEnums::ENCODE, mode, and libMeshEnums::WRITE.
Referenced by operator<<(), libMesh::EquationSystems::write(), libMesh::System::write_header(), libMesh::System::write_parallel_data(), libMesh::XdrIO::write_serialized_bcs(), libMesh::System::write_serialized_vector(), and libMesh::System::write_serialized_vectors().
Member Data Documentation
bool libMesh::Xdr::bzipped_file [private] |
char libMesh::Xdr::comm[xdr_MAX_STRING_LENGTH] [private] |
const int libMesh::Xdr::comm_len [private] |
std::string libMesh::Xdr::file_name [private] |
FILE* libMesh::Xdr::fp [private] |
bool libMesh::Xdr::gzipped_file [private] |
AutoPtr<std::istream> libMesh::Xdr::in [private] |
const XdrMODE libMesh::Xdr::mode [private] |
AutoPtr<std::ostream> libMesh::Xdr::out [private] |
The output file stream.
Definition at line 223 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 239 of file xdr_cxx.h.
Referenced by set_version(), and version().
XDR* libMesh::Xdr::xdrs [private] |
bool libMesh::Xdr::xzipped_file [private] |
The documentation for this class was generated from the following files:
Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:43 UTC
Hosted By: