source: flexpart.git/src/verttransform.f90 @ 72d3a5a

10.4.1_peseiGFS_025bugfixes+enhancementsdevrelease-10release-10.4.1scaling-bugunivie
Last change on this file since 72d3a5a was 72d3a5a, checked in by Espen Sollum ATMOS <eso@…>, 7 years ago

Bugfix in verttransform (call to function ew)

  • Property mode set to 100644
File size: 29.8 KB
RevLine 
[e200b7a]1!**********************************************************************
2! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
3! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
4! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
5!                                                                     *
6! This file is part of FLEXPART.                                      *
7!                                                                     *
8! FLEXPART is free software: you can redistribute it and/or modify    *
9! it under the terms of the GNU General Public License as published by*
10! the Free Software Foundation, either version 3 of the License, or   *
11! (at your option) any later version.                                 *
12!                                                                     *
13! FLEXPART is distributed in the hope that it will be useful,         *
14! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
15! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
16! GNU General Public License for more details.                        *
17!                                                                     *
18! You should have received a copy of the GNU General Public License   *
19! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
20!**********************************************************************
21
22subroutine verttransform(n,uuh,vvh,wwh,pvh)
[4d45639]23!                         i  i   i   i   i
[8a65cb0]24!*****************************************************************************
25!                                                                            *
26!     This subroutine transforms temperature, dew point temperature and      *
27!     wind components from eta to meter coordinates.                         *
28!     The vertical wind component is transformed from Pa/s to m/s using      *
29!     the conversion factor pinmconv.                                        *
30!     In addition, this routine calculates vertical density gradients        *
31!     needed for the parameterization of the turbulent velocities.           *
32!                                                                            *
33!     Author: A. Stohl, G. Wotawa                                            *
34!                                                                            *
35!     12 August 1996                                                         *
36!     Update: 16 January 1998                                                *
37!                                                                            *
38!     Major update: 17 February 1999                                         *
39!     by G. Wotawa                                                           *
40!                                                                            *
41!     - Vertical levels for u, v and w are put together                      *
42!     - Slope correction for vertical velocity: Modification of calculation  *
43!       procedure                                                            *
44!                                                                            *
45!*****************************************************************************
46!  Changes, Bernd C. Krueger, Feb. 2001:
47!   Variables tth and qvh (on eta coordinates) from common block
48!*****************************************************************************
49! Sabine Eckhardt, March 2007
50! added the variable cloud for use with scavenging - descr. in com_mod
51!*****************************************************************************
[72d3a5a]52! Date: 2017-05-30 modification of a bug in ew. Don Morton (CTBTO project)   *
53!*****************************************************************************
[8a65cb0]54!                                                                            *
55! Variables:                                                                 *
56! nx,ny,nz                        field dimensions in x,y and z direction    *
57! clouds(0:nxmax,0:nymax,0:nzmax,numwfmem) cloud field for wet deposition    *
58! uu(0:nxmax,0:nymax,nzmax,numwfmem)     wind components in x-direction [m/s]*
59! vv(0:nxmax,0:nymax,nzmax,numwfmem)     wind components in y-direction [m/s]*
60! ww(0:nxmax,0:nymax,nzmax,numwfmem)     wind components in z-direction      *
61!                                          [deltaeta/s]                      *
62! tt(0:nxmax,0:nymax,nzmax,numwfmem)     temperature [K]                     *
63! pv(0:nxmax,0:nymax,nzmax,numwfmem)     potential voriticity (pvu)          *
64! ps(0:nxmax,0:nymax,numwfmem)           surface pressure [Pa]               *
65!                                                                            *
66!*****************************************************************************
[e200b7a]67
68  use par_mod
69  use com_mod
70  use cmapf_mod, only: cc2gll
[4d45639]71!  use mpi_mod
[e200b7a]72
73  implicit none
74
[db712a8]75  real,intent(in),dimension(0:nxmax-1,0:nymax-1,nuvzmax) :: uuh,vvh,pvh
76  real,intent(in),dimension(0:nxmax-1,0:nymax-1,nwzmax) :: wwh
77
78  real,dimension(0:nxmax-1,0:nymax-1,nuvzmax) :: rhoh,uvzlev,wzlev
79  real,dimension(0:nxmax-1,0:nymax-1,nzmax) :: pinmconv
80  real,dimension(0:nxmax-1,0:nymax-1) ::  tvold,pold,pint,tv
81  real,dimension(0:nymax-1) :: cosf
82
83  integer,dimension(0:nxmax-1,0:nymax-1) :: rain_cloud_above,idx
84
85  integer :: ix,jy,kz,iz,n,kmin,ix1,jy1,ixp,jyp,ixm,jym,kz_inv
[341f4b7]86  real :: f_qvsat,pressure,rh,lsp,convp,cloudh_min,prec
[db712a8]87  real :: ew,dz1,dz2,dz
[e200b7a]88  real :: xlon,ylat,xlonr,dzdx,dzdy
[4d45639]89  real :: dzdx1,dzdx2,dzdy1,dzdy2
[e200b7a]90  real :: uuaux,vvaux,uupolaux,vvpolaux,ddpol,ffpol,wdummy
91  real,parameter :: const=r_air/ga
[db712a8]92  real,parameter :: precmin = 0.002 ! minimum prec in mm/h for cloud diagnostics
[e200b7a]93
94  logical :: init = .true.
[6481010]95  logical :: init_w = .false.
96  logical :: init_r = .false.
97
[e200b7a]98
[d6a0977]99  !ZHG SEP 2014 tests 
[db712a8]100  ! integer :: cloud_ver,cloud_min, cloud_max
101  ! integer ::teller(5), convpteller=0, lspteller=0
102  ! real :: cloud_col_wat, cloud_water
[d6a0977]103  !ZHG 2015 temporary variables for testing
[db712a8]104  ! real :: rcw(0:nxmax-1,0:nymax-1)
105  ! real :: rpc(0:nxmax-1,0:nymax-1)
[26f6039]106  ! character(len=60) :: zhgpath='/xnilu_wrk/flex_wrk/zhg/'
107  ! character(len=60) :: fnameA,fnameB,fnameC,fnameD,fnameE,fnameF,fnameG,fnameH
[db712a8]108  ! CHARACTER(LEN=3)  :: aspec
109  ! integer :: virr=0
[ceb7e4d]110  !real :: tot_cloud_h
111  !real :: dbg_height(nzmax)
[d6a0977]112!ZHG
[e200b7a]113
[8a65cb0]114!*************************************************************************
115! If verttransform is called the first time, initialize heights of the   *
116! z levels in meter. The heights are the heights of model levels, where  *
[4d45639]117! u,v,T and qv are given, and of the interfaces, where w is given. So,   *
118! the vertical resolution in the z system is doubled. As reference point,*
119! the lower left corner of the grid is used.                             *
120! Unlike in the eta system, no difference between heights for u,v and    *
121! heights for w exists.                                                  *
[8a65cb0]122!*************************************************************************
[e200b7a]123
[4d45639]124
125!eso measure CPU time
126!  call mpif_mtime('verttransform',0)
127
[e200b7a]128  if (init) then
129
[6481010]130
131    if (init_r) then
132
133        open(333,file='heights.txt', &
134          form='formatted')
135        do kz=1,nuvz
136            read(333,*) height(kz)
137        end do
138        close(333)
139        write(*,*) 'height read'
140    else
141
142
[8a65cb0]143! Search for a point with high surface pressure (i.e. not above significant topography)
144! Then, use this point to construct a reference z profile, to be used at all times
[4d45639]145!*****************************************************************************
[e200b7a]146
147    do jy=0,nymin1
148      do ix=0,nxmin1
149        if (ps(ix,jy,1,n).gt.100000.) then
150          ixm=ix
151          jym=jy
152          goto 3
153        endif
154      end do
155    end do
1563   continue
157
158
[72d3a5a]159    tvold(ixm,jym)=tt2(ixm,jym,1,n)*(1.+0.378*ew(td2(ixm,jym,1,n))/ &
[8a65cb0]160         ps(ixm,jym,1,n))
[4d45639]161    pold(ixm,jym)=ps(ixm,jym,1,n)
[e200b7a]162    height(1)=0.
163
164    do kz=2,nuvz
165      pint=akz(kz)+bkz(kz)*ps(ixm,jym,1,n)
166      tv=tth(ixm,jym,kz,n)*(1.+0.608*qvh(ixm,jym,kz,n))
167
[4d45639]168      if (abs(tv(ixm,jym)-tvold(ixm,jym)).gt.0.2) then
169        height(kz)= &
170             height(kz-1)+const*log(pold(ixm,jym)/pint(ixm,jym))* &
171             (tv(ixm,jym)-tvold(ixm,jym))/log(tv(ixm,jym)/tvold(ixm,jym))
[e200b7a]172      else
[4d45639]173        height(kz)=height(kz-1)+ &
174             const*log(pold(ixm,jym)/pint(ixm,jym))*tv(ixm,jym)
[e200b7a]175      endif
176
[4d45639]177      tvold(ixm,jym)=tv(ixm,jym)
178      pold(ixm,jym)=pint(ixm,jym)
[e200b7a]179    end do
180
[6481010]181    if (init_w) then
182        open(333,file='heights.txt', &
183          form='formatted')
184        do kz=1,nuvz
185              write(333,*) height(kz)
186        end do
187        close(333)
188    endif
189
190    endif ! init
[e200b7a]191
[8a65cb0]192! Determine highest levels that can be within PBL
193!************************************************
[e200b7a]194
195    do kz=1,nz
196      if (height(kz).gt.hmixmax) then
197        nmixz=kz
198        goto 9
199      endif
200    end do
2019   continue
202
[8a65cb0]203! Do not repeat initialization of the Cartesian z grid
204!*****************************************************
[e200b7a]205
206    init=.false.
207
[ceb7e4d]208!    dbg_height = height
[db712a8]209
[e200b7a]210  endif
211
212
[8a65cb0]213! Loop over the whole grid
214!*************************
[e200b7a]215
[4d45639]216
[e200b7a]217  do jy=0,nymin1
218    do ix=0,nxmin1
[72d3a5a]219      tvold(ix,jy)=tt2(ix,jy,1,n)*(1.+0.378*ew(td2(ix,jy,1,n))/ &
[4d45639]220           ps(ix,jy,1,n))
221    enddo
222  enddo
223  pold=ps(:,:,1,n)
224  uvzlev(:,:,1)=0.
225  wzlev(:,:,1)=0.
226  rhoh(:,:,1)=pold/(r_air*tvold)
[e200b7a]227
228
[8a65cb0]229! Compute heights of eta levels
230!******************************
[e200b7a]231
[4d45639]232  do kz=2,nuvz
233    pint=akz(kz)+bkz(kz)*ps(:,:,1,n)
234    tv=tth(:,:,kz,n)*(1.+0.608*qvh(:,:,kz,n))
235    rhoh(:,:,kz)=pint(:,:)/(r_air*tv)
[e200b7a]236
[4d45639]237    where (abs(tv-tvold).gt.0.2)
238      uvzlev(:,:,kz)=uvzlev(:,:,kz-1)+const*log(pold/pint)* &
239           (tv-tvold)/log(tv/tvold)
240    elsewhere
241      uvzlev(:,:,kz)=uvzlev(:,:,kz-1)+const*log(pold/pint)*tv
242    endwhere
[e200b7a]243
[4d45639]244    tvold=tv
245    pold=pint
246  end do
[e200b7a]247
248
[4d45639]249  do kz=2,nwz-1
250    wzlev(:,:,kz)=(uvzlev(:,:,kz+1)+uvzlev(:,:,kz))/2.
251  end do
252  wzlev(:,:,nwz)=wzlev(:,:,nwz-1)+ &
253       uvzlev(:,:,nuvz)-uvzlev(:,:,nuvz-1)
[e200b7a]254
[8a65cb0]255! pinmconv=(h2-h1)/(p2-p1)
[e200b7a]256
[4d45639]257  pinmconv(:,:,1)=(uvzlev(:,:,2))/ &
258       ((aknew(2)+bknew(2)*ps(:,:,1,n))- &
259       (aknew(1)+bknew(1)*ps(:,:,1,n)))
260  do kz=2,nz-1
261    pinmconv(:,:,kz)=(uvzlev(:,:,kz+1)-uvzlev(:,:,kz-1))/ &
262         ((aknew(kz+1)+bknew(kz+1)*ps(:,:,1,n))- &
263         (aknew(kz-1)+bknew(kz-1)*ps(:,:,1,n)))
264  end do
265  pinmconv(:,:,nz)=(uvzlev(:,:,nz)-uvzlev(:,:,nz-1))/ &
266       ((aknew(nz)+bknew(nz)*ps(:,:,1,n))- &
267       (aknew(nz-1)+bknew(nz-1)*ps(:,:,1,n)))
[e200b7a]268
[8a65cb0]269! Levels, where u,v,t and q are given
270!************************************
[e200b7a]271
[4d45639]272
273  uu(:,:,1,n)=uuh(:,:,1)
274  vv(:,:,1,n)=vvh(:,:,1)
275  tt(:,:,1,n)=tth(:,:,1,n)
276  qv(:,:,1,n)=qvh(:,:,1,n)
[8a65cb0]277!hg adding the cloud water
[db712a8]278  if (readclouds) then
279    clwc(:,:,1,n)=clwch(:,:,1,n)
280    if (.not.sumclouds) ciwc(:,:,1,n)=ciwch(:,:,1,n)
281  end if
[8a65cb0]282!hg
[4d45639]283  pv(:,:,1,n)=pvh(:,:,1)
284  rho(:,:,1,n)=rhoh(:,:,1)
[db712a8]285
[4d45639]286  uu(:,:,nz,n)=uuh(:,:,nuvz)
287  vv(:,:,nz,n)=vvh(:,:,nuvz)
288  tt(:,:,nz,n)=tth(:,:,nuvz,n)
289  qv(:,:,nz,n)=qvh(:,:,nuvz,n)
[8a65cb0]290!hg adding the cloud water
[db712a8]291  if (readclouds) then
292    clwc(:,:,nz,n)=clwch(:,:,nuvz,n)
293    if (.not.sumclouds) ciwc(:,:,nz,n)=ciwch(:,:,nuvz,n)
294  end if
[8a65cb0]295!hg
[4d45639]296  pv(:,:,nz,n)=pvh(:,:,nuvz)
297  rho(:,:,nz,n)=rhoh(:,:,nuvz)
298
299
300  kmin=2
301  idx=kmin
302  do iz=2,nz-1
303    do jy=0,nymin1
304      do ix=0,nxmin1
305        if(height(iz).gt.uvzlev(ix,jy,nuvz)) then
306          uu(ix,jy,iz,n)=uu(ix,jy,nz,n)
307          vv(ix,jy,iz,n)=vv(ix,jy,nz,n)
308          tt(ix,jy,iz,n)=tt(ix,jy,nz,n)
309          qv(ix,jy,iz,n)=qv(ix,jy,nz,n)
[8a65cb0]310!hg adding the cloud water
[db712a8]311          if (readclouds) then
312            clwc(ix,jy,iz,n)=clwc(ix,jy,nz,n)
313            if (.not.sumclouds) ciwc(ix,jy,iz,n)=ciwc(ix,jy,nz,n)
314          end if
[8a65cb0]315!hg
[4d45639]316          pv(ix,jy,iz,n)=pv(ix,jy,nz,n)
317          rho(ix,jy,iz,n)=rho(ix,jy,nz,n)
318        else
319          innuvz: do kz=idx(ix,jy),nuvz
320            if (idx(ix,jy) .le. kz .and. (height(iz).gt.uvzlev(ix,jy,kz-1)).and. &
321                 (height(iz).le.uvzlev(ix,jy,kz))) then
322              idx(ix,jy)=kz
323              exit innuvz
324            endif
325          enddo innuvz
326        endif
327      enddo
328    enddo
329    do jy=0,nymin1
330      do ix=0,nxmin1
331        if(height(iz).le.uvzlev(ix,jy,nuvz)) then
332          kz=idx(ix,jy)
333          dz1=height(iz)-uvzlev(ix,jy,kz-1)
334          dz2=uvzlev(ix,jy,kz)-height(iz)
335          dz=dz1+dz2
336          uu(ix,jy,iz,n)=(uuh(ix,jy,kz-1)*dz2+uuh(ix,jy,kz)*dz1)/dz
337          vv(ix,jy,iz,n)=(vvh(ix,jy,kz-1)*dz2+vvh(ix,jy,kz)*dz1)/dz
338          tt(ix,jy,iz,n)=(tth(ix,jy,kz-1,n)*dz2 &
339               +tth(ix,jy,kz,n)*dz1)/dz
340          qv(ix,jy,iz,n)=(qvh(ix,jy,kz-1,n)*dz2 &
341               +qvh(ix,jy,kz,n)*dz1)/dz
[8a65cb0]342!hg adding the cloud water
[db712a8]343          if (readclouds) then
344            clwc(ix,jy,iz,n)=(clwch(ix,jy,kz-1,n)*dz2+clwch(ix,jy,kz,n)*dz1)/dz
345            if (.not.sumclouds) &
346                 &ciwc(ix,jy,iz,n)=(ciwch(ix,jy,kz-1,n)*dz2+ciwch(ix,jy,kz,n)*dz1)/dz
347          end if
[8a65cb0]348!hg
[4d45639]349          pv(ix,jy,iz,n)=(pvh(ix,jy,kz-1)*dz2+pvh(ix,jy,kz)*dz1)/dz
350          rho(ix,jy,iz,n)=(rhoh(ix,jy,kz-1)*dz2+rhoh(ix,jy,kz)*dz1)/dz
351        endif
352      enddo
353    enddo
354  enddo
[e200b7a]355
356
[8a65cb0]357! Levels, where w is given
358!*************************
[e200b7a]359
[4d45639]360  ww(:,:,1,n)=wwh(:,:,1)*pinmconv(:,:,1)
361  ww(:,:,nz,n)=wwh(:,:,nwz)*pinmconv(:,:,nz)
362  kmin=2
363  idx=kmin
364  do iz=2,nz
365    do jy=0,nymin1
366      do ix=0,nxmin1
367        inn:         do kz=idx(ix,jy),nwz
368          if(idx(ix,jy) .le. kz .and. height(iz).gt.wzlev(ix,jy,kz-1).and. &
369               height(iz).le.wzlev(ix,jy,kz)) then
370            idx(ix,jy)=kz
371            exit inn
[e200b7a]372          endif
[4d45639]373        enddo inn
374      enddo
375    enddo
376    do jy=0,nymin1
377      do ix=0,nxmin1
378        kz=idx(ix,jy)
379        dz1=height(iz)-wzlev(ix,jy,kz-1)
380        dz2=wzlev(ix,jy,kz)-height(iz)
381        dz=dz1+dz2
382        ww(ix,jy,iz,n)=(wwh(ix,jy,kz-1)*pinmconv(ix,jy,kz-1)*dz2 &
383             +wwh(ix,jy,kz)*pinmconv(ix,jy,kz)*dz1)/dz
384      enddo
385    enddo
386  enddo
[e200b7a]387
[8a65cb0]388! Compute density gradients at intermediate levels
389!*************************************************
[e200b7a]390
[4d45639]391  drhodz(:,:,1,n)=(rho(:,:,2,n)-rho(:,:,1,n))/ &
392       (height(2)-height(1))
393  do kz=2,nz-1
394    drhodz(:,:,kz,n)=(rho(:,:,kz+1,n)-rho(:,:,kz-1,n))/ &
395         (height(kz+1)-height(kz-1))
[e200b7a]396  end do
[4d45639]397  drhodz(:,:,nz,n)=drhodz(:,:,nz-1,n)
398
399!    end do
400!  end do
[e200b7a]401
402
[8a65cb0]403!****************************************************************
404! Compute slope of eta levels in windward direction and resulting
405! vertical wind correction
406!****************************************************************
[e200b7a]407
408  do jy=1,ny-2
[4d45639]409    cosf(jy)=1./cos((real(jy)*dy+ylat0)*pi180)
410  enddo
411
412  kmin=2
413  idx=kmin
414  do iz=2,nz-1
415    do jy=1,ny-2
416      do ix=1,nx-2
417
418        inneta: do kz=idx(ix,jy),nz
419          if (idx(ix,jy) .le. kz .and. (height(iz).gt.uvzlev(ix,jy,kz-1)).and. &
420               (height(iz).le.uvzlev(ix,jy,kz))) then
421            idx(ix,jy)=kz
422            exit inneta
[e200b7a]423          endif
[4d45639]424        enddo inneta
425      enddo
426    enddo
427
428    do jy=1,ny-2
429      do ix=1,nx-2
430        kz=idx(ix,jy)
431        dz1=height(iz)-uvzlev(ix,jy,kz-1)
432        dz2=uvzlev(ix,jy,kz)-height(iz)
433        dz=dz1+dz2
434        ix1=ix-1
[e200b7a]435        jy1=jy-1
436        ixp=ix+1
437        jyp=jy+1
438
[4d45639]439        dzdx1=(uvzlev(ixp,jy,kz-1)-uvzlev(ix1,jy,kz-1))/2.
440        dzdx2=(uvzlev(ixp,jy,kz)-uvzlev(ix1,jy,kz))/2.
[e200b7a]441        dzdx=(dzdx1*dz2+dzdx2*dz1)/dz
442
[4d45639]443        dzdy1=(uvzlev(ix,jyp,kz-1)-uvzlev(ix,jy1,kz-1))/2.
444        dzdy2=(uvzlev(ix,jyp,kz)-uvzlev(ix,jy1,kz))/2.
[e200b7a]445        dzdy=(dzdy1*dz2+dzdy2*dz1)/dz
446
[4d45639]447        ww(ix,jy,iz,n)=ww(ix,jy,iz,n)+(dzdx*uu(ix,jy,iz,n)*dxconst*cosf(jy)+dzdy*vv(ix,jy,iz,n)*dyconst)
[e200b7a]448
449      end do
450
451    end do
452  end do
453
[8a65cb0]454! If north pole is in the domain, calculate wind velocities in polar
455! stereographic coordinates
456!*******************************************************************
[e200b7a]457
458  if (nglobal) then
[4d45639]459    do iz=1,nz
460      do jy=int(switchnorthg)-2,nymin1
461        ylat=ylat0+real(jy)*dy
462        do ix=0,nxmin1
463          xlon=xlon0+real(ix)*dx
[e200b7a]464          call cc2gll(northpolemap,ylat,xlon,uu(ix,jy,iz,n), &
[4d45639]465               vv(ix,jy,iz,n),uupol(ix,jy,iz,n), &
466               vvpol(ix,jy,iz,n))
[e200b7a]467        end do
468      end do
469    end do
470
471
472    do iz=1,nz
473
[8a65cb0]474! CALCULATE FFPOL, DDPOL FOR CENTRAL GRID POINT
475!
476!   AMSnauffer Nov 18 2004 Added check for case vv=0
477!
[e200b7a]478      xlon=xlon0+real(nx/2-1)*dx
479      xlonr=xlon*pi/180.
[4d45639]480      ffpol=sqrt(uu(nx/2-1,nymin1,iz,n)**2+ &
481           vv(nx/2-1,nymin1,iz,n)**2)
[e200b7a]482      if (vv(nx/2-1,nymin1,iz,n).lt.0.) then
[4d45639]483        ddpol=atan(uu(nx/2-1,nymin1,iz,n)/ &
484             vv(nx/2-1,nymin1,iz,n))-xlonr
[e200b7a]485      else if (vv(nx/2-1,nymin1,iz,n).gt.0.) then
486        ddpol=pi+atan(uu(nx/2-1,nymin1,iz,n)/ &
[8a65cb0]487             vv(nx/2-1,nymin1,iz,n))-xlonr
[e200b7a]488      else
489        ddpol=pi/2-xlonr
490      endif
491      if(ddpol.lt.0.) ddpol=2.0*pi+ddpol
492      if(ddpol.gt.2.0*pi) ddpol=ddpol-2.0*pi
493
[8a65cb0]494! CALCULATE U,V FOR 180 DEG, TRANSFORM TO POLAR STEREOGRAPHIC GRID
[e200b7a]495      xlon=180.0
496      xlonr=xlon*pi/180.
497      ylat=90.0
498      uuaux=-ffpol*sin(xlonr+ddpol)
499      vvaux=-ffpol*cos(xlonr+ddpol)
[4d45639]500      call cc2gll(northpolemap,ylat,xlon,uuaux,vvaux,uupolaux, &
501           vvpolaux)
502
[e200b7a]503      jy=nymin1
504      do ix=0,nxmin1
505        uupol(ix,jy,iz,n)=uupolaux
506        vvpol(ix,jy,iz,n)=vvpolaux
507      end do
508    end do
509
510
[8a65cb0]511! Fix: Set W at pole to the zonally averaged W of the next equator-
512! ward parallel of latitude
[e200b7a]513
[8a65cb0]514    do iz=1,nz
[e200b7a]515      wdummy=0.
516      jy=ny-2
517      do ix=0,nxmin1
518        wdummy=wdummy+ww(ix,jy,iz,n)
519      end do
520      wdummy=wdummy/real(nx)
521      jy=nymin1
522      do ix=0,nxmin1
523        ww(ix,jy,iz,n)=wdummy
524      end do
[8a65cb0]525    end do
[e200b7a]526
527  endif
528
529
[8a65cb0]530! If south pole is in the domain, calculate wind velocities in polar
531! stereographic coordinates
532!*******************************************************************
[e200b7a]533
534  if (sglobal) then
[4d45639]535    do iz=1,nz
536      do jy=0,int(switchsouthg)+3
537        ylat=ylat0+real(jy)*dy
538        do ix=0,nxmin1
539          xlon=xlon0+real(ix)*dx
[e200b7a]540          call cc2gll(southpolemap,ylat,xlon,uu(ix,jy,iz,n), &
[4d45639]541               vv(ix,jy,iz,n),uupol(ix,jy,iz,n), &
542               vvpol(ix,jy,iz,n))
[e200b7a]543        end do
544      end do
545    end do
546
547    do iz=1,nz
548
[8a65cb0]549! CALCULATE FFPOL, DDPOL FOR CENTRAL GRID POINT
550!
551!   AMSnauffer Nov 18 2004 Added check for case vv=0
552!
[e200b7a]553      xlon=xlon0+real(nx/2-1)*dx
554      xlonr=xlon*pi/180.
[4d45639]555      ffpol=sqrt(uu(nx/2-1,0,iz,n)**2+ &
556           vv(nx/2-1,0,iz,n)**2)
[e200b7a]557      if (vv(nx/2-1,0,iz,n).lt.0.) then
[4d45639]558        ddpol=atan(uu(nx/2-1,0,iz,n)/ &
559             vv(nx/2-1,0,iz,n))+xlonr
[e200b7a]560      else if (vv(nx/2-1,0,iz,n).gt.0.) then
[4d45639]561        ddpol=pi+atan(uu(nx/2-1,0,iz,n)/ &
562             vv(nx/2-1,0,iz,n))+xlonr
[e200b7a]563      else
564        ddpol=pi/2-xlonr
565      endif
566      if(ddpol.lt.0.) ddpol=2.0*pi+ddpol
567      if(ddpol.gt.2.0*pi) ddpol=ddpol-2.0*pi
568
[8a65cb0]569! CALCULATE U,V FOR 180 DEG, TRANSFORM TO POLAR STEREOGRAPHIC GRID
[e200b7a]570      xlon=180.0
571      xlonr=xlon*pi/180.
572      ylat=-90.0
573      uuaux=+ffpol*sin(xlonr-ddpol)
574      vvaux=-ffpol*cos(xlonr-ddpol)
[4d45639]575      call cc2gll(northpolemap,ylat,xlon,uuaux,vvaux,uupolaux, &
576           vvpolaux)
[e200b7a]577
578      jy=0
579      do ix=0,nxmin1
580        uupol(ix,jy,iz,n)=uupolaux
581        vvpol(ix,jy,iz,n)=vvpolaux
582      end do
583    end do
584
585
[8a65cb0]586! Fix: Set W at pole to the zonally averaged W of the next equator-
587! ward parallel of latitude
[e200b7a]588
589    do iz=1,nz
590      wdummy=0.
591      jy=1
592      do ix=0,nxmin1
593        wdummy=wdummy+ww(ix,jy,iz,n)
594      end do
595      wdummy=wdummy/real(nx)
596      jy=0
597      do ix=0,nxmin1
598        ww(ix,jy,iz,n)=wdummy
599      end do
600    end do
601  endif
602
603
[d6a0977]604!*********************************************************************************** 
[f75967d]605  if (readclouds) then !HG METHOD
[d6a0977]606! The method is loops all grids vertically and constructs the 3D matrix for clouds
607! Cloud top and cloud bottom gid cells are assigned as well as the total column
608! cloud water. For precipitating grids, the type and whether it is in or below
609! cloud scavenging are assigned with numbers 2-5 (following the old metod).
610! Distinction is done for lsp and convp though they are treated the same in regards
611! to scavenging. Also clouds that are not precipitating are defined which may be
612! to include future cloud processing by non-precipitating-clouds.
613!***********************************************************************************
[b0434e1]614    write(*,*) 'Global ECMWF fields: using cloud water'
[41d8574]615    clw(:,:,:,n)=0.0
[341f4b7]616!    icloud_stats(:,:,:,n)=0.0
617    ctwc(:,:,n)=0.0
[f75967d]618    clouds(:,:,:,n)=0
[41d8574]619! If water/ice are read separately into clwc and ciwc, store sum in clwc
620    if (.not.sumclouds) then
621      clwc(:,:,:,n) = clwc(:,:,:,n) + ciwc(:,:,:,n)
622    end if
[f75967d]623    do jy=0,nymin1
624      do ix=0,nxmin1
625        lsp=lsprec(ix,jy,1,n)
626        convp=convprec(ix,jy,1,n)
627        prec=lsp+convp
[ceb7e4d]628!        tot_cloud_h=0
[f75967d]629! Find clouds in the vertical
630        do kz=1, nz-1 !go from top to bottom
631          if (clwc(ix,jy,kz,n).gt.0) then     
632! assuming rho is in kg/m3 and hz in m gives: kg/kg * kg/m3 *m3/kg /m = m2/m3
633            clw(ix,jy,kz,n)=(clwc(ix,jy,kz,n)*rho(ix,jy,kz,n))*(height(kz+1)-height(kz))
[ceb7e4d]634!            tot_cloud_h=tot_cloud_h+(height(kz+1)-height(kz))
[341f4b7]635           
636!            icloud_stats(ix,jy,4,n)= icloud_stats(ix,jy,4,n)+clw(ix,jy,kz,n)          ! Column cloud water [m3/m3]
637            ctwc(ix,jy,n) = ctwc(ix,jy,n)+clw(ix,jy,kz,n)
638!            icloud_stats(ix,jy,3,n)= min(height(kz+1),height(kz))                     ! Cloud BOT height stats      [m]
639            cloudh_min=min(height(kz+1),height(kz))
[d6a0977]640!ZHG 2015 extra for testing
[db712a8]641!            clh(ix,jy,kz,n)=height(kz+1)-height(kz)
[341f4b7]642!            icloud_stats(ix,jy,1,n)=icloud_stats(ix,jy,1,n)+(height(kz+1)-height(kz)) ! Cloud total vertical extent [m]
643!            icloud_stats(ix,jy,2,n)= max(icloud_stats(ix,jy,2,n),height(kz))          ! Cloud TOP height            [m]
[d6a0977]644!ZHG
[f75967d]645          endif
646        end do
[d6a0977]647
[f75967d]648! If Precipitation. Define removal type in the vertical
649        if ((lsp.gt.0.01).or.(convp.gt.0.01)) then ! cloud and precipitation
650
651          do kz=nz,1,-1 !go Bottom up!
652            if (clw(ix,jy,kz,n).gt. 0) then ! is in cloud
653              cloudsh(ix,jy,n)=cloudsh(ix,jy,n)+height(kz)-height(kz-1)
654              clouds(ix,jy,kz,n)=1                               ! is a cloud
655              if (lsp.ge.convp) then
656                clouds(ix,jy,kz,n)=3                            ! lsp in-cloud
657              else
658                clouds(ix,jy,kz,n)=2                             ! convp in-cloud
659              endif                                              ! convective or large scale
[341f4b7]660            elseif((clw(ix,jy,kz,n).le.0) .and. (cloudh_min.ge.height(kz))) then ! is below cloud
[f75967d]661              if (lsp.ge.convp) then
662                clouds(ix,jy,kz,n)=5                             ! lsp dominated washout
663              else
664                clouds(ix,jy,kz,n)=4                             ! convp dominated washout
665              endif                                              ! convective or large scale
666            endif
[8a65cb0]667
[f75967d]668            if (height(kz).ge. 19000) then                        ! set a max height for removal
669              clouds(ix,jy,kz,n)=0
670            endif !clw>0
671          end do !nz
672        endif ! precipitation
673      end do
674    end do
[b0434e1]675
676! eso: copy the relevant data to clw4 to reduce amount of communicated data for MPI
[341f4b7]677!    ctwc(:,:,n) = icloud_stats(:,:,4,n)
[b0434e1]678
[d6a0977]679!**************************************************************************
[f75967d]680  else       ! use old definitions
[d6a0977]681!**************************************************************************
682!   create a cloud and rainout/washout field, clouds occur where rh>80%
683!   total cloudheight is stored at level 0
[b0434e1]684    write(*,*) 'Global fields: using cloud water from Parameterization'
[f75967d]685    do jy=0,nymin1
686      do ix=0,nxmin1
[8a65cb0]687! OLD METHOD
[f75967d]688        rain_cloud_above(ix,jy)=0
689        lsp=lsprec(ix,jy,1,n)
690        convp=convprec(ix,jy,1,n)
691        cloudsh(ix,jy,n)=0
692        do kz_inv=1,nz-1
693          kz=nz-kz_inv+1
694          pressure=rho(ix,jy,kz,n)*r_air*tt(ix,jy,kz,n)
695          rh=qv(ix,jy,kz,n)/f_qvsat(pressure,tt(ix,jy,kz,n))
696          clouds(ix,jy,kz,n)=0
697          if (rh.gt.0.8) then ! in cloud
698            if ((lsp.gt.0.01).or.(convp.gt.0.01)) then ! cloud and precipitation
699              rain_cloud_above(ix,jy)=1
700              cloudsh(ix,jy,n)=cloudsh(ix,jy,n)+ &
701                   height(kz)-height(kz-1)
702              if (lsp.ge.convp) then
703                clouds(ix,jy,kz,n)=3 ! lsp dominated rainout
704              else
705                clouds(ix,jy,kz,n)=2 ! convp dominated rainout
706              endif
707            else ! no precipitation
708              clouds(ix,jy,kz,n)=1 ! cloud
[e200b7a]709            endif
[f75967d]710          else ! no cloud
711            if (rain_cloud_above(ix,jy).eq.1) then ! scavenging
712              if (lsp.ge.convp) then
713                clouds(ix,jy,kz,n)=5 ! lsp dominated washout
714              else
715                clouds(ix,jy,kz,n)=4 ! convp dominated washout
716              endif
[e200b7a]717            endif
[8a65cb0]718          endif
[f75967d]719        end do
[8a65cb0]720!END OLD METHOD
[d6a0977]721      end do
[f75967d]722    end do
723  endif !readclouds
[d6a0977]724
[41d8574]725
[d6a0977]726     !********* TEST ***************
727     ! WRITE OUT SOME TEST VARIABLES
728     !********* TEST ************'**
729!teller(:)=0
730!virr=virr+1
731!WRITE(aspec, '(i3.3)'), virr
732
733!if (readclouds) then
734!fnameH=trim(zhgpath)//trim(aspec)//'Vertical_placement.txt'
735!else
736!fnameH=trim(zhgpath)//trim(aspec)//'Vertical_placement_old.txt'
737!endif
738!
739!OPEN(UNIT=118, FILE=fnameH,FORM='FORMATTED',STATUS = 'UNKNOWN')
740!do kz_inv=1,nz-1
741!  kz=nz-kz_inv+1
742!  !kz=91
743!  do jy=0,nymin1
744!     do ix=0,nxmin1
745!          if (clouds(ix,jy,kz,n).eq.1) teller(1)=teller(1)+1 ! no precipitation cloud
746!          if (clouds(ix,jy,kz,n).eq.2) teller(2)=teller(2)+1 ! convp dominated rainout
747!          if (clouds(ix,jy,kz,n).eq.3) teller(3)=teller(3)+1 ! lsp dominated rainout
748!          if (clouds(ix,jy,kz,n).eq.4) teller(4)=teller(4)+1 ! convp dominated washout
749!          if (clouds(ix,jy,kz,n).eq.5) teller(5)=teller(5)+1 ! lsp dominated washout
750!         
751!        !  write(*,*) height(kz),teller
752!     end do
753!  end do
754!  write(118,*) height(kz),teller
755!  teller(:)=0
756!end do
757!teller(:)=0
758!write(*,*) teller
759!write(*,*) aspec
760!
761!fnameA=trim(zhgpath)//trim(aspec)//'cloudV.txt'
762!fnameB=trim(zhgpath)//trim(aspec)//'cloudT.txt'
763!fnameC=trim(zhgpath)//trim(aspec)//'cloudB.txt'
764!fnameD=trim(zhgpath)//trim(aspec)//'cloudW.txt'
765!fnameE=trim(zhgpath)//trim(aspec)//'old_cloudV.txt'
766!fnameF=trim(zhgpath)//trim(aspec)//'lsp.txt'
767!fnameG=trim(zhgpath)//trim(aspec)//'convp.txt'
768!if (readclouds) then
769!OPEN(UNIT=111, FILE=fnameA,FORM='FORMATTED',STATUS = 'UNKNOWN')
770!OPEN(UNIT=112, FILE=fnameB,FORM='FORMATTED',STATUS = 'UNKNOWN')
771!OPEN(UNIT=113, FILE=fnameC,FORM='FORMATTED',STATUS = 'UNKNOWN')
772!OPEN(UNIT=114, FILE=fnameD,FORM='FORMATTED',STATUS = 'UNKNOWN')
773!else
774!OPEN(UNIT=115, FILE=fnameE,FORM='FORMATTED',STATUS = 'UNKNOWN')
775!OPEN(UNIT=116, FILE=fnameF,FORM='FORMATTED',STATUS = 'UNKNOWN')
776!OPEN(UNIT=117, FILE=fnameG,FORM='FORMATTED',STATUS = 'UNKNOWN')
777!endif
778!
779!do ix=0,nxmin1
780!if (readclouds) then
781!write(111,*) (icloud_stats(ix,jy,1,n),jy=0,nymin1)
782!write(112,*) (icloud_stats(ix,jy,2,n),jy=0,nymin1)
783!write(113,*) (icloud_stats(ix,jy,3,n),jy=0,nymin1)
784!write(114,*) (icloud_stats(ix,jy,4,n),jy=0,nymin1)
785!else
786!write(115,*) (cloudsh(ix,jy,n),jy=0,nymin1)    !integer
787!write(116,*) (lsprec(ix,jy,1,n),jy=0,nymin1)   !7.83691406E-02
788!write(117,*) (convprec(ix,jy,1,n),jy=0,nymin1) !5.38330078E-02
789!endif
790!end do
791!
792!if (readclouds) then
793!CLOSE(111)
794!CLOSE(112)
795!CLOSE(113)
796!CLOSE(114)
797!else
798!CLOSE(115)
799!CLOSE(116)
800!CLOSE(117)
801!endif
802!
803!END ********* TEST *************** END
804! WRITE OUT SOME TEST VARIABLES
805!END ********* TEST *************** END
806
[8a65cb0]807
808! PS 2012
[4d45639]809!      lsp=lsprec(ix,jy,1,n)
810!      convp=convprec(ix,jy,1,n)
[8a65cb0]811!          prec=lsp+convp
812!          if (lsp.gt.convp) then !  prectype='lsp'
813!            lconvectprec = .false.
[6a678e3]814!          else ! prectype='cp'
[8a65cb0]815!            lconvectprec = .true.
[4d45639]816!           endif
[8a65cb0]817!      else ! windfields does not contain cloud data
818!          rhmin = 0.90 ! standard condition for presence of clouds
819!PS       note that original by Sabine Eckhart was 80%
820!PS       however, for T<-20 C we consider saturation over ice
821!PS       so I think 90% should be enough         
822!          icloudbot(ix,jy,n)=icmv
823!          icloudtop=icmv ! this is just a local variable
824!98        do kz=1,nz
825!            pressure=rho(ix,jy,kz,n)*r_air*tt(ix,jy,kz,n)
826!            rh=qv(ix,jy,kz,n)/f_qvsat(pressure,tt(ix,jy,kz,n))
827!ps            if (prec.gt.0.01) print*,'relhum',prec,kz,rh,height(kz)
828!            if (rh .gt. rhmin) then
829!              if (icloudbot(ix,jy,n) .eq. icmv) then
830!                icloudbot(ix,jy,n)=nint(height(kz))
831!              endif
832!              icloudtop=nint(height(kz)) ! use int to save memory
833!            endif
[4d45639]834    ! end do
[8a65cb0]835!PS try to get a cloud thicker than 50 m
836!PS if there is at least .01 mm/h  - changed to 0.002 and put into
837!PS parameter precpmin       
838!          if ((icloudbot(ix,jy,n) .eq. icmv .or. &
839!              icloudtop-icloudbot(ix,jy,n) .lt. 50) .and. &
840!              prec .gt. precmin) then
841!            rhmin = rhmin - 0.05
842!            if (rhmin .ge. 0.30) goto 98 ! give up for <= 25% rel.hum.
[4d45639]843!   end if
[8a65cb0]844
845!PS is based on looking at a limited set of comparison data
846!          if (lconvectprec .and. icloudtop .lt. 6000 .and. &
847!             prec .gt. precmin) then
848!
849!            if (convp .lt. 0.1) then
850!              icloudbot(ix,jy,n) = 500
851!              icloudtop =         8000
852!            else
853!              icloudbot(ix,jy,n) = 0
854!              icloudtop =      10000
855!            endif
856!          endif
857!          if (icloudtop .ne. icmv) then
858!            icloudthck(ix,jy,n) = icloudtop-icloudbot(ix,jy,n)
859!          else
860!            icloudthck(ix,jy,n) = icmv
861!          endif
862!PS  get rid of too thin clouds     
863!          if (icloudthck(ix,jy,n) .lt. 50) then
864!            icloudbot(ix,jy,n)=icmv
865!            icloudthck(ix,jy,n)=icmv
866!          endif
867!hg__________________________________
868!           rcw(ix,jy)=2E-7*prec**0.36
869!           rpc(ix,jy)=prec
870!hg end______________________________
871
872!      endif !hg read clouds
873
[e200b7a]874
[d6a0977]875
[4d45639]876
877!eso measure CPU time
878!  call mpif_mtime('verttransform',1)
879
880!eso print out the same measure as in Leo's routine
881    ! write(*,*) 'verttransform: ', &
882    !      sum(tt(:,:,:,n)*tt(:,:,:,n)), &
883    !      sum(uu(:,:,:,n)*uu(:,:,:,n)),sum(vv(:,:,:,n)*vv(:,:,:,n)),&
884    !      sum(qv(:,:,:,n)*qv(:,:,:,n)),sum(pv(:,:,:,n)*pv(:,:,:,n)),&
885    !      sum(rho(:,:,:,n)*rho(:,:,:,n)),sum(drhodz(:,:,:,n)*drhodz(:,:,:,n)),&
886    !      sum(ww(:,:,:,n)*ww(:,:,:,n)), &
887    !      sum(clouds(:,:,:,n)), sum(cloudsh(:,:,n)),sum(idx),sum(pinmconv)
[f75967d]888end subroutine verttransform
[4d45639]889
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG