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 #include <med.h>
00027 #define MESGERR 1
00028 #include "med_utils.h"
00029 #include <string.h>
00030
00031 #ifdef DEF_LECT_ECR
00032 #define MODE_ACCES MED_ACC_RDWR
00033 #elif DEF_LECT_AJOUT
00034 #define MODE_ACCES MED_ACC_RDEXT
00035 #else
00036 #define MODE_ACCES MED_ACC_CREAT
00037 #endif
00038
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 = 0;
00048 med_int mdim= 0, sdim=0, axe=0, j=0;
00049 med_float *indices=NULL;
00050 med_int nind=0,nmaa=0, nnoeuds=0;
00051 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
00052 char maa [MED_NAME_SIZE+1] ="";
00053 char axisname[MAXDIM*MED_SNAME_SIZE+1]="";
00054 char axisunit[MAXDIM*MED_SNAME_SIZE+1]="";
00055 char dtunit[MED_SNAME_SIZE+1]="";
00056 char desc[MED_COMMENT_SIZE+1]="";
00057 med_mesh_type meshtype;
00058 med_grid_type gridtype;
00059 med_data_type quoi;
00060 med_sorting_type sort;
00061 med_axis_type repere;
00062 med_float *coo;
00063 med_int *structure_grille;
00064 med_int nstep=0,i=0;
00065
00066
00067 fid = MEDfileOpen("test27.med",MED_ACC_RDONLY);
00068 if (fid < 0) {
00069 MESSAGE("Erreur a l'ouverture du fichier test27.med");
00070 return -1;
00071 }
00072
00073
00074 nmaa = MEDnMesh(fid);
00075 if (nmaa < 0) {
00076 MESSAGE("Erreur a la lecture du nombre de maillage");
00077 return -1;
00078 }
00079
00080
00081
00082 for (i=0;i<nmaa;i++) {
00083
00084 if ((sdim=MEDmeshnAxis(fid, i+1)) <0) {
00085 MESSAGE("Erreur a la lecture de la dimension de l'espace du maillage :");
00086 SSCRUTE(maa);
00087 return -1;
00088 }
00089
00090
00091 if ( MEDmeshInfo( fid, i+1, maa, &sdim, &mdim, &meshtype, desc, dtunit, &sort,
00092 &nstep, &repere, axisname,axisunit) < 0 ) {
00093 MESSAGE("Erreur a la lecture des infos sur le maillage");
00094 return -1;
00095 }
00096
00097 printf("\nMaillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",maa,mdim,meshtype);
00098 printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim);
00099 printf("\t -Description du maillage : |%s|\n",desc);
00100 printf("\t -Noms des axes : |%s|\n",axisname);
00101 printf("\t -Unités des axes : |%s|\n",axisunit);
00102 printf("\t -Type de repère : %d\n",repere);
00103 printf("\t -Nombre d'étapes de calcul : "IFORMAT"\n",nstep);
00104 printf("\t -Unité des dates : |%s|\n",dtunit);
00105 if (meshtype == MED_STRUCTURED_MESH)
00106 printf("\t - Type : Maillage structure \n");
00107 else
00108 printf("\t - Type : Maillage non structure \n");
00109
00110
00111 if (meshtype == MED_STRUCTURED_MESH) {
00112 if (MEDmeshGridTypeRd(fid,maa, &gridtype) < 0) {
00113 MESSAGE("Erreur a la lecture de la nature d'une grille");
00114 return -1;
00115 }
00116 if (gridtype == MED_CARTESIAN_GRID)
00117 printf("\t - Grille cartesienne \n");
00118 if (gridtype == MED_CURVILINEAR_GRID)
00119 printf("\t - Grille de-structureee \n");
00120 }
00121
00122
00123 if (meshtype == MED_STRUCTURED_MESH && gridtype == MED_CURVILINEAR_GRID) {
00124
00125 nnoeuds = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
00126 MED_NODE, MED_NONE, MED_COORDINATE, MED_NO_CMODE, &chgt, &trsf);
00127 if (nnoeuds < 0) {
00128 MESSAGE("Erreur a la lecture du nombre de noeuds");
00129 return -1;
00130 }
00131 printf("Nombre de noeuds : "IFORMAT" \n",nnoeuds);
00132
00133 structure_grille = (med_int *) malloc(sizeof(med_int)*mdim);
00134 if ( MEDmeshGridStructRd(fid,maa,MED_NO_DT,MED_NO_IT, structure_grille ) < 0) {
00135 MESSAGE("Erreur a la lecture de la structure de la grille");
00136 ret = -1;
00137 }
00138 if (ret == 0) {
00139 printf("Structure des noeuds de la grille : [ ");
00140 for (j=0;j<mdim;j++)
00141 printf(" "IFORMAT" ",*(structure_grille+j));
00142 printf(" ] \n");
00143 free(structure_grille);
00144 }
00145
00146 if (ret == 0) {
00147 coo = (med_float *) malloc(sizeof(med_float)*nnoeuds*mdim);
00148
00149 if ( MEDmeshNodeCoordinateRd(fid, maa, MED_NO_DT, MED_NO_IT,
00150 MED_FULL_INTERLACE, coo) < 0 ) {
00151 MESSAGE("Erreur a la lecture des coordonnees des noeuds");
00152 ret = -1;
00153 }
00154 }
00155
00156 if (ret == 0) {
00157 printf("Coordonnees : [ ");
00158 for (j=0;j<nnoeuds*mdim;j++) printf(" %f ",*(coo+j));
00159 printf(" ] \n");
00160 free(coo);
00161 }
00162 }
00163
00164
00165 if (meshtype == MED_STRUCTURED_MESH && gridtype == MED_CARTESIAN_GRID)
00166 for (axe=1;axe<=mdim;axe++) {
00167 switch(axe) {
00168 case 1 :
00169 quoi = MED_COORDINATE_AXIS1;
00170 break;
00171
00172 case 2 :
00173 quoi = MED_COORDINATE_AXIS2;
00174 break;
00175
00176 case 3 :
00177 quoi = MED_COORDINATE_AXIS3;
00178 break;
00179
00180 default :
00181 return -1;
00182 }
00183
00184 nind = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
00185 MED_NODE, MED_NONE, quoi, MED_NO_CMODE, &chgt, &trsf);
00186 if (nind < 0) {
00187 MESSAGE("Erreur a la lecture de la taille de l'indice");
00188 return -1;
00189 }
00190 printf("Lecture de la taille de l'indice : "IFORMAT" \n",nind);
00191
00192
00193 indices = (med_float *) malloc(sizeof(med_float)*nind);
00194 if (MEDmeshGridIndexCoordinateRd(fid,maa,MED_NO_DT,MED_NO_IT, axe,indices) < 0) {
00195 MESSAGE("Erreur a lecture de indices de coordonnees");
00196 ret = -1;
00197 }
00198 if (ret == 0) {
00199 printf("Axe %.*s [%.*s] : [ ",MED_SNAME_SIZE, &axisname[(axe-1)*MED_SNAME_SIZE],
00200 MED_SNAME_SIZE,&axisunit[(axe-1)*MED_SNAME_SIZE]);
00201 for (j=0;j<nind;j++) printf(" %f ",indices[j]);
00202 printf(" ] \n");
00203 }
00204 free(indices);
00205 }
00206 }
00207
00208
00209 if (MEDfileClose(fid) < 0) {
00210 MESSAGE("Erreur a la fermeture du fichier");
00211 return -1;
00212 }
00213 printf("Fermeture du fichier \n");
00214
00215 return ret;
00216 }