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
MEDpolygoneConnEcr(med_idt fid,char * maa,med_int * index,med_int ni,med_int * con,med_entite_maillage type_ent,med_connectivite type_conn)27 MEDpolygoneConnEcr(med_idt fid, char *maa, med_int *index, med_int ni,
28 med_int *con, med_entite_maillage type_ent,
29 med_connectivite type_conn)
30 {
31 med_err ret;
32 med_idt maaid, entid, geoid, dataset;
33 char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
34 char nom_ent[MED_TAILLE_NOM_ENTITE+1];
35 char nom_geo[MED_TAILLE_NOM_ENTITE+1];
36 char nom_dataset1[MED_TAILLE_NOM_ENTITE+1], nom_dataset2[MED_TAILLE_NOM_ENTITE+1];
37 med_geometrie_element type_geo = MED_POLYGONE;
38 med_int n;
39 med_size dimd[1];
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 groupe HDF representant
61 * le type des entites
62 */
63 if ((ret = _MEDnomEntite(nom_ent,_type_ent)) < 0)
64 return -1;
65
66 /*
67 * Si le groupe HDF des entites n'existe pas on le cree
68 */
69 if ((entid = _MEDdatagroupOuvrir(maaid,nom_ent)) < 0)
70 if ((entid = _MEDdatagroupCreer(maaid,nom_ent)) < 0)
71 return -1;
72
73 /*
74 * On cree s'il n'existe pas le groupe HDF du type geometrique
75 */
76 if ((ret = _MEDnomGeometrie(nom_geo,type_geo)) < 0)
77 return -1;
78 if ((geoid = _MEDdatagroupOuvrir(entid,nom_geo)) < 0)
79 if ((geoid = _MEDdatagroupCreer(entid,nom_geo)) < 0)
80 return -1;
81
82 /*
83 * On regarde si le dataset HDF existe et on le cree sinon
84 */
85 switch(type_conn)
86 {
87 case MED_NOD :
88 strcpy(nom_dataset1,MED_NOM_INN);
89 strcpy(nom_dataset2,MED_NOM_NOD);
90 break;
91
92 case MED_DESC :
93 strcpy(nom_dataset1,MED_NOM_IND);
94 strcpy(nom_dataset2,MED_NOM_DES);
95 break;
96
97 default :
98 return -1;
99 }
100
101 #if defined(HAVE_F77INT64)
102 dimd[0] = ni;
103 if ((ret = _MEDdatasetNumEcrire(geoid,nom_dataset1,MED_INT64,MED_NO_INTERLACE,1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
104 (unsigned char*) index)) < 0)
105 return -1;
106 dimd[0] = index[ni-1] - index[0] ;
107 if ((ret = _MEDdatasetNumEcrire(geoid,nom_dataset2,MED_INT64,MED_NO_INTERLACE,1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
108 (unsigned char*) con)) < 0)
109 return -1;
110 #else
111 dimd[0] = ni;
112 if ((ret = _MEDdatasetNumEcrire(geoid,nom_dataset1,MED_INT32,MED_NO_INTERLACE,1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
113 (unsigned char*) index)) < 0)
114 return -1;
115 dimd[0] = index[ni-1] - index[0] ;
116 if ((ret = _MEDdatasetNumEcrire(geoid,nom_dataset2,MED_INT32,MED_NO_INTERLACE,1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
117 (unsigned char*) con)) < 0)
118 return -1;
119 #endif
120
121 /*
122 * On stocke le nombre d'elements du tableau "con"
123 * et le nombre de polygones
124 */
125 n = ni - 1;
126 if ((dataset = _MEDdatasetOuvrir(geoid,nom_dataset2)) < 0)
127 return -1;
128 if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_NBR,&n)) < 0)
129 return -1;
130 if ((ret = _MEDdatasetFermer(dataset)) < 0)
131 return -1;
132
133 n = index[ni-1] - index[0] ;
134 if ((dataset = _MEDdatasetOuvrir(geoid,nom_dataset2)) < 0)
135 return -1;
136 if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_TAI,&n)) < 0)
137 return -1;
138 if ((ret = _MEDdatasetFermer(dataset)) < 0)
139 return -1;
140
141 /*
142 * On ferme tout
143 */
144 if ((ret = _MEDdatagroupFermer(geoid)) < 0)
145 return -1;
146 if ((ret = _MEDdatagroupFermer(entid)) < 0)
147 return -1;
148 if ((ret = _MEDdatagroupFermer(maaid)) < 0)
149 return -1;
150
151 return ret;
152 }
153