C**************************************************************              INISTR.2     
C                   SUBROUTINE INISTR                                        INISTR.3     
C**************************************************************              INISTR.4     
      SUBROUTINE INISTR                                                      INISTR.5     
C                                                                            INISTR.6     
C     Reads in data for a start/restart run                                  INISTR.7     
C                                                                            INISTR.8     
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                                                                            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                                                                            SPECTR.2     
C     Array ordering in SPECTR must correspond to that in GRIDP.             SPECTR.3     
C                                                                            SPECTR.4     
      COMMON/SPECTR/Z(IGB),D(IGB),T(IGB),TRA(IGB,NTRAC),SP(IGA),GS(IGA)      SPECTR.5     
     :              ,SPA(IGA),VP(IGA),DTE(IGB),TT(IGB)                       SPECTR.6     
     :              ,TRAT(IGB,NTRAC),DT(IGB),ZT(IGB)                         SPECTR.7     
     :              ,ZMI(IGB),DMI(IGB),TMI(IGB)                              SPECTR.8     
     :              ,TRAMI(IGB,NTRAC),SPMI(IGA)                              SPECTR.9     
      COMPLEX Z,D,T,TRA,SP,GS,SPA,VP,DTE,TT,TRAT,DT,ZT                       SPECTR.10    
     :       ,ZMI,DMI,TMI,TRAMI,SPMI                                         SPECTR.11    
C                                                                            SPECTR.12    
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                                                                            RESTOR.2     
C     Restoration fields and timescale                                       RESTOR.3     
C                                                                            RESTOR.4     
      COMMON/RESTOR/ZRES(IGN),DRES(IGN),TRES(IGN),SPRES(IGM),DAMP            RESTOR.5     
C                                                                            RESTOR.6     
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     
      COMMON/STATS/GMSP0,GMSPMI,LMASCOR,LMASOLD,LMASPRT                      STATS.2     
      LOGICAL LMASCOR,LMASOLD,LMASPRT                                        STATS.3     
C                                                                            STATS.4     
C-----------------------------------------------------------------------     STATS.5     
C                                                                            BALAN.2     
C     Constants and arrays needed for balancing                              BALAN.3     
C                                                                            BALAN.4     
      COMMON/BALAN/BFILT(NL),RGT0(NL),RG(NL2),TMEAN(NL)                      BALAN.5     
     +            ,EP1(IGA),EP2(IGA),KBAL,MFTBAL,SRGT0,LTBAL                 BALAN.6     
      LOGICAL LTBAL                                                          BALAN.7     
C                                                                            BALAN.8     
       COMMON/GSG/GSG(IGC,JG)                                                OROG_G.2     
       REAL htnet                                                            RADHT.2     
       COMMON /RADHT/ HTNET(NHEM,JG,MG,NL)                                   RADHT.3     
       REAL TAVE(IGP)                                                        RADHT.4     
