00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 #include <med.h>
00019 #define MESGERR 1
00020 #include <med_utils.h>
00021 
00022 #include <string.h>
00023 
00024 #include <med.h>
00025 #define MESGERR 1
00026 #include <med_utils.h>
00027 
00028 #include <string.h>
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 int main (int argc, char **argv) {
00037   med_idt fid,mfid,sfid;
00038   med_idt nfield, i, j;
00039   char meshname[MED_NAME_SIZE+1]="";
00040   med_bool localmesh;
00041   char fieldname[MED_NAME_SIZE+1]="";
00042   med_field_type fieldtype;
00043   char *componentname = NULL;
00044   char *componentunit = NULL;
00045   char dtunit[MED_SNAME_SIZE+1]="";
00046   med_float *values = NULL;
00047   med_int nstep, nvalues;
00048   med_int ncomponent;
00049   med_int csit, numit, numdt, it;
00050   med_float dt;
00051   med_geometry_type *geotypes, geotype;
00052   med_int nmodels;
00053   med_int nprofile, pit, profilesize;
00054   char profilename[MED_NAME_SIZE+1]="";
00055   med_int nintegrationpoint;
00056   char localizationname[MED_NAME_SIZE+1]="";
00057   int k;
00058   char elementname[MED_NAME_SIZE+1];
00059   char supportmeshname[MED_NAME_SIZE+1];
00060   med_entity_type entitype;
00061   med_int elementdim;
00062   med_int nnode,ncell;
00063   med_geometry_type geocelltype;
00064   med_bool anyprofile=0;
00065   med_int nconstatt, *nvaratt;
00066   int ret=-1;
00067 
00068   
00069   fid = MEDfileOpen("UsesCase_MEDfield_15.med",MED_ACC_RDWR);
00070   if (fid < 0) {
00071     MESSAGE("ERROR : open file ...");
00072     goto ERROR;
00073   }
00074 
00075   if (( mfid=MEDfileObjectsMount(fid,  "UsesCase_MEDstructElement_1.med",MED_MESH_SUPPORT)) < 0 ) {
00076     MESSAGE("ERROR : file mounting ...");
00077     goto ERROR;
00078   }
00079 
00080   if (( sfid=MEDfileObjectsMount(fid,  "UsesCase_MEDstructElement_1.med",MED_ELSTRUCT)) < 0 ) {
00081     MESSAGE("ERROR : file mounting ...");
00082     goto ERROR;
00083   }
00084 
00085   
00086   if ((nmodels =  MEDnStructElement(mfid)) < 0) {
00087     MESSAGE("ERROR : read number of struct element models ...");
00088     goto ERROR;
00089   }
00090   geotypes = (med_geometry_type *) malloc(sizeof(med_geometry_type)*nmodels);
00091   nvaratt = (med_int *) malloc(sizeof(med_int)*nmodels);
00092 
00093   for (it=0; it<nmodels; it++) {
00094     if (MEDstructElementInfo(mfid, it+1, elementname, geotypes+it, &elementdim,
00095                              supportmeshname, &entitype, &nnode, &ncell,
00096                              &geocelltype, &nconstatt, &anyprofile, nvaratt+it) < 0) {
00097       MESSAGE("ERROR : struct element models information ...");
00098       free(nvaratt);
00099       goto ERROR;
00100     }
00101   }
00102   free(nvaratt);
00103 
00104 
00105   
00106 
00107 
00108 
00109   if ((nfield = MEDnField(fid)) < 0) {
00110     MESSAGE("ERROR : How many fields in the file ...");
00111     goto ERROR;
00112   }
00113 
00114   
00115 
00116 
00117   for (i=0; i<nfield; i++) {
00118 
00119     if ((ncomponent = MEDfieldnComponent(fid,i+1)) < 0) {
00120       MESSAGE("ERROR : number of field component ...");
00121       goto ERROR;
00122     }
00123     
00124     if ((componentname = (char *) malloc(ncomponent*MED_SNAME_SIZE+1)) == NULL) {
00125       MESSAGE("ERROR : memory allocation ...");
00126       goto ERROR;
00127     }
00128 
00129     if ((componentunit = (char *) malloc(ncomponent*MED_SNAME_SIZE+1)) == NULL) {
00130       MESSAGE("ERROR : memory allocation ...");
00131       goto ERROR;
00132     }
00133 
00134     if (MEDfieldInfo(fid, i+1, fieldname, meshname, &localmesh, &fieldtype,
00135                      componentname, componentunit, dtunit, &nstep) < 0) {
00136       MESSAGE("ERROR : Field info ...");
00137       free(componentname);
00138       free(componentunit);
00139       goto ERROR;
00140     }
00141 
00142     free(componentname);
00143     free(componentunit);
00144 
00145     
00146 
00147  
00148     for (csit=0; csit<nstep; csit++) {
00149 
00150       if (MEDfieldComputingStepInfo(fid, fieldname, csit+1, &numdt, &numit, &dt) < 0) {
00151         MESSAGE("ERROR : Computing step info ...");
00152         goto ERROR;
00153       }
00154 
00155       
00156 
00157 
00158       for (it=0; it<nmodels; it++) {
00159 
00160         geotype = *(geotypes+it);
00161      
00162         
00163 
00164 
00165         if ((nprofile = MEDfieldnProfile(fid, fieldname, numdt, numit, MED_STRUCT_ELEMENT, geotype,
00166                                          profilename, localizationname)) < 0) {
00167           MESSAGE("ERROR : read number of profile ");
00168           goto ERROR;
00169         }
00170         
00171         
00172 
00173 
00174         for (pit=0; pit<nprofile; pit++) {
00175           
00176           if ((nvalues = MEDfieldnValueWithProfile(fid, fieldname, numdt, numit, MED_STRUCT_ELEMENT, geotype,
00177                                                    pit+1, MED_COMPACT_PFLMODE, profilename, &profilesize,
00178                                                    localizationname, &nintegrationpoint)) < 0) {
00179             MESSAGE("ERROR : read number of values with a profile ...");
00180             goto ERROR;
00181           } 
00182           
00183           if (nvalues) {
00184             if ((values = (med_float *) malloc(sizeof(med_float)*nvalues*ncomponent*nintegrationpoint)) == NULL) {
00185               MESSAGE("ERROR : memory allocation ...");
00186               goto ERROR;
00187             }
00188             if (MEDfieldValueWithProfileRd(fid, fieldname, numdt, numit, MED_STRUCT_ELEMENT, geotype,
00189                                            MED_COMPACT_PFLMODE, profilename,
00190                                            MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, 
00191                                            (unsigned char*) values) < 0) {
00192               MESSAGE("ERROR : read fields values for cells ..."); 
00193               goto ERROR; 
00194               free(values);
00195             }  
00196             free(values);
00197           }
00198         }
00199       }
00200     }
00201   }
00202   
00203   ret=0;
00204  ERROR :
00205 
00206   free(geotypes);
00207 
00208   if ( MEDfileObjectsUnmount(fid, sfid, MED_ELSTRUCT) < 0 ) {
00209     MESSAGE("ERROR : file unmounting ...");
00210     ret=-1;
00211   }
00212 
00213   if ( MEDfileObjectsUnmount(fid, mfid, MED_MESH_SUPPORT) < 0 ) {
00214     MESSAGE("ERROR : file unmounting ...");
00215     ret= -1;
00216   }
00217 
00218   
00219   if (MEDfileClose(fid) < 0) {
00220     MESSAGE("ERROR : close file ...");             
00221     ret= -1; 
00222   } 
00223   
00224   return ret;
00225 }