xdr_mgf.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 #ifndef LIBMESH_XDR_MGF_H
19 #define LIBMESH_XDR_MGF_H
20 
21 // Local includes
22 #include "libmesh/legacy_xdr_io.h" // for LegacyXdrIO::FileFormat
23 #include "libmesh/libmesh_config.h" // for LIBMESH_HAVE_XDR
24 
25 // C++ includes
26 #include <cstdio> // for std::FILE
27 #include <string>
28 #include <cstring> // std::strlen, std::strcmp
29 #include <fstream> // for std::ifstream
30 #include <sstream>
31 
32 // Forward Declarations
33 
34 #ifdef LIBMESH_HAVE_XDR
35 # ifdef LIBMESH_HAVE_RPC_RPC_H
36 # include <rpc/rpc.h>
37 # elif LIBMESH_HAVE_RPC_XDR_H
38 # include <rpc/xdr.h>
39 # endif
40 # ifndef LIBMESH_DEFAULT_SINGLE_PRECISION
41 # ifdef LIBMESH_DEFAULT_TRIPLE_PRECISION
42 // # define xdr_REAL xdr_quadruple
43 // For some reason my xdr implementation doesn't define
44 // xdr_quadruple... - RHS
45 # define xdr_REAL xdr_double
46 # define xdr_Real double
47 # else
48 # define xdr_REAL xdr_double
49 # define xdr_Real Real
50 # endif
51 # else
52 # define xdr_REAL xdr_float
53 # define xdr_Real Real
54 # endif
55 #else
56 # define xdr_Real Real
57 #endif
58 
59 
60 namespace libMesh
61 {
62 
85 class XdrMGF
86 {
87 public:
98  enum XdrIO_TYPE {UNKNOWN = -1, ENCODE=0, DECODE,
100 
101 
114 #ifdef LIBMESH_HAVE_XDR
116 #else
118 #endif
119 
135  void init(XdrIO_TYPE t, const char* fn, const char* type, int icnt);
136 
142  virtual ~XdrMGF();
143 
152  void fini();
153 
162  int dataBlk(int* array, int numvar, int size);
163 
169  int dataBlk(Real* array, int numvar, int size);
170 
175 
179  void set_orig_flag(LegacyXdrIO::FileFormat in_orig_flag) { orig_flag = in_orig_flag; }
180 
181 
185  void set_num_levels(unsigned int num_levels) { _num_levels = num_levels; }
186 
190  unsigned int get_num_levels() { return _num_levels; }
191 
192 protected:
193 
197  unsigned int _num_levels;
198 
211 
212 #ifdef LIBMESH_HAVE_XDR
213 
221 
222 #endif
223 
240 
244  std::ifstream mp_in;
245 
249  std::ofstream mp_out;
250 
251 private:
252  std::FILE* mp_fp;
253 
258  void tokenize_first_line(const char* p)
259  {
260  std::string buf_str(p);
261  std::stringstream ss(buf_str);
262 
263  char token[256];
264  ss >> token;
265  if(std::strcmp(token,"LIBM") == 0)
266  {
267  ss >> token;
268  _num_levels = std::atoi(token);
269  }
270 
271  }
272 };
273 
274 
275 } // namespace libMesh
276 
277 
278 #endif // LIBMESH_XDR_MGF_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:07 UTC

Hosted By:
SourceForge.net Logo