1 // Copyright (C) 2007-2008 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
22 #include "MEDMEM_MEDMEMgaussEcr.hxx"
24 * En attendant une correction de la gestion du mode d'accès au fichier dans MEDfichier
25 * on intègre la correction ici.
32 fprintf(stderr, "%s [%d] : " , __FILE__ , __LINE__ ) ;\
36 # define ISCRUTE_MED(entier) {\
38 fprintf(stderr,"%s = %d\n",#entier,entier) ;\
42 # define SSCRUTE_MED(chaine) {\
44 fprintf(stderr,"%s = \"%s\"\n",#chaine,chaine) ;\
47 # define MESSAGE_MED(chaine) {\
49 fprintf(stderr,"%s\n",chaine) ;\
53 extern void _MEDmodeErreurVerrouiller(void);
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.
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)
71 <locname> est à passer en paramètre de MEDchampEcrire.
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 )
78 med_idt gid=0, chid=0;
82 char chemin[MED_TAILLE_GAUSS+1]="";
85 * On inhibe le gestionnaire d'erreur HDF 5
87 _MEDmodeErreurVerrouiller();
90 * Si le groupe "GAUSS" n'existe pas, on le cree
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;
101 * Si le groupe <locname> n'existe pas, on le cree
104 if ((chid = _MEDdatagroupOuvrir(gid,locname)) >= 0) {
105 if ( false )//MED_MODE_ACCES != MED_LECTURE_ECRITURE )
107 MESSAGE_MED("Le nom de localisation existe déjà : ");
108 SSCRUTE_MED(locname); goto ERROR;
111 if ((chid = _MEDdatagroupCreer(gid,locname)) < 0)
115 * On stocke <ngauss> sous forme d'attribut
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;
123 * On stocke <type_geo> sous forme d'attribut
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
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;
139 * On stocke les coordonnées de référence dans un dataset
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;
150 * On stocke les points d'intégration dans un dataset
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;
161 * On stocke les poids dans un dataset
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;
180 if (chid>0) if (_MEDdatagroupFermer(chid) < 0) {
181 MESSAGE_MED("Impossible de fermer le datagroup : ");
182 ISCRUTE_MED(chid); ret = -1;
185 if (gid>0) if (_MEDdatagroupFermer(gid) < 0) {
186 MESSAGE_MED("Impossible de fermer le datagroup : ");
187 ISCRUTE_MED(gid); ret = -1;