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_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 int main (int argc, char **argv)
00040 {
00041   med_err ret = 0;
00042   med_idt fid;
00043   char maa[MED_NAME_SIZE+1];
00044   med_int mdim;
00045   med_int nfam;
00046   int     i,j;
00047   med_int natt,ngro;
00048   char *attdes,*gro;
00049   med_int *attval,*attide;
00050   char nomfam[MED_NAME_SIZE+1];
00051   med_int numfam=0, nstep=0, sdim=0;
00052   char str1[MED_COMMENT_SIZE+1];
00053   char str2[MED_LNAME_SIZE+1];
00054   char desc[MED_COMMENT_SIZE+1];
00055   char dtunit[MED_SNAME_SIZE+1]="";
00056   char nomcoo[2*MED_SNAME_SIZE+1]="";
00057   char unicoo[2*MED_SNAME_SIZE+1]="";
00058   med_mesh_type type;
00059   med_sorting_type sort;
00060   med_axis_type rep;
00061 
00062   /* Ouverture du fichier "test8.med" en lecture seule */
00063   if ((fid = MEDfileOpen("test8.med",MED_ACC_RDONLY)) < 0) {
00064     MESSAGE("Erreur a l'ouverture du fichier test8.med");
00065     return -1;
00066   }
00067 
00068   if ((sdim=MEDmeshnAxis(fid, 1)) <0) {
00069     MESSAGE("Erreur a la lecture de la dimension de l'espace du maillage :");
00070     SSCRUTE(maa);
00071     return -1;
00072   }
00073 
00074   /* Lecture des infos concernant le premier maillage */
00075   if ( MEDmeshInfo( fid, 1,  maa, &sdim, &mdim, &type, desc, dtunit, &sort,
00076                     &nstep,  &rep, nomcoo,unicoo) < 0 ) {
00077     MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa);
00078     return -1;
00079   } else {
00080     printf("Maillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",maa,mdim,type);
00081     printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim);
00082     printf("\t -Description du maillage : %s\n",desc);
00083     printf("\t -Noms des axes : |%s|\n",nomcoo);
00084     printf("\t -Unités des axes : |%s|\n",unicoo);
00085     printf("\t -Type de repère : %d\n",rep);
00086     printf("\t -Nombre d'étape de calcul : "IFORMAT"\n",nstep);
00087     printf("\t -Unité des dates : |%s|\n",dtunit);
00088   }
00089 
00090 
00091   /* Lecture du nombre de familles */
00092   if ((nfam = MEDnFamily(fid,maa)) < 0) {
00093     MESSAGE("Erreur a la lecture du nombre de famille");
00094     return -1;
00095   }
00096   printf("Nombre de familles : "IFORMAT" \n",nfam);
00097 
00098   /* Lecture de chaque famille */
00099   for (i=0;i<nfam;i++) {
00100 
00101     /* Lecture du nombre de groupe */
00102     if ((ngro = MEDnFamilyGroup(fid,maa,i+1)) < 0) {
00103       MESSAGE("Erreur a la lecture du nombre de groupe de la famille d'indice : ");
00104       ISCRUTE_int(i+1);
00105       ret = -1;
00106     }
00107 
00108     /* Lecture du nombre d'attribut */
00109     if ((natt = MEDnFamily23Attribute(fid,maa,i+1)) < 0) {
00110       MESSAGE("Erreur a la lecture du nombre d'attribut de la famille d'indice : ");
00111       ISCRUTE_int(i+1);
00112       ret = -1;
00113     }
00114 
00115     if (ret == 0)
00116       printf("Famille %d a "IFORMAT" attributs et "IFORMAT" groupes \n",i+1,natt,ngro);
00117 
00118     /* Lecture des informations sur la famille */
00119     if (ret == 0) {
00120       /* Allocations memoire */
00121       attide = (med_int*) malloc(sizeof(med_int)*natt);
00122       attval = (med_int*) malloc(sizeof(med_int)*natt);
00123       attdes = (char *) malloc(MED_COMMENT_SIZE*natt+1);
00124       gro = (char*) malloc(MED_LNAME_SIZE*ngro+1);
00125 
00126       if (MEDfamily23Info(fid,maa,i+1,nomfam,attide,attval,attdes,&numfam,gro) < 0) {
00127         MESSAGE("Erreur a la lecture des informations de la famille d'indice : ");
00128         ISCRUTE_int(i+1);
00129         ret = -1;
00130       }
00131 
00132       if (ret == 0) {
00133         printf("Famille de nom %s et de numero "IFORMAT" : \n",nomfam,numfam);
00134         printf("Attributs : \n");
00135         for (j=0;j<natt;j++) {
00136           strncpy(str1,attdes+j*MED_COMMENT_SIZE,MED_COMMENT_SIZE);
00137           str1[MED_COMMENT_SIZE] = '\0';
00138           printf("ide = "IFORMAT" - val = "IFORMAT" - des = %s\n",*(attide+j),
00139                  *(attval+j),str1);
00140         }
00141         free(attide);
00142         free(attval);
00143         free(attdes);
00144 
00145         for (j=0;j<ngro;j++) {
00146           strncpy(str2,gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
00147           str2[MED_LNAME_SIZE] = '\0';
00148           printf("gro = %s\n",str2);
00149               }
00150         free(gro);
00151       }
00152     }
00153   }
00154 
00155   /* Fermeture du fichier */
00156   if (MEDfileClose(fid)  < 0) {
00157     MESSAGE("Erreur a la fermeture du fichier");
00158     return -1;
00159   }
00160 
00161   return ret;
00162 }

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