# MEDparFileOpen.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 #include <mpi.h>
    00024
    00025 #ifdef PPRO_NT
    00026 #define F_OK 0
    00027 #else
    00028 #include <unistd.h>
    00029 #endif
    00030
    00031
    00032 med_access_mode MED_ACCESS_MODE;
    00033
    00047 /*#define true 1*/
    00048
    00049 med_idt
    00050 MEDparFileOpen(const char* const filename,
    00051                const med_access_mode accessmode,
    00052                const MPI_Comm comm, const MPI_Info info)
    00053 {
    00054   med_idt _fid = -1;
    00055
    00056   /*
    00057    * On inhibe le gestionnaire d'erreur HDF
    00058    */
    00059   _MEDmodeErreurVerrouiller();
    00060   /*
    00061    * On ouvre le fichier MED sous HDF
    00062    */
    00063   switch(accessmode)
    00064     {
    00065     case MED_ACC_RDONLY :
    00066       if (access(filename,F_OK)) {
    00067         MED_ERR_(_fid,MED_ERR_DOESNTEXIST,MED_ERR_FILE,filename);
    00068         goto ERROR;
    00069
    00070       } else {
    00071         if ((_fid = _MEDparFileOpen((char*) filename, accessmode, comm, info)) < 0) {
    00072           MED_ERR_(_fid,MED_ERR_OPEN,MED_ERR_FILE,filename);
    00073           goto ERROR;
    00074         }
    00075       };
    00076       break;
    00077
    00078     case MED_ACC_RDWR :
    00079       if (access(filename,F_OK)) {
    00080         if ((_fid = _MEDparFileCreate((char*) filename,accessmode, comm, info)) < 0) {
    00081           MED_ERR_(_fid,MED_ERR_CREATE,MED_ERR_FILE,filename);
    00082           goto ERROR;
    00083         }
    00084       } else
    00085         if ((_fid = _MEDparFileOpen((char*) filename,accessmode, comm, info)) < 0) {
    00086           MED_ERR_(_fid,MED_ERR_OPEN,MED_ERR_FILE,filename);
    00087           goto ERROR;
    00088         }
    00089       break;
    00090
    00091     case MED_ACC_RDEXT :
    00092       if (access(filename,F_OK))
    00093         {
    00094           if ((_fid = _MEDparFileCreate((char*) filename,accessmode, comm, info)) < 0) {
    00095             MED_ERR_(_fid,MED_ERR_CREATE,MED_ERR_FILE,filename);
    00096             goto ERROR;
    00097           }
    00098         } else
    00099
    00100         if ((_fid = _MEDparFileOpen((char *) filename, accessmode, comm, info)) < 0) {
    00101           MED_ERR_(_fid,MED_ERR_OPEN,MED_ERR_FILE,filename);
    00102           goto ERROR;
    00103         }
    00104       break;
    00105
    00106     case MED_ACC_CREAT :
    00107       if ((_fid = _MEDparFileCreate((char *) filename,MED_ACC_RDWR, comm, info)) < 0) {
    00108         MED_ERR_(_fid,MED_ERR_CREATE,MED_ERR_FILE,filename);
    00109         goto ERROR;
    00110       }
    00111       break;
    00112
    00113     default :
    00114       MED_ERR_(_fid,MED_ERR_RANGE,MED_ERR_PARAMETER,"");
    00115       ISCRUTE_int(accessmode);
    00116       goto ERROR;
    00117     }
    00118
    00119   if (_MEDcheckVersion30(_fid) < 0) {
    00120     MEDfileClose(_fid);
    00121     _fid=-1;goto ERROR;
    00122   }
    00123
    00124  ERROR:
    00125
    00126   return _fid;
    00127 }