C***********************************************************                 INISI.2     
C                SUBROUTINE INISI                                            INISI.3     
C***********************************************************                 INISI.4     
      SUBROUTINE INISI                                                       INISI.5     
C                                                                            INISI.6     
C     Sets up arrays and variables for the vertical structure                INISI.7     
C     and the semi-implicit scheme                                           INISI.8     
C                                                                            INISI.9     
C                                                                            PARAM1.2     
C     Determines model resolution                                            PARAM1.3     
C                                                                            PARAM1.4     
      PARAMETER(NN=21,MM=21,NHEM=2,NL=5,MOCT=1,MG=64,JG=16,NWJ2=121          NETCDF.35    
     P         ,NCRAY=64,JGL=JG,NTRAC=1,NLEVRF=1)                            NETCDF.36    
                                                                             PARAM1.7     
C                                                                            PARAM1.8     
C                                                                            PARAM2.2     
C     Sets basic constants, especially those needed for array dimensions     PARAM2.3     
C                                                                            PARAM2.4     
      PARAMETER(MH=2,PI=3.14159265359,PI2=2.0*PI                             PARAM2.5     
     +,NNP=NN+1,MGPP=MG+2,JGP=JG+1,JGG=JG*NHEM,JGGP=JGG+1,MJP=NWJ2+NWJ2      PARAM2.6     
     +,NLM=NL-1,NLP=NL+1,NLPP=NL+2,NLA=NL+3,NLB=NL+4,NL2=NL*NL               PARAM2.7     
     +,IDA=(MG+MG+MG)/2+1,IDB=NWJ2*NL,IDC=IDB+IDB,IDD=MGPP*NL                PARAM2.8     
     +,IDE=NL2*NN,IDF=NCRAY*(MG+1),IDG=JG*NL,IDH=JG*MG                       PARAM2.9     
     +,IDI=NNP/2,IDJ=IDI*IDI,IDK=NL*IDI,IDL=MGPP/2,IDM=NNP/2,IDN=IDM*NL      PARAM2.10    
     +,NWW=1+(MM-1)/MOCT)                                                    PARAM2.11    
      PARAMETER(IGA=NWJ2*NHEM,IGB=IDB*NHEM,IGC=MGPP*NHEM,IGD=IDD*NHEM        PARAM2.12    
     +,IGG=IDG*NHEM,IGL=IDL*NHEM,IGM=IDM*NHEM,IGN=IDN*NHEM                   PARAM2.13    
     +,IGO=IGA+IGA,IGP=IGB+IGB,NFTWG=(5+NTRAC)*NL+3                          PARAM2.14    
     +,NFTGW=(6+3*NTRAC)*NL+2,NFTGD=(3+NTRAC)*NL,NLTR=NL*NTRAC)              PARAM2.15    
C     Number of 2D (surface) output fields. This value is                    PARAM2.16    
C     Doubled due to averaged and instantaneous fields.                      PARAM2.17    
      PARAMETER (N2DFLD=21,NGRPAD=N2DFLD*2*IGC)                              PARAM2.18    
C                                                                            PARAM2.19    
      PARAMETER(NLT=NL+NL)                                                   INISI.12    
C                                                                            BLANK.2     
C     Basic planetary parameters for run plus information about              BLANK.3     
C     vertical grid structure                                                BLANK.4     
C                                                                            BLANK.5     
C     Note that RD and GASCON are identical and CPD is set from RD,AKAP.     BLANK.6     
      COMMON        SQ(NNP),RSQ(NNP),SIGMAH(NLM),SIGMA(NL)                   BLANK.7     
     +              ,T01S2(NLM),T0(NL),ALPHA(NL),DSIGMA(NL),RDSIG(NL)        BLANK.8     
     +              ,TKP(NL),C(NL2),SQH(NNP)                                 BLANK.9     
     +              ,MF,MFP,JZF,NF,NFP                                       BLANK.10    
     +              ,AKAP,GA,GASCON,RADEA,WW,P0,PFAC,EZ,AIOCT                BLANK.11    
     +              ,RD,RV,CPD,CLATNT                                        BLANK.12    
     +              ,LRSTRT,LSHORT,LTVEC,LSTRETCH                            BLANK.13    
     +              ,LFLUX                                                   BLANK.14    
     +              ,LBALAN,LRESTIJ                                          BLANK.15    
     +              ,LCLIM, LPERPET, L22L,LOROG ,LCSFCT                      BLANK.16    
     +              ,LNOISE                                                  BLANK.17    
      COMPLEX EZ,AIOCT                                                       BLANK.18    
      LOGICAL LRSTRT,LSHORT,LTVEC,LSTRETCH,LBALAN,LRESTIJ                    BLANK.19    
     +       ,LFLUX,LNOISE                                                   BLANK.20    
     +       ,LCLIM, LPERPET, L22L,LOROG,LCSFCT                              BLANK.21    
