# MEDfileCompatibility.c

Aller à la documentation de ce fichier.

    00001 /*  This file is part of MED.
    00002  *
    00003  *  COPYRIGHT (C) 1999 - 2012  EDF R&D, CEA/DEN
    00004  *  MED is free software: you can redistribute it and/or modify
    00005  *  it under the terms of the GNU Lesser General Public License as published by
    00006  *  the Free Software Foundation, either version 3 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  MED 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
    00012  *  GNU Lesser General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU Lesser General Public License
    00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
    00016  */
    00017
    00018
    00019 #include <med.h>
    00020 #include <med_config.h>
    00021 #include <med_outils.h>
    00022
    00023
    00033 med_err
    00034 MEDfileCompatibility(const char* const filename,
    00035                      med_bool* const hdfok,
    00036                      med_bool* const medok)
    00037 {
    00038   med_err _ret = -1;
    00039   med_idt _fid =  0;
    00040   med_idt _id  =  0;
    00041   med_int _major;
    00042   med_int _minor;
    00043
    00044   _MEDmodeErreurVerrouiller();
    00045
    00046   /* compatibility with hdf5 */
    00047   if  ( H5Fis_hdf5(filename) > 0 )
    00048     *hdfok = MED_TRUE;
    00049   else
    00050     *hdfok = MED_FALSE;
    00051
    00052   /* compatibility with med */
    00053   if ((_fid = _MEDfileOpen((char *)filename,MED_ACC_RDONLY)) < 0) {
    00054     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,filename);
    00055     SSCRUTE(filename);
    00056     goto ERROR;
    00057   }
    00058
    00059   if ((_id = _MEDdatagroupOuvrir(_fid,MED_INFOS)) < 0) {
    00060     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_INFOS);
    00061     goto ERROR;
    00062   }
    00063
    00064   if (_MEDattrEntierLire(_id,MED_MAJOR_NAME,&_major) < 0) {
    00065     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_MAJOR_NAME);
    00066     goto ERROR;
    00067   }
    00068
    00069   if (_MEDattrEntierLire(_id,MED_MINOR_NAME,&_minor) < 0) {
    00070     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_MINOR_NAME);
    00071     goto ERROR;
    00072   }
    00073
    00074   *medok = MED_FALSE;
    00075   if (*hdfok)
    00076     if ((_major > 2) || ((_major == 2) && (_minor > 1)))
    00077       *medok = MED_TRUE;
    00078
    00079   _ret = 0;
    00080  ERROR:
    00081
    00082   if (_id > 0)
    00083     if (_MEDdatagroupFermer(_id) < 0) {
    00084       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_INFOS);
    00085       _ret = -1;
    00086     }
    00087
    00088   if (_fid > 0)
    00089     if (MEDfileClose(_fid) < 0) {
    00090       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,filename);
    00091       _ret = -1;
    00092     }
    00093
    00094   return _ret;
    00095 }