* PACKAGE DGENG  
*
************************************************************************
      SUBROUTINE GENGD          
     O         ( GDU   , GDV   , GDT   , GDPS  , GDQ   ,
     O           GDVOR , GDDIV ,
     I           WDVOR , WDDIV , WDT   , WDPI  , WDQ   ,
     C           EDEL  , UVFACT                         )
*
*   [PARAM]




* PACKAGE  ZXT10L32 !" 格子点数，波数 X-Z
*
      INTEGER     IMAX           !" 経度格子数
      INTEGER     JMAX           !" 緯度格子数
      INTEGER     IDIM           !" 経度配列サイズ
      INTEGER     JDIM           !" 緯度配列サイズ
      INTEGER     MMAX           !" 最大東西波数
      INTEGER     LMAX           !" 最大南北波数
      INTEGER     NMAX           !" 最大全波数
      INTEGER     MINT           !" 東西波数間隔
      INTEGER     KMAX           !" 鉛直層数
      INTEGER     KDIM           !" 鉛直配列サイズ
      INTEGER     NMDIM          !" 水平波数成分数
      INTEGER     JMXHF          !" JMAX/2+1
      INTEGER     NWORK          !" ワーク領域大きさ
*
      PARAMETER ( IMAX  = 32,     JMAX =  1,
     &            IDIM  = IMAX+1, JDIM = JMAX,
     &            MMAX  = 10,     LMAX =  0,    NMAX = MMAX, MINT = 1,
     &            KMAX  = 32,     KDIM = KMAX,
     &            NMDIM = (MMAX/MINT+1)*(2*(NMAX+1)-MMAX)
     &                  - (NMAX-LMAX)/MINT*(NMAX-LMAX+1),
     &            JMXHF = JMAX/2+1,
     &            NWORK = IDIM*JDIM*KMAX*12                       )

*
*   [OUTPUT]
      ReaL*8       GDU   ( IDIM*JDIM, KMAX )   
      ReaL*8       GDV   ( IDIM*JDIM, KMAX )   
      ReaL*8       GDT   ( IDIM*JDIM, KMAX )   
      ReaL*8       GDPS  ( IDIM*JDIM       )   
      ReaL*8       GDQ   ( IDIM*JDIM, KMAX )   
      ReaL*8       GDVOR ( IDIM*JDIM, KMAX )   
      ReaL*8       GDDIV ( IDIM*JDIM, KMAX )   
*
*   [INPUT]
      ReaL*8       WDVOR ( NMDIM , KMAX     )  
      ReaL*8       WDDIV ( NMDIM , KMAX     )  
      ReaL*8       WDT   ( NMDIM , KMAX     )  
      ReaL*8       WDPI  ( NMDIM            )  
      ReaL*8       WDQ   ( NMDIM , KMAX     )  
*
      ReaL*8       EDEL  ( NMDIM  )            
      ReaL*8       UVFACT( IDIM*JDIM )         
*
*   [INTERNAL WORK]
      COMMON    /COMWRK/
     &           WDPSI , WDCHI
      ReaL*8       WDPSI ( NMDIM, KMAX      )  
      ReaL*8       WDCHI ( NMDIM, KMAX      )  
*
      INTEGER    IJ, K, NM
*
*
*"         < 1. ψ/a, χ/a のスペクトル >
*
      DO 1100 K = 1, KMAX
         DO 1100 NM = 1, NMDIM
            WDPSI( NM,K ) = WDVOR( NM,K ) * EDEL( NM )
            WDCHI( NM,K ) = WDDIV( NM,K ) * EDEL( NM )
 1100 CONTINUE
*
*"         < 2. ζ，Ｄ，Ｔ，π，ｑ格子点値 >
*
      CALL W2G
     O         ( GDVOR ,
     I           WDVOR ,
     I           '    ', 'POS ', KMAX )
*
      CALL W2G
     O         ( GDDIV ,
     I           WDDIV ,
     I           '    ', 'POS ', KMAX )
*
      CALL W2G
     O         ( GDT   ,
     I           WDT   ,
     I           '    ', 'POSO', KMAX )
*
      CALL W2G
     O         ( GDPS  ,
     I           WDPI  ,
     I           '    ', 'POSO', 1    )
*
      DO 2100 IJ = 1, IDIM*JDIM
         GDPS ( IJ ) = EXP( GDPS( IJ ) )
 2100 CONTINUE
*
      CALL W2G
     O         ( GDQ   ,
     I           WDQ   ,
     I           '    ', 'POSO', KMAX )
*
*"         < 3.  Ｕ，Ｖ の格子点値 >
*
      CALL W2G
     O         ( GDU   ,
     I           WDPSI ,
     I           'YGRA', 'NEG ', KMAX )
*
      IF ( MMAX .GE. 1 ) THEN
         CALL W2G
     O         ( GDU   ,
     I           WDCHI ,
     I           'XGRA', 'ADD ', KMAX )
      ENDIF
*
      CALL W2G
     O         ( GDV   ,
     I           WDCHI ,
     I           'YGRA', 'POS ', KMAX )
*
      IF ( MMAX .GE. 1 ) THEN
         CALL W2G
     O         ( GDV   ,
     I           WDPSI ,
     I           'XGRA', 'ADD ', KMAX )
      ENDIF
*
      DO 3100 K = 1, KMAX
         DO 3100 IJ = 1, IDIM*JDIM
            GDU ( IJ,K ) = GDU ( IJ,K ) / UVFACT( IJ )
            GDV ( IJ,K ) = GDV ( IJ,K ) / UVFACT( IJ )
 3100 CONTINUE
*
      RETURN
      END
