!< @brief an example of using SFX/TerM interface
program sfx_term_ex
    
    !> SFX data structures
    use sfx_data, only: meteoDataType, sfxDataType
    !> SFX-TerM interface
    use sfx_api_term
    !> actual interface of ESM model
    use sfx_esm, only: &
        get_surface_fluxes_esm => get_surface_fluxes, &
        numericsType_esm => numericsType

    implicit none

    type(meteoDataType) :: meteo_cell
    type(sfxDataType) :: sfx_cell
    type(numericsType_esm) :: numerics

    !> TerM surface layer uses legacy INMCM AR arrays for input/output
    real :: AR1(6), AR2(11)


    ! --- setting some dummy data
    !   *: the actual values should be supplied by model
    AR1(1) = 10.0       ! wind speed
    AR1(2) = 0.0        ! difference between surface and air temperature
    AR1(3) = 273.15     ! semi-sum of surface and air temperature
    AR1(4) = 0.0        ! difference in surface and air specific humidity
    AR1(5) = 2.0        ! height at which fluxes are evaluated
    AR1(6) = 1.0e-3     ! surface roughness parameter 

    ! --- converting AR input to SFX format -> meteo cell
    call term_to_sfx_in_cell(meteo_cell, AR1)
    ! --- calculating fluxes
    call get_surface_fluxes_esm(sfx_cell, meteo_cell, numerics)
    ! --- converting SFX cell output to AR format
    call sfx_to_term_out_cell(AR2, sfx_cell) 
    !   *: now AR can be passed to other parts of TerM
    
    stop
end program sfx_term_ex
