Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding method to check namelist in any order, tested with NAG Fortran. #801

Merged
merged 6 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 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 @@ -105,6 +106,8 @@ subroutine init_hist (dt)
character (len=25) :: &
gridstr2D, gridstr ! temporary string names
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,42 @@ 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
33 changes: 27 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,41 @@ subroutine init_hist_bgc_2D
!-----------------------------------------------------------------

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this line needs an extra space for alignment.

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
32 changes: 26 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,41 @@ 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
32 changes: 26 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
apcraig marked this conversation as resolved.
Show resolved Hide resolved
character(len=char_len) :: nml_name ! text namelist name

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

Expand All @@ -96,24 +99,41 @@ 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
32 changes: 26 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,41 @@ 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
38 changes: 29 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,41 @@ 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