Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions diag_manager/fms_diag_field_object.F90
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ subroutine fms_register_diag_field_obj &
!> get the optional arguments if included and the diagnostic is in the diag table
if (present(longname)) this%longname = trim(longname)
if (present(standname)) this%standname = trim(standname)
do i=1, SIZE(diag_field_indices)
yaml_var_ptr => diag_yaml%get_diag_field_from_id(diag_field_indices(i))

!! Add standard name to the diag_yaml object, so that it can be used when writing the diag_manifest
call yaml_var_ptr%add_standname(standname)
enddo

!> Ignore the units if they are set to "none". This is to reproduce previous diag_manager behavior
if (present(units)) then
Expand Down
15 changes: 12 additions & 3 deletions diag_manager/fms_diag_file_object.F90
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module fms_diag_file_object_mod
use fms_diag_field_object_mod, only: fmsDiagField_type
use fms_diag_output_buffer_mod, only: fmsDiagOutputBuffer_type
use mpp_mod, only: mpp_get_current_pelist, mpp_npes, mpp_root_pe, mpp_pe, mpp_error, FATAL, stdout, &
uppercase, lowercase, NOTE
uppercase, lowercase, NOTE, mpp_max
use platform_mod, only: FMS_FILE_LEN
use mpp_domains_mod, only: mpp_get_ntile_count, mpp_get_UG_domain_ntiles, mpp_get_io_domain_layout, &
mpp_get_io_domain_UG_layout
Expand Down Expand Up @@ -1615,12 +1615,21 @@ end subroutine init_unlim_dim

!> \brief Get the number of time levels that were actually written to the file
!! \return Number of time levels that were actually written to the file
pure function get_num_time_levels(this) &
function get_num_time_levels(this) &
result(res)
class(fmsDiagFileContainer_type), intent(in), target :: this !< The file object
integer :: res

res = this%FMS_diag_file%num_time_levels
if (this%is_regional()) then
!! If this is a subregional file, num_time_levels will be set to 0 for
!! all PEs that are not in the subregion. If the root pe is not in the subregion
!! then the num_time_levels will not be correct, so this is just getting the max
!! from all PEs
res = this%FMS_diag_file%num_time_levels
call mpp_max(res)
else
res = this%FMS_diag_file%num_time_levels
endif
end function

!> \brief Get the number of tiles in the file's domain
Expand Down
25 changes: 25 additions & 0 deletions diag_manager/fms_diag_yaml.F90
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ module fms_diag_yaml_mod
character (len=:), private, allocatable :: var_outname !< Name of the variable as written to the file
character (len=:), private, allocatable :: var_longname !< Overwrites the long name of the variable
character (len=:), private, allocatable :: var_units !< Overwrites the units
character (len=:), private, allocatable :: standard_name !< Standard_name (saved from the register_diag_field call)
real(kind=r4_kind), private :: var_zbounds(2) !< The z axis limits [vert_min, vert_max]
integer , private :: n_diurnal !< Number of diurnal samples
!! 0 if var_reduction is not "diurnalXX"
Expand Down Expand Up @@ -243,8 +244,10 @@ module fms_diag_yaml_mod
procedure :: has_var_attributes
procedure :: has_n_diurnal
procedure :: has_pow_value
procedure :: has_standname
procedure :: add_axis_name
procedure :: is_file_subregional
procedure :: add_standname

end type diagYamlFilesVar_type

Expand Down Expand Up @@ -1453,6 +1456,12 @@ pure logical function has_pow_value(this)
class(diagYamlFilesVar_type), intent(in) :: this !< diagYamlvar_type object to inquire
has_pow_value = (this%pow_value .ne. 0)
end function has_pow_value
!> @brief Checks if diag_file_obj%standname is set
!! @return true if diag_file_obj%standname is set
pure logical function has_standname(this)
class(diagYamlFilesVar_type), intent(in) :: this !< diagYamlvar_type object to inquire
has_standname = (this%standard_name .ne. "")
end function has_standname

