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