$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 #ifndef LIBMESH_XDR_MGF_H 00019 #define LIBMESH_XDR_MGF_H 00020 00021 // Local includes 00022 #include "libmesh/legacy_xdr_io.h" // for LegacyXdrIO::FileFormat 00023 #include "libmesh/libmesh_config.h" // for LIBMESH_HAVE_XDR 00024 00025 // C++ includes 00026 #include <cstdio> // for std::FILE 00027 #include <string> 00028 #include <cstring> // std::strlen, std::strcmp 00029 #include <fstream> // for std::ifstream 00030 #include <sstream> 00031 00032 // Forward Declarations 00033 00034 #ifdef LIBMESH_HAVE_XDR 00035 # ifdef LIBMESH_HAVE_RPC_RPC_H 00036 # include <rpc/rpc.h> 00037 # elif LIBMESH_HAVE_RPC_XDR_H 00038 # include <rpc/xdr.h> 00039 # endif 00040 # ifndef LIBMESH_DEFAULT_SINGLE_PRECISION 00041 # ifdef LIBMESH_DEFAULT_TRIPLE_PRECISION 00042 // # define xdr_REAL xdr_quadruple 00043 // For some reason my xdr implementation doesn't define 00044 // xdr_quadruple... - RHS 00045 # define xdr_REAL xdr_double 00046 # define xdr_Real double 00047 # else 00048 # define xdr_REAL xdr_double 00049 # define xdr_Real Real 00050 # endif 00051 # else 00052 # define xdr_REAL xdr_float 00053 # define xdr_Real Real 00054 # endif 00055 #else 00056 # define xdr_Real Real 00057 #endif 00058 00059 00060 namespace libMesh 00061 { 00062 00085 class XdrMGF 00086 { 00087 public: 00098 enum XdrIO_TYPE {UNKNOWN = -1, ENCODE=0, DECODE, 00099 W_ASCII , R_ASCII}; 00100 00101 00114 #ifdef LIBMESH_HAVE_XDR 00115 XdrMGF() : _num_levels(0), m_type(UNKNOWN), mp_xdr_handle(0), orig_flag(LegacyXdrIO::LIBM), mp_fp(0) {} 00116 #else 00117 XdrMGF() : _num_levels(0), m_type(UNKNOWN), orig_flag(LegacyXdrIO::LIBM), mp_fp(0) {} 00118 #endif 00119 00135 void init(XdrIO_TYPE t, const char* fn, const char* type, int icnt); 00136 00142 virtual ~XdrMGF(); 00143 00152 void fini(); 00153 00162 int dataBlk(int* array, int numvar, int size); 00163 00169 int dataBlk(Real* array, int numvar, int size); 00170 00174 LegacyXdrIO::FileFormat get_orig_flag() const { return orig_flag; } 00175 00179 void set_orig_flag(LegacyXdrIO::FileFormat in_orig_flag) { orig_flag = in_orig_flag; } 00180 00181 00185 void set_num_levels(unsigned int num_levels) { _num_levels = num_levels; } 00186 00190 unsigned int get_num_levels() { return _num_levels; } 00191 00192 protected: 00193 00197 unsigned int _num_levels; 00198 00210 XdrIO_TYPE m_type; 00211 00212 #ifdef LIBMESH_HAVE_XDR 00213 00220 XDR* mp_xdr_handle; 00221 00222 #endif 00223 00239 LegacyXdrIO::FileFormat orig_flag; 00240 00244 std::ifstream mp_in; 00245 00249 std::ofstream mp_out; 00250 00251 private: 00252 std::FILE* mp_fp; 00253 00258 void tokenize_first_line(const char* p) 00259 { 00260 std::string buf_str(p); 00261 std::stringstream ss(buf_str); 00262 00263 char token[256]; 00264 ss >> token; 00265 if(std::strcmp(token,"LIBM") == 0) 00266 { 00267 ss >> token; 00268 _num_levels = std::atoi(token); 00269 } 00270 00271 } 00272 }; 00273 00274 00275 } // namespace libMesh 00276 00277 00278 #endif // LIBMESH_XDR_MGF_H