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 int main (int argc, char **argv) {
00036 med_idt fid;
00037 med_idt nfield, i, j;
00038 char meshname[MED_NAME_SIZE+1]="";
00039 med_bool localmesh;
00040 char fieldname[MED_NAME_SIZE+1]="";
00041 med_field_type fieldtype;
00042 char *componentname = NULL;
00043 char *componentunit = NULL;
00044 char dtunit[MED_SNAME_SIZE+1]="";
00045 med_float *values = NULL;
00046 med_int nstep, nvalues;
00047 med_int ncomponent;
00048 med_int csit, numit, numdt, it;
00049 med_float dt;
00050 med_geometry_type geotype;
00051 med_geometry_type *geotypes = MED_GET_CELL_GEOMETRY_TYPE;
00052 med_int nprofile, pit, profilesize;
00053 char profilename[MED_NAME_SIZE+1]="";
00054 med_int nintegrationpoint;
00055 char localizationname[MED_NAME_SIZE+1]="";
00056 int ret=-1;
00057
00058
00059 fid = MEDfileOpen("UsesCase_MEDfield_7.med",MED_ACC_RDONLY);
00060 if (fid < 0) {
00061 MESSAGE("ERROR : open file ...");
00062 return -1;
00063 }
00064
00065
00066
00067
00068
00069 if ((nfield = MEDnField(fid)) < 0) {
00070 MESSAGE("ERROR : How many fields in the file ...");
00071 return -1;
00072 }
00073
00074
00075
00076
00077 for (i=0; i<nfield; i++) {
00078
00079 if ((ncomponent = MEDfieldnComponent(fid,i+1)) < 0) {
00080 MESSAGE("ERROR : number of field component ...");
00081 return -1;
00082 }
00083
00084 if ((componentname = (char *) malloc(ncomponent*MED_SNAME_SIZE+1)) == NULL) {
00085 MESSAGE("ERROR : memory allocation ...");
00086 return -1;
00087 }
00088
00089 if ((componentunit = (char *) malloc(ncomponent*MED_SNAME_SIZE+1)) == NULL) {
00090 MESSAGE("ERROR : memory allocation ...");
00091 return -1;
00092 }
00093
00094 if (MEDfieldInfo(fid, i+1, fieldname, meshname, &localmesh, &fieldtype,
00095 componentname, componentunit, dtunit, &nstep) < 0) {
00096 MESSAGE("ERROR : Field info ...");
00097 free(componentname);
00098 free(componentunit);
00099 return -1;
00100 }
00101
00102 free(componentname);
00103 free(componentunit);
00104
00105
00106
00107
00108 for (csit=0; csit<nstep; csit++) {
00109
00110 if (MEDfieldComputingStepInfo(fid, fieldname, csit+1, &numdt, &numit, &dt) < 0) {
00111 MESSAGE("ERROR : Computing step info ...");
00112 return -1;
00113 }
00114
00115
00116
00117
00118 for (it=1; it<=MED_N_CELL_FIXED_GEO; it++) {
00119
00120 geotype = geotypes[it];
00121
00122
00123
00124 if ((nprofile = MEDfieldnProfile(fid, fieldname, numdt, numit, MED_CELL, geotype,
00125 profilename, localizationname)) < 0) {
00126 MESSAGE("ERROR : read number of profile ");
00127 return -1;
00128 }
00129
00130
00131
00132
00133
00134 for (pit=0; pit<nprofile; pit++) {
00135
00136 if ((nvalues = MEDfieldnValueWithProfile(fid, fieldname, numdt, numit, MED_CELL, geotype,
00137 pit+1, MED_COMPACT_PFLMODE, profilename, &profilesize,
00138 localizationname, &nintegrationpoint)) < 0) {
00139 MESSAGE("ERROR : read number of values with a profile ...");
00140 return -1;
00141 }
00142
00143 if (nvalues) {
00144 if ((values = (med_float *) malloc(sizeof(med_float)*nvalues*ncomponent)) == NULL) {
00145 MESSAGE("ERROR : memory allocation ...");
00146 return -1;
00147 }
00148 if (MEDfieldValueWithProfileRd(fid, fieldname, numdt, numit, MED_CELL, geotype,
00149 MED_COMPACT_PFLMODE, profilename,
00150 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, (unsigned char*)values) < 0) {
00151 MESSAGE("ERROR : read fields values for cells ...");
00152 free(values);
00153 return -1;
00154 }
00155
00156 free(values);
00157 }
00158 }
00159 }
00160 }
00161 }
00162
00163 ret=0;
00164 ERROR:
00165
00166
00167 if (MEDfileClose(fid) < 0) {
00168 MESSAGE("ERROR : close file ...");
00169 ret=-1;
00170 }
00171
00172 return ret;
00173 }