test3.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 : test3.c
00021  *
00022  * - Description : lecture des informations sur les maillages d'un fichier 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 
00042 {
00043   med_err ret = 0;
00044   med_idt fid = 0;
00045   med_int nmaa=0,mdim=0,sdim=0,nstep=0;
00046   int i=0;
00047   /*Pour les outils de type memchecker */
00048 /*   char maa[MED_NAME_SIZE+1]=""; */
00049 /*   char nomu[MED_LNAME_SIZE+1]=""; */
00050 /*   char des [MED_COMMENT_SIZE+1]=""; */
00051 /*   char dtunit[MED_SNAME_SIZE+1]=""; */
00052   char *maa   ;
00053   char *nomu  ;
00054   char *des   ;
00055   char *dtunit;
00056   char *axisname=0,*axisunit=0;
00057   med_mesh_type     meshtype;
00058   med_err           inomu;
00059   med_sorting_type  sortingtype;
00060   med_axis_type     axistype;
00061 
00062   /*Pour les outils de type memchecker */
00063   maa    = (char *) malloc(sizeof(char)*(MED_NAME_SIZE+1   ));
00064   nomu   = (char *) malloc(sizeof(char)*(MED_LNAME_SIZE+1  ));
00065   des    = (char *) malloc(sizeof(char)*(MED_COMMENT_SIZE+1));
00066   dtunit = (char *) malloc(sizeof(char)*(MED_SNAME_SIZE+1  ));
00067 
00068   /* Ouverture du fichier "test2.med" en lecture seule */
00069   fid = MEDfileOpen("test2.med",MED_ACC_RDONLY);
00070   if (fid < 0) {
00071     MESSAGE("Erreur a l'ouverture du fichier test2.med");
00072     return -1;
00073   }
00074 
00075   /* Lecture du nombre de maillage dans le fichier */
00076   nmaa = MEDnMesh(fid);
00077   if (nmaa < 0) {
00078     MESSAGE("Erreur a la lecture du nombre de maillage");
00079     return  -1;
00080   }
00081 
00082 
00083   /* Boucle sur tous les maillages, pour chaque maillage, on lit :
00084      - Le nom.
00085      - Le type
00086      - La dimension
00087      - La description
00088      - La dimension de l'espace si elle existe
00089      - Le nom universel s'il existe
00090   */
00091   printf("- Nombre de maillage dans test2.med = "IFORMAT"\n",nmaa);
00092 
00093   for (i=0;i< nmaa;i++) {
00094     /* lecture des informations */
00095 
00096     if ((sdim=MEDmeshnAxis(fid, i+1)) <0) {
00097       MESSAGE("Erreur a la lecture de la dimension de l'espace du maillage :");
00098       SSCRUTE(maa);
00099       ret = -1;
00100     }
00101     axisname  = (char*) malloc(MED_SNAME_SIZE*sdim+1);
00102     axisunit  = (char*) malloc(MED_SNAME_SIZE*sdim+1);
00103 
00104     if (MEDmeshInfo(fid,i+1, maa, &sdim, &mdim,  &meshtype, des, dtunit, &sortingtype, &nstep,
00105                     &axistype, axisname, axisunit) < 0) {
00106       MESSAGE("Erreur a la lecture des informations du maillage :"); SSCRUTE(maa);
00107       ret = -1;
00108     }
00109     /* lecture du nom universel */
00110     inomu = MEDmeshUniversalNameRd(fid,maa,nomu);
00111     /* affichage des donnees lues */
00112     if (inomu < 0)
00113       printf("maillage %d de nom %s, de dimension "IFORMAT" \n",i+1,maa,mdim);
00114     else
00115       printf("maillage %d de nom %s, de dimension "IFORMAT" et de nom univ. %s\n",i+1,maa,mdim,nomu);
00116 
00117     printf("La dimension de l'espace est "IFORMAT" \n",sdim);
00118     if (meshtype == MED_STRUCTURED_MESH)
00119       printf("Il s'agit d'un maillage structure \n");
00120     else
00121       printf("Il s'agit d'un maillage non structure \n");
00122     printf("Description associee au maillage : %s \n\n",des);
00123     printf("\t -Noms des axes : %s\n",  axisname);
00124     printf("\t -Unités des axes : %s\n",axisunit);
00125     printf("\t -Type de repère : %d\n", axistype);
00126     printf("\t -Nombre d'étape de calcul : "IFORMAT"\n",nstep);
00127     printf("\t -Unité des dates : %s\n",dtunit);
00128 
00129     free(axisname);
00130     free(axisunit);
00131   }
00132 
00133   free(  maa    );
00134   free(  nomu   );
00135   free(  des    );
00136   free(  dtunit );
00137 
00138 
00139   /* Fermeture du fichier */
00140   if ( MEDfileClose(fid) < 0) {
00141     MESSAGE("Erreur a la fermeture du fichier test2.med");
00142     return -1;
00143   }
00144 
00145   return ret;
00146 }
00147 
00148 
00149 
00150 

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