source: trunk/LMDZ.PLUTO/libf/phypluto/gfluxi_old.F @ 3380

Last change on this file since 3380 was 3362, checked in by tbertrand, 6 months ago

LMDZ.PLUTO:
Adding old versions of gfluxi and gfluxv
TB

File size: 9.4 KB
Line 
1      module gfluxi_old_mod
2     
3      implicit none
4     
5      contains
6     
7      SUBROUTINE GFLUXI_OLD(NLL,TLEV,NW,DW,DTAU,TAUCUM,W0,COSBAR,UBARI,
8     *                  RSF,BTOP,BSURF,FTOPUP,FMIDP,FMIDM)
9     
10      use radinc_h, only: L_TAUMAX, NTfac, NTstart
11      use radinc_h, only: L_NLAYRAD, L_LEVELS
12      use radcommon_h, only: planckir
13      use comcstfi_mod, only: pi
14     
15      IMPLICIT NONE
16     
17!-----------------------------------------------------------------------
18!  THIS SUBROUTINE TAKES THE OPTICAL CONSTANTS AND BOUNDARY CONDITIONS
19!  FOR THE INFRARED FLUX AT ONE WAVELENGTH AND SOLVES FOR THE FLUXES AT
20!  THE LEVELS.  THIS VERSION IS SET UP TO WORK WITH LAYER OPTICAL DEPTHS
21!  MEASURED FROM THE TOP OF EACH LAYER.  THE TOP OF EACH LAYER HAS 
22!  OPTICAL DEPTH ZERO.  IN THIS SUB LEVEL N IS ABOVE LAYER N. THAT IS LAYER N
23!  HAS LEVEL N ON TOP AND LEVEL N+1 ON BOTTOM. OPTICAL DEPTH INCREASES
24!  FROM TOP TO BOTTOM.  SEE C.P. MCKAY, TGM NOTES.
25!  THE TRI-DIAGONAL MATRIX SOLVER IS DSOLVER AND IS DOUBLE PRECISION SO MANY
26!  VARIABLES ARE PASSED AS SINGLE THEN BECOME DOUBLE IN DSOLVER
27!
28! NLL            = NUMBER OF LEVELS (NLAYERS + 1) MUST BE LESS THAT NL (101)
29! TLEV(L_LEVELS) = ARRAY OF TEMPERATURES AT GCM LEVELS
30! WAVEN          = WAVELENGTH FOR THE COMPUTATION
31! DW             = WAVENUMBER INTERVAL
32! DTAU(NLAYER)   = ARRAY OPTICAL DEPTH OF THE LAYERS
33! W0(NLEVEL)     = SINGLE SCATTERING ALBEDO
34! COSBAR(NLEVEL) = ASYMMETRY FACTORS, 0=ISOTROPIC
35! UBARI          = AVERAGE ANGLE, MUST BE EQUAL TO 0.5 IN IR
36! RSF            = SURFACE REFLECTANCE
37! BTOP           = UPPER BOUNDARY CONDITION ON IR INTENSITY (NOT FLUX)
38! BSURF          = SURFACE EMISSION = (1-RSFI)*PLANCK, INTENSITY (NOT FLUX)
39! FP(NLEVEL)     = UPWARD FLUX AT LEVELS
40! FM(NLEVEL)     = DOWNWARD FLUX AT LEVELS
41! FMIDP(NLAYER)  = UPWARD FLUX AT LAYER MIDPOINTS
42! FMIDM(NLAYER)  = DOWNWARD FLUX AT LAYER MIDPOINTS
43!-----------------------------------------------------------------------
44     
45      INTEGER NLL, NLAYER, L, NW, NT, NT2
46      REAL*8  TERM, CPMID, CMMID
47      REAL*8  PLANCK
48      REAL*8  EM,EP
49      REAL*8  COSBAR(L_NLAYRAD), W0(L_NLAYRAD), DTAU(L_NLAYRAD)
50      REAL*8  TAUCUM(L_LEVELS), DTAUK
51      REAL*8  TLEV(L_LEVELS)
52      REAL*8  WAVEN, DW, UBARI, RSF
53      REAL*8  BTOP, BSURF, FMIDP(L_NLAYRAD), FMIDM(L_NLAYRAD)
54      REAL*8  B0(L_NLAYRAD)
55      REAL*8  B1(L_NLAYRAD)
56      REAL*8  ALPHA(L_NLAYRAD)
57      REAL*8  LAMDA(L_NLAYRAD),XK1(L_NLAYRAD),XK2(L_NLAYRAD)
58      REAL*8  GAMA(L_NLAYRAD),CP(L_NLAYRAD),CM(L_NLAYRAD)
59      REAL*8  CPM1(L_NLAYRAD),CMM1(L_NLAYRAD),E1(L_NLAYRAD)
60      REAL*8  E2(L_NLAYRAD)
61      REAL*8  E3(L_NLAYRAD)
62      REAL*8  E4(L_NLAYRAD)
63      REAL*8  FTOPUP, FLUXUP, FLUXDN
64      REAL*8 :: TAUMAX = L_TAUMAX
65
66! AB : variables for interpolation
67      REAL*8 C1
68      REAL*8 C2
69      REAL*8 P1
70      REAL*8 P2
71     
72!=======================================================================
73!     WE GO WITH THE HEMISPHERIC CONSTANT APPROACH IN THE INFRARED
74     
75      NLAYER = L_NLAYRAD
76
77      DO L=1,L_NLAYRAD-1
78
79!-----------------------------------------------------------------------
80! There is a problem when W0 = 1
81!         open(888,file='W0')
82!           if ((W0(L).eq.0.).or.(W0(L).eq.1.)) then
83!             write(888,*) W0(L), L, 'gfluxi'
84!           endif
85! Prevent this with an if statement:
86!-----------------------------------------------------------------------
87         !if (W0(L).eq.1.D0) then
88         !      W0(L) = 0.99999D0
89         !endif
90         
91         ALPHA(L) = SQRT( (1.0D0-W0(L))/(1.0D0-W0(L)*COSBAR(L)) )
92         LAMDA(L) = ALPHA(L)*(1.0D0-W0(L)*COSBAR(L))/UBARI
93         
94         !NT    = int(TLEV(2*L)*NTfac)   - NTstart+1
95         !NT2   = int(TLEV(2*L+2)*NTfac) - NTstart+1
96         NT2   = int(TLEV(2*L+2)*10.0D0)-NTstart +1
97         NT    = int(TLEV(2*L)*10.0D0)-NTstart + 1
98         
99! AB : PLANCKIR(NW,NT) is replaced by P1, the linear interpolation result for a temperature NT
100! AB : idem for PLANCKIR(NW,NT2) and P2
101         !C1 = TLEV(2*L) * NTfac - int(TLEV(2*L) * NTfac)
102         !C2 = TLEV(2*L+2)*NTfac - int(TLEV(2*L+2)*NTfac)
103         !P1 = (1.0D0 - C1) * PLANCKIR(NW,NT) + C1 * PLANCKIR(NW,NT+1)
104         !P2 = (1.0D0 - C2) * PLANCKIR(NW,NT2) + C2 * PLANCKIR(NW,NT2+1)
105         !B1(L) = (P2 - P1) / DTAU(L)
106         !B0(L) = P1
107         B1(L) = (PLANCKIR(NW,NT2)-PLANCKIR(NW,NT))/DTAU(L)
108         B0(L) = PLANCKIR(NW,NT)
109      END DO
110     
111!     Take care of special lower layer
112     
113      L        = L_NLAYRAD
114
115      !if (W0(L).eq.1.) then
116      !    W0(L) = 0.99999D0
117      !end if
118     
119      ALPHA(L) = SQRT( (1.0D0-W0(L))/(1.0D0-W0(L)*COSBAR(L)) )
120      LAMDA(L) = ALPHA(L)*(1.0D0-W0(L)*COSBAR(L))/UBARI
121     
122      ! Tsurf is used for 1st layer source function
123      ! -- same results for most thin atmospheres
124      ! -- and stabilizes integrations
125      !NT    = int(TLEV(2*L+1)*NTfac) - NTstart+1
126      !! For deep, opaque, thick first layers (e.g. Saturn)
127      !! what is below works much better, not unstable, ...
128      !! ... and actually fully accurate because 1st layer temp (JL)
129      !NT    = int(TLEV(2*L)*NTfac) - NTstart+1
130      !! (or this one yields same results
131      !NT    = int( (TLEV(2*L)+TLEV(2*L+1))*0.5*NTfac ) - NTstart+1
132     
133      !NT2   = int(TLEV(2*L)*NTfac)   - NTstart+1
134      NT2   = TLEV(2*L+1)*10.0D0-NTstart +1
135      NT    = TLEV(2*L)*10.0D0-NTstart + 1
136     
137! AB : PLANCKIR(NW,NT) is replaced by P1, the linear interpolation result for a temperature NT
138! AB : idem for PLANCKIR(NW,NT2) and P2
139      !C1 = TLEV(2*L+1)*NTfac - int(TLEV(2*L+1)*NTfac)
140      !C2 = TLEV(2*L) * NTfac - int(TLEV(2*L) * NTfac)
141      !P1 = (1.0D0 - C1) * PLANCKIR(NW,NT) + C1 * PLANCKIR(NW,NT+1)
142      !P2 = (1.0D0 - C2) * PLANCKIR(NW,NT2) + C2 * PLANCKIR(NW,NT2+1)
143      !B1(L) = (P1 - P2) / DTAU(L)
144      !B0(L) = P2
145      B1(L) = (PLANCKIR(NW,NT)-PLANCKIR(NW,NT2))/DTAU(L)
146      B0(L) = PLANCKIR(NW,NT2)
147     
148      DO L=1,L_NLAYRAD
149         GAMA(L) = (1.0D0-ALPHA(L))/(1.0D0+ALPHA(L))
150         TERM    = UBARI/(1.0D0-W0(L)*COSBAR(L))
151         
152! CPM1 AND CMM1 ARE THE CPLUS AND CMINUS TERMS EVALUATED
153! AT THE TOP OF THE LAYER, THAT IS ZERO OPTICAL DEPTH
154         
155         CP(L) = B0(L)+B1(L)*DTAU(L) +B1(L)*TERM
156         CM(L) = B0(L)+B1(L)*DTAU(L) -B1(L)*TERM
157
158         CPM1(L) = B0(L)+B1(L)*TERM
159         CMM1(L) = B0(L)-B1(L)*TERM
160         
161! CP AND CM ARE THE CPLUS AND CMINUS TERMS EVALUATED AT THE
162! BOTTOM OF THE LAYER.  THAT IS AT DTAU OPTICAL DEPTH.
163! JL18 put CP and CM after the calculation of CPM1 and CMM1 to avoid unecessary calculations.
164         
165         !CP(L) = CPM1(L) +B1(L)*DTAU(L)
166         !CM(L) = CMM1(L) +B1(L)*DTAU(L)
167      END DO
168     
169! NOW CALCULATE THE EXPONENTIAL TERMS NEEDED
170! FOR THE TRIDIAGONAL ROTATED LAYERED METHOD
171! WARNING IF DTAU(J) IS GREATER THAN ABOUT 35 (VAX)
172! WE CLIP IT TO AVOID OVERFLOW.
173     
174      DO L=1,L_NLAYRAD
175        EP    = EXP( MIN((LAMDA(L)*DTAU(L)),TAUMAX)) ! CLIPPED EXPONENTIAL
176        EM    = 1.0D0/EP
177        E1(L) = EP+GAMA(L)*EM
178        E2(L) = EP-GAMA(L)*EM
179        E3(L) = GAMA(L)*EP+EM
180        E4(L) = GAMA(L)*EP-EM
181      END DO
182     
183!      B81=BTOP  ! RENAME BEFORE CALLING DSOLVER - used to be to set
184!      B82=BSURF ! them to real*8 - but now everything is real*8
185!      R81=RSF   ! so this may not be necessary
186
187! DOUBLE PRECISION TRIDIAGONAL SOLVER
188     
189      CALL DSOLVER(NLAYER,GAMA,CP,CM,CPM1,CMM1,E1,E2,E3,E4,BTOP,
190     *             BSURF,RSF,XK1,XK2)
191     
192! NOW WE CALCULATE THE FLUXES AT THE MIDPOINTS OF THE LAYERS.
193     
194      DO L=1,L_NLAYRAD-1
195         DTAUK = TAUCUM(2*L+1)-TAUCUM(2*L)
196         EP    = EXP(MIN(LAMDA(L)*DTAUK,TAUMAX)) ! CLIPPED EXPONENTIAL
197         EM    = 1.0D0/EP
198         TERM  = UBARI/(1.D0-W0(L)*COSBAR(L))
199         
200! CP AND CM ARE THE CPLUS AND CMINUS TERMS EVALUATED AT THE
201! BOTTOM OF THE LAYER.  THAT IS AT DTAU  OPTICAL DEPTH
202         
203         CPMID    = B0(L)+B1(L)*DTAUK +B1(L)*TERM
204         CMMID    = B0(L)+B1(L)*DTAUK -B1(L)*TERM
205         FMIDP(L) = XK1(L)*EP + GAMA(L)*XK2(L)*EM + CPMID
206         FMIDM(L) = XK1(L)*EP*GAMA(L) + XK2(L)*EM + CMMID
207         
208! FOR FLUX WE INTEGRATE OVER THE HEMISPHERE TREATING INTENSITY CONSTANT
209         
210         FMIDP(L) = FMIDP(L)*PI
211         FMIDM(L) = FMIDM(L)*PI
212      END DO
213     
214! And now, for the special bottom layer
215
216      L    = L_NLAYRAD
217
218      EP   = EXP(MIN((LAMDA(L)*DTAU(L)),TAUMAX)) ! CLIPPED EXPONENTIAL
219      EM   = 1.0D0/EP
220      TERM = UBARI/(1.D0-W0(L)*COSBAR(L))
221
222! CP AND CM ARE THE CPLUS AND CMINUS TERMS EVALUATED AT THE
223! BOTTOM OF THE LAYER.  THAT IS AT DTAU  OPTICAL DEPTH
224
225      CPMID    = B0(L)+B1(L)*DTAU(L) +B1(L)*TERM
226      CMMID    = B0(L)+B1(L)*DTAU(L) -B1(L)*TERM
227      FMIDP(L) = XK1(L)*EP + GAMA(L)*XK2(L)*EM + CPMID
228      FMIDM(L) = XK1(L)*EP*GAMA(L) + XK2(L)*EM + CMMID
229 
230! FOR FLUX WE INTEGRATE OVER THE HEMISPHERE TREATING INTENSITY CONSTANT
231     
232      FMIDP(L) = FMIDP(L)*PI
233      FMIDM(L) = FMIDM(L)*PI
234     
235! FLUX AT THE PTOP LEVEL
236     
237      EP   = 1.0D0
238      EM   = 1.0D0
239      TERM = UBARI/(1.0D0-W0(1)*COSBAR(1))
240     
241! CP AND CM ARE THE CPLUS AND CMINUS TERMS EVALUATED AT THE
242! BOTTOM OF THE LAYER.  THAT IS AT DTAU  OPTICAL DEPTH
243     
244      CPMID  = B0(1)+B1(1)*TERM
245      CMMID  = B0(1)-B1(1)*TERM
246     
247      FLUXUP = XK1(1)*EP + GAMA(1)*XK2(1)*EM + CPMID
248      FLUXDN = XK1(1)*EP*GAMA(1) + XK2(1)*EM + CMMID
249     
250! FOR FLUX WE INTEGRATE OVER THE HEMISPHERE TREATING INTENSITY CONSTANT
251     
252      FTOPUP = (FLUXUP-FLUXDN)*PI
253     
254     
255      END SUBROUTINE GFLUXI_OLD
256
257      end module gfluxi_old_mod
Note: See TracBrowser for help on using the repository browser.