Skip to content

Commit

Permalink
More modernization of IO operations
Browse files Browse the repository at this point in the history
More of the old explicit IO operations in the tests are moved into the
new create/delete_file functions.

Also some of the testing stuff was commented out; will re-activate
later.
  • Loading branch information
marshallward committed Jan 7, 2022
1 parent 8d6bfed commit c780f45
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 240 deletions.
77 changes: 43 additions & 34 deletions config_src/drivers/new_unit/MOM_new_unit_tests.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ program MOM_unit_tests

! TODO: Move to a unit testing framework
use MOM_file_parser_tests, only : run_unit_test
use MOM_file_parser_tests, only : create_file
use MOM_file_parser_tests, only : delete_file

use MOM_file_parser_tests, only : param_filename
use MOM_file_parser_tests, only : netcdf_param_filename
Expand All @@ -19,13 +17,13 @@ program MOM_unit_tests
! tests
use MOM_file_parser_tests, only : test_open_param_file
use MOM_file_parser_tests, only : test_close_param_file_quiet
use MOM_file_parser_tests, only : test_open_param_file_component
use MOM_file_parser_tests, only : test_open_param_file_docdir
use MOM_file_parser_tests, only : test_open_param_file_empty_filename
use MOM_file_parser_tests, only : test_missing_param_file
use MOM_file_parser_tests, only : test_open_param_file_ioerr
use MOM_file_parser_tests, only : test_open_param_file_empty_filename
use MOM_file_parser_tests, only : test_open_param_file_netcdf
use MOM_file_parser_tests, only : test_open_param_file_checkable
use MOM_file_parser_tests, only : test_open_param_file_component
use MOM_file_parser_tests, only : test_open_param_file_docdir
use MOM_file_parser_tests, only : test_reopen_param_file
use MOM_file_parser_tests, only : test_open_param_file_no_doc
use MOM_file_parser_tests, only : test_open_param_file_no_iounit
Expand All @@ -47,9 +45,9 @@ program MOM_unit_tests
use MOM_file_parser_tests, only : test_read_param_real_array_type_err
use MOM_file_parser_tests, only : test_read_param_logical
use MOM_file_parser_tests, only : test_read_param_logical_missing
use MOM_file_parser_tests, only : test_read_param_char_no_quote
use MOM_file_parser_tests, only : test_read_param_char_double_quote
use MOM_file_parser_tests, only : test_read_param_char_single_quote
use MOM_file_parser_tests, only : test_read_param_char_no_delim
use MOM_file_parser_tests, only : test_read_param_char_quote_delim
use MOM_file_parser_tests, only : test_read_param_char_apostrophe_delim
use MOM_file_parser_tests, only : test_read_param_char_missing
use MOM_file_parser_tests, only : test_read_param_char_array
use MOM_file_parser_tests, only : test_read_param_char_array_missing
Expand Down Expand Up @@ -178,8 +176,9 @@ program MOM_unit_tests

if (rank == root) then
! Abort if at least one rank sees either input.nml or MOM_input
if (input_nml_exists) error stop "Remove existing 'input.nml' file."
if (MOM_input_exists) error stop "Remove existing 'MOM_input' file."
!if (input_nml_exists) error stop "Remove existing 'input.nml' file."
!if (MOM_input_exists) error stop "Remove existing 'MOM_input' file."
! TODO: Disabling these checks for now; they are annoying!

! Otherwise, create the (empty) files
open(newunit=param_unit, file='input.nml', status='replace')
Expand All @@ -201,7 +200,8 @@ program MOM_unit_tests
inquire(file=param_filename, exist=is_file)
if (is_file) rc = chmod(param_filename, int(o'700'))

call delete_file(param_filename)
inquire(file=param_filename, opened=is_open, number=param_unit)
if (is_open) close(param_unit, status='delete')
endif

! Run tests
Expand Down Expand Up @@ -237,6 +237,7 @@ program MOM_unit_tests
print '(/a)', "=== call test_open_param_file_checkable"
call run_unit_test(test_open_param_file_checkable)

! TODO: Error for >1 rank!
print '(/a)', "=== call test_reopen_param_file"
call run_unit_test(test_reopen_param_file)

