Skip to content

Commit

Permalink
Added method to check namelist errors (#379)
Browse files Browse the repository at this point in the history
* Added method to check namelist errors

* Made ERROR: output consistent

Co-authored-by: David A. Hebert <dhebert@nrlssc.navy.mil>
  • Loading branch information
daveh150 and David A. Hebert authored Dec 8, 2021
1 parent b7148ee commit df1d3ed
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
50 changes: 42 additions & 8 deletions configuration/driver/icedrv_init.F90
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ subroutine input_data

real (kind=real_kind) :: rpcesm, rplvl, rptopo
real (kind=dbl_kind) :: Cf, puny
character(len=char_len_long) :: tmpstr2 ! for namelist error

character(len=*), parameter :: subname='(input_data)'

!-----------------------------------------------------------------
Expand Down Expand Up @@ -306,9 +308,13 @@ subroutine input_data
print*,'Reading setup_nml'
do while (nml_error > 0)
read(nu_nml, nml=setup_nml,iostat=nml_error)
if (nml_error /= 0) exit
end do
if (nml_error /= 0) then
write(ice_stdout,*) 'error reading namelist'
! backspace, re-read erroneous line, then print
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
write(ice_stdout,*) 'ERROR: reading namelist ' // trim(tmpstr2)
call icedrv_system_abort(file=__FILE__,line=__LINE__)
endif
close(nu_nml)
Expand All @@ -318,9 +324,13 @@ subroutine input_data
print*,'Reading grid_nml'
do while (nml_error > 0)
read(nu_nml, nml=grid_nml,iostat=nml_error)
if (nml_error /= 0) exit
end do
if (nml_error /= 0) then
write(ice_stdout,*) 'error reading namelist'
! backspace, re-read erroneous line, then print
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
write(ice_stdout,*) 'ERROR: reading namelist ' // trim(tmpstr2)
call icedrv_system_abort(file=__FILE__,line=__LINE__)
endif
close(nu_nml)
Expand All @@ -330,9 +340,13 @@ subroutine input_data
print*,'Reading tracer_nml'
do while (nml_error > 0)
read(nu_nml, nml=tracer_nml,iostat=nml_error)
if (nml_error /= 0) exit
end do
if (nml_error /= 0) then
write(ice_stdout,*) 'error reading namelist'
! backspace, re-read erroneous line, then print
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
write(ice_stdout,*) 'ERROR: reading namelist ' // trim(tmpstr2)
call icedrv_system_abort(file=__FILE__,line=__LINE__)
endif
close(nu_nml)
Expand All @@ -342,9 +356,13 @@ subroutine input_data
print*,'Reading thermo_nml'
do while (nml_error > 0)
read(nu_nml, nml=thermo_nml,iostat=nml_error)
if (nml_error /= 0) exit
end do
if (nml_error /= 0) then
write(ice_stdout,*) 'error reading namelist'
! backspace, re-read erroneous line, then print
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
write(ice_stdout,*) 'ERROR: reading namelist ' // trim(tmpstr2)
call icedrv_system_abort(file=__FILE__,line=__LINE__)
endif
close(nu_nml)
Expand All @@ -354,9 +372,13 @@ subroutine input_data
print*,'Reading shortwave_nml'
do while (nml_error > 0)
read(nu_nml, nml=shortwave_nml,iostat=nml_error)
if (nml_error /= 0) exit
end do
if (nml_error /= 0) then
write(ice_stdout,*) 'error reading namelist'
! backspace, re-read erroneous line, then print
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
write(ice_stdout,*) 'ERROR: reading namelist ' // trim(tmpstr2)
call icedrv_system_abort(file=__FILE__,line=__LINE__)
endif
close(nu_nml)
Expand All @@ -366,9 +388,13 @@ subroutine input_data
print*,'Reading ponds_nml'
do while (nml_error > 0)
read(nu_nml, nml=ponds_nml,iostat=nml_error)
if (nml_error /= 0) exit
end do
if (nml_error /= 0) then
write(ice_stdout,*) 'error reading namelist'
! backspace, re-read erroneous line, then print
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
write(ice_stdout,*) 'ERROR: reading namelist ' // trim(tmpstr2)
call icedrv_system_abort(file=__FILE__,line=__LINE__)
endif
close(nu_nml)
Expand All @@ -379,9 +405,13 @@ subroutine input_data
print*,'Reading snow_nml'
do while (nml_error > 0)
read(nu_nml, nml=snow_nml,iostat=nml_error)
if (nml_error /= 0) exit
end do
if (nml_error /= 0) then
write(ice_stdout,*) 'error reading namelist'
! backspace, re-read erroneous line, then print
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
write(ice_stdout,*) 'ERROR: reading namelist ' // trim(tmpstr2)
call icedrv_system_abort(file=__FILE__,line=__LINE__)
endif
close(nu_nml)
Expand All @@ -392,9 +422,13 @@ subroutine input_data
print*,'Reading forcing_nml'
do while (nml_error > 0)
read(nu_nml, nml=forcing_nml,iostat=nml_error)
if (nml_error /= 0) exit
end do
if (nml_error /= 0) then
write(ice_stdout,*) 'error reading namelist'
! backspace, re-read erroneous line, then print
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
write(ice_stdout,*) 'ERROR: reading namelist ' // trim(tmpstr2)
call icedrv_system_abort(file=__FILE__,line=__LINE__)
endif
close(nu_nml)
Expand Down
9 changes: 8 additions & 1 deletion configuration/driver/icedrv_init_column.F90
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ subroutine init_zbgc
ntd , & ! for tracer dependency calculation
nk , & !
nt_depend

character(len=char_len_long) :: tmpstr2 ! for namelist errors

character(len=*), parameter :: subname='(init_zbgc)'

Expand Down Expand Up @@ -1016,9 +1018,14 @@ subroutine init_zbgc
print*,'Reading zbgc_nml'
do while (nml_error > 0)
read(nu_nml, nml=zbgc_nml,iostat=nml_error)
if (nml_error /= 0) exit
end do
if (nml_error /= 0) then
print*,'error reading zbgc namelist'
! backspace, re-read erroneous line, then print
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2

print*,'ERROR: reading zbgc namelist ' // trim(tmpstr2)
call icedrv_system_abort(file=__FILE__,line=__LINE__)
endif
close(nu_nml)
Expand Down

0 comments on commit df1d3ed

Please sign in to comment.