00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <med.h>
00024 #define MESGERR 1
00025 #include <med_utils.h>
00026
00027 #include <string.h>
00028
00029 int main (int argc, char **argv) {
00030 med_idt fid;
00031 char meshname[MED_NAME_SIZE+1]="";
00032 med_bool localmesh;
00033 const char fieldname[MED_NAME_SIZE+1] = "TEMPERATURE_FIELD";
00034 med_field_type fieldtype;
00035 char componentname[MED_SNAME_SIZE+1]="";
00036 char componentunit[MED_SNAME_SIZE+1]="";
00037 char dtunit[MED_SNAME_SIZE+1]="";
00038 med_float *values = NULL;
00039 med_int nstep, nvalues;
00040 med_int ncomponent = 1;
00041 med_int csit, numit, numdt, it;
00042 med_float dt;
00043 med_geometry_type geotype;
00044 med_geometry_type *geotypes = MED_GET_CELL_GEOMETRY_TYPE;
00045 med_int nprofile, pit, profilesize;
00046 char profilename[MED_NAME_SIZE+1]="";
00047 med_int nintegrationpoint;
00048 char localizationname[MED_NAME_SIZE+1]="";
00049 med_int ninterp=0;
00050 char interpname[MED_NAME_SIZE+1]="";
00051 int ret=-1;
00052
00053
00054 fid = MEDfileOpen("UsesCase_MEDfield_10.med",MED_ACC_RDONLY);
00055 if (fid < 0) {
00056 MESSAGE("ERROR : open file ...");
00057 goto ERROR;
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 if (MEDfieldInfoByName(fid, fieldname, meshname, &localmesh, &fieldtype,
00069 componentname, componentunit, dtunit, &nstep) < 0) {
00070 MESSAGE("ERROR : Field info by name ...");
00071 goto ERROR;
00072 }
00073
00074
00075
00076
00077 if ((ninterp = MEDfieldnInterp(fid, fieldname)) < 0) {
00078 MESSAGE("ERROR : Read how many interpolation functions for the field ...");
00079 goto ERROR;
00080 }
00081
00082
00083
00084
00085 for (it=0; it<ninterp; it++) {
00086 if (MEDfieldInterpInfo(fid,fieldname,it+1,interpname) < 0) {
00087 MESSAGE("ERROR : read interpolation family name ...");
00088 goto ERROR;
00089 }
00090 }
00091
00092
00093
00094
00095 for (csit=0; csit<nstep; csit++) {
00096
00097 if (MEDfieldComputingStepInfo(fid, fieldname, csit+1, &numdt, &numit, &dt) < 0) {
00098 MESSAGE("ERROR : Computing step info ...");
00099 goto ERROR;
00100 }
00101
00102
00103
00104
00105 for (it=1; it<=MED_N_CELL_FIXED_GEO; it++) {
00106
00107 geotype = geotypes[it];
00108
00109
00110
00111 if ((nprofile = MEDfieldnProfile(fid, fieldname, numdt, numit, MED_CELL, geotype,
00112 profilename, localizationname)) < 0) {
00113 MESSAGE("ERROR : read number of profile ");
00114 goto ERROR;
00115 }
00116
00117
00118
00119
00120 for (pit=0; pit<nprofile; pit++) {
00121
00122 if ((nvalues = MEDfieldnValueWithProfile(fid, fieldname, numdt, numit, MED_CELL, geotype,
00123 pit+1, MED_COMPACT_PFLMODE, profilename, &profilesize,
00124 localizationname, &nintegrationpoint)) < 0) {
00125 MESSAGE("ERROR : read number of values with a profile ...");
00126 goto ERROR;
00127 }
00128
00129 if (nvalues) {
00130 if ((values = (med_float *) malloc(sizeof(med_float)*nvalues*ncomponent*nintegrationpoint)) == NULL) {
00131 MESSAGE("ERROR : memory allocation ...");
00132 goto ERROR;
00133 }
00134 if (MEDfieldValueWithProfileRd(fid, fieldname, numdt, numit, MED_CELL, geotype,
00135 MED_COMPACT_PFLMODE, profilename,
00136 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
00137 (unsigned char*) values) < 0) {
00138 MESSAGE("ERROR : read fields values for cells ...");
00139 free(values);
00140 goto ERROR;
00141 }
00142 free(values);
00143 }
00144 }
00145 }
00146 }
00147
00148 ret=0;
00149 ERROR:
00150
00151
00152 if (MEDfileClose(fid) < 0) {
00153 MESSAGE("ERROR : close file ...");
00154 ret=-1;
00155 }
00156
00157 return ret;
00158 }