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,cmfid;
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=NULL, 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=NULL;
00066   med_bool coordinatechangement;
00067   med_bool geotransformation;
00068   int ret=-1;
00069 
00070 
00071   
00072   fid = MEDfileOpen("UsesCase_MEDfield_17.med",MED_ACC_RDWR);
00073   if (fid < 0) {
00074     MESSAGE("ERROR : open file ...");
00075     return -1;
00076   }
00077 
00078   if (( mfid=MEDfileObjectsMount(fid,  "UsesCase_MEDstructElement_1.med",MED_MESH_SUPPORT)) < 0 ) {
00079     MESSAGE("ERROR : file mounting ...");
00080     return -1;
00081   }
00082 
00083   if (( sfid=MEDfileObjectsMount(fid,  "UsesCase_MEDstructElement_1.med",MED_ELSTRUCT)) < 0 ) {
00084     MESSAGE("ERROR : file mounting ...");
00085     return -1;
00086   }
00087 
00088   if (( cmfid=MEDfileObjectsMount(fid,  "UsesCase_MEDstructElement_1.med",MED_MESH)) < 0 ) {
00089     MESSAGE("ERROR : file mounting ...");
00090     return -1;
00091   }
00092 
00093 
00094   
00095 
00096 
00097 
00098   if ((nfield = MEDnField(fid)) < 0) {
00099     MESSAGE("ERROR : How many fields in the file ...");
00100     return -1;
00101   }
00102 
00103   
00104 
00105 
00106   for (i=0; i<nfield; i++) {
00107 
00108     if ((ncomponent = MEDfieldnComponent(fid,i+1)) < 0) {
00109       MESSAGE("ERROR : number of field component ...");
00110       return -1;
00111     }
00112     
00113     if ((componentname = (char *) malloc(ncomponent*MED_SNAME_SIZE+1)) == NULL) {
00114       MESSAGE("ERROR : memory allocation ...");
00115       return -1;
00116     }
00117 
00118     if ((componentunit = (char *) malloc(ncomponent*MED_SNAME_SIZE+1)) == NULL) {
00119       MESSAGE("ERROR : memory allocation ...");
00120       return -1;
00121     }
00122 
00123     if (MEDfieldInfo(fid, i+1, fieldname, meshname, &localmesh, &fieldtype,
00124                      componentname, componentunit, dtunit, &nstep) < 0) {
00125       MESSAGE("ERROR : Field info ...");
00126       free(componentname);
00127       free(componentunit);
00128       return -1;
00129     }
00130 
00131     free(componentname);
00132     free(componentunit);
00133 
00134     
00135     if ((nmodels = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_STRUCT_ELEMENT, MED_GEO_ALL,
00136                                   MED_UNDEF_DATATYPE, MED_NO_CMODE,&coordinatechangement,
00137                                   &geotransformation)) < 0) {
00138       MESSAGE("ERROR : number of nodes ...");
00139       return -1;
00140     }
00141     geotypes = (med_geometry_type *) malloc(sizeof(med_geometry_type)*nmodels);
00142     nvaratt = (med_int *) malloc(sizeof(med_int)*nmodels);
00143     
00144     for (it=0; it<nmodels; it++) {
00145       if (MEDstructElementInfo(mfid, it+1, elementname, geotypes+it, &elementdim,
00146                                supportmeshname, &entitype, &nnode, &ncell,
00147                                &geocelltype, &nconstatt, &anyprofile, nvaratt+it) < 0) {
00148         MESSAGE("ERROR : struct element models information ...");
00149         return -1;
00150       }
00151     }
00152 
00153 
00154     
00155 
00156  
00157     for (csit=0; csit<nstep; csit++) {
00158 
00159       if (MEDfieldComputingStepInfo(fid, fieldname, csit+1, &numdt, &numit, &dt) < 0) {
00160         MESSAGE("ERROR : Computing step info ...");
00161         return -1;
00162       }
00163 
00164       
00165 
00166 
00167       for (it=0; it<nmodels; it++) {
00168         geotype = *(geotypes+it);
00169         
00170         
00171 
00172 
00173         if ((nprofile = MEDfieldnProfile(fid, fieldname, numdt, numit, MED_STRUCT_ELEMENT, geotype,
00174                                          profilename, localizationname)) < 0) {
00175           MESSAGE("ERROR : read number of profile ");
00176           return -1;
00177         }
00178 
00179         
00180 
00181 
00182         for (pit=0; pit<nprofile; pit++) {
00183           
00184           if ((nvalues = MEDfieldnValueWithProfile(fid, fieldname, numdt, numit, MED_STRUCT_ELEMENT, geotype,
00185                                                    pit+1, MED_COMPACT_PFLMODE, profilename, &profilesize,
00186                                                    localizationname, &nintegrationpoint)) < 0) {
00187             MESSAGE("ERROR : read number of values with a profile ...");
00188             return -1;
00189           } 
00190           
00191           if (nvalues) {
00192             if ((values = (med_float *) malloc(sizeof(med_float)*nvalues*ncomponent*nintegrationpoint)) == NULL) {
00193               MESSAGE("ERROR : memory allocation ...");
00194               return -1;
00195             }
00196             if (MEDfieldValueWithProfileRd(fid, fieldname, numdt, numit, MED_STRUCT_ELEMENT, geotype,
00197                                            MED_COMPACT_PFLMODE, profilename,
00198                                            MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, 
00199                                            (unsigned char*) values) < 0) {
00200               MESSAGE("ERROR : read fields values for cells ..."); 
00201               free(values);
00202               return -1; 
00203             }  
00204             free(values);
00205           }
00206         }
00207       }
00208     }
00209 
00210     ret=0;
00211   ERROR:
00212     if (nvaratt)
00213       free(nvaratt);
00214     if (geotypes)
00215       free(geotypes);
00216 
00217   }
00218 
00219 
00220 
00221   if ( MEDfileObjectsUnmount(fid, mfid, MED_MESH_SUPPORT) < 0 ) {
00222     MESSAGE("ERROR : file unmounting ...");
00223     ret=-1;
00224   }
00225 
00226   if ( MEDfileObjectsUnmount(fid, sfid, MED_ELSTRUCT) < 0 ) {
00227     MESSAGE("ERROR : file unmounting ...");
00228     ret=-1;
00229   }
00230 
00231 
00232   if ( MEDfileObjectsUnmount(fid, cmfid, MED_MESH) < 0 ) {
00233     MESSAGE("ERROR : file unmounting ...");
00234     ret=-1;
00235   }
00236 
00237   
00238   if (MEDfileClose(fid) < 0) {
00239     MESSAGE("ERROR : close file ...");             
00240     ret=-1; 
00241   } 
00242   
00243   return ret;
00244 }