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

Moving empty and non-existent data table handling inside data_override #933

Merged
merged 6 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
73 changes: 44 additions & 29 deletions data_override/data_override.F90
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
module data_override_mod
use yaml_parser_mod
use constants_mod, only: PI
use mpp_mod, only : mpp_error, FATAL, WARNING, stdout, stdlog, mpp_max
use mpp_mod, only : mpp_error, FATAL, WARNING, NOTE, stdout, stdlog, mpp_max
use mpp_mod, only : input_nml_file
use horiz_interp_mod, only : horiz_interp_init, horiz_interp_new, horiz_interp_type, &
assignment(=)
Expand Down Expand Up @@ -261,6 +261,10 @@ subroutine data_override_init(Atm_domain_in, Ocean_domain_in, Ice_domain_in, Lan
module_is_initialized = .TRUE.

if ( .NOT. (atm_on .or. ocn_on .or. lnd_on .or. ice_on .or. lndUG_on)) return
if (table_size .eq. 0) then
call mpp_error(NOTE, "data_table is empty, not doing any data_overrides")
return
endif
call fms2_io_init

! Test if grid_file is already opened
Expand Down Expand Up @@ -367,7 +371,14 @@ subroutine read_table(data_table)

! Read coupler_table
open(newunit=iunit, file='data_table', action='READ', iostat=io_status)
if(io_status/=0) call mpp_error(FATAL, 'data_override_mod: Error in opening file data_table')
if(io_status/=0) then
if(io_status==29) then
Copy link
Member

Choose a reason for hiding this comment

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

Is this compiler or system dependent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ugh, you're right, I thought I was being clever here and using a "standard". I guess I can just use INQUIRE instead?

Copy link
Member

Choose a reason for hiding this comment

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

Don't feel bad, i ALWAYS write write (6,*)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've now pushed a change that should also obviate the need to go through the reading table portion if the file doesn't exist... let me know if anything looks like it won't work with that.

call mpp_error(NOTE, 'data_override_mod: File data_table does not exist.')
else
call mpp_error(FATAL, 'data_override_mod: Error in opening file data_table.')
endif
endif


ntable = 0
ntable_lima = 0
Expand Down Expand Up @@ -495,35 +506,39 @@ subroutine read_table_yaml(data_table)
integer :: file_id

file_id = open_and_parse_file("data_table.yaml")
nentries = get_num_blocks(file_id, "data_table")
allocate(data_table(nentries))
allocate(entry_id(nentries))
call get_block_ids(file_id, "data_table", entry_id)

do i = 1, nentries
call get_value_from_key(file_id, entry_id(i), "gridname", data_table(i)%gridname)
call get_value_from_key(file_id, entry_id(i), "fieldname_code", data_table(i)%fieldname_code)
call get_value_from_key(file_id, entry_id(i), "fieldname_file", data_table(i)%fieldname_file)
call get_value_from_key(file_id, entry_id(i), "file_name", data_table(i)%file_name)
call get_value_from_key(file_id, entry_id(i), "interpol_method", data_table(i)%interpol_method)
call get_value_from_key(file_id, entry_id(i), "factor", data_table(i)%factor)
call get_value_from_key(file_id, entry_id(i), "region_type", buffer, is_optional=.true.)

if(trim(buffer) == "inside_region" ) then
data_table(i)%region_type = INSIDE_REGION
else if( trim(buffer) == "outside_region" ) then
data_table(i)%region_type = OUTSIDE_REGION
else
data_table(i)%region_type = NO_REGION
endif

call get_value_from_key(file_id, entry_id(i), "lon_start", data_table(i)%lon_start, is_optional=.true.)
call get_value_from_key(file_id, entry_id(i), "lon_end", data_table(i)%lon_end, is_optional=.true.)
call get_value_from_key(file_id, entry_id(i), "lat_start", data_table(i)%lat_start, is_optional=.true.)
call get_value_from_key(file_id, entry_id(i), "lat_end", data_table(i)%lat_end, is_optional=.true.)
if (file_id==999) then
nentries = 0
else
nentries = get_num_blocks(file_id, "data_table")
allocate(data_table(nentries))
allocate(entry_id(nentries))
call get_block_ids(file_id, "data_table", entry_id)

do i = 1, nentries
call get_value_from_key(file_id, entry_id(i), "gridname", data_table(i)%gridname)
call get_value_from_key(file_id, entry_id(i), "fieldname_code", data_table(i)%fieldname_code)
call get_value_from_key(file_id, entry_id(i), "fieldname_file", data_table(i)%fieldname_file)
call get_value_from_key(file_id, entry_id(i), "file_name", data_table(i)%file_name)
call get_value_from_key(file_id, entry_id(i), "interpol_method", data_table(i)%interpol_method)
call get_value_from_key(file_id, entry_id(i), "factor", data_table(i)%factor)
call get_value_from_key(file_id, entry_id(i), "region_type", buffer, is_optional=.true.)

if(trim(buffer) == "inside_region" ) then
data_table(i)%region_type = INSIDE_REGION
else if( trim(buffer) == "outside_region" ) then
data_table(i)%region_type = OUTSIDE_REGION
else
data_table(i)%region_type = NO_REGION
endif

call get_value_from_key(file_id, entry_id(i), "lon_start", data_table(i)%lon_start, is_optional=.true.)
call get_value_from_key(file_id, entry_id(i), "lon_end", data_table(i)%lon_end, is_optional=.true.)
call get_value_from_key(file_id, entry_id(i), "lat_start", data_table(i)%lat_start, is_optional=.true.)
call get_value_from_key(file_id, entry_id(i), "lat_end", data_table(i)%lat_end, is_optional=.true.)

end do
end do

end if
table_size = nentries !< Because one variable is not enough
end subroutine read_table_yaml
#endif
Expand Down
7 changes: 7 additions & 0 deletions parser/yaml_parser.F90
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,16 @@ function open_and_parse_file(filename) &

character(len=*), intent(in) :: filename !< Filename of the yaml file
logical :: sucess !< Flag indicating if the read was sucessful
logical :: yaml_exists !< Flag indicating whether the yaml exists

integer :: file_id

inquire(file=trim(filename), EXIST=yaml_exists)
if (.not. yaml_exists) then
file_id = 999
call mpp_error(NOTE, "The yaml file:"//trim(filename)//" does not exist, hopefully this is your intent!")
return
end if
sucess = open_and_parse_file_wrap(trim(filename)//c_null_char, file_id)
if (.not. sucess) call mpp_error(FATAL, "Error opening the yaml file:"//trim(filename)//". Check the file!")

Expand Down
104 changes: 39 additions & 65 deletions tap-driver.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
#!/bin/sh

#***********************************************************************
# GNU Lesser General Public License
#
# This file is part of the GFDL Flexible Modeling System (FMS).
#! /bin/sh
# Copyright (C) 2011-2013 Free Software Foundation, Inc.
#
# 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.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, 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.
# This program 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 <http://www.gnu.org/licenses/>.
#***********************************************************************
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.

# Ryan Mulhall 2/2021
# Modified from original to add verbose output
# Test script output enabled by setting SH_LOG_DRIVER_FLAGS='-v' or '--verbose'
# also can be enabled with TEST_VERBOSE=true
# This file is maintained in Automake, please report
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.

scriptversion=2013-12-23.17; # UTC
scriptversion=2011-12-27.17; # UTC

# Make unconditional expansion of undefined variables an error. This
# helps a lot in preventing typo-related bugs.
Expand Down Expand Up @@ -53,9 +52,8 @@ Usage:
[--expect-failure={yes|no}] [--color-tests={yes|no}]
[--enable-hard-errors={yes|no}] [--ignore-exit]
[--diagnostic-string=STRING] [--merge|--no-merge]
[--verbose | -v] [--comments|--no-comments]
[--] TEST-COMMAND
The '--test-name', '-log-file' and '--trs-file' options are mandatory.
[--comments|--no-comments] [--] TEST-COMMAND
The \`--test-name', \`--log-file' and \`--trs-file' options are mandatory.
END
}

Expand All @@ -70,13 +68,6 @@ merge=0
ignore_exit=0
comments=0
diag_string='#'
# Prints test output if TEST_VERBOSE is set
if test -z ${TEST_VERBOSE+x} ; then
verbose=false
else
verbose=true
fi

while test $# -gt 0; do
case $1 in
--help) print_usage; exit $?;;
Expand All @@ -93,7 +84,6 @@ while test $# -gt 0; do
--comments) comments=1;;
--no-comments) comments=0;;
--diagnostic-string) diag_string=$2; shift;;
--verbose | -v) verbose="true";;
--) shift; break;;
-*) usage_error "invalid option: '$1'";;
esac
Expand Down Expand Up @@ -125,11 +115,6 @@ else
init_colors=''
fi

# use fd 5 to output tests' run scripts
[[ "$verbose" = "true" ]] && exec 5>&1 || exec 5>/dev/null
# use fd 6 to output individual return statuses
exec 6>&1

# :; is there to work around a bug in bash 3.2 (and earlier) which
# does not always set '$?' properly on redirection failure.
# See the Autoconf manual for more details.
Expand All @@ -147,13 +132,13 @@ exec 6>&1
# last `echo $?' statement), and would thus die reporting an internal
# error.
# For more information, see the Autoconf manual and the threads:
# <https://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
# <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
# <http://mail.opensolaris.org/pipermail/ksh93-integration-discuss/2009-February/004121.html>
trap : 1 3 2 13 15
if test $merge -gt 0; then
exec 2>&6
exec 2>&1
else
exec 2>&5
exec 2>&3
fi
"$@"
echo $?
Expand All @@ -167,11 +152,9 @@ exec 6>&1
-v ignore_exit="$ignore_exit" \
-v comments="$comments" \
-v diag_string="$diag_string" \
-v verbose="$verbose" \
-v skippedTests="" \
'
# TODO: the usages of "cat >&3" below could be optimized when using
# GNU awk, and/on on systems that supports /dev/fd/.
# FIXME: the usages of "cat >&3" below could be optimized when using
# FIXME: GNU awk, and/on on systems that supports /dev/fd/.

# Implementation note: in what follows, `result_obj` will be an
# associative array that (partly) simulates a TAP result object
Expand Down Expand Up @@ -220,13 +203,13 @@ function must_recheck()
# be copied into the "global" test-suite.log.
function copy_in_global_log()
{
#for (k in test_results_seen)
# if (k != "PASS")
# return 1
#return verbose == "true" ? 1 : 0;
return 1
for (k in test_results_seen)
if (k != "PASS")
return 1
return 0
}

# FIXME: this can certainly be improved ...
function get_global_test_result()
{
if ("ERROR" in test_results_seen)
Expand Down Expand Up @@ -290,10 +273,10 @@ function report(result, details)
if (length(details))
msg = msg " " details
# Output on console might be colorized.
print decorate_result(result) msg | "cat >&6"
print decorate_result(result) msg
# Log the result in the log file too, to help debugging (this is
# especially true when said result is a TAP error or "Bail out!").
print result msg | "cat";
print result msg | "cat >&3";
}

function testsuite_error(error_message)
Expand Down Expand Up @@ -325,8 +308,6 @@ function handle_tap_result()
details = details " # " result_obj["directive"];
if (length(result_obj["explanation"]))
details = details " " result_obj["explanation"]
if (result_obj["directive"] == "SKIP")
skippedTests= (skippedTests=="") ? result_obj["number"] : skippedTests "," result_obj["number"]
}

report(stringify_result_obj(result_obj), details)
Expand Down Expand Up @@ -562,7 +543,7 @@ while (1)
$0 = curline
}
# Copy any input line verbatim into the log file.
print | "cat"
print | "cat >&3"
# Parsing of TAP input should stop after a "Bail out!" directive.
if (bailed_out)
continue
Expand Down Expand Up @@ -648,11 +629,6 @@ if (!bailed_out)
}
}