!> @brief Checks if diag_file_obj%diag_title is allocated
!! @return true if diag_file_obj%diag_title is allocated
Expand Down Expand Up @@ -1814,6 +1823,7 @@ subroutine fms_diag_yaml_out(ntimes, ntiles, ndistributedfiles)
call fms_f2c_string(keys3(key3_i)%key9, 'n_diurnal')
call fms_f2c_string(keys3(key3_i)%key10, 'pow_value')
call fms_f2c_string(keys3(key3_i)%key11, 'dimensions')
call fms_f2c_string(keys3(key3_i)%key12, 'standard_name')
if (varptr%has_var_module()) call fms_f2c_string(vals3(key3_i)%val1, varptr%var_module)
if (varptr%has_var_varname()) call fms_f2c_string(vals3(key3_i)%val2, varptr%var_varname)
if (varptr%has_var_reduction()) then
Expand Down Expand Up @@ -1853,6 +1863,9 @@ subroutine fms_diag_yaml_out(ntimes, ntiles, ndistributedfiles)

tmpstr1 = ''; tmpstr1 = varptr%var_axes_names
call fms_f2c_string(vals3(key3_i)%val11, trim(adjustl(tmpstr1)))

if(diag_yaml%diag_fields(varnum_i)%has_standname())&
call fms_f2c_string(vals3(key3_i)%val12, diag_yaml%diag_fields(varnum_i)%standard_name)
enddo
endif

Expand Down Expand Up @@ -2080,6 +2093,18 @@ subroutine add_axis_name( this, axis_name )

end subroutine add_axis_name

!> @brief Adds the standname for the DiagYamlFilesVar_type
subroutine add_standname (this, standard_name)
class(diagYamlFilesVar_type), intent(inout) :: this
character(len=*), optional, intent(in) :: standard_name

if (present(standard_name)) then
this%standard_name = standard_name(1:len_trim(standard_name))
else
this%standard_name = ""
endif
end subroutine add_standname

pure function is_file_subregional( this ) &
result(res)
class(diagYamlFilesVar_type), intent(in) :: this
Expand Down
30 changes: 30 additions & 0 deletions test_fms/diag_manager/check_subregional.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

!> @brief Checks the output file after running test_subregional
program check_subregional
#ifdef use_yaml
use fms_mod, only: fms_init, fms_end, string
use fms2_io_mod, only: FmsNetcdfFile_t, read_data, close_file, open_file, get_dimension_size, file_exists
use mpp_mod, only: mpp_npes, mpp_error, FATAL, mpp_pe
use platform_mod, only: r4_kind, r8_kind
use yaml_parser_mod, only: open_and_parse_file, get_num_blocks, get_block_ids, get_value_from_key

implicit none

Expand All @@ -33,6 +35,7 @@ program check_subregional
call check_subregional_file("test_subregional.nc")
call check_subregional_file("test_subregional2.nc")
call check_corner_files()
call check_manifest()

call fms_end()

Expand Down Expand Up @@ -203,4 +206,31 @@ subroutine check_corner_files()

end subroutine check_corner_files

!> @brief Check that the number of time levels was written correctly in the diag manifest yaml
subroutine check_manifest()
integer :: diag_yaml_id !< Id for the diag manifest yaml
integer :: nfiles !< Number of diag files in the yaml
integer, allocatable :: file_ids(:) !< Ids for all the diag files in the yaml
integer :: i !< For do loops
integer :: ntime_levels !< Number of time levels are read from the yaml

if ( .not. file_exists("diag_manifest.yaml.0")) &
call mpp_error(FATAL, "diag manifest file does not exist!")

diag_yaml_id = open_and_parse_file("diag_manifest.yaml.0")

nfiles = get_num_blocks(diag_yaml_id, "diag_files")
allocate(file_ids(nfiles))
call get_block_ids(diag_yaml_id, "diag_files", file_ids)

