1 | subroutine tpindex(pw,tw,qvar,pref,tref,wrefvar,LCOEF,MT,MP, |
---|
2 | & NVAR,wratio) |
---|
3 | |
---|
4 | !================================================================== |
---|
5 | ! |
---|
6 | ! Purpose |
---|
7 | ! ------- |
---|
8 | ! Interpolate K-coefficients to the given P,T and Qvar values. |
---|
9 | ! |
---|
10 | ! Notes |
---|
11 | ! ----- |
---|
12 | ! The interpolation is the usual one in two dimensions given |
---|
13 | ! in "Numerical Recipes", where the "X" are P, the "Y" are |
---|
14 | ! T, and the F(X,Y) are the CO2 K-coefficients. |
---|
15 | ! |
---|
16 | ! The interpolating box is: |
---|
17 | ! |
---|
18 | ! (PL,TU) (PR,TU) |
---|
19 | ! |
---|
20 | ! (TW,PW) |
---|
21 | ! |
---|
22 | ! |
---|
23 | ! (PL,TL) (PR,TL) |
---|
24 | ! |
---|
25 | ! PL - Pressure left |
---|
26 | ! PR - Pressure right |
---|
27 | ! TL - Temperature lower |
---|
28 | ! TU - Temperature upper |
---|
29 | ! PW - Pressure wanted |
---|
30 | ! TW - Temperature wanted |
---|
31 | ! |
---|
32 | ! Inputs |
---|
33 | ! ------ |
---|
34 | ! PW - The pressure to interpolate to |
---|
35 | ! TW - The temperature to interpolate to |
---|
36 | ! Pref(NP) - The pressure grid array |
---|
37 | ! Tref(NT) - The temperature grid array |
---|
38 | ! |
---|
39 | ! Outputs |
---|
40 | ! ------- |
---|
41 | ! TI - Interpolation term (pressure) |
---|
42 | ! UI - Interpolation term (temperature) |
---|
43 | ! MT - Temperature index (bottom left temperature) |
---|
44 | ! of bounding box |
---|
45 | ! MP - Pressure index (bottom left pressure) |
---|
46 | ! of bounding box |
---|
47 | ! |
---|
48 | ! Authors |
---|
49 | ! ------- |
---|
50 | ! Adapted from the NASA Ames code by R. Wordsworth (2009) |
---|
51 | ! |
---|
52 | !================================================================== |
---|
53 | |
---|
54 | use radinc_h |
---|
55 | |
---|
56 | implicit none |
---|
57 | |
---|
58 | real*8 Tref(L_NTREF) |
---|
59 | real*8 pref(L_PINT) |
---|
60 | real*8 wrefvar(L_REFVAR) |
---|
61 | |
---|
62 | integer MT, MP, N, M, NP, NVAR |
---|
63 | real*8 PW, TW, Qvar, wratio |
---|
64 | real*8 PWL, LCOEF(4), T, U |
---|
65 | |
---|
66 | C======================================================================C |
---|
67 | |
---|
68 | ! Get the upper and lower temperature grid indicies that bound the |
---|
69 | ! requested temperature. If the requested temperature is outside |
---|
70 | ! the T-grid, set up to extrapolate from the appropriate end. |
---|
71 | ! TW : temperature to be interpolated |
---|
72 | ! TREF : grid array |
---|
73 | ! MT : index of TREF for bounding new temperature |
---|
74 | ! U : new temperature interpolated |
---|
75 | |
---|
76 | IF(TW.LE.TREF(1)) THEN |
---|
77 | MT = 1 |
---|
78 | ELSE |
---|
79 | do n=1,L_NTREF-1 |
---|
80 | if(tw.gt.Tref(n) .and. TW.LE.TREF(N+1)) then |
---|
81 | MT = n |
---|
82 | goto 10 |
---|
83 | end if |
---|
84 | end do |
---|
85 | |
---|
86 | MT = L_NTREF-1 |
---|
87 | |
---|
88 | 10 continue |
---|
89 | END IF |
---|
90 | |
---|
91 | !TB: case low temp : MT=1: fixed TW right above tref(1) |
---|
92 | IF (MT.eq.1) THEN |
---|
93 | TW=tref(1)*1.01 |
---|
94 | ! write(*,*) 'Caution! Pressure of upper levels lower than |
---|
95 | ! $ ref pressure for k-coef: k-coeff fixed for upper levels' |
---|
96 | ENDIF |
---|
97 | |
---|
98 | U = (TW-TREF(MT))/(TREF(MT+1)-TREF(MT)) |
---|
99 | |
---|
100 | ! Get the upper and lower pressure grid indicies that bound the |
---|
101 | ! requested pressure. If the requested pressure is outside |
---|
102 | ! the P-grid, set up to extrapolate from the appropriate end. |
---|
103 | |
---|
104 | pwl = log10(pw) |
---|
105 | |
---|
106 | do n=2,L_PINT-1 |
---|
107 | if(pwl.le.Pref(n)) then |
---|
108 | MP = n-1 |
---|
109 | goto 20 |
---|
110 | end if |
---|
111 | end do |
---|
112 | |
---|
113 | MP = L_PINT-1 |
---|
114 | |
---|
115 | 20 continue |
---|
116 | |
---|
117 | !TB: case low pressure : n=2 : fixed pwl, right above pref(1) |
---|
118 | IF (MP.eq.1) THEN |
---|
119 | PWL=Pref(1)*1.01 |
---|
120 | ! write(*,*) 'Caution! Pressure of upper levels lower than |
---|
121 | ! $ ref pressure for k-coef: k-coeff fixed for upper levels' |
---|
122 | ENDIF |
---|
123 | |
---|
124 | ! interpolated pressure |
---|
125 | T = (PWL-PREF(MP))/(PREF(MP+1)-PREF(MP)) |
---|
126 | |
---|
127 | ! Fill in the interpolation coefficients |
---|
128 | LCOEF(1) = (1.0-T)*(1.0-U) |
---|
129 | LCOEF(2) = T*(1.0-U) |
---|
130 | LCOEF(3) = T*U |
---|
131 | LCOEF(4) = (1.0-T)*U |
---|
132 | |
---|
133 | ! Get the indicies for abundance of the varying species. There are 10 sets of |
---|
134 | ! k-coefficients with differing amounts of variable vs. constant gas. |
---|
135 | |
---|
136 | IF(QVAR.le.WREFVAR(1)) then |
---|
137 | NVAR = 1 |
---|
138 | WRATIO = 0.0D0 |
---|
139 | ELSEIF(QVAR.ge.WREFVAR(L_REFVAR)) then |
---|
140 | NVAR = L_REFVAR-1 |
---|
141 | WRATIO = 0.99D0 |
---|
142 | ELSE |
---|
143 | DO N=2,L_REFVAR |
---|
144 | IF(QVAR.GE.WREFVAR(N-1) .and. QVAR.lt.WREFVAR(N)) then |
---|
145 | NVAR = N-1 |
---|
146 | WRATIO = (QVAR - WREFVAR(N-1))/(WREFVAR(N) - WREFVAR(N-1)) |
---|
147 | GOTO 30 |
---|
148 | END IF |
---|
149 | END DO |
---|
150 | END IF |
---|
151 | |
---|
152 | 30 CONTINUE |
---|
153 | |
---|
154 | return |
---|
155 | end |
---|