C                                                                            BLANK.22    
C                                                                            BATS.2     
C     Constant arrays and variables associated with time and vertical        BATS.3     
C     differencing. Also counters.                                           BATS.4     
C                                                                            BATS.5     
      COMMON/BATS/  BM1(IDE),AK(NNP),AQ(NL2),G(NL2),TAU(NL2)                 BATS.6     
     +              ,KOUNT,KITS,KSTART,KTOTAL,KRUN,BEGDAY,ITSPD              BATS.7     
     +              ,DELT,DELT2,CV,CG,CT,CQ,PNU,PNU2,PNU21                   BATS.8     
     +              ,NTRACO,CTRA(NTRAC),KOLOUR(NTRAC),RGG(NL2)               BATS.9     
     +              ,BEGDOY,DOY                                              BATS.10    
C                                                                            BATS.11    
C                                                                            OUTCON.2     
C     Switches counters and constants controlling type and frequency of      OUTCON.3     
C     model output                                                           OUTCON.4     
C                                                                            OUTCON.5     
      COMMON/OUTCON/RNTAPE,NCOEFF,NLAT,INLAT,INSPC                           OUTCON.6     
     +              ,RNTAPO                                                  OUTCON.7     
     +              ,KOUNTP,KOUNTE,KOUNTH,KOUNTR                             OUTCON.8     
     +              ,KOUTP,KOUTE,KOUTH,KOUTR,DAY                             OUTCON.9     
     +              ,SQR2,RSQR2,EAM1,EAM2,TOUT1,TOUT2,RMG                    OUTCON.10    
     +              ,LSPO(NL),LGPO(NL)                                       OUTCON.11    
     $              ,LSHIST,LMINIH                                           OUTCON.12    
      LOGICAL LSHIST,LMINIH                                                  OUTCON.13    
      LOGICAL LSPO,LGPO                                                      OUTCON.14    
C                                                                            OUTCON.15    
C                                                                            INISI.16    
      DIMENSION H(NL),CR(NL),CI(NL),TBM1(NL2),WA(NL)                         INISI.17    
      INTEGER IWA(NL)                                                        INISI.18    
      DIMENSION TBME(NL,NL)                                                  INISI.19    
      EQUIVALENCE (TBM1(1),TBME(1,1))                                        INISI.20    
C                                                                            INISI.21    
  203 FORMAT(' STANDARD HEIGHTS IN KM')                                      INISI.22    
  206 FORMAT(' GRAVITY WAVE SPEEDS IN M/SEC')                                INISI.23    
  208 FORMAT(' VALUES OF SIGMA AT HALF LEVELS')                              INISI.24    
  213 FORMAT(1X,8F8.4)                                                       INISI.25    
  214 FORMAT(' VALUES OF SIGMA AT FULL LEVELS')                              INISI.26    
  215 FORMAT(' BASIC STATE TEMPERATURES (NON-DIMENSIONAL)')                  INISI.27    
  216 FORMAT(1X,8F8.3)                                                       INISI.28    
  217 FORMAT(5X,8F8.3)                                                       INISI.29    
