From df1d3ed4c2f8225a0c362da175d52f92553ebea1 Mon Sep 17 00:00:00 2001 From: daveh150 Date: Wed, 8 Dec 2021 12:34:33 -0600 Subject: [PATCH] Added method to check namelist errors (#379) * Added method to check namelist errors * Made ERROR: output consistent Co-authored-by: David A. Hebert --- configuration/driver/icedrv_init.F90 | 50 +++++++++++++++++---- configuration/driver/icedrv_init_column.F90 | 9 +++- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/configuration/driver/icedrv_init.F90 b/configuration/driver/icedrv_init.F90 index 2a57d7d68..7fc063aff 100644 --- a/configuration/driver/icedrv_init.F90 +++ b/configuration/driver/icedrv_init.F90 @@ -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)' !----------------------------------------------------------------- @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/configuration/driver/icedrv_init_column.F90 b/configuration/driver/icedrv_init_column.F90 index dfd2a59e1..029f8b114 100644 --- a/configuration/driver/icedrv_init_column.F90 +++ b/configuration/driver/icedrv_init_column.F90 @@ -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)' @@ -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)