diff --git a/diag_manager/Makefile.am b/diag_manager/Makefile.am index cd5408d06..dc0fc141c 100644 --- a/diag_manager/Makefile.am +++ b/diag_manager/Makefile.am @@ -60,7 +60,8 @@ 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_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_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) diff --git a/diag_manager/fms_diag_file_object.F90 b/diag_manager/fms_diag_file_object.F90 index d16f3055f..0b2079967 100644 --- a/diag_manager/fms_diag_file_object.F90 +++ b/diag_manager/fms_diag_file_object.F90 @@ -24,9 +24,10 @@ !! a pointer to the information from the diag yaml, additional metadata that comes from the model, and a !! list of the variables and their variable IDs that are in the file. module fms_diag_file_object_mod -!use mpp_mod, only: mpp_error, FATAL use fms2_io_mod, only: FmsNetcdfFile_t, FmsNetcdfUnstructuredDomainFile_t, FmsNetcdfDomainFile_t -use diag_data_mod, only: DIAG_NULL, NO_DOMAIN, max_axes, SUB_REGIONAL +use diag_data_mod, only: DIAG_NULL, NO_DOMAIN, max_axes, SUB_REGIONAL, get_base_time +use diag_util_mod, only: diag_time_inc +use time_manager_mod, only: time_type, operator(/=), operator(==) #ifdef use_yaml use fms_diag_yaml_mod, only: diag_yaml, diagYamlObject_type, diagYamlFiles_type #endif @@ -44,6 +45,13 @@ module fms_diag_file_object_mod type :: fmsDiagFile_type private integer :: id !< The number associated with this file in the larger array of files + TYPE(time_type) :: start_time !< The start time for the file + TYPE(time_type) :: last_output !< Time of the last time output was writen + TYPE(time_type) :: next_output !< Time of the next write + TYPE(time_type) :: next_next_output !< Time of the next next write + + !< This will be used when using the new_file_freq keys in the diag_table.yaml + TYPE(time_type) :: next_open !< The next time to open the file class(FmsNetcdfFile_t), allocatable :: fileobj !< fms2_io file object for this history file #ifdef use_yaml type(diagYamlFiles_type), pointer :: diag_yaml_file => null() !< Pointer to the diag_yaml_file data @@ -72,6 +80,7 @@ module fms_diag_file_object_mod procedure, public :: has_diag_yaml_file procedure, public :: set_file_domain procedure, public :: add_axes + procedure, public :: add_start_time #endif procedure, public :: has_var_ids procedure, public :: get_id @@ -122,36 +131,47 @@ logical function fms_diag_files_object_init () #ifdef use_yaml integer :: nFiles !< Number of files in the diag yaml integer :: i !< Looping iterator + type(fmsDiagFile_type), pointer :: obj !< FMS_diag_files(i) (for less typing) if (diag_yaml%has_diag_files()) then nFiles = diag_yaml%size_diag_files() allocate (FMS_diag_files(nFiles)) set_ids_loop: do i= 1,nFiles - FMS_diag_files(i)%diag_yaml_file => diag_yaml%diag_files(i) - FMS_diag_files(i)%id = i - allocate(FMS_diag_files(i)%var_ids(diag_yaml%diag_files(i)%size_file_varlist())) - allocate(FMS_diag_files(i)%var_index(diag_yaml%diag_files(i)%size_file_varlist())) - allocate(FMS_diag_files(i)%var_reg(diag_yaml%diag_files(i)%size_file_varlist())) + obj => FMS_diag_files(i) + obj%diag_yaml_file => diag_yaml%diag_files(i) + obj%id = i + allocate(obj%var_ids(diag_yaml%diag_files(i)%size_file_varlist())) + allocate(obj%var_index(diag_yaml%diag_files(i)%size_file_varlist())) + allocate(obj%var_reg(diag_yaml%diag_files(i)%size_file_varlist())) !! Initialize the integer arrays - FMS_diag_files(i)%var_ids = DIAG_NULL - FMS_diag_files(i)%var_reg = .FALSE. - FMS_diag_files(i)%var_index = DIAG_NULL + obj%var_ids = DIAG_NULL + obj%var_reg = .FALSE. + obj%var_index = DIAG_NULL !> These will be set in a set_file_domain - FMS_diag_files(i)%type_of_domain = NO_DOMAIN - FMS_diag_files(i)%domain => null() + obj%type_of_domain = NO_DOMAIN + obj%domain => null() !> This will be set in a add_axes - allocate(FMS_diag_files(i)%axis_ids(max_axes)) + allocate(obj%axis_ids(max_axes)) !> If the file has a sub_regional, define it as one and allocate the sub_axis_ids array. !! This will be set in a add_axes - if (FMS_diag_files(i)%has_file_sub_region()) then - FMS_diag_files(i)%type_of_domain = SUB_REGIONAL - allocate(FMS_diag_files(i)%sub_axis_ids(max_axes)) - FMS_diag_files(i)%sub_axis_ids = diag_null + if (obj%has_file_sub_region()) then + obj%type_of_domain = SUB_REGIONAL + allocate(obj%sub_axis_ids(max_axes)) + obj%sub_axis_ids = diag_null endif - FMS_diag_files(i)%number_of_axis = 0 + obj%number_of_axis = 0 + + !> Set the start_time of the file to the base_time and set up the *_output variables + obj%start_time = get_base_time() + obj%last_output = get_base_time() + obj%next_output = diag_time_inc(obj%start_time, obj%get_file_freq(), obj%get_file_frequnit()) + obj%next_next_output = diag_time_inc(obj%next_output, obj%get_file_freq(), obj%get_file_frequnit()) + obj%next_open = get_base_time() + + nullify(obj) enddo set_ids_loop fms_diag_files_object_init = .true. else @@ -244,7 +264,7 @@ end function get_file_fname !! \return Copy of file_frequnit pure function get_file_frequnit (obj) result(res) class(fmsDiagFile_type), intent(in) :: obj !< The file object - character (len=:), allocatable :: res + integer :: res res = obj%diag_yaml_file%get_file_frequnit() end function get_file_frequnit !> \brief Returns a copy of file_freq from the yaml object @@ -258,7 +278,7 @@ end function get_file_freq !! \return Copy of file_timeunit pure function get_file_timeunit (obj) result(res) class(fmsDiagFile_type), intent(in) :: obj !< The file object - character (len=:), allocatable :: res + integer :: res res = obj%diag_yaml_file%get_file_timeunit() end function get_file_timeunit !> \brief Returns a copy of file_unlimdim from the yaml object @@ -287,7 +307,7 @@ end function get_file_new_file_freq !! \return Copy of file_new_file_freq_units pure function get_file_new_file_freq_units (obj) result(res) class(fmsDiagFile_type), intent(in) :: obj !< The file object - character (len=:), allocatable :: res + integer :: res res = obj%diag_yaml_file%get_file_new_file_freq_units() end function get_file_new_file_freq_units !> \brief Returns a copy of file_start_time from the yaml object @@ -308,7 +328,7 @@ end function get_file_duration !! \return Copy of file_duration_units pure function get_file_duration_units (obj) result(res) class(fmsDiagFile_type), intent(in) :: obj !< The file object - character (len=:), allocatable :: res + integer :: res res = obj%diag_yaml_file%get_file_duration_units() end function get_file_duration_units !> \brief Returns a copy of file_varlist from the yaml object @@ -475,5 +495,33 @@ subroutine add_axes(obj, axis_ids) enddo end subroutine add_axes + +!> @brief adds the start time to the fileobj +!! @note This should be called from the register field calls. It can be called multiple times (one for each variable) +!! So it needs to make sure that the start_time is the same for each variable. The initial value is the base_time +subroutine add_start_time(obj, start_time) + class(fmsDiagFile_type), intent(inout) :: obj !< The file object + TYPE(time_type), intent(in) :: start_time !< Start time to add to the fileobj + + !< If the start_time sent in is equal to the base_time return because + !! obj%start_time was already set to the base_time + if (start_time .eq. get_base_time()) return + + if (obj%start_time .ne. get_base_time()) then + !> If the obj%start_time is not equal to the base_time from the diag_table + !! obj%start_time was already updated so make sure it is the same or error out + if (obj%start_time .ne. start_time)& + call mpp_error(FATAL, "The variables associated with the file:"//obj%get_file_fname()//" have"& + &" different start_time") + else + !> If the obj%start_time is equal to the base_time, + !! simply update it with the start_time and set up the *_output variables + obj%start_time = start_time + obj%last_output = start_time + obj%next_output = diag_time_inc(start_time, obj%get_file_freq(), obj%get_file_frequnit()) + obj%next_next_output = diag_time_inc(obj%next_output, obj%get_file_freq(), obj%get_file_frequnit()) + endif + +end subroutine #endif end module fms_diag_file_object_mod diff --git a/diag_manager/fms_diag_object.F90 b/diag_manager/fms_diag_object.F90 index e2734e4b1..0f31e2d83 100644 --- a/diag_manager/fms_diag_object.F90 +++ b/diag_manager/fms_diag_object.F90 @@ -245,7 +245,7 @@ subroutine fms_register_diag_field_obj & CHARACTER(len=*), INTENT(in) :: varname !< The variable name integer, INTENT(in) :: diag_field_indices(:) !< Array of indices to the field !! in the yaml object - TYPE(time_type), OPTIONAL, INTENT(in) :: init_time !< Initial time !< TO DO + TYPE(time_type), OPTIONAL, INTENT(in) :: init_time !< Initial time INTEGER, TARGET, OPTIONAL, INTENT(in) :: axes(:) !< The axes indicies CHARACTER(len=*), OPTIONAL, INTENT(in) :: longname !< THe variables long name CHARACTER(len=*), OPTIONAL, INTENT(in) :: units !< The units of the variables @@ -285,6 +285,7 @@ subroutine fms_register_diag_field_obj & j = dobj%file_ids(i) call FMS_diag_files(j)%set_file_domain(dobj%domain, dobj%type_of_domain) call FMS_diag_files(j)%add_axes(axes) + if (present(init_time)) call FMS_diag_files(j)%add_start_time(init_time) enddo !> TO DO: !! Mark the field as registered in the diag_files diff --git a/diag_manager/fms_diag_yaml.F90 b/diag_manager/fms_diag_yaml.F90 index 33019b0b9..e436e1a2a 100644 --- a/diag_manager/fms_diag_yaml.F90 +++ b/diag_manager/fms_diag_yaml.F90 @@ -31,7 +31,8 @@ module fms_diag_yaml_mod #ifdef use_yaml use diag_data_mod, only: DIAG_NULL, DIAG_OCEAN, DIAG_ALL, DIAG_OTHER, set_base_time, latlon_gridtype, & - index_gridtype, null_gridtype + index_gridtype, null_gridtype, DIAG_SECONDS, DIAG_MINUTES, DIAG_HOURS, DIAG_DAYS, & + DIAG_MONTHS, DIAG_YEARS use yaml_parser_mod, only: open_and_parse_file, get_value_from_key, get_num_blocks, get_nkeys, & get_block_ids, get_key_value, get_key_ids, get_key_name use mpp_mod, only: mpp_error, FATAL @@ -84,14 +85,18 @@ module fms_diag_yaml_mod !> @brief type to hold the diag_file information type diagYamlFiles_type character (len=:), private, allocatable :: file_fname !< file name - character (len=:), private, allocatable :: file_frequnit !< the frequency unit + integer, private :: file_frequnit !< the frequency unit (DIAG_SECONDS, DIAG_MINUTES, & + !! DIAG_HOURS, DIAG_DAYS, DIAG_YEARS) integer, private :: file_freq !< the frequency of data - character (len=:), private, allocatable :: file_timeunit !< The unit of time + integer, private :: file_timeunit !< The unit of time (DIAG_SECONDS, DIAG_MINUTES, & + !! DIAG_HOURS, DIAG_DAYS, DIAG_YEARS) character (len=:), private, allocatable :: file_unlimdim !< The name of the unlimited dimension type(subRegion_type), private :: file_sub_region !< type containing info about the subregion, if any integer, private :: file_new_file_freq !< Frequency for closing the existing file - character (len=:), private, allocatable :: file_new_file_freq_units !< Time units for creating a new file. + integer, private :: file_new_file_freq_units !< Time units for creating a new file. !! Required if “new_file_freq” used + !! (DIAG_SECONDS, DIAG_MINUTES, & + !! DIAG_HOURS, DIAG_DAYS, DIAG_YEARS) character (len=:), private, allocatable :: file_start_time !< Time to start the file for the first time. Requires !! “new_file_freq” integer, private :: file_duration !< How long the file should receive data after start time @@ -101,7 +106,9 @@ module fms_diag_yaml_mod !! frequency for creating new files. !! NOTE: The file_duration_units field must also be present if !! this field is present. - character (len=:), private, allocatable :: file_duration_units !< The file duration units + integer, private :: file_duration_units !< The file duration units + !! (DIAG_SECONDS, DIAG_MINUTES, & + !! DIAG_HOURS, DIAG_DAYS, DIAG_YEARS) !< Need to use `MAX_STR_LEN` because not all filenames/global attributes are the same length character (len=MAX_STR_LEN), dimension(:), private, allocatable :: file_varlist !< An array of variable names !! within a file @@ -451,26 +458,30 @@ subroutine fill_in_diag_files(diag_yaml_id, diag_file_id, fileobj) integer, allocatable :: key_ids(:) !< Id of the gloabl atttributes key/value pairs character(len=:), ALLOCATABLE :: grid_type !< grid_type as it is read in from the yaml + character(len=:), ALLOCATABLE :: buffer !< buffer to store any *_units as it is read from the yaml call diag_get_value_from_key(diag_yaml_id, diag_file_id, "file_name", fileobj%file_fname) - call diag_get_value_from_key(diag_yaml_id, diag_file_id, "freq_units", fileobj%file_frequnit) + call diag_get_value_from_key(diag_yaml_id, diag_file_id, "freq_units", buffer) call get_value_from_key(diag_yaml_id, diag_file_id, "freq", fileobj%file_freq) - call check_file_freq(fileobj) + call set_file_freq(fileobj, buffer) + deallocate(buffer) call diag_get_value_from_key(diag_yaml_id, diag_file_id, "unlimdim", fileobj%file_unlimdim) - call diag_get_value_from_key(diag_yaml_id, diag_file_id, "time_units", fileobj%file_timeunit) - call check_file_time_units(fileobj) + call diag_get_value_from_key(diag_yaml_id, diag_file_id, "time_units", buffer) + call set_file_time_units(fileobj, buffer) + deallocate(buffer) call get_value_from_key(diag_yaml_id, diag_file_id, "new_file_freq", fileobj%file_new_file_freq, is_optional=.true.) - call diag_get_value_from_key(diag_yaml_id, diag_file_id, "new_file_freq_units", fileobj%file_new_file_freq_units, & + call diag_get_value_from_key(diag_yaml_id, diag_file_id, "new_file_freq_units", buffer, & is_optional=.true.) - call check_new_file_freq(fileobj) + call set_new_file_freq(fileobj, buffer) + deallocate(buffer) call diag_get_value_from_key(diag_yaml_id, diag_file_id, "start_time", fileobj%file_start_time, is_optional=.true.) call get_value_from_key(diag_yaml_id, diag_file_id, "file_duration", fileobj%file_duration, is_optional=.true.) - call diag_get_value_from_key(diag_yaml_id, diag_file_id, "file_duration_units", fileobj%file_duration_units, & + call diag_get_value_from_key(diag_yaml_id, diag_file_id, "file_duration_units", buffer, & is_optional=.true.) - call check_file_duration(fileobj) + call set_file_duration(fileobj, buffer) nsubregion = 0 nsubregion = get_num_blocks(diag_yaml_id, "sub_region", parent_block_id=diag_file_id) @@ -631,60 +642,57 @@ function get_total_num_vars(diag_yaml_id, diag_file_id) & end do end function -!> @brief This checks if the file frequency in a diag file is valid and crashes if it isn't -subroutine check_file_freq(fileobj) - type(diagYamlFiles_type), intent(inout) :: fileobj !< diagYamlFiles_type obj to check +!> @brief This checks if the file frequency and file frequency units in a diag file are valid and +!! sets the integer equivalent +subroutine set_file_freq(fileobj, file_frequnit) + type(diagYamlFiles_type), intent(inout) :: fileobj !< diagYamlFiles_type obj to check + character(len=*), intent(in) :: file_frequnit !< File_freq_units as it is read from the diag_table if (.not. (fileobj%file_freq >= -1) ) & call mpp_error(FATAL, "freq must be greater than or equal to -1. & &Check you entry for"//trim(fileobj%file_fname)) - if(.not. is_valid_time_units(fileobj%file_frequnit)) & - call mpp_error(FATAL, trim(fileobj%file_frequnit)//" is not a valid file_frequnit. & - &The acceptable values are seconds, minuts, hours, days, months, years. & - &Check your entry for file:"//trim(fileobj%file_fname)) -end subroutine check_file_freq - -!> @brief This checks if the time unit in a diag file is valid and crashes if it isn't -subroutine check_file_time_units (fileobj) - type(diagYamlFiles_type), intent(inout) :: fileobj !< diagYamlFiles_type obj to checK - - if(.not. is_valid_time_units(fileobj%file_timeunit)) & - call mpp_error(FATAL, trim(fileobj%file_timeunit)//" is not a valid time_unit. & - &The acceptable values are seconds, minuts, hours, days, months, years. & - &Check your entry for file:"//trim(fileobj%file_fname)) -end subroutine check_file_time_units - -!> @brief This checks if the new file frequency in a diag file is valid and crashes if it isn't -subroutine check_new_file_freq(fileobj) - type(diagYamlFiles_type), intent(inout) :: fileobj !< diagYamlFiles_type obj to check + fileobj%file_frequnit = set_valid_time_units(file_frequnit, "frequnit for file:"//trim(fileobj%file_fname)) +end subroutine set_file_freq + +!> @brief This checks if the time unit in a diag file is valid and sets the integer equivalent +subroutine set_file_time_units (fileobj, file_timeunit) + type(diagYamlFiles_type), intent(inout) :: fileobj !< diagYamlFiles_type obj to checK + character(len=*), intent(in) :: file_timeunit !< file_timeunit as it is read from the diag_table + + fileobj%file_timeunit = set_valid_time_units(file_timeunit, "timeunit for file:"//trim(fileobj%file_fname)) +end subroutine set_file_time_units +!> @brief This checks if the new file frequency and the new file frequency units in a diag file are valid +!! and sets the integer equivalent +subroutine set_new_file_freq(fileobj, file_new_file_freq_units) + type(diagYamlFiles_type), intent(inout) :: fileobj !< diagYamlFiles_type obj to check + character(len=*), intent(in) :: file_new_file_freq_units !< new file freq units as it is read from + !! the diag_table if (fileobj%file_new_file_freq > 0) then - if (trim(fileobj%file_new_file_freq_units) .eq. "") & + if (trim(file_new_file_freq_units) .eq. "") & call mpp_error(FATAL, "new_file_freq_units is required if using new_file_freq. & &Check your entry for file:"//trim(fileobj%file_fname)) - if (.not. is_valid_time_units(fileobj%file_new_file_freq_units)) & - call mpp_error(FATAL, trim(fileobj%file_new_file_freq_units)//" is not a valid new_file_freq_units. & - &The acceptable values are seconds, minuts, hours, days, months, years. & - &Check your entry for file:"//trim(fileobj%file_fname)) + fileobj%file_new_file_freq_units = set_valid_time_units(file_new_file_freq_units, & + "new_file_freq_units for file:"//trim(fileobj%file_fname)) endif -end subroutine check_new_file_freq +end subroutine set_new_file_freq -!> @brief This checks if the file duration in a diag file is valid and crashes if it isn't -subroutine check_file_duration(fileobj) - type(diagYamlFiles_type), intent(inout) :: fileobj !< diagYamlFiles_type obj to check +!> @brief This checks if the file duration and the file duration units in a diag file are valid +!! and sets the integer equivalent +subroutine set_file_duration(fileobj, file_duration_units) + type(diagYamlFiles_type), intent(inout) :: fileobj !< diagYamlFiles_type obj to check + character(len=*), intent(in) :: file_duration_units !< file_duration as it is read from the diag_table if (fileobj%file_duration > 0) then - if(trim(fileobj%file_duration_units) .eq. "") & + if(trim(file_duration_units) .eq. "") & call mpp_error(FATAL, "file_duration_units is required if using file_duration. & &Check your entry for file:"//trim(fileobj%file_fname)) - if (.not. is_valid_time_units(fileobj%file_duration_units)) & - call mpp_error(FATAL, trim(fileobj%file_duration_units)//" is not a valid file_duration_units. & - &The acceptable values are seconds, minuts, hours, days, months, years. & - &Check your entry for file:"//trim(fileobj%file_duration_units)) + fileobj%file_duration_units = set_valid_time_units(file_duration_units, & + "file_duration_units for file:"//trim(fileobj%file_fname)) endif -end subroutine check_file_duration +end subroutine set_file_duration !> @brief This checks if the kind of a diag field is valid and crashes if it isn't subroutine check_field_kind(field) @@ -740,20 +748,35 @@ subroutine check_field_reduction(field) field%pow_value = pow_value end subroutine check_field_reduction -!> @brief This checks if a time unit is valid -!! @return Flag indicating if the time units are valid -pure function is_valid_time_units(time_units) & -result(is_valid) - character(len=*), intent(in) :: time_units - logical :: is_valid +!> @brief This checks if a time unit is valid and if it is, it assigns the integer equivalent +!! @return The integer equivalent to the time units +function set_valid_time_units(time_units, error_msg) & +result(time_units_int) + + character(len=*), intent(in) :: time_units !< The time_units as a string + character(len=*), intent(in) :: error_msg !< Error message to append + + integer :: time_units_int !< The integer equivalent of the time_units select case (TRIM(time_units)) - case ("seconds", "minutes", "hours", "days", "months", "years") - is_valid = .true. + case ("seconds") + time_units_int = DIAG_SECONDS + case ("minutes") + time_units_int = DIAG_MINUTES + case ("hours") + time_units_int = DIAG_HOURS + case ("days") + time_units_int = DIAG_DAYS + case ("months") + time_units_int = DIAG_MONTHS + case ("years") + time_units_int = DIAG_YEARS case default - is_valid = .false. + time_units_int =DIAG_NULL + call mpp_error(FATAL, trim(error_msg)//" is not valid. Acceptable values are "& + "seconds, minutes, hours, days, months, years") end select -end function is_valid_time_units +end function set_valid_time_units !!!!!!! YAML FILE INQUIRIES !!!!!!! !> @brief Finds the number of variables in the file_varlist @@ -776,7 +799,7 @@ end function get_file_fname pure function get_file_frequnit (diag_files_obj) & result (res) class (diagYamlFiles_type), intent(in) :: diag_files_obj !< The object being inquiried - character (len=:), allocatable :: res !< What is returned + integer :: res !< What is returned res = diag_files_obj%file_frequnit end function get_file_frequnit !> @brief Inquiry for diag_files_obj%file_freq @@ -792,7 +815,7 @@ end function get_file_freq pure function get_file_timeunit (diag_files_obj) & result (res) class (diagYamlFiles_type), intent(in) :: diag_files_obj !< The object being inquiried - character (len=:), allocatable :: res !< What is returned + integer :: res !< What is returned res = diag_files_obj%file_timeunit end function get_file_timeunit !> @brief Inquiry for diag_files_obj%file_unlimdim @@ -824,7 +847,7 @@ end function get_file_new_file_freq pure function get_file_new_file_freq_units (diag_files_obj) & result (res) class (diagYamlFiles_type), intent(in) :: diag_files_obj !< The object being inquiried - character (:), allocatable :: res !< What is returned + integer :: res !< What is returned res = diag_files_obj%file_new_file_freq_units end function get_file_new_file_freq_units !> @brief Inquiry for diag_files_obj%file_start_time @@ -848,7 +871,7 @@ end function get_file_duration pure function get_file_duration_units (diag_files_obj) & result (res) class (diagYamlFiles_type), intent(in) :: diag_files_obj !< The object being inquiried - character (:), allocatable :: res !< What is returned + integer :: res !< What is returned res = diag_files_obj%file_duration_units end function get_file_duration_units !> @brief Inquiry for diag_files_obj%file_varlist @@ -990,7 +1013,9 @@ subroutine diag_yaml_files_obj_init(obj) obj%file_freq = DIAG_NULL obj%file_duration = DIAG_NULL + obj%file_duration_units = DIAG_NULL obj%file_new_file_freq = DIAG_NULL + obj%file_new_file_freq_units = DIAG_NULL obj%file_sub_region%tile = DIAG_NULL end subroutine diag_yaml_files_obj_init @@ -1004,7 +1029,7 @@ end function has_file_fname !! @return true if obj%file_frequnit is allocated pure logical function has_file_frequnit (obj) class(diagYamlFiles_type), intent(in) :: obj !< diagYamlFiles_type object to initialize - has_file_frequnit = allocated(obj%file_frequnit) + has_file_frequnit = obj%file_frequnit .NE. DIAG_NULL end function has_file_frequnit !> @brief obj%file_freq is on the stack, so the object always has it !! @return true if obj%file_freq is allocated @@ -1016,7 +1041,7 @@ end function has_file_freq !! @return true if obj%file_timeunit is allocated pure logical function has_file_timeunit (obj) class(diagYamlFiles_type), intent(in) :: obj !< diagYamlFiles_type object to initialize - has_file_timeunit = allocated(obj%file_timeunit) + has_file_timeunit = obj%file_timeunit .ne. diag_null end function has_file_timeunit !> @brief Checks if obj%file_unlimdim is allocated !! @return true if obj%file_unlimdim is allocated @@ -1050,7 +1075,7 @@ end function has_file_new_file_freq !! @return true if obj%file_new_file_freq_units is allocated pure logical function has_file_new_file_freq_units (obj) class(diagYamlFiles_type), intent(in) :: obj !< diagYamlFiles_type object to initialize - has_file_new_file_freq_units = allocated(obj%file_new_file_freq_units) + has_file_new_file_freq_units = obj%file_new_file_freq_units .ne. diag_null end function has_file_new_file_freq_units !> @brief Checks if obj%file_start_time is allocated !! @return true if obj%file_start_time is allocated @@ -1068,7 +1093,7 @@ end function has_file_duration !! @return true pure logical function has_file_duration_units (obj) class(diagYamlFiles_type), intent(in) :: obj !< diagYamlFiles_type object to initialize - has_file_duration_units = .true. + has_file_duration_units = obj%file_duration_units .ne. diag_null end function has_file_duration_units !> @brief Checks if obj%file_varlist is allocated !! @return true if obj%file_varlist is allocated diff --git a/test_fms/diag_manager/test_diag_yaml.F90 b/test_fms/diag_manager/test_diag_yaml.F90 index 0ec2740a9..ad157cc32 100644 --- a/test_fms/diag_manager/test_diag_yaml.F90 +++ b/test_fms/diag_manager/test_diag_yaml.F90 @@ -25,7 +25,7 @@ program test_diag_yaml use FMS_mod, only: fms_init, fms_end use fms_diag_yaml_mod use diag_data_mod, only: DIAG_NULL, DIAG_ALL, get_base_year, get_base_month, get_base_day, get_base_hour, & - & get_base_minute, get_base_second, diag_data_init + & get_base_minute, get_base_second, diag_data_init, DIAG_HOURS, DIAG_NULL, DIAG_DAYS use time_manager_mod, only: set_calendar_type, JULIAN use mpp_mod use platform_mod @@ -211,13 +211,13 @@ subroutine compare_diag_files(res) call compare_result("file_freq 2", res(2)%get_file_freq(), 24) call compare_result("file_freq 3", res(3)%get_file_freq(), -1) - call compare_result("file_frequnit 1", res(1)%get_file_frequnit(), "hours") - call compare_result("file_frequnit 2", res(2)%get_file_frequnit(), "days") - call compare_result("file_frequnit 3", res(3)%get_file_frequnit(), "days") + call compare_result("file_frequnit 1", res(1)%get_file_frequnit(), DIAG_HOURS) + call compare_result("file_frequnit 2", res(2)%get_file_frequnit(), DIAG_DAYS) + call compare_result("file_frequnit 3", res(3)%get_file_frequnit(), DIAG_DAYS) - call compare_result("file_timeunit 1", res(1)%get_file_timeunit(), "hours") - call compare_result("file_timeunit 2", res(2)%get_file_timeunit(), "hours") - call compare_result("file_timeunit 3", res(3)%get_file_timeunit(), "hours") + call compare_result("file_timeunit 1", res(1)%get_file_timeunit(), DIAG_HOURS) + call compare_result("file_timeunit 2", res(2)%get_file_timeunit(), DIAG_HOURS) + call compare_result("file_timeunit 3", res(3)%get_file_timeunit(), DIAG_HOURS) call compare_result("file_unlimdim 1", res(1)%get_file_unlimdim(), "time") call compare_result("file_unlimdim 2", res(2)%get_file_unlimdim(), "records") @@ -227,17 +227,17 @@ subroutine compare_diag_files(res) call compare_result("file_new_file_freq 2", res(2)%get_file_new_file_freq(), DIAG_NULL) call compare_result("file_new_file_freq 3", res(3)%get_file_new_file_freq(), DIAG_NULL) - call compare_result("file_new_file_freq_units 1", res(1)%get_file_new_file_freq_units(), "hours") - call compare_result("file_new_file_freq_units 2", res(2)%get_file_new_file_freq_units(), "") - call compare_result("file_new_file_freq_units 3", res(3)%get_file_new_file_freq_units(), "") + call compare_result("file_new_file_freq_units 1", res(1)%get_file_new_file_freq_units(), DIAG_HOURS) + call compare_result("file_new_file_freq_units 2", res(2)%get_file_new_file_freq_units(), DIAG_NULL) + call compare_result("file_new_file_freq_units 3", res(3)%get_file_new_file_freq_units(), DIAG_NULL) call compare_result("file_duration 1", res(1)%get_file_duration(), 12) call compare_result("file_duration 2", res(2)%get_file_duration(), DIAG_NULL) call compare_result("file_duration 3", res(3)%get_file_duration(), DIAG_NULL) - call compare_result("file_duration_units 1", res(1)%get_file_duration_units(), "hours") - call compare_result("file_duration_units 2", res(2)%get_file_duration_units(), "") - call compare_result("file_duration_units 3", res(3)%get_file_duration_units(), "") + call compare_result("file_duration_units 1", res(1)%get_file_duration_units(), DIAG_HOURS) + call compare_result("file_duration_units 2", res(2)%get_file_duration_units(), DIAG_NULL) + call compare_result("file_duration_units 3", res(3)%get_file_duration_units(), DIAG_NULL) call compare_result("file_start_time 1", res(1)%get_file_start_time(), "2 1 1 0 0 0") call compare_result("file_start_time 2", res(2)%get_file_start_time(), "") @@ -306,6 +306,8 @@ subroutine compare_result_0d(key_name, res, expected_res) if(trim(res) .ne. trim(expected_res)) & call mpp_error(FATAL, "Error!: "//trim(key_name)//" is not the expected result. "//trim(res)//" ne "//& trim(expected_res)//".") + class default + call mpp_error(FATAL, "Error!: "//trim(key_name)//" does not have the same type") end select type is (integer(kind=i4_kind)) select type(expected_res) @@ -314,6 +316,8 @@ subroutine compare_result_0d(key_name, res, expected_res) print *, res, " ne ", expected_res call mpp_error(FATAL, "Error!: "//trim(key_name)//" is not the expected result.") endif + class default + call mpp_error(FATAL, "Error!: "//trim(key_name)//" does not have the same type") end select type is (logical) select type(expected_res) @@ -322,6 +326,8 @@ subroutine compare_result_0d(key_name, res, expected_res) print*, res, " ne ", expected_res call mpp_error(FATAL, "Error!:"//trim(key_name)//" is not the expected result") endif + class default + call mpp_error(FATAL, "Error!: "//trim(key_name)//" does not have the same type") end select end select @@ -349,6 +355,8 @@ subroutine compare_result_1d(key_name, res, expected_res) call mpp_error(FATAL, "Error!: "//trim(key_name)//" is not the expected result. ") endif enddo + class default + call mpp_error(FATAL, "Error!: "//trim(key_name)//" does not have the same type") end select type is (real(kind=r4_kind)) select type(expected_res) @@ -359,6 +367,8 @@ subroutine compare_result_1d(key_name, res, expected_res) call mpp_error(FATAL, "Error!: "//trim(key_name)//" is not the expected result. ") endif enddo + class default + call mpp_error(FATAL, "Error!: "//trim(key_name)//" does not have the same type") end select type is (real(kind=r8_kind)) select type(expected_res) @@ -369,6 +379,8 @@ subroutine compare_result_1d(key_name, res, expected_res) call mpp_error(FATAL, "Error!: "//trim(key_name)//" is not the expected result. ") endif enddo + class default + call mpp_error(FATAL, "Error!: "//trim(key_name)//" does not have the same type") end select end select end subroutine compare_result_1d