source: LMDZ6/trunk/libf/phylmdiso/climb_hq_mod.F90 @ 4128

Last change on this file since 4128 was 4124, checked in by dcugnet, 3 years ago

Remove solsym, ok_isotopes (=niso>0), ok_isotrac (=nzone>0)

  • Property svn:keywords set to Id
File size: 28.1 KB
Line 
1MODULE climb_hq_mod
2!
3! Module to solve the verctical diffusion of "q" and "H";
4! specific humidity and potential energi.
5!
6  USE dimphy
7#ifdef ISO
8  USE infotrac_phy, ONLY: ntraciso ! ajout C Risi pour isos     
9#endif
10
11  IMPLICIT NONE
12  SAVE
13  PRIVATE
14  PUBLIC :: climb_hq_down, climb_hq_up, d_h_col_vdf, f_h_bnd
15
16  REAL, DIMENSION(:,:), ALLOCATABLE :: gamaq, gamah
17  !$OMP THREADPRIVATE(gamaq,gamah)
18  REAL, DIMENSION(:,:), ALLOCATABLE :: Ccoef_Q, Dcoef_Q
19  !$OMP THREADPRIVATE(Ccoef_Q, Dcoef_Q)
20  REAL, DIMENSION(:,:), ALLOCATABLE :: Ccoef_H, Dcoef_H
21  !$OMP THREADPRIVATE(Ccoef_H, Dcoef_H)
22  REAL, DIMENSION(:), ALLOCATABLE   :: Acoef_Q, Bcoef_Q
23  !$OMP THREADPRIVATE(Acoef_Q, Bcoef_Q)
24  REAL, DIMENSION(:), ALLOCATABLE   :: Acoef_H, Bcoef_H
25  !$OMP THREADPRIVATE(Acoef_H, Bcoef_H)
26  REAL, DIMENSION(:,:), ALLOCATABLE :: Kcoefhq
27  !$OMP THREADPRIVATE(Kcoefhq)
28  REAL, SAVE, DIMENSION(:,:), ALLOCATABLE :: h_old ! for diagnostics, h before solving diffusion
29  !$OMP THREADPRIVATE(h_old)
30  REAL, SAVE, DIMENSION(:), ALLOCATABLE :: d_h_col_vdf ! for diagnostics, vertical integral of enthalpy change
31  !$OMP THREADPRIVATE(d_h_col_vdf)
32  REAL, SAVE, DIMENSION(:), ALLOCATABLE :: f_h_bnd ! for diagnostics, enthalpy flux at surface
33  !$OMP THREADPRIVATE(f_h_bnd)
34#ifdef ISO
35  REAL, DIMENSION(:,:,:), ALLOCATABLE :: gamaxt
36  !$OMP THREADPRIVATE(gamaxt)
37  REAL, DIMENSION(:,:,:), ALLOCATABLE :: Ccoef_XT, Dcoef_XT
38  !$OMP THREADPRIVATE(Ccoef_XT, Dcoef_XT)
39  REAL, DIMENSION(:,:), ALLOCATABLE   :: Acoef_XT, Bcoef_XT
40  !$OMP THREADPRIVATE(Acoef_XT, Bcoef_XT)
41#endif
42
43CONTAINS
44!
45!****************************************************************************************
46!
47  SUBROUTINE climb_hq_down(knon, coefhq, paprs, pplay, &
48       delp, temp, q, dtime, &
49!!! nrlmd le 02/05/2011
50       Ccoef_H_out, Ccoef_Q_out, Dcoef_H_out, Dcoef_Q_out, &
51       Kcoef_hq_out, gama_q_out, gama_h_out, &
52!!!
53       Acoef_H_out, Acoef_Q_out, Bcoef_H_out, Bcoef_Q_out &
54#ifdef ISO
55            ,xt,  &
56       Ccoef_XT_out,Dcoef_XT_out,gama_xt_out,  &
57       Acoef_XT_out, Bcoef_XT_out &
58#endif               
59            )
60#ifdef ISOVERIF
61!USE infotrac_phy, ONLY: use_iso
62USE isotopes_mod, ONLY: iso_eau,iso_HDO
63!USE isotopes_verif_mod, ONLY: errmax, errmaxrel
64USE isotopes_verif_mod
65#endif
66
67! This routine calculates recursivly the coefficients C and D
68! for the quantity X=[Q,H] in equation X(k) = C(k) + D(k)*X(k-1), where k is
69! the index of the vertical layer.
70!
71! Input arguments
72!****************************************************************************************
73    INTEGER, INTENT(IN)                      :: knon
74    REAL, DIMENSION(klon,klev), INTENT(IN)   :: coefhq
75    REAL, DIMENSION(klon,klev), INTENT(IN)   :: pplay
76    REAL, DIMENSION(klon,klev+1), INTENT(IN) :: paprs
77    REAL, DIMENSION(klon,klev), INTENT(IN)   :: temp, delp  ! temperature
78    REAL, DIMENSION(klon,klev), INTENT(IN)   :: q
79    REAL, INTENT(IN)                         :: dtime
80#ifdef ISO
81    REAL, DIMENSION(ntraciso,klon,klev), INTENT(IN)   :: xt
82#endif
83
84
85! Output arguments
86!****************************************************************************************
87    REAL, DIMENSION(klon), INTENT(OUT)       :: Acoef_H_out
88    REAL, DIMENSION(klon), INTENT(OUT)       :: Acoef_Q_out
89    REAL, DIMENSION(klon), INTENT(OUT)       :: Bcoef_H_out
90    REAL, DIMENSION(klon), INTENT(OUT)       :: Bcoef_Q_out
91#ifdef ISO
92    REAL, DIMENSION(ntraciso,klon), INTENT(OUT)       :: Acoef_XT_out
93    REAL, DIMENSION(ntraciso,klon), INTENT(OUT)       :: Bcoef_XT_out
94#endif
95
96!!! nrlmd le 02/05/2011
97    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Ccoef_H_out
98    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Ccoef_Q_out
99    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Dcoef_H_out
100    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Dcoef_Q_out
101    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Kcoef_hq_out
102    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: gama_q_out
103    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: gama_h_out
104#ifdef ISO
105    REAL, DIMENSION(ntraciso,klon,klev), INTENT(OUT)  :: Ccoef_XT_out
106    REAL, DIMENSION(ntraciso,klon,klev), INTENT(OUT)  :: Dcoef_XT_out
107    REAL, DIMENSION(ntraciso,klon,klev), INTENT(OUT)  :: gama_xt_out
108#endif
109!!!
110
111! Local variables
112!****************************************************************************************
113    LOGICAL, SAVE                            :: first=.TRUE.
114    !$OMP THREADPRIVATE(first)
115! JLD now renamed h_old and declared in module
116!    REAL, DIMENSION(klon,klev)               :: local_H
117    REAL, DIMENSION(klon)                    :: psref
118    REAL                                     :: delz, pkh
119    INTEGER                                  :: k, i, ierr
120
121#ifdef ISO
122    real, DIMENSION(klon,2:klev) :: gamaxt_tmp
123    real, DIMENSION(klon,klev) :: xt_tmp
124    real, DIMENSION(klon,klev) ::  Ccoef_XT_tmp,Dcoef_XT_tmp
125    real, DIMENSION(klon) ::  Acoef_XT_tmp,Bcoef_XT_tmp
126    integer ixt
127#endif
128! Include
129!****************************************************************************************
130    INCLUDE "YOMCST.h"
131    INCLUDE "compbl.h"   
132   
133#ifdef ISO
134#ifdef ISOVERIF
135   if (iso_eau.gt.0) then
136       do k = 1, klev
137          DO i = 1, knon
138            call iso_verif_egalite_choix( &
139                xt(iso_eau,i,k),q(i,k), &
140                'climb_hq 100',errmax,errmaxrel)
141          enddo
142       enddo
143   endif ! if (iso_eau.gt.0) then
144#endif
145#endif
146
147!****************************************************************************************
148! 1)
149! Allocation at first time step only
150!   
151!****************************************************************************************
152
153    IF (first) THEN
154       first=.FALSE.
155       ALLOCATE(Ccoef_Q(klon,klev), STAT=ierr)
156       IF ( ierr /= 0 )  PRINT*,' pb in allloc Ccoef_Q, ierr=', ierr
157       
158       ALLOCATE(Dcoef_Q(klon,klev), STAT=ierr)
159       IF ( ierr /= 0 )  PRINT*,' pb in allloc Dcoef_Q, ierr=', ierr
160       
161       ALLOCATE(Ccoef_H(klon,klev), STAT=ierr)
162       IF ( ierr /= 0 )  PRINT*,' pb in allloc Ccoef_H, ierr=', ierr
163       
164       ALLOCATE(Dcoef_H(klon,klev), STAT=ierr)
165       IF ( ierr /= 0 )  PRINT*,' pb in allloc Dcoef_H, ierr=', ierr
166       
167       ALLOCATE(Acoef_Q(klon), Bcoef_Q(klon), Acoef_H(klon), Bcoef_H(klon), STAT=ierr)
168       IF ( ierr /= 0 )  PRINT*,' pb in allloc Acoef_X and Bcoef_X, ierr=', ierr
169       
170       ALLOCATE(Kcoefhq(klon,klev), STAT=ierr)
171       IF ( ierr /= 0 )  PRINT*,' pb in allloc Kcoefhq, ierr=', ierr
172       
173       ALLOCATE(gamaq(1:klon,2:klev), STAT=ierr)
174       IF ( ierr /= 0 ) PRINT*,' pb in allloc gamaq, ierr=', ierr
175       
176       ALLOCATE(gamah(1:klon,2:klev), STAT=ierr)
177       IF ( ierr /= 0 ) PRINT*,' pb in allloc gamah, ierr=', ierr
178
179#ifdef ISO
180       ALLOCATE(Ccoef_XT(ntraciso,klon,klev), STAT=ierr)
181       IF ( ierr /= 0 )  PRINT*,' pb in allloc Ccoef_XT, ierr=', ierr
182       
183       ALLOCATE(Dcoef_XT(ntraciso,klon,klev), STAT=ierr)
184       IF ( ierr /= 0 )  PRINT*,' pb in allloc Dcoef_XT, ierr=', ierr
185       
186       ALLOCATE(Acoef_XT(ntraciso,klon), Bcoef_XT(ntraciso,klon), STAT=ierr)
187       IF ( ierr /= 0 )  PRINT*,' pb in allloc Acoef_XT and Bcoef_XT, ierr=', ierr
188       
189        ALLOCATE(gamaxt(ntraciso,1:klon,2:klev), STAT=ierr)
190       IF ( ierr /= 0 ) PRINT*,' pb in allloc gamaxt, ierr=', ierr
191#endif
192       
193       ALLOCATE(h_old(klon,klev), STAT=ierr)
194       IF ( ierr /= 0 )  PRINT*,' pb in allloc h_old, ierr=', ierr
195       
196       ALLOCATE(d_h_col_vdf(klon), STAT=ierr)
197       IF ( ierr /= 0 )  PRINT*,' pb in allloc d_h_col_vdf, ierr=', ierr
198       
199       ALLOCATE(f_h_bnd(klon), STAT=ierr)
200       IF ( ierr /= 0 )  PRINT*,' pb in allloc f_h_bnd, ierr=', ierr
201    END IF
202
203!****************************************************************************************
204! 2)
205! Definition of the coeficient K
206!
207!****************************************************************************************
208    Kcoefhq(:,:) = 0.0
209    DO k = 2, klev
210       DO i = 1, knon
211          Kcoefhq(i,k) = &
212               coefhq(i,k)*RG*RG*dtime /(pplay(i,k-1)-pplay(i,k)) &
213               *(paprs(i,k)*2/(temp(i,k)+temp(i,k-1))/RD)**2
214       ENDDO
215    ENDDO
216
217!****************************************************************************************
218! 3)
219! Calculation of gama for "Q" and "H"
220!
221!****************************************************************************************
222!   surface pressure is used as reference
223    psref(:) = paprs(:,1)
224
225!   definition of gama
226    IF (iflag_pbl == 1) THEN
227       gamaq(:,:) = 0.0
228       gamah(:,:) = -1.0e-03
229       gamah(:,2) = -2.5e-03
230#ifdef ISO
231       do ixt=1,ntraciso
232        gamaxt(:,:,:) = 0.0
233       enddo ! do ixt=1,ntraciso
234#endif
235 
236! conversion de gama
237       DO k = 2, klev
238          DO i = 1, knon
239             delz = RD * (temp(i,k-1)+temp(i,k)) / &
240                    2.0 / RG / paprs(i,k) * (pplay(i,k-1)-pplay(i,k))
241             pkh  = (psref(i)/paprs(i,k))**RKAPPA
242         
243! convertie gradient verticale d'humidite specifique en difference d'humidite specifique entre centre de couches
244             gamaq(i,k) = gamaq(i,k) * delz   
245! convertie gradient verticale de temperature en difference de temperature potentielle entre centre de couches
246             gamah(i,k) = gamah(i,k) * delz * RCPD * pkh
247#ifdef ISO
248             do ixt=1,ntraciso
249              gamaxt(ixt,i,k) = gamaxt(ixt,i,k) * delz
250             enddo
251#endif
252          ENDDO
253       ENDDO
254
255    ELSE
256       gamaq(:,:) = 0.0
257       gamah(:,:) = 0.0
258#ifdef ISO
259       do ixt=1,ntraciso
260        gamaxt(:,:,:) = 0.0
261       enddo ! do ixt=1,ntraciso
262#endif
263    ENDIF
264   
265#ifdef ISO
266#ifdef ISOVERIF
267        do k = 2, klev
268          DO i = 1, knon
269            call iso_verif_egalite_choix( &
270                gamaxt(iso_eau,i,k),gamaq(i,k), &
271                'climb_hq 209',errmax,errmaxrel)
272          enddo
273       enddo
274#endif
275#endif
276   
277
278!****************************************************************************************   
279! 4)
280! Calculte the coefficients C and D for specific humidity, q
281!
282!****************************************************************************************
283   
284    CALL calc_coef(knon, Kcoefhq(:,:), gamaq(:,:), delp(:,:), q(:,:), &
285         Ccoef_Q(:,:), Dcoef_Q(:,:), Acoef_Q, Bcoef_Q)
286
287
288#ifdef ISO
289        do ixt=1,ntraciso       
290        ! compression
291        do k = 2, klev
292          DO i = 1, knon
293            gamaxt_tmp(i,k)=gamaxt(ixt,i,k)
294          enddo
295        enddo !do k = 2, klev
296        do k = 1, klev
297          DO i = 1, knon
298            xt_tmp(i,k)=xt(ixt,i,k)
299          enddo
300        enddo !do k = 2, klev
301        !appel routine generique
302          CALL calc_coef(knon, Kcoefhq(:,:), gamaxt_tmp(:,:), delp(:,:), xt_tmp(:,:), &
303                Ccoef_XT_tmp(:,:), Dcoef_XT_tmp(:,:), Acoef_XT_tmp, Bcoef_XT_tmp) 
304
305        ! decompression
306        do k = 1, klev
307          DO i = 1, knon
308            Ccoef_XT(ixt,i,k)=Ccoef_XT_tmp(i,k)
309            Dcoef_XT(ixt,i,k)=Dcoef_XT_tmp(i,k)
310          enddo
311        enddo !do k = 2, klev
312        DO i = 1, knon
313            Acoef_XT(ixt,i)=Acoef_XT_tmp(i)
314            Bcoef_XT(ixt,i)=Bcoef_XT_tmp(i)
315        enddo
316       enddo ! do ixt=1,ntraciso
317#ifdef ISOVERIF
318        if (iso_eau.gt.0) then
319         do k = 1, klev
320          DO i = 1, knon
321            call iso_verif_egalite_choix( &
322                Ccoef_XT(iso_eau,i,k),Ccoef_Q(i,k), &
323                        'climb_hq 234c',errmax,errmaxrel)
324            call iso_verif_egalite_choix( &
325                Dcoef_XT(iso_eau,i,k),Dcoef_Q(i,k), &
326                        'climb_hq 234d',errmax,errmaxrel)
327          enddo !DO i = 1, knon
328         enddo !do k = 2, klev
329         DO i = 1, knon
330            call iso_verif_egalite_choix( &
331                Acoef_XT(iso_eau,i),Acoef_Q(i), &
332                        'climb_hq 234a',errmax,errmaxrel)
333            call iso_verif_egalite_choix( &
334                Bcoef_XT(iso_eau,i),Bcoef_Q(i), &
335                        'climb_hq 234b',errmax,errmaxrel)
336         enddo !DO i = 1, knon
337        endif !if (iso_eau.gt.0) then
338#endif
339#endif 
340!****************************************************************************************
341! 5)
342! Calculte the coefficients C and D for potentiel entalpie, H
343!
344!****************************************************************************************
345    h_old(:,:) = 0.0
346
347    DO k=1,klev
348       DO i = 1, knon
349          ! convertie la temperature en entalpie potentielle
350          h_old(i,k) = RCPD * temp(i,k) * &
351               (psref(i)/pplay(i,k))**RKAPPA
352       ENDDO
353    ENDDO
354
355    CALL calc_coef(knon, Kcoefhq(:,:), gamah(:,:), delp(:,:), h_old(:,:), &
356         Ccoef_H(:,:), Dcoef_H(:,:), Acoef_H, Bcoef_H)
357 
358!****************************************************************************************
359! 6)
360! Return the first layer in output variables
361!
362!****************************************************************************************
363    Acoef_H_out = Acoef_H
364    Bcoef_H_out = Bcoef_H
365    Acoef_Q_out = Acoef_Q
366    Bcoef_Q_out = Bcoef_Q
367#ifdef ISO
368    Acoef_XT_out = Acoef_XT
369    Bcoef_XT_out = Bcoef_XT
370#endif
371
372!****************************************************************************************
373! 7)
374! If Pbl is split, return also the other layers in output variables
375!
376!****************************************************************************************
377!!! jyg le 07/02/2012
378!!jyg       IF (mod(iflag_pbl_split,2) .eq.1) THEN
379       IF (mod(iflag_pbl_split,10) .ge.1) THEN
380!!! nrlmd le 02/05/2011
381    DO k= 1, klev
382      DO i= 1, klon
383        Ccoef_H_out(i,k) = Ccoef_H(i,k)
384        Dcoef_H_out(i,k) = Dcoef_H(i,k)
385        Ccoef_Q_out(i,k) = Ccoef_Q(i,k)
386        Dcoef_Q_out(i,k) = Dcoef_Q(i,k)
387        Kcoef_hq_out(i,k) = Kcoefhq(i,k)
388#ifdef ISO
389        do ixt=1,ntraciso
390          Ccoef_XT_out(ixt,i,k) = Ccoef_XT(ixt,i,k)
391          Dcoef_XT_out(ixt,i,k) = Dcoef_XT(ixt,i,k)             
392        enddo   
393#endif
394          IF (k.eq.1) THEN
395            gama_h_out(i,k)  = 0.
396            gama_q_out(i,k)  = 0.
397#ifdef ISO
398            do ixt=1,ntraciso
399              gama_xt_out(ixt,i,k)  = 0.
400            enddo   
401#endif
402          ELSE
403            gama_h_out(i,k)  = gamah(i,k)
404            gama_q_out(i,k)  = gamaq(i,k)
405#ifdef ISO
406            do ixt=1,ntraciso
407              gama_xt_out(ixt,i,k)  = gamaxt(ixt,i,k)
408            enddo   
409#endif
410          ENDIF
411      ENDDO
412    ENDDO
413!!!     
414       ENDIF  ! (mod(iflag_pbl_split,2) .ge.1)
415!!!
416
417  END SUBROUTINE climb_hq_down
418!
419!****************************************************************************************
420!
421  SUBROUTINE calc_coef(knon, Kcoef, gama, delp, X, Ccoef, Dcoef, Acoef, Bcoef)
422!
423! Calculate the coefficients C and D in : X(k) = C(k) + D(k)*X(k-1)
424! where X is H or Q, and k the vertical level k=1,klev
425!
426    INCLUDE "YOMCST.h"
427! Input arguments
428!****************************************************************************************
429    INTEGER, INTENT(IN)                      :: knon
430    REAL, DIMENSION(klon,klev), INTENT(IN)   :: Kcoef, delp
431    REAL, DIMENSION(klon,klev), INTENT(IN)   :: X
432    REAL, DIMENSION(klon,2:klev), INTENT(IN) :: gama
433
434! Output arguments
435!****************************************************************************************
436    REAL, DIMENSION(klon), INTENT(OUT)       :: Acoef, Bcoef
437    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: Ccoef, Dcoef
438
439! Local variables
440!****************************************************************************************
441    INTEGER                                  :: k, i
442    REAL                                     :: buf
443
444!****************************************************************************************
445! Niveau au sommet, k=klev
446!
447!****************************************************************************************
448    Ccoef(:,:) = 0.0
449    Dcoef(:,:) = 0.0
450
451    DO i = 1, knon
452       buf = delp(i,klev) + Kcoef(i,klev)
453       
454       Ccoef(i,klev) = (X(i,klev)*delp(i,klev) - Kcoef(i,klev)*gama(i,klev))/buf
455       Dcoef(i,klev) = Kcoef(i,klev)/buf
456    END DO
457
458
459!****************************************************************************************
460! Niveau  (klev-1) <= k <= 2
461!
462!****************************************************************************************
463
464    DO k=(klev-1),2,-1
465       DO i = 1, knon
466          buf = delp(i,k) + Kcoef(i,k) + Kcoef(i,k+1)*(1.-Dcoef(i,k+1))
467          Ccoef(i,k) = (X(i,k)*delp(i,k) + Kcoef(i,k+1)*Ccoef(i,k+1) + &
468               Kcoef(i,k+1)*gama(i,k+1) - Kcoef(i,k)*gama(i,k))/buf
469          Dcoef(i,k) = Kcoef(i,k)/buf
470       END DO
471    END DO
472
473!****************************************************************************************
474! Niveau k=1
475!
476!****************************************************************************************
477
478    DO i = 1, knon
479       buf = delp(i,1) + Kcoef(i,2)*(1.-Dcoef(i,2))
480       Acoef(i) = (X(i,1)*delp(i,1) + Kcoef(i,2)*(gama(i,2)+Ccoef(i,2)))/buf
481       Bcoef(i) = -1. * RG / buf
482    END DO
483
484  END SUBROUTINE calc_coef
485!
486!****************************************************************************************
487!
488  SUBROUTINE climb_hq_up(knon, dtime, t_old, q_old, &
489       flx_q1, flx_h1, paprs, pplay, &
490!!! nrlmd le 02/05/2011
491       Acoef_H_in, Acoef_Q_in, Bcoef_H_in, Bcoef_Q_in, &
492       Ccoef_H_in, Ccoef_Q_in, Dcoef_H_in, Dcoef_Q_in, &
493       Kcoef_hq_in, gama_q_in, gama_h_in, &
494!!!
495       flux_q, flux_h, d_q, d_t &
496#ifdef ISO
497       ,xt_old, flx_xt1, &
498       Acoef_XT_in,Bcoef_XT_in,Ccoef_XT_in,Dcoef_XT_in,gama_xt_in,  &
499       flux_xt, d_xt &
500#endif       
501       )
502
503#ifdef ISOVERIF
504USE infotrac_phy, ONLY: nzone
505USE isotopes_mod, ONLY: iso_eau,iso_HDO,iso_O18, ridicule
506USE isotopes_verif_mod
507#endif
508!
509! This routine calculates the flux and tendency of the specific humidity q and
510! the potential engergi H.
511! The quantities q and H are calculated according to
512! X(k) = C(k) + D(k)*X(k-1) for X=[q,H], where the coefficients
513! C and D are known from before and k is index of the vertical layer.
514!   
515
516! Input arguments
517!****************************************************************************************
518    INTEGER, INTENT(IN)                      :: knon
519    REAL, INTENT(IN)                         :: dtime
520    REAL, DIMENSION(klon,klev), INTENT(IN)   :: t_old, q_old
521    REAL, DIMENSION(klon), INTENT(IN)        :: flx_q1, flx_h1
522    REAL, DIMENSION(klon,klev+1), INTENT(IN) :: paprs
523    REAL, DIMENSION(klon,klev), INTENT(IN)   :: pplay
524
525!!! nrlmd le 02/05/2011
526    REAL, DIMENSION(klon), INTENT(IN)        :: Acoef_H_in,Acoef_Q_in, Bcoef_H_in, Bcoef_Q_in
527    REAL, DIMENSION(klon,klev), INTENT(IN)   :: Ccoef_H_in, Ccoef_Q_in, Dcoef_H_in, Dcoef_Q_in
528    REAL, DIMENSION(klon,klev), INTENT(IN)   :: Kcoef_hq_in, gama_q_in, gama_h_in
529#ifdef ISO
530    REAL, DIMENSION(ntraciso,klon), INTENT(IN)        :: Acoef_XT_in,  Bcoef_XT_in
531    REAL, DIMENSION(ntraciso,klon,klev), INTENT(IN)   :: Ccoef_XT_in,  Dcoef_XT_in
532    REAL, DIMENSION(ntraciso,klon,klev), INTENT(IN)   :: gama_xt_in
533#endif
534!!!
535
536! Output arguments
537!****************************************************************************************
538    REAL, DIMENSION(klon,klev), INTENT(OUT)  :: flux_q, flux_h, d_q, d_t
539
540! Local variables
541!****************************************************************************************
542    LOGICAL, SAVE                            :: last=.FALSE.
543    REAL, DIMENSION(klon,klev)               :: h_new, q_new
544    REAL, DIMENSION(klon)                    :: psref         
545    INTEGER                                  :: k, i, ierr
546 
547#ifdef ISO
548    REAL, DIMENSION(ntraciso,klon,klev), INTENT(IN)   ::  xt_old
549    REAL, DIMENSION(ntraciso,klon,klev), INTENT(OUT)  :: flux_xt, d_xt
550    REAL, DIMENSION(ntraciso,klon,klev)               :: xt_new
551    REAL, DIMENSION(ntraciso,klon), INTENT(IN)        :: flx_xt1
552    integer ixt
553!#ifdef ISOVERIF
554!    integer iso_verif_noNaN_nostop
555!#endif
556#endif
557 
558! Include
559!****************************************************************************************
560    INCLUDE "YOMCST.h"
561    INCLUDE "compbl.h"       
562
563!****************************************************************************************
564! 1)
565! Definition of some variables
566    REAL, DIMENSION(klon,klev)               :: d_h, zairm
567!
568!****************************************************************************************
569
570
571#ifdef ISO
572#ifdef ISOVERIF
573       DO k = 1, klev
574        DO i = 1, knon 
575         if (iso_eau.gt.0) then
576           call iso_verif_egalite(xt_old(iso_eau,i,k), &
577    &          q_old(i,k),'climb_hq_mod 421')
578         endif
579#ifdef ISOTRAC
580         IF(nzone > 0) CALL iso_verif_traceur(xt_old(1,i,k),'climb_hq_mod 422')
581#endif
582        enddo
583       enddo
584#endif 
585#endif
586
587    flux_q(:,:) = 0.0
588    flux_h(:,:) = 0.0
589    d_q(:,:)    = 0.0
590    d_t(:,:)    = 0.0
591    d_h(:,:)    = 0.0
592    f_h_bnd(:)= 0.0
593#ifdef ISO
594    q_new(:,:)    = 0.0
595    flux_xt(:,:,:) = 0.0
596    d_xt(:,:,:)    = 0.0   
597    xt_new(:,:,:)    = 0.0
598#endif
599    psref(1:knon) = paprs(1:knon,1) 
600
601!!! jyg le 07/02/2012
602!!jyg       IF (mod(iflag_pbl_split,2) .eq.1) THEN
603       IF (mod(iflag_pbl_split,10) .ge.1) THEN
604!!! nrlmd le 02/05/2011
605    DO i = 1, knon
606      Acoef_H(i)=Acoef_H_in(i)
607      Acoef_Q(i)=Acoef_Q_in(i)
608      Bcoef_H(i)=Bcoef_H_in(i)
609      Bcoef_Q(i)=Bcoef_Q_in(i)
610#ifdef ISO
611      do ixt=1,ntraciso
612        Acoef_XT(ixt,i)=Acoef_XT_in(ixt,i)
613        Bcoef_XT(ixt,i)=Bcoef_XT_in(ixt,i)
614      enddo   
615#endif
616    ENDDO
617    DO k = 1, klev
618      DO i = 1, knon
619        Ccoef_H(i,k)=Ccoef_H_in(i,k)
620        Ccoef_Q(i,k)=Ccoef_Q_in(i,k)
621        Dcoef_H(i,k)=Dcoef_H_in(i,k)
622        Dcoef_Q(i,k)=Dcoef_Q_in(i,k)
623        Kcoefhq(i,k)=Kcoef_hq_in(i,k)
624#ifdef ISO
625      do ixt=1,ntraciso
626        Ccoef_XT(ixt,i,k)=Ccoef_XT_in(ixt,i,k)
627        Dcoef_XT(ixt,i,k)=Dcoef_XT_in(ixt,i,k)
628      enddo   
629#endif
630          IF (k.gt.1) THEN
631            gamah(i,k)=gama_h_in(i,k)
632            gamaq(i,k)=gama_q_in(i,k)
633#ifdef ISO
634            do ixt=1,ntraciso
635              gamaxt(ixt,i,k)=gama_xt_in(ixt,i,k)
636            enddo
637#endif
638          ENDIF
639      ENDDO
640    ENDDO
641!!!     
642       ENDIF  ! (mod(iflag_pbl_split,2) .ge.1)
643!!!
644
645!****************************************************************************************
646! 2)
647! Calculation of Q and H
648!
649!****************************************************************************************
650
651!- First layer
652    q_new(1:knon,1) = Acoef_Q(1:knon) + Bcoef_Q(1:knon)*flx_q1(1:knon)*dtime
653    h_new(1:knon,1) = Acoef_H(1:knon) + Bcoef_H(1:knon)*flx_h1(1:knon)*dtime
654    f_h_bnd(1:knon) = flx_h1(1:knon)
655#ifdef ISO
656    do ixt=1,ntraciso
657      xt_new(ixt,1:knon,1) = Acoef_XT(ixt,1:knon) + Bcoef_XT(ixt,1:knon)*flx_xt1(ixt,1:knon)*dtime
658    enddo ! do ixt=1,ntraciso
659#endif
660!- All the other layers
661    DO k = 2, klev
662       DO i = 1, knon
663          q_new(i,k) = Ccoef_Q(i,k) + Dcoef_Q(i,k)*q_new(i,k-1)
664          h_new(i,k) = Ccoef_H(i,k) + Dcoef_H(i,k)*h_new(i,k-1)
665#ifdef ISO
666        do ixt=1,ntraciso
667          xt_new(ixt,i,k) = Ccoef_XT(ixt,i,k) + Dcoef_XT(ixt,i,k)*xt_new(ixt,i,k-1)
668        enddo ! do ixt=1,ntraciso
669#endif
670       END DO
671    END DO
672
673#ifdef ISO
674#ifdef ISOVERIF
675    DO k = 1, klev
676       DO i = 1, knon     
677        do ixt=1,ntraciso
678         if (iso_verif_noNaN_nostop(xt_new(ixt,i,k),'climb_hq 507').eq.1) then
679             write(*,*) 'Acoef_XT(ixt,i)=',Acoef_XT(ixt,i)
680             write(*,*) 'Bcoef_XT(ixt,i)=',Bcoef_XT(ixt,i)
681             write(*,*) 'flx_xt1(ixt,i)=',flx_xt1(ixt,i)
682             if (k.ge.2) then
683               write(*,*) 'Ccoef_XT(ixt,i,k)=',Ccoef_XT(ixt,i,k)
684               write(*,*) 'Dcoef_XT(ixt,i,k)=',Dcoef_XT(ixt,i,k)
685             endif
686             stop
687         endif
688        enddo !do ixt=1,ntraciso
689       END DO
690    END DO       
691#endif
692#ifdef ISOVERIF
693     if (iso_eau.gt.0) then
694        call iso_verif_egalite_vect2D( &
695     &           xt_new,q_new, &
696     &           'climb_hq_mod 504',ntraciso,klon,klev)
697     endif !if (iso_eau.gt.0) then
698     if ((iso_HDO.gt.0).and.(iso_O18.gt.0)) then 
699        do i=1,klon
700         do k=1,klev
701            if (q_new(i,k).gt.ridicule) then 
702               if (iso_verif_o18_aberrant_nostop( &
703     &              xt_new(iso_HDO,i,k)/q_new(i,k), &
704     &              xt_new(iso_O18,i,k)/q_new(i,k), &
705     &              'climb_hq_mod 690').eq.1) then
706                  write(*,*) 'i,k,q_new(i,k)=',i,k,q_new(i,k)                       
707                  stop
708              endif !  if (iso_verif_o18_aberrant_nostop
709            endif !if (q_seri(i,k).gt.errmax) then   
710          enddo !k=1,klev
711         enddo  !i=1,klon
712        endif !if ((iso_HDO.gt.0).and.(iso_O18.gt.0)) then   
713#endif
714#endif   
715!****************************************************************************************
716! 3)
717! Calculation of the flux for Q and H
718!
719!****************************************************************************************
720
721!- The flux at first layer, k=1
722    flux_q(1:knon,1)=flx_q1(1:knon)
723    flux_h(1:knon,1)=flx_h1(1:knon)
724#ifdef ISO
725    do ixt=1,ntraciso
726        flux_xt(ixt,1:knon,1)=flx_xt1(ixt,1:knon)
727    enddo ! do ixt=1,ntraciso
728#endif
729
730!- The flux at all layers above surface
731    DO k = 2, klev
732       DO i = 1, knon
733          flux_q(i,k) = (Kcoefhq(i,k)/RG/dtime) * &
734               (q_new(i,k)-q_new(i,k-1)+gamaq(i,k))
735
736          flux_h(i,k) = (Kcoefhq(i,k)/RG/dtime) * &
737               (h_new(i,k)-h_new(i,k-1)+gamah(i,k))
738
739#ifdef ISO
740        do ixt=1,ntraciso
741          flux_xt(ixt,i,k) = (Kcoefhq(i,k)/RG/dtime) * &
742               (xt_new(ixt,i,k)-xt_new(ixt,i,k-1)+gamaxt(ixt,i,k))
743        enddo ! do ixt=1,ntraciso
744#endif
745       END DO
746    END DO
747
748!****************************************************************************************
749! 4)
750! Calculation of tendency for Q and H
751!
752!****************************************************************************************
753    d_h_col_vdf(:) = 0.0
754    DO k = 1, klev
755       DO i = 1, knon
756          d_t(i,k) = h_new(i,k)/(psref(i)/pplay(i,k))**RKAPPA/RCPD - t_old(i,k)
757          d_q(i,k) = q_new(i,k) - q_old(i,k)
758          d_h(i,k) = h_new(i,k) - h_old(i,k)
759!JLD          d_t(i,k) = d_h(i,k)/(psref(i)/pplay(i,k))**RKAPPA/RCPD    !correction a venir
760    ! layer air mass
761          zairm(i, k) = (paprs(i,k)-paprs(i,k+1))/rg
762          d_h_col_vdf(i) = d_h_col_vdf(i) + d_h(i,k)*zairm(i,k)
763#ifdef ISO
764        do ixt=1,ntraciso
765          d_xt(ixt,i,k) = xt_new(ixt,i,k) - xt_old(ixt,i,k)
766        enddo ! do ixt=1,ntraciso
767#ifdef ISOVERIF
768        do ixt=1,ntraciso
769          call iso_verif_noNaN(xt_new(ixt,i,k),'climb_hq 562')
770          call iso_verif_noNaN(d_xt(ixt,i,k),'climb_hq 562')
771        enddo ! do ixt=1,ntraciso
772#endif
773#ifdef ISOVERIF
774        if (iso_eau.gt.0) then
775           call iso_verif_egalite(d_xt(iso_eau,i,k), &
776     &         d_q(i,k),'climb_hq_mod 503')
777           call iso_verif_egalite(xt_new(iso_eau,i,k), &
778     &         q_new(i,k),'climb_hq_mod 503b')
779        endif
780#ifdef ISOTRAC
781        IF(nzone > 0) CALL iso_verif_traceur(xt_old(1,i,k),'climb_hq_mod 526')
782#endif       
783#endif       
784#endif
785        END DO
786    END DO
787
788#ifdef ISO
789#ifdef ISOVERIF
790!        write(*,*) 'climb_hq_mod 758: d_xt,d_q=',d_xt(iso_eau,1,1),d_q(1,1)
791        if (iso_eau.gt.0) then
792         call iso_verif_egalite_vect2D( &
793                d_xt,d_q, &
794                'climb_hq_mod 761',ntraciso,klon,klev)
795        endif       
796#endif
797#endif
798
799!****************************************************************************************
800! Some deallocations
801!
802!****************************************************************************************
803    IF (last) THEN
804       DEALLOCATE(Ccoef_Q, Dcoef_Q, Ccoef_H, Dcoef_H,stat=ierr)   
805       IF ( ierr /= 0 )  PRINT*,' pb in dealllocate Ccoef_Q, Dcoef_Q, Ccoef_H, Dcoef_H, ierr=', ierr
806       DEALLOCATE(Acoef_Q, Bcoef_Q, Acoef_H, Bcoef_H,stat=ierr)   
807       IF ( ierr /= 0 )  PRINT*,' pb in dealllocate Acoef_Q, Bcoef_Q, Acoef_H, Bcoef_H, ierr=', ierr
808       DEALLOCATE(gamaq, gamah,stat=ierr)
809       IF ( ierr /= 0 )  PRINT*,' pb in dealllocate gamaq, gamah, ierr=', ierr
810       DEALLOCATE(Kcoefhq,stat=ierr)
811       IF ( ierr /= 0 )  PRINT*,' pb in dealllocate Kcoefhq, ierr=', ierr
812       DEALLOCATE(h_old, d_h_col_vdf, f_h_bnd, stat=ierr)
813       IF ( ierr /= 0 )  PRINT*,' pb in dealllocate h_old, d_h_col_vdf, f_h_bnd, ierr=', ierr
814
815#ifdef ISO
816       DEALLOCATE(Ccoef_XT, Dcoef_XT ,stat=ierr)   
817       IF ( ierr /= 0 )  PRINT*,' pb in dealllocate Ccoef_XT, Dcoef_XT, ierr=', ierr
818       DEALLOCATE(Acoef_XT, Bcoef_XT, stat=ierr)   
819       IF ( ierr /= 0 )  PRINT*,' pb in dealllocate Acoef_XT, Bcoef_XT, ierr=', ierr
820       DEALLOCATE(gamaxt, stat=ierr)
821       IF ( ierr /= 0 )  PRINT*,' pb in dealllocate gamaxt, ierr=', ierr
822#endif
823    END IF
824  END SUBROUTINE climb_hq_up
825!
826!****************************************************************************************
827!
828END MODULE climb_hq_mod
829
830 
831
832
833
834
Note: See TracBrowser for help on using the repository browser.