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