-
Notifications
You must be signed in to change notification settings - Fork 137
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
Modifydiag_field_add_attribute
to accept r4 and r8
#1625
Open
uramirez8707
wants to merge
4
commits into
NOAA-GFDL:main
Choose a base branch
from
uramirez8707:diag_field_add_fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+235
−61
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
!*********************************************************************** | ||
!* 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 <http://www.gnu.org/licenses/>. | ||
!*********************************************************************** | ||
|
||
program test_diag_attribute_add | ||
use platform_mod, only: r4_kind, r8_kind | ||
use mpp_mod, only: FATAL, mpp_error | ||
use fms_mod, only: fms_init, fms_end | ||
use diag_manager_mod, only: diag_axis_init, register_static_field, diag_send_complete, send_data | ||
use diag_manager_mod, only: register_diag_field, diag_field_add_attribute | ||
use diag_manager_mod, only: diag_manager_init, diag_manager_end, diag_manager_set_time_end | ||
use time_manager_mod, only: time_type, set_calendar_type, set_date, JULIAN, set_time, OPERATOR(+) | ||
use fms2_io_mod | ||
|
||
implicit none | ||
|
||
integer :: id_potatoes | ||
integer :: i | ||
type(time_type) :: Time | ||
type(time_type) :: Time_step | ||
logical :: used | ||
real(kind=r4_kind) :: fbuffer(2) = (/ 13., 14./) | ||
real(kind=r8_kind) :: dbuffer(2) = (/ 23., 24./) | ||
integer :: ibuffer(2) = (/ 551, 552/) | ||
character(len=20) :: cbuffer = "Hello World" | ||
|
||
call fms_init() | ||
call set_calendar_type(JULIAN) | ||
call diag_manager_init() | ||
|
||
Time = set_date(2,1,1,0,0,0) | ||
Time_step = set_time (3600*4,0) | ||
call diag_manager_set_time_end(set_date(2,1,2,0,0,0)) | ||
|
||
id_potatoes = register_diag_field ('food_mod', 'potatoes', init_time=Time) | ||
call diag_field_add_attribute(id_potatoes, "real_32", fbuffer(1)) | ||
call diag_field_add_attribute(id_potatoes, "real_32_1d", fbuffer) | ||
call diag_field_add_attribute(id_potatoes, "real_64", dbuffer(1)) | ||
call diag_field_add_attribute(id_potatoes, "real_64_1d", dbuffer ) | ||
call diag_field_add_attribute(id_potatoes, "integer", ibuffer(1)) | ||
call diag_field_add_attribute(id_potatoes, "integer_1d", ibuffer) | ||
call diag_field_add_attribute(id_potatoes, "some_string", cbuffer) | ||
|
||
do i = 1, 6 | ||
Time = Time + Time_step | ||
used = send_data(id_potatoes, real(103.201), Time) | ||
call diag_send_complete(Time_step) | ||
enddo | ||
|
||
call diag_manager_end(Time) | ||
|
||
call check_output() | ||
call fms_end() | ||
|
||
contains | ||
|
||
subroutine check_output() | ||
type(FmsNetcdfFile_t) :: fileobj !< FMS2io fileobj | ||
character(len=256) :: cbuffer_out !< Buffer to read stuff into | ||
integer :: ibuffer_out(2) | ||
real(kind=r4_kind) :: fbuffer_out(2) | ||
real(kind=r8_kind) :: dbuffer_out(2) | ||
|
||
if (.not. open_file(fileobj, "food_file.nc", "read")) & | ||
call mpp_error(FATAL, "food_file.nc was not created by the diag manager!") | ||
if (.not. variable_exists(fileobj, "potatoes")) & | ||
call mpp_error(FATAL, "potatoes is not in food_file.nc") | ||
|
||
!! Checking the string attributes | ||
call get_variable_attribute(fileobj, "potatoes", "some_string", cbuffer_out) | ||
if (trim(cbuffer_out) .ne. trim(cbuffer)) call mpp_error(FATAL, "some_string is not the expected attribute") | ||
|
||
!! Checking the integer attributes | ||
ibuffer_out = -999 | ||
call get_variable_attribute(fileobj, "potatoes", "integer", ibuffer_out(1)) | ||
if (ibuffer(1) .ne. ibuffer_out(1)) call mpp_error(FATAL, "integer is not the expected attribute") | ||
|
||
ibuffer_out = -999 | ||
call get_variable_attribute(fileobj, "potatoes", "integer_1d", ibuffer_out) | ||
if (ibuffer(1) .ne. ibuffer_out(1)) call mpp_error(FATAL, "integer_1d is not the expected attribute") | ||
if (ibuffer(2) .ne. ibuffer_out(2)) call mpp_error(FATAL, "integer_1d is not the expected attribute") | ||
|
||
!! Checking the double attributes | ||
dbuffer_out = -999 | ||
call get_variable_attribute(fileobj, "potatoes", "real_64", dbuffer_out(1)) | ||
if (dbuffer(1) .ne. dbuffer_out(1)) call mpp_error(FATAL, "real_64 is not the expected attribute") | ||
|
||
dbuffer_out = -999 | ||
call get_variable_attribute(fileobj, "potatoes", "real_64_1d", dbuffer_out) | ||
if (dbuffer(1) .ne. dbuffer_out(1)) call mpp_error(FATAL, "real_64_1d is not the expected attribute") | ||
if (dbuffer(2) .ne. dbuffer_out(2)) call mpp_error(FATAL, "real_64_1d is not the expected attribute") | ||
|
||
!! Checking the float attributes | ||
fbuffer_out = -999 | ||
call get_variable_attribute(fileobj, "potatoes", "real_32", fbuffer_out(1)) | ||
if (fbuffer(1) .ne. fbuffer_out(1)) call mpp_error(FATAL, "real_32 is not the expected attribute") | ||
|
||
fbuffer_out = -999 | ||
call get_variable_attribute(fileobj, "potatoes", "real_32_1d", fbuffer_out) | ||
if (fbuffer(1) .ne. fbuffer_out(1)) call mpp_error(FATAL, "real_32_1d is not the expected attribute") | ||
if (fbuffer(2) .ne. fbuffer_out(2)) call mpp_error(FATAL, "real_32_1d is not the expected attribute") | ||
|
||
call close_file(fileobj) | ||
end subroutine check_output | ||
end program test_diag_attribute_add |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/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 <http://www.gnu.org/licenses/>. | ||
#*********************************************************************** | ||
|
||
# Set common test settings. | ||
. ../test-lib.sh | ||
|
||
if [ -z "${skipflag}" ]; then | ||
# create and enter directory for in/output files | ||
output_dir | ||
|
||
cat <<_EOF > diag_table.yaml | ||
title: test_diag_manager | ||
base_date: 2 1 1 0 0 0 | ||
|
||
diag_files: | ||
- file_name: food_file | ||
freq: 4 hours | ||
time_units: hours | ||
unlimdim: time | ||
reduction: none | ||
kind: r4 | ||
module: food_mod | ||
varlist: | ||
- var_name: potatoes | ||
_EOF | ||
|
||
# remove any existing files that would result in false passes during checks | ||
rm -f *.nc | ||
|
||
my_test_count=1 | ||
cat <<_EOF > input.nml | ||
&diag_manager_nml | ||
use_modern_diag=.true. | ||
max_field_attributes = 10 | ||
/ | ||
_EOF | ||
|
||
test_expect_success "Testing diag_field_attribute_add (test $my_test_count)" ' | ||
mpirun -n 1 ../test_diag_attribute_add | ||
' | ||
fi | ||
test_done |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a r8 value is coming in, shouldn't this be an
NF90_DOUBLE
in both?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In both routines, not both lines, that is.