C                                                                            INISTR.21    
 2000 FORMAT(' ***WARNING*** KITS < 1 FOR AN INITIAL RUN.'/)                 INISTR.22    
 2010 FORMAT(/' ***ABORT*** THE HISTORY RECORDS READ FROM CHANNEL '          INISTR.23    
     + ,I3,/' ARE NOT IN CORRECT FORMAT ')                                   INISTR.24    
 2020 FORMAT(/' ***ABORT*** THE RUN NUMBER IN THE HISTORY RECORD ',F10.3     INISTR.25    
     +       /' DIFFERS FROM RNTAPO IN THE NAMELIST ',F10.3)                 INISTR.26    
 2030 FORMAT(/' ***ABORT*** CANNOT FIND THE CORRECT HISTORY RECORD.'/        INISTR.27    
     + ' LOOKING FOR DAY',F8.2/,' BUT THE NEAREST RECORD FOUND',             INISTR.28    
     + ' IS FOR DAY',F8.2)                                                   INISTR.29    
 2040 FORMAT(/' HISTORY RECORD READ FROM CHANNEL ',I3,/                      INISTR.30    
     + ' KOUNT  RMTAPE  DAY  DOY =',I8,3F12.3)                               INISTR.31    
 2011 FORMAT(/' ***ABORT*** THE RESTART RECORDS READ FROM CHANNEL '          INISTR.32    
     + ,I3,/' ARE NOT IN CORRECT FORMAT ')                                   INISTR.33    
 2021 FORMAT(/' ***ABORT*** THE RUN NUMBER IN THE RESTART RECORD ',F10.3     INISTR.34    
     +       /' DIFFERS FROM RNTAPO IN THE NAMELIST ',F10.3)                 INISTR.35    
 2031 FORMAT(/' ***ABORT*** CANNOT FIND THE CORRECT RESTART RECORD.'/        INISTR.36    
     + ' LOOKING FOR DAY',F8.2/,' BUT THE NEAREST RECORD FOUND',             INISTR.37    
     + ' IS FOR DAY',F8.2)                                                   INISTR.38    
 2041 FORMAT(/' RESTART RECORD READ FROM CHANNEL ',I3,/                      INISTR.39    
     + ' KOUNT  RMTAPE  DAY  DOY =',I8,3F12.3)                               INISTR.40    
 2012 FORMAT(/' ***ABORT*** THE RESTORATION RECORDS READ FROM CHANNEL '      INISTR.41    
     + ,I3,/' ARE NOT IN CORRECT FORMAT ')                                   INISTR.42    
 2022 FORMAT(/' ***ABORT*** THE RUN NUMBER IN THE RESTORATION RECORD '       INISTR.43    
     +       ,F10.3/' IS NOT THE SAME AS RNTAPO IN THE NAMELIST ',F10.3)     INISTR.44    
 2032 FORMAT(/' ***ABORT*** CANNOT FIND THE CORRECT RESTORATION RECORD.'     INISTR.45    
     + /' LOOKING FOR DAY',F8.2/,' BUT THE NEAREST RECORD FOUND',            INISTR.46    
     + ' IS FOR DAY',F8.2)                                                   INISTR.47    
 2042 FORMAT(' RESTORATION RECORD READ FROM CHANNEL ',I3,/                   INISTR.48    
     + ' KOUNT  RMTAPE  DAY  DOY =',I8,3F12.3)                               INISTR.49    
 2050 FORMAT(/' SPECTRAL ARRAYS ARE SET TO ZERO ')                           INISTR.50    
 2100 FORMAT(/' MASS INFORMATION READ AT RESTART:'                           INISTR.51    
     :       /'    INITIAL (REFERENCE) MASS     = ',1PE20.12,' (PA)'         INISTR.52    
     :       /'    TIME-LAGGED MASS             = ',1PE20.12,' (PA)')        INISTR.53    
 2110 FORMAT(/' ***ABORT: MASS RESTART RECORD HAS WRONG LENGTH')             INISTR.54    
 2130 FORMAT(/' ***ABORT: EOF READING MASS RESTART RECORD AT DAY ',F8.2)     INISTR.55    
C                                                                            INISTR.56    
C     Initialize spectral arrays to zero and overwrite as desired            INISTR.57    
C                                                                            INISTR.58    
      DO 1 I=1,IGA                                                           INISTR.59    
         SP(I)=(0.0,0.0)                                                     INISTR.60    
         SPMI(I)=(0.,0.)                                                     INISTR.61    
         GS(I)=(0.0,0.0)                                                     INISTR.62    
    1 CONTINUE                                                               INISTR.63    
      DO 5 I=1,IGB                                                           INISTR.64    
         Z(I)=(0.0,0.0)                                                      INISTR.65    
         D(I)=(0.0,0.0)                                                      INISTR.66    
         T(I)=(0.0,0.0)                                                      INISTR.67    
         ZMI(I)=(0.0,0.0)                                                    INISTR.68    
         DMI(I)=(0.0,0.0)                                                    INISTR.69    
         TMI(I)=(0.0,0.0)                                                    INISTR.70    
    5 CONTINUE                                                               INISTR.71    
      DO 6 KK=1,NTRAC                                                        INISTR.72    
         DO 6 I=1,IGB                                                        INISTR.73    
            TRA(I,KK)=(0.0,0.0)                                              INISTR.74    
            TRAMI(I,KK)=(0.0,0.0)                                            INISTR.75    
    6 CONTINUE                                                               INISTR.76    
      DO 8 l=1,nl                                                            INISTR.77    
        DO 8 i=1,mg                                                          INISTR.78    
          DO 8 j=1,jg                                                        INISTR.79    
            DO 8 ihem=1,nhem                                                 INISTR.80    
              htnet(ihem,j,i,l)=0.                                           INISTR.81    
    8 CONTINUE                                                               INISTR.82    
