Back to index

salome-med  6.5.0
MEDFileUtilities.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 "MEDFileUtilities.hxx"
00021 #include "MEDLoaderBase.hxx"
00022 
00023 #include <sstream>
00024 
00025 med_access_mode MEDFileUtilities::TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception)
00026 {
00027   switch(medloaderwritemode)
00028     {
00029     case 2:
00030       return MED_ACC_CREAT;
00031     case 1:
00032       return MED_ACC_RDEXT;
00033     case 0:
00034       return MED_ACC_RDWR;
00035     default:
00036       throw INTERP_KERNEL::Exception("Invalid write mode specified ! must be 0(write with no question), 1(append) or 2(creation)");
00037     }
00038 }
00039 
00040 int MEDFileUtilities::TraduceFieldType(med_field_type ft) throw(INTERP_KERNEL::Exception)
00041 {
00042   switch(ft)
00043     {
00044     case MED_FLOAT64:
00045       return 0;
00046     case MED_INT32:
00047       return 1;
00048     case MED_INT64:
00049       return 2;
00050     default:
00051       throw INTERP_KERNEL::Exception("Non supported field type ! Should be FLOAT64, INT32 or INT64 !");
00052     }
00053 }
00054 
00055 void MEDFileUtilities::CheckMEDCode(int code, med_idt fid, const char *msg) throw(INTERP_KERNEL::Exception)
00056 {
00057   if(code<0)
00058     {
00059       std::ostringstream oss;
00060       oss << "MEDFile has returned an error code (" << code <<") : " << msg;
00061       throw INTERP_KERNEL::Exception(oss.str().c_str());
00062     }
00063 }
00064 
00065 void MEDFileUtilities::CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception)
00066 {
00067   int status=MEDLoaderBase::getStatusOfFile(fileName);
00068   std::ostringstream oss;
00069   oss << " File : \"" << fileName << "\"";
00070   switch(status)
00071     {
00072     case MEDLoaderBase::DIR_LOCKED:
00073       {
00074         oss << " has been detected as unreadable : impossible to read anything !";
00075         throw INTERP_KERNEL::Exception(oss.str().c_str());
00076       }
00077     case MEDLoaderBase::NOT_EXIST:
00078       {
00079         oss << " has been detected as NOT EXISTING : impossible to read anything !";
00080         throw INTERP_KERNEL::Exception(oss.str().c_str());
00081       }
00082     case MEDLoaderBase::EXIST_WRONLY:
00083       {
00084         oss << " has been detected as WRITE ONLY : impossible to read anything !";
00085         throw INTERP_KERNEL::Exception(oss.str().c_str());
00086       }
00087     }
00088   AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00089   if(fid<0)
00090     {
00091       oss << " has been detected as unreadable by MED file : impossible to read anything !";
00092       throw INTERP_KERNEL::Exception(oss.str().c_str());
00093     }
00094   oss << " has been detected readable but ";
00095   int major,minor,release;
00096   MEDfileNumVersionRd(fid,&major,&minor,&release);
00097   if(major<2 || (major==2 && minor<2))
00098     {
00099       oss << "version of MED file is < 2.2 : impossible to read anything !";
00100       throw INTERP_KERNEL::Exception(oss.str().c_str());
00101     }
00102 }
00103 
00104 MEDFileUtilities::AutoFid::AutoFid(med_idt fid):_fid(fid)
00105 {
00106 }
00107 
00108 MEDFileUtilities::AutoFid::operator med_idt() const
00109 {
00110   return _fid;
00111 }
00112 
00113 MEDFileUtilities::AutoFid::~AutoFid()
00114 {
00115   MEDfileClose(_fid);
00116 }
00117 
00118 ParaMEDMEM::MEDFileWritable::MEDFileWritable():_too_long_str(0),_zipconn_pol(2)
00119 {
00120 }
00121 
00122 void ParaMEDMEM::MEDFileWritable::copyOptionsFrom(const MEDFileWritable& other) const
00123 {
00124   _too_long_str=other._too_long_str;
00125   _zipconn_pol=other._zipconn_pol;
00126 }
00127 
00128 int ParaMEDMEM::MEDFileWritable::getTooLongStrPolicy() const throw(INTERP_KERNEL::Exception)
00129 {
00130   return _too_long_str;
00131 }
00132 
00133 void ParaMEDMEM::MEDFileWritable::setTooLongStrPolicy(int newVal) throw(INTERP_KERNEL::Exception)
00134 {
00135   if(newVal!=2 && newVal!=1 && newVal!=0)
00136     throw INTERP_KERNEL::Exception("MEDFileWritable::setTooLongStrPolicy : invalid policy should be in 0,1 or 2 !");
00137   _too_long_str=newVal;
00138 }
00139 
00140 int ParaMEDMEM::MEDFileWritable::getZipConnPolicy() throw(INTERP_KERNEL::Exception)
00141 {
00142   return _zipconn_pol;
00143 }
00144 
00145 void ParaMEDMEM::MEDFileWritable::setZipConnPolicy(int newVal) throw(INTERP_KERNEL::Exception)
00146 {
00147   _zipconn_pol=newVal;
00148 }