if (skippedTests != "") {
print color_map["blu"] "Skipped the following test numbers in " test_script_name ": " | "cat >&6"
print color_map["blu"] skippedTests | "cat >&6"
print color_map["std"] | "cat >&6"# reset text color
}
write_test_results()

exit 0
Expand All @@ -661,18 +637,16 @@ exit 0
'

# TODO: document that we consume the file descriptor 3 :-(
#} 3>"$log_file"
} | tee "$log_file" >&5

} 3>"$log_file"

test $? -eq 0 || fatal "I/O or internal error"

# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'before-save-hook 'time-stamp)
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC0"
# time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End:
7 changes: 1 addition & 6 deletions test_fms/parser/test_yaml_parser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
. ../test-lib.sh

if [ ! -z $parser_skip ]; then
SKIP_TESTS='test_yaml_parser.[1-22]'
SKIP_TESTS='test_yaml_parser.[1-21]'
bensonr marked this conversation as resolved.
Show resolved Hide resolved
fi

touch input.nml
Expand Down Expand Up @@ -95,11 +95,6 @@ test_expect_success "parser_demo2" '
mpirun -n 1 ./parser_demo2
'

printf "&check_crashes_nml \n missing_file = .true. \n/" | cat > input.nml
test_expect_failure "missing file" '
mpirun -n 1 ./check_crashes
'

printf "&check_crashes_nml \n bad_conversion = .true. \n/" | cat > input.nml
test_expect_failure "bad conversion" '
mpirun -n 1 ./check_crashes
Expand Down