!-------------------------------------------------------------------------
!     NASA GSFC Land Information Systems LIS 2.3                         !
!-------------------------------------------------------------------------
!BOP
!
! !MODULE: lsm_pluginMod.F90  
! 
! !DESCRIPTION: 
!   This module contains the definition of the functions used for
!   land surface model initialization, execution, reading and 
!   writing of restart files and other relevant land surface
!   model computations, corresponding to each of the LSMs used in LIS.
!   
! !REVISION HISTORY: 
!  09 Oct 03    Sujay Kumar  Initial Specification
! 
! !INTERFACE:
module lsm_pluginMod
!EOP  
  implicit none
  
contains
!BOP
! !ROUTINE: lsm_plugin
!
! !DESCRIPTION:
!
! This is a custom-defined plugin point for introducing a new LSM. 
! The interface mandates that the following routines be implemented
! and registered for each of the LSM that is included in LIS. 
!
!  \begin{description}
!  \item[Initialization]
!      Definition of LSM variables 
!      (to be registered using registerlsmini)
!  \item[Setup] 
!      Initialization of parameters
!      (to be registered using registerlsmsetup)
!  \item[DynamicSetup]
!      Routines to setup time dependent parameters
!      (to be registered using registerlsmdynsetup)
!  \item[Run]
!      Routines to execute LSM on a single gridcell for single timestep
!      (to be registered using registerlsmrun)
!  \item[Read restart]
!      Routines to read a restart file for an LSM run
!      (to be registered using registerlsmrestart)
!  \item[Output]
!      Routines to write output
!      (to be registered using registerlsmoutput)
!  \item[Forcing transfer to model tiles]
!      Routines to transfer an array of given forcing to model tiles
!      (to be registered using registerlsmf2t)
!  \item[Write restart]
!      Routines to write a restart file
!      (to be registered using registerlsmwrst)
!  \end{description}
! Multiple LSMs can be 
! included as well, each distinguished in the function table registry
! by the associated LSM index assigned in the card file. 
! 
! !INTERFACE:
  subroutine lsm_plugin
! !USES:
    use noah_varder, only : noah_varder_ini
    use clm_varder, only : clm_varder_ini
    use vic_varder, only : vic_varder_ini
    use atmdrvMod, only : atmdrv
!EOP
    external noah_main , driver, vic_main
    external noah_setup, clm2_setup,vic_setup
    external noahrst, clm2_restart,vic_readrestart
    external noah_output, clm2_output,vic_output
    external noah_f2t,vic_atmdrv
    external noah_writerst, clm2wrst,vic_writerestart
    external noah_dynsetup,clm2_dynsetup,vic_dynsetup
!BOC
    call registerlsmini(1,noah_varder_ini)
    call registerlsmini(2,clm_varder_ini)
    call registerlsmini(3,vic_varder_ini)
    
    call registerlsmsetup(1,noah_setup)
    call registerlsmsetup(2,clm2_setup)
    call registerlsmsetup(3,vic_setup)
    
    call registerlsmdynsetup(1,noah_dynsetup)
    call registerlsmdynsetup(2,clm2_dynsetup)
    call registerlsmdynsetup(3,vic_dynsetup)
    
    call registerlsmrun(1,noah_main)
    call registerlsmrun(2,driver)
    call registerlsmrun(3,vic_main)
    
    call registerlsmrestart(1,noahrst)
    call registerlsmrestart(2,clm2_restart)
    call registerlsmrestart(3,vic_readrestart)
    
    call registerlsmoutput(1,noah_output)
    call registerlsmoutput(2,clm2_output)
    call registerlsmoutput(3,vic_output)
    
    call registerlsmf2t(1,noah_f2t)
    call registerlsmf2t(2,atmdrv)
    call registerlsmf2t(3,vic_atmdrv)
    
    call registerlsmwrst(1,noah_writerst)
    call registerlsmwrst(2,clm2wrst)
    call registerlsmwrst(3,vic_writerestart)
!EOC         
  end subroutine lsm_plugin
end module lsm_pluginMod