Expand All @@ -254,16 +255,22 @@ program MOM_unit_tests
!enddo
! TODO: This assumes that *all* iounits should be closed before each test...
! The only method did not require such an assumption.
do io_unit=10,512
inquire(io_unit, opened=is_open)
if (is_open) close(io_unit)
enddo
if (is_root_PE()) then
do io_unit=10,512
inquire(io_unit, opened=is_open)
if (is_open) close(io_unit)
enddo
endif
call mpp_sync

print '(/a)', "=== call test_open_param_file_netcdf"
call run_unit_test(test_open_param_file_netcdf, fatal=.true.)
inquire(file=param_filename, opened=is_open, number=param_unit)
if (.not. is_open) open(newunit=param_unit, file=netcdf_param_filename)
close(param_unit, status='delete')
if (is_root_PE()) then
inquire(file=param_filename, opened=is_open, number=param_unit)
if (.not. is_open) open(newunit=param_unit, file=netcdf_param_filename)
close(param_unit, status='delete')
endif
call mpp_sync

print '(/a)', "=== call test_open_param_file_no_doc"
call run_unit_test(test_open_param_file_no_doc)
Expand Down Expand Up @@ -330,14 +337,14 @@ program MOM_unit_tests
print '(/a)', "=== call test_read_param_logical_missing"
call run_unit_test(test_read_param_logical_missing, fatal=.true.)

print '(/a)', "=== call test_read_param_char_no_quote"
call run_unit_test(test_read_param_char_no_quote)
print '(/a)', "=== call test_read_param_char_no_delim"
call run_unit_test(test_read_param_char_no_delim)

print '(/a)', "=== call test_read_param_char_double_quote"
call run_unit_test(test_read_param_char_double_quote)
print '(/a)', "=== call test_read_param_char_quote_delim"
call run_unit_test(test_read_param_char_quote_delim)

print '(/a)', "=== call test_read_param_char_single_quote"
call run_unit_test(test_read_param_char_single_quote)
print '(/a)', "=== call test_read_param_char_apostrophe_delim"
call run_unit_test(test_read_param_char_apostrophe_delim)

print '(/a)', "=== call test_read_param_char_missing"
call run_unit_test(test_read_param_char_missing, fatal=.true.)
Expand Down Expand Up @@ -557,19 +564,21 @@ program MOM_unit_tests
!--

! Cleanup
open(newunit=param_unit, file=param_filename)
close(param_unit, status='delete')

do i=1,4
open(newunit=param_unit, file="MOM_parameter_doc."//param_docfiles(i))
if (is_root_PE()) then
open(newunit=param_unit, file=param_filename)
close(param_unit, status='delete')
enddo

open(io_unit, file='MOM_input')
close(io_unit, status='delete')
do i=1,4
open(newunit=param_unit, file="MOM_parameter_doc."//param_docfiles(i))
close(param_unit, status='delete')
enddo

open(io_unit, file='input.nml')
close(io_unit, status='delete')
open(io_unit, file='MOM_input')
close(io_unit, status='delete')

open(io_unit, file='input.nml')
close(io_unit, status='delete')
endif

call MOM_infra_end

Expand Down
9 changes: 6 additions & 3 deletions src/framework/MOM_file_parser.F90
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,13 @@ subroutine open_param_file(filename, CS, checkable, component, doc_file_dir)
"open_param_file: internal inconsistency! "//trim(filename)// &
" is registered as open but has the wrong unit number!")

! TODO: There are MPI-parallel issues here, since only one rank
! will return from this function. The rest will have iounit = 1
! and will proceed to hang in populate_param_data()'s broadcast().
call MOM_error(WARNING, &
"open_param_file: file "//trim(filename)// &
" has already been opened. This should NOT happen!"// &
" Did you specify the same file twice in a namelist?")
"open_param_file: file "//trim(filename)// &
" has already been opened. This should NOT happen!"// &
" Did you specify the same file twice in a namelist?")
return
endif ! unit numbers
enddo ! i
Expand Down
Loading

0 comments on commit c780f45

Please sign in to comment.