Skip to content

Commit

Permalink
Adding method to check namelist in any order, tested with NAG Fortran. (
Browse files Browse the repository at this point in the history
#801)

* Adding method to check namelist in any order. Use subroutine in ice_namelist_mod.F90 to search for namelist in ice_in.

* Moved goto_nml subroutine to ice_fileunits.F90. Removed ice_namelist_mod.F90

* Cleanup indentations with tmpstr2 use

* Cleanup spacing and intentation

* For namelist check, remove extra continuation after making ice_abort string.

Co-authored-by: Tony Craig <[email protected]>
  • Loading branch information
daveh150 and apcraig authored Dec 16, 2022
1 parent f813294 commit eebb350
Show file tree
Hide file tree
Showing 10 changed files with 410 additions and 122 deletions.
32 changes: 25 additions & 7 deletions cicecore/cicedyn/analysis/ice_history.F90
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ subroutine init_hist (dt)
use ice_history_fsd, only: init_hist_fsd_2D, init_hist_fsd_3Df, &
init_hist_fsd_4Df, f_afsd, f_afsdn
use ice_restart_shared, only: restart
use ice_fileunits, only: goto_nml

real (kind=dbl_kind), intent(in) :: &
dt ! time step
Expand All @@ -104,7 +105,9 @@ subroutine init_hist (dt)
cstr_got, cstr_gou, cstr_gov ! mask area name for t, u, v ocn grid (go)
character (len=25) :: &
gridstr2D, gridstr ! temporary string names
character(len=char_len) :: description
character(len=char_len) :: description
character(len=char_len_long) :: tmpstr2 ! for namelist check
character(len=char_len) :: nml_name ! text namelist name

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

Expand Down Expand Up @@ -228,24 +231,39 @@ subroutine init_hist (dt)
file=__FILE__, line=__LINE__)

if (my_task == master_task) then
write(nu_diag,*) subname,' Reading icefields_nml'
nml_name = 'icefields_nml'
write(nu_diag,*) subname,' Reading ', trim(nml_name)

! open file
call get_fileunit(nu_nml)
open (nu_nml, file=trim(nml_filename), status='old',iostat=nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: icefields_nml open file '// &
call abort_ice(subname//'ERROR: '//trim(nml_name)//' open file '// &
trim(nml_filename), &
file=__FILE__, line=__LINE__)
endif

! seek to this namelist
call goto_nml(nu_nml,trim(nml_name),nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: searching for '// trim(nml_name), &
file=__FILE__, line=__LINE__)
endif

! read namelist
nml_error = 1
do while (nml_error > 0)
read(nu_nml, nml=icefields_nml,iostat=nml_error)
! check if error
if (nml_error /= 0) then
! backspace and re-read erroneous line
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
call abort_ice(subname//'ERROR: ' // trim(nml_name) // ' reading ' // &
trim(tmpstr2), file=__FILE__, line=__LINE__)
endif
end do
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: icefields_nml reading ', &
file=__FILE__, line=__LINE__)
endif

close(nu_nml)
call release_fileunit(nu_nml)
endif
Expand Down
31 changes: 25 additions & 6 deletions cicecore/cicedyn/analysis/ice_history_bgc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ subroutine init_hist_bgc_2D
use ice_communicate, only: my_task, master_task
use ice_history_shared, only: tstr2D, tcstr, define_hist_field, &
f_fsalt, f_fsalt_ai, f_sice
use ice_fileunits, only: goto_nml

integer (kind=int_kind) :: n, ns
integer (kind=int_kind) :: nml_error ! namelist i/o error flag
Expand All @@ -283,6 +284,9 @@ subroutine init_hist_bgc_2D
tr_bgc_DON, tr_bgc_Fe, tr_bgc_hum, &
skl_bgc, solve_zsal, z_tracers

character(len=char_len) :: nml_name ! for namelist check
character(len=char_len_long) :: tmpstr2 ! for namelist check

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

