00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <med.h>
00028 #define MESGERR 1
00029 #include "med_utils.h"
00030 #include <string.h>
00031
00032 #ifdef DEF_LECT_ECR
00033 #define MODE_ACCES MED_ACC_RDWR
00034 #elif DEF_LECT_AJOUT
00035 #define MODE_ACCES MED_ACC_RDEXT
00036 #else
00037 #define MODE_ACCES MED_ACC_CREAT
00038 #endif
00039
00040 #define MAXDIM 3
00041
00042 int main (int argc, char **argv)
00043
00044
00045 {
00046 med_err ret = 0;
00047 med_idt fid;
00048 char maa[MED_NAME_SIZE+1];
00049 med_int nmaa,i,j,mdim;
00050 char desc[MED_COMMENT_SIZE+1];
00051 med_int taille,nindf,nindn,npoly;
00052 med_int taille2,nindf2,nindn2;
00053 med_int *conn, *conn2, *indexn, *indexn2, *num, *fam;
00054 med_int *indexf, *indexf2;
00055 char *nom;
00056 char tmp[MED_SNAME_SIZE+1];
00057 int ind1, ind2,k,nfaces,nnoeuds,l;
00058 char dtunit[MED_SNAME_SIZE+1]="";
00059 char nomcoo[MAXDIM*MED_SNAME_SIZE+1];
00060 char unicoo[MAXDIM*MED_SNAME_SIZE+1];
00061 med_mesh_type type;
00062 med_sorting_type sort;
00063 med_axis_type rep;
00064 med_int nstep=0,sdim=0;
00065 med_int inoele=0,inuele=0,ifaele=0;
00066 med_bool chgt=MED_FALSE,trsf=MED_FALSE;;
00067
00068
00069 fid = MEDfileOpen("test25.med",MED_ACC_RDONLY);
00070 if (fid < 0) {
00071 MESSAGE("Erreur a l'ouverture du fichier test25.med");
00072 return -1;
00073 }
00074 printf("Ouverture du fichier test25.med \n");
00075
00076
00077 nmaa = MEDnMesh(fid);
00078 if (nmaa < 0) {
00079 MESSAGE("Erreur a lecture du nombre de maillage");
00080 return -1;
00081 }
00082 printf("Nombre de maillages = "IFORMAT"\n",nmaa);
00083
00084 for (i=0;i<nmaa;i++) {
00085
00086
00087 if ( MEDmeshInfo( fid, i+1, maa, &sdim, &mdim, &type, desc, dtunit, &sort,
00088 &nstep, &rep, nomcoo, unicoo) < 0 ) {
00089 MESSAGE("Erreur a lecture des infos sur le maillage");
00090 return -1;
00091 } else {
00092 printf("maillage "IFORMAT" de nom [%s] et de dimension : "IFORMAT" , et de type %d\n",i+1,maa,mdim,type);
00093 printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim);
00094 printf("\t -Description du maillage : |%s|\n",desc);
00095 printf("\t -Noms des axes : |%s|\n",nomcoo);
00096 printf("\t -Unités des axes : |%s|\n",unicoo);
00097 printf("\t -Type de repère : %d\n",rep);
00098 printf("\t -Nombre d'étapes de calcul : "IFORMAT"\n",nstep);
00099 printf("\t -Unité des dates : |%s|\n",dtunit);
00100 }
00101
00102 printf("maillage "IFORMAT" de nom [%s] et de dimension : "IFORMAT" \n",i+1,maa,mdim);
00103
00104
00105 if ((nindf = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
00106 MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,
00107 &chgt,&trsf)) < 0) {
00108 MESSAGE("Erreur a lecture du nombre de maille MED_POLYEDRE en mode nodal");
00109 return -1;
00110 }
00111 npoly = nindf-1;
00112 printf("Nombre de mailles polyedres : "IFORMAT" \n",npoly);
00113
00114
00115 if ((nindn = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
00116 MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,
00117 &chgt,&trsf)) < 0) {
00118 MESSAGE("Erreur a lecture des infos sur les polyedres");
00119 return -1;
00120 }
00121 printf("Taille a allouer pour le tableau des faces (d'indexation des noeuds),(nodal) : "IFORMAT" \n",nindn);
00122
00123
00124 if ((nindn2 = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
00125 MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_DESCENDING,
00126 &chgt,&trsf)) < 0) {
00127 MESSAGE("Erreur a lecture des infos sur les polyedres");
00128 return -1;
00129 }
00130 printf("Taille a allouer pour le tableau des types de faces (descendant) : "IFORMAT" \n",nindn2);
00131
00132
00133 if ((taille = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
00134 MED_CELL,MED_POLYHEDRON,MED_CONNECTIVITY,MED_NODAL,
00135 &chgt,&trsf)) < 0) {
00136 MESSAGE("Erreur a la lecture des infos sur les polyedres");
00137 return -1;
00138 }
00139 printf("Taille a allouer pour le tableau des noeuds des polyedres (connectivite),(nodal) : "IFORMAT" \n",taille);
00140
00141
00142 if ((taille2 = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
00143 MED_CELL,MED_POLYHEDRON,MED_CONNECTIVITY,MED_DESCENDING,
00144 &chgt,&trsf)) < 0) {
00145 MESSAGE("Erreur a la lecture des infos sur les polyedres");
00146 return -1;
00147 }
00148 printf("Taille a allouer pour le tableau des noeuds des polyedres (connectivite),(descendant) : "IFORMAT" \n",taille2);
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 indexf = (med_int *) malloc(sizeof(med_int)*nindf);
00159 indexf2 = (med_int *) malloc(sizeof(med_int)*nindf);
00160 indexn = (med_int *) malloc(sizeof(med_int)*nindn);
00161 indexn2 = (med_int *) malloc(sizeof(med_int)*nindn2);
00162 conn = (med_int *) malloc(sizeof(med_int)*taille);
00163 conn2 = (med_int *) malloc(sizeof(med_int)*taille2);
00164 num = (med_int *) malloc(sizeof(med_int)*npoly);
00165 fam = (med_int *) calloc(sizeof(med_int),npoly);
00166 nom = (char *) malloc(sizeof(char)*MED_SNAME_SIZE*npoly+1);
00167
00168
00169 if (MEDmeshPolyhedronRd(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_NODAL,
00170 indexf,indexn,conn) < 0) {
00171 MESSAGE("Erreur a lecture de la connectivite nodale des polyedres");
00172 return -1;
00173 }
00174
00175 printf("Lecture de la connectivite des mailles MED_POLYEDRE en mode nodal \n");
00176
00177
00178 if (MEDmeshPolyhedronRd(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_DESCENDING,
00179 indexf2,indexn2,conn2) < 0) {
00180 MESSAGE("Erreur a lecture de la connectivite descendante des polyedres");
00181 return -1;
00182 }
00183 printf("Lecture de la connectivite des mailles MED_POLYEDRE en mode descendant \n");
00184
00185
00186 if ( (inoele = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
00187 MED_CELL,MED_POLYHEDRON,MED_NAME,MED_DESCENDING,
00188 &chgt,&trsf)) < 0) {
00189 MESSAGE("Erreur de detection de la présence de noms optionnels des polyedres");
00190 return -1;
00191 }
00192 if ( inoele ) {
00193 if (MEDmeshEntityNameRd(fid,maa,MED_NO_DT,MED_NO_IT,
00194 MED_CELL,MED_POLYHEDRON,nom) < 0) {
00195 MESSAGE("Erreur à la lecture des noms optionnels des polyedres");
00196 } else {
00197 printf("Lecture des noms des mailles MED_POLYEDRE \n");
00198 }
00199 }
00200
00201
00202 if ( (inuele = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
00203 MED_CELL,MED_POLYHEDRON,MED_NUMBER,MED_DESCENDING,
00204 &chgt,&trsf)) < 0) {
00205 MESSAGE("Erreur de detection de la présence de noms optionnels des polyedres");
00206 return -1;
00207 }
00208 if ( inuele) {
00209 if (MEDmeshEntityNumberRd(fid,maa,MED_NO_DT,MED_NO_IT,
00210 MED_CELL,MED_POLYHEDRON,num) < 0) {
00211 MESSAGE("Erreur à la lecture des numeros optionnels des polyedres");
00212 } else {
00213 printf("Lecture des numeros des mailles MED_POLYEDRE \n");
00214 }
00215 }
00216
00217
00218 if ( (ifaele = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
00219 MED_CELL,MED_POLYHEDRON,MED_FAMILY_NUMBER,MED_DESCENDING,
00220 &chgt,&trsf)) < 0) {
00221 MESSAGE("Erreur de detection de la présence des numéros de familles des polyedres");
00222 return -1;
00223 }
00224 if ( ifaele )
00225 if (MEDmeshEntityFamilyNumberRd(fid,maa,MED_NO_DT,MED_NO_IT,
00226 MED_CELL,MED_POLYHEDRON,fam) < 0) {
00227 MESSAGE("Erreur a lecture des numeros de famille des polyedres");
00228
00229 return -1;
00230 }
00231 printf("Lecture des numeros de familles des mailles MED_POLYEDRE \n");
00232
00233 printf("Affichage des resultats \n");
00234 for (j=0;j<npoly;j++) {
00235
00236 printf(">> Maille MED_POLYEDRE "IFORMAT" : \n",j+1);
00237 printf("---- Connectivite nodale ----- : \n");
00238 nfaces = *(indexf+j+1) - *(indexf+j);
00239 ISCRUTE_int(nfaces);
00240
00241 ind1 = *(indexf+j) - 1;
00242 for (k=0;k<nfaces;k++) {
00243
00244 ind2 = *(indexn+ind1+k) - 1;
00245 nnoeuds = *(indexn+ind1+k+1) - *(indexn+ind1+k);
00246 printf(" - Face %d : [ ", k+1);
00247 for (l=0;l<nnoeuds;l++)
00248 printf(" "IFORMAT" ",*(conn+ind2+l));
00249 printf(" ] \n");
00250 }
00251 printf("---- Connectivite descendante ----- : \n");
00252 nfaces = *(indexf2+j+1) - *(indexf2+j);
00253
00254 ind1 = *(indexf2+j) - 1;
00255 for (k=0;k<nfaces;k++)
00256 printf(" - Face %d de numero : "IFORMAT" et de type "IFORMAT" \n", k+1,*(conn2+ind1+k),*(indexn2+ind1+k));
00257 strncpy(tmp,nom+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
00258 tmp[MED_SNAME_SIZE] = '\0';
00259 if (inoele) printf("---- Nom ----- : %s \n",tmp);
00260 if (inuele) printf("---- Numero ----- : "IFORMAT" \n",*(num+j));
00261 printf("---- Numero de famille ----- : "IFORMAT" \n",*(fam+j));
00262 }
00263
00264
00265
00266 free(indexf);
00267 free(indexf2);
00268 free(indexn);
00269 free(indexn2);
00270 free(conn);
00271 free(conn2);
00272 free(num);
00273 free(fam);
00274 free(nom);
00275 }
00276
00277
00278 if (MEDfileClose(fid) < 0) {
00279 MESSAGE("Erreur a fermeture du fichier");
00280 return -1;
00281 }
00282 printf("Fermeture du fichier \n");
00283
00284 return ret;
00285 }