Skip to content

Commit

Permalink
feat: add diag_yaml object (NOAA-GFDL#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
uramirez8707 authored and rem1776 committed Apr 30, 2024
1 parent 35ccbe0 commit 1a7468f
Show file tree
Hide file tree
Showing 9 changed files with 470 additions and 311 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ list(APPEND fms_fortran_src_files
diag_manager/fms_diag_elem_weight_procs.F90
diag_manager/fms_diag_fieldbuff_update.F90
diag_manager/fms_diag_bbox.F90
diag_manager/fms_diag_object.F90
diag_manager/fms_diag_yaml.F90
diag_manager/fms_diag_yaml_object.F90
drifters/cloud_interpolator.F90
drifters/drifters.F90
drifters/drifters_comm.F90
Expand Down
22 changes: 7 additions & 15 deletions diag_manager/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ libdiag_manager_la_SOURCES = \
include/fms_diag_fieldbuff_update.inc \
include/fms_diag_fieldbuff_update.fh
fms_diag_yaml.F90 \
diag_yaml.h \
diag_yaml.c \
fms_diag_object.F90 \
fms_diag_yaml_object.F90

Expand All @@ -56,21 +54,15 @@ diag_data_mod.$(FC_MODEXT): fms_diag_bbox_mod.$(FC_MODEXT)
diag_axis_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT)
diag_output_mod.$(FC_MODEXT): diag_axis_mod.$(FC_MODEXT) diag_data_mod.$(FC_MODEXT)
diag_util_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) diag_axis_mod.$(FC_MODEXT) diag_output_mod.$(FC_MODEXT) \
diag_grid_mod.$(FC_MODEXT) fms_diag_bbox_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_axis_object_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) fms_diag_time_utils_mod.$(FC_MODEXT)
fms_diag_time_reduction_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT)
fms_diag_elem_weight_procs_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT)
fms_diag_outfield_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) fms_diag_elem_weight_procs_mod.$(FC_MODEXT)
fms_diag_fieldbuff_update_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) diag_util_mod.$(FC_MODEXT) \
fms_diag_outfield_mod.$(FC_MODEXT) fms_diag_elem_weight_procs_mod.$(FC_MODEXT) \
fms_diag_bbox_mod.$(FC_MODEXT)
fms_diag_yaml_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) diag_util_mod.$(FC_MODEXT) \
fms_diag_yaml_object_mod.$(FC_MODEXT)
fms_diag_object_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) diag_axis_mod.$(FC_MODEXT) \
fms_diag_yaml_object_mod.$(FC_MODEXT)
diag_manager_mod.$(FC_MODEXT): diag_axis_mod.$(FC_MODEXT) diag_data_mod.$(FC_MODEXT) diag_util_mod.$(FC_MODEXT) \
diag_output_mod.$(FC_MODEXT) diag_grid_mod.$(FC_MODEXT) diag_table_mod.$(FC_MODEXT) \
fms_diag_time_reduction_mod.$(FC_MODEXT) fms_diag_outfield_mod.$(FC_MODEXT) \
fms_diag_fieldbuff_update_mod.$(FC_MODEXT) fms_diag_object_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_yaml_mod.$(FC_MODEXT)
diag_output_mod.$(FC_MODEXT) diag_grid_mod.$(FC_MODEXT) diag_table_mod.$(FC_MODEXT) \
fms_diag_object_mod.$(FC_MODEXT) fms_diag_yaml_mod.$(FC_MODEXT)

# Mod files are built and then installed as headers.
MODFILES = \
Expand Down
27 changes: 0 additions & 27 deletions diag_manager/diag_data.F90
Original file line number Diff line number Diff line change
Expand Up @@ -104,33 +104,6 @@ MODULE diag_data_mod

!> @}


!> @brief The files type matching a C struct containing diag_yaml information
!> @ingroup diag_data_mod
type, bind(c) :: diag_files_type
character (kind=c_char) :: fname (20) !< file name
character (kind=c_char) :: frequnit (7) !< the frequency unit
integer (c_int) :: freq !< the frequency of data
character (kind=c_char) :: timeunit(7) !< The unit of time
character (kind=c_char) :: unlimdim(8) !< The name of the unlimited dimension
character (kind=c_char) :: key(8) !< Storage for the key in the yaml file
end type diag_files_type
!> @brief The field type matching the C struct for diag_yaml information
!> @ingroup diag_data_mod
type, bind(c) :: diag_fields_type
character (kind=c_char) :: fname (20) !< The field/diagnostic name
character (kind=c_char) :: var(20) !< The name of the variable
character (kind=c_char) :: files(20) !< The files that the diagnostic will be written to
integer (c_int) :: ikind !< The type/kind of the variable
character (kind=c_char) :: skind(20) !< The type/kind of the variable
character (kind=c_char) :: reduction(20) !< IDK
character (kind=c_char) :: all_all(4) !< This has to be "all"
character (kind=c_char) :: region(50) !< The region
character (kind=c_char) :: regcoord(50) !< Coodinates of the region
character (kind=c_char) :: module_location(20) !< The module
character (kind=c_char) :: key(8) !< Storage for the key in the yaml file
end type diag_fields_type

