_MEDfileObjectsMount236.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 #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 #include <2.3.6/med23v30.h>
00031 #include <2.3.6/med23v30_proto.h>
00032 #include "2.3.6/med23v30_misc.h"
00033 
00034 void _MEDfileObjectsMount236(int dummy,...) {
00035 
00036   va_list params;
00037   va_start(params,dummy);
00038 
00039   const med_idt         fid           = va_arg(params,const med_idt          );
00040   const char*     const mountfilename = va_arg(params,const char*     const  );
00041   const med_class       medclass      = va_arg(params,const med_class        );
00042   med_idt *             fret          = va_arg(params, med_idt *);
00043 
00044   med_idt _ret = -1;
00045   med_idt _id, _rootId=0;
00046   char _mountPath[2*MED_NAME_SIZE+1];
00047   char _link[MED_NAME_SIZE+1];
00048   med_access_mode _accessMode;
00049   med_int  majeur=0, mineur=0, release=0;
00050   med_int  rfileversionMMR,rfileversionMM,rfileversionM;
00051   med_int  lfileversionMMR,lfileversionMM,lfileversionM;
00052   med_bool _datagroupexist=MED_FALSE,_isasoftlink=MED_FALSE;
00053 
00054   _MEDmodeErreurVerrouiller();
00055 
00056   if ( MEDfileNumVersionRd(fid, &majeur, &mineur, &release) < 0) {
00057     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDfileNumVersionRd");
00058     ISCRUTE(majeur);ISCRUTE(mineur);ISCRUTE(release);
00059     goto ERROR;
00060   }
00061   lfileversionM   = 100*majeur;
00062   lfileversionMM  = 100*majeur+10*mineur;
00063   lfileversionMMR = lfileversionMM+release;
00064 
00065   /*
00066    * does the file exist ?
00067    */
00068   if (access(mountfilename,F_OK)) {
00069     MED_ERR_(_ret,MED_ERR_EXIST,MED_ERR_FILE,mountfilename);
00070     goto ERROR;
00071   }
00072 
00073   if ( (_accessMode = (med_access_mode)_MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
00074     MED_ERR_(_ret,MED_ERR_ACCESS,MED_ERR_FILE,"");
00075     ISCRUTE_int(_accessMode);
00076     goto ERROR;
00077   }
00078 
00079   /*
00080    * Open the file "mountfilename".
00081    */
00082   if ((_id = _MEDfileOpen(mountfilename,_accessMode)) < 0) {
00083     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,mountfilename);
00084     goto ERROR;
00085   }
00086 
00087   if ( MEDfileNumVersionRd(_id, &majeur, &mineur, &release) < 0 ) {
00088     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDfileNumVersionRd");
00089     SSCRUTE(mountfilename);ISCRUTE(majeur);ISCRUTE(mineur); ISCRUTE(release);
00090     goto ERROR;
00091   }
00092   rfileversionM   = 100*majeur;
00093   rfileversionMM  = 100*majeur+10*mineur;
00094   rfileversionMMR = rfileversionMM+release;
00095 
00096   if ( !( ( (rfileversionMM >= 220) && (lfileversionMM >= 220)
00097             && (rfileversionMMR <= 236) && (lfileversionMMR <= 236) )     ) ){
00098          MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_FILE,mountfilename);
00099          ISCRUTE(rfileversionMMR);ISCRUTE(lfileversionMMR);
00100          goto ERROR;
00101        }
00102 
00103   /*
00104    * Mount point creation in the local file
00105    */
00106   _rootId = _MEDdatagroupOuvrir(fid,MED_MNT);
00107   if (_rootId < 0)
00108     if ((_rootId = _MEDdatagroupCreer(fid,MED_MNT)) < 0) {
00109       MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,MED_MNT);
00110       goto ERROR;
00111     }
00112 
00113   /*
00114    * The file "mountfilename" is mounted in the local file
00115    */
00116   strncpy(_mountPath,MED_MNT,strlen(MED_MNT)-1);
00117   _mountPath[strlen(MED_MNT)-1] = '\0';
00118   if (_MEDfichierMonter(fid,_mountPath,_id) < 0) {
00119     MED_ERR_(_ret,MED_ERR_MOUNT,MED_ERR_FILE,mountfilename);
00120     goto ERROR;
00121   }
00122 
00123 
00124   /*
00125    * Give access to the class object in the local file
00126    */
00127   switch(medclass) {
00128 
00129   case MED_MESH :
00130     strcpy(_link,MED_MAA);
00131     break;
00132 
00133   case MED_FIELD :
00134     strcpy(_link,MED_CHA);
00135     break;
00136 
00137   default :
00138     goto ERROR;
00139   }
00140 
00141   strcat(_mountPath,_link);
00142   _mountPath[strlen(_mountPath)-1] = '\0';
00143   _link[strlen(_link)-1] = '\0';
00144   if (_MEDdatagroupLienCreer(fid,_mountPath,_link) < 0) {
00145     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_LINK,_link);
00146     SSCRUTE(_mountPath);
00147     goto ERROR;
00148   }
00149 
00150   _ret = _id;
00151  ERROR:
00152 
00153   if (_rootId > 0)
00154     if (_MEDdatagroupFermer(_rootId) < 0) {
00155       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,MED_MNT);
00156     }
00157 
00158   va_end(params);
00159   *fret = _ret;
00160   return;
00161 }

Généré le Mon May 16 17:10:22 2011 pour MED fichier par  doxygen 1.6.1