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 
27 /**\ingroup MEDsubdomainJoint
28    \brief \MEDsubdomainJointCrBrief
29    \param fid \fid
30    \param localmeshname \localmeshname
31    \param jointname \jointname
32    \param description \description
33    \param domainnumber \domainnumber
34    \param remotemeshname \remotemeshname
35    \return \error
36    \details
37    \MEDsubdomainJointCrDetails
38    \par Remarques
39    \MEDjointDef
40 */
41 
42 med_err
MEDsubdomainJointCr(const med_idt fid,const char * const localmeshname,const char * const jointname,const char * const description,const med_int domainnumber,const char * const remotemeshname)43 MEDsubdomainJointCr(const med_idt      fid,
44 		    const char * const localmeshname,
45 		    const char * const jointname,
46 		    const char * const description,
47 		    const med_int      domainnumber,
48 		    const char * const remotemeshname)
49 {
50   med_access_mode _MED_ACCESS_MODE;
51   med_idt        _root=0,_jntid=0,_meshid=0;
52   med_err        _ret=-1;
53   char           _path[MED_JOINT_GRP_SIZE+MED_NAME_SIZE+1]=MED_JOINT_GRP;
54 
55   /*
56    * On inhibe le gestionnaire d'erreur
57    */
58   _MEDmodeErreurVerrouiller();
59  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
60 
61   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
62     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
63     goto ERROR;
64   }
65 
66   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
67     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
68     ISCRUTE_int(_MED_ACCESS_MODE);
69     goto ERROR;
70   }
71 
72   /*
73    * Si le DataGroup /JNT/ n'existe pas, on le cree
74    */
75   if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0)
76     if ((_root = _MEDdatagroupCreer(fid,_path)) < 0) {
77       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
78      goto ERROR;
79     }
80 
81   NOFINALBLANK(localmeshname,ERROR);
82 
83   /*
84    * Si le DataGroup /JNT/<localmeshname> n'existe pas, on le cree
85    */
86   if ((_meshid = _MEDdatagroupOuvrir(_root,localmeshname)) < 0)
87     if ((_meshid = _MEDdatagroupCreer(_root,localmeshname)) < 0) {
88       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,localmeshname);
89       SSCRUTE(_path);goto ERROR;
90     }
91 
92   strcat(_path,localmeshname);
93   NOFINALBLANK(jointname,ERROR);
94 
95   /*
96    * Si le Data Group "/JNT/<localmeshname>/<jointname>" n'existe pas, on le cree
97    */
98   if ((_jntid = _MEDdatagroupOuvrir(_meshid,jointname)) < 0)
99     if ((_jntid = _MEDdatagroupCreer(_meshid,jointname)) < 0 ) {
100       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,jointname);
101       SSCRUTE(_path);goto ERROR;
102     }
103 
104  /*  if ( (_jntid = _MEDmeshAssociatedGroupCr(fid, */
105 /* 					  MED_JOINT_NAME, */
106 /* 					  localmeshname, */
107 /* 					  numdt, */
108 /* 					  numit, */
109 /* 					  -1, */
110 /* 					  MED_FALSE, */
111 /* 					  subdomainJointname ) ) < 0)  { */
112 /*     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDmeshAssociatedGroupCr"); */
113 /*     SSCRUTE(MED_JOINT_NAME);SSCRUTE(localmeshname);ISCRUTE(numit);ISCRUTE(numdt); */
114 /*     SSCRUTE(subdomainJointname); */
115 /*     goto ERROR; */
116 /*   } */
117 
118   /*
119    * L'attribut "DES"
120    */
121   if ((_ret = _MEDattributeStringWr(_jntid,MED_NOM_DES,MED_COMMENT_SIZE,
122 				   description)) < 0) {
123     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_SUBDOMAINJOINT_MSG);
124     SSCRUTE(jointname);SSCRUTE(MED_NOM_DES);SSCRUTE(description);
125     goto ERROR;
126   }
127 
128   /*
129    * L'attribut "MAI"
130    */
131   if ((_ret = _MEDattributeStringWr(_jntid,MED_NOM_MAI,MED_NAME_SIZE,
132 				   remotemeshname)) < 0) {
133     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_SUBDOMAINJOINT_MSG);
134     SSCRUTE(jointname);SSCRUTE(MED_NOM_MAI);SSCRUTE(remotemeshname);
135     goto ERROR;
136   }
137 
138   /*
139    * L'attribut "DOM"
140    */
141   if ((_ret = _MEDattributeIntWr(_jntid, MED_NOM_DOM, &domainnumber)) < 0) {
142     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_SUBDOMAINJOINT_MSG);
143     SSCRUTE(jointname);SSCRUTE(MED_NOM_DOM);ISCRUTE(domainnumber);
144     goto ERROR;
145   }
146 
147 
148   _ret=0;
149  ERROR:
150 
151   if (_jntid>0)            if (_MEDdatagroupFermer(_jntid) < 0) {
152     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,jointname);
153     ISCRUTE_id(_jntid);SSCRUTE(_path);
154   }
155 
156   if (_meshid>0)            if (_MEDdatagroupFermer(_meshid) < 0) {
157     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
158     ISCRUTE_id(_jntid);
159   }
160 
161   if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
162     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_JOINT_GRP);
163     ISCRUTE_id(_jntid);
164   }
165 
166   return _ret;
167 }
168 
169 
170 
171