C**********************************************************                  DLSGCR.2     
C             SUBROUTINE DLSGCR                                              DLSGCR.3     
C**********************************************************                  DLSGCR.4     
      SUBROUTINE DLSGCR(NCOL,F,RGG,DF,IDIM,NL)                               DLSGCR.5     
C                                                                            DLSGCR.6     
C     Black-box routine to take vertical derivative of a 2D array            DLSGCR.7     
C     in the model's vertical co-ordinates using the RGG matrix:             DLSGCR.8     
C                                                                            DLSGCR.9     
C              DF   =   RGG   *   F                                          DLSGCR.10    
C                                                                            DLSGCR.11    
C     gives    DF   =   d(F)/dln(sigma)   =   (sigma)d(F)/d(sigma).          DLSGCR.12    
C                                                                            DLSGCR.13    
C     Calculates DF at NL levels for NCOL columns from the array F.          DLSGCR.14    
C     Uses vector loops over NCOL at each level.  Note that for              DLSGCR.15    
C     NCOL <= 3 inner loops unroll to give vectorisation over levels.        DLSGCR.16    
C                                                                            DLSGCR.17    
C     Uses explicit values of RGG matrix rather than function SDOT           DLSGCR.18    
C     over NL elements of RGG at each level.  Due to sparse nature           DLSGCR.19    
C     of RGG, this gives large speed-up for NL >> 3.                         DLSGCR.20    
C                                                                            DLSGCR.21    
C     Reading model - sigma.                                                 DLSGCR.22    
C                                                                            DLSGCR.23    
      REAL F(IDIM,NL),DF(IDIM,NL),RGG(NL,NL)                                 DLSGCR.24    
C                                                                            DLSGCR.25    
 6900 FORMAT(/' ***ABORT IN DLSGCR: MORE COLUMNS THAN ARRAY DIMENSION:'      DLSGCR.26    
     :       ,' NCOL IDIM ='2I10)                                            DLSGCR.27    
C                                                                            DLSGCR.28    
      IF (NCOL.GT.IDIM) THEN                                                 DLSGCR.29    
         WRITE(2,6900) NCOL,IDIM                                             DLSGCR.30    
         CALL ABORT                                                          DLSGCR.31    
      ENDIF                                                                  DLSGCR.32    
C                                                                            DLSGCR.33    
      NLM=NL-1                                                               DLSGCR.34    
      NLMM=NL-2                                                              DLSGCR.35    
C     Top and bottom levels.                                                 DLSGCR.36    
      DO 10 I=1,NCOL                                                         DLSGCR.37    
      DF(I,1 )=F(I,1)*RGG(1,1)+F(I,2)*RGG(2,1)+F(I,3)*RGG(3,1)               DLSGCR.38    
      DF(I,NL)=F(I,NLMM)*RGG(NLMM,NL)+F(I,NLM)*RGG(NLM,NL)                   DLSGCR.39    
     :        +F(I,NL)*RGG(NL,NL)                                            DLSGCR.40    
   10 CONTINUE                                                               DLSGCR.41    
C     Intermediate levels.                                                   DLSGCR.42    
      DO 20 L=2,NLM                                                          DLSGCR.43    
      DO 20 I=1,NCOL                                                         DLSGCR.44    
      DF(I,L)=F(I,L-1)*RGG(L-1,L)+F(I,L+1)*RGG(L+1,L)                        DLSGCR.45    
   20 CONTINUE                                                               DLSGCR.46    
C                                                                            DLSGCR.47    
      RETURN                                                                 DLSGCR.48    
      END                                                                    DLSGCR.49    
