*" PACKAGE XMKINIT  !" 初期値作成
*
*"  [HIS] 92/09/17(takepiro)
*
***********************************************************************
      PROGRAM MKINIT    !" 初期値メインルーチン
*
*   [PARAM]
#ifdef SYS_IBMS
      INCLUDE   (ZCDIM)                      !" 格子点数, 波数
      INCLUDE   (ZHDIM)                      !" 文字列文字数
      INCLUDE   (ZCCOM)                      !" 標準物理定数
#else
#include        "zcdim.F"                    !" 格子点数, 波数
#include        "zhdim.F"                    !" 文字列文字数
#include        "zccom.F"                    !" 標準物理定数
#endif
*
*   [VAR]
      REAL       GAU   ( IDIM, JDIM, 0:KDIM )  !" 西風   ｕ
      REAL       GAV   ( IDIM, JDIM, 0:KDIM )  !" 南風   ｖ
      REAL       GAW   ( IDIM, JDIM, 0:KDIM )  !" 鉛直風 ｗ
      REAL       GAT   ( IDIM, JDIM, 0:KDIM )  !" 温度   Ｔ
      REAL       GATOR ( IDIM, JDIM, 0:KDIM )  !" トロイダル Ψ
      REAL       GAPOR ( IDIM, JDIM, 0:KDIM )  !" ポロイダル Φ
*"       : 格子点データ(t) <DYNMCS>  格子点データ(t+Δt)
*
      REAL       GBU   ( IDIM, JDIM, 0:KDIM )  !" 西風   ｕ
      REAL       GBV   ( IDIM, JDIM, 0:KDIM )  !" 南風   ｖ
      REAL       GBW   ( IDIM, JDIM, 0:KDIM )  !" 鉛直風 ｗ
      REAL       GBT   ( IDIM, JDIM, 0:KDIM )  !" 温度   Ｔ
      REAL       GBTOR ( IDIM, JDIM, 0:KDIM )  !" トロイダル Ψ
      REAL       GBPOR ( IDIM, JDIM, 0:KDIM )  !" ポロイダル Φ
*"       : 格子点データ(t-Δt) <DYNMCS>  格子点データ(t)
*
*
*   [INTERNAL PARM] 
      INTEGER    ISTEP                 !" 通しステップ数
      INTEGER    ITA                   !" 通し時間(t)
      INTEGER    ITB                   !" 通し時間(t-Δt)
      INTEGER    IDATEA( 6 )           !" 時刻：年月日時分秒
      INTEGER    IDATEB( 6 )           !" 時刻：年月日時分秒
*"       : 時刻等
*
      DATA       ITA, ITB     / 0 , 0 /
      DATA       IDATEA       / 1990, 1, 1, 0, 0, 0 /
      DATA       IDATEB       / 1990, 1, 1, 0, 0, 0 /
      DATA       ISTEP        / 0  /
*
      NAMELIST  /NMDATE/ ITA, ITB, ISTEP
*
      CHARACTER  HDSET *(NCC)
      CHARACTER  HFILE *(NFILN)
      CHARACTER  HDFMT *(NCC)
      DATA       HDFMT  / 'UR8' /
      INTEGER    JFLRST 
      DATA       JFLRST / 41 /
*
*   [INTERNAL WORK] 
      REAL       ALAT  ( JDIM )        !" 緯度
      REAL       DLAT  ( JDIM )        !" 緯度荷重
      REAL       ALON  ( IDIM )        !" 経度
      REAL       DLON  ( IDIM )        !" 経度荷重
      REAL       ARAD  ( 0:KDIM )        !" ｒレベル(整数)
      REAL       DRAD  ( 0:KDIM )        !" Δｒ(整数)
*
      CALL YPREP
      CALL PCONST
      CALL GTOPEN
*
      WRITE( 6,*     ) ' DATA NAME  ?'
      READ ( 5,'(A)' ) HDSET
      WRITE( 6,*     ) ' FILE NAME  ?'
      READ ( 5,'(A)' ) HFILE
      CALL GFWOPN ( JFLRST, HFILE )
*
      CALL GTCSET( 'DDSET' , HDSET     )
*
      CALL SETCOR
     O         ( ALON  , DLON  ,
     O           ALAT  , DLAT  ,
     O           ARAD  , DRAD    )
*
      CALL INISET               !" 初期値設定
     O         ( GAU   , GAV   , GAW   , GAT   , 
     O           GATOR , GAPOR , 
     I           ALON  , ALAT  , ARAD              )
*
      CALL COPY ( GBU  , GAU  , IDIM*JDIM*KMAX )
      CALL COPY ( GBV  , GAV  , IDIM*JDIM*KMAX )
      CALL COPY ( GBW  , GAW  , IDIM*JDIM*KMAX )
      CALL COPY ( GBT  , GAT  , IDIM*JDIM*KMAX )
      CALL COPY ( GBTOR, GATOR, IDIM*JDIM*KMAX )
      CALL COPY ( GBPOR, GAPOR, IDIM*JDIM*KMAX )
