Skip to content

Commit

Permalink
minor cleanup?
Browse files Browse the repository at this point in the history
  • Loading branch information
uramirez8707 committed Dec 30, 2024
1 parent 1e3a044 commit 9530290
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
15 changes: 13 additions & 2 deletions diag_manager/fms_diag_field_object.F90
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ module fms_diag_field_object_mod
procedure :: add_area_volume
procedure :: append_time_cell_methods
procedure :: get_file_ids
procedure :: get_nfiles
procedure :: set_mask
procedure :: allocate_mask
procedure :: set_halo_present
Expand Down Expand Up @@ -1753,13 +1754,23 @@ function get_starting_compute_domain(axis_ids, diag_axis) &
enddo axis_loop
end function get_starting_compute_domain

pure function get_nfiles(this)
class(fmsDiagField_type), intent(in) :: this
integer :: get_nfiles

get_nfiles = 0
if (allocated(this%file_ids)) get_nfiles = size(this%file_ids)
end function get_nfiles

!> Get list of field ids
pure function get_file_ids(this)
class(fmsDiagField_type), intent(in) :: this
integer, allocatable :: get_file_ids(:) !< Ids of the FMS_diag_files the variable

allocate(get_file_ids(size(this%file_ids)))
get_file_ids = this%file_ids
if (size(this%file_ids) .ge. 0) then
allocate(get_file_ids(size(this%file_ids)))
get_file_ids = this%file_ids
endif
end function

!> @brief Get the mask from the input buffer object
Expand Down
43 changes: 19 additions & 24 deletions diag_manager/fms_diag_object.F90
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,6 @@ subroutine do_buffer_math(this)
class(*), allocatable :: input_data_buffer(:,:,:,:)
character(len=128) :: error_string
type(fmsDiagIbounds_type) :: bounds
integer, dimension(:), allocatable :: file_ids !< Array of file IDs for a field
logical, parameter :: DEBUG_SC = .false. !< turn on output for debugging

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand All @@ -742,38 +741,34 @@ subroutine do_buffer_math(this)

! Skip this field if it was never registered
if(.not. diag_field%is_registered()) cycle
if (diag_field%get_nfiles() .eq. 0) cycle

! Get the the file ids of the file the field is in
file_ids = diag_field%get_file_ids()
math = diag_field%get_math_needs_to_be_done()
if (.not. math) cycle

! If doing math loop through each file the field is in
doing_math: if (size(file_ids) .ge. 1 .and. math) then
has_input_buff: if (diag_field%has_input_data_buffer()) then
! If the buffer was registered with multiple_send_data calls, prepare the input buffer data
call diag_field%prepare_data_buffer()
has_input_buff: if (diag_field%has_input_data_buffer()) then
! If the buffer was registered with multiple_send_data calls, prepare the input buffer data
call diag_field%prepare_data_buffer()

! Get the input data buffer
input_data_buffer = diag_field%get_data_buffer()
! Get the input data buffer
input_data_buffer = diag_field%get_data_buffer()

call bounds%reset_bounds_from_array_4D(input_data_buffer)
call this%allocate_diag_field_output_buffers(input_data_buffer, ifield)
error_string = this%fms_diag_do_reduction(input_data_buffer, ifield, &
call bounds%reset_bounds_from_array_4D(input_data_buffer)
call this%allocate_diag_field_output_buffers(input_data_buffer, ifield)
error_string = this%fms_diag_do_reduction(input_data_buffer, ifield, &
diag_field%get_mask(), diag_field%get_weight(), &
bounds, .False., Time=diag_field%get_send_data_time())
call diag_field%init_data_buffer()

!TODO Better error handling
!if (trim(error_string) .ne. "") call mpp_error(FATAL, "Field:"//trim(diag_field%get_varname()//&
! " -"//trim(error_string)))
else
!TODO Better error handling
! call mpp_error(FATAL, "diag_send_complete:: no input buffer allocated for field"//diag_field%get_longname())
endif has_input_buff
endif doing_math
call diag_field%init_data_buffer()

!TODO Better error handling
!if (trim(error_string) .ne. "") call mpp_error(FATAL, "Field:"//trim(diag_field%get_varname()//&
! " -"//trim(error_string)))
else
!TODO Better error handling
! call mpp_error(FATAL, "diag_send_complete:: no input buffer allocated for field"//diag_field%get_longname())
endif has_input_buff
call diag_field%set_math_needs_to_be_done(.False.)
!> Clean up, clean up, everybody do your share
if (allocated(file_ids)) deallocate(file_ids)
if (associated(diag_field)) nullify(diag_field)
enddo field_loop
#endif
Expand Down

0 comments on commit 9530290

Please sign in to comment.