UsesCase_MEDfield_5.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 int main (int argc, char **argv) {
00029 med_idt fid;
00030 char meshname[MED_NAME_SIZE+1]="";
00031 med_bool localmesh;
00032 const char fieldname[MED_NAME_SIZE+1] = "TEMPERATURE_FIELD";
00033 med_field_type fieldtype;
00034 char componentname[MED_SNAME_SIZE+1]="";
00035 char componentunit[MED_SNAME_SIZE+1]="";
00036 char dtunit[MED_SNAME_SIZE+1]="";
00037 med_float *values = NULL;
00038 med_int nstep, nvalues;
00039 med_int ncomponent = 1;
00040 med_int csit, numit, numdt, meshnumit, meshnumdt, it;
00041 med_float dt;
00042 med_geometry_type geotype;
00043 med_geometry_type *geotypes = MED_GET_CELL_GEOMETRY_TYPE;
00044 int ret=-1;
00045
00046
00047 fid = MEDfileOpen("UsesCase_MEDfield_4.med",MED_ACC_RDONLY);
00048 if (fid < 0) {
00049 MESSAGE("ERROR : open file ...");
00050 goto ERROR;
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 if (MEDfieldInfoByName(fid, fieldname, meshname, &localmesh, &fieldtype,
00062 componentname, componentunit, dtunit, &nstep) < 0) {
00063 MESSAGE("ERROR : Field info by name ...");
00064 goto ERROR;
00065 }
00066
00067
00068
00069
00070 for (csit=0; csit<nstep; csit++) {
00071
00072 if (MEDfieldComputingStepMeshInfo(fid, fieldname, csit+1, &numdt, &numit, &dt,
00073 &meshnumdt, &meshnumit) < 0) {
00074 MESSAGE("ERROR : Computing step info ...");
00075 goto ERROR;
00076 }
00077
00078
00079
00080
00081 for (it=1; it<=MED_N_CELL_FIXED_GEO; it++) {
00082
00083 geotype = geotypes[it];
00084
00085 if ((nvalues = MEDfieldnValue(fid, fieldname, numdt, numit, MED_CELL, geotype)) < 0) {
00086 MESSAGE("ERROR : read number of values ...");
00087 goto ERROR;
00088 }
00089
00090 if (nvalues) {
00091 if ((values = (med_float *) malloc(sizeof(med_float)*nvalues*ncomponent)) == NULL) {
00092 MESSAGE("ERROR : memory allocation ...");
00093 goto ERROR;
00094 }
00095 if (MEDfieldValueRd(fid, fieldname, numdt, numit, MED_CELL, geotype,
00096 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, (unsigned char*) values) < 0) {
00097 MESSAGE("ERROR : read fields values for cells ...");
00098 free(values);
00099 goto ERROR;
00100 }
00101 free(values);
00102 }
00103 }
00104 }
00105
00106 ret=0;
00107 ERROR:
00108
00109
00110 if (MEDfileClose(fid) < 0) {
00111 MESSAGE("ERROR : close file ...");
00112 ret=-1;
00113 }
00114
00115 return ret;
00116 }