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 #include <med.h>
00026 #define MESGERR 1
00027 #include "med_utils.h"
00028 #include <string.h>
00029
00030 #ifdef DEF_LECT_ECR
00031 #define MODE_ACCES MED_ACC_RDWR
00032 #elif DEF_LECT_AJOUT
00033 #define MODE_ACCES MED_ACC_RDEXT
00034 #else
00035 #define MODE_ACCES MED_ACC_CREAT
00036 #endif
00037
00038 int main (int argc, char **argv)
00039
00040
00041 {
00042 med_err ret = 0;
00043 med_idt fid;
00044 med_int nse2;
00045 med_int *se2_1;
00046 med_int *se2_2;
00047 char *nomse2;
00048 med_int *numse2;
00049 med_int *nufase2;
00050 med_int ntr3;
00051 med_int *tr3;
00052 char *nomtr3;
00053 med_int *numtr3;
00054 med_int *nufatr3;
00055 char maa[MED_NAME_SIZE+1] ="maa1";
00056 med_int mdim=0,sdim=0;
00057 med_bool inoele=MED_FALSE,inuele=MED_FALSE,chgt=MED_FALSE,trsf=MED_FALSE;
00058 med_bool inoele3=MED_FALSE,inuele3=MED_FALSE;
00059 med_int tse2,ttr3;
00060 char str[MED_SNAME_SIZE+1];
00061 med_int flt[2] = { 2, 3 }, fltsize=2;
00062 char desc[MED_COMMENT_SIZE+1];
00063 char dtunit[MED_SNAME_SIZE+1]="";
00064 char nomcoo[2*MED_SNAME_SIZE+1];
00065 char unicoo[2*MED_SNAME_SIZE+1];
00066 med_mesh_type type;
00067 med_sorting_type sort;
00068 med_int nstep=0,i=0;
00069 med_filter filter=MED_FILTER_INIT;
00070 med_axis_type rep;
00071 med_int nname=0;
00072
00073
00074 if ((fid = MEDfileOpen("test6.med",MED_ACC_RDONLY)) < 0) {
00075 MESSAGE("Erreur a l'ouverture du fichier test6.med");
00076 return -1;
00077 }
00078 if ((sdim=MEDmeshnAxis(fid, 1)) <0) {
00079 MESSAGE("Erreur a la lecture de la dimension de l'espace du maillage :");
00080 SSCRUTE(maa);
00081 return -1;
00082 }
00083
00084
00085 if ( MEDmeshInfo( fid, 1, maa, &sdim, &mdim, &type, desc, dtunit, &sort,
00086 &nstep, &rep, nomcoo,unicoo) < 0 ) {
00087 MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa);
00088 return -1;
00089 } else {
00090 printf("Maillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",maa,mdim,type);
00091 printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim);
00092 printf("\t -Description du maillage : %s\n",desc);
00093 printf("\t -Noms des axes : |%s|\n",nomcoo);
00094 printf("\t -Unités des axes : |%s|\n",unicoo);
00095 printf("\t -Type de repère : %d\n",rep);
00096 printf("\t -Nombre d'étapes de calcul : "IFORMAT"\n",nstep);
00097 printf("\t -Unité des dates : |%s|\n",dtunit);
00098 }
00099
00100
00101 if ((nse2 = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
00102 MED_DESCENDING_EDGE, MED_SEG2,MED_CONNECTIVITY, MED_DESCENDING,
00103 &chgt, &trsf)) < 0) {
00104 MESSAGE("Erreur a la lecture du nombre de faces MED_SEG2");
00105 return -1;
00106 }
00107
00108 if ((ntr3 = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
00109 MED_CELL,MED_TRIA3,MED_CONNECTIVITY, MED_DESCENDING,
00110 &chgt, &trsf))<0) {
00111 MESSAGE("Erreur a la lecture du nombre de mailles MED_TRIA3");
00112 return -1;
00113 }
00114 printf("Nombre de MED_SEG2 : "IFORMAT" - nombre de MED_TRIA3 : "IFORMAT"\n",nse2,ntr3);
00115
00116
00117
00118 tse2 = 2;
00119 se2_1 = (med_int*) calloc(tse2*nse2,sizeof(med_int));
00120 se2_2 = (med_int*) malloc(sizeof(med_int)*tse2*nse2);
00121 nomse2 = (char*) malloc(MED_SNAME_SIZE*nse2+1);
00122 numse2 = (med_int*) malloc(sizeof(med_int)*nse2);
00123 nufase2 = (med_int*) malloc(sizeof(med_int)*nse2);
00124
00125 ttr3 = 3;
00126 tr3 = (med_int*) malloc(sizeof(med_int)*ntr3*ttr3);
00127 nomtr3 = (char*) malloc(MED_SNAME_SIZE*ntr3+1);
00128 numtr3 = (med_int*) malloc(sizeof(med_int)*ntr3);
00129 nufatr3 = (med_int*) malloc(sizeof(med_int)*ntr3);
00130
00131 if ( MEDfilterEntityCr( fid, nse2, 1, sdim, 2,
00132 MED_FULL_INTERLACE, MED_GLOBAL_PFLMODE,
00133 MED_NO_PROFILE, fltsize,
00134 flt, &filter) < 0 ) {
00135 MESSAGE("Erreur à la crétion du filtre 1.");
00136 }
00137
00138
00139
00140 if (MEDmeshElementConnectivityAdvancedRd(fid, maa, MED_NO_DT, MED_NO_IT,
00141 MED_DESCENDING_EDGE, MED_SEG2, MED_DESCENDING, &filter,
00142 se2_1) < 0) {
00143 MESSAGE("Erreur a la lecture de la connectivite des segments");
00144 return -1;
00145 }
00146
00147 MEDfilterClose(&filter);
00148
00149
00150 if (MEDmeshElementConnectivityRd(fid, maa, MED_NO_DT, MED_NO_IT,
00151 MED_DESCENDING_EDGE, MED_SEG2, MED_DESCENDING,
00152 MED_FULL_INTERLACE, se2_2) < 0) {
00153 MESSAGE("Erreur a la lecture de la connectivite des segments");
00154 return -1;
00155 }
00156
00157
00158 if (MEDmeshEntityNameRd(fid, maa, MED_NO_DT, MED_NO_IT,
00159 MED_DESCENDING_EDGE, MED_SEG2,nomse2) < 0)
00160 inoele = MED_FALSE;
00161 else
00162 inoele = MED_TRUE;
00163
00164
00165 if ((nname = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
00166 MED_DESCENDING_EDGE,MED_SEG2,MED_NAME, MED_NO_CMODE,
00167 &chgt, &trsf))<0) {
00168 MESSAGE("Erreur a la lecture du nombre de nom de mailles MED_SEG2");
00169 return -1;
00170 }
00171 printf("Nombre de nom de MED_SEG2 : "IFORMAT" \n",nname);
00172
00173
00174 if ( MEDmeshEntityNumberRd(fid, maa, MED_NO_DT, MED_NO_IT,
00175 MED_DESCENDING_EDGE, MED_SEG2, numse2) < 0)
00176 inuele = MED_FALSE;
00177 else
00178 inuele = MED_TRUE;
00179
00180
00181 if (MEDmeshEntityFamilyNumberRd(fid,maa, MED_NO_DT, MED_NO_IT,
00182 MED_DESCENDING_EDGE, MED_SEG2,nufase2) < 0) {
00183 MESSAGE("Erreur a la lecture des numéros de famille des segments");
00184 return -1;
00185 }
00186
00187
00188 if (MEDmeshElementConnectivityRd(fid, maa, MED_NO_DT, MED_NO_IT,
00189 MED_CELL, MED_TRIA3, MED_DESCENDING,
00190 MED_FULL_INTERLACE, tr3) < 0) {
00191 MESSAGE("Erreur a la lecture de la connectivite des triangles");
00192 return -1;
00193 }
00194
00195
00196 if (MEDmeshEntityNameRd(fid, maa, MED_NO_DT, MED_NO_IT,
00197 MED_CELL, MED_TRIA3, nomtr3) < 0)
00198 inoele3 = MED_FALSE;
00199 else
00200 inoele3 = MED_TRUE;
00201
00202
00203 if (MEDmeshEntityNumberRd(fid, maa, MED_NO_DT, MED_NO_IT,
00204 MED_CELL, MED_TRIA3, numtr3) < 0)
00205 inuele3 = MED_FALSE;
00206 else
00207 inuele3 = MED_TRUE;
00208
00209
00210 if ( (ret = MEDmeshEntityFamilyNumberRd(fid,maa, MED_NO_DT, MED_NO_IT,
00211 MED_CELL, MED_TRIA3,nufatr3)) < 0) {
00212 MESSAGE("Erreur a la lecture des numeros de famille des segments");
00213 return -1;
00214 }
00215
00216
00217 if (MEDfileClose(fid) < 0) {
00218 MESSAGE("Erreur a la fermeture du fichier");
00219 return -1;
00220 }
00221
00222
00223 if (ret == 0) {
00224 printf("Connectivite des segments (1): \n");
00225 for (i=0;i<nse2*tse2;i++)
00226 printf(IFORMAT" ",*(se2_1+i));
00227 printf("\n");
00228 printf("Connectivite des segments (2): \n");
00229 for (i=0;i<nse2*tse2;i++)
00230 printf(IFORMAT" ",*(se2_2+i));
00231 if (inoele) {
00232 printf("\nNoms des segments :\n");
00233 for (i=0;i<nse2;i++) {
00234 strncpy(str,nomse2+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
00235 str[MED_SNAME_SIZE] = '\0';
00236 printf("|%s| ",str);
00237 }
00238 }
00239 if (inuele) {
00240 printf("\nNumeros des segments :\n");
00241 for (i=0;i<nse2;i++)
00242 printf(IFORMAT" ",*(numse2+i));
00243 }
00244 printf("\nNumeros des familles des segments :\n");
00245 for (i=0;i<nse2;i++)
00246 printf(IFORMAT" ",*(nufase2+i));
00247
00248 printf("\nConnectivite des triangles : \n");
00249 for (i=0;i<ntr3*ttr3;i++)
00250 printf(IFORMAT" ",*(tr3+i));
00251 if (inoele3) {
00252 printf("\nNoms des triangles :\n");
00253 for (i=0;i<ntr3;i++) {
00254 strncpy(str,nomtr3+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
00255 str[MED_SNAME_SIZE] = '\0';
00256 printf("|%s| ",str);
00257 }
00258 }
00259 if (inuele3) {
00260 printf("\nNumeros des triangles :\n");
00261 for (i=0;i<ntr3;i++)
00262 printf(IFORMAT" ",*(numtr3+i));
00263 }
00264 printf("\nNumeros des familles des triangles :\n");
00265 for (i=0;i<ntr3;i++)
00266 printf(IFORMAT" ",*(nufatr3+i));
00267
00268 printf("\n");
00269 }
00270
00271
00272 free(se2_1);
00273 free(se2_2);
00274 free(nomse2);
00275 free(numse2);
00276 free(nufase2);
00277
00278 free(tr3);
00279 free(nomtr3);
00280 free(numtr3);
00281 free(nufatr3);
00282
00283 return ret;
00284 }
00285