| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include <med.h> |
| 24 |
#define MESGERR 1 |
| 25 |
#include <med_utils.h> |
| 26 |
|
| 27 |
#include <string.h> |
| 28 |
|
| 29 |
int main (int argc, char **argv) { |
| 30 |
med_idt fid; |
| 31 |
med_int nmesh; |
| 32 |
char meshname[MED_NAME_SIZE+1]=""; |
| 33 |
char meshdescription[MED_COMMENT_SIZE+1]=""; |
| 34 |
med_int meshdim; |
| 35 |
med_int spacedim; |
| 36 |
med_sorting_type sortingtype; |
| 37 |
med_int nstep; |
| 38 |
med_mesh_type meshtype; |
| 39 |
med_axis_type axistype; |
| 40 |
char *axisname; |
| 41 |
char *unitname; |
| 42 |
char dtunit[MED_SNAME_SIZE+1]=""; |
| 43 |
med_float *coordinates = NULL; |
| 44 |
med_int ngeo = 0; |
| 45 |
med_int nnodes = 0; |
| 46 |
med_int *connectivity = NULL; |
| 47 |
med_bool coordinatechangement; |
| 48 |
med_bool geotransformation; |
| 49 |
int i, it, j; |
| 50 |
med_int profilesize; |
| 51 |
char profilename[MED_NAME_SIZE+1]=""; |
| 52 |
med_int numdt, numit; |
| 53 |
med_float dt; |
| 54 |
med_geometry_type geotype; |
| 55 |
med_geometry_type *geotypes = MED_GET_CELL_GEOMETRY_TYPE; |
| 56 |
int ret=-1; |
| 57 |
|
| 58 |
|
| 59 |
fid = MEDfileOpen("UsesCase_MEDmesh_6.med",MED_ACC_RDONLY); |
| 60 |
if (fid < 0) { |
| 61 |
MESSAGE("ERROR : open file in READ ONLY ACCESS mode ..."); |
| 62 |
goto ERROR; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
if ((nmesh = MEDnMesh(fid)) < 0) { |
| 68 |
MESSAGE("ERROR : read how many mesh ..."); |
| 69 |
goto ERROR; |
| 70 |
} |
| 71 |
|
| 72 |
for (i=0;i<nmesh;i++) { |
| 73 |
|
| 74 |
|
| 75 |
if ((spacedim = MEDmeshnAxis(fid, i+1)) < 0) { |
| 76 |
MESSAGE("ERROR : read computation space dimension ..."); |
| 77 |
goto ERROR; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
if ((axisname = (char*) malloc(MED_SNAME_SIZE*spacedim+1)) == NULL) { |
| 82 |
MESSAGE("ERROR : memory allocation ..."); |
| 83 |
goto ERROR; |
| 84 |
} |
| 85 |
if ((unitname = (char*) malloc(MED_SNAME_SIZE*spacedim+1)) == NULL) { |
| 86 |
MESSAGE("ERROR : memory allocation ..."); |
| 87 |
goto ERROR; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
if (MEDmeshInfo(fid, i+1, meshname, &spacedim, &meshdim, &meshtype, meshdescription, |
| 92 |
dtunit, &sortingtype, &nstep, |
| 93 |
&axistype, axisname, unitname) < 0) { |
| 94 |
MESSAGE("ERROR : mesh info ...") |
| 95 |
free(axisname); |
| 96 |
free(unitname); |
| 97 |
goto ERROR; |
| 98 |
} |
| 99 |
free(axisname); |
| 100 |
free(unitname); |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
if ((nnodes = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NONE, |
| 105 |
MED_COORDINATE, MED_NO_CMODE,&coordinatechangement, |
| 106 |
&geotransformation)) < 0) { |
| 107 |
MESSAGE("ERROR : number of nodes ..."); |
| 108 |
goto ERROR; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
if ((coordinates = (med_float*) malloc(sizeof(med_float)*nnodes*spacedim)) == NULL) { |
| 113 |
MESSAGE("ERROR : memory allocation ..."); |
| 114 |
goto ERROR; |
| 115 |
} |
| 116 |
|
| 117 |
if (MEDmeshNodeCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE, |
| 118 |
coordinates) < 0) { |
| 119 |
MESSAGE("ERROR : nodes coordinates ..."); |
| 120 |
free(coordinates); |
| 121 |
goto ERROR; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
for (it=1; it<=MED_N_CELL_FIXED_GEO; it++) { |
| 127 |
|
| 128 |
geotype = geotypes[it]; |
| 129 |
|
| 130 |
if ((ngeo = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,geotype, |
| 131 |
MED_CONNECTIVITY, MED_NODAL, &coordinatechangement, |
| 132 |
&geotransformation)) < 0) { |
| 133 |
MESSAGE("ERROR : number of cell ..."); |
| 134 |
ISCRUTE_int(geotype); |
| 135 |
goto ERROR; |
| 136 |
} |
| 137 |
|
| 138 |
if (ngeo) { |
| 139 |
|
| 140 |
if ((connectivity = (med_int *) malloc(sizeof(med_int)*ngeo*(geotype%100))) == NULL) { |
| 141 |
MESSAGE("ERROR : memory allocation ..."); |
| 142 |
goto ERROR; |
| 143 |
} |
| 144 |
|
| 145 |
if (MEDmeshElementConnectivityRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL, |
| 146 |
geotype, MED_NODAL, MED_FULL_INTERLACE, connectivity) < 0) { |
| 147 |
MESSAGE("ERROR : cell connectivity ..."); |
| 148 |
ISCRUTE_int(geotype); |
| 149 |
free(connectivity); |
| 150 |
goto ERROR; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
free(connectivity); |
| 155 |
connectivity = NULL; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
for (it=1;it<nstep;it++) { |
| 162 |
|
| 163 |
if (MEDmeshComputationStepInfo(fid, meshname, it+1, |
| 164 |
&numdt, &numit, &dt) < 0) { |
| 165 |
MESSAGE("ERROR : Computing step info ..."); |
| 166 |
SSCRUTE(meshname); |
| 167 |
goto ERROR; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
if ((nnodes = MEDmeshnEntityWithProfile(fid, meshname, numdt, numit, |
| 172 |
MED_NODE, MED_NONE, |
| 173 |
MED_COORDINATE, MED_NO_CMODE, |
| 174 |
MED_GLOBAL_STMODE, profilename, &profilesize, |
| 175 |
&coordinatechangement, &geotransformation)) < 0) { |
| 176 |
MESSAGE("ERROR : number of nodes ..."); |
| 177 |
goto ERROR; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
if (coordinatechangement && geotransformation) { |
| 183 |
if (MEDmeshNodeCoordinateWithProfileRd(fid, meshname, numdt, numit, |
| 184 |
MED_GLOBAL_STMODE,profilename, |
| 185 |
MED_FULL_INTERLACE,MED_ALL_CONSTITUENT, |
| 186 |
coordinates) < 0) { |
| 187 |
MESSAGE("ERROR : nodes coordinates ..."); |
| 188 |
free(coordinates); |
| 189 |
goto ERROR; |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
free(coordinates); |
| 197 |
|
| 198 |
ret=0; |
| 199 |
ERROR: |
| 200 |
|
| 201 |
|
| 202 |
if (MEDfileClose(fid) < 0) { |
| 203 |
MESSAGE("ERROR : close file"); |
| 204 |
ret=-1; |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
return ret; |
| 209 |
} |
| 210 |
|