!--
!----------------------------------------------------------------------
!     Copyright (c) 2017 Shin-ichi Takehiro. All rights reserved.
!----------------------------------------------------------------------
!è¡¨é¡Œ  w_wave_deriv_module_svpack
!
!  spml/w_wave_deriv_module_svpack ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã¯çƒé¢ä¸Šã§ã® 2 æ¬¡å…ƒ
!  æµä½“é‹å‹•ã‚’çƒé¢èª¿å’Œå‡½æ•°ã‚’ç”¨ã„ãŸã‚¹ãƒšã‚¯ãƒˆãƒ«æ³•ã«ã‚ˆã£ã¦æ•°å€¤è¨ˆç®—ã™ã‚‹
!  ãŸã‚ã® ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ« w_module_svpack ã®ä¸‹éƒ¨ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã§ã‚ã‚Š,
!  ã‚¹ãƒšã‚¯ãƒˆãƒ«æ³•ã®å¾®åˆ†è¨ˆç®—ã®ãŸã‚ã® Fortran90 é–¢æ•°ã‚’æä¾›ã™ã‚‹.
!
!  å†…éƒ¨ã§ ISPACK ã® LJPACK(SVPACK) ã® Fortran77 ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã‚’å‘¼ã‚“ã§ã„ã‚‹.
!  ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ãŠã‚ˆã³æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã®æ ¼ç´æ–¹æ³•ã‚„å¤‰æ›ã®è©³ã—ã„è¨ˆç®—æ³•ã«
!  ã¤ã„ã¦ã¯ ISPACK/SVPACK ã®ãƒžãƒ‹ãƒ¥ã‚¢ãƒ«ã‚’å‚ç…§ã•ã‚ŒãŸã„.
!
!  ã“ã®ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã‚’ä½¿ã†ãŸã‚ã«ã¯å‰ã‚‚ã£ã¦ w_base_initial ã‚’å‘¼ã‚“ã§
!  åˆ‡æ–æ³¢æ•°, æ ¼åç‚¹æ•°ã®è¨å®šã‚’ã—ã¦ãŠãå¿…è¦ãŒã‚ã‚‹.
!
!
!å±¥æ´
!      2017/03/09  ç«¹åºƒçœŸä¸€  w_wave_deriv_module_sjpack ã‚ˆã‚Šæ”¹é€
!
!      åˆ¶é™
!         ãƒ»å¤‰æ›ã™ã‚‹æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿, ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®é…åˆ—ã®å¤§ãã•ã¯æ±ºã‚ã†ã¡
!
!++
module w_wave_deriv_module_svpack
  !
  != w_wave_deriv_module_svpack
  !
  ! Authors:: Shin-ichi Takehiro, Youhei SASAKI
  ! Version:: $Id: w_deriv_module_svpack.f90 586 2013-05-23 17:42:12Z uwabami $
  ! Copyright&License:: See COPYRIGHT[link:../COPYRIGHT]
  !
  !== æ¦‚è¦
  !
  !  spml/w_wave_deriv_module_svpack ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã¯çƒé¢ä¸Šã§ã® 2 æ¬¡å…ƒ
  !  æµä½“é‹å‹•ã‚’çƒé¢èª¿å’Œå‡½æ•°ã‚’ç”¨ã„ãŸã‚¹ãƒšã‚¯ãƒˆãƒ«æ³•ã«ã‚ˆã£ã¦æ•°å€¤è¨ˆç®—ã™ã‚‹
  !  ãŸã‚ã® ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ« w_module_svpack ã®ä¸‹éƒ¨ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã§ã‚ã‚Š,
  !  ã‚¹ãƒšã‚¯ãƒˆãƒ«æ³•ã®å¾®åˆ†è¨ˆç®—ã®ãŸã‚ã® Fortran90 é–¢æ•°ã‚’æä¾›ã™ã‚‹.
  !
  !  å†…éƒ¨ã§ ISPACK ã® LJPACK(SVPACK) ã® Fortran77 ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã‚’å‘¼ã‚“ã§ã„ã‚‹.
  !  ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ãŠã‚ˆã³æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã®æ ¼ç´æ–¹æ³•ã‚„å¤‰æ›ã®è©³ã—ã„è¨ˆç®—æ³•ã«
  !  ã¤ã„ã¦ã¯ ISPACK/SVPACK ã®ãƒžãƒ‹ãƒ¥ã‚¢ãƒ«ã‚’å‚ç…§ã•ã‚ŒãŸã„.
  !
  !  ã“ã®ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã‚’ä½¿ã†ãŸã‚ã«ã¯å‰ã‚‚ã£ã¦ w_base_initial ã‚’å‘¼ã‚“ã§
  !  åˆ‡æ–æ³¢æ•°, æ ¼åç‚¹æ•°ã®è¨å®šã‚’ã—ã¦ãŠãå¿…è¦ãŒã‚ã‚‹.
  !
  use dc_message, only : MessageNotify
  use w_wave_base_module_svpack, only : im, jm, nm=>nn, mm, m, r, &
                                        w_base_Initial, xy_w, w_xy, w_DLon_w
  implicit none

  real(8), allocatable  :: D(:)
  ! ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³æ¼”ç®—ç”¨é…åˆ—
  !
  ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³ã‚’è¨ˆç®—ã™ã‚‹ãŸã‚ã®ä¿‚æ•°
  ! é…åˆ—ã®ã‚µã‚¤ã‚ºã¯(2*(nm-m+1))
  !

  real(8), allocatable  :: rn(:,:)
  ! ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³æ¼”ç®—ç”¨é…åˆ—(w_module ã¨äº’æ›æ€§ã‚’ä¿ã¤ãŸã‚)
  !
  ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³ã‚’è¨ˆç®—ã™ã‚‹ãŸã‚ã®ä¿‚æ•°
  ! é…åˆ—ã®ã‚µã‚¤ã‚ºã¯(2*(nm-m+1), 2)
  !
  ! r(L,1) ã«ã¯ L ç•ªç›®ã®æ ¼ç´ä½ç½®ã®ã‚¹ãƒšã‚¯ãƒˆãƒ«ã«å¯¾ã™ã‚‹ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³è¨ˆç®—ã®
  ! ä¿‚æ•° -n(n+1) ã®å€¤ãŒæ ¼ç´ã•ã‚Œã¦ã„ã‚‹.
  !

  logical               :: w_wave_deriv_initialize=.false.   ! åˆæœŸåŒ–ãƒ•ãƒ©ãƒƒã‚°

  private

  public w_deriv_Initial                      ! åˆæœŸåŒ–
  public w_deriv_Finalize                     ! çµ‚äº†å‡¦ç†

  public w_Lapla_w, w_LaplaInv_w              ! ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³ã¨é€†æ¼”ç®—
  public xy_GradLon_w, xy_GradLat_w           ! å‹¾é…åž‹å¾®åˆ†
  public w_DivLon_xy, w_DivLat_xy             ! ç™ºæ•£åž‹å¾®åˆ†
  public w_Div_xy_xy                          ! ç™ºæ•£åž‹å¾®åˆ†
