Merge remote-tracking branch 'origin/release-v4.5.2'
[WRF.git] / var / convertor / wave2grid_kma / GH2TV.inc
blob4fab8013014002a0a7aa300a8d9cc672e5061ae0
1       SUBROUTINE GH2TV(GZ, TV,    PS,    TOPO, 
2      1                                  A, B, IMAX, JMAX, LMAX,
3      W                                  PK,PBETA,DPHI,ALPHA)
4 C----------------------------------------------------------------------         
5 C     INPUT   GZ  (I,J,L) : GEOPOTENTIAL HEIGHT(M)                              
6 C             PS  (I,J)   : SURFACE PRESSURE(HPA)                               
7 C             TOPO(I,J)   : SURFACE GEOPOTENTIAL(GPM)
8 C             A(L), B(L)  : A+B*PS DEFINITION OF ETA-HALF LEVEL                 
9 C     OUTPUT  TV  (I,J,L) : VIRTUAL TEMPERATURE(K)                              
10 C----------------------------------------------------------------------         
11       DIMENSION Z(IMAX*JMAX,LMAX), TV(IMAX*JMAX,LMAX), PS(IMAX*JMAX),           
12      1     A(LMAX), B(LMAX),TOPO(IMAX*JMAX),GZ(IMAX*JMAX,LMAX)
13       DIMENSION    PK(IMAX*JMAX,LMAX),PBETA(IMAX*JMAX,LMAX),                     
14      1          ALPHA(IMAX*JMAX,LMAX), DPHI(IMAX*JMAX,LMAX)                      
15           DIMENSION VMAX(LMAX),VMIN(LMAX)
16            
17                 Z=GZ*gravity
18 C......... PK is pressure at half level
19         DO L = 1, LMAX
20         DO I = 1, IMAX*JMAX
21           PK(I,L) = A(L)+B(L)*PS(I)
22                 END DO
23                 END DO
24 C...... DPHI is DEL PHI
25                 WRITE(*,*)'MAX PHI(1)=',MAXVAL(Z(:,1)),' MAX TOPO=',MAXVAL(TOPO)
26                 DO I=1, IMAX*JMAX
27                         DPHI(I,1)=Z(I,1)-TOPO(I)
28                 END DO
29                 DO L=2,LMAX
30                 DO I=1, IMAX*JMAX
31                         DPHI(I,L)=Z(I,L)-Z(I,L-1)
32                 END DO
33                 END DO
35 C               VMAX=MAXVAL(DPHI,DIM=1)
36 C               VMIN=MINVAL(DPHI,DIM=1)
37 C               WRITE(*,*)' LEVEL    MAX         MIN   OF DPHI'
38 C               DO L=1,LMAX
39 C                       WRITE(*,'(I3,2F13.4)')L,VMAX(L),VMIN(L)
40 C               END DO
41 C               WRITE(*,*)'MAX(1)=',VMAX(1)
42 C....... PBETA is ln(Pk-1/2)-ln(Pk+1/2)
43         DO L = 1, LMAX-1                                                    
44         DO I = 1, IMAX*JMAX                                                 
45                         PBETA(I,L)=LOG(PK(I,L)/PK(I,L+1))
46                 END DO
47                 END DO
48 C....... ALPHA is ALPHA(K)
49         DO L = 1, LMAX-1                                                    
50         DO I = 1, IMAX*JMAX                                                 
51                         ALPHA(I,L)=1-PK(I,L+1)*PBETA(I,L)/
52      1                            (PK(I,L)-PK(I,L+1))
53                 END DO
54                 END DO
55         DO I = 1, IMAX*JMAX                                                 
56                         ALPHA(I,LMAX)=LOG(2.0)
57                 END DO
59 C               VMAX=MAXVAL(ALPHA,DIM=1)
60 C               VMIN=MINVAL(ALPHA,DIM=1)
61 C               WRITE(*,*)' LEVEL    MAX         MIN   OF ALPHA'
62 C               DO L=1,LMAX
63 C                       WRITE(*,'(I3,2F13.8)')L,VMAX(L),VMIN(L)
64 C               END DO
65 C........ CACULATE Tv
66                 DO I = 1, IMAX*JMAX
67                         TV(I,1)=DPHI(I,1)/(ALPHA(I,1)*gas_constant)
68                 END DO
69                 DO L = 2, LMAX
70                 DO I = 1, IMAX*JMAX
71                   TV(I,L)=(DPHI(I,L)+gas_constant*TV(I,L-1)*
72      1                    (ALPHA(I,L-1)-PBETA(I,L-1)))/
73      1                    (ALPHA(I,L)*gas_constant)
74                 END DO
75                 END DO
77       RETURN                                                                    
78       END SUBROUTINE GH2TV