UsesCase_MEDfield_6.c
Aller à la documentation de ce fichier.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 #include <med.h>
00023 #define MESGERR 1
00024 #include <med_utils.h>
00025 
00026 #include <string.h>
00027 
00028 #include <med.h>
00029 #define MESGERR 1
00030 #include <med_utils.h>
00031 
00032 #include <string.h>
00033 
00034 int main (int argc, char **argv) {
00035   med_idt fid;
00036   med_idt nfield, i, j;
00037   char meshname[MED_NAME_SIZE+1]="";
00038   med_bool localmesh;
00039   char fieldname[MED_NAME_SIZE+1]="";
00040   med_field_type fieldtype;
00041   char *componentname = NULL;
00042   char *componentunit = NULL;
00043   char dtunit[MED_SNAME_SIZE+1]="";
00044   med_float *values = NULL;
00045   med_int nstep, nvalues;
00046   med_int ncomponent;
00047   med_int csit, numit, numdt, meshnumit, meshnumdt, it;
00048   med_float dt;
00049   med_geometry_type geotype;
00050   med_geometry_type *geotypes = MED_GET_CELL_GEOMETRY_TYPE;
00051   int k;
00052   int ret=-1;
00053 
00054   
00055   fid = MEDfileOpen("UsesCase_MEDfield_4.med",MED_ACC_RDONLY);
00056   if (fid < 0) {
00057     MESSAGE("ERROR : open file ...");
00058     goto ERROR;
00059   }
00060 
00061   
00062 
00063 
00064 
00065   if ((nfield = MEDnField(fid)) < 0) {
00066     MESSAGE("ERROR : How many fields in the file ...");
00067     goto ERROR;
00068   }
00069 
00070   
00071 
00072 
00073   for (i=0; i<nfield; i++) {
00074 
00075     if ((ncomponent = MEDfieldnComponent(fid,i+1)) < 0) {
00076       MESSAGE("ERROR : number of field component ...");
00077       goto ERROR;
00078     }
00079 
00080     if ((componentname = (char *) malloc(ncomponent*MED_SNAME_SIZE+1)) == NULL) {
00081       MESSAGE("ERROR : memory allocation ...");
00082       goto ERROR;
00083     }
00084 
00085     if ((componentunit = (char *) malloc(ncomponent*MED_SNAME_SIZE+1)) == NULL) {
00086       MESSAGE("ERROR : memory allocation ...");
00087       goto ERROR;
00088     }    
00089 
00090     if (MEDfieldInfo(fid, i+1, fieldname, meshname, &localmesh, &fieldtype,
00091                      componentname, componentunit, dtunit, &nstep) < 0) {
00092       MESSAGE("ERROR : Field info ...");
00093       free(componentname);
00094       free(componentunit);
00095       goto ERROR;
00096     }
00097     free(componentname);
00098     free(componentunit);
00099 
00100     
00101 
00102  
00103     for (csit=0; csit<nstep; csit++) {
00104 
00105       if (MEDfieldComputingStepMeshInfo(fid, fieldname, csit+1, &numdt, &numit, &dt, 
00106                                         &meshnumdt, &meshnumit) < 0) {
00107         MESSAGE("ERROR : Computing step info ...");
00108         goto ERROR;
00109       }
00110 
00111       
00112 
00113 
00114       for (it=1; it<=MED_N_CELL_FIXED_GEO; it++) {
00115 
00116         geotype = geotypes[it];
00117         if ((nvalues = MEDfieldnValue(fid, fieldname, numdt, numit, MED_CELL, geotype)) < 0) {
00118           MESSAGE("ERROR : read number of values ...");
00119           goto ERROR;
00120         } 
00121         if (nvalues) {
00122           if ((values = (med_float *) malloc(sizeof(med_float)*nvalues*ncomponent)) == NULL) {
00123             MESSAGE("ERROR : memory allocation ...");
00124           goto ERROR;
00125           }
00126           if (MEDfieldValueRd(fid, fieldname, numdt, numit, MED_CELL, geotype,
00127                               MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, (unsigned char*) values) < 0) {
00128             MESSAGE("ERROR : read fields values for cells ..."); 
00129             free(values);
00130             goto ERROR; 
00131           } 
00132           free(values);
00133         }
00134 
00135       }
00136     }
00137   }
00138 
00139   ret=0;
00140  ERROR:
00141   
00142   
00143   if (MEDfileClose(fid) < 0) {
00144     MESSAGE("ERROR : close file ...");             
00145     ret=-1; 
00146   } 
00147   
00148   return ret;
00149 }