00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <med.h>
00019 #define MESGERR 1
00020 #include <med_utils.h>
00021
00022 #include <string.h>
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 int main (int argc, char **argv) {
00034 med_idt fid;
00035 med_int nmodels, nsmesh;
00036 int i,j,k;
00037 char elementname[MED_NAME_SIZE+1]="";
00038 char supportmeshname[MED_NAME_SIZE+1]="";
00039 const char computmeshname[MED_NAME_SIZE+1]="COMPUT_MESH";
00040 med_geometry_type *geotype;
00041 med_entity_type entitype;
00042 med_int elementdim;
00043 med_int nnode,ncell;
00044 med_geometry_type geocelltype;
00045 med_bool anyprofile=0;
00046 med_int nconstatt, *nvaratt;
00047 char attname[MED_NAME_SIZE+1]="";
00048 char profilename[MED_NAME_SIZE+1]="";
00049 med_attribute_type atttype;
00050 med_int nattcomp;
00051 med_entity_type attentitype;
00052 med_int profilesize;
00053 unsigned char *value;
00054 med_int size=0;
00055 med_int meshdim, spacedim;
00056 char description[MED_COMMENT_SIZE+1]="";
00057 char axisname[3*MED_SNAME_SIZE+1]="";
00058 char axisunit[3*MED_SNAME_SIZE+1]="";
00059 med_axis_type axistype;
00060 med_float *coordinates;
00061 med_bool coordinatechangement;
00062 med_bool geotransformation;
00063 med_int nseg2;
00064 med_int *seg2connectivity;
00065 med_int nentities=0;
00066 med_sorting_type sortingtype;
00067 med_mesh_type meshtype;
00068 med_int nstep;
00069 char dtunit[MED_SNAME_SIZE+1]="";
00070 char unitname[2*MED_SNAME_SIZE+1]="";
00071 char tmp[MED_NAME_SIZE+1]="";
00072 int ret=-1;
00073
00074
00075 fid = MEDfileOpen("UsesCase_MEDstructElement_1.med",MED_ACC_RDONLY);
00076 if (fid < 0) {
00077 MESSAGE("ERROR : file creation ...");
00078 goto ERROR;
00079 }
00080
00081
00082
00083
00084 if ((nsmesh = MEDnSupportMesh(fid)) < 0 ) {
00085 MESSAGE("ERROR : read number of support mesh ...");
00086 goto ERROR;
00087 }
00088
00089
00090 for (i=0; i<nsmesh; i++) {
00091 if ( MEDsupportMeshInfo(fid, i+1, supportmeshname, &spacedim, &meshdim, description,
00092 &axistype, axisname, axisunit) < 0 ) {
00093 MESSAGE("ERROR : read information about mesh support ...");
00094 goto ERROR;
00095 }
00096
00097
00098 if ((nnode = MEDmeshnEntity(fid, supportmeshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NONE,
00099 MED_COORDINATE, MED_NO_CMODE,&coordinatechangement,
00100 &geotransformation)) < 0) {
00101 MESSAGE("ERROR : read number of nodes ...");
00102 goto ERROR;
00103 }
00104
00105
00106 coordinates = (med_float*) malloc(sizeof(med_float)*nnode*spacedim);
00107
00108 if (MEDmeshNodeCoordinateRd(fid, supportmeshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE,
00109 coordinates) < 0) {
00110 MESSAGE("ERROR : read nodes coordinates ...");
00111 free(coordinates);
00112 goto ERROR;
00113 }
00114
00115
00116 free(coordinates);
00117
00118
00119
00120
00121 if ((nseg2 = MEDmeshnEntity(fid, supportmeshname, MED_NO_DT, MED_NO_IT, MED_CELL,MED_SEG2,
00122 MED_CONNECTIVITY, MED_NODAL, &coordinatechangement,
00123 &geotransformation)) < 0) {
00124 MESSAGE("ERROR : number of MED_SEG2 ...");
00125 goto ERROR;
00126 }
00127
00128
00129 if (nseg2 > 0) {
00130 seg2connectivity = (med_int *) malloc(sizeof(med_int)*nseg2*2);
00131
00132 if (MEDmeshElementConnectivityRd(fid, supportmeshname, MED_NO_DT, MED_NO_IT, MED_CELL,
00133 MED_SEG2, MED_NODAL, MED_FULL_INTERLACE, seg2connectivity) < 0) {
00134 MESSAGE("ERROR : MED_SEG2 connectivity ...");
00135 free(seg2connectivity);
00136 goto ERROR;
00137 }
00138
00139 free(seg2connectivity);
00140 }
00141
00142 }
00143
00144
00145
00146
00147 if ((nmodels = MEDnStructElement(fid)) < 0) {
00148 MESSAGE("ERROR : read number of struct element models ...");
00149 goto ERROR;
00150 }
00151
00152 geotype = (med_geometry_type *) malloc(sizeof(med_geometry_type)*nmodels);
00153 nvaratt = (med_int *) malloc(sizeof(med_int)*nmodels);
00154
00155
00156
00157 for (i=0; i<nmodels; i++) {
00158 if (MEDstructElementInfo(fid, i+1, elementname, geotype+i, &elementdim,
00159 supportmeshname, &entitype, &nnode, &ncell,
00160 &geocelltype, &nconstatt, &anyprofile, nvaratt+i) < 0) {
00161 MESSAGE("ERROR : struct element models information ...");
00162 goto ERROR;
00163 }
00164
00165
00166 for (j=0; j<nconstatt; j++) {
00167 if ( MEDstructElementConstAttInfo(fid, elementname, j+1,
00168 attname, &atttype, &nattcomp, &attentitype,
00169 profilename, &profilesize) < 0) {
00170 MESSAGE("ERROR : const attribute information ...");
00171 goto ERROR;
00172 }
00173
00174
00175 if (profilesize != 0)
00176 size = profilesize*nattcomp*MEDstructElementAttSizeof(atttype);
00177 else
00178 if (entitype == MED_NODE)
00179 size = nnode*nattcomp*MEDstructElementAttSizeof(atttype);
00180 else
00181 size = ncell*nattcomp*MEDstructElementAttSizeof(atttype);
00182 if ( atttype == MED_ATT_NAME) ++size;
00183 value = (unsigned char *) malloc(size);
00184
00185
00186 if ( MEDstructElementConstAttRd(fid, elementname, attname, (unsigned char *)value ) < 0 ) {
00187 MESSAGE("ERROR : const attribute value ...");
00188 free(value);
00189 goto ERROR;
00190 }
00191
00192 free(value);
00193
00194 }
00195
00196
00197
00198 }
00199
00200
00201
00202
00203
00204
00205
00206
00207 if (MEDmeshInfoByName(fid, computmeshname, &spacedim, &meshdim, &meshtype, description,
00208 dtunit, &sortingtype, &nstep, &axistype, axisname, unitname) < 0) {
00209 MESSAGE("ERROR : mesh info ...");
00210 goto ERROR;
00211 }
00212
00213
00214 if ((nnode = MEDmeshnEntity(fid, computmeshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NONE,
00215 MED_COORDINATE, MED_NO_CMODE,&coordinatechangement,
00216 &geotransformation)) < 0) {
00217 MESSAGE("ERROR : number of nodes ...");
00218 goto ERROR;
00219 }
00220
00221
00222
00223
00224
00225 for (i=0;i<nmodels;i++) {
00226
00227
00228 if ((nentities = MEDmeshnEntity(fid, computmeshname, MED_NO_DT, MED_NO_IT, MED_STRUCT_ELEMENT,*(geotype+i),
00229 MED_CONNECTIVITY, MED_NODAL, &coordinatechangement,
00230 &geotransformation)) < 0) {
00231 MESSAGE("ERROR : number of MED_STRUCT_ELEMENT ...");
00232 goto ERROR;
00233 }
00234
00235 if (MEDstructElementName(fid,*(geotype+i),elementname) < 0) {
00236 MESSAGE("ERROR : get element name ...");
00237 goto ERROR;
00238 }
00239
00240 for (j=0; j<*(nvaratt+i); j++) {
00241
00242
00243 if ( MEDstructElementVarAttInfo(fid, elementname, j+1,
00244 attname, &atttype, &nattcomp) < 0) {
00245 MESSAGE("ERROR : var attribute information ...");
00246 goto ERROR;
00247 }
00248
00249
00250 if (entitype == MED_NODE)
00251 size = nnode*nattcomp*MEDstructElementAttSizeof(atttype);
00252 else
00253 size = ncell*nattcomp*MEDstructElementAttSizeof(atttype);
00254 if ( atttype == MED_ATT_NAME) ++size;
00255 value = (unsigned char *) malloc(size);
00256
00257
00258 if (MEDmeshStructElementVarAttRd(fid, computmeshname, MED_NO_DT, MED_NO_IT,
00259 *(geotype+i), attname, value ) < 0) {
00260 MESSAGE("ERROR : read variable attributes values ...");
00261 free(value);
00262 goto ERROR;
00263 }
00264
00265 free(value);
00266
00267 }
00268 }
00269
00270 ret=0;
00271 ERROR:
00272
00273 free(geotype);
00274 free(nvaratt);
00275
00276
00277 if (MEDfileClose(fid) < 0) {
00278 MESSAGE("ERROR : file closing ...");
00279 ret=-1;
00280 }
00281
00282 return ret;
00283 }
00284