1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDFileUtilities.hxx"
22 #include "MEDLoaderBase.hxx"
26 med_access_mode MEDFileUtilities::TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception)
28 switch(medloaderwritemode)
37 throw INTERP_KERNEL::Exception("Invalid write mode specified ! must be 0(write with no question), 1(append) or 2(creation)");
41 int MEDFileUtilities::TraduceFieldType(med_field_type ft) throw(INTERP_KERNEL::Exception)
52 throw INTERP_KERNEL::Exception("Non supported field type ! Should be FLOAT64, INT32 or INT64 !");
56 void MEDFileUtilities::CheckMEDCode(int code, med_idt fid, const char *msg) throw(INTERP_KERNEL::Exception)
60 std::ostringstream oss;
61 oss << "MEDFile has returned an error code (" << code <<") : " << msg;
62 throw INTERP_KERNEL::Exception(oss.str().c_str());
66 void MEDFileUtilities::CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception)
68 int status=MEDLoaderBase::getStatusOfFile(fileName);
69 std::ostringstream oss;
70 oss << " File : \"" << fileName << "\"";
73 case MEDLoaderBase::DIR_LOCKED:
75 oss << " has been detected as unreadable : impossible to read anything !";
76 throw INTERP_KERNEL::Exception(oss.str().c_str());
78 case MEDLoaderBase::NOT_EXIST:
80 oss << " has been detected as NOT EXISTING : impossible to read anything !";
81 throw INTERP_KERNEL::Exception(oss.str().c_str());
83 case MEDLoaderBase::EXIST_WRONLY:
85 oss << " has been detected as WRITE ONLY : impossible to read anything !";
86 throw INTERP_KERNEL::Exception(oss.str().c_str());
89 AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
92 oss << " has been detected as unreadable by MED file : impossible to read anything !";
93 throw INTERP_KERNEL::Exception(oss.str().c_str());
95 oss << " has been detected readable but ";
96 int major,minor,release;
97 MEDfileNumVersionRd(fid,&major,&minor,&release);
98 if(major<2 || (major==2 && minor<2))
100 oss << "version of MED file is < 2.2 : impossible to read anything !";
101 throw INTERP_KERNEL::Exception(oss.str().c_str());
105 MEDFileUtilities::AutoFid::AutoFid(med_idt fid):_fid(fid)
109 MEDFileUtilities::AutoFid::operator med_idt() const
114 MEDFileUtilities::AutoFid::~AutoFid()
119 ParaMEDMEM::MEDFileWritable::MEDFileWritable():_too_long_str(0),_zipconn_pol(2)
123 void ParaMEDMEM::MEDFileWritable::copyOptionsFrom(const MEDFileWritable& other) const
125 _too_long_str=other._too_long_str;
126 _zipconn_pol=other._zipconn_pol;
129 int ParaMEDMEM::MEDFileWritable::getTooLongStrPolicy() const throw(INTERP_KERNEL::Exception)
131 return _too_long_str;
134 void ParaMEDMEM::MEDFileWritable::setTooLongStrPolicy(int newVal) throw(INTERP_KERNEL::Exception)
136 if(newVal!=2 && newVal!=1 && newVal!=0)
137 throw INTERP_KERNEL::Exception("MEDFileWritable::setTooLongStrPolicy : invalid policy should be in 0,1 or 2 !");
138 _too_long_str=newVal;
141 int ParaMEDMEM::MEDFileWritable::getZipConnPolicy() throw(INTERP_KERNEL::Exception)
146 void ParaMEDMEM::MEDFileWritable::setZipConnPolicy(int newVal) throw(INTERP_KERNEL::Exception)