source: trunk/LMDZ.GENERIC/libf/phystd/gfluxi.F @ 848

Last change on this file since 848 was 804, checked in by lkerber, 12 years ago

A bug was found in gfluxi.F. If co2_ice was the only aerosol, the single scattering albedo was occasionally equal to 1. This led to NaNs? in gfluxi.F because we divide by a (1-W0) statement. Now there is a test in gfluxi.F which puts any W0=1 to W0=99999. This change removed the necessity in aeropacity.F90 for aerosols which are supposed to be zero to be put at 1.E-9 (they are now set to zero). In the case of zero aerosols, a dummy co2 aerosol is created and set to zero abundance everywhere. An obsolete test was removed from inifis.F. Some extraneous print statements were removed from physiq.F90.

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