# MEDfileOpen.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 #ifdef PPRO_NT
    00024 #define F_OK 0
    00025 #else
    00026 #include <unistd.h>
    00027 #endif
    00028
    00029
    00040 med_idt
    00041 MEDfileOpen(const char* const filename,
    00042             const med_access_mode accessmode)
    00043 {
    00044   med_idt _fid = 0;
    00045   med_err _ret = -1;
    00046
    00047   /*
    00048    * On inhibe le gestionnaire d'erreur HDF
    00049    */
    00050   _MEDmodeErreurVerrouiller();
    00051
    00052   /*
    00053    * On ouvre le fichier MED sous HDF
    00054    */
    00055   switch(accessmode)
    00056     {
    00057     case MED_ACC_RDONLY :
    00058       if (access(filename,F_OK)) {
    00059         MED_ERR_(_ret,MED_ERR_EXIST,MED_ERR_FILE,filename);
    00060         goto ERROR;
    00061
    00062       } else {
    00063         if ((_fid = _MEDfileOpen((char*) filename,accessmode)) < 0) {
    00064           MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,filename);
    00065           goto ERROR;
    00066         }
    00067       };
    00068       break;
    00069
    00070     case MED_ACC_RDWR :
    00071       if (access(filename,F_OK)) {
    00072         if ((_fid = _MEDfileCreate((char*) filename,accessmode)) < 0) {
    00073           MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILE,filename);
    00074           goto ERROR;
    00075         }
    00076       } else
    00077         if ((_fid = _MEDfileOpen((char*) filename,accessmode)) < 0) {
    00078           MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,filename);
    00079           goto ERROR;
    00080         }
    00081       break;
    00082
    00083     case MED_ACC_RDEXT :
    00084       if (access(filename,F_OK))
    00085         {
    00086           if ((_fid = _MEDfileCreate((char*) filename,accessmode)) < 0) {
    00087             MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILE,filename);
    00088             goto ERROR;
    00089           }
    00090         }
    00091       else
    00092         if ((_fid = _MEDfileOpen((char *) filename,accessmode)) < 0) {
    00093           MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,filename);
    00094           goto ERROR;
    00095         }
    00096       break;
    00097
    00098     case MED_ACC_CREAT :
    00099       if ((_fid = _MEDfileCreate((char *) filename,MED_ACC_RDWR)) < 0) {
    00100         MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILE,filename);
    00101         goto ERROR;
    00102       }
    00103       break;
    00104
    00105     default :
    00106       MED_ERR_(_ret,MED_ERR_INIT,MED_ERR_FILE,filename);
    00107       goto ERROR;
    00108     }
    00109
    00110   _ret=0;
    00111  ERROR:
    00112
    00113   if (_ret < 0)
    00114     _fid = (med_idt) _ret;
    00115
    00116   return _fid;
    00117 }
    00118