C*************************************************************               INIRESIJ.2     
C               SUBROUTINE INIRESIJ                                          INIRESIJ.3     
C*************************************************************               INIRESIJ.4     
      SUBROUTINE INIRESIJ                                                    INIRESIJ.5     
C                                                                            INIRESIJ.6     
C     Sets up restoration variables and arrays. Sets NAMELIST                INIRESIJ.7     
C     variables to their default settings, then reads NAMELIST               INIRESIJ.8     
C     Sets up Rayleigh friction coefficients.                                INIRESIJ.9     
C                                                                            INIRESIJ.10    
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    
C                                                                            RESTIJ.2     
C     Restoration temperature field and constants which determine it,        RESTIJ.3     
C     also contains timescales                                               RESTIJ.4     
C                                                                            RESTIJ.5     
      COMMON/RESTIJ/TTRES(IGB)                                               RESTIJ.6     
     + ,DTNS,DTEP,DTTRP,FAC(NL),DDAMP(NL),TFRC(NL),YRLEN,TRS(NL)             RESTIJ.7     
     +  ,ALR,ZTROP,TGR                                                       RESTIJ.8     
      COMPLEX TTRES                                                          RESTIJ.9     
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    
      DIMENSION RESTIM(NL)                                                   INIRESIJ.16    
C                                                                            INIRESIJ.17    
      NAMELIST/INPRSIJ/ TFRC,RESTIM,DTNS,DTEP,ALR,                           INIRESIJ.18    
     +                  DTTRP,ZTROP,TGR,YRLEN                                INIRESIJ.19    
C                                                                            INIRESIJ.20    
      TFRC(NL)=1.                                                            INIRESIJ.21    
      DO 19 L=1,NL-1                                                         INIRESIJ.22    
         TFRC(L) = 0.! Rayleigh friction time scale IN DAYS                  INIRESIJ.23    
! NB zero here equates to infinity - no friction.                            INIRESIJ.24    
 19   CONTINUE                                                               INIRESIJ.25    
      DO 20 L=1,NL                                                           INIRESIJ.26    
         RESTIM(L) = 15.0                                                    INIRESIJ.27    
 20   CONTINUE                                                               INIRESIJ.28    
      DTNS=0.                                                                INIRESIJ.29    
      DTEP=60.                                                               INIRESIJ.30    
      ALR=6.5E-03                                                            INIRESIJ.31    
      DTTRP=2.                                                               INIRESIJ.32    
      ZTROP=12.0E03                                                          INIRESIJ.33    
      TGR=288.                                                               INIRESIJ.34    
      YRLEN=0.                                                               INIRESIJ.35    
C                                                                            INIRESIJ.36    
      READ(7,INPRSIJ)                                                        INIRESIJ.37    
      WRITE(2,INPRSIJ)                                                       INIRESIJ.38    
C                                                                            INIRESIJ.39    
C     Dimensionless coefficient for Newtonian cooling friction               INIRESIJ.40    
C     and timestep. A day is 2*pi in non dimensional                         INIRESIJ.41    
C     units using omega as the unit of frequency.                            INIRESIJ.42    
C                                                                            INIRESIJ.43    
      DO 22 L=1,NL                                                           INIRESIJ.44    
         IF (RESTIM(L).GT.0.0) THEN                                          INIRESIJ.45    
            DDAMP(L)=1.0/(PI2*RESTIM(L))                                     INIRESIJ.46    
         ELSE                                                                INIRESIJ.47    
            DDAMP(L)=0.0                                                     INIRESIJ.48    
         ENDIF                                                               INIRESIJ.49    
         IF (TFRC(L).GT.0.0) THEN                                            INIRESIJ.50    
            TFRC(L)=1.0/(PI2*TFRC(L))                                        INIRESIJ.51    
         ELSE                                                                INIRESIJ.52    
            TFRC(L)=0.0                                                      INIRESIJ.53    
         ENDIF                                                               INIRESIJ.54    
 22   CONTINUE                                                               INIRESIJ.55    
C                                                                            INIRESIJ.56    
C     Make temperatures dimensionless                                        INIRESIJ.57    
C                                                                            INIRESIJ.58    
      DTNS=DTNS/CT                                                           INIRESIJ.59    
      DTEP=DTEP/CT                                                           INIRESIJ.60    
      DTTRP=DTTRP/CT                                                         INIRESIJ.61    
C                                                                            INIRESIJ.62    
C     Loop to set array FAC - this controls temperature gradients            INIRESIJ.63    
C     as a function of SIGMA in TTRES. It is a sine wave from one            INIRESIJ.64    
C     at SIGMA = 1 to zero at STPS (SIGMA at the tropopause).                INIRESIJ.65    
C                                                                            INIRESIJ.66    
C     First find SIGMA at ZTROP                                              INIRESIJ.67    
C                                                                            INIRESIJ.68    
      TTROP = TGR - ZTROP*ALR                                                INIRESIJ.69    
      STPS = (TTROP/TGR)**(GA/(ALR*GASCON))                                  INIRESIJ.70    
      DO 600 L=1,NL                                                          INIRESIJ.71    
         THING=SIN(0.5*PI*(SIGMA(L)-STPS)/(1.-STPS))                         INIRESIJ.72    
         IF (THING.LT.0.) THEN                                               INIRESIJ.73    
            FAC(L)=0.                                                        INIRESIJ.74    
         ELSE                                                                INIRESIJ.75    
            FAC(L)=THING                                                     INIRESIJ.76    
         ENDIF                                                               INIRESIJ.77    
600   CONTINUE                                                               INIRESIJ.78    
C                                                                            INIRESIJ.79    
      END                                                                    INIRESIJ.80    
