diff --git a/test_fms/mpp/Makefile.am b/test_fms/mpp/Makefile.am
index 65e0624901..f624d4e4d5 100644
--- a/test_fms/mpp/Makefile.am
+++ b/test_fms/mpp/Makefile.am
@@ -37,7 +37,8 @@ check_PROGRAMS = test_mpp \
test_mpp_print_memuse_stats_stderr \
test_mpp_print_memuse_stats_file \
test_mpp_memutils_begin_2x \
- test_mpp_memutils_end_before_begin
+ test_mpp_memutils_end_before_begin \
+ test_read_input_nml
# These are the sources for the tests.
test_mpp_SOURCES = test_mpp.F90
@@ -50,6 +51,7 @@ test_mpp_print_memuse_stats_stderr_SOURCES=test_mpp_print_memuse_stats_stderr.F9
test_mpp_print_memuse_stats_file_SOURCES=test_mpp_print_memuse_stats_file.F90
test_mpp_memutils_begin_2x_SOURCES=test_mpp_memutils_begin_2x.F90
test_mpp_memutils_end_before_begin_SOURCES=test_mpp_memutils_end_before_begin.F90
+test_read_input_nml_SOURCES=test_read_input_nml.F90
# Run the test programs.
TESTS = test_mpp_domains2.sh \
@@ -57,14 +59,17 @@ TESTS = test_mpp_domains2.sh \
test_mpp2.sh \
test_mpp_memuse \
test_mpp_mem_dump \
- test_mpp_memutils_mod.sh
+ test_mpp_memutils_mod.sh \
+ test_read_input_nml2.sh
+
# These files will also be included in the distribution.
EXTRA_DIST = input_base.nml \
test_mpp_domains2.sh \
test_mpp_pset2.sh \
test_mpp2.sh \
- test_mpp_memutils_mod.sh
+ test_mpp_memutils_mod.sh \
+ test_read_input_nml2.sh
# Clean up
CLEANFILES = input.nml *.out*
diff --git a/test_fms/mpp/test_read_input_nml.F90 b/test_fms/mpp/test_read_input_nml.F90
new file mode 100644
index 0000000000..70e0530be5
--- /dev/null
+++ b/test_fms/mpp/test_read_input_nml.F90
@@ -0,0 +1,225 @@
+!***********************************************************************
+!* GNU Lesser General Public License
+!*
+!* This file is part of the GFDL Flexible Modeling System (FMS).
+!*
+!* FMS is free software: you can redistribute it and/or modify it under
+!* the terms of the GNU Lesser General Public License as published by
+!* the Free Software Foundation, either version 3 of the License, or (at
+!* your option) any later version.
+!*
+!* FMS is distributed in the hope that it will be useful, but WITHOUT
+!* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+!* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+!* for more details.
+!*
+!* You should have received a copy of the GNU Lesser General Public
+!* License along with FMS. If not, see .
+!***********************************************************************
+
+!> @file
+!! @brief Tests the read_input_nml subroutine
+!! @author Colin Gladue
+!! @email gfdl.climate.model.info@noaa.gov
+
+program test_read_input_nml
+
+ use mpp_mod, only : mpp_init, mpp_exit
+ use mpp_mod, only : mpp_error, FATAL, NOTE
+ use mpp_mod, only : read_input_nml, mpp_get_current_pelist_name
+
+#include
+
+character(len=200) :: line !< Current line being read
+character(len=200) :: linelog, linenml !< Current log and nml lines being read
+character(len=128) :: filename !< Name of file being read
+integer :: n !< Looping variable
+logical :: version_bool, filename_bool !< Booleans that tell whether or not the
+ !! lines where version and filename should be
+ !! written in logfile have been found
+ !! yet. Default value is false
+
+namelist /test_read_input_nml_nml/ test_numb
+
+open(10, file="test_numb.nml", form="formatted", status="old")
+read(10, nml = test_read_input_nml_nml)
+close(10)
+
+if (test_numb.eq.1) then
+ ! Test 1: Tests the subroutine on a valid input nml full of data,
+ ! with no arguments passed to read_input_nml()
+
+ filename = "input.nml"
+ call mpp_init() ! Initialize mpp
+ call read_input_nml()
+ call mpp_exit()
+ open(110, file='logfile.000000.out', iostat=ioslog) ! Open logfile
+ open(111, file='input.nml', iostat=iosnml) ! Open of input nml
+ do while (ioslog.eq.0) ! Check for the first two written lines, then stay at this
+ ! position so we can compare from here on to the namelist
+ read(110, '(A)', iostat=ioslog) line
+ ! Check if we have found the version line
+ if (index(line, "READ_INPUT_NML: "//trim(version)).ne.0) then
+ version_bool = .true.
+ end if
+ ! Check if we have found the filename line
+ if (index(line, "READ_INPUT_NML: "//trim(filename)).ne.0) then
+ filename_bool = .true.
+ end if
+ ! Check if we have found all we are looking for
+ if (version_bool.and.filename_bool) then
+ write(*,*) "SUCCESS: Found the first 2 written lines, version&
+ & and filename"
+ exit ! Successful test portion
+ end if
+ ! If we have reached the end of the file, was anything missed?
+ if (index(line, "Total runtime").ne.0) then
+ if (.not.version_bool) then
+ call mpp_error(FATAL, "Version not written to &
+ &logfile")
+ else if (.not.filename_bool) then
+ call mpp_error(FATAL, "Filename not written to &
+ &logfile")
+ else
+ call mpp_error(FATAL, "Logfile not written to by &
+ &read_input_nml correctly.")
+ end if
+ end if
+ end do
+ ! Make sure the read pointers for logfile and input nml are in the same
+ ! location below.
+ read(110, '(A)', iostat=ioslog) linelog
+ read(111, '(A)', iostat=iosnml) linenml
+ do while (TRIM(linelog).ne.TRIM(" "//linenml))
+ read(110, '(A)', iostat=ioslog) linelog
+ end do
+ ! Compare contents of logfile and the input nml
+ do while (iosnml.eq.0)
+ if (TRIM(linelog).ne.TRIM(" "//linenml)) then
+ call mpp_error(FATAL, linelog//" -Does not equal- "//&
+ &linenml//". Namelist not written to logfile &
+ &correctly")
+ end if
+ read(110, '(A)', iostat=ioslog) linelog
+ read(111, '(A)', iostat=iosnml) linenml
+ end do
+ write(*,*) "SUCCESS: Matched all lines from input nml to the logfile"
+ close(110)
+ close(111)
+
+else if (test_numb.eq.2) then
+ ! Test 2: Tests the same valid input nml, but with a pelist_name_in passed as an
+ ! argument to read_input_nml().
+
+ filename = "input_alternative.nml"
+ call mpp_init() ! Initialize mpp
+ call read_input_nml("alternative")
+ call mpp_exit()
+ open(110, file='logfile.000000.out', iostat=ioslog) ! Open logfile
+ open(111, file='input_alternative.nml', iostat=iosnml) ! Open of input nml
+ do while (ioslog.eq.0) ! Check for the first two written lines, then stay at this
+ ! position so we can compare from here on to the namelist
+ read(110, '(A)', iostat=ioslog) line
+ ! Check if we have found the version line
+ if (index(line, "READ_INPUT_NML: "//trim(version)).ne.0) then
+ version_bool = .true.
+ end if
+ ! Check if we have found the filename line
+ if (index(line, "READ_INPUT_NML: "//trim(filename)).ne.0) then
+ filename_bool = .true.
+ end if
+ ! Check if we have found all we are looking for
+ if (version_bool.and.filename_bool) then
+ write(*,*) "SUCCESS: Found the first 2 written lines, version&
+ & and filename"
+ exit ! Successful test portion
+ end if
+ ! If we have reached the end of the file, was anything missed?
+ if (index(line, "Total runtime").ne.0) then
+ if (.not.version_bool) then
+ call mpp_error(FATAL, "Version not written to &
+ &logfile")
+ else if (.not.filename_bool) then
+ call mpp_error(FATAL, "Filename not written to &
+ &logfile")
+ else
+ call mpp_error(FATAL, "Logfile not written to by &
+ &read_input_nml correctly.")
+ end if
+ end if
+ end do
+ ! Make sure the read pointers for logfile and input nml are in the same
+ ! location below.
+ read(110, '(A)', iostat=ioslog) linelog
+ read(111, '(A)', iostat=iosnml) linenml
+ do while (TRIM(linelog).ne.TRIM(" "//linenml))
+ read(110, '(A)', iostat=ioslog) linelog
+ end do
+ ! Compare contents of logfile and the input nml
+ do while (iosnml.eq.0)
+ if (TRIM(linelog).ne.TRIM(" "//linenml)) then
+ call mpp_error(FATAL, linelog//" -Does not equal- "//&
+ &linenml//". Namelist not written to logfile &
+ &correctly")
+ end if
+ read(110, '(A)', iostat=ioslog) linelog
+ read(111, '(A)', iostat=iosnml) linenml
+ end do
+ write(*,*) "SUCCESS: Matched all lines from input nml to the logfile"
+ close(110)
+ close(111)
+
+else if (test_numb.eq.3) then
+ ! Test 3: Tests with an invalid pelist_name_in pass as an argument. An invalid
+ ! pelist_name_in would be one who's size is greater than local pelist_name
+
+ call mpp_init ! Initialize mpp
+ call read_input_nml(mpp_get_current_pelist_name()//"e")
+ ! Call read_input_nml
+ ! with the local
+ ! pelist_name plus an
+ ! extra character "e"
+ call mpp_exit() ! Exit mpp
+
+else if (test_numb.eq.4) then
+ ! Test 4: Tests an empty input nml. No arguments are passed.
+
+ filename = "input.nml"
+ call mpp_init() ! Initialize mpp
+ call read_input_nml()
+ call mpp_exit()
+ open(44, file='logfile.000000.out', iostat=ios)
+ do while (ios.eq.0) ! Check for the first two written lines
+ read(44, '(A)', iostat=ios) line
+ ! Check if we have found the version line
+ if (index(line, "READ_INPUT_NML: "//trim(version)).ne.0) then
+ version_bool = .true.
+ end if
+ ! Check if we have found the filename line
+ if (index(line, "READ_INPUT_NML: "//trim(filename)).ne.0) then
+ filename_bool = .true.
+ end if
+ ! Check if we have found all we are looking for
+ if (version_bool.and.filename_bool) then
+ write(*,*) "SUCCESS: Found the first 2 written lines, version&
+ & and filename"
+ exit ! Successful test
+ end if
+ ! If we have reached the end of the file, was anything missed?
+ if (index(line, "Total runtime").ne.0) then
+ if (.not.version_bool) then
+ call mpp_error(FATAL, "Version not written to &
+ &logfile")
+ else if (.not.filename_bool) then
+ call mpp_error(FATAL, "Filename not written to &
+ &logfile")
+ else
+ call mpp_error(FATAL, "Logfile not written to by &
+ &read_input_nml correctly.")
+ end if
+ end if
+ end do
+ close(44)
+end if
+
+end program test_read_input_nml
diff --git a/test_fms/mpp/test_read_input_nml.sh b/test_fms/mpp/test_read_input_nml.sh
new file mode 100644
index 0000000000..3fdde636bd
--- /dev/null
+++ b/test_fms/mpp/test_read_input_nml.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+#***********************************************************************
+# GNU Lesser General Public License
+#
+# This file is part of the GFDL Flexible Modeling System (FMS).
+#
+# FMS is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or (at
+# your option) any later version.
+#
+# FMS is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with FMS. If not, see .
+#***********************************************************************
+
+# This is part of the GFDL FMS package. This is a shell script to
+# execute tests in the test_fms/mpp directory.
+
+# Colin Gladue 04/27/2020
+
+# Set common test settings.
+. ../test_common.sh
+
+# Run tests
+
+run_test test_read_input_nml 1
diff --git a/test_fms/mpp/test_read_input_nml2.sh b/test_fms/mpp/test_read_input_nml2.sh
new file mode 100644
index 0000000000..74576a8ed2
--- /dev/null
+++ b/test_fms/mpp/test_read_input_nml2.sh
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+#***********************************************************************
+# GNU Lesser General Public License
+#
+# This file is part of the GFDL Flexible Modeling System (FMS).
+#
+# FMS is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or (at
+# your option) any later version.
+#
+# FMS is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with FMS. If not, see .
+#***********************************************************************
+
+# This is part of the GFDL FMS package. This is a shell script to
+# execute tests in the test_fms/mpp directory.
+
+# Colin Gladue 04/27/2020
+
+touch test_numb_base.nml
+echo "&test_read_input_nml_nml" > test_numb_base.nml
+echo "test_numb = 0" >> test_numb_base.nml
+echo "/" >> test_numb_base.nml
+
+# Test 1
+sed "s/test_numb = [0-9]/test_numb = 1/" test_numb_base.nml > test_numb.nml
+cp input_base.nml input.nml
+./test_read_input_nml.sh
+if [ $? = 0 ]; then
+ echo "Test 1 has passed"
+else
+ echo "ERROR: Test 1 was unsuccessful."
+ exit 11
+fi
+
+# Test 2
+sed "s/test_numb = [0-9]/test_numb = 2/" test_numb_base.nml > test_numb.nml
+cp input_base.nml input_alternative.nml
+./test_read_input_nml.sh
+if [ $? = 0 ]; then
+ echo "Test 2 has passed"
+else
+ echo "ERROR: Test 2 was unsuccessful."
+ exit 12
+fi
+
+# Test 3
+sed "s/test_numb = [0-9]/test_numb = 3/" test_numb_base.nml > test_numb.nml
+cp input_base.nml input.nml
+./test_read_input_nml.sh
+if [ $? = 1 ]; then
+ echo "Test 3 has passed"
+else
+ echo "ERROR: Test 3 did not hit the error it was expected to"
+ exit 13
+fi
+
+# Test 4
+sed "s/test_numb = [0-9]/test_numb = 4/" test_numb_base.nml > test_numb.nml
+rm input.nml
+touch input.nml # Achieve a blank namelist to be read
+./test_read_input_nml.sh
+if [ $? = 0 ]; then
+ echo "Test 4 has passed"
+else
+ echo "ERROR: Test 4 was unsuccessful."
+ exit 14
+fi
+
+cp input_base.nml input.nml