1 /*  This file is part of MED.
2  *
3  *  COPYRIGHT (C) 1999 - 2019  EDF R&D, CEA/DEN
4  *  MED is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU Lesser General Public License as published by
6  *  the Free Software Foundation, either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  MED is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public License
15  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /******************************************************************************
19  * - Nom du fichier : test32.c
20  *
21  * - Description : lecture nominale d'une numerotation globale dans un maillage MED
22  *
23  *****************************************************************************/
24 
25 #include <med.h>
26 #define MESGERR 1
27 #include <med_utils.h>
28 
29 #ifdef DEF_LECT_ECR
30 #define MODE_ACCES MED_ACC_RDWR
31 #elif DEF_LECT_AJOUT
32 #define MODE_ACCES MED_ACC_RDEXT
33 #else
34 #define MODE_ACCES MED_ACC_CREAT
35 #endif
36 
main(int argc,char ** argv)37 int main (int argc, char **argv)
38 
39 
40 {
41   med_err ret = 0;
42   med_idt fid;
43   med_int mdim,sdim;
44   char maa[MED_NAME_SIZE+1];
45   /* le nombre de noeuds */
46   med_int nnoe = 0;
47   /* table des numeros global */
48   med_int *numglobalnoe=NULL;
49   /* variable de stockage pour reperer le maillage */
50   med_int i;
51   char des[MED_COMMENT_SIZE+1]="";
52   char dtunit[MED_SNAME_SIZE+1]="";
53   char nomcoo[3*MED_SNAME_SIZE+1]="";
54   char unicoo[3*MED_SNAME_SIZE+1]="";
55   med_axis_type rep;
56   med_mesh_type type;
57   med_sorting_type sort;
58   med_int nstep=0;
59   med_bool chgt=MED_FALSE,trsf=MED_FALSE;
60 
61 
62 
63   if (argc != 2) {
64     MESSAGE("Il faut passer un fichier MED en param�tre");
65     return -1;
66   }
67 
68   /* Ouverture du fichier passe en argument */
69   if ((fid = MEDfileOpen(argv[1],MED_ACC_RDWR)) < 0) {
70     MESSAGE("Erreur a l'ouverture du fichier : "); SSCRUTE(argv[1]);
71     return -1;
72   }
73 
74   if ((sdim=MEDmeshnAxis(fid, 1)) <0) {
75     MESSAGE("Erreur � la lecture de la dimension de l'espace du maillage :");
76     SSCRUTE(maa);
77     return -1;
78   }
79 
80   /* Lecture des infos concernant le premier maillage */
81   if ( MEDmeshInfo( fid, 1,  maa, &sdim, &mdim, &type, des, dtunit, &sort,
82 		    &nstep,  &rep, nomcoo,unicoo) < 0 ) {
83     MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(maa);
84     return -1;
85   } else {
86     printf("Maillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",maa,mdim,type);
87     printf("\t -Dimension de l'espace : "IFORMAT"\n",sdim);
88     printf("\t -Description du maillage : %s\n",des);
89     printf("\t -Noms des axes : %s\n",nomcoo);
90     printf("\t -Unit�s des axes : %s\n",unicoo);
91     printf("\t -Type de rep�re : %d\n",rep);
92     printf("\t -Nombre d'�tapes de calcul : "IFORMAT"\n",nstep);
93     printf("\t -Unit� des dates : %s\n\n",dtunit);
94   }
95 
96   /* Lecture du nombre de noeuds */
97   if ( (nnoe = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
98 			      MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,
99 			      &chgt,&trsf)) < 0) {
100     MESSAGE("Erreur a la lecture du nombre de noeuds ");
101     return -1;
102   }
103   printf("Nombre de noeuds : "IFORMAT" \n",nnoe);
104 
105 
106   /* Allocations memoires */
107 
108   /* table de la numerotation globale
109      profil : (nombre de noeuds ) */
110   if (nnoe > 0) {
111     numglobalnoe = (med_int*) malloc(sizeof(med_int)*nnoe);
112   }
113 
114   /* lecture de la numerotation globale attachee aux noeuds*/
115   if (MEDmeshGlobalNumberRd(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,numglobalnoe)<0) {
116     MESSAGE("Erreur a la lecture de de la numerotation globale");
117     return -1;
118   }
119 
120   /* ecriture a l'ecran des resultats */
121   for (i=0;i<nnoe;i++)
122     printf("Numero global du noeud "IFORMAT" : "IFORMAT" \n",i+1,numglobalnoe[i]);
123 
124   free(numglobalnoe);
125 
126   /* Fermeture du fichier */
127   if (MEDfileClose(fid) < 0) {
128     MESSAGE("Erreur a la fermeture du fichier ");
129     return -1;
130   }
131 
132   return 0;
133 }
134 
135