From 3c67e2618463a3057337b058989a798736ffe71c Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 19 May 2022 20:24:28 +0100 Subject: [PATCH] ECC-1392: Fortran interface: codes_open_file fails if the filename has spaces --- fortran/grib_f90_tail.f90 | 2 +- fortran/grib_fortran.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/fortran/grib_f90_tail.f90 b/fortran/grib_f90_tail.f90 index d29ba887f..afc5628a9 100644 --- a/fortran/grib_f90_tail.f90 +++ b/fortran/grib_f90_tail.f90 @@ -505,7 +505,7 @@ if (present(status)) then status = iret else - call grib_check(iret, 'open_file', '('//filename//')') + call grib_check(iret, 'open_file', '('// trim(filename) //')') end if end subroutine grib_open_file diff --git a/fortran/grib_fortran.c b/fortran/grib_fortran.c index 07dc4a9e6..145cdfb91 100644 --- a/fortran/grib_fortran.c +++ b/fortran/grib_fortran.c @@ -1037,7 +1037,7 @@ int grib_f_open_file_(int* fid, char* name , char* op, int lname, int lop) { char fname[1024]; int ret=GRIB_SUCCESS; char* iobuf=NULL; - /*TODO Proper context passed as external parameter */ + char* trimmed = NULL; /* filename trimmed */ grib_context* context=grib_context_get_default(); cast_char(oper,op,lop); @@ -1046,10 +1046,12 @@ int grib_f_open_file_(int* fid, char* name , char* op, int lname, int lop) { while (*p != '\0') { *p=tolower(*p);p++;} - f = fopen(cast_char(fname,name,lname),oper); + trimmed = cast_char_no_cut(fname,name,lname); /* ECC-1392 */ + rtrim( trimmed ); + f = fopen(trimmed, oper); if(!f) { ioerr=errno; - grib_context_log(context,(GRIB_LOG_ERROR)|(GRIB_LOG_PERROR),"IO ERROR: %s: %s",strerror(ioerr),cast_char(fname,name,lname)); + grib_context_log(context,(GRIB_LOG_ERROR)|(GRIB_LOG_PERROR),"IO ERROR: %s: '%s'",strerror(ioerr),trimmed); *fid = -1; ret=GRIB_IO_PROBLEM; } else { @@ -3439,7 +3441,9 @@ void grib_f_check_(int* err,char* call,char* str,int lencall,int lenstr){ grib_context* c=grib_context_get_default(); if ( *err == GRIB_SUCCESS || *err == GRIB_END_OF_FILE ) return; cast_char(bufcall,call,lencall); - cast_char(bufstr,str,lenstr); + /* ECC-1392 */ + cast_char_no_cut(bufstr,str,lenstr); + grib_context_log(c,GRIB_LOG_ERROR,"%s: %s %s", bufcall,bufstr,grib_get_error_message(*err)); exit(*err);