C                                                                            INISI.30    
      STP=1.0/NL                                                             INISI.31    
      IF (.NOT. LSTRETCH) THEN                                               INISI.32    
         DO 23 L=1,NLM                                                       INISI.33    
            SIGMAH(L)=L*STP                                                  INISI.34    
   23    CONTINUE                                                            INISI.35    
      ELSE                                                                   INISI.36    
         P=0.0                                                               INISI.37    
         T1=(.9375/.94-1.25)/(.9375*(SQRT(.9375)-1.0))                       INISI.38    
         T2=4.0+T1                                                           INISI.39    
         DO 25 L=1,NLM                                                       INISI.40    
            P=P+STP                                                          INISI.41    
            SIGMAH(L)=P*(2.0-P)*(1.0+0.25*SIN(PI2*(P**.6)))/                 INISI.42    
     1                (5.0-T2*P+T1*(P**1.5))                                 INISI.43    
   25    CONTINUE                                                            INISI.44    
      END IF                                                                 INISI.45    
      IF (L22L.AND.NL.EQ.22) THEN                                            INISI.46    
      SIGMAH(1)=0.002                                                        INISI.47    
      SIGMAH(2)=0.009                                                        INISI.48    
      SIGMAH(3)=0.019                                                        INISI.49    
      SIGMAH(4)=0.037                                                        INISI.50    
      ENDIF                                                                  INISI.68    
      S1=0.                                                                  INISI.69    
      DO 60 L=1,NLM                                                          INISI.70    
         S2=SIGMAH(L)                                                        INISI.71    
         DSIGMA(L)=S2-S1                                                     INISI.72    
         SIGMA(L)=0.5*(S2+S1)                                                INISI.73    
         RDSIG(L)=0.5/DSIGMA(L)                                              INISI.74    
         S1=S2                                                               INISI.75    
   60 CONTINUE                                                               INISI.76    
      DSIGMA(NL)=1.-SIGMAH(NLM)                                              INISI.77    
      RDSIG(NL)=0.5/DSIGMA(NL)                                               INISI.78    
      SIGMA(NL)=0.5*(1.+SIGMAH(NLM))                                         INISI.79    