*

      CALL WRRSTX           !" 基本リスタート・ファイルの書き込み
     I         ( GAU   , GAV   , GAW   , GAT   , 
     I           GBU   , GBV   , GBW   , GBT   , 
     I           ITA   , ITB   , IDATEA, IDATEB, ISTEP ,
     I           JFLRST, HDFMT                            )
*
      CALL WRRSTY     !" ポテンシャルリスタート・ファイルの書き込み
     I         ( GATOR , GAPOR ,
     I           GBTOR , GBPOR ,
     I           ITA   , ITB   , IDATEA, IDATEB, ISTEP ,
     I           JFLRST, HDFMT                            )
      CALL YFINE
*
      STOP
      END
**********************************************************************
      SUBROUTINE INISET        !" 初期値設定
     O        ( GAU   , GAV   , GAW   , GAT   , 
     O          GATOR , GAPOR , 
     I          ALON  , ALAT  , ARAD               )
*
*
*   [PARAM] 
#ifdef SYS_IBMS
      INCLUDE   (ZCDIM)                      !" 格子点数, 波数
      INCLUDE   (ZCCOM)                      !" 標準物理定数
#else
#include        "zcdim.F"                    !" 格子点数, 波数
#include        "zccom.F"                    !" 標準物理定数
#endif
*
*   [OUTPUT] 
      REAL       GAU   ( IDIM, JDIM, 0:KDIM )
      REAL       GAV   ( IDIM, JDIM, 0:KDIM )
      REAL       GAW   ( IDIM, JDIM, 0:KDIM )
      REAL       GAT   ( IDIM, JDIM, 0:KDIM ) 
      REAL       GATOR ( IDIM, JDIM, 0:KDIM )  !" トロイダル Ψ
      REAL       GAPOR ( IDIM, JDIM, 0:KDIM )  !" ポロイダル Φ
      REAL       ALON  ( IDIM )
      REAL       ALAT  ( JDIM )
      REAL       ARAD  ( 0:KDIM )
*
*   [INTERNAL PARM] 
      REAL       TPRTRB
      DATA       TPRTRB       / 0.1 /
      LOGICAL    ORANDM
      DATA       ORANDM       / .TRUE. /
*
      REAL       GATTOP, GATBTM          !" 上面, 下面温度
      DATA       GATTOP, GATBTM  / 100.,  200. /
*
      REAL       PI
*
*   [INTERNAL WORK] 
      REAL       RANDOM( IDIM, JDIM, 0:KDIM )
      INTEGER    I, J, K
*
      PI = 4 * ATAN( 1.0D0 )
*
      CALL RESET ( GAU   , IDIM*JDIM*KMAX )
      CALL RESET ( GAV   , IDIM*JDIM*KMAX )
      CALL RESET ( GAW   , IDIM*JDIM*KMAX )
      CALL RESET ( GAT   , IDIM*JDIM*KMAX )
      CALL RESET ( GATOR , IDIM*JDIM*KMAX )
      CALL RESET ( GAPOR , IDIM*JDIM*KMAX )
*
*" << INIT : これが初期値だ >> 
*
      DO 1000 K = 0, KDIM
        DO 1000 J = 1, JDIM
          DO 1000 I = 1, IDIM
            GAU  ( I,J,K ) = 0.
            GAV  ( I,J,K ) = 0.
            GAW  ( I,J,K ) = 0.
            GAT  ( I,J,K ) = GATBTM + 
     &                        ( ARAD(K) - ERI ) / ( ERO - ERI ) 
     &                      * ( GATTOP - GATBTM )
c$$$            GATOR ( I,J,K ) = ARAD( K ) * SIN ( ALAT( J ) )
            GATOR ( I,J,K ) = 0.
            GAPOR ( I,J,K ) = 
     &                COS ( ALAT( J ) ) * ARAD ( K )
 1000 CONTINUE
*
*" << RANDOM : 乱数の付加 >> 
*
CCC   CALL \SGU1M( IDIM*JDIM*KMAX, 0, RANDOM, IER )
*
      IF ( ORANDM ) THEN
*
         DO 3000 K = 0, KDIM
            DO 3000 J = 1, JDIM
               DO 3000 I = 1, IDIM
                  RANDOM( I,J,K )
     &                 =  SIN(  REAL(I*J*(KMAX-K))
     &                       / REAL(IMAX*JMAX*KMAX)*10. )
 3000    CONTINUE
*
         DO 3100 K = 1, KDIM
            DO 3100 J = 1, JDIM
               DO 3100 I = 1, IDIM
                  GAT ( I,J,K ) = GAT ( I,J,K )
     &                 + RANDOM( I,J,K ) * TPRTRB
 3100    CONTINUE
*
      ENDIF
*
      RETURN
      END