call icepack_query_parameters(skl_bgc_out=skl_bgc, &
Expand All @@ -305,24 +309,39 @@ subroutine init_hist_bgc_2D
!-----------------------------------------------------------------

if (my_task == master_task) then
write(nu_diag,*) subname,' Reading icefields_bgc_nml'
nml_name = 'icefields_bgc_nml'
write(nu_diag,*) subname,' Reading ', trim(nml_name)

! check if can open file
call get_fileunit(nu_nml)
open (nu_nml, file=trim(nml_filename), status='old',iostat=nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: icefields_bgc_nml open file '// &
call abort_ice(subname//'ERROR: '//trim(nml_name)//' open file '// &
trim(nml_filename), &
file=__FILE__, line=__LINE__)
endif

! seek to namelist in file
call goto_nml(nu_nml,trim(nml_name),nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: searching for '// trim(nml_name), &
file=__FILE__, line=__LINE__)
endif

! read namelist
nml_error = 1
do while (nml_error > 0)
read(nu_nml, nml=icefields_bgc_nml,iostat=nml_error)
! check if error
if (nml_error /= 0) then
! backspace and re-read erroneous line
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
call abort_ice(subname//'ERROR: ' // trim(nml_name) // ' reading ' // &
trim(tmpstr2), file=__FILE__, line=__LINE__)
endif
end do
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: icefields_bgc_nml reading ', &
file=__FILE__, line=__LINE__)
endif

close(nu_nml)
call release_fileunit(nu_nml)
endif
Expand Down
30 changes: 24 additions & 6 deletions cicecore/cicedyn/analysis/ice_history_drag.F90
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ subroutine init_hist_drag_2D
use ice_calendar, only: nstreams
use ice_communicate, only: my_task, master_task
use ice_history_shared, only: tstr2D, tcstr, define_hist_field
use ice_fileunits, only: goto_nml

integer (kind=int_kind) :: ns
integer (kind=int_kind) :: nml_error ! namelist i/o error flag
logical (kind=log_kind) :: formdrag
character(len=char_len_long) :: tmpstr2 ! for namelist check
character(len=char_len) :: nml_name ! for namelist check

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

Expand All @@ -81,24 +84,39 @@ subroutine init_hist_drag_2D
!-----------------------------------------------------------------

if (my_task == master_task) then
write(nu_diag,*) subname,' Reading icefields_drag_nml'
nml_name = 'icefields_drag_nml'
write(nu_diag,*) subname,' Reading ', trim(nml_name)

! open namelist file
call get_fileunit(nu_nml)
open (nu_nml, file=trim(nml_filename), status='old',iostat=nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: icefields_drag_nml open file '// &
call abort_ice(subname//'ERROR: '//trim(nml_name)//' open file '// &
trim(nml_filename), &
file=__FILE__, line=__LINE__)
endif

! go to this namelist
call goto_nml(nu_nml,trim(nml_name),nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: searching for '// trim(nml_name), &
file=__FILE__, line=__LINE__)
endif

! read namelist
nml_error = 1
do while (nml_error > 0)
read(nu_nml, nml=icefields_drag_nml,iostat=nml_error)
! check if error
if (nml_error /= 0) then
! backspace and re-read erroneous line
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
call abort_ice(subname//'ERROR: ' // trim(nml_name) // ' reading ' // &
trim(tmpstr2), file=__FILE__, line=__LINE__)
endif
end do
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: icefields_drag_nml reading ', &
file=__FILE__, line=__LINE__)
endif

close(nu_nml)
call release_fileunit(nu_nml)
endif
Expand Down
30 changes: 24 additions & 6 deletions cicecore/cicedyn/analysis/ice_history_fsd.F90
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ subroutine init_hist_fsd_2D
use ice_calendar, only: nstreams
use ice_communicate, only: my_task, master_task
use ice_history_shared, only: tstr2D, tcstr, define_hist_field
use ice_fileunits, only: goto_nml

integer (kind=int_kind) :: ns
integer (kind=int_kind) :: nml_error ! namelist i/o error flag
logical (kind=log_kind) :: tr_fsd, wave_spec
character (len=char_len_long) :: tmpstr2 ! test namelist
character(len=char_len) :: nml_name ! text namelist name

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

Expand All @@ -96,24 +99,39 @@ subroutine init_hist_fsd_2D
!-----------------------------------------------------------------

if (my_task == master_task) then
write(nu_diag,*) subname,' Reading icefields_fsd_nml'
nml_name = 'icefields_fsd_nml'
write(nu_diag,*) subname,' Reading ', trim(nml_name)

! open namelist file
call get_fileunit(nu_nml)
open (nu_nml, file=trim(nml_filename), status='old',iostat=nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: icefields_fsd_nml open file '// &
call abort_ice(subname//'ERROR: '//trim(nml_name)//' open file '// &
trim(nml_filename), &
file=__FILE__, line=__LINE__)
endif

! goto this namelist
call goto_nml(nu_nml,trim(nml_name),nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: searching for '// trim(nml_name), &
file=__FILE__, line=__LINE__)
endif

! read namelist
nml_error = 1
do while (nml_error > 0)
read(nu_nml, nml=icefields_fsd_nml,iostat=nml_error)
! check if error
if (nml_error /= 0) then
! backspace and re-read erroneous line
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
call abort_ice(subname//'ERROR: ' // trim(nml_name) // ' reading ' // &
trim(tmpstr2), file=__FILE__, line=__LINE__)
endif
end do
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: icefields_fsd_nml reading ', &
file=__FILE__, line=__LINE__)
endif

close(nu_nml)
call release_fileunit(nu_nml)
endif
Expand Down
30 changes: 24 additions & 6 deletions cicecore/cicedyn/analysis/ice_history_mechred.F90
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ subroutine init_hist_mechred_2D
use ice_calendar, only: nstreams, histfreq
use ice_communicate, only: my_task, master_task
use ice_history_shared, only: tstr2D, tcstr, define_hist_field
use ice_fileunits, only: goto_nml

integer (kind=int_kind) :: ns
integer (kind=int_kind) :: nml_error ! namelist i/o error flag
real (kind=dbl_kind) :: secday
logical (kind=log_kind) :: tr_lvl
character(len=char_len_long) :: tmpstr2 ! for namelist check
character(len=char_len) :: nml_name ! for namelist check

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

Expand All @@ -103,24 +106,39 @@ subroutine init_hist_mechred_2D
!-----------------------------------------------------------------

if (my_task == master_task) then
write(nu_diag,*) subname,' Reading icefields_mechred_nml'
nml_name = 'icefields_mechred_nml'
write(nu_diag,*) subname,' Reading ', trim(nml_name)

! open namelist file
call get_fileunit(nu_nml)
open (nu_nml, file=trim(nml_filename), status='old',iostat=nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: icefields_mechred_nml open file '// &
call abort_ice(subname//'ERROR: '//trim(nml_name)//' open file '// &
trim(nml_filename), &
file=__FILE__, line=__LINE__)
endif

! goto this namelist in file
call goto_nml(nu_nml,trim(nml_name),nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: searching for '// trim(nml_name), &
file=__FILE__, line=__LINE__)
endif

! read namelist
nml_error = 1
do while (nml_error > 0)
read(nu_nml, nml=icefields_mechred_nml,iostat=nml_error)
! check if error
if (nml_error /= 0) then
! backspace and re-read erroneous line
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
call abort_ice(subname//'ERROR: ' // trim(nml_name) // ' reading ' // &
trim(tmpstr2), file=__FILE__, line=__LINE__)
endif
end do
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: icefields_mechred_nml reading ', &
file=__FILE__, line=__LINE__)
endif

close(nu_nml)
call release_fileunit(nu_nml)
endif
Expand Down
36 changes: 27 additions & 9 deletions cicecore/cicedyn/analysis/ice_history_pond.F90
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ subroutine init_hist_pond_2D
use ice_calendar, only: nstreams, histfreq
use ice_communicate, only: my_task, master_task
use ice_history_shared, only: tstr2D, tcstr, define_hist_field
use ice_fileunits, only: goto_nml

integer (kind=int_kind) :: ns
integer (kind=int_kind) :: nml_error ! namelist i/o error flag
logical (kind=log_kind) :: tr_pond
character(len=char_len_long) :: tmpstr2 ! for namelist check
character(len=char_len) :: nml_name ! text namelist name

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

Expand All @@ -86,24 +89,39 @@ subroutine init_hist_pond_2D
!-----------------------------------------------------------------

if (my_task == master_task) then
write(nu_diag,*) subname,' Reading icefields_pond_nml'
nml_name = 'icefields_pond_nml'
write(nu_diag,*) subname,' Reading ', trim(nml_name)

! open namelist file
call get_fileunit(nu_nml)
open (nu_nml, file=trim(nml_filename), status='old',iostat=nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: icefields_pond_nml open file '// &
trim(nml_filename), &
file=__FILE__, line=__LINE__)
call abort_ice(subname//'ERROR: '//trim(nml_name)//' open file '// &
trim(nml_filename), &
file=__FILE__, line=__LINE__)
endif


! goto this namelist in file
call goto_nml(nu_nml,trim(nml_name),nml_error)
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: searching for '// trim(nml_name), &
file=__FILE__, line=__LINE__)
endif

! read namelist
nml_error = 1
do while (nml_error > 0)
read(nu_nml, nml=icefields_pond_nml,iostat=nml_error)
! check if error
if (nml_error /= 0) then
! backspace and re-read erroneous line
backspace(nu_nml)
read(nu_nml,fmt='(A)') tmpstr2
call abort_ice(subname//'ERROR: ' // trim(nml_name) // ' reading ' // &
trim(tmpstr2), file=__FILE__, line=__LINE__)
endif
end do
if (nml_error /= 0) then
call abort_ice(subname//'ERROR: icefields_pond_nml reading ', &
file=__FILE__, line=__LINE__)
endif

close(nu_nml)
call release_fileunit(nu_nml)
endif
Expand Down
Loading

0 comments on commit eebb350

Please sign in to comment.