!> @brief Contains the coordinates of the local domain to output.
!> @ingroup diag_data_mod
TYPE diag_grid
Expand Down
21 changes: 14 additions & 7 deletions diag_manager/diag_manager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ 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
#ifdef use_yaml
use fms_diag_yaml_mod, only: diag_yaml_object_init, diag_yaml_object_end
#endif
USE fms_diag_object_mod, ONLY: fms_diag_object, diag_object_placeholder
USE constants_mod, ONLY: SECONDS_PER_DAY
USE fms_diag_outfield_mod, ONLY: fmsDiagOutfieldIndex_type, fmsDiagOutfield_type
Expand Down Expand Up @@ -3706,6 +3709,10 @@ SUBROUTINE diag_manager_end(time)
if (allocated(fileobj)) deallocate(fileobj)
if (allocated(fileobjND)) deallocate(fileobjND)
if (allocated(fnum_for_domain)) deallocate(fnum_for_domain)

#ifdef use_yaml
if (use_modern_diag) call diag_yaml_object_end
#endif
END SUBROUTINE diag_manager_end

!> @brief Replaces diag_manager_end; close just one file: files(file)
Expand Down Expand Up @@ -3803,12 +3810,8 @@ SUBROUTINE diag_manager_init(diag_model_subset, time_init, err_msg)
& max_input_fields, max_axes, do_diag_field_log, write_bytes_in_file, debug_diag_manager,&
& max_num_axis_sets, max_files, use_cmor, issue_oor_warnings,&
& oor_warnings_fatal, max_out_per_in_field, flush_nc_files, region_out_use_alt_value, max_field_attributes,&
<<<<<<< HEAD
& max_file_attributes, max_axis_attributes, prepend_date, use_mpp_io, field_log_separator,&
& use_refactored_send
=======
& max_file_attributes, max_axis_attributes, prepend_date, use_modern_diag, use_mpp_io
>>>>>>> 98bb81e0 (Adds namelist variable)
& use_modern_diag

! If the module was already initialized do nothing
IF ( module_is_initialized ) RETURN
Expand Down Expand Up @@ -3928,8 +3931,12 @@ SUBROUTINE diag_manager_init(diag_model_subset, time_init, err_msg)
END IF
END IF

CALL parse_diag_table(DIAG_SUBSET=diag_subset_output, ISTAT=mystat, ERR_MSG=err_msg_local)
IF ( mystat /= 0 ) THEN
#ifdef use_yaml
if (use_modern_diag) CALL diag_yaml_object_init()
#endif

CALL parse_diag_table(DIAG_SUBSET=diag_subset_output, ISTAT=mystat, ERR_MSG=err_msg_local)
IF ( mystat /= 0 ) THEN
IF ( fms_error_handler('diag_manager_mod::diag_manager_init',&
& 'Error parsing diag_table. '//TRIM(err_msg_local), err_msg) ) RETURN
END IF
Expand Down
6 changes: 0 additions & 6 deletions diag_manager/diag_yaml.c

This file was deleted.

28 changes: 0 additions & 28 deletions diag_manager/diag_yaml.h

This file was deleted.

19 changes: 9 additions & 10 deletions diag_manager/fms_diag_object.F90
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ module fms_diag_object_mod
use diag_data_mod, only: diag_null
use diag_data_mod, only: r8, r4, i8, i4, string, null_type_int
use diag_data_mod, only: diag_null, diag_not_found, diag_not_registered, diag_registered_id
use diag_data_mod, only: diag_fields_type, diag_files_type
use fms_diag_yaml_mod, only: is_field_type_null
use fms_diag_yaml_mod, only: diag_yaml
use diag_axis_mod, only: diag_axis_type
use mpp_mod, only: fatal, note, warning, mpp_error
use fms_diag_yaml_object_mod, only: diagYamlFiles_type, diagYamlFilesVar_type
use time_manager_mod, ONLY: time_type
!!!set_time, set_date, get_time, time_type, OPERATOR(>=), OPERATOR(>),&
!!! & OPERATOR(<), OPERATOR(==), OPERATOR(/=), OPERATOR(/), OPERATOR(+), ASSIGNMENT(=), get_date, &
Expand Down Expand Up @@ -59,8 +57,8 @@ module fms_diag_object_mod

!> \brief Object that holds all variable information
type fms_diag_object
type (diag_fields_type) :: diag_field !< info from diag_table
type (diag_files_type),allocatable, dimension(:) :: diag_file !< info from diag_table
type (diagYamlFilesVar_type), allocatable, dimension(:) :: diag_field !< info from diag_table
type (diagYamlFiles_type), allocatable, dimension(:) :: diag_file !< info from diag_table
integer, allocatable, private :: diag_id !< unique id for varable
class(FmsNetcdfFile_t), dimension (:), pointer :: fileob => NULL() !< A pointer to all of the
!! file objects for this variable
Expand Down Expand Up @@ -238,13 +236,14 @@ subroutine fms_register_diag_field_obj &
allocate(character(len=len(modname)) :: dobj%modname)
dobj%modname = trim(modname)
!> Grab the information from the diag_table
! TO DO:
! dobj%diag_field = get_diag_table_field(trim(varname))
! dobj%diag_field = diag_yaml%get_diag_field(
if (is_field_type_null(dobj%diag_field)) then
dobj%diag_id = diag_not_found
dobj%vartype = diag_null
return
endif
! if (is_field_type_null(dobj%diag_field)) then
! dobj%diag_id = diag_not_found
! dobj%vartype = diag_null
! return
! endif
!> get the optional arguments if included and the diagnostic is in the diag table
if (present(longname)) then
allocate(character(len=len(longname)) :: dobj%longname)
Expand Down
Loading

0 comments on commit 1a7468f

Please sign in to comment.