C                                                                            INISTR.83    
C     Initialise current and global reference mass to zero (unset).          INISTR.84    
C                                                                            INISTR.85    
      GMSP0=0.0                                                              INISTR.86    
      GMSPMI=0.0                                                             INISTR.87    
C                                                                            INISTR.88    
      IF (.NOT.LRSTRT) THEN                                                  INISTR.89    
C                                                                            INISTR.90    
C        Initial run                                                         INISTR.91    
C                                                                            INISTR.92    
         IF ( KITS .LT. 1) THEN                                              INISTR.93    
            WRITE(2,2000)                                                    INISTR.94    
         ENDIF                                                               INISTR.95    
         DAY=0.0                                                             INISTR.96    
         IF (KITS.EQ.0) THEN                                                 INISTR.97    
            KTOTAL=KRUN                                                      INISTR.98    
            KOUTP=0                                                          INISTR.99    
            KOUTE=0                                                          INISTR.100   
            KOUTH=0                                                          INISTR.101   
            KOUTR=0                                                          INISTR.102   
         ELSE                                                                INISTR.103   
            KTOTAL=KRUN+KITS-1                                               INISTR.104   
            KOUTP=1-KITS                                                     INISTR.105   
            KOUTE=1-KITS                                                     INISTR.106   
            KOUTH=1-KITS                                                     INISTR.107   
            KOUTR=1-KITS                                                     INISTR.108   
         END IF                                                              INISTR.109   
C                                                                            INISTR.110   
C        Initialise restoration array                                        INISTR.111   
C                                                                            INISTR.112   
         IF (LRESTIJ) CALL SETZT                                             INISTR.113   
C                                                                            INISTR.114   
C        Initialise spectral arrays                                          INISTR.115   
C                                                                            INISTR.116   
         IF (LBALAN) THEN                                                    INISTR.117   
           CALL INIBAL                                                       INISTR.118   
           KOUNT=-KBAL                                                       INISTR.119   
           KSTART=0                                                          INISTR.120   
         ELSE                                                                INISTR.121   
           IF (LRESTIJ) THEN                                                 INISTR.122   
              CALL INISP                                                     INISTR.123   
           ELSE                                                              INISTR.124   
              WRITE (2,2050)                                                 INISTR.125   
           ENDIF                                                             INISTR.126   
           KOUNT=0                                                           INISTR.127   
           KSTART=KOUNT                                                      INISTR.128   
         ENDIF                                                               INISTR.129   
      ELSE                                                                   INISTR.130   
C                                                                            INISTR.131   
C        Code for restart and normal mode perturbation runs.                 INISTR.132   
C        assume spectral data is set up non-dimensionalised                  INISTR.133   
C        on a history (LSHORT) or restart (.NOT.LSHORT) record.              INISTR.134   
C                                                                            INISTR.135   
         ID=10                                                               INISTR.136   
         DAYNEAR=-9999.5 ! allows desired day no. = 0                        INISTR.137   
         IF (LSHORT) THEN                                                    INISTR.138   
  180       IF (NTRACO.EQ.0) THEN                                            INISTR.139   
              READ(ID,END=1000)RKOUNT,RM1TAPE,DAY,Z,D,T,SP,RM2TAPE           INISTR.140   
            ELSE                                                             INISTR.141   
              READ(ID,END=1000)RKOUNT,RM1TAPE,DAY,DOY,Z,D,T                  INISTR.142   
     +             ,((TRA(I,KK),I=1,IGB),KK=1,NTRACO),SP,RM2TAPE             INISTR.143   
            ENDIF                                                            INISTR.144   
            IF (ABS(RM1TAPE-RM2TAPE) .GT. 1.0E-03) THEN                      INISTR.145   
               WRITE(2,2010) ID                                              INISTR.146   
               CALL ABORT                                                    INISTR.147   
            ENDIF                                                            INISTR.148   
            IF (ABS(RM1TAPE-RNTAPO) .GT. 1.0E-03) THEN                       INISTR.149   
               WRITE(2,2020) RM1TAPE,RNTAPO                                  INISTR.150   
               CALL ABORT                                                    INISTR.151   
            ENDIF                                                            INISTR.152   
