Skip to content

Commit

Permalink
feat: modern diag implement time_none reduction (NOAA-GFDL#1347)
Browse files Browse the repository at this point in the history
  • Loading branch information
uramirez8707 authored and rem1776 committed May 1, 2024
1 parent bb1bd2a commit 6425342
Show file tree
Hide file tree
Showing 14 changed files with 802 additions and 147 deletions.
24 changes: 20 additions & 4 deletions diag_manager/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ libdiag_manager_la_SOURCES = \
fms_diag_bbox.F90 \
fms_diag_reduction_methods.F90 \
include/fms_diag_fieldbuff_update.inc \
include/fms_diag_fieldbuff_update.fh
include/fms_diag_fieldbuff_update.fh \
include/fms_diag_reduction_methods.inc \
include/fms_diag_reduction_methods_r4.fh \
include/fms_diag_reduction_methods_r8.fh

# Some mods are dependant on other mods in this dir.
diag_data_mod.$(FC_MODEXT): fms_diag_bbox_mod.$(FC_MODEXT)
Expand All @@ -75,22 +78,33 @@ fms_diag_yaml_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT)
fms_diag_object_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) fms_diag_file_object_mod.$(FC_MODEXT) fms_diag_field_object_mod.$(FC_MODEXT) fms_diag_yaml_mod.$(FC_MODEXT) \
fms_diag_time_utils_mod.$(FC_MODEXT) \
fms_diag_output_buffer_mod.$(FC_MODEXT) \
fms_diag_reduction_methods_mod.$(FC_MODEXT)
fms_diag_reduction_methods_mod.$(FC_MODEXT) \
fms_diag_bbox_mod.$(FC_MODEXT)
fms_diag_field_object_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) fms_diag_yaml_mod.$(FC_MODEXT) fms_diag_time_utils_mod.$(FC_MODEXT) \
fms_diag_axis_object_mod.$(FC_MODEXT)
fms_diag_file_object_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) fms_diag_yaml_mod.$(FC_MODEXT) fms_diag_field_object_mod.$(FC_MODEXT) fms_diag_time_utils_mod.$(FC_MODEXT) \
fms_diag_axis_object_mod.$(FC_MODEXT) fms_diag_output_buffer_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_time_utils_mod.$(FC_MODEXT)
fms_diag_axis_object_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) fms_diag_time_utils_mod.$(FC_MODEXT) fms_diag_yaml_mod.$(FC_MODEXT) \
diag_grid_mod.$(FC_MODEXT)
<<<<<<< HEAD
=======
fms_diag_time_reduction_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) fms_diag_bbox_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)
>>>>>>> 07ff0679 (Implement time_none (#1347))
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_object_mod.$(FC_MODEXT) fms_diag_file_object_mod.$(FC_MODEXT) \
fms_diag_yaml_mod.$(FC_MODEXT) fms_diag_time_utils_mod.$(FC_MODEXT) \
fms_diag_object_container_mod.$(FC_MODEXT) fms_diag_axis_object_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_output_buffer_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) fms_diag_yaml_mod.$(FC_MODEXT)
fms_diag_output_buffer_mod.$(FC_MODEXT): diag_data_mod.$(FC_MODEXT) fms_diag_yaml_mod.$(FC_MODEXT) \
fms_diag_reduction_methods_mod.$(FC_MODEXT)
fms_diag_reduction_methods_mod.$(FC_MODEXT): fms_diag_bbox_mod.$(FC_MODEXT) fms_diag_output_buffer_mod.$(FC_MODEXT) \
diag_data_mod.$(FC_MODEXT)

Expand Down Expand Up @@ -127,7 +141,9 @@ MODFILES = \
fms_diag_fieldbuff_update_mod.$(FC_MODEXT) \
fms_diag_reduction_methods_mod.$(FC_MODEXT) \
include/fms_diag_fieldbuff_update.inc \
include/fms_diag_fieldbuff_update.fh
include/fms_diag_fieldbuff_update.fh \
include/fms_diag_reduction_methods_r4.fh \
include/fms_diag_reduction_methods_r8.fh

nodist_include_HEADERS = $(MODFILES)
BUILT_SOURCES = $(MODFILES)
Expand Down
67 changes: 54 additions & 13 deletions diag_manager/diag_manager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1665,9 +1665,9 @@ LOGICAL FUNCTION diag_send_data(diag_field_id, field, time, is_in, js_in, ks_in,
CHARACTER(len=128) :: error_string, error_string1

REAL, ALLOCATABLE, DIMENSION(:,:,:) :: field_out !< Local copy of field
class(*), pointer, dimension(:,:,:,:) :: field_remap !< 4d remapped pointer
logical, pointer, dimension(:,:,:,:) :: mask_remap !< 4d remapped pointer
class(*), pointer, dimension(:,:,:,:) :: rmask_remap !< 4d remapped pointer
class(*), allocatable, dimension(:,:,:,:) :: field_remap !< 4d remapped array
logical, allocatable, dimension(:,:,:,:) :: mask_remap !< 4d remapped array
class(*), allocatable, dimension(:,:,:,:) :: rmask_remap !< 4d remapped array
REAL(kind=r4_kind), POINTER, DIMENSION(:,:,:) :: rmask_ptr_r4 !< A pointer to r4 type of rmask
REAL(kind=r8_kind), POINTER, DIMENSION(:,:,:) :: rmask_ptr_r8 !<A pointer to r8 type of rmask

Expand All @@ -1677,7 +1677,12 @@ LOGICAL FUNCTION diag_send_data(diag_field_id, field, time, is_in, js_in, ks_in,

REAL :: rmask_threshold !< Holds the values 0.5_r4_kind or 0.5_r8_kind, or related threhold values
!! needed to be passed to the math/buffer update functions.
<<<<<<< HEAD
class(*), pointer, dimension(:,:,:,:) :: field_modern => null() !< i8 4d remapped pointer
=======
character(len=:), allocatable :: field_name !< Name of the field

>>>>>>> 07ff0679 (Implement time_none (#1347))
! If diag_field_id is < 0 it means that this field is not registered, simply return
IF ( diag_field_id <= 0 ) THEN
diag_send_data = .FALSE.
Expand Down Expand Up @@ -1708,15 +1713,8 @@ LOGICAL FUNCTION diag_send_data(diag_field_id, field, time, is_in, js_in, ks_in,
IF ( fms_error_handler('diag_manager_mod::send_data_3d', err_msg_local, err_msg) ) RETURN
END IF
if (use_modern_diag) then !> Set up array lengths for remapping
field_remap => null()
mask_remap => null()
rmask_remap => null()
ie = SIZE(field,1)
je = SIZE(field,2)
ke = SIZE(field,3)
field_remap(1:ie,1:je,1:ke,1:1) => field
if (present(mask)) mask_remap(1:ie,1:je,1:ke,1:1) => mask
if (present(rmask)) rmask_remap(1:ie,1:je,1:ke,1:1) => rmask


endif
SELECT TYPE (field)
TYPE IS (real(kind=r4_kind))
Expand All @@ -1730,10 +1728,19 @@ LOGICAL FUNCTION diag_send_data(diag_field_id, field, time, is_in, js_in, ks_in,
END SELECT
! Split old and modern2023 here
modern_if: iF (use_modern_diag) then
field_name = fms_diag_object%fms_get_field_name_from_id(diag_field_id)
field_remap = copy_3d_to_4d(field, trim(field_name)//"'s data")
if (present(rmask)) rmask_remap = copy_3d_to_4d(rmask, trim(field_name)//"'s mask")
if (present(mask)) then
allocate(mask_remap(1:size(mask,1), 1:size(mask,2), 1:size(mask,3), 1))
mask_remap(:,:,:,1) = mask
endif
diag_send_data = fms_diag_object%fms_diag_accept_data(diag_field_id, field_remap, mask_remap, rmask_remap, &
time, is_in, js_in, ks_in, ie_in, je_in, ke_in, weight, &
err_msg)
nullify (field_remap)
deallocate (field_remap)
if (allocated(mask_remap)) deallocate(mask_remap)
if (allocated(rmask_remap)) deallocate(rmask_remap)
elSE ! modern_if
! oor_mask is only used for checking out of range values.
ALLOCATE(oor_mask(SIZE(field,1),SIZE(field,2),SIZE(field,3)), STAT=status)
Expand Down Expand Up @@ -4474,6 +4481,40 @@ SUBROUTINE diag_field_add_cell_measures(diag_field_id, area, volume)
END IF
END SUBROUTINE diag_field_add_cell_measures

!> @brief Copies a 3d buffer to a 4d buffer
!> @return a 4d buffer
function copy_3d_to_4d(data_in, field_name) &
result(data_out)
class (*), intent(in) :: data_in(:,:,:) !< Data to copy
character(len=*), intent(in) :: field_name !< Name of the field copying (for error messages)
class (*), allocatable :: data_out(:,:,:,:)

!TODO this should be extended to integers
select type(data_in)
type is (real(kind=r8_kind))
allocate(real(kind=r8_kind) :: data_out(1:size(data_in,1), 1:size(data_in,2), 1:size(data_in,3), 1))
select type (data_out)
type is (real(kind=r8_kind))
data_out(:,:,:,1) = data_in
class default
call mpp_error(FATAL, "The copy of "//trim(field_name)//&
" was not allocated to the correct type (r8_kind). This shouldn't have happened")
end select
type is (real(kind=r4_kind))
allocate(real(kind=r4_kind) :: data_out(1:size(data_in,1), 1:size(data_in,2), 1:size(data_in,3), 1))
select type (data_out)
type is (real(kind=r4_kind))
data_out(:,:,:,1) = data_in
class default
call mpp_error(FATAL, "The copy of "//trim(field_name)//&
" was not allocated to the correct type (r4_kind). This shouldn't have happened")
end select
class default
call mpp_error(FATAL, "The data for "//trim(field_name)//&
&" is not a valid type. Currently only r4 and r8 are supported")
end select
end function copy_3d_to_4d

END MODULE diag_manager_mod
!> @}
! close documentation grouping
Loading

0 comments on commit 6425342

Please sign in to comment.