Skip to content

Commit

Permalink
feat: redesign objects and add diag field object (NOAA-GFDL#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-robinson authored and rem1776 committed May 1, 2024
1 parent 3667bc7 commit fca0fba
Show file tree
Hide file tree
Showing 8 changed files with 1,214 additions and 1,236 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ list(APPEND fms_fortran_src_files
diag_manager/fms_diag_object.F90
diag_manager/fms_diag_yaml.F90
diag_manager/fms_diag_file_object.F90
diag_manager/fms_diag_field_object.F90
diag_manager/fms_diag_axis_object.F90
diag_manager/fms_diag_dlinked_list.F90
diag_manager/fms_diag_object_container.F90
Expand Down
8 changes: 6 additions & 2 deletions diag_manager/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ libdiag_manager_la_SOURCES = \
include/fms_diag_fieldbuff_update.inc \
include/fms_diag_fieldbuff_update.fh \
fms_diag_file_object.F90 \
fms_diag_field_object.F90 \
fms_diag_yaml.F90 \
fms_diag_object.F90 \
fms_diag_axis_object.F90 \
Expand All @@ -60,9 +61,11 @@ diag_util_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) diag_axis_mod.$(FC_MODEXT
diag_grid_mod.$(FC_MODEXT)
diag_table_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) diag_util_mod.$(FC_MODEXT)
fms_diag_yaml_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) diag_util_mod.$(FC_MODEXT)
fms_diag_object_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) diag_axis_mod.$(FC_MODEXT) fms_diag_file_object_mod.$(FC_MODEXT) fms_diag_yaml_mod.$(FC_MODEXT) \
fms_diag_object_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) diag_axis_mod.$(FC_MODEXT) fms_diag_file_object_mod.$(FC_MODEXT) fms_diag_field_object_mod.$(FC_MODEXT) fms_diag_yaml_mod.$(FC_MODEXT) \
diag_util_mod.$(FC_MODEXT)
fms_diag_file_object_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) diag_axis_mod.$(FC_MODEXT) fms_diag_yaml_mod.$(FC_MODEXT)
fms_diag_field_object_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) diag_axis_mod.$(FC_MODEXT) fms_diag_yaml_mod.$(FC_MODEXT) \
diag_util_mod.$(FC_MODEXT)
fms_diag_file_object_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) diag_axis_mod.$(FC_MODEXT) fms_diag_yaml_mod.$(FC_MODEXT) fms_diag_field_object_mod.$(FC_MODEXT)
fms_diag_object_container_mod.$(FC_MODEXT): fms_diag_object_mod.$(FC_MODEXT) fms_diag_dlinked_list_mod.$(FC_MODEXT)
fms_diag_axis_object_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT)
diag_manager_mod.$(FC_MODEXT): diag_axis_mod.$(FC_MODEXT) diag_data_mod.$(FC_MODEXT) diag_util_mod.$(FC_MODEXT) \
Expand All @@ -89,6 +92,7 @@ MODFILES = \
include/fms_diag_fieldbuff_update.fh
fms_diag_yaml_mod.$(FC_MODEXT) \
fms_diag_file_object_mod.$(FC_MODEXT) \
fms_diag_field_object_mod.$(FC_MODEXT) \
fms_diag_object_mod.$(FC_MODEXT) \
fms_diag_axis_object_mod.$(FC_MODEXT) \
fms_diag_dlinked_list_mod.$(FC_MODEXT) \
Expand Down
36 changes: 16 additions & 20 deletions diag_manager/diag_manager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,11 @@ MODULE diag_manager_mod
USE diag_table_mod, ONLY: parse_diag_table
USE diag_output_mod, ONLY: get_diag_global_att, set_diag_global_att
USE diag_grid_mod, ONLY: diag_grid_init, diag_grid_end
USE fms_diag_object_mod, ONLY: fmsDiagObject_type, fms_diag_object_init, fms_register_diag_field_array, &
& fms_register_diag_field_scalar, fms_diag_object_end, fms_register_static_field, fms_diag_field_add_attribute, &
& fms_get_diag_field_id
USE fms_diag_file_object_mod, only: fms_diag_files_object_initialized
#ifdef use_yaml
use fms_diag_yaml_mod, only: diag_yaml_object_init, diag_yaml_object_end, get_num_unique_fields, find_diag_field
use fms_diag_axis_object_mod, only: fms_diag_axis_object_end, fms_diag_axis_object_init
use fms_diag_file_object_mod, only: fms_diag_files_object_init
#endif
use fms_diag_object_mod, only:fms_diag_object

