From 8bcf36938073b6541d6689fd0a3c2b6d317882e7 Mon Sep 17 00:00:00 2001 From: wknoben Date: Mon, 14 Sep 2020 19:22:15 -0600 Subject: [PATCH] Updated read_force.f90 to correctly report netcdf reading error The error message in ``` ! read forcing data for all HRUs if(simultaneousRead)then err=nf90_get_var(ncid,forcFileInfo(iFile)%data_id(ivar),dataVec,start=(/ixHRUfile_min,iRead/),count=(/nHRUlocal,1/)) if(err/=nf90_noerr)then; message=trim(message)//'problem reading forcing data: '//trim(varname)//'/'//trim(nf90_strerror(err)); return; endif endif ``` needs variable `varName`. This variable is undefined in the current code and thus this error message attempts to print an undefined string. This fix gets the varName before the reading error can occur and this ensures a readable error message. --- build/source/engine/read_force.f90 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/source/engine/read_force.f90 b/build/source/engine/read_force.f90 index 1296b01d3..bf3435a60 100755 --- a/build/source/engine/read_force.f90 +++ b/build/source/engine/read_force.f90 @@ -486,6 +486,10 @@ subroutine readForcingData(currentJulday,ncId,iFile,iRead,nHRUlocal,time_data,fo ! get index in forcing structure iVar = forcFileInfo(iFile)%var_ix(iNC) checkForce(iVar) = .true. + + ! get variable name for error reporting + err=nf90_inquire_variable(ncid,iNC,name=varName) + if(err/=nf90_noerr)then; message=trim(message)//'problem reading forcing variable name from netCDF: '//trim(nf90_strerror(err)); return; endif ! read forcing data for all HRUs if(simultaneousRead)then