1 subroutine da_cloud_sim(KINDIC,KDIM,PX,PF,PG,IZS,RZS,DZS)
5 ! Simulate the cloud as a linear combination of grey clouds at model levels
10 ! KDIM : Dimension of cloud fraction variable
11 ! PX : Cloud fraction variable -> Input
13 ! PG : Gradient of cloud fraction variable -> Output
26 ! 01/08/2005 Thomas Auligne *ECMWF*
31 ! ---------------------------------------------------------------------------------------------
36 INTEGER,INTENT(IN) :: KINDIC
37 INTEGER,INTENT(IN) :: KDIM
38 INTEGER,INTENT(IN) :: IZS(2)
39 double precision ,INTENT(INOUT) :: PX(KDIM) !izs(2)
40 double precision ,INTENT(OUT) :: PF
41 double precision ,INTENT(OUT) :: PG(KDIM)
42 real ,INTENT(IN) :: RZS(kdim*izs(2)) ! Eigenvectors
43 DOUBLE PRECISION ,INTENT(IN) :: DZS(IZS(1)*KDIM) ! AMAT
45 INTEGER :: JCH, ilev, JLEV, nchan, neignvec
46 REAL :: ZNORM_PG, ZCLR, ZDCLR, eignvec(kdim,izs(2)), eignval(izs(2))
47 double precision :: AMAT(IZS(1),KDIM)
48 double precision :: alpha, beta
49 double precision :: zx(KDIM), zgx(KDIM, KDIM), zx_eof(KDIM)
51 !IF (KINDIC == 1) RETURN
56 !eignvec = RESHAPE(rzs(1:KDIM*neignvec),(/KDIM,neignvec/))
57 !eignval = rzs(KDIM*neignvec+1:(KDIM+1)*neignvec)
59 AMAT = RESHAPE(DZS(1:NCHAN*KDIM),(/NCHAN,KDIM/))
60 PX(KDIM) = 1.0 - SUM(PX(1:kdim-1))
61 ! where (PX < 0.0) PX = 0.0
62 ! where (PX > 1.0) PX = 1.0
64 !ZX_EOF = MATMUL(eignvec,eignval*PX)
65 !!! ZX_EOF = MATMUL(eignvec,MATMUL(TRANSPOSE(eignvec),PX))
69 ! Softmax (= multiple-logistic) variable transform
72 !zx = exp(beta*zx_eof) / SUM(exp(beta*zx_eof))
75 ! zgx(ilev,jlev) = - beta * zx(ilev) * zx(jlev)
76 ! if (ilev == jlev) zgx(ilev,jlev) = zgx(ilev,jlev) + zx(ilev) * beta
81 PF = PF + 0.5 * (SUM(ZX*AMAT(JCH,:)) - 1.0)**2
83 PG(JLEV) = PG(JLEV) + (AMAT(JCH,JLEV)-AMAT(JCH,KDIM)) * (SUM(ZX*AMAT(JCH,:)) - 1.0)
88 alpha = float(nchan)*100.0
89 PF = PF + 0.5*alpha*SUM(ZX**2, MASK=ZX<0.0)
90 WHERE (ZX<0.0) PG = PG + alpha*ZX
92 !write(*,'(a,2f10.2,50f6.1)') 'ACD_PX',PF,sqrt(sum(pg**2)),sum(px(1:kdim-1))*100.,PX*100.
93 !write(*,'(a,2f10.5,f10.2,50f7.2)') '888888 ',PF,sqrt(sum(pg**2)),sum(zx(1:kdim-1))*100.,ZX*100.
95 end subroutine da_cloud_sim