00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 #include <med.h>
00020 #include <med_config.h>
00021 #include <med_outils.h>
00022 
00023 #include <string.h>
00024 #include <stdlib.h>
00025 
00047 
00048 
00049 med_geometry_type
00050 MEDstructElementCr(const med_idt                 fid,
00051                    const char*             const modelname,
00052                    const med_int                 modeldim,
00053                    const char*             const supportmeshname,
00054                    const med_entity_type         sentitytype,
00055                    const med_geometry_type       sgeotype
00056                    )
00057 {
00058   med_access_mode   _MED_ACCESS_MODE;
00059   med_err           _err=-1;
00060   med_idt           _root=0,_elemid=0;
00061   med_int           _ret=-1;
00062   char              _path[MED_TAILLE_STRCT+MED_NAME_SIZE+1]=MED_STRCT;
00063   med_size          _tmpn=0;
00064   med_geometry_type _stgeotype=0;
00065   med_int           _medintstgeotype = 0;
00066   med_int           _medintsgeotype  = sgeotype;
00067   med_int           _intentitytype   = sentitytype;
00068   med_int           _nnode=0,_ncell=0;
00069   med_bool          _chgt=MED_FALSE,_trsf=MED_FALSE;
00070 
00071 
00072 
00073   
00074 
00075 
00076   _MEDmodeErreurVerrouiller();
00077  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
00078 
00079   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
00080     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00081     goto ERROR;
00082   }
00083 
00084   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
00085     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00086     ISCRUTE_int(_MED_ACCESS_MODE);
00087     goto ERROR;
00088   }
00089 
00090   
00091 
00092 
00093   if ((_root = _MEDdatagroupOpen(fid,_path)) < 0)
00094     if ((_root = _MEDdatagroupCrOrderCr(fid,_path)) < 0) {
00095       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
00096      goto ERROR;
00097     }
00098 
00099   NOFINALBLANK(modelname,ERROR);
00100 
00101   
00102 
00103 
00104   if ((_elemid = _MEDdatagroupOpen(_root,modelname)) < 0) {
00105     if ((_elemid = _MEDdatagroupCreer(_root,modelname)) < 0) {
00106       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,modelname);
00107       SSCRUTE(_path);goto ERROR;
00108     }
00109   } else {
00110     
00111 
00112 
00113     if ( _MEDattrEntierLire(_elemid,MED_NOM_NEO,&_medintstgeotype) < 0 ) {
00114       MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path);
00115       SSCRUTE(MED_NOM_NEO);ISCRUTE(_medintstgeotype);
00116       goto ERROR;
00117     }
00118     _stgeotype = _medintstgeotype;
00119   }
00120   strcat(_path,modelname);
00121 
00122   
00123 
00124 
00125   if ( _MEDattributeIntWr(_elemid,MED_NOM_DIM,&modeldim) < 0 ) {
00126     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
00127     SSCRUTE(MED_NOM_DIM);ISCRUTE(modeldim);
00128     goto ERROR;
00129   }
00130 
00131   
00132 
00133 
00134   if ( _MEDattributeStringWr(_elemid,MED_NOM_NOM,MED_NAME_SIZE,supportmeshname) < 0) {
00135     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
00136     SSCRUTE(MED_NOM_NOM);SSCRUTE(supportmeshname);
00137     goto ERROR;
00138   }
00139 
00140   
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149   if ( _MEDattributeIntWr(_elemid,MED_NOM_ENT,&_intentitytype) < 0 ) {
00150     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
00151     SSCRUTE(MED_NOM_ENT);ISCRUTE(_intentitytype);
00152     goto ERROR;
00153   }
00154 
00155   
00156 
00157 
00158 
00159   if (strlen(supportmeshname)) {
00160     if ( (_nnode = MEDmeshnEntity(fid,supportmeshname,MED_NO_DT,MED_NO_IT,
00161                                      MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,
00162                                      &_chgt,&_trsf) )  <= 0) {
00163       MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
00164       ISCRUTE(_nnode);goto ERROR;
00165     }
00166   } else {
00167     _nnode=1;
00168   }
00169 
00170   if (strlen(supportmeshname)) {
00171     if ( (_ncell = MEDmeshnEntity(fid,supportmeshname,MED_NO_DT,MED_NO_IT,
00172                                      MED_CELL,sgeotype,MED_CONNECTIVITY,MED_NODAL,
00173                                      &_chgt,&_trsf) )  < 0) {
00174       MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
00175       ISCRUTE(_ncell);goto ERROR;
00176     }
00177   } else {
00178     _ncell=0;
00179   }
00180 
00181   
00182 
00183 
00184   _medintsgeotype = sgeotype;
00185   if ( _MEDattributeIntWr(_elemid,MED_NOM_GEO,&_medintsgeotype) < 0 ) {
00186     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
00187     SSCRUTE(MED_NOM_GEO);ISCRUTE(_medintsgeotype);
00188     goto ERROR;
00189   }
00190 
00191   
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200   
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 
00210   
00211 
00212 
00213   if ( !_stgeotype ) {
00214 
00215     
00216 
00217     if ((_err=_MEDnObjects(fid,MED_STRCT,&_tmpn)) <0) {
00218       MED_ERR_(_ret,MED_ERR_COUNT,MED_ERR_STRUCT,MED_STRCT);
00219       goto ERROR;
00220     }
00221 
00222     _stgeotype=_tmpn+MED_STRUCT_GEO_INTERNAL;
00223     _medintstgeotype=_stgeotype;
00224 
00225     
00226 
00227 
00228     if ( _MEDattributeIntWr(_elemid,MED_NOM_NEO,&_medintstgeotype) < 0 ) {
00229       MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
00230       SSCRUTE(MED_NOM_NEO);ISCRUTE(_medintstgeotype);
00231       goto ERROR;
00232     }
00233   }
00234 
00235   _ret = _stgeotype;
00236 
00237  ERROR:
00238 
00239   if (_elemid>0)     if (_MEDdatagroupFermer(_elemid) < 0) {
00240     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
00241     ISCRUTE_id(_elemid);
00242   }
00243 
00244   if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
00245     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_STRCT);
00246     ISCRUTE_id(_root);
00247   }
00248 
00249   return _ret;
00250 
00251 }