*IF DEF,A03_7A                                                             STDEV7A.2      
C *****************************COPYRIGHT******************************     STDEV7A.3      
C (c) CROWN COPYRIGHT 1997, METEOROLOGICAL OFFICE, All Rights Reserved.    STDEV7A.4      
C                                                                          STDEV7A.5      
C Use, duplication or disclosure of this code is subject to the            STDEV7A.6      
C restrictions as set forth in the contract.                               STDEV7A.7      
C                                                                          STDEV7A.8      
C                Meteorological Office                                     STDEV7A.9      
C                London Road                                               STDEV7A.10     
C                BRACKNELL                                                 STDEV7A.11     
C                Berkshire UK                                              STDEV7A.12     
C                RG12 2SZ                                                  STDEV7A.13     
C                                                                          STDEV7A.14     
C If no contract has been raised with this copy of the code, the use,      STDEV7A.15     
C duplication or disclosure of it is strictly prohibited.  Permission      STDEV7A.16     
C to do so must first be obtained in writing from the Head of Numerical    STDEV7A.17     
C Modelling at the above address.                                          STDEV7A.18     
C ******************************COPYRIGHT******************************    STDEV7A.19     
!                                                                          STDEV7A.20     
!!!  SUBROUTINES STDEV1_SEA and STDEV1_LAND ----------------------------   STDEV7A.21     
!!!                                                                        STDEV7A.22     
!!!  Purpose: Calculate the standard deviations of layer 1 turbulent       STDEV7A.23     
!!!           fluctuations of temperature and humidity using approximate   STDEV7A.24     
!!!           formulae from first order closure.                           STDEV7A.25     
!!!                                                                        STDEV7A.26     
!!!  -------------------------------------------------------------------   STDEV7A.27     
!                                                                          STDEV7A.28     
                                                                           STDEV7A.29     
!!!  SUBROUTINE STDEV1_SEA ---------------------------------------------   STDEV7A.30     
!!!  Layer 1 standard deviations for sea and sea-ice                       STDEV7A.31     
!!!  -------------------------------------------------------------------   STDEV7A.32     

      SUBROUTINE STDEV1_SEA (                                               1,2STDEV7A.33     
     & P_POINTS,P_FIELD,P1,LAND_MASK,                                      STDEV7A.34     
     & BQ_1,BT_1,FQW_1,FTL_1,ICE_FRACT,RHOKM_1,RHOSTAR,VSHR,               STDEV7A.35     
     & Z0MSEA,Z0_ICE,Z1_TQ,                                                STDEV7A.36     
     & Q1_SD,T1_SD,LTIMER                                                  STDEV7A.37     
     & )                                                                   STDEV7A.38     
                                                                           STDEV7A.39     
      IMPLICIT NONE                                                        STDEV7A.40     
                                                                           STDEV7A.41     
      INTEGER                                                              STDEV7A.42     
     & P_POINTS              ! IN Number of points to be processed.        STDEV7A.43     
     &,P_FIELD               ! IN Total number points.                     STDEV7A.44     
     &,P1                    ! IN First point to be processed.             STDEV7A.45     
                                                                           STDEV7A.46     
      LOGICAL                                                              STDEV7A.47     
     & LTIMER                ! IN logical for TIMER                        STDEV7A.48     
     &,LAND_MASK(P_FIELD)    ! IN .TRUE. for land                          STDEV7A.49     
                                                                           STDEV7A.50     
      REAL                                                                 STDEV7A.51     
     & BQ_1(P_FIELD)         ! IN Buoyancy parameter.                      STDEV7A.52     
     &,BT_1(P_FIELD)         ! IN Buoyancy parameter.                      STDEV7A.53     
     &,FQW_1(P_FIELD)        ! IN Surface flux of QW.                      STDEV7A.54     
     &,FTL_1(P_FIELD)        ! IN Surface flux of TL.                      STDEV7A.55     
     &,ICE_FRACT(P_FIELD)    ! IN Fraction of gridbox which is sea-ice.    STDEV7A.56     
     &,RHOKM_1(P_FIELD)      ! IN Surface momentum exchange coefficient.   STDEV7A.57     
     &,RHOSTAR(P_FIELD)      ! IN Surface air density.                     STDEV7A.58     
     &,VSHR(P_FIELD)         ! IN Magnitude of surface-to-lowest-level     STDEV7A.59     
!                            !    wind shear.                              STDEV7A.60     
     &,Z0MSEA(P_FIELD)       ! IN Sea roughness length.                    STDEV7A.61     
     &,Z0_ICE(P_FIELD)       ! IN Sea-ice roughness length.                STDEV7A.62     
     &,Z1_TQ(P_FIELD)        ! IN Height of lowest tq level.               STDEV7A.63     
                                                                           STDEV7A.64     
      REAL                                                                 STDEV7A.65     
     & Q1_SD(P_FIELD)        ! OUT Standard deviation of turbulent         STDEV7A.66     
