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 
00101   for (i=0;i<nmodels;i++) {
00102 
00103     
00104     if (MEDmeshEntityInfo(fid, computmeshname, MED_NO_DT, MED_NO_IT, MED_STRUCT_ELEMENT,i+1,elementname,(geotype+i)) < 0) {
00105       MESSAGE("ERROR : name and type of MED_STRUCT_ELEMENT ...");
00106       goto ERROR;
00107     }
00108 
00109     
00110     if ((nentities = MEDmeshnEntity(fid, computmeshname, MED_NO_DT, MED_NO_IT, MED_STRUCT_ELEMENT,*(geotype+i),
00111                                     MED_CONNECTIVITY, MED_NODAL, &coordinatechangement,
00112                                     &geotransformation)) < 0) {
00113       MESSAGE("ERROR : number of MED_STRUCT_ELEMENT ...");
00114       goto ERROR;
00115     }
00116 
00117     
00118     if (MEDstructElementInfoByName(fid, elementname, geotype+i, &elementdim,
00119                                    supportmeshname, &entitype, &nnode, &ncell,
00120                                    &geocelltype, &nconstatt, &anyprofile, nvaratt+i) < 0) {
00121       MESSAGE("ERROR : struct element models information ...");
00122       goto ERROR;
00123     }
00124     
00125     
00126      
00127     if (strcmp(supportmeshname,"")) {
00128       if ( MEDsupportMeshInfoByName(fid, supportmeshname, &spacedim, &meshdim, description,
00129                                     &axistype, axisname, axisunit) < 0 ) {
00130         MESSAGE("ERROR : read information about mesh support ...");
00131         goto ERROR;
00132       }
00133 
00134       ISCRUTE(nnode);
00135       
00136        
00137       if ((nnode = MEDmeshnEntity(fid, supportmeshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NONE,
00138                                   MED_COORDINATE, MED_NO_CMODE,&coordinatechangement,
00139                                   &geotransformation)) < 0) {
00140         MESSAGE("ERROR : read number of nodes ...");
00141         goto ERROR;
00142       }
00143      ISCRUTE(nnode);
00144 
00145       
00146        
00147       coordinates = (med_float*) malloc(sizeof(med_float)*nnode*spacedim);
00148 
00149       if (MEDmeshNodeCoordinateRd(fid, supportmeshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE,
00150                                   coordinates) < 0) {
00151         MESSAGE("ERROR : read nodes coordinates ...");
00152         free(coordinates);
00153         goto ERROR;
00154       }
00155 
00156       
00157       free(coordinates);
00158 
00159       
00160        
00161       if ((nseg2 = MEDmeshnEntity(fid, supportmeshname, MED_NO_DT, MED_NO_IT, MED_CELL,geocelltype,
00162                                   MED_CONNECTIVITY, MED_NODAL, &coordinatechangement,
00163                                   &geotransformation)) < 0) {
00164         MESSAGE("ERROR : number of MED_SEG2 ...");
00165         goto ERROR;
00166       }
00167      ISCRUTE(nseg2);
00168      ISCRUTE(ncell);
00169       
00170       if (nseg2 > 0) {
00171         seg2connectivity = (med_int *) malloc(sizeof(med_int)*nseg2*2);
00172 
00173         if (MEDmeshElementConnectivityRd(fid, supportmeshname, MED_NO_DT, MED_NO_IT, MED_CELL,
00174                                          geocelltype, MED_NODAL, MED_FULL_INTERLACE, seg2connectivity) < 0) {
00175           MESSAGE("ERROR : MED_SEG2 connectivity ...");
00176           free(seg2connectivity);
00177           goto ERROR;
00178         }
00179         free(seg2connectivity);
00180       }
00181     }
00182 
00183     
00184     
00185     for (j=0; j<nconstatt; j++) {
00186       if ( MEDstructElementConstAttInfo(fid, elementname, j+1,
00187                                         attname, &atttype, &nattcomp, &attentitype,
00188                                         profilename, &profilesize) < 0) {
00189         MESSAGE("ERROR : const attribute information ...");
00190         goto ERROR;
00191       }
00192 
00193       
00194 
00195       
00196       if (profilesize != 0)
00197         size = profilesize*nattcomp*MEDstructElementAttSizeof(atttype);
00198       else
00199         if (attentitype== MED_NODE)
00200           size = nnode*nattcomp*MEDstructElementAttSizeof(atttype);
00201         else
00202           size = ncell*nattcomp*MEDstructElementAttSizeof(atttype);
00203       if ( atttype == MED_ATT_NAME) ++size;
00204       ISCRUTE(size);
00205       value = (med_float *) malloc(size);
00206 
00207 
00208       
00209       if ( MEDstructElementConstAttRd(fid, elementname, attname, (unsigned char *)value ) < 0 ) {
00210         MESSAGE("ERROR : const attribute value ...");
00211         free(value);
00212         goto ERROR;
00213       }
00214 
00215       
00216       free(value);
00217     }
00218 
00219     
00220     for (j=0; j<*(nvaratt+i); j++) {
00221 
00222       
00223       if ( MEDstructElementVarAttInfo(fid, elementname, j+1, 
00224                                       attname, &atttype, &nattcomp) < 0) {
00225             MESSAGE("ERROR : var attribute information ...");
00226             goto ERROR;
00227       }
00228       
00229       
00230       size = nentities*nattcomp*MEDstructElementAttSizeof(atttype);
00231       if ( atttype == MED_ATT_NAME) ++size;
00232       ISCRUTE(size);
00233       value = (med_float *) malloc((size)*sizeof(char));
00234       
00235       
00236       if (MEDmeshStructElementVarAttRd(fid, computmeshname, MED_NO_DT, MED_NO_IT,
00237                                        *(geotype+i), attname, value ) < 0) {
00238         MESSAGE("ERROR : read variable attributes values ...");
00239         free(value);
00240         goto ERROR;
00241       }
00242 
00243       
00244       free(value);
00245       
00246     }
00247     
00248   }
00249 
00250   ret=0;
00251  ERROR:
00252 
00253   
00254   free(geotype);
00255   free(nvaratt);
00256 
00257   
00258   if (MEDfileClose(fid) < 0) {
00259     MESSAGE("ERROR : file closing ...");
00260     ret=-1;
00261   }
00262 
00263   return ret;
00264 }
00265