MODULE disvert_plugin_mod
  USE prec, ONLY: rstd
  IMPLICIT NONE
  REAL(rstd), SAVE, ALLOCATABLE,TARGET :: ap(:)
!$OMP THREADPRIVATE(ap)
  REAL(rstd), SAVE, ALLOCATABLE,TARGET :: bp(:)
!$OMP THREADPRIVATE(bp)
  REAL(rstd), SAVE, ALLOCATABLE,TARGET :: presnivs(:)
!$OMP THREADPRIVATE(presnivs)
  REAL(rstd), SAVE, ALLOCATABLE,TARGET :: presinter(:)
  !$OMP THREADPRIVATE(presinter)


  INTERFACE
    SUBROUTINE plugin_disvert(ap,bp,presnivs,presinter)
      REAL,INTENT(OUT) :: ap(:)
      REAL,INTENT(OUT) :: bp(:)
      REAL,INTENT(OUT) :: presnivs(:)
      REAL,INTENT(OUT) :: presinter(:)
    END SUBROUTINE
  END INTERFACE
  
  PROCEDURE(plugin_disvert), POINTER :: disvert_plugin => NULL()

CONTAINS

  SUBROUTINE init_disvert

  USE grid_param, ONLY: llm
  USE abort_mod, ONLY: dynamico_abort

  IMPLICIT NONE
  
    ALLOCATE(ap(llm+1))
    ALLOCATE(bp(llm+1))
    ALLOCATE(presnivs(llm))
    ALLOCATE(presinter(llm+1))
  
    IF(.NOT.ASSOCIATED(disvert_plugin)) THEN
      WRITE(*,*) "Fatal Error: option disvert=plugin is selected ",&
                 "but disvert_plugin not set by driver"
       CALL dynamico_abort("init_disvert : disvert_plugin not set")
    ENDIF

    CALL disvert_plugin(ap,bp,presnivs,presinter)

  END SUBROUTINE init_disvert  

END MODULE disvert_plugin_mod
