_MEDfileObjectsMount30.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 _MEDfileObjectsMount30(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=0, _rootId=0,_linkId=0;
00046   char             _mountPath[MED_TAILLE_MNT+2*MED_NAME_SIZE+2]=MED_MNT;
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 
00093   rfileversionM   = 100*majeur;
00094   rfileversionMM  = 100*majeur+10*mineur;
00095   rfileversionMMR = rfileversionMM+release;
00096 
00097   if ( !( (rfileversionMM == lfileversionMM) && (rfileversionMMR <= lfileversionMM+9 ) ) ) {
00098          MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_FILE,mountfilename);
00099          ISCRUTE(rfileversionMMR);ISCRUTE(lfileversionMMR);
00100          goto ERROR;
00101        }
00102 
00103   /*
00104    * Give access to the class object in the local file
00105    */
00106   switch(medclass) {
00107 
00108   case MED_MESH :
00109     strcpy(_link,MED_MAA);
00110     break;
00111 
00112   case MED_MESH_SUPPORT :
00113     strcpy(_link,MED_SUP_MAA);
00114     break;
00115 
00116   case MED_ELSTRUCT :
00117     strcpy(_link,MED_STRCT);
00118     break;
00119 
00120   case MED_FAMILY :
00121     strcpy(_link,MED_FAS);
00122     break;
00123 
00124   case MED_EQUIVALENCE :
00125     strcpy(_link,MED_EQS);
00126     break;
00127 
00128   case MED_JOINT :
00129     strcpy(_link,MED_JNT);
00130     break;
00131 
00132   case MED_FIELD :         /* Ajouter aussi MED_CHA_INTERP*/
00133     strcpy(_link,MED_CHA);
00134     break;
00135 
00136   case MED_LOCALIZATION :
00137     strcpy(_link,MED_GAUSS);
00138     break;
00139 
00140   case MED_PROFILE :
00141     strcpy(_link,MED_PROFILS);
00142     break;
00143 
00144   case MED_INTERPOLATION :
00145     strcpy(_link,MED_JNT);
00146     break;
00147 
00148   case MED_NUMERICAL_DATA :
00149     strcpy(_link,MED_NUM_DATA);
00150     break;
00151 
00152   default :
00153     goto ERROR;
00154   }
00155 
00156   /*
00157    * Mount point creation in the local file
00158    * TODO : Ds un fichier mémoire
00159    */
00160   if ((_rootId = _MEDdatagroupOuvrir(fid,MED_MNT)) < 0 )
00161     if ((_rootId = _MEDdatagroupCreer(fid,MED_MNT)) < 0) {
00162       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_MNT);
00163       goto ERROR;
00164     }
00165 
00166   if ((_linkId = _MEDdatagroupOuvrir(_rootId,&_link[1])) <0)
00167     if ((_linkId = _MEDdatagroupCreer(_rootId,&_link[1])) < 0) {
00168       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_MNT);
00169       SSCRUTE(&_link[1]);goto ERROR;
00170     }
00171 
00172   strcpy(&_mountPath[strlen(_mountPath)-1],_link);
00173 /*   SSCRUTE(_mountPath); */
00174   if ( _MEDfichierMonter(fid,_mountPath,_id) < 0 ) {
00175     MED_ERR_(_ret,MED_ERR_MOUNT,MED_ERR_FILE,_mountPath);
00176     H5Eprint1(stderr);
00177     goto ERROR;
00178   }
00179 
00180   strcpy(&_mountPath[strlen(_mountPath)-1],_link);
00181 /*   SSCRUTE(_mountPath); */
00182   if( _MEDdatagroupExist(fid,_link,&_datagroupexist,&_isasoftlink) < 0 ) {
00183     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDdatagroupExist");
00184     SSCRUTE(MED_NOM_NOE);goto ERROR;
00185   }
00186   if ( _datagroupexist && !_isasoftlink ) {
00187     MED_ERR_(_ret,MED_ERR_EXIST,MED_ERR_DATAGROUP,_link);
00188     SSCRUTE(_mountPath);
00189     goto ERROR;
00190   }
00191 
00192   if ( (!_datagroupexist) )
00193     if (_MEDdatagroupLienCreer(fid,_mountPath,_link) < 0) {
00194       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_LINK,_link);
00195       SSCRUTE(_mountPath);
00196       goto ERROR;
00197     }
00198 
00199   _ret = _id;
00200  ERROR:
00201 
00202   if (_linkId > 0)
00203     if (_MEDdatagroupFermer(_linkId) < 0) {
00204       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,MED_MNT);
00205     }
00206 
00207   if (_rootId > 0)
00208     if (_MEDdatagroupFermer(_rootId) < 0) {
00209       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,MED_MNT);
00210     }
00211 
00212   va_end(params);
00213   *fret = _ret;
00214   return;
00215 }

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