C Extra read if restart record contains mass correction.                     INISTR.153   
            IF (LMASOLD) THEN                                                INISTR.154   
               READ(ID,END=1010) RK,RMT1,RDAY,RREC,GMSP0,GMSPMI,RMT2         INISTR.155   
               IF (RMT2.NE.RMT1) THEN                                        INISTR.156   
                  WRITE(2,2110)                                              INISTR.157   
                  CALL ABORT                                                 INISTR.158   
               ENDIF                                                         INISTR.159   
            ENDIF                                                            INISTR.160   
            IF (ABS(DAY-BEGDAY) .GT. 1.0E-02) THEN                           INISTR.161   
               IF (ABS(DAY-BEGDAY) .LT. ABS(DAYNEAR-BEGDAY)) THEN            INISTR.162   
                  DAYNEAR = DAY                                              INISTR.163   
               ENDIF                                                         INISTR.164   
               GOTO 180                                                      INISTR.165   
            ELSE                                                             INISTR.166   
               GOTO 200                                                      INISTR.167   
            ENDIF                                                            INISTR.168   
 1000       WRITE(2,2030) BEGDAY,DAYNEAR                                     INISTR.169   
            CALL ABORT                                                       INISTR.170   
 1010       WRITE(2,2130) DAY                                                INISTR.171   
            CALL ABORT                                                       INISTR.172   
C                                                                            INISTR.173   
  200       KOUNT=NINT(RKOUNT)                                               INISTR.174   
            WRITE(2,2040) ID,KOUNT,RM1TAPE,BEGDAY,DOY                        INISTR.175   
            KOUNT=0                                                          INISTR.176   
            IF (KITS.EQ.0) THEN                                              INISTR.177   
               KTOTAL=KRUN                                                   INISTR.178   
               KOUTP=0                                                       INISTR.179   
               KOUTE=0                                                       INISTR.180   
               KOUTH=0                                                       INISTR.181   
               KOUTR=0                                                       INISTR.182   
            ELSE                                                             INISTR.183   
               KTOTAL=KRUN+KITS-1                                            INISTR.184   
               KOUTP=1-KITS                                                  INISTR.185   
               KOUTE=1-KITS                                                  INISTR.186   
               KOUTH=1-KITS                                                  INISTR.187   
               KOUTR=1-KITS                                                  INISTR.188   
            ENDIF                                                            INISTR.189   
            KSTART=KOUNT                                                     INISTR.190   
            DO 183 I=1,IGA                                                   INISTR.191   
               SPMI(I)=SP(I)                                                 INISTR.192   
  183       CONTINUE                                                         INISTR.193   
            DO 184 J=1,IGB                                                   INISTR.194   
               ZMI(J)=Z(J)                                                   INISTR.195   
               DMI(J)=D(J)                                                   INISTR.196   
               TMI(J)=T(J)                                                   INISTR.197   
  184       CONTINUE                                                         INISTR.198   
            DO 185 KK=1,NTRAC                                                INISTR.199   
               DO 185 J=1,IGB                                                INISTR.200   
                  TRAMI(J,KK)=TRA(J,KK)                                      INISTR.201   
  185       CONTINUE                                                         INISTR.202   
         ELSE                                                                INISTR.203   
  181       IF (NTRACO.EQ.0) THEN                                            INISTR.204   
               READ(ID,END=1001)RKOUNT,RM1TAPE,DAY,Z,D,T,SP,RM2TAPE          INISTR.205   
     +         ,ZMI,DMI,TMI,SPMI,HTNET,RM3TAPE                               INISTR.206   
            ELSE                                                             INISTR.207   
               READ(ID,END=1001)RKOUNT,RM1TAPE,DAY,DOY,Z,D,T                 INISTR.208   
     +             ,((TRA(I,KK),I=1,IGB),KK=1,NTRACO),SP,RM2TAPE             INISTR.209   
     +             ,ZMI,DMI,TMI                                              INISTR.210   
     +             ,((TRAMI(I,KK),I=1,IGB),KK=1,NTRACO),SPMI,                INISTR.211   
     +             HTNET,RM3TAPE                                             INISTR.212   
            ENDIF                                                            INISTR.213   
            IF (ABS(RM1TAPE-RM2TAPE) .GT. 1.0E-03 .OR.                       INISTR.214   
     +          ABS(RM1TAPE-RM3TAPE) .GT. 1.0E-03) THEN                      INISTR.215   
               WRITE(2,2011) ID                                              INISTR.216   
               CALL ABORT                                                    INISTR.217   
            ENDIF                                                            INISTR.218   
            IF (ABS(RM1TAPE-RNTAPO) .GT. 1.0E-03) THEN                       INISTR.219   
               WRITE(2,2021) RM1TAPE,RNTAPO                                  INISTR.220   
               CALL ABORT                                                    INISTR.221   
            ENDIF                                                            INISTR.222   
