C**************************************************************              INIGAU.2     
C                    SUBROUTINE INIGAU                                       INIGAU.3     
C**************************************************************              INIGAU.4     
      SUBROUTINE INIGAU                                                      INIGAU.5     
C                                                                            INIGAU.6     
C     This subroutine calculates gaussian weights and latitudes              INIGAU.7     
C                                                                            INIGAU.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                                                                            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                                                                            LEGAU.2     
C     Legendre polynomials and information about gaussian latitudes          LEGAU.3     
C                                                                            LEGAU.4     
      COMMON/LEGAU/ ALPJ(MJP),DALPJ(MJP)                                     LEGAU.5     
     +              ,ALP(NWJ2,2,JGL),DALP(NWJ2,2,JGL)                        LEGAU.6     
     +              ,RLP(NWJ2,2,JGL),RDLP(NWJ2,2,JGL)                        LEGAU.7     
     +              ,SI(JGG),CS(JGG),SISQ(JGG),CSSQ(JGG),SECSQ(JGG)          LEGAU.8     
     +              ,ALAT(JGG),GWT(JGG),AW(JGG),JH,JL,JINC                   LEGAU.9     
C                                                                            LEGAU.10    
C                                                                            INIGAU.14    
  230 FORMAT(/' *** ABORT *** PARAMETER JGL IS DIFFERENT FROM 1 OR JG')      INIGAU.15    
  202 FORMAT(' GAUSSIAN LATITUDES')                                          INIGAU.16    
  201 FORMAT(10F7.2)                                                         INIGAU.17    
C                                                                            INIGAU.18    
      IF(JGL.NE.1.AND.JGL.NE.JG) THEN                                        INIGAU.19    
         WRITE(2,230)                                                        INIGAU.20    
         CALL ABORT                                                          INIGAU.21    
      ENDIF                                                                  INIGAU.22    
      IF(JGL.EQ.1) JINC=0                                                    INIGAU.23    
      IF(JGL.EQ.JG)JINC=1                                                    INIGAU.24    
      JL=1                                                                   INIGAU.25    
      DO 8 J=1,JG                                                            INIGAU.26    
         JH=J                                                                INIGAU.27    
         CALL GWTLT(SI(J),WEIGHT,J,JG)                                       INIGAU.28    
         SISQ(J)=SI(J)*SI(J)                                                 INIGAU.29    
         CSSQ(J)=1.-SISQ(J)                                                  INIGAU.30    
         SECSQ(J)=1./CSSQ(J)                                                 INIGAU.31    
         CS(J)=SQRT(CSSQ(J))                                                 INIGAU.32    
         ALAT(J)=ATAN(SI(J)/CS(J))*180.0/PI                                  INIGAU.33    
         GWT(J)=WEIGHT/REAL(NHEM)                                            INIGAU.34    
         AW(J)=WEIGHT*2.0*SECSQ(J)                                           INIGAU.35    
C                                                                            INIGAU.36    
C        Compute Legendre functions at the current latitude.                 INIGAU.37    
C                                                                            INIGAU.38    
         CALL LGNDRE(NN,MM,MOCT,ALPJ,DALPJ,MJP,1,SI(JH),CS(JH))              INIGAU.39    
C                                                                            INIGAU.40    
C        Reorder Legendre functions, separating even/odd functions.          INIGAU.41    
C                                                                            INIGAU.42    
         DO 58 K=1,2                                                         INIGAU.43    
            I=0                                                              INIGAU.44    
            II=K-2                                                           INIGAU.45    
            DO 57 M=0,MM-1,MOCT                                              INIGAU.46    
               DO 56 N=M,NN-1,2                                              INIGAU.47    
                  I=I+1                                                      INIGAU.48    
                  II=II+2                                                    INIGAU.49    
                  ALP(I,K,JL)=ALPJ(II)                                       INIGAU.50    
                  DALP(I,K,JL)=DALPJ(II)                                     INIGAU.51    
                  RLP(I,K,JL)=-RSQ(N+K)*ALP(I,K,JL)                          INIGAU.52    
                  RDLP(I,K,JL)=-RSQ(N+K)*DALP(I,K,JL)                        INIGAU.53    
   56          CONTINUE                                                      INIGAU.54    
   57       CONTINUE                                                         INIGAU.55    
   58    CONTINUE                                                            INIGAU.56    
C                                                                            INIGAU.57    
         IF(JGL.EQ.1) WRITE(25) ALP,DALP,RLP,RDLP                            INIGAU.58    
C                                                                            INIGAU.59    
         JL=JL+JINC                                                          INIGAU.60    
    8 CONTINUE                                                               INIGAU.61    
C                                                                            INIGAU.62    
      IF (NHEM.EQ.2) THEN                                                    INIGAU.63    
CDIR$    IVDEP                                                               INIGAU.64    
         DO 59 J=1,JG                                                        INIGAU.65    
            SI(JGGP-J)=-SI(J)                                                INIGAU.66    
            CS(JGGP-J)=CS(J)                                                 INIGAU.67    
            SISQ(JGGP-J)=SISQ(J)                                             INIGAU.68    
            CSSQ(JGGP-J)=CSSQ(J)                                             INIGAU.69    
            SECSQ(JGGP-J)=SECSQ(J)                                           INIGAU.70    
            ALAT(JGGP-J)=-ALAT(J)                                            INIGAU.71    
            GWT(JGGP-J)=GWT(J)                                               INIGAU.72    
            AW(JGGP-J)=AW(J)                                                 INIGAU.73    
   59    CONTINUE                                                            INIGAU.74    
      ENDIF                                                                  INIGAU.75    
C                                                                            INIGAU.76    
C     Output the Gaussian latitudes                                          INIGAU.77    
C                                                                            INIGAU.78    
      WRITE(2,202)                                                           INIGAU.79    
      WRITE(2,201)(ALAT(J),J=1,JGG)                                          INIGAU.80    
C                                                                            INIGAU.81    
      END                                                                    INIGAU.82    