!!$  public w_Jacobian_w_w                       ! ãƒ¤ã‚³ãƒ“ã‚¢ãƒ³
  public xy_GradLambda_w, xy_GradMu_w         ! å‹¾é…åž‹å¾®åˆ†(Î»,Î¼åº§æ¨™)
  public w_DivLambda_xy, w_DivMu_xy           ! ç™ºæ•£åž‹å¾®åˆ†(Î»,Î¼åº§æ¨™)
  public rn                                   ! ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³æ¼”ç®—ç”¨é…åˆ—

  save D, rn

  contains

  !--------------- åˆæœŸåŒ– -----------------
    subroutine w_deriv_initial
      !
      ! ã‚¹ãƒšã‚¯ãƒˆãƒ«å¾®åˆ†è¨ˆç®—ã«å¿…è¦ã¨ãªã‚‹ä½œæ¥é ˜åŸŸã‚’è¨å®šã™ã‚‹.
      !
      ! ä»–ã®é–¢æ•°ã‚’å‘¼ã¶å‰ã«, æœ€åˆã«ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã‚’å‘¼ã‚“ã§
      ! åˆæœŸè¨å®šã‚’ã—ãªã‘ã‚Œã°ãªã‚‰ãªã„.
      !
      ! ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã‚’å˜ç‹¬ã§ç”¨ã„ã‚‹ã®ã§ãªã,
      ! ä¸Šä½ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ w_Initial ã‚’ä½¿ç”¨ã™ã‚‹ã“ã¨.
      !
      integer :: n

      w_wave_deriv_initialize=.true.

      allocate(D(2*(nm-m+1)))
      allocate(rn(2*(nm-m+1),2))

      do n=m,nm
         D(2*(n-m+1)-1) = -n*(n+1)
         D(2*(n-m+1))   = -n*(n+1)
         rn(2*(n-m+1)-1,1) = -n*(n+1)
         rn(2*(n-m+1),1)   = -n*(n+1)
         rn(2*(n-m+1)-1,2) = -1/(n*(n+1))
         rn(2*(n-m+1),2)   = -1/(n*(n+1))
      end do

      call MessageNotify('M','w_deriv_initial',&
           'w_wave_deriv_module_svpack (2013/07/02) is initialized')

    end subroutine w_deriv_initial

  !--------------- å¾®åˆ†è¨ˆç®— -----------------
    function w_Lapla_w(w_data)
      !
      ! å…¥åŠ›ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³
      !
      !    â–½^2 = 1/cos^2Ï†ãƒ»âˆ‚^2/âˆ‚Î»^2 + 1/cosÏ†ãƒ»âˆ‚/âˆ‚Ï†(cosÏ†âˆ‚/âˆ‚Ï†)
      !
      ! ã‚’ä½œç”¨ã™ã‚‹(1 å±¤ç”¨).
      !
      ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³ã¨ã¯, å¯¾å¿œã™ã‚‹æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã«
      ! ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³ã‚’ä½œç”¨ã•ã›ãŸãƒ‡ãƒ¼ã‚¿ã®ã‚¹ãƒšã‚¯ãƒˆãƒ«å¤‰æ›ã®ã“ã¨ã§ã‚ã‚‹.
      !
      real(8)              :: w_Lapla_w(2*(nm-m+1))
      !(out) å…¥åŠ›ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³

      real(8), intent(in)  :: w_data(2*(nm-m+1))
      !(in) å…¥åŠ›ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿

      w_Lapla_w = D*w_Data

    end function w_Lapla_w

    function w_LaplaInv_w(w_data)
      !
      ! å…¥åŠ›ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«é€†ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³
      !
      !    â–½^{-2}
      !      =[1/cos^2Ï†ãƒ»âˆ‚^2/âˆ‚Î»^2 + 1/cosÏ†ãƒ»âˆ‚/âˆ‚Ï†(cosÏ†âˆ‚/âˆ‚Ï†)]^{-1}
      !
      ! ã‚’ä½œç”¨ã™ã‚‹(1 å±¤ç”¨).
      !
      ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®é€†ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³ã¨ã¯, å¯¾å¿œã™ã‚‹æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã«
      ! é€†ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³ã‚’ä½œç”¨ã•ã›ãŸãƒ‡ãƒ¼ã‚¿ã®ã‚¹ãƒšã‚¯ãƒˆãƒ«å¤‰æ›ã®ã“ã¨ã§ã‚ã‚‹.
      !
      real(8)              :: w_LaplaInv_w(2*(nm-m+1))
      !(out) ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®é€†ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³

      real(8), intent(in)  :: w_data(2*(nm-m+1))
      !(in) å…¥åŠ›ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿

      w_LaplaInv_w = w_data/D

    end function w_LaplaInv_w

    function xy_GradLon_w(w_data)
      !
      ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å‹¾é…åž‹çµŒåº¦å¾®åˆ† 1/cosÏ†ãƒ»âˆ‚/âˆ‚Î» ã‚’
      ! ä½œç”¨ã•ã›ãŸæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã‚’è¿”ã™(1 å±¤ç”¨).
      !
      real(8)              :: xy_GradLon_w(0:im-1,1:jm)
      !(out) ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã‚’å‹¾é…åž‹çµŒåº¦å¾®åˆ†ã—ãŸæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿

      real(8), intent(in)  :: w_data(2*(nm-m+1))
      !(in) å…¥åŠ›ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿

      xy_GradLon_w = xy_w(w_data,ipow=1,iflag=-1)

    end function xy_GradLon_w

    function xy_GradLat_w(w_data)
      !
      ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å‹¾é…åž‹ç·¯åº¦å¾®åˆ† âˆ‚/âˆ‚Ï† ã‚’ä½œç”¨ã•ã›ã¦
      ! æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã«å¤‰æ›ã—ã¦è¿”ã™(1 å±¤ç”¨).
      !
      real(8)              :: xy_GradLat_w(0:im-1,1:jm)
      !(out) ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã‚’å‹¾é…åž‹ç·¯åº¦å¾®åˆ†ã—ãŸæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿

      real(8), intent(in)  :: w_data(2*(nm-m+1))
      !(in) å…¥åŠ›ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿

      xy_GradLat_w = xy_w(w_data,ipow=1,iflag=1)

    end function xy_GradLat_w

    function w_DivLon_xy(xy_data)
      !
      ! æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£åž‹çµŒåº¦å¾®åˆ† 1/cosÏ†ãƒ»âˆ‚/âˆ‚Î» ã‚’ä½œç”¨ã•ã›ã¦
      ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å¤‰æ›ã—ã¦è¿”ã™(1 å±¤ç”¨).
      !
      real(8)              :: w_DivLon_xy(2*(nm-m+1))
      !(out) æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã‚’ç™ºæ•£åž‹çµŒåº¦å¾®åˆ†ã—ãŸã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿
      real(8), intent(in)  :: xy_data(0:im-1,1:jm)
      !(in) å…¥åŠ›æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿

      w_DivLon_xy = w_xy(xy_data,ipow=1,iflag=-1)

    end function w_DivLon_xy

    function w_DivLat_xy(xy_data)
      !
      ! æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£åž‹ç·¯åº¦å¾®åˆ† 1/cosÏ†ãƒ»âˆ‚(f cosÏ†)/âˆ‚Ï† ã‚’ä½œç”¨ã•ã›ã¦
      ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å¤‰æ›ã—ã¦è¿”ã™(1 å±¤ç”¨).
      !
      real(8)              :: w_DivLat_xy(2*(nm-m+1))
      !(out) æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã‚’ç™ºæ•£åž‹ç·¯åº¦å¾®åˆ†ã—ãŸã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿

      real(8), intent(in)  :: xy_data(0:im-1,1:jm)
      !(in) å…¥åŠ›æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿

      w_DivLat_xy = w_xy(xy_data,ipow=1,iflag=1)

    end function w_DivLat_xy

    function w_Div_xy_xy(xy_u,xy_v)
      !
      ! 2 ã¤ã®å…¥åŠ›æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã‚’ãƒ™ã‚¯ãƒˆãƒ«æˆåˆ†ã¨ã™ã‚‹ç™ºæ•£ã‚’è¨ˆç®—ã—,
      ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã¨ã—ã¦è¿”ã™(1 å±¤ç”¨).
      !
      real(8)              :: w_Div_xy_xy(2*(nm-m+1))
      !(out) 2 ã¤ã®å…¥åŠ›æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã‚’ãƒ™ã‚¯ãƒˆãƒ«æˆåˆ†ã¨ã™ã‚‹ç™ºæ•£ã®ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿

      real(8), intent(in)  :: xy_u(0:im-1,1:jm)
      !(in) ãƒ™ã‚¯ãƒˆãƒ«çµŒåº¦æˆåˆ†ã®æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿

      real(8), intent(in)  :: xy_v(0:im-1,1:jm)
      !(in) ãƒ™ã‚¯ãƒˆãƒ«ç·¯åº¦æˆåˆ†ã®æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿

      w_Div_xy_xy = w_Divlon_xy(xy_u) + w_Divlat_xy(xy_v)

    end function w_Div_xy_xy