C Extra read if restart record contains mass correction.                     INISTR.223   
            IF (LMASOLD) THEN                                                INISTR.224   
               READ(ID,END=1011) RK,RMT1,RDAY,RREC,GMSP0,GMSPMI,RMT2         INISTR.225   
               IF (RMT2.NE.RMT1) THEN                                        INISTR.226   
                  WRITE(2,2110)                                              INISTR.227   
                  CALL ABORT                                                 INISTR.228   
               ENDIF                                                         INISTR.229   
            ENDIF                                                            INISTR.230   
            IF (ABS(DAY-BEGDAY) .GT. 1.0E-02) THEN                           INISTR.231   
               IF (ABS(DAY-BEGDAY) .LT. ABS(DAYNEAR-BEGDAY)) THEN            INISTR.232   
                  DAYNEAR = DAY                                              INISTR.233   
               ENDIF                                                         INISTR.234   
               GOTO 181                                                      INISTR.235   
            ELSE                                                             INISTR.236   
               GOTO 201                                                      INISTR.237   
            ENDIF                                                            INISTR.238   
 1001       WRITE(2,2031) BEGDAY,DAYNEAR                                     INISTR.239   
            CALL ABORT                                                       INISTR.240   
 1011       WRITE(2,2130) DAY                                                INISTR.241   
            CALL ABORT                                                       INISTR.242   
C                                                                            INISTR.243   
  201       KOUNT=NINT(RKOUNT)                                               INISTR.244   
            WRITE(2,2041) ID,KOUNT,RM1TAPE,BEGDAY,DOY                        INISTR.245   
            KTOTAL=KOUNT+KRUN                                                INISTR.246   
            KSTART=KOUNT                                                     INISTR.247   
            KTEMP=KOUNT                                                      INISTR.248   
            IF(KITS.GT.0) KTEMP=KOUNT+1-KITS                                 INISTR.249   
            KOUTP=KTEMP-KOUNTP*(KTEMP/KOUNTP)                                INISTR.250   
            KOUTE=KTEMP-KOUNTE*(KTEMP/KOUNTE)                                INISTR.251   
            KOUTH=KTEMP-KOUNTH*(KTEMP/KOUNTH)                                INISTR.252   
            KOUTR=KTEMP-KOUNTR*(KTEMP/KOUNTR)                                INISTR.253   
            IF ((KTEMP.GT.0).AND.(KOUTH.EQ.0)) THEN                          INISTR.254   
               KOUTH=KOUNTH                                                  INISTR.255   
            ENDIF                                                            INISTR.256   
         END IF                                                              INISTR.257   
C                                                                            INISTR.258   
         IF (LMASOLD) THEN                                                   INISTR.259   
            WRITE(2,2100) GMSP0*P0,GMSPMI*P0                                 INISTR.260   
         ENDIF                                                               INISTR.261   
