Salome HOME
MED write/append with a lower major version of MED file format: comments
[modules/smesh.git] / src / MEDWrapper / MED_Factory.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "MED_Factory.hxx"
24 #include "MED_Utilities.hxx"
25 #include "MED_Wrapper.hxx"
26
27 #include <stdio.h>
28 #include <errno.h>
29 #include <sstream>
30 #include <fstream>
31
32 #include <med.h>
33 extern "C"
34 {
35 #ifndef WIN32
36   #include <unistd.h>
37 #endif
38 }
39 #include <utilities.h>
40
41 #ifdef WIN32
42 #include <windows.h>
43 #endif
44
45 // -------------------------------------------------------------------------------------------------------------------
46 // --- MED file compatibility: write using a lower major version implies append on an empty file of the target version
47
48 #define MED_MAJOR_EXPECTED 4
49 #define MED_MINOR_EXPECTED 0
50 #if MED_MAJOR_NUM != MED_MAJOR_EXPECTED
51   #error "MED major version does not correspond to the expected version, fix the minor and major compatibility values in CheckCompatibility method (MED_VERSIONS_APPEND_COMPATIBLE) and set the correct expected version"
52 #endif
53 #if MED_MINOR_NUM != MED_MINOR_EXPECTED
54   #error "MED minor version does not correspond to the expected version, fix the minor and major compatibility values in CheckCompatibility method (MED_VERSIONS_APPEND_COMPATIBLE) and set the correct expected version"
55 #endif
56 #define MED_VERSIONS_APPEND_COMPATIBLE {40, 32, 33} // --- 10*major + minor (the 3rd digit, release, is not used here,
57                                                     //                       med uses always the latest available)
58                                                     // --- The first in the list should be the default: current version
59 // --- empty med file content for the different MED versions with a different major.
60 //     ==> correct accordingly CreateEmptyMEDFile method below!
61 #define EMPTY_FILE_32 {0x89,0x48,0x44,0x46,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0x0,0x0,0x8,0x8,0x0,0x4,0x0,0x10,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe8,0x7,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x60,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x88,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa8,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x1,0x0,0x1,0x0,0x0,0x0,0x18,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x11,0x0,0x10,0x0,0x0,0x0,0x0,0x0,0x88,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa8,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x54,0x52,0x45,0x45,0x0,0x0,0x1,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xe0,0x5,0x0,0x0,0x0,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0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exa representation of MED file built in Python
64 f= open('vide_321.med', 'rb')
65 data=f.read()
66 ba=bytearray(data)
67 a=""
68 for i in ba:
69   a+=hex(i)
70   a+=','
71 print a
72 */
73
74 //! internal use: fileName and version must be checked before call
75 bool CreateEmptyMEDFile(const std::string& fileName, int version)
76 {
77   MESSAGE("create an empty med file of the right version, for append " << version);
78   static const unsigned char empty_32[] = EMPTY_FILE_32;
79   static const unsigned char empty_33[] = EMPTY_FILE_33;
80   std::ofstream ofs(fileName);
81   if (version == 32)
82     ofs.write(reinterpret_cast<const char *>(empty_32),sizeof(empty_32));
83   else if (version == 33)
84     ofs.write(reinterpret_cast<const char *>(empty_33),sizeof(empty_33));
85   return true;
86 }
87 // -------------------------------------------------------------------------------------------------------------------
88
89 namespace MED
90 {
91   bool exists(const std::string& fileName)
92   {
93 #ifdef WIN32
94 #ifdef UNICODE
95         size_t length = strlen(fileName.c_str()) + sizeof(char);
96         wchar_t* path = new wchar_t[length];
97         memset(path, '\0', length);
98         mbstowcs(path, fileName.c_str(), length);
99 #else
100         cosnt char* path = xmlPath.c_str();
101 #endif
102     return (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES);
103 #else
104     return (access(fileName.c_str(), F_OK) == 0);
105 #endif
106   }
107
108   /*!
109    *  Return the list of med versions compatibles for write/append,
110    *  encoded in 10*major+minor (for instance, code for med 3.2.1 is 32)
111    */
112   std::vector<int> GetMEDVersionsAppendCompatible()
113   {
114     int mvok[] = MED_VERSIONS_APPEND_COMPATIBLE;
115     std::vector<int> MEDVersionsOK(mvok, mvok + sizeof(mvok)/sizeof(int));
116     return MEDVersionsOK;
117   }
118
119   /*!
120    *  \brief: Check read or write(append) Compatibility of a med file
121    *  \param [in] : fileName - the file to read or to append to
122    *  \param [in] : isforAppend - when true, check if the med file version is OK to append a mesh,
123    *                              when false, check if the med file is readable.
124    */
125   bool CheckCompatibility(const std::string& fileName, bool isForAppend)
126   {
127     bool ok = false;
128     int medVersionsOK[] = MED_VERSIONS_APPEND_COMPATIBLE;
129     // check that file is accessible
130     if ( exists(fileName) ) {
131       // check HDF5 && MED compatibility
132       med_bool hdfok, medok;
133       med_err r0 = MEDfileCompatibility(fileName.c_str(), &hdfok, &medok);
134       MESSAGE(r0 << " " << hdfok << " " << medok);
135       if ( r0==0 && hdfok && medok ) {
136         med_idt aFid = MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
137         if (aFid >= 0) {
138           med_int major, minor, release;
139           med_err ret = MEDfileNumVersionRd(aFid, &major, &minor, &release);
140           MESSAGE(ret << " " << major << "." << minor << "." << release);
141           if (ret >= 0) {
142             bool isReadOnly = !isForAppend;
143             if (isReadOnly)
144               ok = true;
145             else {
146               int medVersion = 10*major + minor;
147               for (int ii=0; ii < sizeof(medVersionsOK)/sizeof(int); ii++)
148                 if (medVersionsOK[ii] == medVersion) {
149                   ok =true;
150                   break;
151                 }
152             }
153           }
154         }
155         MEDfileClose(aFid);
156       }
157     }
158     return ok;
159   }
160
161   bool GetMEDVersion(const std::string& fileName, int& major, int& minor, int& release)
162   {
163     bool ok = false;
164     major = minor = release = 0;
165     med_idt aFid = MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
166     if (aFid >= 0) {
167       med_int _major, _minor, _release;
168       med_err ret = MEDfileNumVersionRd(aFid, &_major, &_minor, &_release);
169       if (ret == 0) {
170         major = _major;
171         minor = _minor;
172         release = _release;
173         ok = true;
174       }
175       MEDfileClose(aFid);
176     }
177     return ok;
178   }
179
180   std::string GetMEDVersion(const std::string& fileName)
181   {
182     std::string version;
183     int major, minor, release;
184     if (GetMEDVersion(fileName, major, minor, release)) {
185       std::ostringstream os;
186       os << major << "." << minor << "." << release;
187       version = os.str();
188     }
189     return version;
190   }
191
192   PWrapper CrWrapperR(const std::string& fileName)
193   {
194     if (!CheckCompatibility(fileName)) {
195       EXCEPTION(std::runtime_error, "Cannot open file '"<<fileName<<"'.");
196     }
197     return new MED::TWrapper(fileName);
198   }
199
200   PWrapper CrWrapperW(const std::string& fileName, int theVersion)
201   {
202     bool isCreated = false;
203     if (!CheckCompatibility(fileName, true))
204       {
205         remove(fileName.c_str());
206         isCreated = true;
207       }
208     int minor = -1;
209     if (isCreated)
210       {
211         med_int wantedMajor = MED_MAJOR_NUM;
212         med_int wantedMinor = MED_MINOR_NUM;
213         if (theVersion > 0)
214           {
215             wantedMajor = theVersion/10;
216             wantedMinor = theVersion%10;
217           }
218         if (wantedMajor == MED_MAJOR_NUM) // the med file will be actually created
219           {
220             if (wantedMinor < MED_MINOR_NUM)
221               minor = wantedMinor;
222           }
223         else                              // an empty existing med file of the right version will be used for append
224           {
225             int medVersionsOK[] = MED_VERSIONS_APPEND_COMPATIBLE;
226             bool isVersionOK = false;
227             for (int ii=0; ii < sizeof(medVersionsOK)/sizeof(int); ii++)
228               if (medVersionsOK[ii] == theVersion)
229                 {
230                   isVersionOK =true;
231                   break;
232                 }
233             if (isVersionOK)              // copy an empty existing med file of the right version, for append
234               CreateEmptyMEDFile(fileName, theVersion);
235           }
236       }
237     return new MED::TWrapper(fileName, minor);
238   }
239 }