Back to index

salome-med  6.5.0
MEDFileData.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDFileData.hxx"
00021 
00022 using namespace ParaMEDMEM;
00023 
00024 MEDFileData *MEDFileData::New(const char *fileName) throw(INTERP_KERNEL::Exception)
00025 {
00026   return new MEDFileData(fileName);
00027 }
00028 
00029 MEDFileData *MEDFileData::New()
00030 {
00031   return new MEDFileData;
00032 }
00033 
00034 MEDFileFields *MEDFileData::getFields() const
00035 {
00036   return const_cast<MEDFileFields *>(static_cast<const MEDFileFields *>(_fields));
00037 }
00038 
00039 MEDFileMeshes *MEDFileData::getMeshes() const
00040 {
00041   return const_cast<MEDFileMeshes *>(static_cast<const MEDFileMeshes *>(_meshes));
00042 }
00043 
00044 void MEDFileData::setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception)
00045 {
00046   if(!fields)
00047     throw INTERP_KERNEL::Exception("MEDFileData::setFields : input pointer is null !");
00048   fields->incrRef();
00049   _fields=fields;
00050 }
00051 
00052 void MEDFileData::setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception)
00053 {
00054   if(!meshes)
00055     throw INTERP_KERNEL::Exception("MEDFileData::setMeshes : input pointer is null !");
00056   meshes->incrRef();
00057   _meshes=meshes;
00058 }
00059 
00060 int MEDFileData::getNumberOfFields() const throw(INTERP_KERNEL::Exception)
00061 {
00062   const MEDFileFields *f=_fields;
00063   if(!f)
00064     throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfFields : no fields set !");
00065   return f->getNumberOfFields();
00066 }
00067 
00068 int MEDFileData::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception)
00069 {
00070   const MEDFileMeshes *m=_meshes;
00071   if(!m)
00072     throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfMeshes : no meshes set !");
00073   return m->getNumberOfMeshes();
00074 }
00075 
00076 std::string MEDFileData::simpleRepr() const
00077 {
00078   std::ostringstream oss;
00079   oss << "(***************)\n(* MEDFileData *)\n(***************)\n\nFields part :\n*************\n\n";
00080   const MEDFileFields *tmp=_fields;
00081   if(tmp)
00082     {
00083       tmp->simpleRepr(0,oss);
00084       oss << std::endl;
00085     }
00086   else
00087     oss << "No fields set !!!\n\n";
00088   oss << "Meshes part :\n*************\n\n";
00089   const MEDFileMeshes *tmp2=_meshes;
00090   if(tmp2)
00091     {
00092       tmp2->simpleReprWithoutHeader(oss);
00093     }
00094   else
00095     oss << "No meshes set !!!\n";
00096   return oss.str();
00097 }
00098 
00099 MEDFileData::MEDFileData()
00100 {
00101 }
00102 
00103 MEDFileData::MEDFileData(const char *fileName) throw(INTERP_KERNEL::Exception)
00104 try
00105   {
00106     _fields=MEDFileFields::New(fileName);
00107     _meshes=MEDFileMeshes::New(fileName);
00108   }
00109 catch(INTERP_KERNEL::Exception& e)
00110   {
00111     throw e;
00112   }
00113 
00114 void MEDFileData::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
00115 {
00116   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
00117   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
00118   const MEDFileMeshes *ms=_meshes;
00119   if(ms)
00120     ms->write(fid);
00121   const MEDFileFields *fs=_fields;
00122   if(fs)
00123     fs->writeLL(fid);
00124 }