USE constants_mod, ONLY: SECONDS_PER_DAY
USE fms_diag_outfield_mod, ONLY: fmsDiagOutfieldIndex_type, fmsDiagOutfield_type
Expand Down Expand Up @@ -402,8 +398,9 @@ INTEGER FUNCTION register_diag_field_scalar(module_name, field_name, init_time,
CHARACTER(len=*), OPTIONAL, INTENT(in) :: realm !< String to set as the modeling_realm attribute

if (use_modern_diag) then
register_diag_field_scalar = fms_register_diag_field_scalar(module_name, field_name, init_time, &
& long_name=long_name, units=units, missing_value=missing_value, var_range=range, standard_name=standard_name, &
register_diag_field_scalar = fms_diag_object%fms_register_diag_field_scalar( &
& module_name, field_name, init_time, long_name=long_name, units=units, &
& missing_value=missing_value, var_range=range, standard_name=standard_name, &
& do_not_log=do_not_log, err_msg=err_msg, area=area, volume=volume, realm=realm)
else
register_diag_field_scalar = register_diag_field_scalar_old(module_name, field_name, init_time, &
Expand Down Expand Up @@ -440,8 +437,9 @@ INTEGER FUNCTION register_diag_field_array(module_name, field_name, axes, init_t
CHARACTER(len=*), OPTIONAL, INTENT(in) :: realm !< String to set as the modeling_realm attribute

if (use_modern_diag) then
register_diag_field_array = fms_register_diag_field_array(module_name, field_name, axes, init_time, &
& long_name=long_name, units=units, missing_value=missing_value, var_range=range, mask_variant=mask_variant, &
register_diag_field_array = fms_diag_object%fms_register_diag_field_array( &
& module_name, field_name, axes, init_time, long_name=long_name, &
& units=units, missing_value=missing_value, var_range=range, mask_variant=mask_variant, &
& standard_name=standard_name, verbose=verbose, do_not_log=do_not_log, err_msg=err_msg, &
& interp_method=interp_method, tile_count=tile_count, area=area, volume=volume, realm=realm)
else
Expand Down Expand Up @@ -488,7 +486,7 @@ INTEGER FUNCTION register_static_field(module_name, field_name, axes, long_name,
END IF

if (use_modern_diag) then
register_static_field = fms_register_static_field(module_name, field_name, axes, &
register_static_field = fms_diag_object%fms_register_static_field(module_name, field_name, axes, &
& long_name=long_name, units=units, missing_value=missing_value, range=range, mask_variant=mask_variant, &
& standard_name=standard_name, dynamic=DYNAMIC, do_not_log=do_not_log, interp_method=interp_method,&
& tile_count=tile_count, area=area, volume=volume, realm=realm)
Expand Down Expand Up @@ -1223,7 +1221,7 @@ INTEGER FUNCTION get_diag_field_id(module_name, field_name)

get_diag_field_id = DIAG_FIELD_NOT_FOUND
if (use_modern_diag) then
get_diag_field_id = fms_get_diag_field_id(module_name, field_name)
get_diag_field_id = fms_diag_object%fms_get_diag_field_id_from_name(module_name, field_name)
else
! find_input_field will return DIAG_FIELD_NOT_FOUND if the field is not
! included in the diag_table
Expand Down Expand Up @@ -3828,7 +3826,7 @@ SUBROUTINE diag_manager_end(time)
if (use_modern_diag) then
call diag_yaml_object_end
call fms_diag_axis_object_end()
call fms_diag_object_end()
call fms_diag_object%diag_end()
endif
#endif
END SUBROUTINE diag_manager_end
Expand Down Expand Up @@ -4045,9 +4043,7 @@ SUBROUTINE diag_manager_init(diag_model_subset, time_init, err_msg)
if (use_modern_diag) then
CALL diag_yaml_object_init(diag_subset_output)
CALL fms_diag_axis_object_init()
CALL fms_diag_object_init(255, 255) !< TO DO: MAX_LEN_VARNAME and MAX_LEN_META are supposed to be read from
!! the namelist and sent to fms_diag_object
fms_diag_files_object_initialized = fms_diag_files_object_init ()
CALL fms_diag_object%init(diag_subset_output)
endif
#else
if (use_modern_diag) &
Expand Down Expand Up @@ -4345,7 +4341,7 @@ SUBROUTINE diag_field_add_attribute_scalar_r(diag_field_id, att_name, att_value)
REAL, INTENT(in) :: att_value !< new attribute value

if (use_modern_diag) then
call fms_diag_field_add_attribute(diag_field_id, att_name, (/att_value /))
call fms_diag_object%fms_diag_field_add_attribute(diag_field_id, att_name, (/att_value /))
else
CALL diag_field_add_attribute_r1d(diag_field_id, att_name, (/ att_value /))
endif
Expand All @@ -4358,7 +4354,7 @@ SUBROUTINE diag_field_add_attribute_scalar_i(diag_field_id, att_name, att_value)
INTEGER, INTENT(in) :: att_value !< new attribute value

if (use_modern_diag) then
call fms_diag_field_add_attribute(diag_field_id, att_name, (/att_value /))
call fms_diag_object%fms_diag_field_add_attribute(diag_field_id, att_name, (/att_value /))
else
CALL diag_field_add_attribute_i1d(diag_field_id, att_name, (/ att_value /))
endif
Expand All @@ -4371,7 +4367,7 @@ SUBROUTINE diag_field_add_attribute_scalar_c(diag_field_id, att_name, att_value)
CHARACTER(len=*), INTENT(in) :: att_value !< new attribute value

if (use_modern_diag) then
call fms_diag_field_add_attribute(diag_field_id, att_name, (/att_value /))
call fms_diag_object%fms_diag_field_add_attribute(diag_field_id, att_name, (/att_value /))
else
CALL diag_field_attribute_init(diag_field_id, att_name, NF90_CHAR, cval=att_value)
endif
Expand All @@ -4384,7 +4380,7 @@ SUBROUTINE diag_field_add_attribute_r1d(diag_field_id, att_name, att_value)
REAL, DIMENSION(:), INTENT(in) :: att_value !< new attribute value

if (use_modern_diag) then
call fms_diag_field_add_attribute(diag_field_id, att_name, att_value)
call fms_diag_object%fms_diag_field_add_attribute(diag_field_id, att_name, att_value)
else
CALL diag_field_attribute_init(diag_field_id, att_name, NF90_FLOAT, rval=att_value)
endif
Expand All @@ -4397,7 +4393,7 @@ SUBROUTINE diag_field_add_attribute_i1d(diag_field_id, att_name, att_value)
INTEGER, DIMENSION(:), INTENT(in) :: att_value !< new attribute value

if (use_modern_diag) then
call fms_diag_field_add_attribute(diag_field_id, att_name, att_value)
call fms_diag_object%fms_diag_field_add_attribute(diag_field_id, att_name, att_value)
else
CALL diag_field_attribute_init(diag_field_id, att_name, NF90_INT, ival=att_value)
endif
Expand Down
Loading

0 comments on commit fca0fba

Please sign in to comment.