function get_filename_from_template_use_index (obsfile_start_time, obsfile_interval, &
f_index, file_template, exist, rc) result(filename)
use Plain_netCDF_Time, only : ESMF_time_to_two_integer
use MAPL_StringTemplate, only : fill_grads_template
character(len=ESMF_MAXSTR) :: filename
type(ESMF_Time), intent(in) :: obsfile_start_time
type(ESMF_TimeInterval), intent(in) :: obsfile_interval
character(len=*), intent(in) :: file_template
integer, intent(in) :: f_index
logical, intent(out) :: exist
integer, optional, intent(out) :: rc
integer :: itime(2)
integer :: nymd, nhms
integer :: status
real(ESMF_KIND_R8) :: dT0_s
real(ESMF_KIND_R8) :: s
type(ESMF_TimeInterval) :: dT
type(ESMF_Time) :: time
integer :: i, j, u
logical :: allow_wild_char
character(len=ESMF_MAXSTR) :: filename2
call ESMF_TimeIntervalGet(obsfile_interval, s_r8=dT0_s, rc=status)
s = dT0_s * f_index
call ESMF_TimeIntervalSet(dT, s_r8=s, rc=status)
time = obsfile_start_time + dT
call ESMF_time_to_two_integer(time, itime, _RC)
nymd = itime(1)
nhms = itime(2)
! parse time info
!
allow_wild_char=.true.
j= index(file_template, '*')
_ASSERT ( j==0 .OR. allow_wild_char, "* is not allowed in template")
call fill_grads_template ( filename, file_template, &
experiment_id='', nymd=nymd, nhms=nhms, _RC )
if (j==0) then
! exact file name
inquire(file= trim(filename), EXIST = exist)
else
! now filename is: file*.nc
call fglob(filename, filename2, rc=status)
exist = (status==0)
if (exist) filename=trim(filename2)
end if
_RETURN(_SUCCESS)
end function get_filename_from_template_use_index