!--
!----------------------------------------------------------------------
!     Copyright (c) 2019 Shin-ichi Takehiro. All rights reserved.
!----------------------------------------------------------------------
!è¡¨é¡Œ  w_mpi_module_sypack
!
!   spml3/w_mpi_module_sypack ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã¯çƒé¢ä¸Šã§ã® 2 æ¬¡å…ƒæµä½“é‹å‹•ã‚’
!   çƒé¢èª¿å’Œå‡½æ•°ã‚’ç”¨ã„ãŸã‚¹ãƒšã‚¯ãƒˆãƒ«æ³•ã¨ MPI ä¸¦åˆ—åŒ–ã«ã‚ˆã£ã¦æ•°å€¤è¨ˆç®—ã™ã‚‹ãŸã‚ã®
!   Fortran90 é–¢æ•°ã‚’æä¾›ã™ã‚‹.
!
!   w_mpi_module_sypack ã¯å®Ÿéš›ã«ã¯åŸºæœ¬å¤‰æ›, å¾®åˆ†è¨ˆç®—, ç©åˆ†ãƒ»å¹³å‡è¨ˆç®—,
!   ã‚¹ãƒšã‚¯ãƒˆãƒ«è§£æžã‚’ãã‚Œãžã‚Œæ‹…ã£ã¦ã„ã‚‹ä¸‹éƒ¨ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ« w_base_mpi_module_sypack,
!   w_deriv_mpi_module_sypack w_integral_mpi_module_sypack ã‹ã‚‰ãªã£ã¦ã„ã‚‹.
!
!   å†…éƒ¨ã§ ISPACK3 ã® SYPACK ã® Fortran77 ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã‚’å‘¼ã‚“ã§ã„ã‚‹.
!   ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ãŠã‚ˆã³æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã®æ ¼ç´æ–¹æ³•ã‚„å¤‰æ›ã®è©³ã—ã„è¨ˆç®—æ³•ã«
!   ã¤ã„ã¦ã¯ ISPACK3/SYPACK ã®ãƒžãƒ‹ãƒ¥ã‚¢ãƒ«ã‚’å‚ç…§ã•ã‚ŒãŸã„.
!
!
!å±¥æ´  2019/03/17  ç«¹åºƒçœŸä¸€
!
!++
module w_mpi_module_sypack
  !
  != w_mpi_module_sypack
  !
  ! Authors:: Shin-ichi Takehiro, Youhei SASAKI
  ! Version:: $Id: w_mpi_module_sypack.f90 651 2015-02-06 20:28:35Z uwabami $
  ! Copyright&License:: See COPYRIGHT[link:../../COPYRIGHT]
  !
  !== æ¦‚è¦
  !
  ! spml3/w_module_sypack ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã¯çƒé¢ä¸Šã§ã® 2 æ¬¡å…ƒæµä½“é‹å‹•ã‚’
  ! çƒé¢èª¿å’Œå‡½æ•°ã‚’ç”¨ã„ãŸã‚¹ãƒšã‚¯ãƒˆãƒ«æ³•ã¨ MPI ã«ã‚ˆã£ã¦æ•°å€¤è¨ˆç®—ã™ã‚‹ãŸã‚ã®
  ! Fortran90 é–¢æ•°ã‚’æä¾›ã™ã‚‹.
  !
  ! w_mpi_module_sypack ã¯å®Ÿéš›ã«ã¯åŸºæœ¬å¤‰æ›, å¾®åˆ†è¨ˆç®—, ç©åˆ†ãƒ»å¹³å‡è¨ˆç®—,
  ! ã‚¹ãƒšã‚¯ãƒˆãƒ«è§£æžã‚’ãã‚Œãžã‚Œæ‹…ã£ã¦ã„ã‚‹ä¸‹éƒ¨ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ« w_base_mpi_module_sypack,
  ! w_deriv_mpi_module_sypack, w_integral_mpi_module_sypack ã‹ã‚‰ãªã£ã¦ã„ã‚‹.
  !
  ! å†…éƒ¨ã§ ISPACK3 ã® SYPACK ã® Fortran77 ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã‚’å‘¼ã‚“ã§ã„ã‚‹.
  ! ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ãŠã‚ˆã³æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã®æ ¼ç´æ–¹æ³•ã‚„å¤‰æ›ã®è©³ã—ã„è¨ˆç®—æ³•ã«
  ! ã¤ã„ã¦ã¯ ISPACK3/SYPACK ã®ãƒžãƒ‹ãƒ¥ã‚¢ãƒ«ã‚’å‚ç…§ã•ã‚ŒãŸã„.
  !
  !
  !== é–¢æ•°ãƒ»å¤‰æ•°ã®åå‰ã¨åž‹ã«ã¤ã„ã¦
  !
  !=== å‘½åæ³•
  !
  ! * é–¢æ•°åã®å…ˆé  (w_, nm_, n_, xy_, xv_, x_, y_, v_) ã¯,
  !   è¿”ã™å€¤ã®å½¢ã‚’ç¤ºã—ã¦ã„ã‚‹.
  !     w_ :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿
  !    xy_ :: 2 æ¬¡å…ƒæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿
  !    xv_ :: 2 æ¬¡å…ƒåˆ†æ•£æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿
  !    nm_ :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®ä¸¦ã‚“ã  3 æ¬¡å…ƒé…åˆ—(ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®ä¸¦ã³ã¯
  !           å…¨æ³¢æ•° n, å¸¯çŠ¶æ³¢æ•° m ã§æŒ‡å®šã•ã‚Œã‚‹ 2 æ¬¡å…ƒé…åˆ—)
  !     n_ :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®ä¸¦ã‚“ã  2 æ¬¡å…ƒé…åˆ— (ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®ä¸¦ã³ã¯
  !           å…¨æ³¢æ•° n ã§æŒ‡å®šã•ã‚Œã‚‹ 1 æ¬¡å…ƒé…åˆ—)
  !     x_ :: çµŒåº¦æ–¹å‘ 1 æ¬¡å…ƒæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿
  !     y_ :: ç·¯åº¦æ–¹å‘ 1 æ¬¡å…ƒæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿
  !     v_ :: ç·¯åº¦æ–¹å‘ 1 æ¬¡å…ƒåˆ†æ•£æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿
  !
  ! * é–¢æ•°åã®é–“ã®æ–‡å—åˆ—(DLon, GradLat, GradLat, DivLon, DivLat, Lapla,
  !   LaplaInv, Jacobian)ã¯, ãã®é–¢æ•°ã®ä½œç”¨ã‚’è¡¨ã—ã¦ã„ã‚‹.
  !
  ! * é–¢æ•°åã®æœ€å¾Œ (_w_w, _w, _xy, _x, _y) ã¯, å…¥åŠ›å¤‰æ•°ã®å½¢ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿
  !   ãŠã‚ˆã³æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã§ã‚ã‚‹ã“ã¨ã‚’ç¤ºã—ã¦ã„ã‚‹.
  !     _w :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿
  !   _w_w :: 2 ã¤ã®ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿
  !    _xy :: 2 æ¬¡å…ƒæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿
  !    _xv :: 2 æ¬¡å…ƒåˆ†æ•£æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿
  !     _x :: çµŒåº¦æ–¹å‘ 1 æ¬¡å…ƒæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿
  !     _y :: ç·¯åº¦æ–¹å‘ 1 æ¬¡å…ƒæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿
  !     _v :: ç·¯åº¦æ–¹å‘ 1 æ¬¡å…ƒåˆ†æ•£æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿
  !
  !=== å„ãƒ‡ãƒ¼ã‚¿ã®ç¨®é¡žã®èª¬æ˜Ž
  !
  ! * xy : 2 æ¬¡å…ƒæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿.
  !   * å¤‰æ•°ã®ç¨®é¡žã¨æ¬¡å…ƒã¯ real(8), dimension(im,jm).
  !   * im, jm ã¯ãã‚Œãžã‚ŒçµŒåº¦, ç·¯åº¦åº§æ¨™ã®æ ¼åç‚¹æ•°ã§ã‚ã‚Š, ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³
  !     w_mpi_Initial ã«ã¦ã‚ã‚‰ã‹ã˜ã‚è¨å®šã—ã¦ãŠã.
  !
  ! * xv : 2 æ¬¡å…ƒåˆ†æ•£æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿.
  !   * å¤‰æ•°ã®ç¨®é¡žã¨æ¬¡å…ƒã¯ real(8), dimension(im,jc).
  !   * im, jc ã¯ãã‚Œãžã‚ŒçµŒåº¦ã®æ ¼åç‚¹æ•°ãŠã‚ˆã³
  !     ãƒ—ãƒã‚»ã‚¹ã§ä¿æœ‰ã™ã‚‹ç·¯åº¦æ–¹å‘ã®æ ¼åç‚¹æ•°ã§ã‚ã‚‹.
  !     jc ã¯ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ w_mpi_Initial ã«ã¦è¨å®šã—ã¦
  !     ãŠãã“ã¨ã«ã‚ˆã‚Šè¨å®šã•ã‚Œã‚‹ public å¤‰æ•°ã§ã‚ã‚‹.
  !
  ! * w : ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿.
  !   * å¤‰æ•°ã®ç¨®é¡žã¨æ¬¡å…ƒã¯ real(8), dimension((nm+1)*(nm+1)).
  !     nm ã¯çƒé¢èª¿å’Œå‡½æ•°ã®æœ€å¤§å…¨æ³¢æ•°ã§ã‚ã‚Š, ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ w_Initial ã«ã¦
  !     ã‚ã‚‰ã‹ã˜ã‚è¨å®šã—ã¦ãŠã.
  !   * ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®æ ¼ç´ã®ã•ã‚Œæ–¹ã¯
  !     é–¢æ•° l_nm, nm_l ã«ã‚ˆã£ã¦èª¿ã¹ã‚‹ã“ã¨ãŒã§ãã‚‹.
  !
  ! * nm : ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®ä¸¦ã‚“ã  2 æ¬¡å…ƒé…åˆ—.
  !   * å¤‰æ•°ã®ç¨®é¡žã¨æ¬¡å…ƒã¯ real(8), dimension(0:nm,-nm:nm).
  !     ç¬¬ 1 æ¬¡å…ƒãŒæ°´å¹³å…¨æ³¢æ•°,  ç¬¬ 2 æ¬¡å…ƒãŒå¸¯çŠ¶æ³¢æ•°ã‚’è¡¨ã™.
  !   * nm ã¯çƒé¢èª¿å’Œå‡½æ•°ã®æœ€å¤§å…¨æ³¢æ•°ã§ã‚ã‚Š, ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ w_Initial ã«ã¦
  !     ã‚ã‚‰ã‹ã˜ã‚è¨å®šã—ã¦ãŠã.
  !
  ! * n : ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®ä¸¦ã‚“ã  1 æ¬¡å…ƒé…åˆ—.
  !   * å¤‰æ•°ã®ç¨®é¡žã¨æ¬¡å…ƒã¯ real(8), dimension(0:nm).
  !   * ç¬¬ 1 æ¬¡å…ƒãŒæ°´å¹³å…¨æ³¢æ•°ã‚’è¡¨ã™. nm ã¯çƒé¢èª¿å’Œå‡½æ•°ã®æœ€å¤§å…¨æ³¢æ•°ã§ã‚ã‚Š,
  !     ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ w_Initial ã«ã¦ã‚ã‚‰ã‹ã˜ã‚è¨å®šã—ã¦ãŠã.
  !
  ! * x, y : çµŒåº¦, ç·¯åº¦æ–¹å‘ 1 æ¬¡å…ƒæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿.
  !   * å¤‰æ•°ã®ç¨®é¡žã¨æ¬¡å…ƒã¯ãã‚Œãžã‚Œ real(8), dimension(im)
  !     ãŠã‚ˆã³ real(8), dimension(jm).
  !
  ! * w_ ã§å§‹ã¾ã‚‹é–¢æ•°ãŒè¿”ã™å€¤ã¯ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«åŒã˜.
  !
  ! * xy_ ã§å§‹ã¾ã‚‹é–¢æ•°ãŒè¿”ã™å€¤ã¯ 2 æ¬¡å…ƒæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã«åŒã˜.
  !
  ! * xv_ ã§å§‹ã¾ã‚‹é–¢æ•°ãŒè¿”ã™å€¤ã¯ 2 æ¬¡å…ƒåˆ†æ•£æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã«åŒã˜.
  !
  ! * x_, y_, v_ ã§å§‹ã¾ã‚‹é–¢æ•°ãŒè¿”ã™å€¤ã¯ 1 æ¬¡å…ƒæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã«åŒã˜.
  !
  ! * ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å¯¾ã™ã‚‹å¾®åˆ†ç‰ã®ä½œç”¨ã¨ã¯, å¯¾å¿œã™ã‚‹æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã«
  !   å¾®åˆ†ãªã©ã‚’ä½œç”¨ã•ã›ãŸãƒ‡ãƒ¼ã‚¿ã‚’ã‚¹ãƒšã‚¯ãƒˆãƒ«å¤‰æ›ã—ãŸã‚‚ã®ã“ã¨ã§ã‚ã‚‹.
  !
  !
  !== å¤‰æ•°ãƒ»æ‰‹ç¶šãç¾¤ã®è¦ç´„
  !
  !==== åˆæœŸåŒ–
  !
  ! w_mpi_Initial :: ã‚¹ãƒšã‚¯ãƒˆãƒ«å¤‰æ›ã®æ ¼åç‚¹æ•°, æ³¢æ•°, é ˜åŸŸã®å¤§ãã•ã®è¨å®š
  !
  !==== çµ‚äº†å‡¦ç†
  !
  ! w_mpi_Finalize :: ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®çµ‚äº†å‡¦ç†(å‰²ã‚Šä»˜ã‘é…åˆ—ã®è§£æ”¾)ã‚’ãŠã“ãªã†.
  !
  !==== åº§æ¨™å¤‰æ•°
  !
  ! x_Lon, x_Lon_Weight,  ::  æ ¼åç‚¹åº§æ¨™(çµŒåº¦)ã¨é‡ã¿ã‚’æ ¼ç´ã—ãŸ 1 æ¬¡å…ƒé…åˆ—
  ! y_Lat, y_Lat_Weight   ::  æ ¼åç‚¹åº§æ¨™(ç·¯åº¦)ã¨é‡ã¿ã‚’æ ¼ç´ã—ãŸ 1 æ¬¡å…ƒé…åˆ—
  ! v_Lat, v_Lat_Weight   ::  åˆ†æ•£æ ¼åç‚¹åº§æ¨™(ç·¯åº¦)ã¨é‡ã¿ã‚’æ ¼ç´ã—ãŸ 1 æ¬¡å…ƒé…åˆ—
  ! xy_Lon, xy_Lat        ::  æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã®çµŒåº¦ãƒ»ç·¯åº¦åº§æ¨™(X,Y)
  !                           (æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿åž‹ 2 æ¬¡å…ƒé…åˆ—)
  ! xv_Lon, xv_Lat        ::  åˆ†æ•£æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã®çµŒåº¦ãƒ»ç·¯åº¦åº§æ¨™(X,Y)
  !                           (æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿åž‹ 2 æ¬¡å…ƒé…åˆ—)
  !
  !==== åŸºæœ¬å¤‰æ›
  !
  ! xy_w :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰æ ¼åãƒ‡ãƒ¼ã‚¿ã¸ã®å¤‰æ›
  ! w_xy :: æ ¼åãƒ‡ãƒ¼ã‚¿ã‹ã‚‰ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã¸ã®å¤‰æ›
  ! xv_w :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰åˆ†æ•£æ ¼åãƒ‡ãƒ¼ã‚¿ã¸ã®å¤‰æ›
  ! w_xv :: åˆ†æ•£æ ¼åãƒ‡ãƒ¼ã‚¿ã‹ã‚‰ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã¸ã®å¤‰æ›
  ! l_nm, nm_l :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®æ ¼ç´ä½ç½®ã¨å…¨æ³¢æ•°ãƒ»å¸¯çŠ¶æ³¢æ•°ã®å¤‰æ›
  ! w_StreamPotential2Vector :: æµç·šãƒãƒ†ãƒ³ã‚·ãƒ£ãƒ«ã‹ã‚‰é€Ÿåº¦å ´è¨ˆç®—
  ! w_Vector2VorDiv   :: é€Ÿåº¦å ´ã‹ã‚‰æ¸¦åº¦ç™ºæ•£ã‚’è¨ˆç®—
  ! w_VectorCosLat2VorDiv   :: é€Ÿåº¦å ´ã‹ã‚‰æ¸¦åº¦ç™ºæ•£ã‚’è¨ˆç®—
  ! w_StreamPotential2VectorMPI :: æµç·šãƒãƒ†ãƒ³ã‚·ãƒ£ãƒ«ã‹ã‚‰é€Ÿåº¦å ´è¨ˆç®—
  ! w_Vector2VorDivMPI   :: é€Ÿåº¦å ´ã‹ã‚‰æ¸¦åº¦ç™ºæ•£ã‚’è¨ˆç®—
  ! w_VectorCosLat2VorDivMPI   :: é€Ÿåº¦å ´ã‹ã‚‰æ¸¦åº¦ç™ºæ•£ã‚’è¨ˆç®—
  !
  !==== å¾®åˆ†
  !
  ! w_Lapla_w       :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³ã‚’ä½œç”¨ã•ã›ã‚‹
  ! rn              :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã®ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³ã‚’è¨ˆç®—ã™ã‚‹ãŸã‚ã®ä¿‚æ•°.
  ! irm             :: çµŒåº¦å¾®åˆ†æ¼”ç®—ç”¨é…åˆ—
  ! w_LaplaInv_w    :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³ã®é€†å¤‰æ›ã‚’ä½œç”¨ã•ã›ã‚‹
  ! w_DLon_w        :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«çµŒåº¦å¾®åˆ†âˆ‚/âˆ‚Î»ã‚’ä½œç”¨ã•ã›ã‚‹
  ! xy_GradLon_w    :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å‹¾é…åž‹çµŒåº¦å¾®åˆ†
  !                    1/cosÏ†ãƒ»âˆ‚/âˆ‚Î»ã‚’ä½œç”¨ã•ã›ã‚‹
  ! xy_GradLat_w    :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å‹¾é…åž‹ç·¯åº¦å¾®åˆ†âˆ‚/âˆ‚Ï†ã‚’ä½œç”¨ã•ã›ã‚‹
  ! w_DivLon_xy     :: æ ¼åãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£åž‹çµŒåº¦å¾®åˆ†
  !                    1/cosÏ†ãƒ»âˆ‚/âˆ‚Î»ã‚’ä½œç”¨ã•ã›ã‚‹
  ! w_DivLat_xy     :: æ ¼åãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£åž‹ç·¯åº¦å¾®åˆ†
  !                    1/cosÏ†ãƒ»âˆ‚(g cosÏ†)/âˆ‚Ï†ã‚’ä½œç”¨ã•ã›ã‚‹
  ! w_Div_xy_xy     :: ãƒ™ã‚¯ãƒˆãƒ«æˆåˆ†ã§ã‚ã‚‹ 2 ã¤ã®æ ¼åãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£ã‚’ä½œç”¨ã•ã›ã‚‹
  ! w_Jacobian_w_w  :: 2 ã¤ã®ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰ãƒ¤ã‚³ãƒ“ã‚¢ãƒ³ã‚’è¨ˆç®—ã™ã‚‹
  ! xv_GradLon_w    :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å‹¾é…åž‹çµŒåº¦å¾®åˆ†
  !                    1/cosÏ†ãƒ»âˆ‚/âˆ‚Î»ã‚’ä½œç”¨ã•ã›ã‚‹
  ! xv_GradLat_w    :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å‹¾é…åž‹ç·¯åº¦å¾®åˆ†âˆ‚/âˆ‚Ï†ã‚’ä½œç”¨ã•ã›ã‚‹
  ! w_DivLon_xv     :: æ ¼åãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£åž‹çµŒåº¦å¾®åˆ† 1/cosÏ†ãƒ»âˆ‚/âˆ‚Î»ã‚’ä½œç”¨ã•ã›ã‚‹
  ! w_DivLat_xv     :: æ ¼åãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£åž‹ç·¯åº¦å¾®åˆ†
  !                    1/cosÏ†ãƒ»âˆ‚(g cosÏ†)/âˆ‚Ï†ã‚’ä½œç”¨ã•ã›ã‚‹
  ! w_Div_xv_xv     :: ãƒ™ã‚¯ãƒˆãƒ«æˆåˆ†ã§ã‚ã‚‹ 2 ã¤ã®æ ¼åãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£ã‚’ä½œç”¨ã•ã›ã‚‹
  ! w_JacobianMPI_w_w  :: 2 ã¤ã®ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰ãƒ¤ã‚³ãƒ“ã‚¢ãƒ³ã‚’è¨ˆç®—ã™ã‚‹
  !
  !
  !==== å¾®åˆ†(Î»,Î¼=sinÏ† åº§æ¨™)
  !
  ! xy_GradLambda_w :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å‹¾é…åž‹çµŒåº¦å¾®åˆ†âˆ‚/âˆ‚Î»ã‚’ä½œç”¨ã•ã›ã‚‹
  ! xy_GradMw_w     :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å‹¾é…åž‹ç·¯åº¦å¾®åˆ†
  !                    (1-Î¼^2)âˆ‚/âˆ‚Î¼ã‚’ä½œç”¨ã•ã›ã‚‹
  ! w_DivLambda_xy  :: æ ¼åãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£åž‹çµŒåº¦å¾®åˆ†
  !                    1/(1-Î¼^2)ãƒ»âˆ‚/âˆ‚Î»ã‚’ä½œç”¨ã•ã›ã‚‹
  ! w_DivMw_xy      :: æ ¼åãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£åž‹ç·¯åº¦å¾®åˆ†âˆ‚/âˆ‚Î¼ã‚’ä½œç”¨ã•ã›ã‚‹
  !
  ! xv_GradLambda_w :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å‹¾é…åž‹çµŒåº¦å¾®åˆ†âˆ‚/âˆ‚Î»ã‚’ä½œç”¨ã•ã›ã‚‹
  ! xv_GradMw_w     :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã«å‹¾é…åž‹ç·¯åº¦å¾®åˆ†
  !                    (1-Î¼^2)âˆ‚/âˆ‚Î¼ã‚’ä½œç”¨ã•ã›ã‚‹
  ! w_DivLambda_xv  :: æ ¼åãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£åž‹çµŒåº¦å¾®åˆ†
  !                    1/(1-Î¼^2)ãƒ»âˆ‚/âˆ‚Î»ã‚’ä½œç”¨ã•ã›ã‚‹
  ! w_DivMw_xv      :: æ ¼åãƒ‡ãƒ¼ã‚¿ã«ç™ºæ•£åž‹ç·¯åº¦å¾®åˆ†âˆ‚/âˆ‚Î¼ã‚’ä½œç”¨ã•ã›ã‚‹
  !
  !==== è£œé–“
  !
  ! Interpolate_w :: ã‚¹ãƒšã‚¯ãƒˆãƒ«ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰ä»»æ„ã®ç‚¹ã§ã®å€¤ã‚’æ±‚ã‚ã‚‹.
  !
  !==== ç©åˆ†ãƒ»å¹³å‡
  !
  ! IntLonLat_xy, AvrLonLat_xy :: 2 æ¬¡å…ƒæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã®å…¨é ˜åŸŸç©åˆ†ãŠã‚ˆã³å¹³å‡
  ! y_IntLon_xy, y_AvrLon_xy   :: 2 æ¬¡å…ƒæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã®çµŒåº¦æ–¹å‘ç©åˆ†ãŠã‚ˆã³å¹³å‡
  ! IntLon_x, AvrLon_x         :: 1 æ¬¡å…ƒ(X)æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã®çµŒåº¦æ–¹å‘ç©åˆ†ãŠã‚ˆã³å¹³å‡
  ! x_IntLat_xy, x_AvrLat_xy   :: 2 æ¬¡å…ƒæ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã®ç·¯åº¦æ–¹å‘ç©åˆ†ãŠã‚ˆã³å¹³å‡
  ! IntLat_y, AvrLat_y         :: 1 æ¬¡å…ƒ(Y)æ ¼åç‚¹ãƒ‡ãƒ¼ã‚¿ã®ç·¯åº¦æ–¹å‘ç©åˆ†ãŠã‚ˆã³å¹³å‡
  !
  !==== ã‚¹ãƒšã‚¯ãƒˆãƒ«è§£æž
  !
  ! nm_EnergyFromStreamfunc_w  :: æµç·šé–¢æ•°ã‹ã‚‰ã‚¨ãƒãƒ«ã‚®ãƒ¼ã‚¹ãƒšã‚¯ãƒˆãƒ«ã‚’è¨ˆç®—ã™ã‚‹
  !                               (æ°´å¹³å…¨æ³¢æ•° n, å¸¯çŠ¶æ³¢æ•° m ç©ºé–“)
  ! n_EnergyFromStreamfunc_w   :: æµç·šé–¢æ•°ã‹ã‚‰ã‚¨ãƒãƒ«ã‚®ãƒ¼ã‚¹ãƒšã‚¯ãƒˆãƒ«ã‚’è¨ˆç®—ã™ã‚‹
  !                               (æ°´å¹³å…¨æ³¢æ•° n ç©ºé–“)
  ! nm_EnstrophyFromStreamfunc_w  :: æµç·šé–¢æ•°ã‹ã‚‰ã‚¨ãƒ³ã‚¹ãƒˆãƒãƒ•ã‚£ãƒ¼ã‚¹ãƒšã‚¯ãƒˆãƒ«ã‚’
  !                                  è¨ˆç®—ã™ã‚‹ (æ°´å¹³å…¨æ³¢æ•° n, å¸¯çŠ¶æ³¢æ•° m ç©ºé–“)
  ! n_EnstrophyFromStreamfunc_w   :: æµç·šé–¢æ•°ã‹ã‚‰ã‚¨ãƒ³ã‚¹ãƒˆãƒãƒ•ã‚£ãƒ¼ã‚¹ãƒšã‚¯ãƒˆãƒ«ã‚’
  !                                  è¨ˆç®—ã™ã‚‹ (æ°´å¹³å…¨æ³¢æ•° n ç©ºé–“)
  ! w_spectrum_VMiss              ::  æ¬ æå€¤
  !
  !
  use dc_message, only : MessageNotify
  use w_base_mpi_module_sypack, only : jc => jl, nc, &
       x_Lon, x_Lon_Weight, v_Lat, v_Lat_Weight, xv_Lon, xv_Lat, &
       y_Lat, y_lat_Weight, xy_Lon, xy_Lat, &
       w_base_mpi_Initial, w_base_mpi_Finalize, nm_l, l_nm, xv_w, w_xv, &
       w_StreamPotential2VectorMPI,  w_Vector2VorDivMPI, w_VectorCosLat2VorDivMPI,&
       ay_av, av_ay
  use w_deriv_mpi_module_sypack
  use w_integral_mpi_module_sypack
  use w_interpolate_mpi_module_sypack
  use w_spectrum_mpi_module_sypack

  implicit none
  private

  public jc                                   ! ç·¯åº¦æ–¹å‘åˆ†æ•£æ ¼åç‚¹æ•°
  public nc                                   ! ã‚¹ãƒšã‚¯ãƒˆãƒ«åˆ†æ•£æ ¼åç‚¹æ•°

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

  public x_Lon, x_Lon_Weight                  ! çµŒåº¦åˆ†æ•£æ ¼ååº§æ¨™ãƒ»é‡ã¿
  public v_Lat, v_Lat_Weight                  ! çµŒåº¦åˆ†æ•£æ ¼ååº§æ¨™ãƒ»é‡ã¿
  public y_Lat, y_Lat_Weight                  ! çµŒåº¦åˆ†æ•£æ ¼ååº§æ¨™ãƒ»é‡ã¿
  public xv_Lon, xv_Lat                       ! åˆ†æ•£æ ¼ååº§æ¨™(im,jc)
  public xy_Lon, xy_Lat                       ! å…¨æ ¼ååº§æ¨™(im,jm)
  public l_nm, nm_l                           ! æ³¢æ•°æ ¼ç´ä½ç½®
  public xv_w, w_xv                           ! å¤‰æ›é–¢æ•°
  public w_StreamPotential2VectorMPI          ! æµç·šãƒãƒ†ãƒ³ã‚·ãƒ£ãƒ«ã‹ã‚‰é€Ÿåº¦å ´è¨ˆç®—
  public w_Vector2VorDivMPI                   ! é€Ÿåº¦å ´ã‹ã‚‰æ¸¦åº¦ç™ºæ•£ã‚’è¨ˆç®—
  public w_VectorCosLat2VorDivMPI             ! é€Ÿåº¦å ´ã‹ã‚‰æ¸¦åº¦ç™ºæ•£ã‚’è¨ˆç®—
  public ay_av, av_ay                         ! åˆ†æ•£ãƒ‡ãƒ¼ã‚¿/å…¨ãƒ‡ãƒ¼ã‚¿å¤‰æ›

  public rn                                   ! ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³æ¼”ç®—ç”¨é…åˆ—
  public w_Lapla_w, w_LaplaInv_w              ! ãƒ©ãƒ—ãƒ©ã‚·ã‚¢ãƒ³ã¨é€†æ¼”ç®—
  public w_DLon_w                             ! çµŒåº¦å¾®åˆ†
  public xv_GradLon_w, xv_GradLat_w           ! å‹¾é…åž‹å¾®åˆ†
  public w_DivLon_xv, w_DivLat_xv             ! ç™ºæ•£åž‹å¾®åˆ†
  public w_Div_xv_xv                          ! ç™ºæ•£åž‹å¾®åˆ†
  public w_JacobianMPI_w_w                    ! ãƒ¤ã‚³ãƒ“ã‚¢ãƒ³
  public xv_GradLambda_w, xv_GradMu_w         ! å‹¾é…åž‹å¾®åˆ†(Î»,Î¼åº§æ¨™)
  public w_DivLambda_xv, w_DivMu_xv           ! ç™ºæ•£åž‹å¾®åˆ†(Î»,Î¼åº§æ¨™)

  public IntLonLat_xv                         ! ç·¯åº¦çµŒåº¦ç©åˆ†
  public v_IntLon_xv, IntLon_x                ! çµŒåº¦ç©åˆ†
  public x_IntLat_xv, IntLat_v                ! ç·¯åº¦ç©åˆ†
  public AvrLonLat_xv                         ! ç·¯åº¦çµŒåº¦å¹³å‡
  public v_AvrLon_xv, AvrLon_x                ! çµŒåº¦å¹³å‡
  public x_AvrLat_xv, AvrLat_v                ! ç·¯åº¦å¹³å‡

  public Interpolate_w                        ! è£œé–“é–¢æ•°

  public nm_EnergyFromStreamfunc_w            ! ã‚¨ãƒãƒ«ã‚®ãƒ¼ã‚¹ãƒšã‚¯ãƒˆãƒ«
                                              ! (æ°´å¹³å…¨æ³¢æ•° n, å¸¯çŠ¶æ³¢æ•° m ç©ºé–“)
  public n_EnergyFromStreamfunc_w             ! ã‚¨ãƒãƒ«ã‚®ãƒ¼ã‚¹ãƒšã‚¯ãƒˆãƒ«
                                              ! (æ°´å¹³å…¨æ³¢æ•° n ç©ºé–“)
  public nm_EnstrophyFromStreamfunc_w         ! ã‚¨ãƒ³ã‚¹ãƒˆãƒãƒ•ã‚£ãƒ¼ã‚¹ãƒšã‚¯ãƒˆãƒ«
                                              ! (æ°´å¹³å…¨æ³¢æ•° n, å¸¯çŠ¶æ³¢æ•° m ç©ºé–“)
  public n_EnstrophyFromStreamfunc_w          ! ã‚¨ãƒ³ã‚¹ãƒˆãƒãƒ•ã‚£ãƒ¼ã‚¹ãƒšã‚¯ãƒˆãƒ«
                                              ! (æ°´å¹³å…¨æ³¢æ•° n ç©ºé–“)
  public w_spectrum_VMiss                     ! æ¬ æå€¤

