2.3.6/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_LECTURE_ECRITURE
00034 #elif DEF_LECT_AJOUT
00035 #define MODE_ACCES MED_LECTURE_AJOUT
00036 #else
00037 #define MODE_ACCES MED_CREATION
00038 #endif
00039 
00040 int main (int argc, char **argv)
00041 
00042 
00043 {
00044   med_err ret = 0;
00045   med_idt fid;
00046   /* la dimension du maillage */
00047   med_int mdim;
00048   /* nom du maillage de longueur maxi MED_TAILLE_NOM */
00049   char maa[MED_TAILLE_NOM+1];
00050   /* le nombre de noeuds */
00051   med_int nnoe = 0;
00052   /* table des coordonnees */
00053   med_float *coo;
00054   /* tables des noms et des unites des coordonnees 
00055      profil : (dimension*MED_TAILLE_PNOM+1) */
00056   char nomcoo[3*MED_TAILLE_PNOM+1];
00057   char unicoo[3*MED_TAILLE_PNOM+1];
00058   /* tables des noms, numeros, numeros de familles des noeuds
00059      autant d'elements que de noeuds - les noms ont pout longueur
00060      MED_TAILLE_PNOM */
00061   char *nomnoe;
00062   med_int *numnoe;
00063   med_int *nufano; 
00064   med_repere rep;
00065   med_booleen inonoe,inunoe;
00066   char str[MED_TAILLE_PNOM+1];
00067   med_int i;
00068   char desc[MED_TAILLE_DESC+1];
00069   med_maillage type;
00070 
00071   /* Ouverture du fichier passe en argument en lecture seule */
00072   if ((fid= MEDouvrir(argv[1],MED_LECTURE)) < 0) {
00073     MESSAGE("Erreur a l'ouverture du fichier :");
00074     SSCRUTE(argv[1]);
00075     return -1;
00076   }
00077 
00078   /* Lecture des infos concernant le premier maillage */
00079   if (MEDmaaInfo(fid,1,maa,&mdim,&type,desc) < 0) {
00080     MESSAGE("Erreur a la lecture des informations du 1er maillage");
00081     return -1;
00082   }
00083   printf("Maillage de nom : %s et de dimension : "IFORMAT" \n",maa,mdim);
00084 
00085   /* Lecture du nombre de noeuds */
00086   if ((nnoe = MEDnEntMaa(fid,maa,MED_COOR,MED_NOEUD,0,0)) < 0) {
00087     MESSAGE("Erreur a la lecture du nombre de noeuds ");
00088     return -1;
00089   }
00090   printf("Nombre de noeuds : %d \n",nnoe);
00091 
00092   /* Allocations memoires */
00093   /* table des coordonnees 
00094      profil : (dimension * nombre de noeuds ) */
00095   if (nnoe > 0) {
00096     coo = (med_float*) malloc(sizeof(med_float)*nnoe*mdim);
00097     /* table des des numeros, des numeros de familles des noeuds
00098        profil : (nombre de noeuds) */
00099     numnoe = (med_int*) malloc(sizeof(med_int)*nnoe);
00100     nufano = (med_int*) malloc(sizeof(med_int)*nnoe);
00101     /* table des noms des noeuds 
00102        profil : (nnoe*MED_TAILLE_PNOM+1) */
00103     nomnoe = (char*) malloc(MED_TAILLE_PNOM*nnoe+1);
00104 
00105     /* Lecture des noeuds : 
00106        - Coordonnees
00107        - Noms (optionnel dans un fichier MED) 
00108        - Numeros (optionnel dans un fichier MED) 
00109        - Numeros de familles    */
00110     if (MEDnoeudsLire(fid,maa,mdim,coo,MED_FULL_INTERLACE,&rep,nomcoo,unicoo,
00111                       nomnoe,&inonoe,numnoe,&inunoe,nufano,nnoe) < 0) {
00112       MESSAGE("Erreur a la lecture des noeuds du maillage");
00113       ret = -1;
00114     }
00115 
00116     /* Affichage */
00117     if (ret == 0) {
00118       printf("Type de repere : %d \n",rep);
00119       printf("Nom des coordonnees : \n");
00120       for (i=0;i<mdim;i++) {
00121         strncpy(str,nomcoo+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
00122         str[MED_TAILLE_PNOM] = '\0';
00123         printf("%s ",str);
00124       }
00125       printf("\nUnites des coordonnees : \n");
00126       for (i=0;i<mdim;i++) {
00127         strncpy(str,unicoo+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
00128         str[MED_TAILLE_PNOM] = '\0';
00129         printf("%s ",str);
00130       }     
00131       printf("\nCoordonnees des noeuds : \n");
00132       for (i=0;i<nnoe*mdim;i++)
00133         printf("%f ",*(coo+i));
00134       if (inonoe) {
00135         printf("\nNoms des noeuds : \n");
00136         for (i=0;i<nnoe;i++) {
00137           strncpy(str,nomnoe+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
00138           str[MED_TAILLE_PNOM] = '\0';
00139           printf(" %s ",str);
00140         }
00141       }
00142       if (inunoe) {
00143         printf("\nNumeros des noeuds : \n");
00144         for (i=0;i<nnoe;i++)
00145           printf("%d ",*(numnoe+i));
00146       }
00147       printf("\nNumeros des familles des noeuds : \n");
00148       for (i=0;i<nnoe;i++)
00149         printf(IFORMAT" ",*(nufano+i));
00150       printf("\n");
00151     }
00152 
00153     /* Liberation memoire */
00154     free(coo);
00155     free(nomnoe);
00156     free(numnoe);
00157     free(nufano);
00158   }
00159 
00160   /* Fermeture du fichier */
00161   if (MEDfermer(fid) < 0) {
00162     MESSAGE("Erreur a la fermeture du fichier");
00163     return -1;
00164   }
00165  
00166   return ret;
00167 }
00168 
00169 
00170 
00171 

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