Salome HOME
Copyrights update
[modules/med.git] / src / MEDWrapper / V2_1 / MEDconnEcr.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library 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 GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 /*************************************************************************
21 * COPYRIGHT (C) 1999 - 2002  EDF R&D
22 * THIS LIBRARY IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
23 * IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE 
24 * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
25 * EITHER VERSION 2.1 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
26 *  
27 * THIS LIBRARY IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
28 * WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
29 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
30 * LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
31 *
32 * YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE
33 * ALONG WITH THIS LIBRARY; IF NOT, WRITE TO THE FREE SOFTWARE FOUNDATION,
34 * INC., 59 TEMPLE PLACE, SUITE 330, BOSTON, MA 02111-1307 USA
35 *
36 *************************************************************************/
37
38 #include "med.hxx"
39 #include "med_outils.hxx"
40
41 #include <string.h>
42 #include <stdlib.h>
43
44 extern int mode_interlace; 
45
46 namespace med_2_1{
47
48 med_err 
49 MEDconnEcr(med_idt fid,char *maa, med_int mdim, med_int *connectivite,med_mode_switch mode_switch,
50            med_int nbre,med_mode_acces mode,med_entite_maillage type_ent,
51            med_geometrie_element type_geo,med_connectivite type_conn)
52 {
53   med_idt maaid, entid, geoid, dataset;
54   med_err ret;
55   med_size dimd[1];
56   char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
57   char nom_ent[MED_TAILLE_NOM_ENTITE+1];
58   char nom_geo[MED_TAILLE_NOM_ENTITE+1];
59   char nom_dataset[MED_TAILLE_NOM_ENTITE+1];
60   int dim, nnoe, ndes;
61   int nsup = 0;
62   int taille;
63   
64   /*
65    * On inhibe le gestionnaire d'erreur HDF 5
66    */
67   _MEDmodeErreurVerrouiller();
68
69   /*
70    * Si le maillage n'existe pas => erreur
71    */
72   strcpy(chemin,MED_MAA);
73   strcat(chemin,maa);
74   if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
75       return -1;
76
77   /*
78    * On met a jour le nom du Data Group representant
79    * le type des entites
80    */
81    if ((ret = _MEDnomEntite(nom_ent,type_ent)) < 0)
82      return -1;
83    /*
84     * Si le Data Group des entites n'existe pas on le cree
85     */
86    /*EF Gerer le mode */
87    if ((entid = _MEDdatagroupOuvrir(maaid,nom_ent)) < 0)
88      if ((entid = _MEDdatagroupCreer(maaid,nom_ent)) < 0)
89        return -1;
90
91    /*
92     * On cree s'il n'existe pas le Data Group du type geometrique
93     */
94    /*EF Gerer le mode */
95   if ((ret = _MEDnomGeometrie(nom_geo,type_geo)) < 0)
96      return -1;
97    if ((geoid = _MEDdatagroupOuvrir(entid,nom_geo)) < 0)
98      if ((geoid = _MEDdatagroupCreer(entid,nom_geo)) < 0)
99        return -1;
100
101    /*
102     * On regarde si le Data Set existe et on le cree sinon
103     */
104    if ((ret=_MEDparametresGeometrie(type_ent,type_geo,&dim,&nnoe,&ndes))<0)
105      return -1;
106    if (mdim == 2 || mdim == 3)
107      if (type_ent == MED_MAILLE && dim == 1)
108        nsup = 1;
109    if (mdim == 3)
110      if (type_ent == MED_MAILLE && dim == 2)
111        nsup = 1;
112    switch(type_conn)
113      {
114      case MED_NOD :
115        strcpy(nom_dataset,MED_NOM_NOD);
116        taille = nsup + nnoe;
117        break;
118
119      case MED_DESC :
120        strcpy(nom_dataset,MED_NOM_DES);
121        taille = nsup + ndes;
122        break;
123        
124      default :
125        return -1;
126      }
127    dimd[0] = nbre*taille;
128 #if defined(IRIX64)||defined(OSF1)
129    if ((ret = _MEDdatasetNumEcrire(geoid,nom_dataset,MED_INT64,mode_switch,(med_size)taille,MED_ALL,MED_NOPF,0,MED_NOPG,dimd,
130                                     (unsigned char*) connectivite,mode)) < 0)
131      return -1;
132 #else
133    if ((ret = _MEDdatasetNumEcrire(geoid,nom_dataset,MED_INT32,mode_switch,(med_size)taille,MED_ALL,MED_NOPF,0,MED_NOPG,dimd,
134                                     (unsigned char*) connectivite,mode)) < 0)
135      return -1;
136 #endif
137
138   /*
139    * Attribut NBR (nombre de noeuds ou d'elements)
140    */
141    if ((dataset = _MEDdatasetOuvrir(geoid,nom_dataset)) < 0)
142      return -1;
143    if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_NBR,&nbre,mode)) < 0)
144      return -1;
145
146    /*
147     * On ferme tout 
148     */
149    if ((ret = _MEDdatasetFermer(dataset)) < 0)
150      return -1;
151    if ((ret = _MEDdatagroupFermer(geoid)) < 0)
152      return -1;
153    if ((ret = _MEDdatagroupFermer(entid)) < 0)
154      return -1;
155    if ((ret = _MEDdatagroupFermer(maaid)) < 0)
156      return -1;
157
158   return 0; 
159 }
160
161 }