contains

    subroutine w_mpi_initial(n_in,i_in,j_in,np_in)
      !
      ! ã‚¹ãƒšã‚¯ãƒˆãƒ«å¤‰æ›ã®æ ¼åç‚¹æ•°, æ³¢æ•°ãŠã‚ˆã³ OPENMP ä½¿ç”¨æ™‚ã®
      ! æœ€å¤§ã‚¹ãƒ¬ãƒƒãƒ‰æ•°ã‚’è¨å®šã™ã‚‹.
      !
      ! ä»–ã®é–¢æ•°ã‚’å‘¼ã¶å‰ã«, æœ€åˆã«ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã‚’å‘¼ã‚“ã§åˆæœŸè¨å®šã‚’
      ! ã—ãªã‘ã‚Œã°ãªã‚‰ãªã„.
      !
      ! np_in ã« 1 ã‚ˆã‚Šå¤§ããªå€¤ã‚’æŒ‡å®šã™ã‚Œã° ISPACK ã®çƒé¢èª¿å’Œå‡½æ•°å¤‰æ›
      ! OPENMP ä¸¦åˆ—è¨ˆç®—ãƒ«ãƒ¼ãƒãƒ³ãŒç”¨ã„ã‚‰ã‚Œã‚‹. ä¸¦åˆ—è¨ˆç®—ã‚’å®Ÿè¡Œã™ã‚‹ã«ã¯,
      ! å®Ÿè¡Œæ™‚ã«ç’°å¢ƒå¤‰æ•° OMP_NUM_THREADS ã‚’ np_in ä»¥ä¸‹ã®æ•°å—ã«è¨å®šã™ã‚‹ç‰ã®
      ! ã‚·ã‚¹ãƒ†ãƒ ã«å¿œã˜ãŸæº–å‚™ãŒå¿…è¦ã¨ãªã‚‹.
      !
      ! np_in ã« 1 ã‚ˆã‚Šå¤§ããªå€¤ã‚’æŒ‡å®šã—ãªã‘ã‚Œã°ä¸¦åˆ—è¨ˆç®—ãƒ«ãƒ¼ãƒãƒ³ã¯å‘¼ã°ã‚Œãªã„.
      !
      integer,intent(in) :: i_in              !(in) æ ¼åç‚¹æ•°(æ±è¥¿)
      integer,intent(in) :: j_in              !(in) æ ¼åç‚¹æ•°(å—åŒ—)
      integer,intent(in) :: n_in              !(in) åˆ‡æ–æ³¢æ•°ã®è¨å®š
      integer,intent(in), optional :: np_in   !(in) OPENMP ã§ã®æœ€å¤§ã‚¹ãƒ¬ãƒƒãƒ‰æ•°

      if ( present (np_in) )then
         call MessageNotify('M','w_mpi_base_Initial', &
              'Optional argument "NP_IN" is dummy in w_mpi_module_sypack')
      else
         call w_base_mpi_initial(n_in,i_in,j_in)
      endif

      call w_deriv_mpi_initial

      call MessageNotify('M','w_mpi_initial', &
           'w_mpi_module_sypack (2019/03/17) is initialized')

    end subroutine w_mpi_initial

  !--------------- çµ‚äº†å‡¦ç† -----------------
    subroutine w_mpi_Finalize
      !
      ! ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®çµ‚äº†å‡¦ç†(å‰²ã‚Šä»˜ã‘é…åˆ—ã®è§£æ”¾)ã‚’ãŠã“ãªã†.
      !
      ! è§£åƒåº¦ã‚’å¤‰æ›´ã™ã‚‹éš›ã«ã¯ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã‚’å‘¼ã‚“ã§çµ‚äº†å‡¦ç†ã‚’
      ! ãŠã“ãªã£ãŸã®ã¡ã«å†åº¦ w_mpi_Initial ã§åˆæœŸè¨å®šã—ãªã‘ã‚Œã°
      ! ãªã‚‰ãªã„.
      !
      call w_base_mpi_Finalize
      call w_deriv_mpi_Finalize

      call MessageNotify('M','w_mpi_Finalize',&
           'w_mpi_module_sypack (2019/03/21) is finalized')

    end subroutine w_mpi_Finalize

end module w_mpi_module_sypack