1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "MEDMEM_MEDMEMgaussEcr.hxx"
25 * En attendant une correction de la gestion du mode d'accès au fichier dans MEDfichier
26 * on intègre la correction ici.
33 fprintf(stderr, "%s [%d] : " , __FILE__ , __LINE__ ) ;\
37 # define ISCRUTE_MED(entier) {\
39 fprintf(stderr,"%s = %d\n",#entier,entier) ;\
43 # define SSCRUTE_MED(chaine) {\
45 fprintf(stderr,"%s = \"%s\"\n",#chaine,chaine) ;\
48 # define MESSAGE_MED(chaine) {\
50 fprintf(stderr,"%s\n",chaine) ;\
54 extern void _MEDmodeErreurVerrouiller(void);
57 * - Nom de la fonction : MEDgaussEcr
58 * - Description : Itérateur renvoyant (n°pdt,n°or), le nbre de point de GAUSS pour le type d'élément,
59 * et le maillage par défaut avec son eventuel lien à un autre fichier.
61 * - fid (IN) : ID du fichier HDF courant
62 * - type_geo (IN) : Le type géométrique de l'entité concerné {MED_POINT,MED_SEG2 ......}
63 * - refcoo (IN) : Les coordonnées des noeuds de l'élément de référence (tableau de taille(typegeo%100)*(typegeo/100) )
64 * - mode_coo (IN) : Choix du type d'entrelacement utilisé en mémoire pour refcoo et gscoo
65 * { MED_FULL_INTERLACE(x1,y1,z1,x2,...)) , MED_NO_INTERLACE(x1,x2,y1,y2,z1,z2) }
66 * - ngauss (IN) : Nombre de points de Gauss pour l'élément de référence considéré
67 * - gscoo (IN) : Les coordonnées des points de Gauss pour l'élément de référence (tableau de taille ngauss*type_geo/100)
68 * - wg (IN) : Poids à appliquer aux points d'intégration (tableau de taille ngauss)
69 * - locname (IN) : Nom à associer à la localisation (MED_TAILLe_NOM)
72 <locname> est à passer en paramètre de MEDchampEcrire.
76 MEDMEMgaussEcr(med_idt fid, med_geometrie_element type_geo, med_float *refcoo, med_mode_switch mode_coo,
77 med_int ngauss, med_float *gscoo, med_float * wg, char * locname )
79 med_idt gid=0, chid=0;
83 char chemin[MED_TAILLE_GAUSS+1]="";
86 * On inhibe le gestionnaire d'erreur HDF 5
88 _MEDmodeErreurVerrouiller();
91 * Si le groupe "GAUSS" n'existe pas, on le cree
93 strncpy(chemin,MED_GAUSS,MED_TAILLE_GAUSS-1);
94 chemin[MED_TAILLE_GAUSS-1] = '\0';
95 if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
96 if ((gid = _MEDdatagroupCreer(fid,chemin)) < 0) {
97 MESSAGE_MED("Impossible de creer le groupe MED_GAUSS : ");
98 SSCRUTE_MED(chemin); goto ERROR;
102 * Si le groupe <locname> n'existe pas, on le cree
105 if ((chid = _MEDdatagroupOuvrir(gid,locname)) >= 0) {
106 if ( false )//MED_MODE_ACCES != MED_LECTURE_ECRITURE )
108 MESSAGE_MED("Le nom de localisation existe déjà : ");
109 SSCRUTE_MED(locname); goto ERROR;
112 if ((chid = _MEDdatagroupCreer(gid,locname)) < 0)
116 * On stocke <ngauss> sous forme d'attribut
118 if (_MEDattrEntierEcrire(chid,MED_NOM_NBR,&ngauss) < 0) {
119 MESSAGE_MED("Erreur à l'écriture de l'attribut MED_NOM_NBR : ");
120 ISCRUTE_MED(ngauss);goto ERROR;
124 * On stocke <type_geo> sous forme d'attribut
126 typegeo = (med_int) type_geo;
127 /* sizeof(enum) tjrs = sizeof(int) en C, or
128 sur machines 64 bits par défaut med_int==long,
129 du coup sur machines 64 bits _MEDattrEntierEcrire utilise
130 le type hdf NATIVE_LONG, ce qui pose un problème qd on passe
133 if (_MEDattrEntierEcrire(chid,MED_NOM_GEO,&typegeo) < 0) {
134 MESSAGE_MED("Erreur à l'écriture de l'attribut MED_NOM_GEO : ");
135 ISCRUTE_MED(type_geo);goto ERROR;
140 * On stocke les coordonnées de référence dans un dataset
143 dimd[0] = (type_geo%100)*(type_geo/100);
144 if ( _MEDdatasetNumEcrire(chid,MED_NOM_COO,MED_FLOAT64,mode_coo,(type_geo/100),MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
145 (unsigned char*) refcoo) < 0 ) {
146 MESSAGE_MED("Impossible d'ecrire le dataset : ");SSCRUTE_MED(MED_NOM_COO);
147 ISCRUTE_MED(dimd); goto ERROR;
151 * On stocke les points d'intégration dans un dataset
154 dimd[0] = ngauss*(type_geo/100);
155 if ( _MEDdatasetNumEcrire(chid,MED_NOM_GAU,MED_FLOAT64,mode_coo,(type_geo/100),MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
156 (unsigned char*) gscoo) < 0 ) {
157 MESSAGE_MED("Impossible d'ecrire le dataset : ");SSCRUTE_MED(MED_NOM_GAU);
158 ISCRUTE_MED(dimd); goto ERROR;
162 * On stocke les poids dans un dataset
166 if ( _MEDdatasetNumEcrire(chid,MED_NOM_VAL,MED_FLOAT64,mode_coo,1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd,
167 (unsigned char*) wg) < 0 ) {
168 MESSAGE_MED("Impossible d'ecrire le dataset : ");SSCRUTE_MED(MED_NOM_VAL);
169 ISCRUTE_MED(dimd); goto ERROR;
181 if (chid>0) if (_MEDdatagroupFermer(chid) < 0) {
182 MESSAGE_MED("Impossible de fermer le datagroup : ");
183 ISCRUTE_MED(chid); ret = -1;
186 if (gid>0) if (_MEDdatagroupFermer(gid) < 0) {
187 MESSAGE_MED("Impossible de fermer le datagroup : ");
188 ISCRUTE_MED(gid); ret = -1;