]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_MEDMEMgaussEcr.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_MEDMEMgaussEcr.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "MEDMEM_MEDMEMgaussEcr.hxx"
23 /*
24  * En attendant une correction de la gestion du mode d'accès au fichier dans MEDfichier
25  * on intègre la correction ici.
26  */
27
28 namespace med_2_3 {
29   extern "C" {
30 # define ICI                    {\
31                                         fflush(stdout);\
32                                         fprintf(stderr, "%s [%d] : " , __FILE__ , __LINE__ ) ;\
33                                         fflush(stderr) ;\
34                                 }
35
36 # define ISCRUTE_MED(entier)        {\
37                                         ICI ;\
38                                         fprintf(stderr,"%s = %d\n",#entier,entier) ;\
39                                         fflush(stderr) ;\
40                                 }
41
42 # define SSCRUTE_MED(chaine)        {\
43                                         ICI ;\
44                                         fprintf(stderr,"%s = \"%s\"\n",#chaine,chaine) ;\
45                                         fflush(stderr) ;\
46                                 }
47 # define MESSAGE_MED(chaine)        {\
48                                         ICI ;\
49                                         fprintf(stderr,"%s\n",chaine) ;\
50                                         fflush(stderr) ;\
51                                 }
52
53     extern void _MEDmodeErreurVerrouiller(void);
54
55     /*
56      * - Nom de la fonction : MEDgaussEcr
57      * - Description : Itérateur renvoyant (n°pdt,n°or), le nbre de point de GAUSS pour le type d'élément,
58      *                 et le  maillage par défaut avec son eventuel lien à un autre fichier.
59      * - Parametres :
60      *     - fid      (IN) : ID du fichier HDF courant
61      *     - type_geo (IN) : Le type géométrique de l'entité concerné {MED_POINT,MED_SEG2 ......}
62      *     - refcoo   (IN) : Les coordonnées des noeuds de l'élément de référence (tableau de taille(typegeo%100)*(typegeo/100) )
63      *     - mode_coo (IN) : Choix du type d'entrelacement utilisé en mémoire pour refcoo et gscoo
64      *                        { MED_FULL_INTERLACE(x1,y1,z1,x2,...)) , MED_NO_INTERLACE(x1,x2,y1,y2,z1,z2) }
65      *     - ngauss   (IN) : Nombre de points de Gauss pour l'élément de référence considéré
66      *     - gscoo    (IN) : Les coordonnées des points de Gauss pour l'élément de référence (tableau de taille ngauss*type_geo/100)
67      *     - wg       (IN) : Poids à appliquer aux points d'intégration (tableau de taille ngauss)
68      *     - locname (IN) : Nom à associer à la localisation (MED_TAILLe_NOM)
69
70      REM :
71      <locname> est à passer en paramètre de MEDchampEcrire.
72     */
73
74     med_err
75     MEDMEMgaussEcr(med_idt fid, med_geometrie_element type_geo, med_float *refcoo, med_mode_switch mode_coo,
76                    med_int ngauss, med_float *gscoo, med_float * wg, char * locname )
77     {
78       med_idt gid=0, chid=0;
79       med_size dimd[1];
80       med_err ret = -1;
81       med_int typegeo = -1;
82       char chemin[MED_TAILLE_GAUSS+1]="";
83
84       /*
85        * On inhibe le gestionnaire d'erreur HDF 5
86        */
87       _MEDmodeErreurVerrouiller();
88
89       /*
90        * Si le groupe "GAUSS" n'existe pas, on le cree
91        */
92       strncpy(chemin,MED_GAUSS,MED_TAILLE_GAUSS-1);
93       chemin[MED_TAILLE_GAUSS-1] = '\0';
94       if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
95         if ((gid = _MEDdatagroupCreer(fid,chemin)) < 0) {
96           MESSAGE_MED("Impossible de creer le groupe MED_GAUSS : ");
97           SSCRUTE_MED(chemin); goto ERROR;
98         }
99
100       /*
101        * Si le groupe <locname> n'existe pas, on le cree
102        * Sinon => erreur
103        */
104       if ((chid = _MEDdatagroupOuvrir(gid,locname)) >= 0) {
105         if ( false )//MED_MODE_ACCES != MED_LECTURE_ECRITURE )
106   {
107           MESSAGE_MED("Le nom de localisation existe déjà : ");
108           SSCRUTE_MED(locname); goto ERROR;
109         }
110       } else
111         if ((chid = _MEDdatagroupCreer(gid,locname)) < 0)
112           goto ERROR;
113
114       /*
115        * On stocke <ngauss> sous forme d'attribut
116        */
117       if (_MEDattrEntierEcrire(chid,MED_NOM_NBR,&ngauss) < 0) {
118         MESSAGE_MED("Erreur à l'écriture de l'attribut MED_NOM_NBR : ");
119         ISCRUTE_MED(ngauss);goto ERROR;
120       };
121
122       /*
123        * On stocke <type_geo> sous forme d'attribut
124        */
125       typegeo = (med_int) type_geo;
126       /* sizeof(enum) tjrs = sizeof(int) en C, or
127          sur machines 64 bits par défaut med_int==long,
128          du coup sur  machines 64 bits _MEDattrEntierEcrire utilise
129          le type hdf NATIVE_LONG, ce qui pose un problème qd on passe
130          un enum.
131       */
132       if (_MEDattrEntierEcrire(chid,MED_NOM_GEO,&typegeo) < 0) {
133         MESSAGE_MED("Erreur à l'écriture de l'attribut MED_NOM_GEO : ");
134         ISCRUTE_MED(type_geo);goto ERROR;
135       };
136
137
138       /*
139        * On stocke les coordonnées de référence dans un dataset
140        */
141
142       dimd[0] = (type_geo%100)*(type_geo/100);
143       if ( _MEDdatasetNumEcrire(chid,MED_NOM_COO,MED_FLOAT64,mode_coo,(type_geo/100),MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
144                                 (unsigned char*) refcoo)  < 0 ) {
145         MESSAGE_MED("Impossible d'ecrire le dataset : ");SSCRUTE_MED(MED_NOM_COO);
146         ISCRUTE_MED(dimd); goto ERROR;
147       }
148
149       /*
150        * On stocke les points d'intégration dans un dataset
151        */
152
153       dimd[0] = ngauss*(type_geo/100);
154       if ( _MEDdatasetNumEcrire(chid,MED_NOM_GAU,MED_FLOAT64,mode_coo,(type_geo/100),MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
155                                 (unsigned char*) gscoo)  < 0 ) {
156         MESSAGE_MED("Impossible d'ecrire le dataset : ");SSCRUTE_MED(MED_NOM_GAU);
157         ISCRUTE_MED(dimd); goto ERROR;
158       }
159
160       /*
161        * On stocke les poids dans un dataset
162        */
163
164       dimd[0] = ngauss;
165       if ( _MEDdatasetNumEcrire(chid,MED_NOM_VAL,MED_FLOAT64,mode_coo,1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
166                                 (unsigned char*) wg)  < 0 ) {
167         MESSAGE_MED("Impossible d'ecrire le dataset : ");SSCRUTE_MED(MED_NOM_VAL);
168         ISCRUTE_MED(dimd); goto ERROR;
169       }
170
171
172       ret = 0;
173
174     ERROR:
175
176       /*
177        * On ferme tout
178        */
179
180       if (chid>0)     if (_MEDdatagroupFermer(chid) < 0) {
181         MESSAGE_MED("Impossible de fermer le datagroup : ");
182         ISCRUTE_MED(chid); ret = -1;
183       }
184
185       if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
186         MESSAGE_MED("Impossible de fermer le datagroup : ");
187         ISCRUTE_MED(gid); ret = -1;
188       }
189
190       return ret;
191     }
192
193 #undef MESSAGE_MED
194 #undef SSCRUTE_MED
195 #undef ISCRUTE_MED
196
197   }
198 }