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   med_int nmesh;
00032   char meshname[MED_NAME_SIZE+1]="";
00033   char meshdescription[MED_COMMENT_SIZE+1]="";
00034   med_int meshdim;
00035   med_int spacedim;
00036   med_sorting_type sortingtype;
00037   med_int nstep;
00038   med_mesh_type meshtype;
00039   med_axis_type axistype;
00040   char *axisname;
00041   char *unitname;
00042   char dtunit[MED_SNAME_SIZE+1]="";
00043   med_float *coordinates = NULL;
00044   med_int ngeo = 0;
00045   med_int nnodes = 0;
00046   med_int *connectivity = NULL;
00047   med_bool coordinatechangement;
00048   med_bool geotransformation;
00049   int i, it, j;
00050   med_int profilesize;
00051   char profilename[MED_NAME_SIZE+1]="";
00052   med_int numdt, numit;
00053   med_float dt;
00054   med_geometry_type geotype;
00055   med_geometry_type *geotypes = MED_GET_CELL_GEOMETRY_TYPE;
00056   int ret=-1;
00057 
00058   
00059   fid = MEDfileOpen("UsesCase_MEDmesh_6.med",MED_ACC_RDONLY);
00060   if (fid < 0) {
00061     MESSAGE("ERROR : open file in READ ONLY ACCESS mode ...");
00062     goto ERROR;
00063   }
00064 
00065 
00066   
00067   if ((nmesh = MEDnMesh(fid)) < 0) {
00068     MESSAGE("ERROR : read how many mesh ...");
00069     goto ERROR;
00070   }
00071 
00072   for (i=0;i<nmesh;i++) {
00073 
00074     
00075     if ((spacedim = MEDmeshnAxis(fid, i+1)) < 0) {
00076       MESSAGE("ERROR : read computation space dimension ...");
00077       goto ERROR;
00078     }
00079     
00080     
00081     if ((axisname  = (char*) malloc(MED_SNAME_SIZE*spacedim+1)) == NULL) {
00082       MESSAGE("ERROR : memory allocation ...");
00083       goto ERROR;
00084     }
00085     if ((unitname  = (char*) malloc(MED_SNAME_SIZE*spacedim+1)) == NULL) {
00086       MESSAGE("ERROR : memory allocation ...");
00087       goto ERROR;
00088     }
00089 
00090     
00091     if (MEDmeshInfo(fid, i+1, meshname, &spacedim, &meshdim, &meshtype, meshdescription, 
00092                     dtunit, &sortingtype, &nstep,  
00093                     &axistype, axisname, unitname) < 0) {
00094       MESSAGE("ERROR : mesh info ...")
00095         free(axisname);
00096       free(unitname);
00097       goto ERROR;
00098     }
00099     free(axisname);
00100     free(unitname);
00101 
00102 
00103     
00104     if ((nnodes = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NONE,
00105                                  MED_COORDINATE, MED_NO_CMODE,&coordinatechangement,
00106                                  &geotransformation)) < 0) {
00107       MESSAGE("ERROR : number of nodes ...");
00108       goto ERROR;
00109     }
00110   
00111     
00112     if ((coordinates = (med_float*) malloc(sizeof(med_float)*nnodes*spacedim)) == NULL) {
00113       MESSAGE("ERROR : memory allocation ...");
00114       goto ERROR;
00115     }
00116     
00117     if (MEDmeshNodeCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE,
00118                                 coordinates) < 0) {
00119       MESSAGE("ERROR : nodes coordinates ...");
00120       free(coordinates);
00121       goto ERROR;
00122     }
00123     
00124 
00125     
00126     for (it=1; it<=MED_N_CELL_FIXED_GEO; it++) {   
00127 
00128       geotype = geotypes[it];   
00129 
00130       if ((ngeo = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,geotype,
00131                                  MED_CONNECTIVITY, MED_NODAL, &coordinatechangement,
00132                                  &geotransformation)) < 0) {
00133         MESSAGE("ERROR : number of cell ...");
00134         ISCRUTE(geotype);
00135         goto ERROR;
00136       }
00137     
00138       if (ngeo) {
00139         
00140         if ((connectivity = (med_int *) malloc(sizeof(med_int)*ngeo*(geotype%100))) == NULL) {
00141           MESSAGE("ERROR : memory allocation ...");
00142           goto ERROR;
00143         }
00144         
00145         if (MEDmeshElementConnectivityRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,
00146                                          geotype, MED_NODAL, MED_FULL_INTERLACE, connectivity) < 0) {
00147           MESSAGE("ERROR : cellconnectivity ...");
00148           ISCRUTE(geotype);
00149           free(connectivity);
00150           goto ERROR;
00151         }
00152 
00153         
00154         free(connectivity);
00155         connectivity = NULL;
00156       }
00157     }
00158     
00159 
00160     
00161     for (it=1;it<nstep;it++) {
00162       
00163       if (MEDmeshComputationStepInfo(fid, meshname, it+1, 
00164                                      &numdt, &numit, &dt) < 0) {
00165         MESSAGE("ERROR : Computing step info ...");
00166         SSCRUTE(meshname);
00167         goto ERROR;
00168       }
00169       
00170       
00171       if ((nnodes = MEDmeshnEntityWithProfile(fid, meshname, numdt, numit, 
00172                                               MED_NODE, MED_NONE,
00173                                               MED_COORDINATE, MED_NO_CMODE,
00174                                               MED_GLOBAL_PFLMODE, profilename, &profilesize,
00175                                               &coordinatechangement, &geotransformation)) < 0) {
00176         MESSAGE("ERROR : number of nodes ..."); 
00177         goto ERROR;
00178       }
00179       
00180       
00181       
00182       if (coordinatechangement && geotransformation) {
00183         if (MEDmeshNodeCoordinateWithProfileRd(fid, meshname, numdt, numit, 
00184                                                MED_GLOBAL_PFLMODE,profilename,
00185                                                MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,
00186                                                coordinates) < 0) {
00187           MESSAGE("ERROR : nodes coordinates ...");
00188           free(coordinates);
00189           goto ERROR;
00190         }
00191       }
00192       
00193     }
00194   }
00195 
00196   free(coordinates);
00197 
00198   ret=0;
00199  ERROR:
00200 
00201   
00202   if (MEDfileClose(fid) < 0) {
00203     MESSAGE("ERROR : close file");             
00204     ret=-1; 
00205   } 
00206 
00207   
00208   return ret;
00209 }
00210