do i = 1, nfiles
ntime_levels = -999
call get_value_from_key(diag_yaml_id, file_ids(i), "number_of_timelevels", ntime_levels)

if (ntime_levels .ne. 8)&
call mpp_error(FATAL, "The number of time levels is not correct:: "//string(ntime_levels))
enddo

end subroutine check_manifest
#endif
end program
16 changes: 16 additions & 0 deletions test_fms/diag_manager/test_diag_manager2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: z
standard_name:
sub_region:
- grid_type:
tile:
Expand Down Expand Up @@ -948,6 +949,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: time y x
standard_name:
- module: ocn_mod
var_name: var2
reduction: average
Expand All @@ -959,6 +961,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: time x y
standard_name:
sub_region:
- grid_type:
tile:
Expand Down Expand Up @@ -993,6 +996,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: time y3 x3
standard_name:
- module: atm_mod
var_name: var4
reduction: average
Expand All @@ -1004,6 +1008,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: time z y3 x3
standard_name:
- module: atm_mod
var_name: var6
reduction: average
Expand All @@ -1015,6 +1020,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: time z
standard_name: I hope this is the MDTF tables
- module: atm_mod
var_name: var4
reduction: average
Expand All @@ -1026,6 +1032,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: time z_sub01 y3 x3
standard_name:
sub_region:
- grid_type:
tile:
Expand Down Expand Up @@ -1060,6 +1067,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: time grid_index
standard_name:
- module: atm_mod
var_name: var7
reduction: none
Expand All @@ -1071,6 +1079,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: z
standard_name:
sub_region:
- grid_type:
tile:
Expand Down Expand Up @@ -1105,6 +1114,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: time
standard_name: Land is important!
sub_region:
- grid_type:
tile:
Expand Down Expand Up @@ -1139,6 +1149,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: time z y3_sub01 x3_sub01
standard_name:
sub_region:
- grid_type: index
tile: 1
Expand Down Expand Up @@ -1173,6 +1184,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: time y x
standard_name:
sub_region:
- grid_type:
tile:
Expand Down Expand Up @@ -1207,6 +1219,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: time y x
standard_name:
sub_region:
- grid_type:
tile:
Expand Down Expand Up @@ -1241,6 +1254,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: time y x
standard_name:
sub_region:
- grid_type:
tile:
Expand Down Expand Up @@ -1275,6 +1289,7 @@ diag_files:
n_diurnal:
pow_value:
dimensions: time y x
standard_name:
sub_region:
- grid_type:
tile:
Expand Down Expand Up @@ -1309,6 +1324,7 @@ diag_files:
n_diurnal: 12
pow_value:
dimensions: time time_of_day_12 y x
standard_name:
sub_region:
- grid_type:
tile:
Expand Down
6 changes: 4 additions & 2 deletions test_fms/diag_manager/test_modern_diag.F90
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ program test_modern_diag
id_var4 = register_diag_field ('atm_mod', 'var4', (/id_x3, id_y3, id_z/), Time, &
'3D var in a cube sphere domain', 'mullions')
id_var5 = register_diag_field ('lnd_mod', 'var5', (/id_ug/), Time, 'Var in a UG domain', 'mullions')
id_var6 = register_diag_field ('atm_mod', 'var6', (/id_z/), Time, 'Var not domain decomposed', 'mullions')
id_var6 = register_diag_field ('atm_mod', 'var6', (/id_z/), Time, 'Var not domain decomposed', 'mullions', &
standard_name="I hope this is the MDTF tables")

!< This has the same name as var1, but it should have a different id because the module is different
!! so it should have its own diag_obj
id_var7 = register_diag_field ('lnd_mod', 'var1', Time, 'Some scalar var', 'mullions')
id_var7 = register_diag_field ('lnd_mod', 'var1', Time, 'Some scalar var', 'mullions', &
standard_name="Land is important!")
id_var8 = register_static_field ('atm_mod', 'var7', (/id_z/), "Be static!", "none")

if (.not. debug) then
Expand Down
Loading