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 #include <string.h>
00023 #include <stdlib.h>
00024
00040 med_err
00041 MEDmeshGridStructWr(const med_idt fid,
00042 const char* const meshname,
00043 const med_int numdt,
00044 const med_int numit,
00045 const med_float dt,
00046 const med_int * const gridstruct)
00047 {
00048 med_access_mode _MED_ACCESS_MODE;
00049 med_idt _meshid=0;
00050 med_err _ret = -1;
00051 med_data_type _datatype = MED_UNDEF_DATATYPE;
00052 med_grid_type _gridtype = MED_UNDEF_GRID_TYPE;
00053 med_int _intgridtype = 0;
00054 med_int _meshdim = 0;
00055 char _meshpath[MED_TAILLE_MAA+MED_NAME_SIZE+1]=MED_MAA;
00056 int _i=0;
00057
00058
00059
00060
00061 _MEDmodeErreurVerrouiller();
00062 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
00063
00064 if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
00065 MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00066 goto ERROR;
00067 }
00068
00069 if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
00070 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00071 ISCRUTE_int(_MED_ACCESS_MODE);
00072 goto ERROR;
00073 }
00074
00075 strcat(_meshpath,meshname);
00076 if ((_meshid = _MEDdatagroupOuvrir(fid,_meshpath)) < 0) {
00077 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_MESH_MSG);
00078 SSCRUTE(meshname);SSCRUTE(_meshpath); goto ERROR;
00079 }
00080
00081
00082 if (_MEDattrEntierLire(_meshid,MED_NOM_DIM,&_meshdim) < 0) {
00083 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00084 SSCRUTE(meshname);SSCRUTE(MED_NOM_DIM);ISCRUTE(_meshdim);goto ERROR;
00085 }
00086
00087
00088
00089
00090 if (_MEDattrEntierLire(_meshid,MED_NOM_GTY,&_intgridtype) < 0) {
00091 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00092 SSCRUTE(meshname);SSCRUTE(MED_NOM_GTY);ISCRUTE_int(_gridtype);goto ERROR;
00093 }
00094 _gridtype=(med_grid_type) _intgridtype;
00095
00096 if ((_gridtype != MED_CURVILINEAR_GRID)) {
00097 MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_GRIDTYPE,MED_ERR_MESH_MSG);
00098 SSCRUTE(meshname);ISCRUTE_int(_gridtype);goto ERROR;
00099 }
00100
00101
00102
00103
00104 for (_i=0;_i<_meshdim;++_i) {
00105
00106 switch(_i) {
00107 case 0 :
00108 _datatype = MED_COORDINATE_AXIS1;
00109 break;
00110 case 1 :
00111 _datatype = MED_COORDINATE_AXIS2;
00112 break;
00113 case 2 :
00114 _datatype = MED_COORDINATE_AXIS3;
00115 break;
00116 default :
00117 MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_GRIDTYPE,MED_ERR_MESH_MSG);
00118 SSCRUTE(meshname);ISCRUTE_int(_gridtype);goto ERROR;
00119 }
00120
00121 if (_MEDmeshAdvancedWr(fid,
00122 meshname,
00123 _datatype,
00124 MED_NO_NAME,
00125 MED_INTERNAL_INT,
00126 numdt,
00127 numit,
00128 dt,
00129 MED_NODE,
00130 MED_NONE,
00131 MED_NO_CMODE,
00132 MED_UNDEF_PFLMODE,
00133 MED_NO_PROFILE,
00134 MED_FULL_INTERLACE,
00135 MED_ALL_CONSTITUENT,
00136 NULL,
00137 1,
00138 (gridstruct+_i)) < 0 ) {
00139 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDmeshAdvancedWr");
00140 goto ERROR;
00141 }
00142
00143 }
00144
00145 _ret = 0;
00146
00147 ERROR:
00148
00149 if (_meshid>0) if (_MEDdatagroupFermer(_meshid) < 0) {
00150 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_meshpath);
00151 ISCRUTE_id(_meshid);
00152 }
00153
00154 return _ret;
00155
00156 }