C**********************************************************                  SETRES.2     
C             SUBROUTINE SETRES                                              SETRES.3     
C**********************************************************                  SETRES.4     
      SUBROUTINE SETRES                                                      SETRES.5     
C                                                                            SETRES.6     
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                                                                            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                                                                            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                                                                            SETRES.11    
C     Set up restoration state from the KOUNT=0 zonally averaged             SETRES.12    
C     state and write this to FT13 for future use.                           SETRES.13    
C     This is only done when KOUNT=0 and DAMP.GT.0.0.                        SETRES.14    
C                                                                            SETRES.15    
 2200 FORMAT(/' RESTORATION RECORD WRITTEN TO CHANNEL ',I3)                  SETRES.16    
C                                                                            SETRES.17    
      IF (DAMP.LE.0) RETURN                                                  SETRES.18    
C                                                                            SETRES.19    
      DO 840 IHEM=1,NHEM                                                     SETRES.20    
         I=NWJ2*(IHEM-1)                                                     SETRES.21    
         IR=IDM*(IHEM-1)                                                     SETRES.22    
         DO 100 J=1,IDM                                                      SETRES.23    
            I=I+1                                                            SETRES.24    
            IR=IR+1                                                          SETRES.25    
            SPRES(IR)=SP(I)                                                  SETRES.26    
  100    CONTINUE                                                            SETRES.27    
         DO 850 L=1,NL                                                       SETRES.28    
            I=NWJ2*(IHEM-1)+(L-1)*IGA                                        SETRES.29    
            IR=IDM*(IHEM-1)+(L-1)*IGM                                        SETRES.30    
            DO 860 J=1,IDM                                                   SETRES.31    
               I=I+1                                                         SETRES.32    
               IR=IR+1                                                       SETRES.33    
               ZRES(IR)=Z(I)                                                 SETRES.34    
               DRES(IR)=D(I)                                                 SETRES.35    
               TRES(IR)=T(I)                                                 SETRES.36    
  860       CONTINUE                                                         SETRES.37    
  850    CONTINUE                                                            SETRES.38    
  840 CONTINUE                                                               SETRES.39    
C                                                                            SETRES.40    
      REWIND 13                                                              SETRES.41    
      WRITE(13)ZRES,DRES,TRES,SPRES                                          SETRES.42    
      WRITE(2,2200)13                                                        SETRES.43    
C                                                                            SETRES.44    
      END                                                                    SETRES.45    
