2.3.6/test9.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 /******************************************************************************
00020  * - Nom du fichier : test9.c
00021  *
00022  * - Description : lecture des familles d'un maillage MED 
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_LECTURE_ECRITURE
00033 #elif DEF_LECT_AJOUT
00034 #define MODE_ACCES MED_LECTURE_AJOUT
00035 #else
00036 #define MODE_ACCES MED_CREATION
00037 #endif
00038 
00039 int main (int argc, char **argv)
00040 
00041 
00042 {
00043   med_err ret = 0;
00044   med_idt fid;
00045   char maa[MED_TAILLE_NOM+1];
00046   med_int mdim;
00047   med_int nfam;
00048   med_int i,j;
00049   med_int natt,ngro;
00050   char *attdes,*gro;
00051   med_int *attval,*attide;
00052   char nomfam[MED_TAILLE_NOM+1];
00053   med_int numfam;
00054   char str1[MED_TAILLE_DESC+1];
00055   char str2[MED_TAILLE_LNOM+1];
00056   char desc[MED_TAILLE_DESC+1];
00057   med_maillage type;
00058 
00059   /* Ouverture du fichier "test8.med" en lecture seule */
00060   if ((fid = MEDouvrir("test8.med",MED_LECTURE)) < 0) {
00061     MESSAGE("Erreur a l'ouverture du fichier test8.med");
00062     return -1;
00063   }
00064 
00065   /* Lecture des information sur le 1er maillage */
00066   if (MEDmaaInfo(fid,1,maa,&mdim,&type,desc) < 0) {
00067     MESSAGE("Erreur a la lecture des informations du premier maillage");
00068     return -1;
00069   }
00070 
00071   /* Lecture du nombre de familles */
00072   if ((nfam = MEDnFam(fid,maa)) < 0) {
00073     MESSAGE("Erreur a la lecture du nombre de famille");
00074     return -1;
00075   }
00076   printf("Nombre de familles : "IFORMAT" \n",nfam);
00077 
00078   /* Lecture de chaque famille */
00079   for (i=0;i<nfam;i++) {
00080         
00081     /* Lecture du nombre de groupe */
00082     if ((ngro = MEDnGroupe(fid,maa,i+1)) < 0) {
00083       MESSAGE("Erreur a la lecture du nombre de groupe de la famille d'indice : ");
00084       ISCRUTE(i+1);
00085       ret = -1;
00086     }
00087         
00088     /* Lecture du nombre d'attribut */
00089     if ((natt = MEDnAttribut(fid,maa,i+1)) < 0) {
00090       MESSAGE("Erreur a la lecture du nombre d'attribut de la famille d'indice : ");
00091       ISCRUTE(i+1);
00092       ret = -1;
00093     }
00094 
00095     if (ret == 0)
00096       printf("Famille "IFORMAT" a "IFORMAT" attributs et "IFORMAT" groupes \n",i+1,natt,ngro); 
00097 
00098     /* Lecture des informations sur la famille */
00099     if (ret == 0) {
00100       /* Allocations memoire */
00101       attide = (med_int*) malloc(sizeof(med_int)*natt);
00102       attval = (med_int*) malloc(sizeof(med_int)*natt);     
00103       attdes = (char *) malloc(MED_TAILLE_DESC*natt+1);
00104       gro = (char*) malloc(MED_TAILLE_LNOM*ngro+1);
00105 
00106       if (MEDfamInfo(fid,maa,i+1,nomfam,&numfam,attide,attval,attdes,
00107                      &natt,gro,&ngro) < 0) {
00108         MESSAGE("Erreur a la lecture des informations de la famille d'indice : ");
00109         ISCRUTE(i+1);
00110         ret = -1;
00111       }
00112 
00113       if (ret == 0) {
00114         printf("Famille de nom %s et de numero "IFORMAT" : \n",nomfam,numfam);
00115         printf("Attributs : \n");
00116         for (j=0;j<natt;j++) {
00117           strncpy(str1,attdes+j*MED_TAILLE_DESC,MED_TAILLE_DESC);
00118           str1[MED_TAILLE_DESC] = '\0';
00119           printf("ide = "IFORMAT" - val = "IFORMAT" - des = %s\n",*(attide+j),
00120                  *(attval+j),str1);
00121         }
00122         free(attide);
00123         free(attval);
00124         free(attdes);   
00125         
00126         for (j=0;j<ngro;j++) {
00127           strncpy(str2,gro+j*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
00128           str2[MED_TAILLE_LNOM] = '\0';
00129           printf("gro = %s\n",str2);
00130               }
00131         free(gro);
00132       }
00133     }
00134   }
00135 
00136   /* Fermeture du fichier */
00137   if (MEDfermer(fid)  < 0) {
00138     MESSAGE("Erreur a la fermeture du fichier");
00139     return -1;
00140   }
00141   
00142   return ret;
00143 }

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