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