!                            !     fluctuations of surface layer           STDEV7A.67     
!                            !     specific humidity (kg/kg).              STDEV7A.68     
     &,T1_SD(P_FIELD)        ! OUT Standard deviation of turbulent         STDEV7A.69     
!                            !     fluctuations of surface layer           STDEV7A.70     
!                            !     temperature (K).                        STDEV7A.71     
                                                                           STDEV7A.72     
*CALL C_G                                                                  STDEV7A.73     
                                                                           STDEV7A.74     
!  Workspace --------------------------------------------------------      STDEV7A.75     
      INTEGER                                                              STDEV7A.76     
     & I                     ! Loop counter (horizontal field index).      STDEV7A.77     
      REAL                                                                 STDEV7A.78     
     & VS                    ! Surface layer friction velocity             STDEV7A.79     
     &,VSF1_CUBED            ! Cube of surface layer free convective       STDEV7A.80     
!                            ! scaling velocity                            STDEV7A.81     
     &,WS1                   ! Turbulent velocity scale for surface        STDEV7A.82     
!                            ! layer                                       STDEV7A.83     
     &,Z0                    ! Roughness length                            STDEV7A.84     
                                                                           STDEV7A.85     
      IF (LTIMER) THEN                                                     STDEV7A.86     
        CALL TIMER('STDEV1  ',3)                                           STDEV7A.87     
      ENDIF                                                                STDEV7A.88     
                                                                           STDEV7A.89     
      DO I=P1,P1+P_POINTS-1                                                STDEV7A.90     
        IF ( .NOT.LAND_MASK(I) ) THEN                                      STDEV7A.91     
                                                                           STDEV7A.92     
          Z0 = Z0MSEA(I)                                                   STDEV7A.93     
          IF ( ICE_FRACT(I) .GT. 0. ) Z0 = Z0_ICE(I)                       STDEV7A.94     
          VS = SQRT ( RHOKM_1(I)/RHOSTAR(I) * VSHR(I) )                    STDEV7A.95     
          VSF1_CUBED = 1.25*G*(Z1_TQ(I) + Z0) *                            STDEV7A.96     
     &                ( BT_1(I)*FTL_1(I) + BQ_1(I)*FQW_1(I) )/RHOSTAR(I)   STDEV7A.97     
          IF ( VSF1_CUBED .GT. 0.0 ) THEN                                  STDEV7A.98     
            WS1 = ( VSF1_CUBED + VS*VS*VS ) ** (1.0/3.0)                   STDEV7A.99     
            T1_SD(I) = MAX ( 0.0 , 1.93*FTL_1(I) / (RHOSTAR(I)*WS1) )      STDEV7A.100    
            Q1_SD(I) = MAX ( 0.0 , 1.93*FQW_1(I) / (RHOSTAR(I)*WS1) )      STDEV7A.101    
          ENDIF                                                            STDEV7A.102    
                                                                           STDEV7A.103    
        ENDIF                                                              STDEV7A.104    
      ENDDO                                                                STDEV7A.105    
                                                                           STDEV7A.106    
      IF (LTIMER) THEN                                                     STDEV7A.107    
        CALL TIMER('STDEV1  ',4)                                           STDEV7A.108    
      ENDIF                                                                STDEV7A.109    
                                                                           STDEV7A.110    
      RETURN                                                               STDEV7A.111    
      END                                                                  STDEV7A.112    
                                                                           STDEV7A.113    
!!!  SUBROUTINE STDEV1_LAND --------------------------------------------   STDEV7A.114    
!!!  Layer 1 standard deviations for land tiles                            STDEV7A.115    
!!!  -------------------------------------------------------------------   STDEV7A.116    

      SUBROUTINE STDEV1_LAND (                                              1,2STDEV7A.117    
     & P_FIELD,LAND_FIELD,TILE_PTS,LAND_INDEX,TILE_INDEX,                  STDEV7A.118    
     & BQ_1,BT_1,FQW_1,FTL_1,RHOKM_1,RHOSTAR,VSHR,Z0M,Z1_TQ,               STDEV7A.119    
     & Q1_SD,T1_SD,LTIMER                                                  STDEV7A.120    
     & )                                                                   STDEV7A.121    
                                                                           STDEV7A.122    
      IMPLICIT NONE                                                        STDEV7A.123    
                                                                           STDEV7A.124    
      INTEGER                                                              STDEV7A.125    
     & P_FIELD               ! IN Total number of P-grid points.           STDEV7A.126    
     &,LAND_FIELD            ! IN Total number of land points.             STDEV7A.127    
     &,TILE_PTS              ! IN Number of tile points.                   STDEV7A.128    
     &,LAND_INDEX(P_FIELD)   ! IN Index of land points.                    STDEV7A.129    
     &,TILE_INDEX(LAND_FIELD)! IN Index of tile points.                    STDEV7A.130    
                                                                           STDEV7A.131    
      LOGICAL                                                              STDEV7A.132    
     & LTIMER                ! IN logical for TIMER                        STDEV7A.133    
                                                                           STDEV7A.134    
      REAL                                                                 STDEV7A.135    
     & BQ_1(P_FIELD)         ! IN Buoyancy parameter.                      STDEV7A.136    
     &,BT_1(P_FIELD)         ! IN Buoyancy parameter.                      STDEV7A.137    
     &,FQW_1(LAND_FIELD)     ! IN Surface flux of QW.                      STDEV7A.138    
     &,FTL_1(LAND_FIELD)     ! IN Surface flux of TL.                      STDEV7A.139    
     &,RHOKM_1(LAND_FIELD)   ! IN Surface momentum exchange coefficient.   STDEV7A.140    
     &,RHOSTAR(P_FIELD)      ! IN Surface air density.                     STDEV7A.141    
     &,VSHR(P_FIELD)         ! IN Magnitude of surface-to-lowest-level     STDEV7A.142    
