C**********************************************************                  SPDEL2.2     
C             SUBROUTINE SPDEL2                                              SPDEL2.3     
C**********************************************************                  SPDEL2.4     
      SUBROUTINE SPDEL2(Z,FILT,NWJ2,NN,MM,MOCT,NHEM,NL,IPAR,ITYPE)           SPDEL2.5     
C                                                                            SPDEL2.6     
C     Perform del**2 or del**(-2) operation on a spectral field.             SPDEL2.7     
C     The input spectral array is assumed to use the jagged triangular       SPDEL2.8     
C     truncation of the Reading baroclinic spectral models.  This is         SPDEL2.9     
C     also used in the diagnostics program for fields from both Reading      SPDEL2.10    
C     models and the UGCM.                                                   SPDEL2.11    
C                                                                            SPDEL2.12    
C     Input arguments:                                                       SPDEL2.13    
C        Z      - Complex array containing input spectral field.             SPDEL2.14    
C                 The truncation is assumed to be jagged triangular.         SPDEL2.15    
C                 i.e. symmetric (even) coefficients are included up         SPDEL2.16    
C                 to total wavenumber (NN-1), while anti-symmetric           SPDEL2.17    
C                 (odd) coefficients are included up to wavenumber NN.       SPDEL2.18    
C                 This gives equal numbers of even and odd coefficients      SPDEL2.19    
C                 in the truncated series.  Ordering is of increasing        SPDEL2.20    
C                 total wavenumber within increasing zonal wavenumber.       SPDEL2.21    
C        FILT   - Real array, unset, to receive filter coefficients.         SPDEL2.22    
C        NWJ2   - First dimension of Z: number of even or odd coeffs         SPDEL2.23    
C                 at a single level in the jagged triangular truncation.     SPDEL2.24    
C        NN     - Highest total wavenumber of input truncation.              SPDEL2.25    
C        MM     - Highest zonal wavenumber of input truncation.              SPDEL2.26    
C        MOCT   - Symmetry in longitude.  Only zonal wavenumbers 0,MOCT,     SPDEL2.27    
C                 2*MOCT,..,MM are included in the input truncation.         SPDEL2.28    
C        NHEM   - Symmetry in latitude: { 1 = hemispheric, only even or      SPDEL2.29    
C                                       {     odd coefficients included.     SPDEL2.30    
C                                       { 2 = global, both even and odd      SPDEL2.31    
C                                       {     coefficients included.         SPDEL2.32    
C        NL     - Number of levels in vertical.                              SPDEL2.33    
C        IPAR   - Parity of field: { IPAR=even for even hem symmetry,        SPDEL2.34    
C                                  { IPAR=odd  for  odd hem symmetry.        SPDEL2.35    
C        ITYPE  - Type of operation required: { +2, del**(+2),               SPDEL2.36    
C                                             { -2, del**(-2).               SPDEL2.37    
C     Output arguments:                                                      SPDEL2.38    
C        Z      - Filtered spectral field.  Ordering of spectral             SPDEL2.39    
C                 coefficients is unchanged.                                 SPDEL2.40    
C        FILT   - Real array of filter coefficients.                         SPDEL2.41    
C        Other arguments unchanged.                                          SPDEL2.42    
C                                                                            SPDEL2.43    
C     Method:                                                                SPDEL2.44    
C        This routine can perform the following operations:                  SPDEL2.45    
C     ITYPE=+2 : Del**(+2), in which the non-dimensional spectral            SPDEL2.46    
C                coefficient Z(n,m) is multiplied by -[n*(n+1)].             SPDEL2.47    
C     ITYPE=-2 : Del**(-2), in which the non-dimensional spectral            SPDEL2.48    
C                coefficient Z(n,m) is divided by -[n*(n+1)].                SPDEL2.49    
C                                                                            SPDEL2.50    
C     Author:                                                                SPDEL2.51    
C        Original version.                    Mike Blackburn,  25.11.94.     SPDEL2.52    
C        FILT is now a dummy array, (0:NN).   Mike Blackburn,  04.09.96.     SPDEL2.53    
C        FILT(0)=-1 for inverse Laplacian.    Mike Blackburn,  17.04.00.     SPDEL2.54    
C                                                                            SPDEL2.55    
      COMPLEX Z(NWJ2,NHEM,NL)                                                SPDEL2.56    
      REAL FILT(0:NN)                                                        SPDEL2.57    
C                                                                            SPDEL2.58    
C     Set up filter coefficients.                                            SPDEL2.59    
C     Note that FILT(n)=-n*(n+1) (or its inverse).                           SPDEL2.60    
C                                                                            SPDEL2.61    
      IF (ITYPE.EQ.2) THEN                                                   SPDEL2.62    
         DO 10 N=0,NN                                                        SPDEL2.63    
            FILT(N)=-REAL(N*(N+1))                                           SPDEL2.64    
   10    CONTINUE                                                            SPDEL2.65    
      ELSE IF (ITYPE.EQ.-2) THEN                                             SPDEL2.66    
         FILT(0)=-1.0                                                        SPDEL2.67    
         DO 20 N=1,NN                                                        SPDEL2.68    
            FILT(N)=-1./REAL(N*(N+1))                                        SPDEL2.69    
   20    CONTINUE                                                            SPDEL2.70    
      ELSE                                                                   SPDEL2.71    
         PRINT *,' ***SPDEL2: INVALID VALUE OF ITYPE SUPPLIED = '            SPDEL2.72    
     :          ,ITYPE,' : MUST BE +-2 FOR DEL**(+-2) OPERATION'             SPDEL2.73    
         CALL ABORT                                                          SPDEL2.74    
      ENDIF                                                                  SPDEL2.75    
C                                                                            SPDEL2.76    
C     Del**(+-2) operation.                                                  SPDEL2.77    
C     Counting for total wavenumber in inner loop is for even coeffs,        SPDEL2.78    
C     NOF increases total wavenumber for odd coeffs.                         SPDEL2.79    
C                                                                            SPDEL2.80    
      DO 30 IHEM=1,NHEM                                                      SPDEL2.81    
         NOF=1-MOD(IHEM+IPAR,2)                                              SPDEL2.82    
         DO 30 L=1,NL                                                        SPDEL2.83    
            I=0                                                              SPDEL2.84    
            DO 30 M=0,MM-1,MOCT                                              SPDEL2.85    
               DO 30 N=M,NN-1,2                                              SPDEL2.86    
                  I=I+1                                                      SPDEL2.87    
                  Z(I,IHEM,L)=Z(I,IHEM,L)*FILT(N+NOF)                        SPDEL2.88    
   30 CONTINUE                                                               SPDEL2.89    
C                                                                            SPDEL2.90    
C     Check that inner loop count is NWJ2.                                   SPDEL2.91    
C                                                                            SPDEL2.92    
      IF (I.NE.NWJ2) THEN                                                    SPDEL2.93    
         PRINT *,' ***SPDEL2: ERROR IN WAVENUMBER COUNTING: FINAL I = '      SPDEL2.94    
     :          ,I,' SHOULD EQUAL NWJ2 = ',NWJ2                              SPDEL2.95    
         CALL ABORT                                                          SPDEL2.96    
      ENDIF                                                                  SPDEL2.97    
C                                                                            SPDEL2.98    
      RETURN                                                                 SPDEL2.99    
      END                                                                    SPDEL2.100   
