subroutine MAPL_read_bundle(bundle,file_tmpl,time,only_vars,regrid_method,noread,file_override,file_weights,rc)
type(ESMF_FieldBundle), intent(inout) :: bundle
character(len=*), intent(in) :: file_tmpl
type(ESMF_Time), intent(in) :: time
character(len=*), optional, intent(in) :: only_vars
integer, optional, intent(in) :: regrid_method
logical, optional, intent(in) :: noread
character(len=*), optional, intent(in) :: file_override
logical, optional, intent(in) :: file_weights
integer, optional, intent(out) :: rc
integer :: status
integer :: num_fields, metadata_id, collection_id, time_index, i, regrid_hints
type(MAPL_GriddedIO) :: cfio
character(len=ESMF_MAXPATHLEN) :: file_name
type(MAPLDataCollection), pointer :: collection => null()
type(fileMetaDataUtils), pointer :: metadata
type(ESMF_Time), allocatable :: time_series(:)
type(GriddedIOItemVector) :: items
character(len=ESMF_MAXSTR), allocatable :: field_names(:)
type(GriddedIOitem) :: item
call fill_grads_template(file_name,file_tmpl,time=time,rc=status)
_VERIFY(status)
collection_id=i_clients%add_ext_collection(trim(file_tmpl))
metadata_id = MAPL_DataAddCollection(trim(file_tmpl))
collection => DataCollections%at(metadata_id)
if (present(file_override)) file_name = file_override
metadata => collection%find(trim(file_name), _RC)
call metadata%get_time_info(timeVector=time_series,rc=status)
_VERIFY(status)
time_index=-1
do i=1,size(time_series)
if (time==time_series(i)) then
time_index=i
exit
end if
end do
_ASSERT(time_index/=-1,"Time not found on file "//trim(file_name))
deallocate(time_series)
call ESMF_FieldBundleGet(bundle,fieldCount=num_fields,rc=status)
_VERIFY(status)
if (num_fields ==0) then
call MAPL_create_bundle_from_metdata_id(bundle,metadata_id,file_name,only_vars=only_vars,rc=status)
_VERIFY(status)
end if
if (present(noread)) then
if (noread) then
_RETURN(_SUCCESS)
end if
end if
call ESMF_FieldBundleGet(bundle,fieldCount=num_fields,rc=status)
_VERIFY(status)
allocate(field_names(num_fields))
call ESMF_FieldBundleGet(bundle,fieldnamelist=field_names,rc=status)
_VERIFY(status)
do i=1,num_fields
item%itemTYpe=ItemTYpeScalar
item%xname=trim(field_names(i))
call items%push_back(item)
enddo
cfio=MAPL_GriddedIO(output_bundle=bundle,metadata_collection_id=metadata_id,read_collection_id=collection_id,items=items)
call cfio%set_param(regrid_method=regrid_method)
if (present(file_weights)) then
if (file_weights) then
regrid_hints = 0
regrid_hints = IOR(regrid_hints,REGRID_HINT_FILE_WEIGHTS)
call cfio%set_param(regrid_hints=regrid_hints)
end if
end if
call cfio%request_data_from_file(trim(file_name),timeindex=time_index,rc=status)
_VERIFY(status)
call i_clients%done_collective_prefetch(_RC)
call i_clients%wait(_RC)
call cfio%process_data_from_file(rc=status)
_VERIFY(status)
_RETURN(_SUCCESS)
end subroutine MAPL_read_bundle