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 #include <med.h>
20 #include <med_config.h>
21 #include <med_outils.h>
22
23 #include <string.h>
24 #include <stdlib.h>
25
26 med_err
MEDconnEcr(med_idt fid,char * maa,med_int mdim,med_int * connectivite,med_mode_switch mode_switch,med_int nbre,med_entite_maillage type_ent,med_geometrie_element type_geo,med_connectivite type_conn)27 MEDconnEcr(med_idt fid,char *maa, med_int mdim, med_int *connectivite,med_mode_switch mode_switch,
28 med_int nbre, med_entite_maillage type_ent,
29 med_geometrie_element type_geo,med_connectivite type_conn)
30 {
31 med_idt maaid, entid, geoid, dataset;
32 med_err ret;
33 med_size dimd[1];
34 char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
35 char nom_ent[MED_TAILLE_NOM_ENTITE+1];
36 char nom_geo[MED_TAILLE_NOM_ENTITE+1];
37 char nom_dataset[MED_TAILLE_NOM_ENTITE+1];
38 int dim, nnoe, ndes;
39 int taille;
40 med_entite_maillage _type_ent=type_ent;
41
42 if ( type_ent == MED_NOEUD_MAILLE ) _type_ent=MED_NOEUD ;
43
44 /*
45 * On inhibe le gestionnaire d'erreur HDF 5
46 */
47 _MEDmodeErreurVerrouiller();
48 if (MEDcheckVersion(fid) < 0) return -1;
49
50
51 /*
52 * Si le maillage n'existe pas => erreur
53 */
54 strcpy(chemin,MED_MAA);
55 strcat(chemin,maa);
56 if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
57 return -1;
58
59 /*
60 * On met a jour le nom du Data Group representant
61 * le type des entites
62 */
63 if ((ret = _MEDnomEntite(nom_ent,_type_ent)) < 0)
64 return -1;
65 /*
66 * Si le Data Group des entites n'existe pas on le cree
67 */
68 if ((entid = _MEDdatagroupOuvrir(maaid,nom_ent)) < 0)
69 if ((entid = _MEDdatagroupCreer(maaid,nom_ent)) < 0)
70 return -1;
71
72 /*
73 * On cree s'il n'existe pas le Data Group du type geometrique
74 */
75 if ((ret = _MEDnomGeometrie(nom_geo,type_geo)) < 0)
76 return -1;
77 if ((geoid = _MEDdatagroupOuvrir(entid,nom_geo)) < 0)
78 if ((geoid = _MEDdatagroupCreer(entid,nom_geo)) < 0)
79 return -1;
80
81 /*
82 * On regarde si le Data Set existe et on le cree sinon
83 */
84 if ((ret=_MEDparametresGeometrie(_type_ent,type_geo,&dim,&nnoe,&ndes))<0)
85 return -1;
86
87 switch(type_conn)
88 {
89 case MED_NOD :
90 strcpy(nom_dataset,MED_NOM_NOD);
91 taille = nnoe;
92 break;
93
94 case MED_DESC :
95 strcpy(nom_dataset,MED_NOM_DES);
96 taille = ndes;
97 break;
98
99 default :
100 return -1;
101 }
102 dimd[0] = nbre*taille;
103 #if defined(HAVE_F77INT64)
104 ret = _MEDdatasetNumEcrire(geoid,nom_dataset,MED_INT64,mode_switch,(med_size)taille,MED_ALL,
105 MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
106 (unsigned char*) connectivite);
107 #else
108 ret = _MEDdatasetNumEcrire(geoid,nom_dataset,MED_INT32,mode_switch,(med_size)taille,MED_ALL,
109 MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
110 (unsigned char*) connectivite);
111 #endif
112 if (ret < 0 ) {
113 MESSAGE("Impossible d'ecrire le dataset coon de taille : ");
114 ISCRUTE_int(taille); return -1;
115 }
116
117 /*
118 * Attribut NBR (nombre de noeuds ou d'elements)
119 */
120 if ((dataset = _MEDdatasetOuvrir(geoid,nom_dataset)) < 0)
121 return -1;
122 if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_NBR,&nbre)) < 0)
123 return -1;
124
125 /*
126 * On ferme tout
127 */
128 if ((ret = _MEDdatasetFermer(dataset)) < 0)
129 return -1;
130 if ((ret = _MEDdatagroupFermer(geoid)) < 0)
131 return -1;
132 if ((ret = _MEDdatagroupFermer(entid)) < 0)
133 return -1;
134 if ((ret = _MEDdatagroupFermer(maaid)) < 0)
135 return -1;
136
137 return 0;
138 }
139
140
141