xdr_soln.C
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 // Local includes
19 #include "libmesh/xdr_soln.h"
20 #include "libmesh/xdr_shead.h"
21 
22 // System includes
23 #include <string.h>
24 
25 namespace libMesh
26 {
27 
28 
29 
30 // ------------------------------------------------------------
31 // XdrSOLN members
33 {
34  // Temporary variables to facilitate stream reading
35  const int comm_len= 80;
36  char comment[comm_len];
37 
38 
39 
40  switch (m_type)
41  {
42 
43 #ifdef LIBMESH_HAVE_XDR
44 
45  case (XdrMGF::ENCODE):
46  case (XdrMGF::DECODE):
47  {
48 
49  xdr_int(mp_xdr_handle, &(hd->m_wrtVar));
50  xdr_int(mp_xdr_handle, &(hd->m_numvar));
51  xdr_int(mp_xdr_handle, &(hd->m_numNodes));
52  xdr_int(mp_xdr_handle, &(hd->m_meshCnt));
53  xdr_int(mp_xdr_handle, &(hd->m_kstep));
54  xdr_int(mp_xdr_handle, &(hd->m_strSize));
55  xdr_REAL(mp_xdr_handle, &(hd->m_time));
56 
57  m_wrtVar=hd->m_wrtVar;
58 
59  char* temp = const_cast<char *>(hd->getId());
60  xdr_string(mp_xdr_handle,&(temp),
61  ((m_type == XdrMGF::ENCODE) ? std::strlen(temp) : hd->m_strSize));
62  hd->setId(temp);
63 
64  temp = const_cast<char *>(hd->getTitle());
65  xdr_string(mp_xdr_handle,&(temp),
66  ((m_type == XdrMGF::ENCODE) ? std::strlen(temp) : hd->m_strSize));
67  hd->setTitle(temp);
68 
69  temp = const_cast<char *>(hd->getUserTitle());
70  xdr_string(mp_xdr_handle,&(temp),
71  ((m_type == XdrMGF::ENCODE) ? std::strlen(temp) : hd->m_strSize));
72  hd->setUserTitle(temp);
73 
74 
75  char * tempTitle = new char[hd->m_strSize*m_wrtVar];
76 
77 
78  if (m_type == XdrMGF::DECODE)
79  {
80  int tempSize = 0;
81  xdr_string(mp_xdr_handle, &tempTitle, hd->m_strSize*m_wrtVar);
82  int olen= std::strlen(tempTitle);
83  char *p;
84  char *top = tempTitle;
85  for (int ivar = 0; ivar < m_wrtVar; ++ivar)
86  {
87  p = strchr(tempTitle,' ');
88  *p = '\0';
89  tempSize = std::strlen(tempTitle) ;
90  tempTitle+=tempSize+1;
91  }
92  tempTitle = top;
93  hd->mp_varTitle = new char[olen];
94  std::memcpy(hd->mp_varTitle,tempTitle,olen*sizeof(char));
95  }
96  else if (m_type == XdrMGF::ENCODE)
97  {
98  char *p = hd->mp_varTitle;
99  char *top = tempTitle;
100  for (int ivar = 0; ivar < m_wrtVar; ++ivar)
101  {
102  int tempSize = std::strlen(p) + 1;
103  std::memcpy(tempTitle,p,tempSize*sizeof(char));
104  tempSize = std::strlen(tempTitle);
105  tempTitle[tempSize] = ' ';
106  tempTitle += tempSize+1;
107  p += tempSize+1;
108  }
109  tempTitle = top;
110  xdr_string(mp_xdr_handle, &tempTitle, hd->m_strSize*m_wrtVar);
111  }
112  delete [] tempTitle;
113 
114  return 0;
115  }
116 #endif
117 
118 
119  case (XdrMGF::R_ASCII):
120  {
121  libmesh_assert (mp_in.good());
122 
123  mp_in >> hd->m_numNodes ; mp_in.getline(comment, comm_len);
124  mp_in >> hd->m_wrtVar ; mp_in.getline(comment, comm_len);
125  mp_in >> hd->m_strSize ; mp_in.getline(comment, comm_len);
126  mp_in >> hd->m_time ; mp_in.getline(comment, comm_len);
127 
128  mp_in.getline(comment, comm_len);
129  hd->setId(comment);
130 
131  mp_in.getline(comment, comm_len);
132  hd->setTitle(comment);
133 
134  mp_in.getline(comment, comm_len);
135  hd->setUserTitle(comment);
136 
137  m_wrtVar = hd->m_wrtVar;
138 
139  // Read the variable names
140  {
141  std::string var_name;
142  char* titles = new char[hd->m_wrtVar*hd->m_strSize];
143  unsigned int c=0;
144 
145  for (int var=0; var < hd->m_wrtVar; var++)
146  {
147  mp_in >> var_name;
148 
149  for (unsigned int l=0; l<var_name.size(); l++)
150  titles[c++] = var_name[l];
151 
152  titles[c++] = '\0';
153  }
154 
155  mp_in.getline(comment, comm_len);
156 
157  hd->setVarTitle(titles, c);
158 
159  delete [] titles;
160  }
161 
162 
163  return 0;
164  }
165 
166 
167  case (XdrMGF::W_ASCII):
168  {
169  mp_out << hd->m_numNodes << "\t # Num. Nodes\n";
170  mp_out << hd->m_wrtVar << "\t # Num. of Vars\n";
171  mp_out << hd->m_strSize << "\t # String Size (ignore)\n";
172  mp_out << hd->m_time << "\t # Current Time\n";
173  mp_out << hd->mp_id << '\n';
174  mp_out << hd->mp_title << '\n';
175  mp_out << hd->mp_userTitle << '\n';
176 
177  // write the variable names
178  {
179  const char* p = hd->getVarTitle();
180 
181  for (int var=0; var<hd->m_wrtVar ; var++)
182  {
183  mp_out << p << " ";
184  p += std::strlen(p)+1;
185  }
186  mp_out << "\t # Variable Names\n";
187  }
188 
189  m_wrtVar = hd->m_wrtVar;
190 
191  return 0;
192  }
193 
194 
195 
196  default:
197  // Unknown access type
198  libmesh_error();
199 
200  }
201 
202  return 1;
203 }
204 
205 } // namespace libMesh

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

Hosted By:
SourceForge.net Logo