MEDouvrir.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2015  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 
00020 #include <med.h>
00021 #include <med_config.h>
00022 #include <med_outils.h> 
00023 
00024 #ifdef PPRO_NT
00025 #define F_OK 0
00026 #else
00027 #include <unistd.h>
00028 #endif
00029 
00030 /* Variable globale qui gere le mode d'acces aux fichiers */
00031 /* ATTENTION : si on ouvre plusieurs fichiers, il faut les
00032    ouvrir tous avec le meme mode d'acces */
00033 med_mode_acces MED_MODE_ACCES;
00034 
00035 
00036 med_idt
00037 MEDouvrir(char *nom, med_mode_acces mode_acces)
00038 {
00039   med_idt fid=0; 
00040 
00041   /*
00042    * On inhibe le gestionnaire d'erreur HDF
00043    */
00044   _MEDmodeErreurVerrouiller();
00045 
00046   /*
00047    * On ouvre le fichier MED sous HDF
00048    */
00049   switch(mode_acces)
00050     {
00051     case MED_LECTURE :
00052       if (access(nom,F_OK)) {
00053 
00054         MESSAGE("Impossible d'accéder aux fichier :");
00055         SSCRUTE(nom);
00056         return -1;
00057         
00058       } else { 
00059         if ((fid = _MEDfichierOuvrir(nom,mode_acces)) < 0)  return -1;
00060         /*_MEDsetModeAcces(fid,MED_LECTURE);*/
00061       };
00062       break;
00063 
00064     case MED_LECTURE_ECRITURE : 
00065       if (access(nom,F_OK)) {
00066           if ((fid = _MEDfichierCreer(nom,mode_acces)) < 0)
00067             return -1;
00068       } else 
00069         if ((fid = _MEDfichierOuvrir(nom,mode_acces)) < 0)
00070           return -1;
00071       break;
00072 
00073     case MED_LECTURE_AJOUT    :
00074       if (access(nom,F_OK))
00075         {
00076           if ((fid = _MEDfichierCreer(nom,mode_acces)) < 0)
00077             return -1;
00078         }
00079       else 
00080         if ((fid = _MEDfichierOuvrir(nom,mode_acces)) < 0)
00081           return -1;
00082       break;
00083       
00084     case MED_CREATION :
00085       if ((fid = _MEDfichierCreer(nom,MED_LECTURE_ECRITURE)) < 0)
00086         return -1;
00087       break;
00088 
00089     default :
00090       return -1;
00091     }
00092 
00093 if (MEDcheckVersion(fid) < 0) {
00094         if (fid >0) _MEDfichierFermer(fid); 
00095         return -1;
00096 }
00097 
00098   return fid;
00099 }

Généré le Thu Oct 8 14:26:16 2015 pour MED fichier par  doxygen 1.6.1