C                                                                            INISTR.262   
C        Read in restoration state from separate file                        INISTR.263   
C                                                                            INISTR.264   
         IF (LRESTIJ) THEN                                                   INISTR.265   
            ID=13                                                            INISTR.266   
  182       READ(ID,END=1002)RKOUNT,RM1TAPE,DAY,DOY,TTRES,RM2TAPE            INISTR.267   
            IF (ABS(RM1TAPE-RM2TAPE) .GT. 1.0E-03) THEN                      INISTR.268   
              WRITE(2,2012) ID                                               INISTR.269   
              CALL ABORT                                                     INISTR.270   
            ENDIF                                                            INISTR.271   
            IF (ABS(RM1TAPE-RNTAPO) .GT. 1.0E-03) THEN                       INISTR.272   
               WRITE(2,2022) RM1TAPE,RNTAPO                                  INISTR.273   
               CALL ABORT                                                    INISTR.274   
            ENDIF                                                            INISTR.275   
            IF (ABS(DAY-BEGDAY) .GT. 1.0E-02) THEN                           INISTR.276   
               IF (ABS(DAY-BEGDAY) .LT. ABS(DAYNEAR-BEGDAY)) THEN            INISTR.277   
                 DAYNEAR = DAY                                               INISTR.278   
               ENDIF                                                         INISTR.279   
               GOTO 182                                                      INISTR.280   
            ELSE                                                             INISTR.281   
               GOTO 202                                                      INISTR.282   
            ENDIF                                                            INISTR.283   
 1002       WRITE(2,2032) BEGDAY,DAYNEAR                                     INISTR.284   
            CALL ABORT                                                       INISTR.285   
C                                                                            INISTR.286   
  202       WRITE(2,2042) ID,NINT(RKOUNT),RM1TAPE,BEGDAY,DOY                 INISTR.287   
         ELSE                                                                INISTR.288   
            IF(DAMP.GT.0.0) THEN                                             INISTR.289   
               REWIND 13                                                     INISTR.290   
               READ(13)ZRES,DRES,TRES,SPRES                                  INISTR.291   
            END IF                                                           INISTR.292   
         ENDIF                                                               INISTR.293   
C                                                                            INISTR.294   
C  Initialise any new tracer fields and surface state.                       INISTR.295   
C                                                                            INISTR.296   
         CALL ICTRAC                                                         INISTR.297   
C                                                                            INISTR.298   
      END IF                                                                 INISTR.299   
C                                                                            INISTR.300   
C   READS in T21 orography  part                                             INISTR.301   
      IF (LOROG) THEN                                                        INISTR.302   
c read in spectral field                                                     INISTR.303   
        open(50,file='orogdata/t21.50',status='old')                         INISTR.304   
        read(50,*) GS                                                        INISTR.305   
        close(50)                                                            INISTR.306   
C read in gridpoint field                                                    INISTR.307   
C skipping extra line on equator                                             INISTR.308   
c tstar goes from 1 at pole to jg at equator, gsg made the same              INISTR.309   
        open(50,file='orogdata/t21.59',status='old')                         INISTR.310   
                                                                             INISTR.311   
        read(50,*)((gsg(i,j),i=1,mg),j=1,jg),(adum,i=1,mg),                  INISTR.312   
     $      ((gsg(i+mgpp,j),i=1,mg),j=jg,1,-1)                               INISTR.313   
        close(50)                                                            INISTR.314   
c print out land mask                                                        INISTR.315   
        write(2,*) 'land mask looks like:'                                   INISTR.316   
        do j=1,jg                                                            INISTR.317   
          write (2,'(128I1)')                                                INISTR.318   
     $         (nint((gsg(i,j)/(gsg(i,j)+.1))),i=1,mg)                       INISTR.319   
        enddo                                                                INISTR.320   
        do j=jg,1,-1                                                         INISTR.321   
          write (2,'(128I1)')                                                INISTR.322   
     $         (nint((gsg(i+mgpp,j)/(gsg(i+mgpp,j)+.1))),i=1,mg)             INISTR.323   
        enddo                                                                INISTR.324   
      ENDIF                                                                  INISTR.325   
                                                                             INISTR.326   
C If BEGDOY=0 sets DOY from restart record - else                            INISTR.327   
C sets it from namelist                                                      INISTR.328   
      IF (BEGDOY.GT.0.9) DOY=BEGDOY                                          INISTR.329   
      WRITE(2,*) 'STARTING FROM ',DOY,' DAY OF YEAR '                        INISTR.330   
      if (lshort) then                                                       INISTR.331   
        print *,'resetting DAY to 0.0'                                       INISTR.332   
        DAY=0.0                                                              INISTR.333   
      else                                                                   INISTR.334   
        print*,' begdoy day doy ',begdoy,day,doy                             INISTR.335   
      end if                                                                 INISTR.336   
      END                                                                    INISTR.337   
