| 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 |
const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh"; |
| 32 |
char meshdescription[MED_COMMENT_SIZE+1]=""; |
| 33 |
med_int meshdim; |
| 34 |
med_int spacedim; |
| 35 |
med_sorting_type sortingtype; |
| 36 |
med_int nstep; |
| 37 |
med_mesh_type meshtype; |
| 38 |
med_axis_type axistype; |
| 39 |
char axisname[2*MED_SNAME_SIZE+1]=""; |
| 40 |
char unitname[2*MED_SNAME_SIZE+1]=""; |
| 41 |
char dtunit[MED_SNAME_SIZE+1]; |
| 42 |
med_float *coordinates = NULL; |
| 43 |
med_int nnodes = 0; |
| 44 |
med_int *triaconnectivity = NULL; |
| 45 |
med_int ntria3 = 0; |
| 46 |
med_int *quadconnectivity = NULL; |
| 47 |
med_int nquad4 = 0; |
| 48 |
med_bool coordinatechangement; |
| 49 |
med_bool geotransformation; |
| 50 |
int i; |
| 51 |
med_int nfamily, ngroup; |
| 52 |
med_int familynumber; |
| 53 |
char *groupname=NULL; |
| 54 |
char familyname[MED_NAME_SIZE+1]=""; |
| 55 |
med_int *familynumbers = NULL; |
| 56 |
med_int nfamilynumber = 0; |
| 57 |
int ret=-1; |
| 58 |
|
| 59 |
|
| 60 |
fid = MEDfileOpen("UsesCase_MEDmesh_10.med",MED_ACC_RDONLY); |
| 61 |
if (fid < 0) { |
| 62 |
MESSAGE("ERROR : open file in READ ONLY ACCESS mode ..."); |
| 63 |
goto ERROR; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
if (MEDmeshInfoByName(fid, meshname, &spacedim, &meshdim, &meshtype, meshdescription, |
| 73 |
dtunit, &sortingtype, &nstep, &axistype, axisname, unitname) < 0) { |
| 74 |
MESSAGE("ERROR : mesh info ..."); |
| 75 |
goto ERROR; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
if ((nnodes = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NO_GEOTYPE, |
| 80 |
MED_COORDINATE, MED_NO_CMODE,&coordinatechangement, |
| 81 |
&geotransformation)) < 0) { |
| 82 |
MESSAGE("ERROR : number of nodes ..."); |
| 83 |
goto ERROR; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
if ((ntria3 = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,MED_TRIA3, |
| 93 |
MED_CONNECTIVITY, MED_NODAL,&coordinatechangement, |
| 94 |
&geotransformation)) < 0) { |
| 95 |
MESSAGE("ERROR : number of MED_TRIA3 ..."); |
| 96 |
goto ERROR; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
if ((nquad4 = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,MED_QUAD4, |
| 101 |
MED_CONNECTIVITY, MED_NODAL, &coordinatechangement, |
| 102 |
&geotransformation)) < 0) { |
| 103 |
MESSAGE("ERROR : number of MED_QUAD4 ..."); |
| 104 |
goto ERROR; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
if ((coordinates = (med_float*) malloc(sizeof(med_float)*nnodes*spacedim)) == NULL) { |
| 109 |
MESSAGE("ERROR : memory allocation ..."); |
| 110 |
goto ERROR; |
| 111 |
} |
| 112 |
|
| 113 |
if (MEDmeshNodeCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE, |
| 114 |
coordinates) < 0) { |
| 115 |
MESSAGE("ERROR : nodes coordinates ..."); |
| 116 |
free(coordinates); |
| 117 |
goto ERROR; |
| 118 |
} |
| 119 |
|
| 120 |
free(coordinates); |
| 121 |
|
| 122 |
|
| 123 |
if ((triaconnectivity = (med_int *) malloc(sizeof(med_int)*ntria3*3)) == NULL) { |
| 124 |
MESSAGE("ERROR : memory allocation ..."); |
| 125 |
goto ERROR; |
| 126 |
} |
| 127 |
if (MEDmeshElementConnectivityRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL, |
| 128 |
MED_TRIA3, MED_NODAL, MED_FULL_INTERLACE, triaconnectivity) < 0) { |
| 129 |
MESSAGE("ERROR : MED_TRIA3 connectivity ..."); |
| 130 |
free(triaconnectivity); |
| 131 |
goto ERROR; |
| 132 |
} |
| 133 |
free(triaconnectivity); |
| 134 |
|
| 135 |
if ((quadconnectivity = (med_int *) malloc(sizeof(med_int)*nquad4*4)) == NULL) { |
| 136 |
MESSAGE("ERROR : memory allocation ..."); |
| 137 |
goto ERROR; |
| 138 |
} |
| 139 |
if (MEDmeshElementConnectivityRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL, |
| 140 |
MED_QUAD4, MED_NODAL, MED_FULL_INTERLACE, quadconnectivity) < 0) { |
| 141 |
MESSAGE("ERROR : MED_QUAD4 connectivity ..."); |
| 142 |
free(quadconnectivity); |
| 143 |
goto ERROR; |
| 144 |
} |
| 145 |
free(quadconnectivity); |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
if ((nfamily = MEDnFamily(fid,meshname)) < 0) { |
| 151 |
MESSAGE("ERROR : read number of family ..."); |
| 152 |
goto ERROR; |
| 153 |
} |
| 154 |
|
| 155 |
for (i=0; i<nfamily ; i++) { |
| 156 |
|
| 157 |
if ((ngroup = MEDnFamilyGroup(fid, meshname, i+1)) < 0) { |
| 158 |
MESSAGE("ERROR : read number of group in a family ..."); |
| 159 |
goto ERROR; |
| 160 |
} |
| 161 |
|
| 162 |
if (ngroup > 0) { |
| 163 |
if ((groupname = (char*) malloc(sizeof(char)*MED_LNAME_SIZE*ngroup+1)) == NULL) { |
| 164 |
MESSAGE("ERROR : memory allocation ..."); |
| 165 |
goto ERROR; |
| 166 |
} |
| 167 |
|
| 168 |
if (MEDfamilyInfo(fid, meshname, i+1, familyname, &familynumber, groupname) < 0) { |
| 169 |
MESSAGE("ERROR : family info ..."); |
| 170 |
free(groupname); |
| 171 |
goto ERROR; |
| 172 |
} |
| 173 |
free(groupname); |
| 174 |
} |
| 175 |
|
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
if ((nfamilynumber = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, |
| 182 |
MED_NODE, MED_NONE, MED_FAMILY_NUMBER, MED_NO_CMODE, |
| 183 |
&coordinatechangement, &geotransformation)) < 0) { |
| 184 |
MESSAGE("ERROR : check family numbers nodes ..."); |
| 185 |
goto ERROR; |
| 186 |
} |
| 187 |
|
| 188 |
if ((familynumbers = (med_int *) malloc(sizeof(med_int)*nnodes)) == NULL) { |
| 189 |
MESSAGE("ERROR : memory allocation ..."); |
| 190 |
goto ERROR; |
| 191 |
} |
| 192 |
|
| 193 |
if (nfamilynumber > 0) { |
| 194 |
|
| 195 |
if (MEDmeshEntityFamilyNumberRd(fid, meshname, MED_NO_DT, MED_NO_IT, |
| 196 |
MED_NODE, MED_NONE, familynumbers) < 0) { |
| 197 |
MESSAGE("ERROR : read family numbers nodes ..."); |
| 198 |
goto ERROR; |
| 199 |
} |
| 200 |
} else |
| 201 |
for (i=0; i<nnodes; i++) *(familynumbers+i) = 0; |
| 202 |
|
| 203 |
for (i=0; i<nnodes; i++) { |
| 204 |
printf(IFORMAT, *(familynumbers+i)); |
| 205 |
if (i+1 != nnodes) |
| 206 |
printf(" - "); |
| 207 |
else |
| 208 |
printf("\n"); |
| 209 |
} |
| 210 |
|
| 211 |
if (familynumbers) |
| 212 |
free(familynumbers); |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
if ((nfamilynumber = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, |
| 217 |
MED_CELL, MED_TRIA3, MED_FAMILY_NUMBER, MED_NODAL, |
| 218 |
&coordinatechangement, &geotransformation)) < 0) { |
| 219 |
MESSAGE("ERROR : check family number tria3 ...") |
| 220 |
goto ERROR; |
| 221 |
} |
| 222 |
|
| 223 |
if ((familynumbers = (med_int *) malloc(sizeof(med_int)*ntria3)) == NULL) { |
| 224 |
MESSAGE("ERROR : memory allocation ..."); |
| 225 |
goto ERROR; |
| 226 |
} |
| 227 |
|
| 228 |
if (nfamilynumber > 0) { |
| 229 |
if (MEDmeshEntityFamilyNumberRd(fid, meshname, MED_NO_DT, MED_NO_IT, |
| 230 |
MED_CELL, MED_TRIA3, familynumbers) < 0) { |
| 231 |
MESSAGE("ERROR : read family numbers tria3 ..."); |
| 232 |
} |
| 233 |
} else |
| 234 |
for (i=0; i<ntria3; i++) *(familynumbers+i) = 0; |
| 235 |
|
| 236 |
free (familynumbers); |
| 237 |
|
| 238 |
if ((nfamilynumber = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, |
| 239 |
MED_CELL, MED_QUAD4, MED_FAMILY_NUMBER, MED_NODAL, |
| 240 |
&coordinatechangement, &geotransformation)) < 0) { |
| 241 |
MESSAGE("ERROR : check family number quad4 ..."); |
| 242 |
goto ERROR; |
| 243 |
} |
| 244 |
|
| 245 |
if ((familynumbers = (med_int *) malloc(sizeof(med_int)*nquad4)) == NULL) { |
| 246 |
MESSAGE("ERROR : memory allocation ..."); |
| 247 |
goto ERROR; |
| 248 |
} |
| 249 |
|
| 250 |
if (nfamilynumber > 0) { |
| 251 |
if (MEDmeshEntityFamilyNumberRd(fid, meshname, MED_NO_DT, MED_NO_IT, |
| 252 |
MED_CELL, MED_QUAD4, familynumbers) < 0) { |
| 253 |
MESSAGE("ERROR : read family numbers quad4 ..."); |
| 254 |
goto ERROR; |
| 255 |
} |
| 256 |
} else |
| 257 |
for (i=0; i<nquad4; i++) *(familynumbers+i) = 0; |
| 258 |
|
| 259 |
free (familynumbers); |
| 260 |
|
| 261 |
ret=0; |
| 262 |
ERROR: |
| 263 |
|
| 264 |
|
| 265 |
if (MEDfileClose(fid) < 0) { |
| 266 |
MESSAGE("ERROR : close file"); |
| 267 |
ret= -1; |
| 268 |
} |
| 269 |
|
| 270 |
return ret; |
| 271 |
} |