comp_testing_driver Program

Uses

  • program~~comp_testing_driver~~UsesGraph program~comp_testing_driver comp_testing_driver ESMF ESMF program~comp_testing_driver->ESMF NetCDF NetCDF program~comp_testing_driver->NetCDF module~esmfl_mod ESMFL_MOD program~comp_testing_driver->module~esmfl_mod module~mapl MAPL program~comp_testing_driver->module~mapl module~mapl_basemod MAPL_BaseMod program~comp_testing_driver->module~mapl_basemod module~mapl_capgridcompmod MAPL_CapGridCompMod program~comp_testing_driver->module~mapl_capgridcompmod module~mapl_genericmod MAPL_GenericMod program~comp_testing_driver->module~mapl_genericmod module~mapl_gridmanagermod MAPL_GridManagerMod program~comp_testing_driver->module~mapl_gridmanagermod module~mapl_timedatamod MAPL_TimeDataMod program~comp_testing_driver->module~mapl_timedatamod mpi mpi program~comp_testing_driver->mpi

Calls

program~~comp_testing_driver~~CallsGraph program~comp_testing_driver comp_testing_driver proc~main main program~comp_testing_driver->proc~main ESMF_CalendarSetDefault ESMF_CalendarSetDefault proc~main->ESMF_CalendarSetDefault ESMF_ConfigCreate ESMF_ConfigCreate proc~main->ESMF_ConfigCreate ESMF_ConfigLoadFile ESMF_ConfigLoadFile proc~main->ESMF_ConfigLoadFile ESMF_Finalize ESMF_Finalize proc~main->ESMF_Finalize ESMF_Initialize ESMF_Initialize proc~main->ESMF_Initialize ESMF_VMGet ESMF_VMGet proc~main->ESMF_VMGet none~start~47 BaseProfiler%start proc~main->none~start~47 proc~get_global_time_profiler get_global_time_profiler proc~main->proc~get_global_time_profiler proc~mapl_finalize MAPL_Finalize proc~main->proc~mapl_finalize proc~mapl_initialize MAPL_Initialize proc~main->proc~mapl_initialize proc~mapl_verify MAPL_Verify proc~main->proc~mapl_verify proc~run_component_driver run_component_driver proc~main->proc~run_component_driver

Subroutines

subroutine get_config_attributes(config, comp_name, RUN_DT, restart_file, shared_obj, phase, subset, NX, NY, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Config), intent(inout) :: config
character(len=ESMF_MAXSTR), intent(inout) :: comp_name
integer, intent(inout) :: RUN_DT
character(len=ESMF_MAXSTR), intent(inout) :: restart_file
character(len=ESMF_MAXSTR), intent(inout) :: shared_obj
integer, intent(inout) :: phase
logical, intent(inout) :: subset
integer, intent(inout) :: NX
integer, intent(inout) :: NY
integer, intent(out) :: rc

subroutine main()

Arguments

None

subroutine run_component_driver(filename, rc)

Arguments

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

Source Code

program comp_testing_driver
  use ESMF
  use NetCDF
  use ESMFL_Mod
  use MAPL
  use MPI
  use MAPL_GenericMod
  use MAPL_BaseMod
  use MAPL_CapGridCompMod
  use MAPL_TimeDataMod
  use MAPL_GridManagerMod

  implicit none

  call main()

  contains

    subroutine main()
      integer :: status, rc, local_PET, n_PET
      type(ESMF_VM) :: vm
      character(len=ESMF_MAXSTR) :: filename
      type(ESMF_Config) :: config
      class(BaseProfiler), pointer :: t_p

      ! initialize
      call ESMF_Initialize(logKindFlag=ESMF_LOGKIND_NONE, vm=vm, _RC)
      call ESMF_VMGet(vm, localPET=local_PET, petCount=n_PET, _RC)
      call MAPL_Initialize(_RC)
      call ESMF_CalendarSetDefault(ESMF_CALKIND_GREGORIAN, _RC)
      t_p => get_global_time_profiler()
      call t_p%start('Comp_Testing_Driver.x')

      ! get rc filename and component to run
      call get_command_argument(1, filename)
      config = ESMF_ConfigCreate(_RC)
      call ESMF_ConfigLoadFile(config, filename, _RC)
      call run_component_driver(filename, _RC)

      ! finalize
      call t_p%stop('Comp_Testing_Driver.x')
      call MAPL_Finalize(_RC)
      call ESMF_Finalize (_RC)
  end subroutine main

  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

  subroutine get_config_attributes(config, comp_name, RUN_DT, restart_file, shared_obj, phase, subset, NX, NY, rc)
    type(ESMF_Config), intent(inout) :: config
    character(len=ESMF_MAXSTR), intent(inout) :: comp_name, shared_obj, restart_file
    integer, intent(inout) :: NX, NY, phase, RUN_DT
    logical, intent(inout) :: subset
    integer, intent(out) :: rc
    integer :: status

    call ESMF_ConfigGetAttribute(config, value=comp_name, label="COMPONENT_TO_RECORD:", _RC)
    call ESMF_ConfigGetAttribute(config, value=RUN_DT, label="RUN_DT:", _RC)
    call ESMF_ConfigGetAttribute(config, value=restart_file, label="RESTART_FILE:", _RC)
    call ESMF_ConfigGetAttribute(config, value=shared_obj, label = "LIBRARY_FILE:", _RC)
    call ESMF_ConfigGetAttribute(config, value=phase, label="PHASE:", default=1, _RC)
    call ESMF_ConfigGetAttribute(config, value=subset, label="SUBSET:", default=.false., _RC)
    call ESMF_ConfigGetAttribute(config, value=NX, label = "NX:", _RC)
    call ESMF_ConfigGetAttribute(config, value=NY, label = "NX:", _RC)

    _RETURN(_SUCCESS)
  end subroutine get_config_attributes

end program comp_testing_driver