00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <med.h>
00020 #include <med_config.h>
00021 #include <med_outils.h>
00022
00023 #include <string.h>
00024 #include <stdlib.h>
00025
00036 med_err
00037 MEDequivalenceCr(const med_idt fid,
00038 const char * const meshname,
00039 const char * const equivname,
00040 const char * const description)
00041 {
00042 med_access_mode _MED_ACCESS_MODE;
00043 med_idt _root=0,_eqid=0,_meshid=0;
00044 med_err _ret=-1;
00045 char _path[MED_TAILLE_EQS+MED_NAME_SIZE+1]=MED_EQS;
00046
00047
00048
00049
00050 _MEDmodeErreurVerrouiller();
00051 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
00052
00053 if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
00054 MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00055 goto ERROR;
00056 }
00057
00058 if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
00059 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00060 ISCRUTE_int(_MED_ACCESS_MODE);
00061 goto ERROR;
00062 }
00063
00064
00065
00066
00067 if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0)
00068 if ((_root = _MEDdatagroupCreer(fid,_path)) < 0) {
00069 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
00070 goto ERROR;
00071 }
00072
00073 NOFINALBLANK(meshname,ERROR);
00074
00075
00076
00077
00078 if ((_meshid = _MEDdatagroupOuvrir(_root,meshname)) < 0)
00079 if ((_meshid = _MEDdatagroupCreer(_root,meshname)) < 0) {
00080 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,meshname);
00081 SSCRUTE(_path);goto ERROR;
00082 }
00083
00084 strcat(_path,meshname);
00085 NOFINALBLANK(equivname,ERROR);
00086
00087
00088
00089
00090 if ((_eqid = _MEDdatagroupOuvrir(_meshid,equivname)) < 0)
00091 if ((_eqid = _MEDdatagroupCreer(_meshid,equivname)) < 0 ) {
00092 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,equivname);
00093 SSCRUTE(_path);goto ERROR;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 if ((_ret = _MEDattributeStringWr(_eqid,MED_NOM_DES,MED_COMMENT_SIZE,
00114 description)) < 0) {
00115 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_EQUIVALENCE_MSG);
00116 SSCRUTE(equivname);SSCRUTE(description);
00117
00118 goto ERROR;
00119 }
00120
00121
00122 _ret=0;
00123 ERROR:
00124
00125 if (_eqid>0) if (_MEDdatagroupFermer(_eqid) < 0) {
00126 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,equivname);
00127 ISCRUTE_id(_eqid);SSCRUTE(_path);
00128 }
00129
00130 if (_meshid>0) if (_MEDdatagroupFermer(_meshid) < 0) {
00131 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
00132 ISCRUTE_id(_eqid);
00133 }
00134
00135 if (_root>0) if (_MEDdatagroupFermer(_root) < 0) {
00136 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_EQS);
00137 ISCRUTE_id(_eqid);
00138 }
00139
00140 return _ret;
00141 }
00142
00143
00144