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
00026 void _MEDfieldValueAdvancedRd30(int dummy,...) {
00027
00028 med_err _ret=-1;
00029 med_idt _gid=0,_locgid=0, _datagroup1=0, _datagroup2=0, _datagroup3=0;
00030 med_int _nbofconstituentpervalue=0,_nbofvaluesperentityfromloc=0;
00031 med_int _nbofvaluesperentity=0,_profilearraysize=0;
00032 med_int _nbofsectiongeotype=0,_nbofsectioncell=1;
00033 med_bool _filterparameterexist=MED_FALSE;
00034 med_field_type _fieldtype=0;
00035 med_int _intfieldtype=0;
00036 med_geometry_type _locgeotype=0,_sectiongeotype=0;
00037 med_int _intlocgeotype=0;
00038 char _gidname [MED_TAILLE_CHA+MED_NAME_SIZE+1]=MED_CHA;
00039 char _datagroupname1 [2*MED_MAX_PARA+1]="";
00040 char _datagroupname2 [2*MED_TAILLE_NOM_ENTITE+2]="";
00041 char _profilename [MED_NAME_SIZE+1]="";
00042 char _meshname [MED_NAME_SIZE+1]="";
00043 char _locgidname [MED_TAILLE_GAUSS+MED_NAME_SIZE+1]="";
00044 char _sectionmeshname [MED_NAME_SIZE+1]="";
00045 char _sectiongeotypename [MED_NAME_SIZE+1]="";
00046 char _localizationname [MED_NAME_SIZE+1]="";
00047 char _geotypename[MED_TAILLE_NOM_ENTITE+1]="", pfltmp[MED_NAME_SIZE+1]="";
00048 med_filter * _filter = NULL;
00049 med_filter _tmpfilter = MED_FILTER_INIT;
00050 med_filter _paramfilter = MED_FILTER_INIT;
00051 med_bool _chgt=MED_FALSE,_trsf=MED_FALSE;
00052
00053
00054 MED_VARGS_DECL(const, med_idt , , fid );
00055 MED_VARGS_DECL(const, char * , const , fieldname );
00056 MED_VARGS_DECL(const, med_int , , numdt );
00057 MED_VARGS_DECL(const, med_int , , numit );
00058 MED_VARGS_DECL(const, med_entity_type , , entitytype );
00059 MED_VARGS_DECL(const, med_geometry_type , , geotype );
00060 MED_VARGS_DECL(const, char * , const , meshname );
00061 MED_VARGS_DECL(const, med_storage_mode , , storagemode );
00062 MED_VARGS_DECL(const, char * , const , profilename );
00063 MED_VARGS_DECL(const, med_switch_mode , , switchmode );
00064 MED_VARGS_DECL(const, med_int , , componentselect );
00065 MED_VARGS_DECL(const, med_filter* , const , filter );
00066 MED_VARGS_DECL(,unsigned char*, const , value );
00067 MED_VARGS_DECL(, med_err * ,, fret );
00068
00069 va_list params;
00070 va_start(params,dummy);
00071
00072 MED_VARGS_DEF(const, med_idt , , fid );
00073 MED_VARGS_DEF(const, char * , const , fieldname );
00074 MED_VARGS_DEF(const, med_int , , numdt );
00075 MED_VARGS_DEF(const, med_int , , numit );
00076 MED_VARGS_DEF(const, med_entity_type , , entitytype );
00077 MED_VARGS_DEF(const, med_geometry_type , , geotype );
00078 MED_VARGS_DEF(const, char * , const , meshname );
00079 MED_VARGS_DEF(const, med_storage_mode , , storagemode );
00080 MED_VARGS_DEF(const, char * , const , profilename );
00081 MED_VARGS_DEF(const, med_switch_mode , , switchmode );
00082 MED_VARGS_DEF(const, med_int , , componentselect );
00083 MED_VARGS_DEF(const, med_filter* , const , filter );
00084 MED_VARGS_DEF(,unsigned char*, const , value );
00085 MED_VARGS_DEF(, med_err * ,, fret );
00086
00087 if (filter) {
00088 _filter=(med_filter*)(filter); _filterparameterexist=MED_TRUE;
00089 }
00090 else {
00091 _filter=&_tmpfilter;
00092
00093
00094
00095 (*_filter).constituentselect = componentselect;
00096 (*_filter).switchmode = switchmode;
00097 (*_filter).storagemode = storagemode;
00098 strcpy((*_filter).profilename,profilename);
00099
00100 }
00101
00102
00103
00104
00105 _MEDmodeErreurVerrouiller();
00106
00107
00108
00109
00110 strcat(_gidname,fieldname);
00111
00112
00113 if ( _MEDattributeStringRdByName(fid,_gidname,MED_NOM_MAI,MED_NAME_SIZE,_meshname) < 0) {
00114 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
00115 SSCRUTE(_gidname);SSCRUTE(MED_NOM_MAI);SSCRUTE(_meshname);
00116 goto ERROR;
00117 }
00118
00119 if (strlen(meshname) )
00120 if (strcmp(_meshname,meshname) ) {
00121 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_PARAMETER,"meshname");
00122 SSCRUTE(_gidname);SSCRUTE(_meshname);SSCRUTE(meshname);
00123 goto ERROR;
00124 }
00125
00126 if ((_gid = _MEDdatagroupOuvrir(fid,_gidname)) < 0) {
00127 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_FIELD_MSG);
00128 SSCRUTE(fieldname);SSCRUTE(_gidname); goto ERROR;
00129 }
00130
00131
00132
00133 if (_MEDattrEntierLire(_gid,MED_NOM_NCO,&_nbofconstituentpervalue) < 0) {
00134 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
00135 SSCRUTE(fieldname);SSCRUTE(MED_NOM_NCO);goto ERROR;
00136 }
00137
00138 if (_filterparameterexist) {
00139 if ((*_filter).nbofconstituentpervalue != _nbofconstituentpervalue ) {
00140 MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_ATTRIBUTE,MED_ERR_VALUE_MSG);
00141 ISCRUTE((*_filter).nbofconstituentpervalue); ISCRUTE(_nbofconstituentpervalue );
00142 goto ERROR;
00143 }
00144 } else {
00145 (*_filter).nbofconstituentpervalue = _nbofconstituentpervalue;
00146 }
00147
00148
00149 if ( _MEDattrEntierLire(_gid,MED_NOM_TYP,&_intfieldtype) < 0) {
00150 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
00151 SSCRUTE(fieldname);SSCRUTE(MED_NOM_TYP);
00152 goto ERROR;
00153 }
00154 _fieldtype = (med_field_type) (_intfieldtype);
00155
00156
00157
00158
00159
00160 _MEDgetComputationStepName(MED_SORT_DTIT,numdt,numit,_datagroupname1);
00161
00162 _datagroup1 = 0;
00163 if ( (_datagroup1 = _MEDdatagroupOuvrir(_gid,_datagroupname1)) < 0 ) {
00164 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_FIELD_MSG);
00165 SSCRUTE(fieldname);SSCRUTE(_datagroupname1);goto ERROR;
00166 }
00167
00168
00169
00170
00171
00172
00173 if (_MEDgetEntityTypeName(_datagroupname2,entitytype) < 0) {
00174 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ENTITY,MED_ERR_VALUE_MSG);
00175 ISCRUTE_int(entitytype);SSCRUTE(fieldname);goto ERROR;
00176 }
00177
00178 if ( entitytype != MED_NODE ) {
00179
00180 if ( entitytype == MED_STRUCT_ELEMENT ) {
00181 if ( MEDstructElementName(fid, geotype,_geotypename) < 0 ) {
00182 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDstructElementName");
00183 ISCRUTE_int(geotype);goto ERROR;
00184 }
00185 } else {
00186 if ( _MEDgetInternalGeometryTypeName(_geotypename,geotype) < 0) {
00187 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_GEOMETRIC,MED_ERR_VALUE_MSG);
00188 ISCRUTE_int(geotype);SSCRUTE(fieldname);goto ERROR;
00189 }
00190 }
00191 strcat(_datagroupname2,".");
00192 strcat(_datagroupname2,_geotypename);
00193 }
00194 _datagroup2 = 0;
00195 if ( (_datagroup2 = _MEDdatagroupOuvrir(_datagroup1,_datagroupname2)) < 0) {
00196 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_datagroupname2);
00197 SSCRUTE(fieldname);goto ERROR;
00198 }
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 NOFINALBLANK(profilename,ERROR);
00211
00212 if ( strlen((*_filter).profilename) == 0 ) {
00213
00214
00215 strncpy(_profilename,MED_NO_PROFILE_INTERNAL,MED_NAME_SIZE+1);
00216 _profilearraysize = MED_UNDEF_SIZE;
00217 } else {
00218 strncpy(_profilename,(*_filter).profilename,MED_NAME_SIZE+1);
00219 _profilename[MED_NAME_SIZE]='\0';
00220 if ( ( _profilearraysize = MEDprofileSizeByName( fid,_profilename) ) < 0 ) {
00221 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,MED_ERR_FIELD_MSG);
00222 SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);
00223 SSCRUTE(_profilename);SSCRUTE("MEDprofileSizeByName");goto ERROR;
00224 }
00225 }
00226
00227
00228 if (!_filterparameterexist) (*_filter).profilearraysize = _profilearraysize;
00229
00230
00231 _datagroup3 = 0;
00232 if ((_datagroup3 = _MEDdatagroupOuvrir(_datagroup2,_profilename)) < 0) {
00233 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_profilename);
00234 SSCRUTE(fieldname);SSCRUTE(_profilename);goto ERROR;
00235 }
00236
00237
00238
00239 if ( _MEDattrEntierLire(_datagroup3,MED_NOM_NBR,&((*_filter).nbofentity)) < 0) {
00240 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
00241 SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
00242 SSCRUTE(MED_NOM_NBR);ISCRUTE((*_filter).nbofentity);goto ERROR;
00243 }
00244
00245
00246 if ( _MEDattrStringLire(_datagroup3,MED_NOM_GAU,MED_NAME_SIZE,_localizationname) < 0) {
00247 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
00248 SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
00249 SSCRUTE(MED_NOM_GAU);SSCRUTE(_localizationname);goto ERROR;
00250 }
00251
00252
00253
00254
00255 if ( _MEDattrEntierLire(_datagroup3,MED_NOM_NGA,&_nbofvaluesperentity) < 0) {
00256 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
00257 SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
00258 SSCRUTE(MED_NOM_NGA);ISCRUTE(_nbofvaluesperentity);goto ERROR;
00259 }
00260
00261
00262 if (entitytype == MED_NODE_ELEMENT ) {
00263 if (strlen(_localizationname) ) {
00264 MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_PARAMETER,_localizationname);
00265 SSCRUTE(MED_NO_LOCALIZATION);ISCRUTE_int(entitytype);goto ERROR;
00266 }
00267 _nbofvaluesperentityfromloc = geotype % 100;
00268 } else if (! strcmp(_localizationname,MED_GAUSS_ELNO)) {
00269
00270
00271 _nbofvaluesperentityfromloc = geotype % 100;
00272 } else if ( strlen( _localizationname) ) {
00273 strcpy(_locgidname,MED_GAUSS);
00274 strcat(_locgidname,_localizationname);
00275
00276 if ((_locgid = _MEDdatagroupOuvrir(fid,_locgidname)) < 0) {
00277 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_locgidname);
00278 goto ERROR;
00279 }
00280
00281 if (_MEDattrEntierLire(_locgid,MED_NOM_NBR,&_nbofvaluesperentityfromloc) < 0) {
00282 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
00283 SSCRUTE(_localizationname);SSCRUTE(MED_NOM_NBR);ISCRUTE(_nbofvaluesperentity);goto ERROR;
00284 }
00285
00286
00287 if ( entitytype == MED_STRUCT_ELEMENT ) {
00288
00289
00290
00291
00292 if ( _MEDattrStringLire(_locgid,MED_NOM_NOM,MED_NAME_SIZE,_sectionmeshname) < 0) {
00293 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_locgidname);
00294 SSCRUTE(MED_NOM_NOM);SSCRUTE(_sectionmeshname);
00295 goto ERROR;
00296 }
00297
00298 if (strlen(_sectionmeshname) ) {
00299
00300 if ( (_nbofsectiongeotype = MEDmeshnEntity(fid,_sectionmeshname,MED_NO_DT,MED_NO_IT,
00301 MED_CELL,MED_ALL_GEOTYPE,MED_CONNECTIVITY,MED_NODAL,
00302 &_chgt,&_trsf) ) < 0) {
00303 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
00304 ISCRUTE(_nbofsectiongeotype);goto ERROR;
00305 }
00306
00307 if ( (_nbofsectiongeotype != 1 ) ) {
00308 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_RANGE,""); ISCRUTE(_nbofsectiongeotype); goto ERROR;
00309 }
00310
00311
00312 if ( MEDmeshEntityInfo( fid,_sectionmeshname,MED_NO_DT,MED_NO_IT,
00313 MED_CELL, 1, _sectiongeotypename,
00314 &_sectiongeotype ) < 0 ) {
00315 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshEntityInfo");
00316 SSCRUTE(_sectiongeotypename);ISCRUTE_int(_sectiongeotype);goto ERROR;
00317 }
00318
00319 if ( (_nbofsectioncell = MEDmeshnEntity(fid,_sectionmeshname,MED_NO_DT,MED_NO_IT,
00320 MED_CELL,_sectiongeotype,MED_CONNECTIVITY,MED_NODAL,
00321 &_chgt,&_trsf) ) < 0) {
00322 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
00323 ISCRUTE(_nbofsectioncell);goto ERROR;
00324 }
00325 }
00326 }
00327
00328 _nbofvaluesperentityfromloc*=_nbofsectioncell;
00329
00330
00331 if (_MEDattrEntierLire(_locgid,MED_NOM_GEO,&_intlocgeotype) < 0) {
00332 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
00333 SSCRUTE(_localizationname);SSCRUTE(MED_NOM_GEO);ISCRUTE_int(_locgeotype);goto ERROR;
00334 }
00335 _locgeotype = (med_geometry_type) _intlocgeotype;
00336
00337 if ( _locgeotype != geotype ) {
00338 MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
00339 SSCRUTE(_localizationname);SSCRUTE(MED_NOM_GEO);ISCRUTE_int(_locgeotype);ISCRUTE_int(geotype);goto ERROR;
00340 }
00341 } else {
00342 _nbofvaluesperentityfromloc = 1;
00343 }
00344
00345 if ( _nbofvaluesperentityfromloc != _nbofvaluesperentity ) {
00346 MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
00347 SSCRUTE(_localizationname);SSCRUTE(MED_NOM_GEO);ISCRUTE(_nbofvaluesperentityfromloc);
00348 ISCRUTE(_nbofvaluesperentity);goto ERROR;
00349 }
00350
00351 if (!_filterparameterexist) (*_filter).nbofvaluesperentity=_nbofvaluesperentity;
00352
00353
00354
00355
00356
00357
00358
00359
00360 if (!_filterparameterexist) {
00361
00362 if ( MEDfilterEntityCr(fid, (*_filter).nbofentity, (*_filter).nbofvaluesperentity,
00363 (*_filter).nbofconstituentpervalue, (*_filter).constituentselect,
00364 (*_filter).switchmode, (*_filter).storagemode,
00365 (*_filter).profilename, MED_UNDEF_SIZE, NULL, &_paramfilter) < 0 ) {
00366 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
00367 goto ERROR;
00368 }
00369
00370
00371 _filter = &_paramfilter;
00372 }
00373
00374 #ifdef _DEBUG_
00375 ISCRUTE((*_filter).nbofentity );
00376 ISCRUTE((*_filter).nbofvaluesperentity );
00377 ISCRUTE((*_filter).nbofconstituentpervalue );
00378 ISCRUTE((*_filter).constituentselect );
00379 ISCRUTE_int((*_filter).switchmode );
00380 ISCRUTE((*_filter).filterarraysize );
00381 ISCRUTE((*_filter).profilearraysize );
00382 ISCRUTE_int((*_filter).storagemode );
00383 SSCRUTE((*_filter).profilename );
00384 #endif
00385
00386
00387
00388
00389
00390 switch(_fieldtype)
00391 {
00392 case MED_FLOAT64 :
00393 if ( _MEDdatasetRd(_datagroup3,MED_NOM_CO,MED_FLOAT64,_filter,value) < 0) {
00394 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_DATASET,MED_NOM_CO);
00395 SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
00396
00397
00398 goto ERROR;
00399 }
00400 break;
00401
00402 case MED_INT32 :
00403 #if defined(HAVE_F77INT64)
00404 if ( _MEDdatasetRd(_datagroup3,MED_NOM_CO,MED_INT64,_filter,value) < 0) {
00405 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_DATASET,MED_NOM_CO);
00406 SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
00407 goto ERROR;
00408 }
00409 #else
00410 if ( _MEDdatasetRd(_datagroup3,MED_NOM_CO,MED_INT32,_filter,value) < 0) {
00411 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_DATASET,MED_NOM_CO);
00412 SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
00413 goto ERROR;
00414 }
00415 #endif
00416 break;
00417
00418 case MED_INT64 :
00419 #if defined(HAVE_F77INT64)
00420 if ( _MEDdatasetRd(_datagroup3,MED_NOM_CO,MED_INT64,_filter,value) < 0) {
00421 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_DATASET,MED_NOM_CO);
00422 SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
00423 goto ERROR;
00424 }
00425
00426 #else
00427 MESSAGE("Impossible de lire le dataset de type MED_INT64 sur une plateforme dépourvue de int64 !");
00428 goto ERROR;
00429 #endif
00430 break;
00431
00432 default :
00433 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_RANGE,MED_ERR_FIELD_MSG);
00434 SSCRUTE(fieldname);ISCRUTE_int(_fieldtype);
00435 goto ERROR;
00436 }
00437
00438
00439
00440
00441
00442
00443 _ret = 0;
00444
00445 ERROR:
00446
00447
00448 if (!_filterparameterexist) {
00449 if ( MEDfilterClose(_filter) < 0 ) {
00450 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_FIELD_MSG);
00451 SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(_datagroupname2);SSCRUTE(_profilename);
00452 goto ERROR;
00453 }
00454 }
00455
00456 if (_datagroup3>0) if (_MEDdatagroupFermer(_datagroup3) < 0) {
00457 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_profilename);
00458 ISCRUTE_id(_datagroup3);
00459 }
00460
00461 if (_datagroup2>0) if (_MEDdatagroupFermer(_datagroup2) < 0) {
00462 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname2);
00463 ISCRUTE_id(_datagroup2);
00464 }
00465
00466 if (_datagroup1>0) if (_MEDdatagroupFermer(_datagroup1) < 0) {
00467 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname1);
00468 ISCRUTE_id(_datagroup1);
00469 }
00470
00471 if (_gid>0) if (_MEDdatagroupFermer(_gid) < 0) {
00472 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_gidname);
00473 ISCRUTE_id(_gid);
00474 }
00475
00476 if (_locgid>0) if (_MEDdatagroupFermer(_locgid) < 0) {
00477 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_locgidname);
00478 ISCRUTE_id(_locgid);
00479 }
00480
00481 va_end(params);
00482 *fret = _ret;
00483 return;
00484 }
00485
00486
00487
00488