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
00026 med_err
00027 _MEDmeshCr(const med_idt fid, const char * const root,
00028 const char * const meshname, const med_int spacedim,
00029 const med_int meshdim, const med_mesh_type meshtype,
00030 const char * const description, const char * const dtunit,
00031 const med_sorting_type sortingtype,
00032 const med_axis_type axistype, const char * const axisname,
00033 const char * const axisunit)
00034 {
00035
00036 med_access_mode _MED_ACCESS_MODE;
00037 med_err _ret=-1;
00038 med_idt _root=0,_datagroup1=0;
00039
00040 med_int _intmeshtype = (med_int) meshtype;
00041 med_int _intaxistype = (med_int) axistype;
00042 char _datagroupname1[MED_NAME_SIZE+1]="";
00043
00044 med_int _lastnumdt=MED_NO_DT, _lastnumit=MED_NO_IT;
00045 med_int _intsortingtype =(med_int) MED_SORT_UNDEF;
00046 med_int _intexistingmeshtype=(med_int) MED_UNDEF_MESH_TYPE;
00047 med_mesh_type _existingmeshtype = meshtype;
00048 med_sorting_type _existingsortingtype = sortingtype;;
00049 med_size _nstep=0;
00050
00051
00052
00053
00054 _MEDmodeErreurVerrouiller();
00055 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
00056
00057 if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
00058 MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00059 goto ERROR;
00060 }
00061
00062 if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
00063 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00064 ISCRUTE_int(_MED_ACCESS_MODE);
00065 goto ERROR;
00066 }
00067
00068 if ( sortingtype == MED_SORT_UNDEF) {
00069 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_PARAMETER,"sortingtype");
00070 ISCRUTE_int(sortingtype);
00071 goto ERROR;
00072 }
00073
00074
00075
00076
00077 if ((_root = _MEDdatagroupOuvrir(fid,root)) < 0)
00078 if ((_root = _MEDdatagroupCreer(fid,root)) < 0) {
00079 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,root);
00080 goto ERROR;
00081 }
00082
00083 NOFINALBLANK(meshname,ERROR);
00084
00085
00086
00087 if ((_datagroup1 = _MEDdatagroupOuvrir(_root,meshname)) < 0)
00088 if ((_datagroup1 = _MEDdatagroupCreer(_root,meshname)) < 0 ) {
00089 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,meshname);
00090 goto ERROR;
00091 }
00092
00093
00094
00095
00096 if (meshdim > spacedim) {
00097 MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,"meshdim");
00098 ISCRUTE(meshdim);ISCRUTE(spacedim);
00099 SSCRUTE(root);SSCRUTE(meshname);goto ERROR;
00100 }
00101
00102
00103
00104
00105 if ( _MEDattributeIntWr(_datagroup1,MED_NOM_ESP,&spacedim) < 0 ) {
00106 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00107 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_ESP);
00108 ISCRUTE(spacedim);goto ERROR;
00109 }
00110
00111
00112
00113
00114 if ( _MEDattributeIntWr(_datagroup1,MED_NOM_DIM,&meshdim) < 0 ) {
00115 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00116 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_DIM);
00117 ISCRUTE(meshdim);goto ERROR;
00118 }
00119
00120
00121 if (_MEDattrEntierLire(_datagroup1,MED_NOM_TYP,&_intexistingmeshtype) >= 0)
00122 _existingmeshtype = (med_mesh_type) (_intexistingmeshtype);
00123
00124 if ( _existingmeshtype != meshtype ) {
00125 MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_WRITE,MED_ERR_ATTRIBUTE_MSG);
00126 SSCRUTE(MED_NOM_TYP);SSCRUTE(meshname);SSCRUTE(_datagroupname1);
00127 ISCRUTE_int(_existingmeshtype);ISCRUTE_int(meshtype);goto ERROR;
00128
00129 }
00130
00131
00132
00133
00134 if ( _MEDattributeIntWr(_datagroup1,MED_NOM_TYP,&_intmeshtype) < 0) {
00135 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00136 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_TYP);
00137 ISCRUTE(_intmeshtype);goto ERROR;
00138 }
00139
00140
00141
00142
00143 if ( _MEDattributeStringWr(_datagroup1,MED_NOM_DES,MED_COMMENT_SIZE,description) < 0) {
00144 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00145 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_DES);
00146 SSCRUTE(description);goto ERROR;
00147 }
00148
00149
00150
00151
00152
00153 if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNT,MED_SNAME_SIZE,dtunit) < 0) {
00154 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00155 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNT);
00156 SSCRUTE(dtunit);goto ERROR;
00157 }
00158
00159
00160
00161
00162 if ( _MEDattrEntierLire(_datagroup1,MED_NOM_SRT,&_intsortingtype) >= 0) {
00163 _existingsortingtype = (med_sorting_type) (_intsortingtype);
00164
00165 _MEDnObjects(_datagroup1,".",&_nstep);
00166 }
00167
00168 if ( (_existingsortingtype != sortingtype) && _nstep ) {
00169 MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_COMPUTINGSTEP,MED_ERR_ATTRIBUTE_MSG);
00170 SSCRUTE(MED_NOM_SRT);SSCRUTE(meshname);SSCRUTE(_datagroupname1);
00171 ISCRUTE_int(_existingsortingtype);ISCRUTE_int(sortingtype);goto ERROR;
00172 }
00173
00174
00175
00176
00177
00178 _intsortingtype = sortingtype;
00179 if ( _MEDattributeIntWr(_datagroup1,MED_NOM_SRT,&_intsortingtype) < 0) {
00180 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00181 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_SRT);
00182 ISCRUTE_int(sortingtype);goto ERROR;
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 if ( _MEDattributeIntWr(_datagroup1,MED_NOM_REP,&_intaxistype) < 0) {
00199 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00200 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_REP);
00201 ISCRUTE(_intaxistype);goto ERROR;
00202 }
00203
00204
00205
00206
00207 if ( _MEDattributeStringWr(_datagroup1,MED_NOM_NOM,spacedim*MED_SNAME_SIZE,axisname) < 0) {
00208 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00209 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NOM);
00210 SSCRUTE(axisname);goto ERROR;
00211 }
00212
00213
00214
00215
00216 if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNI,spacedim*MED_SNAME_SIZE,axisunit) < 0) {
00217 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00218 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNI);
00219 SSCRUTE(axisunit);goto ERROR;
00220 }
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 _ret = 0;
00260
00261 ERROR:
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 if (_datagroup1>0) if (_MEDdatagroupFermer(_datagroup1) < 0) {
00273 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
00274 ISCRUTE_id(_datagroup1);
00275 }
00276
00277 if (_root>0) if (_MEDdatagroupFermer(_root) < 0) {
00278 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,root);
00279 ISCRUTE_id(_root);
00280 }
00281
00282 return _ret;
00283
00284 }
00285