!                            !    wind shear.                              STDEV7A.143    
     &,Z0M(LAND_FIELD)       ! IN Roughness length for momentum.           STDEV7A.144    
     &,Z1_TQ(P_FIELD)        ! IN Height of lowest tq level.               STDEV7A.145    
                                                                           STDEV7A.146    
      REAL                                                                 STDEV7A.147    
     & Q1_SD(P_FIELD)        ! INOUT Standard deviation of turbulent       STDEV7A.148    
!                            !       fluctuations of surface layer         STDEV7A.149    
!                            !       specific humidity (kg/kg).            STDEV7A.150    
     &,T1_SD(P_FIELD)        ! INOUT Standard deviation of turbulent       STDEV7A.151    
!                            !       fluctuations of surface layer         STDEV7A.152    
!                            !       temperature (K).                      STDEV7A.153    
                                                                           STDEV7A.154    
*CALL C_G                                                                  STDEV7A.155    
                                                                           STDEV7A.156    
!  Workspace --------------------------------------------------------      STDEV7A.157    
      INTEGER                                                              STDEV7A.158    
     & I                     ! Horizontal field index.                     STDEV7A.159    
     &,J                     ! Tile index.                                 STDEV7A.160    
     &,L                     ! Land field inde.                            STDEV7A.161    
      REAL                                                                 STDEV7A.162    
     & VS                    ! Surface layer friction velocity             STDEV7A.163    
     &,VSF1_CUBED            ! Cube of surface layer free convective       STDEV7A.164    
!                            ! scaling velocity                            STDEV7A.165    
     &,WS1                   ! Turbulent velocity scale for surface        STDEV7A.166    
!                            ! layer                                       STDEV7A.167    
                                                                           STDEV7A.168    
      IF (LTIMER) THEN                                                     STDEV7A.169    
        CALL TIMER('STDEV1  ',3)                                           STDEV7A.170    
      ENDIF                                                                STDEV7A.171    
                                                                           STDEV7A.172    
      DO J=1,TILE_PTS                                                      STDEV7A.173    
        L = TILE_INDEX(J)                                                  STDEV7A.174    
        I = LAND_INDEX(L)                                                  STDEV7A.175    
                                                                           STDEV7A.176    
        VS = SQRT ( RHOKM_1(L)/RHOSTAR(I) * VSHR(I) )                      STDEV7A.177    
        VSF1_CUBED = 1.25*G*(Z1_TQ(I) + Z0M(L)) *                          STDEV7A.178    
     &             ( BT_1(I)*FTL_1(L) + BQ_1(I)*FQW_1(L) )/RHOSTAR(I)      STDEV7A.179    
        IF ( VSF1_CUBED .GT. 0.0 ) THEN                                    STDEV7A.180    
          WS1 = ( VSF1_CUBED + VS*VS*VS ) ** (1.0/3.0)                     STDEV7A.181    
          T1_SD(I) = MAX ( 0.0 , T1_SD(I),                                 STDEV7A.182    
     &                     1.93*FTL_1(L) / (RHOSTAR(I)*WS1) )              STDEV7A.183    
          Q1_SD(I) = MAX ( 0.0 , Q1_SD(I),                                 STDEV7A.184    
     &                     1.93*FQW_1(L) / (RHOSTAR(I)*WS1) )              STDEV7A.185    
        ELSE                                                               STDEV7A.186    
          T1_SD(I) = MAX(T1_SD(I), 0.0)                                    STDEV7A.187    
          Q1_SD(I) = MAX(Q1_SD(I), 0.0)                                    STDEV7A.188    
        ENDIF                                                              STDEV7A.189    
                                                                           STDEV7A.190    
      ENDDO                                                                STDEV7A.191    
                                                                           STDEV7A.192    
      IF (LTIMER) THEN                                                     STDEV7A.193    
        CALL TIMER('STDEV1  ',4)                                           STDEV7A.194    
      ENDIF                                                                STDEV7A.195    
                                                                           STDEV7A.196    
      RETURN                                                               STDEV7A.197    
      END                                                                  STDEV7A.198    
*ENDIF                                                                     STDEV7A.199