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