$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 // Local includes 00019 #include "libmesh/xdr_soln.h" 00020 #include "libmesh/xdr_shead.h" 00021 00022 // System includes 00023 #include <string.h> 00024 00025 namespace libMesh 00026 { 00027 00028 00029 00030 // ------------------------------------------------------------ 00031 // XdrSOLN members 00032 int XdrSOLN::header(XdrSHEAD *hd) 00033 { 00034 00035 switch (m_type) 00036 { 00037 00038 #ifdef LIBMESH_HAVE_XDR 00039 00040 case (XdrMGF::ENCODE): 00041 case (XdrMGF::DECODE): 00042 { 00043 00044 xdr_int(mp_xdr_handle, &(hd->m_wrtVar)); 00045 xdr_int(mp_xdr_handle, &(hd->m_numvar)); 00046 xdr_int(mp_xdr_handle, &(hd->m_numNodes)); 00047 xdr_int(mp_xdr_handle, &(hd->m_meshCnt)); 00048 xdr_int(mp_xdr_handle, &(hd->m_kstep)); 00049 xdr_int(mp_xdr_handle, &(hd->m_strSize)); 00050 xdr_REAL(mp_xdr_handle, &(hd->m_time)); 00051 00052 m_wrtVar=hd->m_wrtVar; 00053 00054 char* temp = const_cast<char *>(hd->getId()); 00055 xdr_string(mp_xdr_handle,&(temp), 00056 ((m_type == XdrMGF::ENCODE) ? std::strlen(temp) : hd->m_strSize)); 00057 hd->setId(temp); 00058 00059 temp = const_cast<char *>(hd->getTitle()); 00060 xdr_string(mp_xdr_handle,&(temp), 00061 ((m_type == XdrMGF::ENCODE) ? std::strlen(temp) : hd->m_strSize)); 00062 hd->setTitle(temp); 00063 00064 temp = const_cast<char *>(hd->getUserTitle()); 00065 xdr_string(mp_xdr_handle,&(temp), 00066 ((m_type == XdrMGF::ENCODE) ? std::strlen(temp) : hd->m_strSize)); 00067 hd->setUserTitle(temp); 00068 00069 00070 char * tempTitle = new char[hd->m_strSize*m_wrtVar]; 00071 00072 00073 if (m_type == XdrMGF::DECODE) 00074 { 00075 xdr_string(mp_xdr_handle, &tempTitle, hd->m_strSize*m_wrtVar); 00076 std::size_t olen= std::strlen(tempTitle); 00077 char *top = tempTitle; 00078 for (int ivar = 0; ivar < m_wrtVar; ++ivar) 00079 { 00080 char *p = strchr(tempTitle,' '); 00081 *p = '\0'; 00082 std::size_t tempSize = std::strlen(tempTitle) ; 00083 tempTitle+=tempSize+1; 00084 } 00085 tempTitle = top; 00086 hd->mp_varTitle = new char[olen]; 00087 std::memcpy(hd->mp_varTitle,tempTitle,olen*sizeof(char)); 00088 } 00089 else if (m_type == XdrMGF::ENCODE) 00090 { 00091 char *p = hd->mp_varTitle; 00092 char *top = tempTitle; 00093 for (int ivar = 0; ivar < m_wrtVar; ++ivar) 00094 { 00095 std::size_t tempSize = std::strlen(p) + 1; 00096 std::memcpy(tempTitle,p,tempSize*sizeof(char)); 00097 tempSize = std::strlen(tempTitle); 00098 tempTitle[tempSize] = ' '; 00099 tempTitle += tempSize+1; 00100 p += tempSize+1; 00101 } 00102 tempTitle = top; 00103 xdr_string(mp_xdr_handle, &tempTitle, hd->m_strSize*m_wrtVar); 00104 } 00105 delete [] tempTitle; 00106 00107 return 0; 00108 } 00109 #endif 00110 00111 00112 case (XdrMGF::R_ASCII): 00113 { 00114 // Temporary variables to facilitate stream reading 00115 const int comm_len= 80; 00116 char comment[comm_len]; 00117 00118 libmesh_assert (mp_in.good()); 00119 00120 mp_in >> hd->m_numNodes ; mp_in.getline(comment, comm_len); 00121 mp_in >> hd->m_wrtVar ; mp_in.getline(comment, comm_len); 00122 mp_in >> hd->m_strSize ; mp_in.getline(comment, comm_len); 00123 mp_in >> hd->m_time ; mp_in.getline(comment, comm_len); 00124 00125 mp_in.getline(comment, comm_len); 00126 hd->setId(comment); 00127 00128 mp_in.getline(comment, comm_len); 00129 hd->setTitle(comment); 00130 00131 mp_in.getline(comment, comm_len); 00132 hd->setUserTitle(comment); 00133 00134 m_wrtVar = hd->m_wrtVar; 00135 00136 // Read the variable names 00137 { 00138 std::string var_name; 00139 char* titles = new char[hd->m_wrtVar*hd->m_strSize]; 00140 unsigned int c=0; 00141 00142 for (int var=0; var < hd->m_wrtVar; var++) 00143 { 00144 mp_in >> var_name; 00145 00146 for (unsigned int l=0; l<var_name.size(); l++) 00147 titles[c++] = var_name[l]; 00148 00149 titles[c++] = '\0'; 00150 } 00151 00152 mp_in.getline(comment, comm_len); 00153 00154 hd->setVarTitle(titles, c); 00155 00156 delete [] titles; 00157 } 00158 00159 00160 return 0; 00161 } 00162 00163 00164 case (XdrMGF::W_ASCII): 00165 { 00166 mp_out << hd->m_numNodes << "\t # Num. Nodes\n"; 00167 mp_out << hd->m_wrtVar << "\t # Num. of Vars\n"; 00168 mp_out << hd->m_strSize << "\t # String Size (ignore)\n"; 00169 mp_out << hd->m_time << "\t # Current Time\n"; 00170 mp_out << hd->mp_id << '\n'; 00171 mp_out << hd->mp_title << '\n'; 00172 mp_out << hd->mp_userTitle << '\n'; 00173 00174 // write the variable names 00175 { 00176 const char* p = hd->getVarTitle(); 00177 00178 for (int var=0; var<hd->m_wrtVar ; var++) 00179 { 00180 mp_out << p << " "; 00181 p += std::strlen(p)+1; 00182 } 00183 mp_out << "\t # Variable Names\n"; 00184 } 00185 00186 m_wrtVar = hd->m_wrtVar; 00187 00188 return 0; 00189 } 00190 00191 00192 00193 default: 00194 // Unknown access type 00195 libmesh_error_msg("Unknown m_type" << m_type); 00196 } 00197 00198 return 1; 00199 } 00200 00201 } // namespace libMesh