* PACKAGE   !"  定数(緯度経度座標値)
*
*"  [HIS] 90/05/19(numaguti)
*"        96/09/14(takepiro) 内部作業領域を引数へ変更
*
***********************************************************************
      SUBROUTINE SETLAT      !"  モデル緯度座標定数の計算 
     O         ( ALAT   , DLAT  , 
     D           JMAX   , JDIM  , 
     W           QSINLA , QGW   , QPN   )
*
*"    ------ 座標格子定数 -------------------------------------
*
*  [PARAM]
      INTEGER    JMAX, JDIM
*
*  [OUTPUT]
      REAL       ALAT  ( JDIM )              !" 緯度
      REAL       DLAT  ( JDIM )              !" 緯度荷重
*
*  [WORK]
      REAL * 8   QSINLA( JMAX )             !" sin（緯度）：倍精度
      REAL * 8   QGW   ( JMAX )             !" ガウス荷重 ：倍精度
      REAL * 8   QPN( 0:JMAX+1 )            !" Ｐn (倍精度)
*
*    [INTERNAL PARAM]
      REAL       ALATD0                       !" JMAX=のとき(degree)
      DATA       ALATD0 / 0.0  /
      NAMELIST  /NMLAT0/ ALATD0
*    
*    [INTERNAL WORK]
      INTEGER    IFPAR, JFPAR, J
      REAL       PI, SUMGW
*
      IF ( JMAX .GT. JDIM ) THEN
         CALL MSGDMP( 'E', 'SETLAT', 'WORK AREA OVERFULL' )
         RETURN
      ENDIF
*
*"         < 1. 緯度・ガウス荷重の計算 >
*
      IF ( JMAX .GE. 2 ) THEN
         CALL GAUSS
     O         ( QSINLA , QGW    ,
     I           JMAX   ,
     W           QPN             )
      ELSE
*
         WRITE ( 6,* ) ' CONTROL PARAMETER NMLAT0: '
*
         CALL   REWNML ( IFPAR , JFPAR )
         READ   ( IFPAR, NMLAT0, END=1090 )
 1090    WRITE  ( JFPAR, NMLAT0 )
         PI = ATAN( 1. )*4.
         QSINLA ( 1 ) = SIN( ALATD0/180.*PI )
         QGW    ( 1 ) = 1.0
      ENDIF
*
      SUMGW=0.0  
      DO 1100 J = 1, JMAX
         ALAT  ( J ) = ASIN ( QSINLA ( J ) )
         DLAT  ( J ) = QGW ( J )
         SUMGW = SUMGW + QGW ( J )
 1100 CONTINUE
*
      WRITE ( 6,* ) ' check SUMGW = ', SUMGW
*
      DO 1200 J = JMAX+1, JDIM
         ALAT  ( J ) = ALAT   ( JMAX  )
         DLAT  ( J ) = DLAT   ( JMAX  )
 1200 CONTINUE
*
      RETURN
      END
***********************************************************************
      SUBROUTINE SETLON      !"  モデル経度座標定数の計算 
     O         ( ALON  , DLON  , 
     D           IMAX  , IDIM    )
*
*"    ------ 座標格子定数 -------------------------------------
*
      INTEGER    IMAX, IDIM
      REAL       ALON  ( IDIM )              !" 経度
      REAL       DLON  ( IDIM )              !" 経度差分
*
*    [INTERNAL WORK]
      INTEGER    I
      REAL       PI
*
*"         < 1. 経度の計算 >
*
      PI = ATAN( 1. ) *4.
      DO 1100 I = 1, IDIM
         ALON  ( I ) = REAL( I-1 ) / REAL( IMAX ) * 2. * PI
         DLON  ( I ) = 1. / REAL( IMAX )
 1100 CONTINUE
*
      RETURN
      END
