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