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 5 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
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