xdr_mgf.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 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 # include <rpc/rpc.h> 00036 # ifndef LIBMESH_DEFAULT_SINGLE_PRECISION 00037 # ifdef LIBMESH_DEFAULT_TRIPLE_PRECISION 00038 // # define xdr_REAL xdr_quadruple 00039 // For some reason my xdr implementation doesn't define 00040 // xdr_quadruple... - RHS 00041 # define xdr_REAL xdr_double 00042 # define xdr_Real double 00043 # else 00044 # define xdr_REAL xdr_double 00045 # define xdr_Real Real 00046 # endif 00047 # else 00048 # define xdr_REAL xdr_float 00049 # define xdr_Real Real 00050 # endif 00051 #else 00052 # define xdr_Real Real 00053 #endif 00054 00055 00056 namespace libMesh 00057 { 00058 00081 class XdrMGF 00082 { 00083 public: 00094 enum XdrIO_TYPE {UNKNOWN = -1, ENCODE=0, DECODE, 00095 W_ASCII , R_ASCII}; 00096 00097 00110 #ifdef LIBMESH_HAVE_XDR 00111 XdrMGF() : _num_levels(0), m_type(UNKNOWN), mp_xdr_handle(0), orig_flag(LegacyXdrIO::LIBM), mp_fp(0) {} 00112 #else 00113 XdrMGF() : _num_levels(0), m_type(UNKNOWN), orig_flag(LegacyXdrIO::LIBM), mp_fp(0) {} 00114 #endif 00115 00131 void init(XdrIO_TYPE t, const char* fn, const char* type, int icnt); 00132 00138 virtual ~XdrMGF(); 00139 00148 void fini(); 00149 00158 int dataBlk(int* array, int numvar, int size); 00159 00165 int dataBlk(Real* array, int numvar, int size); 00166 00170 LegacyXdrIO::FileFormat get_orig_flag() const { return orig_flag; } 00171 00175 void set_orig_flag(LegacyXdrIO::FileFormat in_orig_flag) { orig_flag = in_orig_flag; } 00176 00177 00181 void set_num_levels(unsigned int num_levels) { _num_levels = num_levels; } 00182 00186 unsigned int get_num_levels() { return _num_levels; } 00187 00188 protected: 00189 00193 unsigned int _num_levels; 00194 00206 XdrIO_TYPE m_type; 00207 00208 #ifdef LIBMESH_HAVE_XDR 00209 00216 XDR* mp_xdr_handle; 00217 00218 #endif 00219 00235 LegacyXdrIO::FileFormat orig_flag; 00236 00240 std::ifstream mp_in; 00241 00245 std::ofstream mp_out; 00246 00247 private: 00248 std::FILE* mp_fp; 00249 00254 void tokenize_first_line(const char* p) 00255 { 00256 std::string buf_str(p); 00257 std::stringstream ss(buf_str); 00258 00259 char token[256]; 00260 ss >> token; 00261 if(std::strcmp(token,"LIBM") == 0) 00262 { 00263 ss >> token; 00264 _num_levels = std::atoi(token); 00265 } 00266 00267 } 00268 }; 00269 00270 00271 } // namespace libMesh 00272 00273 00274 #endif // LIBMESH_XDR_MGF_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:49 UTC
Hosted By: