updated top-level README and version_decl for V4.5 (#1847)
[WRF.git] / phys / module_sf_sfclay.F
blob2b3ba578f0a3a87bf874b074c96e4ff7b9f2b315
1 !WRF:MODEL_LAYER:PHYSICS
3 MODULE module_sf_sfclay
5  REAL    , PARAMETER ::  VCONVC=1.
6  REAL    , PARAMETER ::  CZO=0.0185
7  REAL    , PARAMETER ::  OZO=1.59E-5
9  REAL,   DIMENSION(0:1000 ),SAVE          :: PSIMTB,PSIHTB
11 CONTAINS
13 !-------------------------------------------------------------------
14    SUBROUTINE SFCLAY(U3D,V3D,T3D,QV3D,P3D,dz8w,                    &
15                      CP,G,ROVCP,R,XLV,PSFC,CHS,CHS2,CQS2,CPM,      &
16                      ZNT,UST,PBLH,MAVAIL,ZOL,MOL,REGIME,PSIM,PSIH, &
17                      FM,FH,                                        &
18                      XLAND,HFX,QFX,LH,TSK,FLHC,FLQC,QGH,QSFC,RMOL, &
19                      U10,V10,TH2,T2,Q2,                            &
20                      GZ1OZ0,WSPD,BR,ISFFLX,DX,                     &
21                      SVP1,SVP2,SVP3,SVPT0,EP1,EP2,                 &
22                      KARMAN,EOMEG,STBOLT,                          &
23                      P1000mb,                                      &
24                      ids,ide, jds,jde, kds,kde,                    &
25                      ims,ime, jms,jme, kms,kme,                    &
26                      its,ite, jts,jte, kts,kte,                    &
27                      ustm,ck,cka,cd,cda,                           &
28                      isftcflx,iz0tlnd,scm_force_flux)
29 !-------------------------------------------------------------------
30       IMPLICIT NONE
31 !-------------------------------------------------------------------
32 !   Changes in V3.7 over water surfaces: 
33 !          1. for ZNT/Cd, replacing constant OZO with 0.11*1.5E-5/UST(I)
34 !             the COARE 3.5 (Edson et al. 2013) formulation is also available
35 !          2. for VCONV, reducing magnitude by half
36 !          3. for Ck, replacing Carlson-Boland with COARE 3
37 !-------------------------------------------------------------------
38 !-- U3D         3D u-velocity interpolated to theta points (m/s)
39 !-- V3D         3D v-velocity interpolated to theta points (m/s)
40 !-- T3D         temperature (K)
41 !-- QV3D        3D water vapor mixing ratio (Kg/Kg)
42 !-- P3D         3D pressure (Pa)
43 !-- dz8w        dz between full levels (m)
44 !-- CP          heat capacity at constant pressure for dry air (J/kg/K)
45 !-- G           acceleration due to gravity (m/s^2)
46 !-- ROVCP       R/CP
47 !-- R           gas constant for dry air (J/kg/K)
48 !-- XLV         latent heat of vaporization for water (J/kg)
49 !-- PSFC        surface pressure (Pa)
50 !-- ZNT         roughness length (m)
51 !-- UST         u* in similarity theory (m/s)
52 !-- USTM        u* in similarity theory (m/s) without vconv correction
53 !               used to couple with TKE scheme
54 !-- PBLH        PBL height from previous time (m)
55 !-- MAVAIL      surface moisture availability (between 0 and 1)
56 !-- ZOL         z/L height over Monin-Obukhov length
57 !-- MOL         T* (similarity theory) (K)
58 !-- REGIME      flag indicating PBL regime (stable, unstable, etc.)
59 !-- PSIM        similarity stability function for momentum
60 !-- PSIH        similarity stability function for heat
61 !-- FM          integrated stability function for momentum
62 !-- FH          integrated stability function for heat
63 !-- XLAND       land mask (1 for land, 2 for water)
64 !-- HFX         upward heat flux at the surface (W/m^2)
65 !-- QFX         upward moisture flux at the surface (kg/m^2/s)
66 !-- LH          net upward latent heat flux at surface (W/m^2)
67 !-- TSK         surface temperature (K)
68 !-- FLHC        exchange coefficient for heat (W/m^2/K)
69 !-- FLQC        exchange coefficient for moisture (kg/m^2/s)
70 !-- CHS         heat/moisture exchange coefficient for LSM (m/s)
71 !-- QGH         lowest-level saturated mixing ratio
72 !-- QSFC        ground saturated mixing ratio
73 !-- U10         diagnostic 10m u wind
74 !-- V10         diagnostic 10m v wind
75 !-- TH2         diagnostic 2m theta (K)
76 !-- T2          diagnostic 2m temperature (K)
77 !-- Q2          diagnostic 2m mixing ratio (kg/kg)
78 !-- GZ1OZ0      log(z/z0) where z0 is roughness length
79 !-- WSPD        wind speed at lowest model level (m/s)
80 !-- BR          bulk Richardson number in surface layer
81 !-- ISFFLX      isfflx=1 for surface heat and moisture fluxes
82 !-- DX          horizontal grid size (m)
83 !-- SVP1        constant for saturation vapor pressure (kPa)
84 !-- SVP2        constant for saturation vapor pressure (dimensionless)
85 !-- SVP3        constant for saturation vapor pressure (K)
86 !-- SVPT0       constant for saturation vapor pressure (K)
87 !-- EP1         constant for virtual temperature (R_v/R_d - 1) (dimensionless)
88 !-- EP2         constant for specific humidity calculation 
89 !               (R_d/R_v) (dimensionless)
90 !-- KARMAN      Von Karman constant
91 !-- EOMEG       angular velocity of earth's rotation (rad/s)
92 !-- STBOLT      Stefan-Boltzmann constant (W/m^2/K^4)
93 !-- ck          enthalpy exchange coeff at 10 meters
94 !-- cd          momentum exchange coeff at 10 meters
95 !-- cka         enthalpy exchange coeff at the lowest model level
96 !-- cda         momentum exchange coeff at the lowest model level
97 !-- isftcflx    =0, (Charnock and Carlson-Boland); =1, AHW Ck, Cd, =2 Garratt
98 !-- iz0tlnd     =0 Carlson-Boland, =1 Czil_new
99 !-- ids         start index for i in domain
100 !-- ide         end index for i in domain
101 !-- jds         start index for j in domain
102 !-- jde         end index for j in domain
103 !-- kds         start index for k in domain
104 !-- kde         end index for k in domain
105 !-- ims         start index for i in memory
106 !-- ime         end index for i in memory
107 !-- jms         start index for j in memory
108 !-- jme         end index for j in memory
109 !-- kms         start index for k in memory
110 !-- kme         end index for k in memory
111 !-- its         start index for i in tile
112 !-- ite         end index for i in tile
113 !-- jts         start index for j in tile
114 !-- jte         end index for j in tile
115 !-- kts         start index for k in tile
116 !-- kte         end index for k in tile
117 !-------------------------------------------------------------------
118       INTEGER,  INTENT(IN )   ::        ids,ide, jds,jde, kds,kde, &
119                                         ims,ime, jms,jme, kms,kme, &
120                                         its,ite, jts,jte, kts,kte
121 !                                                               
122       INTEGER,  INTENT(IN )   ::        ISFFLX
123       REAL,     INTENT(IN )   ::        SVP1,SVP2,SVP3,SVPT0
124       REAL,     INTENT(IN )   ::        EP1,EP2,KARMAN,EOMEG,STBOLT
125       REAL,     INTENT(IN )   ::        P1000mb
127       REAL,     DIMENSION( ims:ime, kms:kme, jms:jme )           , &
128                 INTENT(IN   )   ::                           dz8w
129                                         
130       REAL,     DIMENSION( ims:ime, kms:kme, jms:jme )           , &
131                 INTENT(IN   )   ::                           QV3D, &
132                                                               P3D, &
133                                                               T3D
135       REAL,     DIMENSION( ims:ime, jms:jme )                    , &
136                 INTENT(IN   )               ::             MAVAIL, &
137                                                              PBLH, &
138                                                             XLAND, &
139                                                               TSK
141       REAL,     DIMENSION( ims:ime, jms:jme )                    , &
142                 INTENT(INOUT)               ::             REGIME, &
143                                                               HFX, &
144                                                               QFX, &
145                                                                LH, &
146                                                           MOL,RMOL
148       REAL,     DIMENSION( ims:ime, jms:jme )                    , &
149                 INTENT(INOUT)   ::                 GZ1OZ0,WSPD,BR, &
150                                                   PSIM,PSIH,FM,FH
152       REAL,     DIMENSION( ims:ime, kms:kme, jms:jme )           , &
153                 INTENT(IN   )   ::                            U3D, &
154                                                               V3D
155                                         
156       REAL,     DIMENSION( ims:ime, jms:jme )                    , &
157                 INTENT(IN   )               ::               PSFC
159       REAL,     DIMENSION( ims:ime, jms:jme )                    , &
160                 INTENT(INOUT)   ::                            ZNT, &
161                                                               ZOL, &
162                                                               UST, &
163                                                               CPM, &
164                                                              CHS2, &
165                                                              CQS2, &
166                                                               CHS
168       REAL,     DIMENSION( ims:ime, jms:jme )                    , &
169                 INTENT(INOUT)   ::                      FLHC,FLQC
171       REAL,     DIMENSION( ims:ime, jms:jme )                    , &
172                 INTENT(INOUT)   ::                                 &
173                                                               QGH
174       REAL,     INTENT(IN   )               ::   CP,G,ROVCP,R,XLV
176       REAL,     DIMENSION( ims:ime, jms:jme )                    , &
177                 INTENT(IN   )               ::                 DX
179       REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme )              , &
180                 INTENT(OUT)     ::                  ck,cka,cd,cda
182       REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme )              , &
183                 INTENT(INOUT)   ::                           USTM
185       INTEGER,  OPTIONAL,  INTENT(IN )   ::     ISFTCFLX, IZ0TLND
186       INTEGER,  OPTIONAL,  INTENT(IN )   ::     SCM_FORCE_FLUX
188       REAL,     DIMENSION( ims:ime, jms:jme )                    , &
189                 INTENT(INOUT  )             ::               QSFC
191       REAL,     DIMENSION( ims:ime, jms:jme )                    , &
192                 INTENT(OUT  )               ::                U10, &
193                                                               V10, &
194                                                               TH2, &
195                                                                T2, &
196                                                                Q2
198 ! LOCAL VARS
200       REAL,     DIMENSION( its:ite ) ::                       U1D, &
201                                                               V1D, &
202                                                              QV1D, &
203                                                               P1D, &
204                                                               T1D
206       REAL,     DIMENSION( its:ite ) ::                    dz8w1d
208       REAL,     DIMENSION( its:ite ) ::                      DX2D
210       INTEGER ::  I,J
212       DO J=jts,jte
214         DO i=its,ite
215            DX2D(i)=DX(i,j)
216         ENDDO
218         DO i=its,ite
219           dz8w1d(I) = dz8w(i,1,j)
220         ENDDO
221    
222         DO i=its,ite
223            U1D(i) =U3D(i,1,j)
224            V1D(i) =V3D(i,1,j)
225            QV1D(i)=QV3D(i,1,j)
226            P1D(i) =P3D(i,1,j)
227            T1D(i) =T3D(i,1,j)
228         ENDDO
230         !  Sending array starting locations of optional variables may cause
231         !  troubles, so we explicitly change the call.
233         CALL SFCLAY1D(J,U1D,V1D,T1D,QV1D,P1D,dz8w1d,               &
234                 CP,G,ROVCP,R,XLV,PSFC(ims,j),CHS(ims,j),CHS2(ims,j),&
235                 CQS2(ims,j),CPM(ims,j),PBLH(ims,j), RMOL(ims,j),   &
236                 ZNT(ims,j),UST(ims,j),MAVAIL(ims,j),ZOL(ims,j),    &
237                 MOL(ims,j),REGIME(ims,j),PSIM(ims,j),PSIH(ims,j),  &
238                 FM(ims,j),FH(ims,j),                               &
239                 XLAND(ims,j),HFX(ims,j),QFX(ims,j),TSK(ims,j),     &
240                 U10(ims,j),V10(ims,j),TH2(ims,j),T2(ims,j),        &
241                 Q2(ims,j),FLHC(ims,j),FLQC(ims,j),QGH(ims,j),      &
242                 QSFC(ims,j),LH(ims,j),                             &
243                 GZ1OZ0(ims,j),WSPD(ims,j),BR(ims,j),ISFFLX,DX2D,   &
244                 SVP1,SVP2,SVP3,SVPT0,EP1,EP2,KARMAN,EOMEG,STBOLT,  &
245                 P1000mb,                                           &
246                 ids,ide, jds,jde, kds,kde,                         &
247                 ims,ime, jms,jme, kms,kme,                         &
248                 its,ite, jts,jte, kts,kte                          &
249 #if ( ( EM_CORE == 1 ) || ( defined(mpas) ) )
250                 ,isftcflx,iz0tlnd,scm_force_flux,                  &
251                 USTM(ims,j),CK(ims,j),CKA(ims,j),                  &
252                 CD(ims,j),CDA(ims,j)                               &
253 #endif
254                                                                    )
255       ENDDO
258    END SUBROUTINE SFCLAY
261 !-------------------------------------------------------------------
262    SUBROUTINE SFCLAY1D(J,UX,VX,T1D,QV1D,P1D,dz8w1d,                &
263                      CP,G,ROVCP,R,XLV,PSFCPA,CHS,CHS2,CQS2,CPM,PBLH,RMOL, &
264                      ZNT,UST,MAVAIL,ZOL,MOL,REGIME,PSIM,PSIH,FM,FH,&
265                      XLAND,HFX,QFX,TSK,                            &
266                      U10,V10,TH2,T2,Q2,FLHC,FLQC,QGH,              &
267                      QSFC,LH,GZ1OZ0,WSPD,BR,ISFFLX,DX,             &
268                      SVP1,SVP2,SVP3,SVPT0,EP1,EP2,                 &
269                      KARMAN,EOMEG,STBOLT,                          &
270                      P1000mb,                                      &
271                      ids,ide, jds,jde, kds,kde,                    &
272                      ims,ime, jms,jme, kms,kme,                    &
273                      its,ite, jts,jte, kts,kte,                    &
274                      isftcflx, iz0tlnd, scm_force_flux,            &
275                      ustm,ck,cka,cd,cda                            )
276 !-------------------------------------------------------------------
277       IMPLICIT NONE
278 !-------------------------------------------------------------------
279       REAL,     PARAMETER     ::        XKA=2.4E-5
280       REAL,     PARAMETER     ::        PRT=1.
282       INTEGER,  INTENT(IN )   ::        ids,ide, jds,jde, kds,kde, &
283                                         ims,ime, jms,jme, kms,kme, &
284                                         its,ite, jts,jte, kts,kte, &
285                                         J
286 !                                                               
287       INTEGER,  INTENT(IN )   ::        ISFFLX
288       REAL,     INTENT(IN )   ::        SVP1,SVP2,SVP3,SVPT0
289       REAL,     INTENT(IN )   ::        EP1,EP2,KARMAN,EOMEG,STBOLT
290       REAL,     INTENT(IN )   ::        P1000mb
293       REAL,     DIMENSION( ims:ime )                             , &
294                 INTENT(IN   )               ::             MAVAIL, &
295                                                              PBLH, &
296                                                             XLAND, &
297                                                               TSK
299       REAL,     DIMENSION( ims:ime )                             , &
300                 INTENT(IN   )               ::             PSFCPA
302       REAL,     DIMENSION( ims:ime )                             , &
303                 INTENT(INOUT)               ::             REGIME, &
304                                                               HFX, &
305                                                               QFX, &
306                                                          MOL,RMOL
307 !m the following 5 are changed to memory size---
309       REAL,     DIMENSION( ims:ime )                             , &
310                 INTENT(INOUT)   ::                 GZ1OZ0,WSPD,BR, &
311                                                   PSIM,PSIH,FM,FH
313       REAL,     DIMENSION( ims:ime )                             , &
314                 INTENT(INOUT)   ::                            ZNT, &
315                                                               ZOL, &
316                                                               UST, &
317                                                               CPM, &
318                                                              CHS2, &
319                                                              CQS2, &
320                                                               CHS
322       REAL,     DIMENSION( ims:ime )                             , &
323                 INTENT(INOUT)   ::                      FLHC,FLQC
325       REAL,     DIMENSION( ims:ime )                             , &
326                 INTENT(INOUT)   ::                                 &
327                                                          QSFC,QGH
329       REAL,     DIMENSION( ims:ime )                             , &
330                 INTENT(OUT)     ::                        U10,V10, &
331                                                      TH2,T2,Q2,LH
333       REAL,     INTENT(IN   )               ::   CP,G,ROVCP,R,XLV
335       REAL,     DIMENSION( its:ite ),  INTENT(IN   )   ::      DX
337 ! MODULE-LOCAL VARIABLES, DEFINED IN SUBROUTINE SFCLAY
338       REAL,     DIMENSION( its:ite ),  INTENT(IN   )   ::  dz8w1d
340       REAL,     DIMENSION( its:ite ),  INTENT(IN   )   ::      UX, &
341                                                                VX, &
342                                                              QV1D, &
343                                                               P1D, &
344                                                               T1D
346       REAL, OPTIONAL, DIMENSION( ims:ime )                       , &
347                 INTENT(OUT)     ::                  ck,cka,cd,cda
348       REAL, OPTIONAL, DIMENSION( ims:ime )                       , &
349                 INTENT(INOUT)   ::                           USTM
351       INTEGER,  OPTIONAL,  INTENT(IN )   ::     ISFTCFLX, IZ0TLND
352       INTEGER,  OPTIONAL,  INTENT(IN )   ::     SCM_FORCE_FLUX
354 ! LOCAL VARS
356       REAL,     DIMENSION( its:ite )        ::                 ZA, &
357                                                         THVX,ZQKL, &
358                                                            ZQKLP1, &
359                                                            THX,QX, &
360                                                             PSIH2, &
361                                                             PSIM2, &
362                                                            PSIH10, &
363                                                            PSIM10, &
364                                                            DENOMQ, &
365                                                           DENOMQ2, &
366                                                           DENOMT2, &
367                                                             WSPDI, &
368                                                            GZ2OZ0, &
369                                                            GZ10OZ0
371       REAL,     DIMENSION( its:ite )        ::                     &
372                                                       RHOX,GOVRTH, &
373                                                             TGDSA
375       REAL,     DIMENSION( its:ite)         ::          SCR3,SCR4
376       REAL,     DIMENSION( its:ite )        ::         THGB, PSFC
378       INTEGER                               ::                 KL
380       INTEGER ::  N,I,K,KK,L,NZOL,NK,NZOL2,NZOL10
382       REAL    ::  PL,THCON,TVCON,E1
383       REAL    ::  ZL,TSKV,DTHVDZ,DTHVM,VCONV,RZOL,RZOL2,RZOL10,ZOL2,ZOL10
384       REAL    ::  DTG,PSIX,DTTHX,PSIX10,PSIT,PSIT2,PSIQ,PSIQ2,PSIQ10
385       REAL    ::  FLUXC,VSGD,Z0Q,VISC,RESTAR,CZIL,GZ0OZQ,GZ0OZT
386       REAL    ::  ZW, ZN1, ZN2
387       REAL    ::  Z0T, CZC
388 !-------------------------------------------------------------------
389       KL=kte
391       DO i=its,ite
392 ! PSFC cb
393          PSFC(I)=PSFCPA(I)/1000.
394       ENDDO
395 !                                                      
396 !----CONVERT GROUND TEMPERATURE TO POTENTIAL TEMPERATURE:  
397 !                                                            
398       DO 5 I=its,ite                                   
399         TGDSA(I)=TSK(I)                                    
400 ! PSFC cb
401 !        THGB(I)=TSK(I)*(100./PSFC(I))**ROVCP                
402         THGB(I)=TSK(I)*(P1000mb/PSFCPA(I))**ROVCP   
403     5 CONTINUE                                               
404 !                                                            
405 !-----DECOUPLE FLUX-FORM VARIABLES TO GIVE U,V,T,THETA,THETA-VIR.,
406 !     T-VIR., QV, AND QC AT CROSS POINTS AND AT KTAU-1.  
407 !                                                                 
408 !     *** NOTE ***                                           
409 !         THE BOUNDARY WINDS MAY NOT BE ADEQUATELY AFFECTED BY FRICTION,         
410 !         SO USE ONLY INTERIOR VALUES OF UX AND VX TO CALCULATE 
411 !         TENDENCIES.                             
412 !                                                           
413    10 CONTINUE                                                     
415 !     DO 24 I=its,ite
416 !        UX(I)=U1D(I)
417 !        VX(I)=V1D(I)
418 !  24 CONTINUE                                             
419                                                              
420    26 CONTINUE                                               
421                                                    
422 !.....SCR3(I,K) STORE TEMPERATURE,                           
423 !     SCR4(I,K) STORE VIRTUAL TEMPERATURE.                                       
424                                                                                  
425       DO 30 I=its,ite
426 ! PL cb
427          PL=P1D(I)/1000.
428          SCR3(I)=T1D(I)                                                   
429 !         THCON=(100./PL)**ROVCP                                                 
430          THCON=(P1000mb*0.001/PL)**ROVCP
431          THX(I)=SCR3(I)*THCON                                               
432          SCR4(I)=SCR3(I)                                                    
433          THVX(I)=THX(I)                                                     
434          QX(I)=0.                                                             
435    30 CONTINUE                                                                 
436 !                                                                                
437       DO I=its,ite
438          QGH(I)=0.                                                                
439          FLHC(I)=0.                                                               
440          FLQC(I)=0.                                                               
441          CPM(I)=CP                                                                
442       ENDDO
443 !                                                                                
444 !     IF(IDRY.EQ.1)GOTO 80                                                   
445       DO 50 I=its,ite
446          QX(I)=QV1D(I)                                                    
447          TVCON=(1.+EP1*QX(I))                                      
448          THVX(I)=THX(I)*TVCON                                               
449          SCR4(I)=SCR3(I)*TVCON                                              
450    50 CONTINUE                                                                 
451 !                                                                                
452       DO 60 I=its,ite
453         E1=SVP1*EXP(SVP2*(TGDSA(I)-SVPT0)/(TGDSA(I)-SVP3))                       
454 !  for land points QSFC can come from previous time step
455         if(xland(i).gt.1.5.or.qsfc(i).le.0.0)QSFC(I)=EP2*E1/(PSFC(I)-E1)                                                 
456 ! QGH CHANGED TO USE LOWEST-LEVEL AIR TEMP CONSISTENT WITH MYJSFC CHANGE
457 ! Q2SAT = QGH IN LSM
458         E1=SVP1*EXP(SVP2*(T1D(I)-SVPT0)/(T1D(I)-SVP3))                       
459         PL=P1D(I)/1000.
460         QGH(I)=EP2*E1/(PL-E1)                                                 
461         CPM(I)=CP*(1.+0.8*QX(I))                                   
462    60 CONTINUE                                                                   
463    80 CONTINUE
464                                                                                  
465 !-----COMPUTE THE HEIGHT OF FULL- AND HALF-SIGMA LEVELS ABOVE GROUND             
466 !     LEVEL, AND THE LAYER THICKNESSES.                                          
467                                                                                  
468       DO 90 I=its,ite
469         ZQKLP1(I)=0.
470         RHOX(I)=PSFC(I)*1000./(R*SCR4(I))                                       
471    90 CONTINUE                                                                   
472 !                                                                                
473       DO 110 I=its,ite                                                   
474            ZQKL(I)=dz8w1d(I)+ZQKLP1(I)
475   110 CONTINUE                                                                 
476 !                                                                                
477       DO 120 I=its,ite
478          ZA(I)=0.5*(ZQKL(I)+ZQKLP1(I))                                        
479   120 CONTINUE                                                                 
480 !                                                                                
481       DO 160 I=its,ite
482         GOVRTH(I)=G/THX(I)                                                    
483   160 CONTINUE                                                                   
484                                                                                  
485 !-----CALCULATE BULK RICHARDSON NO. OF SURFACE LAYER, ACCORDING TO               
486 !     AKB(1976), EQ(12).                                                         
487                    
488       DO 260 I=its,ite
489         GZ1OZ0(I)=ALOG(ZA(I)/ZNT(I))                                        
490         GZ2OZ0(I)=ALOG(2./ZNT(I))                                        
491         GZ10OZ0(I)=ALOG(10./ZNT(I))                                        
492         IF((XLAND(I)-1.5).GE.0)THEN                                            
493           ZL=ZNT(I)                                                            
494         ELSE                                                                     
495           ZL=0.01                                                                
496         ENDIF                                                                    
497         WSPD(I)=SQRT(UX(I)*UX(I)+VX(I)*VX(I))                        
499         TSKV=THGB(I)*(1.+EP1*QSFC(I))                     
500         DTHVDZ=(THVX(I)-TSKV)                                                 
501 !  Convective velocity scale Vc and subgrid-scale velocity Vsg
502 !  following Beljaars (1994, QJRMS) and Mahrt and Sun (1995, MWR)
503 !                                ... HONG Aug. 2001
505 !       VCONV = 0.25*sqrt(g/tskv*pblh(i)*dthvm)
506 !      Use Beljaars over land, old MM5 (Wyngaard) formula over water
507         if (xland(i).lt.1.5) then
508         fluxc = max(hfx(i)/rhox(i)/cp                    &
509               + ep1*tskv*qfx(i)/rhox(i),0.)
510         VCONV = vconvc*(g/tgdsa(i)*pblh(i)*fluxc)**.33
511         else
512         IF(-DTHVDZ.GE.0)THEN
513           DTHVM=-DTHVDZ
514         ELSE
515           DTHVM=0.
516         ENDIF
517 !       VCONV = 2.*SQRT(DTHVM)
518 ! V3.7: reducing contribution in calm conditions
519         VCONV = SQRT(DTHVM)
520         endif
521 ! Mahrt and Sun low-res correction
522         VSGD = 0.32 * (max(dx(i)/5000.-1.,0.))**.33
523         WSPD(I)=SQRT(WSPD(I)*WSPD(I)+VCONV*VCONV+vsgd*vsgd)
524         WSPD(I)=AMAX1(WSPD(I),0.1)
525         BR(I)=GOVRTH(I)*ZA(I)*DTHVDZ/(WSPD(I)*WSPD(I))                        
526 !  IF PREVIOUSLY UNSTABLE, DO NOT LET INTO REGIMES 1 AND 2
527         IF(MOL(I).LT.0.)BR(I)=AMIN1(BR(I),0.0)
528 !jdf
529         RMOL(I)=-GOVRTH(I)*DTHVDZ*ZA(I)*KARMAN
530 !jdf
532   260 CONTINUE                                                                   
534 !                                                                                
535 !-----DIAGNOSE BASIC PARAMETERS FOR THE APPROPRIATED STABILITY CLASS:            
536 !                                                                                
537 !                                                                                
538 !     THE STABILITY CLASSES ARE DETERMINED BY BR (BULK RICHARDSON NO.)           
539 !     AND HOL (HEIGHT OF PBL/MONIN-OBUKHOV LENGTH).                              
540 !                                                                                
541 !     CRITERIA FOR THE CLASSES ARE AS FOLLOWS:                                   
542 !                                                                                
543 !        1. BR .GE. 0.2;                                                         
544 !               REPRESENTS NIGHTTIME STABLE CONDITIONS (REGIME=1),               
545 !                                                                                
546 !        2. BR .LT. 0.2 .AND. BR .GT. 0.0;                                       
547 !               REPRESENTS DAMPED MECHANICAL TURBULENT CONDITIONS                
548 !               (REGIME=2),                                                      
549 !                                                                                
550 !        3. BR .EQ. 0.0                                                          
551 !               REPRESENTS FORCED CONVECTION CONDITIONS (REGIME=3),              
552 !                                                                                
553 !        4. BR .LT. 0.0                                                          
554 !               REPRESENTS FREE CONVECTION CONDITIONS (REGIME=4).                
555 !                                                                                
556 !CCCCC                                                                           
558       DO 320 I=its,ite
559 !CCCCC                                                                           
560 !CC     REMOVE REGIME 3 DEPENDENCE ON PBL HEIGHT                                 
561 !CC          IF(BR(I).LT.0..AND.HOL(I,J).GT.1.5)GOTO 310                         
562         IF(BR(I).LT.0.)GOTO 310                                                  
563 !                                                                                
564 !-----CLASS 1; STABLE (NIGHTTIME) CONDITIONS:                                    
565 !                                                                                
566         IF(BR(I).LT.0.2)GOTO 270                                                 
567         REGIME(I)=1.                                                           
568         PSIM(I)=-10.*GZ1OZ0(I)                                                   
569 !    LOWER LIMIT ON PSI IN STABLE CONDITIONS                                     
570         PSIM(I)=AMAX1(PSIM(I),-10.)                                              
571         PSIH(I)=PSIM(I)                                                          
572         PSIM10(I)=10./ZA(I)*PSIM(I)
573         PSIM10(I)=AMAX1(PSIM10(I),-10.)                               
574         PSIH10(I)=PSIM10(I)                                          
575         PSIM2(I)=2./ZA(I)*PSIM(I)
576         PSIM2(I)=AMAX1(PSIM2(I),-10.)                              
577         PSIH2(I)=PSIM2(I)                                         
579 !       1.0 over Monin-Obukhov length
580         IF(UST(I).LT.0.01)THEN
581            RMOL(I)=BR(I)*GZ1OZ0(I) !ZA/L
582         ELSE
583            RMOL(I)=KARMAN*GOVRTH(I)*ZA(I)*MOL(I)/(UST(I)*UST(I)) !ZA/L
584         ENDIF
585         RMOL(I)=AMIN1(RMOL(I),9.999) ! ZA/L
586         RMOL(I) = RMOL(I)/ZA(I) !1.0/L
588         GOTO 320                                                                 
589 !                                                                                
590 !-----CLASS 2; DAMPED MECHANICAL TURBULENCE:                                     
591 !                                                                                
592   270   IF(BR(I).EQ.0.0)GOTO 280                                                 
593         REGIME(I)=2.                                                           
594         PSIM(I)=-5.0*BR(I)*GZ1OZ0(I)/(1.1-5.0*BR(I))                             
595 !    LOWER LIMIT ON PSI IN STABLE CONDITIONS                                     
596         PSIM(I)=AMAX1(PSIM(I),-10.)                                              
597 !.....AKB(1976), EQ(16).                                                         
598         PSIH(I)=PSIM(I)                                                          
599         PSIM10(I)=10./ZA(I)*PSIM(I)
600         PSIM10(I)=AMAX1(PSIM10(I),-10.)                               
601         PSIH10(I)=PSIM10(I)                                          
602         PSIM2(I)=2./ZA(I)*PSIM(I)
603         PSIM2(I)=AMAX1(PSIM2(I),-10.)                              
604         PSIH2(I)=PSIM2(I)                                         
606         ! Linear form: PSIM = -0.5*ZA/L; e.g, see eqn 16 of
607         ! Blackadar, Modeling the nocturnal boundary layer, Preprints,
608         ! Third Symposium on Atmospheric Turbulence Diffusion and Air Quality,
609         ! Raleigh, NC, 1976
610         ZOL(I) = BR(I)*GZ1OZ0(I)/(1.00001-5.0*BR(I))
612         if ( ZOL(I) .GT. 0.5 ) then ! linear form ok
613            ! Holtslag and de Bruin, J. App. Meteor 27, 689-704, 1988;
614            ! see also, Launiainen, Boundary-Layer Meteor 76,165-179, 1995
615            ! Eqn (8) of Launiainen, 1995
616            ZOL(I) = ( 1.89*GZ1OZ0(I) + 44.2 ) * BR(I)*BR(I)    &
617                 + ( 1.18*GZ1OZ0(I) - 1.37 ) * BR(I)
618            ZOL(I)=AMIN1(ZOL(I),9.999)
619         end if
621         ! 1.0 over Monin-Obukhov length
622         RMOL(I)= ZOL(I)/ZA(I)
624         GOTO 320                                                                 
625 !                                                                                
626 !-----CLASS 3; FORCED CONVECTION:                                                
627 !                                                                                
628   280   REGIME(I)=3.                                                           
629         PSIM(I)=0.0                                                              
630         PSIH(I)=PSIM(I)                                                          
631         PSIM10(I)=0.                                                   
632         PSIH10(I)=PSIM10(I)                                           
633         PSIM2(I)=0.                                                  
634         PSIH2(I)=PSIM2(I)                                           
636                                                                                  
637         IF(UST(I).LT.0.01)THEN                                                 
638           ZOL(I)=BR(I)*GZ1OZ0(I)                                               
639         ELSE                                                                     
640           ZOL(I)=KARMAN*GOVRTH(I)*ZA(I)*MOL(I)/(UST(I)*UST(I)) 
641         ENDIF                                                                    
643         RMOL(I) = ZOL(I)/ZA(I)  
645         GOTO 320                                                                 
646 !                                                                                
647 !-----CLASS 4; FREE CONVECTION:                                                  
648 !                                                                                
649   310   CONTINUE                                                                 
650         REGIME(I)=4.                                                           
651         IF(UST(I).LT.0.01)THEN                                                 
652           ZOL(I)=BR(I)*GZ1OZ0(I)                                               
653         ELSE                                                                     
654           ZOL(I)=KARMAN*GOVRTH(I)*ZA(I)*MOL(I)/(UST(I)*UST(I))
655         ENDIF                                                                    
656         ZOL10=10./ZA(I)*ZOL(I)                                    
657         ZOL2=2./ZA(I)*ZOL(I)                                     
658         ZOL(I)=AMIN1(ZOL(I),0.)                                              
659         ZOL(I)=AMAX1(ZOL(I),-9.9999)                                         
660         ZOL10=AMIN1(ZOL10,0.)                                          
661         ZOL10=AMAX1(ZOL10,-9.9999)                                    
662         ZOL2=AMIN1(ZOL2,0.)                                          
663         ZOL2=AMAX1(ZOL2,-9.9999)                                    
664         NZOL=INT(-ZOL(I)*100.)                                                 
665         RZOL=-ZOL(I)*100.-NZOL                                                 
666         NZOL10=INT(-ZOL10*100.)                                        
667         RZOL10=-ZOL10*100.-NZOL10                                     
668         NZOL2=INT(-ZOL2*100.)                                        
669         RZOL2=-ZOL2*100.-NZOL2                                      
670         PSIM(I)=PSIMTB(NZOL)+RZOL*(PSIMTB(NZOL+1)-PSIMTB(NZOL))                  
671         PSIH(I)=PSIHTB(NZOL)+RZOL*(PSIHTB(NZOL+1)-PSIHTB(NZOL))                  
672         PSIM10(I)=PSIMTB(NZOL10)+RZOL10*(PSIMTB(NZOL10+1)-PSIMTB(NZOL10))                                                    
673         PSIH10(I)=PSIHTB(NZOL10)+RZOL10*(PSIHTB(NZOL10+1)-PSIHTB(NZOL10))
674         PSIM2(I)=PSIMTB(NZOL2)+RZOL2*(PSIMTB(NZOL2+1)-PSIMTB(NZOL2))    
675         PSIH2(I)=PSIHTB(NZOL2)+RZOL2*(PSIHTB(NZOL2+1)-PSIHTB(NZOL2))   
677 !---LIMIT PSIH AND PSIM IN THE CASE OF THIN LAYERS AND HIGH ROUGHNESS            
678 !---  THIS PREVENTS DENOMINATOR IN FLUXES FROM GETTING TOO SMALL                 
679 !       PSIH(I)=AMIN1(PSIH(I),0.9*GZ1OZ0(I))                                     
680 !       PSIM(I)=AMIN1(PSIM(I),0.9*GZ1OZ0(I))                                     
681         PSIH(I)=AMIN1(PSIH(I),0.9*GZ1OZ0(I))
682         PSIM(I)=AMIN1(PSIM(I),0.9*GZ1OZ0(I))
683         PSIH2(I)=AMIN1(PSIH2(I),0.9*GZ2OZ0(I))
684         PSIM10(I)=AMIN1(PSIM10(I),0.9*GZ10OZ0(I))
685 ! AHW: mods to compute ck, cd
686         PSIH10(I)=AMIN1(PSIH10(I),0.9*GZ10OZ0(I))
688         RMOL(I) = ZOL(I)/ZA(I)  
690   320 CONTINUE                                                                   
691 !                                                                                
692 !-----COMPUTE THE FRICTIONAL VELOCITY:                                           
693 !     ZA(1982) EQS(2.60),(2.61).                                                 
694 !                                                                                
695       DO 330 I=its,ite
696         DTG=THX(I)-THGB(I)                                                   
697         PSIX=GZ1OZ0(I)-PSIM(I)                                                   
698         PSIX10=GZ10OZ0(I)-PSIM10(I)
699 !     LOWER LIMIT ADDED TO PREVENT LARGE FLHC IN SOIL MODEL
700 !     ACTIVATES IN UNSTABLE CONDITIONS WITH THIN LAYERS OR HIGH Z0
701         PSIT=AMAX1(GZ1OZ0(I)-PSIH(I),2.)
703         IF((XLAND(I)-1.5).GE.0)THEN                                            
704           ZL=ZNT(I)                                                            
705         ELSE                                                                     
706           ZL=0.01                                                                
707         ENDIF                                                                    
708         PSIQ=ALOG(KARMAN*UST(I)*ZA(I)/XKA+ZA(I)/ZL)-PSIH(I)   
709         PSIT2=GZ2OZ0(I)-PSIH2(I)                                     
710         PSIQ2=ALOG(KARMAN*UST(I)*2./XKA+2./ZL)-PSIH2(I)                                   
711 ! AHW: mods to compute ck, cd
712         PSIQ10=ALOG(KARMAN*UST(I)*10./XKA+10./ZL)-PSIH10(I)
714 ! V3.7: using Fairall 2003 to compute z0q and z0t over water:
715 !       adapted from module_sf_mynn.F
716         IF ( (XLAND(I)-1.5).GE.0. ) THEN
717               VISC=(1.32+0.009*(SCR3(I)-273.15))*1.E-5
718 !             VISC=1.326e-5*(1. + 6.542e-3*SCR3(I) + 8.301e-6*SCR3(I)*SCR3(I) &
719 !                 - 4.84e-9*SCR3(I)*SCR3(I)*SCR3(I))
720               RESTAR=UST(I)*ZNT(I)/VISC
721               Z0T = (5.5e-5)*(RESTAR**(-0.60))
722               Z0T = MIN(Z0T,1.0e-4)
723               Z0T = MAX(Z0T,2.0e-9)
724               Z0Q = Z0T
726               PSIQ=max(ALOG((ZA(I)+Z0Q)/Z0Q)-PSIH(I), 2.)
727               PSIT=max(ALOG((ZA(I)+Z0T)/Z0T)-PSIH(I), 2.)
728               PSIQ2=max(ALOG((2.+Z0Q)/Z0Q)-PSIH2(I), 2.)
729               PSIT2=max(ALOG((2.+Z0T)/Z0T)-PSIH2(I), 2.)
730               PSIQ10=max(ALOG((10.+Z0Q)/Z0Q)-PSIH10(I), 2.)
731         ENDIF
733         IF ( PRESENT(ISFTCFLX) ) THEN
734            IF ( ISFTCFLX.EQ.1 .AND. (XLAND(I)-1.5).GE.0. ) THEN
735 ! v3.1
736 !             Z0Q = 1.e-4 + 1.e-3*(MAX(0.,UST(I)-1.))**2
737 ! hfip1
738 !             Z0Q = 0.62*2.0E-5/UST(I) + 1.E-3*(MAX(0.,UST(I)-1.5))**2
739 ! v3.2
740               Z0Q = 1.e-4
741               PSIQ=ALOG(ZA(I)/Z0Q)-PSIH(I)
742               PSIT=PSIQ
743               PSIQ2=ALOG(2./Z0Q)-PSIH2(I)
744               PSIQ10=ALOG(10./Z0Q)-PSIH10(I)
745               PSIT2=PSIQ2
746            ENDIF
747            IF ( ISFTCFLX.EQ.2 .AND. (XLAND(I)-1.5).GE.0. ) THEN
748 ! AHW: Garratt formula: Calculate roughness Reynolds number
749 !        Kinematic viscosity of air (linear approc to
750 !                 temp dependence at sea level)
751 ! GZ0OZT and GZ0OZQ are based off formulas from Brutsaert (1975), which
752 ! Garratt (1992) used with values of k = 0.40, Pr = 0.71, and Sc = 0.60
753               VISC=(1.32+0.009*(SCR3(I)-273.15))*1.E-5
754 !!            VISC=1.5E-5
755               RESTAR=UST(I)*ZNT(I)/VISC
756               GZ0OZT=0.40*(7.3*SQRT(SQRT(RESTAR))*SQRT(0.71)-5.)
757               GZ0OZQ=0.40*(7.3*SQRT(SQRT(RESTAR))*SQRT(0.60)-5.)
758               PSIT=GZ1OZ0(I)-PSIH(I)+GZ0OZT
759               PSIQ=GZ1OZ0(I)-PSIH(I)+GZ0OZQ
760               PSIT2=GZ2OZ0(I)-PSIH2(I)+GZ0OZT
761               PSIQ2=GZ2OZ0(I)-PSIH2(I)+GZ0OZQ
762               PSIQ10=GZ10OZ0(I)-PSIH(I)+GZ0OZQ
763            ENDIF
764         ENDIF
765         IF(PRESENT(ck) .and. PRESENT(cd) .and. PRESENT(cka) .and. PRESENT(cda)) THEN
766            Ck(I)=(karman/psix10)*(karman/psiq10)
767            Cd(I)=(karman/psix10)*(karman/psix10)
768            Cka(I)=(karman/psix)*(karman/psiq)
769            Cda(I)=(karman/psix)*(karman/psix)
770         ENDIF
771         IF ( PRESENT(IZ0TLND) ) THEN
772            IF ( IZ0TLND.GE.1 .AND. (XLAND(I)-1.5).LE.0. ) THEN
773               ZL=ZNT(I)
774 !             CZIL RELATED CHANGES FOR LAND
775               VISC=(1.32+0.009*(SCR3(I)-273.15))*1.E-5
776               RESTAR=UST(I)*ZL/VISC
777 !             Modify CZIL according to Chen & Zhang, 2009 if iz0tlnd = 1
778 !             If iz0tlnd = 2, use traditional value
780               IF ( IZ0TLND.EQ.1 ) THEN
781                  CZIL = 10.0 ** ( -0.40 * ( ZL / 0.07 ) )
782               ELSE IF ( IZ0TLND.EQ.2 ) THEN
783                  CZIL = 0.1
784               END IF
786               PSIT=GZ1OZ0(I)-PSIH(I)+CZIL*KARMAN*SQRT(RESTAR)
787               PSIQ=GZ1OZ0(I)-PSIH(I)+CZIL*KARMAN*SQRT(RESTAR)
788               PSIT2=GZ2OZ0(I)-PSIH2(I)+CZIL*KARMAN*SQRT(RESTAR)
789               PSIQ2=GZ2OZ0(I)-PSIH2(I)+CZIL*KARMAN*SQRT(RESTAR)
791            ENDIF
792         ENDIF
793 ! TO PREVENT OSCILLATIONS AVERAGE WITH OLD VALUE 
794         UST(I)=0.5*UST(I)+0.5*KARMAN*WSPD(I)/PSIX                                             
795 ! TKE coupling: compute ust without vconv for use in tke scheme
796         WSPDI(I)=SQRT(UX(I)*UX(I)+VX(I)*VX(I))
797         IF ( PRESENT(USTM) ) THEN
798         USTM(I)=0.5*USTM(I)+0.5*KARMAN*WSPDI(I)/PSIX
799         ENDIF
800         U10(I)=UX(I)*PSIX10/PSIX                                    
801         V10(I)=VX(I)*PSIX10/PSIX                                   
802         TH2(I)=THGB(I)+DTG*PSIT2/PSIT                                
803         Q2(I)=QSFC(I)+(QX(I)-QSFC(I))*PSIQ2/PSIQ                   
804 !        T2(I) = TH2(I)*(PSFC(I)/100.)**ROVCP                     
805         T2(I) = TH2(I)*(PSFCPA(I)/P1000mb)**ROVCP                     
806 !       LATER Q2 WILL BE OVERWRITTEN FOR LAND POINTS IN SURFCE     
807 !       QA2(I,J) = Q2(I)                                         
808 !       UA10(I,J) = U10(I)                                      
809 !       VA10(I,J) = V10(I)                                     
810 !       write(*,1002)UST(I),KARMAN*WSPD(I),PSIX,KARMAN*WSPD(I)/PSIX
811 !                                                                                
812         IF((XLAND(I)-1.5).LT.0.)THEN                                            
813           UST(I)=AMAX1(UST(I),0.1)
814         ENDIF                                                                    
815         MOL(I)=KARMAN*DTG/PSIT/PRT                              
816         DENOMQ(I)=PSIQ
817         DENOMQ2(I)=PSIQ2
818         DENOMT2(I)=PSIT2
819         FM(I)=PSIX
820         FH(I)=PSIT
821   330 CONTINUE                                                                   
822 !                                                                                
823   335 CONTINUE                                                                   
824                                                                                   
825 !-----COMPUTE THE SURFACE SENSIBLE AND LATENT HEAT FLUXES:                       
826       IF ( PRESENT(SCM_FORCE_FLUX) ) THEN
827          IF (SCM_FORCE_FLUX.EQ.1) GOTO 350              
828       ENDIF
829       DO i=its,ite
830         QFX(i)=0.                                                              
831         HFX(i)=0.                                                              
832       ENDDO
833   350 CONTINUE
835       IF (ISFFLX.EQ.0) GOTO 410                                                
836                                                                                  
837 !-----OVER WATER, ALTER ROUGHNESS LENGTH (ZNT) ACCORDING TO WIND (UST).
838                                                                                  
839       DO 360 I=its,ite
840         IF((XLAND(I)-1.5).GE.0)THEN                                            
841 !         ZNT(I)=CZO*UST(I)*UST(I)/G+OZO                                   
842 ! Since V3.7 (ref: EC Physics document for Cy36r1)
843           ZNT(I)=CZO*UST(I)*UST(I)/G+0.11*1.5E-5/UST(I)
844 ! V3.9: Add limit as in isftcflx = 1,2
845           ZNT(I)=MIN(ZNT(I),2.85e-3)
846 ! COARE 3.5 (Edson et al. 2013)
847 !         CZC = 0.0017*WSPD(I)-0.005
848 !         CZC = min(CZC,0.028)
849 !         ZNT(I)=CZC*UST(I)*UST(I)/G+0.11*1.5E-5/UST(I)
850 ! AHW: change roughness length, and hence the drag coefficients Ck and Cd
851           IF ( PRESENT(ISFTCFLX) ) THEN
852              IF ( ISFTCFLX.NE.0 ) THEN
853 !               ZNT(I)=10.*exp(-9.*UST(I)**(-.3333))
854 !               ZNT(I)=10.*exp(-9.5*UST(I)**(-.3333))
855 !               ZNT(I)=ZNT(I) + 0.11*1.5E-5/AMAX1(UST(I),0.01)
856 !               ZNT(I)=0.011*UST(I)*UST(I)/G+OZO
857 !               ZNT(I)=MAX(ZNT(I),3.50e-5)
858 ! AHW 2012:
859                 ZW  = MIN((UST(I)/1.06)**(0.3),1.0)
860                 ZN1 = 0.011*UST(I)*UST(I)/G + OZO
861                 ZN2 = 10.*exp(-9.5*UST(I)**(-.3333)) + &
862                        0.11*1.5E-5/AMAX1(UST(I),0.01)
863                 ZNT(I)=(1.0-ZW) * ZN1 + ZW * ZN2
864                 ZNT(I)=MIN(ZNT(I),2.85e-3)
865                 ZNT(I)=MAX(ZNT(I),1.27e-7)
866              ENDIF
867           ENDIF
868           ZL = ZNT(I)
869         ELSE
870           ZL = 0.01
871         ENDIF                                                                    
872         FLQC(I)=RHOX(I)*MAVAIL(I)*UST(I)*KARMAN/DENOMQ(I)
873 !       FLQC(I)=RHOX(I)*MAVAIL(I)*UST(I)*KARMAN/(   &
874 !               ALOG(KARMAN*UST(I)*ZA(I)/XKA+ZA(I)/ZL)-PSIH(I))
875         DTTHX=ABS(THX(I)-THGB(I))                                            
876         IF(DTTHX.GT.1.E-5)THEN                                                   
877           FLHC(I)=CPM(I)*RHOX(I)*UST(I)*MOL(I)/(THX(I)-THGB(I))          
878 !         write(*,1001)FLHC(I),CPM(I),RHOX(I),UST(I),MOL(I),THX(I),THGB(I),I
879  1001   format(f8.5,2x,f12.7,2x,f12.10,2x,f12.10,2x,f13.10,2x,f12.8,f12.8,2x,i3)
880         ELSE                                                                     
881           FLHC(I)=0.                                                             
882         ENDIF                                                                    
883   360 CONTINUE
885 !                                                                                
886 !-----COMPUTE SURFACE MOIST FLUX:                                               
888 !     IF(IDRY.EQ.1)GOTO 390
889      IF ( PRESENT(SCM_FORCE_FLUX) ) THEN
890         IF (SCM_FORCE_FLUX.EQ.1) GOTO 405                                     
891      ENDIF
892 !                                                                               
893       DO 370 I=its,ite
894         QFX(I)=FLQC(I)*(QSFC(I)-QX(I))                                     
895         QFX(I)=AMAX1(QFX(I),0.)                                            
896         LH(I)=XLV*QFX(I)
897   370 CONTINUE                                                                 
898                                                                                 
899 !-----COMPUTE SURFACE HEAT FLUX:                                                 
900 !                                                                                
901   390 CONTINUE                                                                 
902       DO 400 I=its,ite
903         IF(XLAND(I)-1.5.GT.0.)THEN                                           
904           HFX(I)=FLHC(I)*(THGB(I)-THX(I))                                
905 !         IF ( PRESENT(ISFTCFLX) ) THEN
906 !            IF ( ISFTCFLX.NE.0 ) THEN
907 ! AHW: add dissipative heating term (commented out in 3.6.1)
908 !               HFX(I)=HFX(I)+RHOX(I)*USTM(I)*USTM(I)*WSPDI(I)
909 !            ENDIF
910 !         ENDIF
911         ELSEIF(XLAND(I)-1.5.LT.0.)THEN                                       
912           HFX(I)=FLHC(I)*(THGB(I)-THX(I))                                
913           HFX(I)=AMAX1(HFX(I),-250.)                                       
914         ENDIF                                                                  
915   400 CONTINUE                                                                 
917   405 CONTINUE                                                                 
918          
919       DO I=its,ite
920          IF((XLAND(I)-1.5).GE.0)THEN
921            ZL=ZNT(I)
922          ELSE
923            ZL=0.01
924          ENDIF
925          CHS(I)=UST(I)*KARMAN/DENOMQ(I)
926 !        GZ2OZ0(I)=ALOG(2./ZNT(I))
927 !        PSIM2(I)=-10.*GZ2OZ0(I)
928 !        PSIM2(I)=AMAX1(PSIM2(I),-10.)
929 !        PSIH2(I)=PSIM2(I)
930          CQS2(I)=UST(I)*KARMAN/DENOMQ2(I)
931          CHS2(I)=UST(I)*KARMAN/DENOMT2(I)
932       ENDDO
933                                                                         
934   410 CONTINUE                                                                   
935 !jdf
936 !     DO I=its,ite
937 !       IF(UST(I).GE.0.1) THEN
938 !         RMOL(I)=RMOL(I)*(-FLHC(I))/(UST(I)*UST(I)*UST(I))
939 !       ELSE
940 !         RMOL(I)=RMOL(I)*(-FLHC(I))/(0.1*0.1*0.1)
941 !       ENDIF
942 !     ENDDO
943 !jdf
945 !                                                                                
946    END SUBROUTINE SFCLAY1D
948 !====================================================================
949    SUBROUTINE sfclayinit( allowed_to_read )         
951    LOGICAL , INTENT(IN)      ::      allowed_to_read
952    INTEGER                   ::      N
953    REAL                      ::      ZOLN,X,Y
955    DO N=0,1000
956       ZOLN=-FLOAT(N)*0.01
957       X=(1-16.*ZOLN)**0.25
958       PSIMTB(N)=2*ALOG(0.5*(1+X))+ALOG(0.5*(1+X*X))- &
959                 2.*ATAN(X)+2.*ATAN(1.)
960       Y=(1-16*ZOLN)**0.5
961       PSIHTB(N)=2*ALOG(0.5*(1+Y))
962    ENDDO
964    END SUBROUTINE sfclayinit
966 !-------------------------------------------------------------------          
968 END MODULE module_sf_sfclay