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 #include <string.h>
23 #include <stdlib.h>
24 
25 void
MEDjointCr231(int dummy,...)26 MEDjointCr231(int dummy,...) {
27 
28 
29   med_idt   fid      ;
30   char *    maa_lcl  ;
31   char *    jn       ;
32   char *    desc     ;
33   med_int   dom      ;
34   char *    maa_dist ;
35   med_err * fret     ;
36 
37   med_idt root=0,jntid=0;
38   med_err ret=-1;
39   char chemin[MED_TAILLE_MAA+MED_TAILLE_JNT+MED_TAILLE_NOM+1];
40   char tmp[MED_TAILLE_JNT+1];
41   med_int nbc=0;
42   med_mode_acces MED_MODE_ACCES;
43 
44   va_list params;
45   va_start(params,dummy);
46 
47   fid      = va_arg(params,med_idt);
48   maa_lcl  = va_arg(params,char *);
49   jn       = va_arg(params,char *);
50   desc     = va_arg(params,char *);
51   dom      = va_arg(params,med_int);
52   maa_dist = va_arg(params,char*);
53   fret     = va_arg(params,med_err *);
54 
55   /*
56    * On inhibe le gestionnaire d'erreur
57    */
58   _MEDmodeErreurVerrouiller();
59 if (MEDcheckVersion(fid) < 0) {*fret=-1;return;}
60 
61 
62   if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
63     MESSAGE("Impossible de déterminer le mode d'acces au fichier.");
64     goto ERROR;
65   }
66 
67   if ( MED_MODE_ACCES == MED_LECTURE ) {
68     MESSAGE("Impossible de créer un joint en mode MED_LECTURE.");
69     goto ERROR;
70   };
71 
72   /*
73    * Si le Data Group "JNT" n'existe pas, on le cree
74    */
75   strcpy(chemin,MED_MAA);
76   NOFINALBLANK(maa_lcl,ERROR);
77   strcat(chemin,maa_lcl);
78   strncpy(tmp,MED_JNT,MED_TAILLE_JNT-1);
79   tmp[MED_TAILLE_JNT-1] = '\0';
80   strcat(chemin,tmp);
81   if ((root = _MEDdatagroupOuvrir(fid,chemin)) < 0)
82     if ((root = _MEDdatagroupCreer(fid,chemin)) < 0) {
83       MESSAGE("Erreur à la création du datagroup : ");
84       SSCRUTE(chemin);
85       goto ERROR;
86     }
87 
88   /*
89    * Si un joint du meme nom existe => erreur
90    * Sinon on le cree
91    */
92   NOFINALBLANK(jn,ERROR);
93   if ((jntid = _MEDdatagroupCreer(root,jn)) < 0) {
94     MESSAGE("Erreur à la création du joint : ");
95     SSCRUTE(jn);
96     goto ERROR;
97   }
98 
99   /*
100    * L'attribut "DES"
101    */
102   if ((ret = _MEDattrStringEcrire(jntid,MED_NOM_DES,MED_TAILLE_DESC,desc)) < 0) {
103     MESSAGE("Erreur à l'écriture de la description du joint : ");
104     SSCRUTE(desc);
105     goto ERROR;
106   }
107 
108   /*
109    * L'attribut "MAI"
110    */
111   /* BUG CORRIGE EN 232 MED_TAILLE_NOM au lieu de MED_TAILLE_MAA */
112   /* conservé ici pour éviter de reprendre en lib2.3.2 un fichier 2.3.1
113      en écrivant l'attribut avec une taille plus grande que celle des fichiers 2.3.1 */
114   if ((ret = _MEDattrStringEcrire(jntid,MED_NOM_MAI,MED_TAILLE_MAA,maa_dist)) < 0) {
115     MESSAGE("Erreur à l'écriture du nom du maillage distant : ");
116     SSCRUTE(maa_dist);
117     goto ERROR;
118   }
119 
120   /*
121    * L'attribut "DOM"
122    */
123   if ((ret = _MEDattrEntierEcrire(jntid,MED_NOM_DOM,&dom)) < 0) {
124     MESSAGE("Erreur à l'écriture du domaine : ");
125     ISCRUTE(dom);
126     goto ERROR;
127   }
128 
129   /*
130    * On ferme tout
131    */
132   ret=0;
133  ERROR:
134 
135   if (jntid>0)     if (_MEDdatagroupFermer(jntid) < 0) {
136     MESSAGE("Impossible de fermer le datagroup : ");
137     ISCRUTE_id(jntid);ret = -1;
138   }
139 
140   if (root>0)     if (_MEDdatagroupFermer(root) < 0) {
141     MESSAGE("Impossible de fermer le datagroup : ");
142     ISCRUTE_id(root); ret = -1;
143   }
144 
145   va_end(params);
146   *fret = ret;
147   return;
148 }
149 
150 
151 
152