# MEDparFileOpen.c

Aller à la documentation de ce fichier.

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