CH-Earth / summa

Structure for Unifying Multiple Modeling Alternatives:
http://www.ral.ucar.edu/projects/summa
GNU General Public License v3.0
80 stars 104 forks source link

Updated read_force.f90 to correctly report netcdf reading error #425

Closed wknoben closed 3 years ago

wknoben commented 3 years ago

read_force.f90 can print error message if reading of data from a netcdf file fails. The error messages in subroutinereadForcingData()

! 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

and

! read forcing data for a single HRU
    if(.not.simultaneousRead)then
     err=nf90_get_var(ncid,forcFileInfo(iFile)%data_id(ivar),dataVal,start=(/iHRU_global,iRead/))
     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.

Error without fix:

number of time steps =          65
Skipping over LUTYPE = USGS
Skipping over SLTYPE = STAS
Skipping over SLTYPE = STAS-RUC

WARNING: summa_readForcing/readForcingData/problem reading forcing data:                                                                                                                                                                                                   ‡       °        

 (can keep going, but stopping anyway)

Error after fix:

number of time steps =          65
Skipping over LUTYPE = USGS
Skipping over SLTYPE = STAS
Skipping over SLTYPE = STAS-RUC

WARNING: summa_readForcing/readForcingData/problem reading forcing data: pptrate/NetCDF: Start+count exceeds dimension boundgetFirstTimestep/

 (can keep going, but stopping anyway)