Skip to content

Commit

Permalink
use shr_log_error and pass up stack
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Jan 30, 2025
1 parent baa3024 commit 4aa602b
Show file tree
Hide file tree
Showing 27 changed files with 268 additions and 167 deletions.
31 changes: 19 additions & 12 deletions datm/atm_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ module cdeps_datm_comp
use NUOPC_Model , only : NUOPC_ModelGet, setVM
use shr_kind_mod , only : r8=>shr_kind_r8, i8=>shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_const_mod , only : shr_const_cday
use shr_sys_mod , only : shr_sys_abort
use shr_cal_mod , only : shr_cal_ymd2date
use shr_log_mod , only : shr_log_setLogUnit
use shr_log_mod , only : shr_log_setLogUnit, shr_log_error
use dshr_methods_mod , only : dshr_state_diagnose, chkerr, memcheck
use dshr_strdata_mod , only : shr_strdata_type, shr_strdata_init_from_config, shr_strdata_advance
use dshr_strdata_mod , only : shr_strdata_get_stream_pointer, shr_strdata_setOrbs
Expand Down Expand Up @@ -267,14 +266,16 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
open (newunit=nu,file=trim(nlfilename),status="old",action="read")
call shr_nl_find_group_name(nu, 'datm_nml', status=ierr)
if (ierr > 0) then
write(logunit,*) 'ERROR: reading input namelist, '//trim(nlfilename)//' iostat=',ierr
call shr_sys_abort(subName//': namelist read error '//trim(nlfilename))
rc = ierr
call shr_log_error(subName//': namelist read error '//trim(nlfilename), rc=rc)
return
end if
read (nu,nml=datm_nml,iostat=ierr)
close(nu)
if (ierr > 0) then
write(logunit,*) 'ERROR: reading input namelist, '//trim(nlfilename)//' iostat=',ierr
call shr_sys_abort(subName//': namelist read error '//trim(nlfilename))
rc = ierr
call shr_log_error(subName//': namelist read error '//trim(nlfilename), rc=rc)
return
end if
bcasttmp = 0
bcasttmp(1) = nx_global
Expand Down Expand Up @@ -327,7 +328,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
else if (nextsw_cday_calc == 'cam6') then
nextsw_cday_calc_cam7 = .false.
else
call shr_sys_abort(' ERROR illegal datm nextsw_cday_calc = '//trim(nextsw_cday_calc))
call shr_log_error(' ERROR illegal datm nextsw_cday_calc = '//trim(nextsw_cday_calc), rc=rc)
return
end if

! write namelist input to standard out
Expand Down Expand Up @@ -364,7 +366,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
trim(datamode) == 'ERA5' .or. &
trim(datamode) == 'SIMPLE') then
else
call shr_sys_abort(' ERROR illegal datm datamode = '//trim(datamode))
call shr_log_error(' ERROR illegal datm datamode = '//trim(datamode), rc=rc)
return
endif

! Advertise datm fields
Expand Down Expand Up @@ -495,7 +498,8 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
if (isPresent .and. isSet) then
read (cvalue,*) flds_scalar_index_nextsw_cday
else
call shr_sys_abort(subname//'Need to set attribute ScalarFieldIdxNextSwCday')
call shr_log_error(subname//'Need to set attribute ScalarFieldIdxNextSwCday', rc=rc)
return
endif

nextsw_cday = getNextRadCDay(dayofYear, current_tod, stepno, idt, iradsw)
Expand Down Expand Up @@ -656,7 +660,8 @@ subroutine datm_comp_run(gcomp, importState, exportState, target_ymd, target_tod
call dshr_restart_read(restfilm, rpfile, logunit, my_task, mpicom, sdat, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
case default
call shr_sys_abort(subName//'datamode '//trim(datamode)//' not recognized')
call shr_log_error(subName//'datamode '//trim(datamode)//' not recognized', rc=rc)
return
end select
end if

Expand Down Expand Up @@ -727,7 +732,8 @@ subroutine datm_comp_run(gcomp, importState, exportState, target_ymd, target_tod
my_task, sdat, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
case default
call shr_sys_abort(subName//'datamode '//trim(datamode)//' not recognized')
call shr_log_error(subName//'datamode '//trim(datamode)//' not recognized', rc=rc)
return
end select
end if

Expand Down Expand Up @@ -830,7 +836,8 @@ subroutine datm_init_dfields(rc)
case('cpl_scalars')
continue
case default
call shr_sys_abort(subName//'field '//trim(lfieldnames(n))//' not recognized')
call shr_log_error(subName//'field '//trim(lfieldnames(n))//' not recognized', rc=rc)
return
end select
end if
end do
Expand Down
1 change: 0 additions & 1 deletion datm/datm_datamode_cfsr_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module datm_datamode_cfsr_mod
use ESMF , only : ESMF_State, ESMF_SUCCESS, ESMF_LogWrite, ESMF_LOGMSG_INFO
use NUOPC , only : NUOPC_Advertise
use shr_kind_mod , only : r8=>shr_kind_r8, i8=>shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_sys_mod , only : shr_sys_abort
use shr_precip_mod , only : shr_precip_partition_rain_snow_ramp
use shr_const_mod , only : shr_const_tkfrz, shr_const_rhofw, shr_const_rdair
use dshr_methods_mod , only : dshr_state_getfldptr, chkerr
Expand Down
17 changes: 11 additions & 6 deletions datm/datm_datamode_clmncep_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module datm_datamode_clmncep_mod
use ESMF , only : ESMF_STATEITEM_NOTFOUND, ESMF_LOGMSG_INFO, ESMF_StateGet, operator(/=)
use NUOPC , only : NUOPC_Advertise
use shr_kind_mod , only : r8=>shr_kind_r8, i8=>shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_sys_mod , only : shr_sys_abort
use shr_log_mod , only : shr_log_error
use shr_precip_mod , only : shr_precip_partition_rain_snow_ramp
use shr_const_mod , only : shr_const_spval, shr_const_tkfrz, shr_const_pi
use shr_const_mod , only : shr_const_pstd, shr_const_stebol, shr_const_rdair
Expand Down Expand Up @@ -319,7 +319,8 @@ subroutine datm_datamode_clmncep_init_pointers(importState, exportState, sdat, r

! error check
if (.not. associated(strm_wind) .or. .not. associated(strm_tbot)) then
call shr_sys_abort(trim(subname)//' ERROR: wind and tbot must be in streams for CLMNCEP')
call shr_log_error(trim(subname)//' ERROR: wind and tbot must be in streams for CLMNCEP', rc=rc)
return
endif

! determine anidrmax (see below for use)
Expand Down Expand Up @@ -380,7 +381,8 @@ subroutine datm_datamode_clmncep_advance(mainproc, logunit, mpicom, rc)
tbotmax = rtmp(2)
if (mainproc) write(logunit,*) trim(subname),' tbotmax = ',tbotmax
if(tbotmax <= 0) then
call shr_sys_abort(subname//'ERROR: bad value in tbotmax')
call shr_log_error(subname//'ERROR: bad value in tbotmax', rc=rc)
return
endif

! determine anidrmax (see below for use)
Expand Down Expand Up @@ -456,7 +458,8 @@ subroutine datm_datamode_clmncep_advance(mainproc, logunit, mpicom, rc)
qsat = (0.622_r8 * e)/(pbot - 0.378_r8 * e)
Sa_shum(n) = qsat
else
call shr_sys_abort(subname//'ERROR: cannot compute shum')
call shr_log_error(subname//'ERROR: cannot compute shum', rc=rc)
return
endif
!--- density ---
vp = (Sa_shum(n)*pbot) / (0.622_r8 + 0.378_r8 * Sa_shum(n))
Expand Down Expand Up @@ -493,7 +496,8 @@ subroutine datm_datamode_clmncep_advance(mainproc, logunit, mpicom, rc)
swvdf = strm_swdn(n) * 0.50_r8
Faxa_swvdf(n) = (1._r8 - ratio_rvrf)*swvdf
else
call shr_sys_abort(subName//'ERROR: cannot compute short-wave down')
call shr_log_error(subName//'ERROR: cannot compute short-wave down', rc=rc)
return
endif

!--- swnet: a diagnostic quantity ---
Expand All @@ -517,7 +521,8 @@ subroutine datm_datamode_clmncep_advance(mainproc, logunit, mpicom, rc)
Faxa_rainc(n) = strm_precn(n)*0.1_r8
Faxa_rainl(n) = strm_precn(n)*0.9_r8
else
call shr_sys_abort(subName//'ERROR: cannot compute rain and snow')
call shr_log_error(subName//'ERROR: cannot compute rain and snow', rc=rc)
return
endif

!--- split precip between rain & snow ---
Expand Down
8 changes: 5 additions & 3 deletions datm/datm_datamode_core2_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module datm_datamode_core2_mod
use pio , only : pio_closefile
use NUOPC , only : NUOPC_Advertise
use shr_kind_mod , only : r8=>shr_kind_r8, i8=>shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_sys_mod , only : shr_sys_abort
use shr_log_mod , only : shr_log_error
use shr_cal_mod , only : shr_cal_date2julian
use shr_const_mod , only : shr_const_tkfrz, shr_const_pi
use dshr_strdata_mod , only : shr_strdata_get_stream_pointer, shr_strdata_type
Expand Down Expand Up @@ -262,12 +262,14 @@ subroutine datm_datamode_core2_init_pointers(exportState, sdat, datamode, factor
end if

if (.not. associated(strm_prec) .or. .not. associated(strm_swdn)) then
call shr_sys_abort(trim(subname)//'ERROR: prec and swdn must be in streams for CORE2')
call shr_log_error(trim(subname)//'ERROR: prec and swdn must be in streams for CORE2', rc=rc)
return
endif

if (trim(datamode) == 'CORE2_IAF' ) then
if (.not. associated(strm_tarcf)) then
call shr_sys_abort(trim(subname)//'tarcf must be in an input stream for CORE2_IAF')
call shr_log_error(trim(subname)//'tarcf must be in an input stream for CORE2_IAF', rc=rc)
return
endif
endif

Expand Down
1 change: 0 additions & 1 deletion datm/datm_datamode_cplhist_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module datm_datamode_cplhist_mod
use ESMF , only : ESMF_StateItem_Flag
use NUOPC , only : NUOPC_Advertise
use shr_kind_mod , only : r8=>shr_kind_r8, i8=>shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_sys_mod , only : shr_sys_abort
use dshr_methods_mod , only : dshr_state_getfldptr, chkerr
use dshr_strdata_mod , only : shr_strdata_type, shr_strdata_get_stream_pointer
use dshr_strdata_mod , only : shr_strdata_type
Expand Down
1 change: 0 additions & 1 deletion datm/datm_datamode_era5_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module datm_datamode_era5_mod
use ESMF , only : ESMF_State, ESMF_SUCCESS, ESMF_LogWrite, ESMF_LOGMSG_INFO
use NUOPC , only : NUOPC_Advertise
use shr_kind_mod , only : r8=>shr_kind_r8, i8=>shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_sys_mod , only : shr_sys_abort
use shr_precip_mod , only : shr_precip_partition_rain_snow_ramp
use shr_const_mod , only : shr_const_tkfrz, shr_const_rhofw, shr_const_rdair
use dshr_methods_mod , only : dshr_state_getfldptr, chkerr
Expand Down
1 change: 0 additions & 1 deletion datm/datm_datamode_gefs_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module datm_datamode_gefs_mod
use ESMF , only : ESMF_State, ESMF_SUCCESS, ESMF_LogWrite, ESMF_LOGMSG_INFO
use NUOPC , only : NUOPC_Advertise
use shr_kind_mod , only : r8=>shr_kind_r8, i8=>shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_sys_mod , only : shr_sys_abort
use shr_precip_mod , only : shr_precip_partition_rain_snow_ramp
use shr_const_mod , only : shr_const_tkfrz, shr_const_rhofw, shr_const_rdair
use dshr_methods_mod , only : dshr_state_getfldptr, chkerr
Expand Down
4 changes: 2 additions & 2 deletions datm/datm_datamode_jra_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module datm_datamode_jra_mod
use ESMF , only : ESMF_StateItem_Flag, ESMF_STATEITEM_NOTFOUND, operator(/=)
use NUOPC , only : NUOPC_Advertise
use shr_kind_mod , only : r8=>shr_kind_r8, i8=>shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_sys_mod , only : shr_sys_abort
use shr_log_mod , only : shr_log_error
use shr_cal_mod , only : shr_cal_date2julian
use shr_const_mod , only : shr_const_tkfrz, shr_const_pi, shr_const_rdair
use dshr_strdata_mod , only : shr_strdata_get_stream_pointer, shr_strdata_type
Expand Down Expand Up @@ -226,7 +226,7 @@ subroutine datm_datamode_jra_init_pointers(exportState, sdat, rc)

! erro check
if (.not. associated(strm_prec) .or. .not. associated(strm_swdn)) then
call shr_sys_abort(trim(subname)//'ERROR: prec and swdn must be in streams for CORE_IAF_JRA')
call shr_log_error(trim(subname)//'ERROR: prec and swdn must be in streams for CORE_IAF_JRA', rc=rc)
endif

end subroutine datm_datamode_jra_init_pointers
Expand Down
7 changes: 5 additions & 2 deletions datm/datm_datamode_simple_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module datm_datamode_simple_mod
use dshr_methods_mod , only : dshr_state_getfldptr, dshr_fldbun_getfldptr, dshr_fldbun_regrid, chkerr
use dshr_strdata_mod , only : shr_strdata_type
use dshr_fldlist_mod , only : fldlist_type, dshr_fldlist_add

use shr_log_mod , only : shr_log_error

implicit none
private ! except

Expand Down Expand Up @@ -117,7 +118,9 @@ subroutine datm_datamode_simple_advertise(exportState, fldsexport, flds_scalar_n
read (nu,nml=const_forcing_nml,iostat=ierr)
close(nu)
if (ierr > 0) then
call shr_sys_abort(subName//': namelist read error '//trim(nlfilename))
rc = ierr
call shr_log_error(subName//': namelist read error '//trim(nlfilename), rc=rc)
return
end if

bcasttmp = 0
Expand Down
9 changes: 5 additions & 4 deletions dglc/dglc_datamode_noevolve_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module dglc_datamode_noevolve_mod
use ESMF , only : ESMF_VMGetCurrent, ESMF_VMBroadCast
use NUOPC , only : NUOPC_Advertise, NUOPC_IsConnected
use shr_kind_mod , only : r8=>shr_kind_r8, i8=>shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_sys_mod , only : shr_sys_abort
use shr_log_mod , only : shr_log_error
use shr_const_mod , only : SHR_CONST_RHOICE, SHR_CONST_RHOSW, SHR_CONST_REARTH, SHR_CONST_TKFRZ
use shr_const_mod , only : SHR_CONST_SPVAL
use shr_cal_mod , only : shr_cal_datetod2string
Expand Down Expand Up @@ -204,7 +204,8 @@ subroutine dglc_datamode_noevolve_init_pointers(NStateExp, NstateImp, rc)
if (.not. NUOPC_IsConnected(NStateImp(ns), fieldName=field_in_tsrf)) then
! NOTE: the field is connected ONLY if the MED->GLC entry is in the nuopc.runconfig file
! This restriction occurs even if the field was advertised
call shr_sys_abort(trim(subname)//": MED->GLC must appear in run sequence")
call shr_log_error(trim(subname)//": MED->GLC must appear in run sequence", rc=rc)
return
end if
call dshr_state_getfldptr(NStateImp(ns), field_in_tsrf, fldptr1=Sl_tsrf(ns)%ptr, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
Expand Down Expand Up @@ -309,8 +310,8 @@ subroutine dglc_datamode_noevolve_advance(gcomp, pio_subsystem, io_type, io_form
! Create pioid and pio_iodesc at the module level
inquire(file=trim(model_datafiles(ns)), exist=exists)
if (.not.exists) then
write(6,'(a)')' ERROR: model input file '//trim(model_datafiles(ns))//' does not exist'
call shr_sys_abort()
call shr_log_error(' ERROR: model input file '//trim(model_datafiles(ns))//' does not exist', rc=rc)
return
end if
rcode = pio_openfile(pio_subsystem, pioid, io_type, trim(model_datafiles(ns)), pio_nowrite)
call pio_seterrorhandling(pioid, PIO_BCAST_ERROR)
Expand Down
17 changes: 9 additions & 8 deletions dglc/glc_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ module cdeps_dglc_comp
use NUOPC_Model , only : model_label_Finalize => label_Finalize
use NUOPC_Model , only : NUOPC_ModelGet, SetVM
use shr_kind_mod , only : r8=>shr_kind_r8, i8=>shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_sys_mod , only : shr_sys_abort
use shr_cal_mod , only : shr_cal_ymd2date
use shr_log_mod , only : shr_log_setLogUnit
use shr_log_mod , only : shr_log_setLogUnit, shr_log_error
use shr_string_mod , only : shr_string_listGetNum, shr_string_listGetName
#ifdef CESMCOUPLED
use shr_pio_mod , only : shr_pio_getiosys, shr_pio_getiotype, shr_pio_getioformat
Expand Down Expand Up @@ -225,8 +224,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
read (nu,nml=dglc_nml,iostat=ierr)
close(nu)
if (ierr > 0) then
write(logunit,'(a,i8)') 'ERROR: reading input namelist, '//trim(nlfilename)//' iostat=',ierr
call shr_sys_abort(subName//': namelist read error '//trim(nlfilename))
call shr_log_error(subName//': namelist read error '//trim(nlfilename), rc=rc)
return
end if

! Determine number of ice sheets
Expand Down Expand Up @@ -284,7 +283,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
if ( trim(datamode) == 'noevolve') then ! read stream, no import data
! do nothing
else
call shr_sys_abort(' ERROR illegal dglc datamode = '//trim(datamode))
call shr_log_error(' ERROR illegal dglc datamode = '//trim(datamode), rc=rc)
return
endif

! Allocate module variables
Expand Down Expand Up @@ -362,7 +362,8 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
if (isPresent .and. isSet) then
read(cvalue,*) restart_read
else
call shr_sys_abort(subname//' ERROR: read restart flag must be present')
call shr_log_error(subname//' ERROR: read restart flag must be present', rc=rc)
return
end if

! Get the time to interpolate the stream data to
Expand Down Expand Up @@ -390,8 +391,8 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
if (my_task == main_task) then
inquire(file=trim(model_meshfiles(ns)), exist=exists)
if (.not.exists) then
write(logunit,'(a)')' ERROR: model_meshfile '//trim(model_meshfiles(ns))//' does not exist'
call shr_sys_abort(trim(subname)//' ERROR: model_meshfile '//trim(model_meshfiles(ns))//' does not exist')
call shr_log_error(trim(subname)//' ERROR: model_meshfile '//trim(model_meshfiles(ns))//' does not exist', rc=rc)
return
end if
endif

Expand Down
1 change: 0 additions & 1 deletion dice/dice_datamode_ssmi_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module dice_datamode_ssmi_mod
use ESMF , only : ESMF_ArrayCreate, ESMF_ArrayDestroy, ESMF_GridComp
use NUOPC , only : NUOPC_Advertise
use shr_kind_mod , only : r8=>shr_kind_r8, i8=>shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_sys_mod , only : shr_sys_abort
use shr_const_mod , only : shr_const_pi, shr_const_spval, shr_const_tkfrz, shr_const_latice
use shr_frz_mod , only : shr_frz_freezetemp
use dshr_strdata_mod , only : shr_strdata_get_stream_pointer, shr_strdata_type
Expand Down
11 changes: 6 additions & 5 deletions dice/ice_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ module cdeps_dice_comp
use NUOPC_Model , only : NUOPC_ModelGet, SetVM
use shr_kind_mod , only : r8=>shr_kind_r8, cxx=>shr_kind_cxx, cl=>shr_kind_cl, cs=>shr_kind_cs
use shr_const_mod , only : shr_const_pi
use shr_log_mod , only : shr_log_setLogUnit
use shr_sys_mod , only : shr_sys_abort
use shr_log_mod , only : shr_log_setLogUnit, shr_log_error
use shr_cal_mod , only : shr_cal_ymd2date, shr_cal_ymd2julian
use dshr_mod , only : dshr_model_initphase, dshr_init, dshr_mesh_init, dshr_check_restart_alarm
use dshr_mod , only : dshr_state_setscalar, dshr_set_runclock, dshr_log_clock_advance
Expand Down Expand Up @@ -212,8 +211,9 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
read (nu,nml=dice_nml,iostat=ierr)
close(nu)
if (ierr > 0) then
write(logunit,*) 'ERROR: reading input namelist, '//trim(nlfilename)//' iostat=',ierr
call shr_sys_abort(subName//': namelist read error '//trim(nlfilename))
rc = ierr
call shr_log_error(subName//': namelist read error '//trim(nlfilename), rc=rc)
return
end if

! write namelist input to standard out
Expand Down Expand Up @@ -268,7 +268,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
if ( trim(datamode) == 'ssmi' .or. trim(datamode) == 'ssmi_iaf') then
if (my_task == main_task) write(logunit,*) ' dice datamode = ',trim(datamode)
else
call shr_sys_abort(' ERROR illegal dice datamode = '//trim(datamode))
call shr_log_error(' ERROR illegal dice datamode = '//trim(datamode), rc=rc)
return
endif

! Advertise import and export fields
Expand Down
Loading

0 comments on commit 4aa602b

Please sign in to comment.