MEDmonter.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 #include <med.h>
00020 #include <med_config.h>
00021 #include <med_outils.h> 
00022 #include <string.h>
00023  
00024 #ifdef PPRO_NT
00025 #define F_OK 0
00026 #else
00027 #include <unistd.h>
00028 #endif
00029 
00030 med_idt
00031 MEDmonter(med_idt fid, const char *acces,med_type_donnee type)
00032 {
00033   med_err ret;
00034   med_idt root,id, did;
00035   char chemin[MED_TAILLE_NOM+1];
00036   char acces_montage[2*MED_TAILLE_NOM+1];
00037   med_mode_acces MED_MODE_ACCES;
00038 
00039   /*
00040    * On inhibe le gestionnaire d'erreur HDF
00041    */
00042   _MEDmodeErreurVerrouiller();
00043 if (MEDcheckVersion(fid) < 0) return -1;
00044 
00045 
00046   /*
00047    * On regarde si le fichier de nom "acces" existe
00048    * Si ce n'est pas le cas => erreur
00049    */
00050   if (access(acces,F_OK))
00051     return -1;
00052 
00053   if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
00054     MESSAGE("Impossible de déterminer le mode d'acces au fichier ");
00055     return -1;
00056   }
00057 
00058   /*
00059    * On ouvre le fichier "acces" selon le mode d'acces MED_MODE_ACCES
00060    */
00061   if ((id = _MEDfichierOuvrir((char *)acces,MED_MODE_ACCES)) < 0)
00062     return -1;
00063 
00064   /* 
00065    * Si le point de montage n'existe pas dans le fichier local, on le cree
00066    */
00067   root = _MEDdatagroupOuvrir(fid,MED_MNT);
00068   if (root < 0)
00069     if ((root = _MEDdatagroupCreer(fid,MED_MNT)) < 0)
00070       return -1;
00071   if ((ret = _MEDdatagroupFermer(root)) < 0)
00072     return -1;
00073 
00074   /*
00075    * Montage du fichier (id) sur le point de montage local (fid)
00076    */
00077   strncpy(acces_montage,MED_MNT,strlen(MED_MNT)-1);
00078   acces_montage[strlen(MED_MNT)-1] = '\0';
00079   if ((ret = _MEDfichierMonter(fid,acces_montage,id)) < 0)
00080     return -1;
00081 
00082   /*
00083    * On cree un lien vers le point de montage
00084    * selon qu'on l'on veuille acceder aux champs
00085    * ou aux maillages du fichier "acces" que l'on vient
00086    * de monter sur le fichier local "fid"
00087    */
00088   switch(type) {
00089 
00090   case MED_MAILLAGE :
00091     strcpy(chemin,MED_MAA);
00092     break;
00093 
00094   case MED_CHAMP :
00095     strcpy(chemin,MED_CHA);
00096     break;
00097 
00098   default :
00099     return -1;
00100   }
00101   
00102   /* 
00103    * Creation du lien HDF vers le(s) champ(s) ou le(s) maillage(s) 
00104    * dans le fichier local :
00105    * - Si ce type de donnee existe deja en local => erreur
00106    * - Sinon on le cree le lien vers le point de montage
00107    */
00108   strcat(acces_montage,chemin);
00109   acces_montage[strlen(acces_montage)-1] = '\0';
00110   chemin[strlen(chemin)-1] = '\0';
00111   if ((ret = _MEDdatagroupLienCreer(fid,acces_montage,chemin)) < 0)
00112     return -1;
00113 
00114   /*
00115    * On renvoie l'ID du fichier "acces" que l'on vient de monter
00116    */
00117   return id;
00118 }

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