!!$    function w_Jacobian_w_w(w_a,w_b)
!!$      ! 2 ã¤ã®ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«ãƒ¤ã‚³ãƒ“ã‚¢ãƒ³
!!$      !
!!$      !   J(f,g) = âˆ‚f/âˆ‚Î»ãƒ»âˆ‚g/âˆ‚Î¼ - âˆ‚g/âˆ‚Î»ãƒ»âˆ‚f/âˆ‚Î¼
!!$      !          = âˆ‚f/âˆ‚Î»ãƒ»1/cosÏ†ãƒ»âˆ‚g/âˆ‚Ï†
!!$      !             - âˆ‚g/âˆ‚Î»ãƒ»1/cosÏ†ãƒ»âˆ‚f/âˆ‚Ï†
!!$      !
!!$      ! ã‚’ä½œç”¨ã•ã›ã‚‹(1 å±¤ç”¨).
!!$
!!$      real(8)             :: w_Jacobian_w_w(2*(nm-m+1))
!!$      !(out) 2 ã¤ã®ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®ãƒ¤ã‚³ãƒ“ã‚¢ãƒ³
!!$
!!$      real(8), intent(in) :: w_a(2*(nm-m+1))
!!$      !(in) 1ã¤ç›®ã®å…¥åŠ›ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿
!!$
!!$      real(8), intent(in) :: w_b(2*(nm-m+1))
!!$      !(in) 2ã¤ç›®ã®å…¥åŠ›ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿
!!$
!!$      w_Jacobian_w_w = w_xy( &
!!$                  xy_w(w_DLon_w(w_a))*xy_w(w_b,ipow=2,iflag=1) &
!!$                - xy_w(w_DLon_w(w_b))*xy_w(w_a,ipow=2,iflag=1) )
!!$
!!$    end function w_Jacobian_w_w

  !--------------- å¾®åˆ†è¨ˆç®— (Î»,Î¼åº§æ¨™ç³»ç”¨) -----------------
    function xy_GradLambda_w(w_data)
      !
      ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å‹¾é…åž‹çµŒåº¦å¾®åˆ† âˆ‚/âˆ‚Î» ã‚’ä½œç”¨ã™ã‚‹(1 å±¤ç”¨).
      !
      real(8)              :: xy_GradLambda_w(0:im-1,1:jm)
      !(out) ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã‚’å‹¾é…åž‹çµŒåº¦å¾®åˆ†ã—ãŸæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿

      real(8), intent(in)  :: w_data(2*(nm-m+1))
      !(in) å…¥åŠ›ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿

      xy_GradLambda_w = xy_w(w_data,ipow=0,iflag=-1)

    end function xy_GradLambda_w

    function xy_GradMu_w(w_data)
      !
      ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å‹¾é…åž‹ç·¯åº¦å¾®åˆ† (1-Î¼^2)âˆ‚/âˆ‚Î¼  (Î¼=sinÏ†)
      ! ã‚’ä½œç”¨ã•ã›ã¦æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã«å¤‰æ›ã—ã¦è¿”ã™(1 å±¤ç”¨).
      !
      real(8)              :: xy_GradMu_w(0:im-1,1:jm)
      !(out) ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã‚’å‹¾é…åž‹ç·¯åº¦å¾®åˆ†ã—ãŸæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿

      real(8), intent(in)  :: w_data(2*(nm-m+1))
      !(in) å…¥åŠ›ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿

      xy_GradMu_w = xy_w(w_data,ipow=0,iflag=1)

    end function xy_GradMu_w

    function w_DivLambda_xy(xy_data)
      !
      ! æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£åž‹çµŒåº¦å¾®åˆ† 1/(1-Î¼^2)ãƒ»âˆ‚/âˆ‚Î» (Î¼=sinÏ†)
      ! ã‚’ä½œç”¨ã•ã›ã¦ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å¤‰æ›ã—ã¦è¿”ã™(1 å±¤ç”¨).
      !
      real(8)              :: w_DivLambda_xy(2*(nm-m+1))
      !(out) æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã‚’ç™ºæ•£åž‹çµŒåº¦å¾®åˆ†ã—ãŸã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿

      real(8), intent(in)  :: xy_data(0:im-1,1:jm)
      !(in) å…¥åŠ›æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿

      w_DivLambda_xy = w_xy(xy_data,ipow=2,iflag=-1)

    end function w_DivLambda_xy

    function w_DivMu_xy(xy_data)
      !
      ! æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£åž‹ç·¯åº¦å¾®åˆ† âˆ‚/âˆ‚Î¼ (Î¼=sinÏ†)ã‚’ä½œç”¨ã•ã›ã¦
      ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å¤‰æ›ã—ã¦è¿”ã™(1 å±¤ç”¨).
      !
      real(8)              :: w_DivMu_xy(2*(nm-m+1))
      !(out) æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã‚’ç™ºæ•£åž‹ç·¯åº¦å¾®åˆ†ã—ãŸã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿

      real(8), intent(in)  :: xy_data(0:im-1,1:jm)
      !(in) å…¥åŠ›æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿

      w_DivMu_xy = w_xy(xy_data,ipow=2,iflag=1)

    end function w_DivMu_xy

  !--------------- çµ‚äº†å‡¦ç† -----------------
    subroutine w_deriv_finalize
      !
      ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®çµ‚äº†å‡¦ç†(å‰²ã‚Šä»˜ã‘é…åˆ—ã®è§£æ”¾)ã‚’ãŠã“ãªã†.
      !
      ! ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã‚’å˜ç‹¬ã§ç”¨ã„ã‚‹ã®ã§ãªã,
      ! ä¸Šä½ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ w_Finalize ã‚’ä½¿ç”¨ã™ã‚‹ã“ã¨.
      !
      if ( .not. w_wave_deriv_initialize ) then
         call MessageNotify('W','w_deriv_Finalize',&
              'w_wave_deriv_module_svpack not initialized yet')
         return
      endif

      deallocate(D)           ! ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³æ¼”ç®—ç”¨é…åˆ—
      deallocate(rn)          ! ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³æ¼”ç®—ç”¨é…åˆ—

      w_wave_deriv_initialize = .false.

      call MessageNotify('M','w_deriv_Finalize',&
           'w_wave_deriv_module_svpack (2017/03/06) is finalized')

    end subroutine w_deriv_finalize

end module w_wave_deriv_module_svpack