test15.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2015  EDF R&D, CEA/DEN
00004  *  MED is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 3 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  MED is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 /******************************************************************************
00019  * - Nom du fichier : test15.c
00020  *
00021  * - Description : lecture des noeuds d'un maillage MED
00022  *                 a l'aide des routines de niveau 2
00023  *                 - equivalent a test5.c
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 int main (int argc, char **argv)
00041 
00042 
00043 {
00044   med_err ret = 0;
00045   med_idt fid = 0;
00046   med_int mdim=0,sdim=0;
00047   /* nom du maillage de longueur maxi MED_NAME_SIZE */
00048   char maa[MED_NAME_SIZE+1];
00049   /* le nombre de noeuds */
00050   med_int nnoe = 0;
00051   /* table des coordonnees */
00052   med_float *coo;
00053   /* tables des noms et des unites des coordonnees (dimension*MED_SNAME_SIZE+1) */
00054   char nomcoo[3*MED_SNAME_SIZE+1]="";
00055   char unicoo[3*MED_SNAME_SIZE+1]="";
00056   /* tables des noms, numeros, numeros de familles des noeuds
00057      autant d'elements que de noeuds - les noms ont pour longueur  MED_SNAME_SIZE */
00058   char       *nomnoe;
00059   med_int    *numnoe;
00060   med_int    *nufano;
00061   med_bool   inonoe,inunoe,inufam;
00062   med_bool   chgt=MED_FALSE, trsf=MED_FALSE;
00063   char str   [MED_SNAME_SIZE+1]  ="";
00064   char desc  [MED_COMMENT_SIZE+1]="";
00065   char dtunit[MED_SNAME_SIZE+1]  ="";
00066   med_mesh_type    type;
00067   med_sorting_type sort;
00068   med_axis_type    rep;
00069   med_int          nstep=0;
00070   med_int i;
00071 
00072   /* Ouverture du fichier en mode lecture seule */
00073   if ((fid = MEDfileOpen(argv[1],MED_ACC_RDONLY)) < 0) {
00074     MESSAGE("Erreur a l'ouverture du fichier.");
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   /* Lecture des infos concernant le premier maillage */
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   /* Combien de triangles et de segments */
00100   if ((nnoe = MEDmeshnEntity(fid, maa, MED_NO_DT, MED_NO_IT,
00101                               MED_NODE, MED_NODE,MED_COORDINATE, MED_NO_CMODE,
00102                              &chgt, &trsf)) < 0)  {
00103     MESSAGE("Erreur a la lecture du nombre de noeuds");
00104     return -1;
00105   }
00106   printf("Nombre de noeuds : "IFORMAT" \n",nnoe);
00107 
00108   /* Allocations memoires */
00109   /* table des coordonnees
00110      profil : (dimension * nombre de noeuds ) */
00111   if (nnoe > 0) {
00112     coo = (med_float*) malloc(sizeof(med_float)*nnoe*mdim);
00113     /* table des des numeros, des numeros de familles des noeuds
00114        profil : (nombre de noeuds) */
00115     numnoe = (med_int*) malloc(sizeof(med_int)*nnoe);
00116     nufano = (med_int*) calloc(nnoe,sizeof(med_int));
00117     /* table des noms des noeuds
00118        profil : (nnoe*MED_SNAME_SIZE+1) */
00119     nomnoe = (char*) malloc(MED_SNAME_SIZE*nnoe+1);
00120 
00121     /* Lecture des noeuds :
00122        - Coordonnees
00123        - Noms (optionnel dans un fichier MED)
00124        - Numeros (optionnel dans un fichier MED)
00125        - Numeros de familles    */
00126     if (MEDmeshNodeRd(fid,maa,MED_NO_DT,MED_NO_IT,MED_FULL_INTERLACE,
00127                       coo,&inonoe,nomnoe,&inunoe,numnoe,&inufam,nufano) < 0) {
00128       MESSAGE("Erreur a la lecture des noeuds du maillage");
00129       ret = -1;
00130     }
00131 
00132     /* Affichage */
00133     if (ret == 0) {
00134       printf("Type de repere : %d \n",rep);
00135       printf("Nom des coordonnees : \n");
00136       for (i=0;i<mdim;i++) {
00137         strncpy(str,nomcoo+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
00138         str[MED_SNAME_SIZE] = '\0';
00139         printf("|%s| ",str);
00140       }
00141       printf("\nUnites des coordonnees : \n");
00142       for (i=0;i<mdim;i++) {
00143         strncpy(str,unicoo+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
00144         str[MED_SNAME_SIZE] = '\0';
00145         printf("|%s| ",str);
00146       }
00147       printf("\nCoordonnees des noeuds : \n");
00148       for (i=0;i<nnoe*mdim;i++)
00149         printf("%f ",*(coo+i));
00150       if (inonoe) {
00151         printf("\nNoms des noeuds : \n");
00152         for (i=0;i<nnoe;i++) {
00153           strncpy(str,nomnoe+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
00154           str[MED_SNAME_SIZE] = '\0';
00155           printf(" |%s| ",str);
00156         }
00157       }
00158       if (inunoe) {
00159         printf("\nNumeros des noeuds : \n");
00160         for (i=0;i<nnoe;i++)
00161           printf(""IFORMAT" ",*(numnoe+i));
00162       }
00163 
00164       printf("\nPrésence de numeros des familles des noeuds : %d\n",inufam);
00165       printf("\nNumeros des familles des noeuds : \n");
00166       for (i=0;i<nnoe;i++)
00167         printf(IFORMAT" ",*(nufano+i));
00168       printf("\n");
00169     }
00170 
00171     /* Liberation memoire */
00172     free(coo);
00173     free(nomnoe);
00174     free(numnoe);
00175     free(nufano);
00176   }
00177 
00178   /* Fermeture du fichier */
00179   if (MEDfileClose(fid) < 0) {
00180     MESSAGE("Erreur a la fermeture du fichier");
00181     return -1;
00182   }
00183 
00184   return ret;
00185 }
00186 
00187 
00188 
00189 

Généré le Thu Oct 8 14:26:17 2015 pour MED fichier par  doxygen 1.6.1