📄 xdr_cxx.c
字号:
} in->getline(comm, comm_len); return; } case WRITE: { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); unsigned int length=v.size(); data(length, "# vector length"); for (unsigned int i=0; i<v.size(); i++) { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); OFSRealscientific(*out,17,v[i]) << " "; } *out << "\t " << comment << '\n'; return; } default: libmesh_error(); }}#ifdef USE_COMPLEX_NUMBERSvoid Xdr::data (std::vector< std::complex<double> >& v, const char* comment){ switch (mode) { case ENCODE: {#ifdef HAVE_XDR libmesh_assert (is_open()); unsigned int length = v.size(); data(length, "# vector length x 2 (complex)"); std::vector< std::complex<double> >::iterator iter = v.begin(); for (; iter != v.end(); ++iter) data(*iter, "");#else std::cerr << "ERROR: Functionality is not available." << std::endl << "Make sure HAVE_XDR is defined at build time" << std::endl << "The XDR interface is not available in this installation" << std::endl; libmesh_error();#endif return; } case DECODE: {#ifdef HAVE_XDR libmesh_assert (is_open()); unsigned int length=0; data(length, "# vector length x 2 (complex)"); v.resize(length); std::vector< std::complex<double> >::iterator iter = v.begin(); for (; iter != v.end(); ++iter) data(*iter, ""); #else std::cerr << "ERROR: Functionality is not available." << std::endl << "Make sure HAVE_XDR is defined at build time" << std::endl << "The XDR interface is not available in this installation" << std::endl; libmesh_error();#endif return; } case READ: { libmesh_assert (in.get() != NULL); libmesh_assert (in->good()); unsigned int length=0; data(length, "# vector length x 2 (complex)"); v.resize(length); for (unsigned int i=0; i<v.size(); i++) { libmesh_assert (in.get() != NULL); libmesh_assert (in->good()); double _r, _i; *in >> _r; *in >> _i; v[i] = std::complex<double>(_r,_i); } in->getline(comm, comm_len); return; } case WRITE: { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); unsigned int length=v.size(); data(length, "# vector length x 2 (complex)"); for (unsigned int i=0; i<v.size(); i++) { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); OFSNumberscientific(*out,17,v[i]) << " "; } *out << "\t " << comment << '\n'; return; } default: libmesh_error(); }}#endif // ifdef USE_COMPLEX_NUMBERSvoid Xdr::data (std::string& s, const char* comment){ switch (mode) { case ENCODE: {#ifdef HAVE_XDR libmesh_assert (is_open()); { char* sptr = new char[s.size()+1]; for (unsigned int c=0; c<s.size(); c++) sptr[c] = s[c]; sptr[s.size()] = '\0'; xdr_string(xdrs, &sptr, std::strlen(sptr)); delete [] sptr; }#else std::cerr << "ERROR: Functionality is not available." << std::endl << "Make sure HAVE_XDR is defined at build time" << std::endl << "The XDR interface is not available in this installation" << std::endl; libmesh_error();#endif return; } case DECODE: {#ifdef HAVE_XDR libmesh_assert (is_open()); { char* sptr = new char[xdr_MAX_STRING_LENGTH]; xdr_string(xdrs, &sptr, xdr_MAX_STRING_LENGTH); s.resize(std::strlen(sptr)); for (unsigned int c=0; c<s.size(); c++) s[c] = sptr[c]; delete [] sptr; }#else std::cerr << "ERROR: Functionality is not available." << std::endl << "Make sure HAVE_XDR is defined at build time" << std::endl << "The XDR interface is not available in this installation" << std::endl; libmesh_error();#endif return; } case READ: { libmesh_assert (in.get() != NULL); libmesh_assert (in->good()); in->getline(comm, comm_len);//#ifndef BROKEN_IOSTREAM// s.clear();//#else s = "";//#endif for (unsigned int c=0; c<std::strlen(comm); c++) { if (comm[c] == '\t') break; s.push_back(comm[c]); } return; } case WRITE: { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); *out << s << "\t " << comment << '\n'; return; } default: libmesh_error(); }}template <typename T>void Xdr::data_stream (T *val, const unsigned int len, const unsigned int line_break){ switch (mode) { case ENCODE: {#ifdef HAVE_XDR libmesh_assert (this->is_open()); xdr_vector(xdrs, (char*) val, len, sizeof(unsigned int), (xdrproc_t) xdr_u_int);#else std::cerr << "ERROR: Functionality is not available." << std::endl << "Make sure HAVE_XDR is defined at build time" << std::endl << "The XDR interface is not available in this installation" << std::endl; libmesh_error();#endif return; } case DECODE: {#ifdef HAVE_XDR libmesh_assert (this->is_open()); if (len > 0) xdr_vector(xdrs, (char*) val, len, sizeof(unsigned int), (xdrproc_t) xdr_u_int); #else std::cerr << "ERROR: Functionality is not available." << std::endl << "Make sure HAVE_XDR is defined at build time" << std::endl << "The XDR interface is not available in this installation" << std::endl; libmesh_error();#endif return; } case READ: { libmesh_assert (in.get() != NULL); libmesh_assert (in->good()); for (unsigned int i=0; i<len; i++) { libmesh_assert (in.get() != NULL); libmesh_assert (in->good()); *in >> val[i]; } return; } case WRITE: { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); if (line_break == libMesh::invalid_uint) for (unsigned int i=0; i<len; i++) { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); *out << val[i] << " "; } else { unsigned int cnt=0; while (cnt < len) { for (unsigned int i=0; i<std::min(line_break,len); i++) { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); *out << val[cnt++] << " "; } libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); *out << '\n'; } } return; } default: libmesh_error(); }}template <>void Xdr::data_stream (double *val, const unsigned int len, const unsigned int line_break){ switch (mode) { case ENCODE: case DECODE: {#ifdef HAVE_XDR libmesh_assert (this->is_open()); if (len > 0) xdr_vector(xdrs, (char*) val, len, sizeof(double), (xdrproc_t) xdr_double); #else std::cerr << "ERROR: Functionality is not available." << std::endl << "Make sure HAVE_XDR is defined at build time" << std::endl << "The XDR interface is not available in this installation" << std::endl; libmesh_error();#endif return; } case READ: { libmesh_assert (in.get() != NULL); libmesh_assert (in->good()); for (unsigned int i=0; i<len; i++) { libmesh_assert (in.get() != NULL); libmesh_assert (in->good()); *in >> val[i]; } return; } case WRITE: { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); if (line_break == libMesh::invalid_uint) for (unsigned int i=0; i<len; i++) { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); OFSRealscientific(*out,17,val[i]) << " "; } else { unsigned int cnt=0; while (cnt < len) { for (unsigned int i=0; i<std::min(line_break,len); i++) { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); OFSRealscientific(*out,17,val[cnt++]) << " "; } libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); *out << '\n'; } } return; } default: libmesh_error(); }}template <>void Xdr::data_stream (long double *val, const unsigned int len, const unsigned int line_break){ switch (mode) { case ENCODE: case DECODE: {#ifdef HAVE_XDR libmesh_assert (this->is_open()); // FIXME[JWP]: How to implement this for long double? Mac OS // X defines 'xdr_quadruple' but AFAICT, it does not exist for // Linux... for now, reading/writing XDR files with long // doubles is disabled, but you can still write long double // ASCII files of course. // if (len > 0) // xdr_vector(xdrs, // (char*) val, // len, // sizeof(double), // (xdrproc_t) xdr_quadruple); std::cerr << "Writing binary XDR files with long double's is not\n" << "currently supported on all platforms." << std::endl; libmesh_error(); #else std::cerr << "ERROR: Functionality is not available." << std::endl << "Make sure HAVE_XDR is defined at build time" << std::endl << "The XDR interface is not available in this installation" << std::endl; libmesh_error();#endif return; } case READ: { libmesh_assert (in.get() != NULL); libmesh_assert (in->good()); for (unsigned int i=0; i<len; i++) { libmesh_assert (in.get() != NULL); libmesh_assert (in->good()); *in >> val[i]; } return; } case WRITE: { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); if (line_break == libMesh::invalid_uint) for (unsigned int i=0; i<len; i++) { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); OFSRealscientific(*out,17,val[i]) << " "; } else { unsigned int cnt=0; while (cnt < len) { for (unsigned int i=0; i<std::min(line_break,len); i++) { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); OFSRealscientific(*out,17,val[cnt++]) << " "; } libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); *out << '\n'; } } return; } default: libmesh_error(); }}#ifdef USE_COMPLEX_NUMBERStemplate <>void Xdr::data_stream (std::complex<double> *val, const unsigned int len, const unsigned int line_break){ switch (mode) { case ENCODE: case DECODE: {#ifdef HAVE_XDR libmesh_assert (this->is_open()); if (len > 0) { std::vector<double> io_buffer (2*len); // Fill io_buffer if we are writing. if (mode == ENCODE) for (unsigned int i=0, cnt=0; i<len; i++) { io_buffer[cnt++] = val[i].real(); io_buffer[cnt++] = val[i].imag(); } xdr_vector(xdrs, (char*) &io_buffer[0], 2*len, sizeof(double), (xdrproc_t) xdr_double); // Fill val array if we are reading. if (mode == DECODE) for (unsigned int i=0, cnt=0; i<len; i++) { val[i].real() = io_buffer[cnt++]; val[i].imag() = io_buffer[cnt++]; } }#else std::cerr << "ERROR: Functionality is not available." << std::endl << "Make sure HAVE_XDR is defined at build time" << std::endl << "The XDR interface is not available in this installation" << std::endl; libmesh_error();#endif return; } case READ: { libmesh_assert (in.get() != NULL); libmesh_assert (in->good()); for (unsigned int i=0; i<len; i++) { libmesh_assert (in.get() != NULL); libmesh_assert (in->good()); *in >> val[i].real() >> val[i].imag(); } return; } case WRITE: { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); if (line_break == libMesh::invalid_uint) for (unsigned int i=0; i<len; i++) { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); OFSRealscientific(*out,17,val[i].real()) << " "; OFSRealscientific(*out,17,val[i].imag()) << " "; } else { unsigned int cnt=0; while (cnt < len) { for (unsigned int i=0; i<std::min(line_break,len); i++) { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); OFSRealscientific(*out,17,val[cnt].real()) << " "; OFSRealscientific(*out,17,val[cnt].imag()) << " "; cnt++; } libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); *out << '\n'; } } return; } default: libmesh_error(); }}#endif // # USE_COMPLEX_NUMBERSvoid Xdr::comment (std::string &comment){ switch (mode) { case ENCODE: case DECODE: { return; } case READ: { libmesh_assert (in.get() != NULL); libmesh_assert (in->good()); in->getline(comm, comm_len); return; } case WRITE: { libmesh_assert (out.get() != NULL); libmesh_assert (out->good()); *out << "\t " << comment << '\n'; return; } default: libmesh_error(); }}#undef xdr_REAL//template void Xdr::data_stream<int> (int *val, const unsigned int len, const unsigned int line_break);template void Xdr::data_stream<unsigned int> (unsigned int *val, const unsigned int len, const unsigned int line_break);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -