Find_M_files_for_currTime Subroutine

public subroutine Find_M_files_for_currTime(currTime, obsfile_start_time, obsfile_end_time, obsfile_interval, epoch_frequency, file_template, M, filenames, T_offset_in_file_content, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Time), intent(in) :: currTime
type(ESMF_Time), intent(in) :: obsfile_start_time
type(ESMF_Time), intent(in) :: obsfile_end_time
type(ESMF_TimeInterval), intent(in) :: obsfile_interval
type(ESMF_TimeInterval), intent(in) :: epoch_frequency
character(len=*), intent(in) :: file_template
integer, intent(out) :: M
character(len=ESMF_MAXSTR), intent(inout) :: filenames(:)
type(ESMF_TimeInterval), intent(in), optional :: T_offset_in_file_content
integer, intent(out), optional :: rc

Calls

proc~~find_m_files_for_currtime~~CallsGraph proc~find_m_files_for_currtime Find_M_files_for_currTime ESMF_TimeIntervalGet ESMF_TimeIntervalGet proc~find_m_files_for_currtime->ESMF_TimeIntervalGet ESMF_TimeIntervalSet ESMF_TimeIntervalSet proc~find_m_files_for_currtime->ESMF_TimeIntervalSet interface~mapl_assert MAPL_Assert proc~find_m_files_for_currtime->interface~mapl_assert proc~get_filename_from_template_use_index get_filename_from_template_use_index proc~find_m_files_for_currtime->proc~get_filename_from_template_use_index proc~mapl_return MAPL_Return proc~find_m_files_for_currtime->proc~mapl_return proc~get_filename_from_template_use_index->ESMF_TimeIntervalGet proc~get_filename_from_template_use_index->ESMF_TimeIntervalSet proc~get_filename_from_template_use_index->interface~mapl_assert proc~get_filename_from_template_use_index->proc~mapl_return proc~esmf_time_to_two_integer ESMF_time_to_two_integer proc~get_filename_from_template_use_index->proc~esmf_time_to_two_integer proc~fglob fglob proc~get_filename_from_template_use_index->proc~fglob proc~fill_grads_template fill_grads_template proc~get_filename_from_template_use_index->proc~fill_grads_template proc~mapl_verify MAPL_Verify proc~get_filename_from_template_use_index->proc~mapl_verify at at proc~mapl_return->at insert insert proc~mapl_return->insert proc~mapl_throw_exception MAPL_throw_exception proc~mapl_return->proc~mapl_throw_exception proc~esmf_time_to_two_integer->proc~mapl_return proc~esmf_time_to_two_integer->proc~mapl_verify ESMF_TimeGet ESMF_TimeGet proc~esmf_time_to_two_integer->ESMF_TimeGet proc~fglob->interface~mapl_assert interface~f_call_c_glob f_call_c_glob proc~fglob->interface~f_call_c_glob interface~mapl_am_i_root MAPL_Am_I_Root proc~fglob->interface~mapl_am_i_root proc~fill_grads_template->interface~mapl_assert proc~fill_grads_template->proc~mapl_return proc~fill_grads_template->proc~mapl_verify ESMF_CalendarCreate ESMF_CalendarCreate proc~fill_grads_template->ESMF_CalendarCreate ESMF_CalendarDestroy ESMF_CalendarDestroy proc~fill_grads_template->ESMF_CalendarDestroy proc~fill_grads_template->ESMF_TimeGet ESMF_TimeSet ESMF_TimeSet proc~fill_grads_template->ESMF_TimeSet proc~mapl_verify->proc~mapl_throw_exception

Source Code

  subroutine Find_M_files_for_currTime (currTime, &
       obsfile_start_time, obsfile_end_time, obsfile_interval, &
       epoch_frequency, file_template, M, filenames, &
       T_offset_in_file_content, rc)
    implicit none
    type(ESMF_Time), intent(in) :: currTime
    type(ESMF_Time), intent(in) :: obsfile_start_time, obsfile_end_time
    type(ESMF_TimeInterval), intent(in) :: obsfile_interval, epoch_frequency
    character(len=*), intent(in) :: file_template
    integer, intent(out) :: M
    character(len=ESMF_MAXSTR), intent(inout) :: filenames(:)
    type(ESMF_TimeInterval), intent(in), optional :: T_offset_in_file_content
    integer, optional, intent(out) :: rc

    type(ESMF_Time) :: T1, Tn
    type(ESMF_Time) :: cT1
    type(ESMF_Time) :: Ts, Te
    type(ESMF_TimeInterval) :: dT1, dT2, dTs, dTe
    type(ESMF_TimeInterval) :: Toff
    real(ESMF_KIND_R8) :: dT0_s, dT1_s, dT2_s
    real(ESMF_KIND_R8) :: s1, s2
    character(len=ESMF_MAXSTR) :: test_file

    integer :: obsfile_Ts_index, obsfile_Te_index
    integer :: n1, n2
    integer :: i, j
    integer :: status
    logical :: exist

    !__ s1.  Arithmetic index list based on s,e,interval
    !
    if (present(T_offset_in_file_content)) then
       Toff = T_offset_in_file_content
    else
       call ESMF_TimeIntervalSet(Toff, h=0, m=0, s=60, rc=status)
    endif

    !    T1 = obsfile_start_time + Toff
    !    Tn = obsfile_end_time + Toff

    T1 = obsfile_start_time
    Tn = obsfile_end_time

    cT1 = currTime
    dT1 = currTime - T1
    dT2 = currTime + epoch_frequency - T1

    call ESMF_TimeIntervalGet(obsfile_interval, s_r8=dT0_s, rc=status)
    call ESMF_TimeIntervalGet(dT1, s_r8=dT1_s, rc=status)
    call ESMF_TimeIntervalGet(dT2, s_r8=dT2_s, rc=status)

    n1 = floor (dT1_s / dT0_s) - 1  ! downshift by 1, as filename does not guarantee accurate time
    n2 = floor (dT2_s / dT0_s)

!    print*, 'ck dT0_s, dT1_s, dT2_s', dT0_s, dT1_s, dT2_s
!    print*, '1st n1, n2', n1, n2

    obsfile_Ts_index = n1
    obsfile_Te_index = n2


    !__ s2.  further test file existence
    !
    j=0
    do i= n1, n2
       test_file = get_filename_from_template_use_index &
            (obsfile_start_time, obsfile_interval, &
            i, file_template, exist, rc=rc)
       if (exist) then
          j=j+1
          filenames(j) = test_file
       end if
    end do
    M=j

    _ASSERT ( M < size(filenames) , 'code crash, number of files exceeds upper bound')
    _ASSERT (M/=0, 'M is zero, no files found for currTime')

    _RETURN(_SUCCESS)

  end subroutine Find_M_files_for_currTime