mirror of https://github.com/ecmwf/eccodes.git
Fix issue with grib_set mars.type and trailing spaces in F90 character variable
This commit is contained in:
parent
c4d3b26f6b
commit
7b058f3e8d
|
@ -16,34 +16,32 @@ program set
|
|||
integer(kind = 4) :: centre, date1
|
||||
integer :: infile,outfile
|
||||
integer :: igrib
|
||||
character(len=12) :: marsType = 'ses'
|
||||
|
||||
centre = 80
|
||||
call current_date(date1)
|
||||
call codes_open_file(infile, &
|
||||
'../../data/regular_latlon_surface_constant.grib1','r')
|
||||
call codes_open_file(infile, '../../data/regular_latlon_surface_constant.grib1','r')
|
||||
call codes_open_file(outfile, 'out.set.grib1','w')
|
||||
|
||||
call codes_open_file(outfile, &
|
||||
'out.set.grib1','w')
|
||||
|
||||
! a new grib message is loaded from file
|
||||
! igrib is the grib id to be used in subsequent calls
|
||||
! A new GRIB message is loaded from file
|
||||
! igrib is the grib id to be used in subsequent calls
|
||||
call codes_grib_new_from_file(infile,igrib)
|
||||
|
||||
call codes_set(igrib,'dataDate',date1)
|
||||
call codes_set(igrib,'type', marsType)
|
||||
|
||||
! set centre as a integer */
|
||||
call codes_set(igrib,'centre',centre)
|
||||
|
||||
! check if it is correct in the actual GRIB message
|
||||
|
||||
! Check if it is correct in the actual GRIB message
|
||||
call check_settings(igrib)
|
||||
|
||||
! write modified message to a file
|
||||
! Write modified message to a file
|
||||
call codes_write(igrib,outfile)
|
||||
|
||||
call codes_release(igrib)
|
||||
|
||||
call codes_close_file(infile)
|
||||
|
||||
call codes_close_file(outfile)
|
||||
|
||||
contains
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
. ./include.sh
|
||||
|
||||
${examples_dir}eccodes_f_grib_set_keys > /dev/null
|
||||
res=`${tools_dir}/grib_get -p centre out.set.grib1`
|
||||
[ "$res" = "cnmc" ]
|
||||
|
||||
${examples_dir}eccodes_f_grib_set_gvc > /dev/null
|
||||
res=`${tools_dir}/grib_get -p typeOfLevel,NV out_gvc.grib2`
|
||||
|
|
|
@ -2783,7 +2783,7 @@ int grib_f_get_string_array(int* gid, char* key, char* val,int* nvals,int* slen,
|
|||
static void rtrim(char* s)
|
||||
{
|
||||
size_t len = 0;
|
||||
Assert(s);
|
||||
if (!s) return;
|
||||
len = strlen(s);
|
||||
while (len > 0 && isspace((unsigned char)s[len - 1]))
|
||||
len--;
|
||||
|
@ -2857,15 +2857,19 @@ int grib_f_get_string(int* gid, char* key, char* val, int len, int len2){
|
|||
int grib_f_set_string_(int* gid, char* key, char* val, int len, int len2){
|
||||
|
||||
grib_handle *h = get_handle(*gid);
|
||||
char* val_str = NULL;
|
||||
|
||||
char buf[1024]={0,};
|
||||
char buf2[1024]={0,};
|
||||
size_t lsize = len2;
|
||||
|
||||
if(!h) return GRIB_INVALID_GRIB;
|
||||
|
||||
/* For BUFR, the value may contain spaces e.g. stationOrSiteName='CAMPO NOVO' */
|
||||
val_str = cast_char_no_cut(buf2,val,len2);
|
||||
rtrim( val_str ); /* trim spaces at end of string */
|
||||
|
||||
return grib_set_string(h, cast_char(buf,key,len), cast_char_no_cut(buf2,val,len2), &lsize);
|
||||
|
||||
return grib_set_string(h, cast_char(buf,key,len), val_str, &lsize);
|
||||
}
|
||||
|
||||
int grib_f_set_string__(int* gid, char* key, char* val, int len, int len2){
|
||||
|
|
Loading…
Reference in New Issue