Skip to content

Commit

Permalink
Add additional error checking + fix the test_flexible_time after the …
Browse files Browse the repository at this point in the history
…update + minor documentation updates
  • Loading branch information
uramirez8707 committed Aug 10, 2023
1 parent d123900 commit e6b86a4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
9 changes: 5 additions & 4 deletions diag_manager/fms_diag_file_object.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1122,18 +1122,19 @@ end subroutine write_time_metadata

!> \brief Write out the field data to the file
subroutine write_field_data(this, field_obj, buffer_obj)
class(fmsDiagFileContainer_type), intent(in), target :: this !< The file object
type(fmsDiagField_type), intent(in), target :: field_obj(:)
type(fmsDiagOutputBufferContainer_type), intent(in), target :: buffer_obj(:)
class(fmsDiagFileContainer_type), intent(in), target :: this !< The diag file object to write to
type(fmsDiagField_type), intent(in), target :: field_obj(:) !< The field object to write from
type(fmsDiagOutputBufferContainer_type), intent(in), target :: buffer_obj(:) !< The buffer object with the data

class(fmsDiagFile_type), pointer :: diag_file !< Diag_file object to open
class(FmsNetcdfFile_t), pointer :: fileobj !< Fileobj to write to
integer :: i !< For do loops
integer :: field_id !< The id of the field writing the data to
integer :: field_id !< The id of the field writing the data from

diag_file => this%FMS_diag_file
fileobj => diag_file%fileobj

!TODO This may be offloaded in the future
if (diag_file%is_static) then
!< Here the file is static so there is no need for the unlimited dimension
!! as a variables are static
Expand Down
18 changes: 15 additions & 3 deletions diag_manager/fms_diag_output_buffer.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,9 @@ subroutine write_buffer(this, fileobj, unlim_dim_level)
call this%write_buffer_wrapper_domain(fileobj, unlim_dim_level=unlim_dim_level)
type is (FmsNetcdfUnstructuredDomainFile_t)
call this%write_buffer_wrapper_u(fileobj, unlim_dim_level=unlim_dim_level)
class default
call mpp_error(FATAL, "The file "//trim(fileobj%path)//" is not one of the accepted types"//&
" only FmsNetcdfFile_t, FmsNetcdfDomainFile_t, and FmsNetcdfUnstructuredDomainFile_t are accepted.")
end select
end subroutine write_buffer

Expand All @@ -1542,8 +1545,11 @@ subroutine write_buffer_wrapper_netcdf(this, fileobj, unlim_dim_level)
call write_data(fileobj, varname, buffer_obj%buffer, unlim_dim_level=unlim_dim_level)
type is (outputBuffer5d_type)
call write_data(fileobj, varname, buffer_obj%buffer, unlim_dim_level=unlim_dim_level)
class default
call mpp_error(FATAL, "The field:"//trim(varname)//" does not have a valid buffer object type."//&
" Only 0d, 1d, 2d, 3d, 4d, and 5d buffers are supported.")
end select
end subroutine
end subroutine write_buffer_wrapper_netcdf

!> @brief Write the buffer to the FmsNetcdfDomainFile_t fileobj
subroutine write_buffer_wrapper_domain(this, fileobj, unlim_dim_level)
Expand All @@ -1567,8 +1573,11 @@ subroutine write_buffer_wrapper_domain(this, fileobj, unlim_dim_level)
call write_data(fileobj, varname, buffer_obj%buffer, unlim_dim_level=unlim_dim_level)
type is (outputBuffer5d_type)
call write_data(fileobj, varname, buffer_obj%buffer, unlim_dim_level=unlim_dim_level)
class default
call mpp_error(FATAL, "The field:"//trim(varname)//" does not have a valid buffer object type."//&
" Only 0d, 1d, 2d, 3d, 4d, and 5d buffers are supported.")
end select
end subroutine
end subroutine write_buffer_wrapper_domain

!> @brief Write the buffer to the FmsNetcdfUnstructuredDomainFile_t fileobj
subroutine write_buffer_wrapper_u(this, fileobj, unlim_dim_level)
Expand All @@ -1592,7 +1601,10 @@ subroutine write_buffer_wrapper_u(this, fileobj, unlim_dim_level)
call write_data(fileobj, varname, buffer_obj%buffer, unlim_dim_level=unlim_dim_level)
type is (outputBuffer5d_type)
call write_data(fileobj, varname, buffer_obj%buffer, unlim_dim_level=unlim_dim_level)
class default
call mpp_error(FATAL, "The field:"//trim(varname)//" does not have a valid buffer object type."//&
" Only 0d, 1d, 2d, 3d, 4d, and 5d buffers are supported.")
end select
end subroutine
end subroutine write_buffer_wrapper_u
#endif
end module fms_diag_output_buffer_mod
18 changes: 13 additions & 5 deletions test_fms/diag_manager/test_flexible_time.F90
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@
program test_flexible_time
use fms_mod, only: fms_init, fms_end
use time_manager_mod, only: set_date, time_type, increment_date, set_calendar_type, &
JULIAN, set_time
JULIAN, set_time, operator(+)
use diag_manager_mod, only: diag_manager_init, diag_axis_init, register_diag_field, &
diag_manager_set_time_end, diag_send_complete, diag_manager_end
diag_manager_set_time_end, diag_send_complete, diag_manager_end, &
send_data
use mpp_mod, only: FATAL, mpp_error
use platform_mod, only: r8_kind

implicit none

real(kind=r8_kind) :: var_data(2) !< Dummy data
logical :: used !< .True. if send_data was sucessful
type(time_type) :: Time !< Time of the simulation
type(time_type) :: Start_Time !< Start time of the simulation
type(time_type) :: Time_step !< Start time of the simulation
type(time_type) :: End_Time !< End Time of the simulation
integer :: i
integer :: id_z, id_var
Expand All @@ -39,18 +43,22 @@ program test_flexible_time
call diag_manager_init

!< Starting time of the simulation
Start_Time = set_date(2,1,1,3,0,0) !02/01/01 hour 3
Time = set_date(2,1,1,3,0,0) !02/01/01 hour 3

!< Set up a dummy variable
id_z = diag_axis_init('z', (/1. ,2. /), 'point_Z', 'z', long_name='point_Z')
id_var = register_diag_field ('atm_mod', 'var1', (/id_z/), Start_Time, 'Var not domain decomposed', 'mullions')
id_var = register_diag_field ('atm_mod', 'var1', (/id_z/), Time, 'Var not domain decomposed', 'mullions')

!< Set up the end of the simulation (i.e 2 days long)
End_Time = set_date(2,1,3,3,0,0)
call diag_manager_set_time_end(End_Time)

!< Set up the simulation
Time_step = set_time (3600,0) !< 1 hour
do i=1,48
var_data = real(i, kind=r8_kind)
Time = Time + Time_step
used = send_data(id_var, var_data, Time)
call diag_send_complete(set_time(3600,0))
enddo

Expand Down

0 comments on commit e6b86a4

Please sign in to comment.