C                                                                            INISI.80    
C     This value, used in setting ALPHA(1), is irrelevant in the             INISI.81    
C     angular momentum conserving ECMWF scheme                               INISI.82    
C                                                                            INISI.83    
      S1=LOG(SIGMA(1)*SIGMA(1)/SIGMAH(1))                                    INISI.84    
      IG=1                                                                   INISI.85    
      T0M=T0(1)                                                              INISI.86    
      DO 61 L=1,NLM                                                          INISI.87    
         LP=L+1                                                              INISI.88    
         S2=LOG(SIGMAH(L))                                                   INISI.89    
         T0P=T0(LP)                                                          INISI.90    
         IG=IG+NL                                                            INISI.91    
         G(IG)=0.                                                            INISI.92    
         T01S2(L)=T0P-T0M                                                    INISI.93    
         ALPHA(L)=S2-S1                                                      INISI.94    
         TKP(L)=AKAP*T0M                                                     INISI.95    
         T0M=T0P                                                             INISI.96    
         S1=S2                                                               INISI.97    
   61 CONTINUE                                                               INISI.98    
      ALPHA(NL)=-S1                                                          INISI.99    
      TKP(NL)=AKAP*T0M                                                       INISI.100   
      G(1)=1.0                                                               INISI.101   
      DO 64 J=2,NL                                                           INISI.102   
         ALJ=ALPHA(J)                                                        INISI.103   
         IG=J                                                                INISI.104   
         LIM=J-1                                                             INISI.105   
         DO 62 I=1,LIM                                                       INISI.106   
            G(IG)=ALJ                                                        INISI.107   
            IG=IG+NL                                                         INISI.108   
   62    CONTINUE                                                            INISI.109   
         G(IG)=1.0-ALJ*SIGMAH(LIM)/DSIGMA(J)                                 INISI.110   
         IF (J.LT.NL) THEN                                                   INISI.111   
            LIM=LIM+2                                                        INISI.112   
            DO 63 I=LIM,NL                                                   INISI.113   
               IG=IG+NL                                                      INISI.114   
               G(IG)=0.                                                      INISI.115   
   63       CONTINUE                                                         INISI.116   
         ENDIF                                                               INISI.117   
   64 CONTINUE                                                               INISI.118   
      IC=-1                                                                  INISI.119   
      DO 50 I=1,NL                                                           INISI.120   
         IC=IC+1                                                             INISI.121   
         JC=IC*NLP                                                           INISI.122   
         JCC=JC-NLM                                                          INISI.123   
         DO 51 J=I,NL                                                        INISI.124   
            JC=JC+1                                                          INISI.125   
            JCC=JCC+NL                                                       INISI.126   
            C(JCC)=G(JC)*DSIGMA(I)/DSIGMA(J)                                 INISI.127   
   51    CONTINUE                                                            INISI.128   
   50 CONTINUE                                                               INISI.129   
      TT01S2=T01S2(1)                                                        INISI.130   
      TAU(1)=0.5*TT01S2*(SIGMAH(1)-1.0)+TKP(1)*C(1)                          INISI.131   
      DO 65 L=2,NL                                                           INISI.132   
         TAU(L)=0.5*TT01S2*DSIGMA(L)                                         INISI.133   
   65 CONTINUE                                                               INISI.134   
      SIG=SIGMAH(1)                                                          INISI.135   
      IT=NL                                                                  INISI.136   
      DO 73 L=2,NL                                                           INISI.137   
         TTKP=TKP(L)                                                         INISI.138   
         TTM=TT01S2                                                          INISI.139   
         SIGM=SIG                                                            INISI.140   
         IF (L.LT.NL) THEN                                                   INISI.141   
            TT01S2=T01S2(L)                                                  INISI.142   
            SIG=SIGMAH(L)                                                    INISI.143   
         ENDIF                                                               INISI.144   
         RDSIGL=RDSIG(L)                                                     INISI.145   
         DO 72 M=1,NL                                                        INISI.146   
            IT=IT+1                                                          INISI.147   
            IF( M.LT.L) THEN                                                 INISI.148   
               TM=1.                                                         INISI.149   
               TMM=1.                                                        INISI.150   
            ELSEIF (M.EQ.L) THEN                                             INISI.151   
               TM=1.                                                         INISI.152   
               TMM=0.                                                        INISI.153   
            ELSE                                                             INISI.154   
               TM=0.                                                         INISI.155   
               TMM=0.                                                        INISI.156   
            ENDIF                                                            INISI.157   
            TTAU=TTM*(SIGM-TMM)                                              INISI.158   
            IF (L.LT.NL) TTAU=TTAU+TT01S2*(SIG-TM)                           INISI.159   
            TTAU=TTAU*RDSIGL*DSIGMA(M)                                       INISI.160   
            IF (M.LE.L) TTAU=TTAU+TTKP*C(IT)                                 INISI.161   
            TAU(IT)=TTAU                                                     INISI.162   
   72    CONTINUE                                                            INISI.163   
   73 CONTINUE                                                               INISI.164   
      FAC=0.001*CG/GA                                                        INISI.165   
      IL=0                                                                   INISI.166   
      DO 78 L=1,NL                                                           INISI.167   
         HL=0.                                                               INISI.168   
         DO 77 M=1,NL                                                        INISI.169   
            IL=IL+1                                                          INISI.170   
            HL=HL+G(IL)*T0(M)                                                INISI.171   
   77    CONTINUE                                                            INISI.172   
         H(L)=HL*FAC                                                         INISI.173   
   78 CONTINUE                                                               INISI.174   
      IL=0                                                                   INISI.175   
      INS=1                                                                  INISI.176   
      DO 81 L=1,NL                                                           INISI.177   
         DO 80 M=1,NL                                                        INISI.178   
            IN=INS                                                           INISI.179   
            IL=IL+1                                                          INISI.180   
            IM=M                                                             INISI.181   
            TAQ=T0(L)*DSIGMA(M)                                              INISI.182   
            DO 79 N=1,NL                                                     INISI.183   
               TAQ=TAQ+G(IN)*TAU(IM)                                         INISI.184   
               IN=IN+1                                                       INISI.185   
               IM=IM+NL                                                      INISI.186   
   79       CONTINUE                                                         INISI.187   
            AQ(IL)=TAQ                                                       INISI.188   
            TBM1(IL)=TAQ                                                     INISI.189   
   80    CONTINUE                                                            INISI.190   
         INS=INS+NL                                                          INISI.191   
   81 CONTINUE                                                               INISI.192   
      CALL QREIG(TBM1,NL,NL,NL,CR,CI)                                        INISI.193   
      DO 82 L=1,NL                                                           INISI.194   
         CR(L)=CV*SQRT(CR(L))                                                INISI.195   
   82 CONTINUE                                                               INISI.196   
C                                                                            INISI.197   
C     Write out vertical information                                         INISI.198   
C                                                                            INISI.199   
      WRITE(2,208)                                                           INISI.200   
      WRITE(2,217)(SIGMAH(L),L=1,NLM)                                        INISI.201   
      WRITE(2,214)                                                           INISI.202   
      WRITE(2,213)(SIGMA(L),L=1,NL)                                          INISI.203   
      WRITE(2,215)                                                           INISI.204   
      WRITE(2,216)(T0(L),L=1,NL)                                             INISI.205   
      WRITE(2,203)                                                           INISI.206   
      WRITE(2,216)(H(L),L=1,NL)                                              INISI.207   
      WRITE(2,206)                                                           INISI.208   
      WRITE(2,216)(CR(L),L=1,NL)                                             INISI.209   
      WRITE(2,*)                                                             INISI.210   
