run_component_driver Subroutine

subroutine run_component_driver(filename, rc)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
integer, intent(out) :: rc

Calls

proc~~run_component_driver~~CallsGraph proc~run_component_driver run_component_driver ESMF_ClockCreate ESMF_ClockCreate proc~run_component_driver->ESMF_ClockCreate ESMF_ConfigCreate ESMF_ConfigCreate proc~run_component_driver->ESMF_ConfigCreate ESMF_ConfigLoadFile ESMF_ConfigLoadFile proc~run_component_driver->ESMF_ConfigLoadFile ESMF_GridCompCreate ESMF_GridCompCreate proc~run_component_driver->ESMF_GridCompCreate ESMF_GridCompFinalize ESMF_GridCompFinalize proc~run_component_driver->ESMF_GridCompFinalize ESMF_GridCompInitialize ESMF_GridCompInitialize proc~run_component_driver->ESMF_GridCompInitialize ESMF_GridCompRun ESMF_GridCompRun proc~run_component_driver->ESMF_GridCompRun ESMF_GridCompSet ESMF_GridCompSet proc~run_component_driver->ESMF_GridCompSet ESMF_GridGetCoord ESMF_GridGetCoord proc~run_component_driver->ESMF_GridGetCoord ESMF_TimeIntervalSet ESMF_TimeIntervalSet proc~run_component_driver->ESMF_TimeIntervalSet interface~mapl_addchild MAPL_AddChild proc~run_component_driver->interface~mapl_addchild interface~mapl_set MAPL_Set proc~run_component_driver->interface~mapl_set none~get_child_export_state MAPL_MetaComp%get_child_export_state proc~run_component_driver->none~get_child_export_state none~get_child_gridcomp MAPL_MetaComp%get_child_gridcomp proc~run_component_driver->none~get_child_gridcomp none~get_child_import_state MAPL_MetaComp%get_child_import_state proc~run_component_driver->none~get_child_import_state none~get_var~21 NetCDF4_FileFormatter%get_var proc~run_component_driver->none~get_var~21 none~make_grid~4 GridManager%make_grid proc~run_component_driver->none~make_grid~4 proc~create FileMetadataUtils%create proc~run_component_driver->proc~create proc~get_config_attributes get_config_attributes proc~run_component_driver->proc~get_config_attributes proc~get_time_info FileMetadataUtils%get_time_info proc~run_component_driver->proc~get_time_info proc~mapl_internalstatecreate MAPL_InternalStateCreate proc~run_component_driver->proc~mapl_internalstatecreate proc~mapl_internalstateretrieve MAPL_InternalStateRetrieve proc~run_component_driver->proc~mapl_internalstateretrieve proc~mapl_return MAPL_Return proc~run_component_driver->proc~mapl_return proc~mapl_verify MAPL_Verify proc~run_component_driver->proc~mapl_verify

Called by

proc~~run_component_driver~~CalledByGraph proc~run_component_driver run_component_driver proc~main main proc~main->proc~run_component_driver program~comp_testing_driver comp_testing_driver program~comp_testing_driver->proc~main

Source Code

  subroutine run_component_driver(filename, rc)
    character(len=*), intent(in) :: filename
    integer, intent(out) :: rc
    integer :: status, root_id, user_RC, RUN_DT
    integer :: NX, NY, phase
    character(len=ESMF_MAXSTR) :: comp_name, shared_obj, restart_file
    type(ESMF_Clock) :: clock
    type(ESMF_TimeInterval) :: time_interval
    type(ESMF_GridComp) :: temp_GC, GC
    type(ESMF_State) :: import, export
    type(ESMF_Config) :: config
    type(ESMF_Time), allocatable :: start_time(:)
    type(ESMF_Grid) :: grid
    type(MAPL_MetaComp), pointer :: mapl_obj
    real(kind=ESMF_KIND_R8), pointer :: lons_field_ptr(:,:), lats_field_ptr(:,:)
    type(NetCDF4_fileFormatter) :: formatter
    type(FileMetadata) :: basic_metadata
    type(FileMetadataUtils) :: metadata
    logical :: subset

    ! get attributes from config file
    config = ESMF_ConfigCreate(_RC)
    call ESMF_ConfigLoadFile(config, filename, _RC)
    call get_config_attributes(config, comp_name, RUN_DT, restart_file, shared_obj, phase, subset, NX, NY, _RC)

    ! create a clock, set current time to required time consistent with checkpoints used
    call formatter%open(restart_file, pFIO_Read, _RC)
    call ESMF_TimeIntervalSet(time_interval, s=RUN_DT, _RC)
    basic_metadata=formatter%read(_RC)
    call metadata%create(basic_metadata,trim(restart_file))
    call metadata%get_time_info(timeVector=start_time,_RC)
    clock = ESMF_ClockCreate(time_interval, start_time(1), _RC)
    call formatter%close(_RC)

    ! create MAPL_MetaComp object, add child
    grid=grid_manager%make_grid(config, _RC)

    temp_GC = ESMF_GridCompCreate(name=comp_name, _RC)
    mapl_obj => null()
    call MAPL_InternalStateCreate(temp_GC, mapl_obj, _RC)
    call MAPL_InternalStateRetrieve(temp_GC, mapl_obj, _RC)
    call MAPL_Set(mapl_obj, CF=config, _RC)

    root_id = MAPL_AddChild(mapl_obj, grid=grid, name=comp_name, userRoutine="setservices_", sharedObj=shared_obj, _RC)

    GC = mapl_obj%get_child_gridcomp(root_id)
    import = mapl_obj%get_child_import_state(root_id)
    export = mapl_obj%get_child_export_state(root_id)

    ! if subsetting, get appropriate lons and lats
    if (subset .and. NX*NY == 1) then
       call formatter%open(restart_file, pFIO_Read, _RC)
       call ESMF_GridGetCoord(grid, coordDim=1, farrayPtr=lons_field_ptr, _RC)
       call ESMF_GridGetCoord(grid, coordDim=2, farrayPtr=lats_field_ptr, _RC)
       call formatter%get_var("lons", lons_field_ptr)
       call formatter%get_var("lats", lats_field_ptr)
       call ESMF_GridCompSet(GC, grid=grid, _RC)
       call formatter%close(_RC)
    else
       call ESMF_GridCompSet(GC, grid=grid, _RC)
    end if


    call ESMF_GridCompInitialize(GC, importState=import, exportState=export, clock=clock, userRC=user_RC, _RC)

    call ESMF_GridCompRun(GC, importState=import, exportState=export, clock=clock, phase=phase, userRC=user_RC, _RC)

    call ESMF_GridCompFinalize(GC, importState=import, exportState=export, clock=clock, userRC=user_RC, _RC)

    _RETURN(_SUCCESS)
  end subroutine run_component_driver