C                                                                            INISI.211   
C     RGG matrix for vertical derivatives:                                   INISI.212   
C     d()/dln(sigma) = (sigma)d()/d(sigma).                                  INISI.213   
C                                                                            INISI.214   
      IL=0                                                                   INISI.215   
      DO 150 L=1,NL                                                          INISI.216   
         RGVAL=SIGMA(L)*RDSIG(L)                                             INISI.217   
         DO 160 M=1,NL                                                       INISI.218   
            IL=IL+1                                                          INISI.219   
            RGG(IL)=0.                                                       INISI.220   
            IF (M.EQ.L-1) RGG(IL)=-RGVAL                                     INISI.221   
            IF (M.EQ.L+1) RGG(IL)=RGVAL                                      INISI.222   
  160    CONTINUE                                                            INISI.223   
  150 CONTINUE                                                               INISI.224   
      DA=SIGMA(1)                                                            INISI.225   
      DB=SIGMA(2)-DA                                                         INISI.226   
      DC=SIGMA(3)-SIGMA(2)                                                   INISI.227   
      DD=DC+DB                                                               INISI.228   
      RGG(1)=-DA*(DD+DB)/(DB*DD)                                             INISI.229   
      RGG(2)=DA*DD/(DB*DC)                                                   INISI.230   
      RGG(3)=-DA*DB/(DC*DD)                                                  INISI.231   
      DA=SIGMA(NL)                                                           INISI.232   
      DD=SIGMA(NL-1)                                                         INISI.233   
      DB=DA-DD                                                               INISI.234   
      DC=DD-SIGMA(NL-2)                                                      INISI.235   
      DD=DC+DB                                                               INISI.236   
      RGG(NL2)=DA*(DD+DB)/(DB*DD)                                            INISI.237   
      RGG(NL2-1)=-DA*DD/(DB*DC)                                              INISI.238   
      RGG(NL2-2)=DA*DB/(DC*DD)                                               INISI.239   
C                                                                            INISI.240   
C     Setup arrays for semi-implicit scheme                                  INISI.241   
C                                                                            INISI.242   
      DELTSQ=DELT*DELT                                                       INISI.243   
      IBM1=0                                                                 INISI.244   
      DO 11 IN=2,NNP                                                         INISI.245   
         RCN=RSQ(IN)                                                         INISI.246   
         IL=0                                                                INISI.247   
         DO 83 L=1,NL                                                        INISI.248   
            DO 84 M=1,NL                                                     INISI.249   
               IL=IL+1                                                       INISI.250   
               TBM1(IL)=AQ(IL)*DELTSQ                                        INISI.251   
               IF(M.EQ.L)TBM1(IL)=TBM1(IL)+RCN                               INISI.252   
   84       CONTINUE                                                         INISI.253   
   83    CONTINUE                                                            INISI.254   
         CALL MATINV(TBME,NL,NL,IWA,WA)                                      INISI.255   
         DO 85 L=1,NL2                                                       INISI.256   
            IBM1=IBM1+1                                                      INISI.257   
            BM1(IBM1)=TBM1(L)                                                INISI.258   
   85    CONTINUE                                                            INISI.259   
   11 CONTINUE                                                               INISI.260   
      SFAC=0.5**KITS                                                         INISI.261   
      IF(LRSTRT.AND..NOT.LSHORT)SFAC=1.0                                     INISI.262   
      DELT=DELT*SFAC                                                         INISI.263   
      DELT2=DELT+DELT                                                        INISI.264   
      DELTSQ=DELT*DELT                                                       INISI.265   
      DO 87 L=1,NL2                                                          INISI.266   
         AQ(L)=AQ(L)*DELTSQ                                                  INISI.267   
   87 CONTINUE                                                               INISI.268   
      TOUT1=0.                                                               INISI.269   
      TOUT2=0.                                                               INISI.270   
      DO 88 L=1,NL                                                           INISI.271   
         T0L=T0(L)                                                           INISI.272   
         DSIG=DSIGMA(L)*T0(L)                                                INISI.273   
         TOUT1=TOUT1+DSIG                                                    INISI.274   
         TOUT2=TOUT2+DSIG*T0L                                                INISI.275   
   88 CONTINUE                                                               INISI.276   
C                                                                            INISI.277   
      END                                                                    INISI.278   
