source: trunk/LMDZ.MARS/libf/phymars/swr_toon.F @ 2077

Last change on this file since 2077 was 1266, checked in by aslmd, 11 years ago

LMDZ.MARS
IMPORTANT CHANGE

  • Remove all reference/use of nlayermx and dimphys.h
  • Made use of automatic arrays whenever arrays are needed with dimension nlayer
  • Remove lots of obsolete reference to dimensions.h
  • Converted iono.h and param_v4.h into corresponding modules

(with embedded subroutine to allocate arrays)
(no arrays allocated if thermosphere not used)

  • Deleted param.h and put contents into module param_v4_h
  • Adapted testphys1d, newstart, etc...
  • Made DATA arrays in param_read to be initialized by subroutine

fill_data_thermos in module param_v4_h

  • Optimized computations in paramfoto_compact (twice less dlog10 calculations)
  • Checked consistency before/after modification in debug mode
  • Checked performance is not impacted (same as before)
File size: 17.6 KB
Line 
1      SUBROUTINE SWR_TOON ( KDLON, KFLEV, KNU
2     S     ,  aerosol,QVISsQREF3d,omegaVIS3d,gVIS3d
3     &     ,  albedo,PDSIG,PPSOL,PRMU,PSEC
4     S     ,  PFD,PFU )
5
6      use dimradmars_mod, only: sunfr, ndlo2, nsun, nflev,
7     &                          ndlon, naerkind
8      use yomlw_h, only: nlaylte
9     
10      IMPLICIT NONE
11C     
12#include "callkeys.h"
13
14C     
15C   SWR - Continuum scattering computations
16C     
17C     PURPOSE.
18C     --------
19C     Computes the reflectivity and transmissivity in case oF
20C     Continuum scattering
21c     F. Forget (1999)
22c   
23c     Modified by Tran The Trung, using radiative transfer code
24c     of Toon 1981. 
25C     
26C     IMPLICIT ARGUMENTS :
27C     --------------------
28C     
29C     ==== INPUTS ===
30c
31c    KDLON :  number of horizontal grid points
32c    KFLEV :  number of vertical layers
33c    KNU   :   Solar band # (1 or 2)
34c   aerosol               aerosol extinction optical depth
35c                         at reference wavelength "longrefvis" set
36c                         in dimradmars_mod , in each layer, for one of
37c                         the "naerkind" kind of aerosol optical properties.
38c    albedo   hemispheric surface albedo
39c                         albedo (i,1) : mean albedo for solar band#1
40c                                        (see below)
41c                         albedo (i,2) : mean albedo for solar band#2
42c                                        (see below)
43c    PDSIG      layer thickness in sigma coordinates
44c    PPSOL       Surface pressure (Pa)
45c    PRMU:  cos of solar zenith angle (=1 when sun at zenith)
46c           (CORRECTED for high zenith angle (atmosphere), unlike mu0)
47c    PSEC   =1./PRMU
48
49C     ==== OUTPUTS ===
50c
51c    PFD : downward flux in spectral band #INU in a given mesh
52c         (normalized to the total incident flux at the top of the atmosphere)
53c    PFU : upward flux in specatral band #INU in a given mesh
54c         (normalized to the total incident flux at the top of the atmosphere)
55C
56C     
57C     METHOD.
58C     -------
59C     
60C     Computes continuum fluxes corresponding to aerosoL
61C     Or/and rayleigh scattering (no molecular gas absorption)
62C     
63C-----------------------------------------------------------------------
64C     
65C     
66C-----------------------------------------------------------------------
67C     
68     
69C     ARGUMENTS
70C     ---------
71      INTEGER KDLON, KFLEV, KNU
72      REAL aerosol(NDLO2,KFLEV,naerkind), albedo(NDLO2,2),
73     S     PDSIG(NDLO2,KFLEV),PSEC(NDLO2)
74
75      REAL QVISsQREF3d(NDLO2,KFLEV,nsun,naerkind) 
76      REAL omegaVIS3d(NDLO2,KFLEV,nsun,naerkind)   
77      REAL gVIS3d(NDLO2,KFLEV,nsun,naerkind)
78
79      REAL PPSOL(NDLO2)
80      REAL PFD(NDLO2,KFLEV+1),PFU(NDLO2,KFLEV+1)
81      REAL PRMU(NDLO2)
82
83C     LOCAL ARRAYS
84C     ------------
85 
86      INTEGER jk,jl,jae
87      REAL ZTRAY, ZRATIO,ZGAR, ZFF
88      REAL ZCGAZ(NDLO2,NFLEV),ZPIZAZ(NDLO2,NFLEV),ZTAUAZ(NDLO2,NFLEV)
89      REAL  ZRAYL(NDLON)
90
91c     Part added by Tran The Trung
92c     inputs to gfluxv
93      REAL*8 DTDEL(nlaylte), WDEL(nlaylte), CDEL(nlaylte)
94c     outputs of gfluxv
95      REAL*8 FP(nlaylte+1), FM(nlaylte+1)     
96c     normalization of top downward flux
97      REAL*8 norm
98c     End part added by Tran The Trung
99
100c     Function
101c     --------
102      real CVMGT
103
104c Computing TOTAL single scattering parameters by adding
105c  properties of all the NAERKIND kind of aerosols
106
107      DO JK = 1 , nlaylte
108         DO  JL = 1 , KDLON
109            ZCGAZ(JL,JK) = 0.
110            ZPIZAZ(JL,JK) =  0.
111            ZTAUAZ(JL,JK) = 0.
112         END DO
113         DO 106 JAE=1,naerkind
114            DO 105 JL = 1 , KDLON
115c              Mean Extinction optical depth in the spectral band
116c              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117               ZTAUAZ(JL,JK)=ZTAUAZ(JL,JK)
118     S              +aerosol(JL,JK,JAE)*QVISsQREF3d(JL,JK,KNU,JAE)
119c              Single scattering albedo
120c              ~~~~~~~~~~~~~~~~~~~~~~~~
121               ZPIZAZ(JL,JK)=ZPIZAZ(JL,JK)+aerosol(JL,JK,JAE)*
122     S           QVISsQREF3d(JL,JK,KNU,JAE)*
123     &           omegaVIS3d(JL,JK,KNU,JAE)
124c              Assymetry factor
125c              ~~~~~~~~~~~~~~~~
126               ZCGAZ(JL,JK) =  ZCGAZ(JL,JK) +aerosol(JL,JK,JAE)*
127     S           QVISsQREF3d(JL,JK,KNU,JAE)*
128     &           omegaVIS3d(JL,JK,KNU,JAE)*gVIS3d(JL,JK,KNU,JAE)
129 105        CONTINUE
130 106     CONTINUE
131      END DO
132C     
133      DO JK = 1 , nlaylte
134         DO JL = 1 , KDLON
135            ZCGAZ(JL,JK) = CVMGT( 0., ZCGAZ(JL,JK) / ZPIZAZ(JL,JK),
136     S            (ZPIZAZ(JL,JK).EQ.0) )
137            ZPIZAZ(JL,JK) = CVMGT( 1., ZPIZAZ(JL,JK) / ZTAUAZ(JL,JK),
138     S           (ZTAUAZ(JL,JK).EQ.0) )
139         END DO
140      END DO
141
142C     --------------------------------
143C     INCLUDING RAYLEIGH SCATERRING
144C     -------------------------------
145      if (rayleigh) then
146
147        call swrayleigh(kdlon,knu,ppsol,prmu,ZRAYL)
148
149c       Modifying mean aerosol parameters to account rayleigh scat by gas:
150
151        DO JK = 1 , nlaylte
152           DO JL = 1 , KDLON
153c             Rayleigh opacity in each layer :
154              ZTRAY = ZRAYL(JL) * PDSIG(JL,JK)
155c             ratio Tau(rayleigh) / Tau (total)
156              ZRATIO = ZTRAY / (ZTRAY + ZTAUAZ(JL,JK))
157              ZGAR = ZCGAZ(JL,JK)
158              ZFF = ZGAR * ZGAR
159                ZTAUAZ(JL,JK)=ZTRAY+ZTAUAZ(JL,JK)*(1.-ZPIZAZ(JL,JK)*ZFF)
160              ZCGAZ(JL,JK) = ZGAR * (1. - ZRATIO) / (1. + ZGAR)
161              ZPIZAZ(JL,JK) =ZRATIO+(1.-ZRATIO)*ZPIZAZ(JL,JK)*(1.-ZFF)
162     S           / (1. -ZPIZAZ(JL,JK) * ZFF)
163           END DO
164        END DO
165      end if
166
167c     Part added by Tran The Trung
168c     new radiative transfer
169
170      do JL = 1, KDLON
171
172c     assign temporary inputs
173        do JK = 1, nlaylte
174           jae = nlaylte+1-JK
175           DTDEL(JK) = real(ZTAUAZ(JL,jae),8)
176           WDEL(JK) = real(ZPIZAZ(JL,jae),8)
177           CDEL(JK) = real(ZCGAZ(JL,jae),8)
178        end do
179
180c     call gfluxv
181        call gfluxv(nlaylte, DTDEL,WDEL,CDEL,
182     S              real(PRMU(JL),8),
183     S              real(albedo(JL,KNU),8),
184     S              FP,FM)
185
186c     assign output
187        norm = FM(1)
188c     here we can have a check of norm not being 0.0
189c     however it would never happen in practice,
190c     so we can comment out
191c        if (norm .gt. 0.0) then
192          do JK = 1, nlaylte+1
193             jae = nlaylte+2-JK
194             PFU(JL,JK) = sunfr(KNU)*real(FP(jae)/norm,4)
195             PFD(JL,JK) = sunfr(KNU)*real(FM(jae)/norm,4)
196          end do
197c        elseif (norm .eq. 0.0) then
198c          do JK = 1, nlaylte+1
199c             PFU(JL,JK) = 0.0
200c             PFD(JL,JK) = 0.0
201c          end do
202c        else
203c          stop "Error: top downward visible flux is negative!"
204c        end if
205 
206      end do
207c     End part added by Tran The Trung
208
209      RETURN
210      END
211
212CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
213
214      SUBROUTINE GFLUXV(NAYER,DTDEL,WDEL,CDEL,UBAR0,RSF
215     &                 ,FP,FM)
216      IMPLICIT NONE
217C  THIS SUBROUTINE TAKES THE OPTICAL CONSTANTS AND BOUNDARY CONDITONS
218C  FOR THE VISIBLE  FLUX AT ONE WAVELENGTH AND SOLVES FOR THE FLUXES AT
219C  THE LEVELS. THIS VERSION IS SET UP TO WORK WITH LAYER OPTICAL DEPTHS
220C  MEASURED FROM THE TOP OF EACH LAYER.  (DTAU) TOP OF EACH LAYER HAS
221C  OPTICAL DEPTH TAU(N). IN THIS SUB LEVEL N IS ABOVE LAYER N. THAT IS LAYER N
222C  HAS LEVEL N ON TOP AND LEVEL N+1 ON BOTTOM. OPTICAL DEPTH INCREASES
223C  FROM TOP TO BOTTOM. SEE C.P. MCKAY, TGM NOTES.
224C  THIS SUBROUTINE DIFFERS FROM ITS IR CONTERPART IN THAT HERE WE SOLVE FOR
225C  THE FLUXES DIRECTLY USING THE GENERALIZED NOTATION OF MEADOR AND WEAVOR
226C  J.A.S., 37, 630-642, 1980.
227C  THE TRI-DIAGONAL MATRIX SOLVER IS DSOLVER AND IS DOUBLE PRECISION SO MANY
228C  VARIABLES ARE PASSED AS SINGLE THEN BECOME DOUBLE IN DSOLVER
229
230C  THIS VERSION HAS BEEN MODIFIED BY TRAN THE TRUNG WITH:
231C   1. Simplified input & output for swr.F subroutine in LMDZ.MARS gcm model
232C   2. Use delta function to modify optical properties
233C   3. Use delta-eddington G1, G2, G3 parameters
234C   4. Optimized for speed
235
236C  INPUTS:
237      INTEGER NAYER     
238c   NAYER = number of layer
239c            first layer is at top
240c            last layer is at bottom
241      REAL*8 DTDEL(NAYER), WDEL(NAYER), CDEL(NAYER)
242c   DTDEL = optical thickness of layer
243c   WDEL = single scattering of layer
244c   CDEL = assymetry parameter
245      REAL*8 UBAR0, RSF
246c   UBAR0 = absolute value of cosine of solar zenith angle
247c   RSF = surface albedo
248C  OUTPUTS:
249      REAL*8 FP(NAYER+1), FM(NAYER+1)
250c   FP = flux up
251c   FM = flux down
252C  PRIVATES:
253      INTEGER J,NL,NLEV
254!!!! AS+JBM 03/2010 BUG BUG si trop niveaux verticaux (LES)
255!!!!                ET PAS BESOIN DE HARDWIRE SALE ICI  !   
256!!!! CORRIGER CE BUG AMELIORE EFFICACITE ET FLEXIBILITE     
257      !! PARAMETER (NL=201)
258      !! C THIS VALUE (201) MUST BE .GE. 2*NAYER
259      REAL*8 BSURF,AP,AM,DENOM,EM,EP,G4
260      !! REAL*8 W0(NL), COSBAR(NL), DTAU(NL), TAU(NL)
261      !! REAL*8 LAMDA(NL),XK1(NL),XK2(NL)
262      !! REAL*8 G1(NL),G2(NL),G3(NL)
263      !! REAL*8 GAMA(NL),CP(NL),CM(NL),CPM1(NL),CMM1(NL)
264      !! REAL*8 E1(NL),E2(NL),E3(NL),E4(NL)
265      REAL*8 W0(2*NAYER), COSBAR(2*NAYER), DTAU(2*NAYER), TAU(2*NAYER) 
266      REAL*8 LAMDA(2*NAYER),XK1(2*NAYER),XK2(2*NAYER)
267      REAL*8 G1(2*NAYER),G2(2*NAYER),G3(2*NAYER)
268      REAL*8 GAMA(2*NAYER),CP(2*NAYER),CM(2*NAYER),CPM1(2*NAYER)
269      REAL*8 CMM1(2*NAYER)
270      REAL*8 E1(2*NAYER),E2(2*NAYER),E3(2*NAYER),E4(2*NAYER)
271
272      NL = 2*NAYER  !!! AS+JBM 03/2010
273      NLEV = NAYER+1
274     
275C  TURN ON THE DELTA-FUNCTION IF REQUIRED HERE
276c      TAU(1) = 0.0
277c      DO J=1,NAYER
278c        W0(J)=WDEL(J)
279c        COSBAR(J)=CDEL(J)
280c        DTAU(J)=DTDEL(J)
281c        TAU(J+1)=TAU(J)+DTAU(J)
282c      END DO
283C  FOR THE DELTA FUNCTION  HERE...
284      TAU(1) = 0.0
285      DO J=1,NAYER
286        COSBAR(J)=CDEL(J)/(1.+CDEL(J))
287        W0(J)=1.-WDEL(J)*CDEL(J)**2
288        DTAU(J)=DTDEL(J)*W0(J)
289        W0(J)=WDEL(J)*(1.-CDEL(J)**2)/W0(J)
290        TAU(J+1)=TAU(J)+DTAU(J)
291      END DO
292     
293c     Optimization, this is the major speed gain
294      TAU(1) = 1.0
295      do J = 2, NAYER+1
296        TAU(J) = EXP(-TAU(J)/UBAR0)
297      end do
298      BSURF = RSF*UBAR0*TAU(NLEV)
299C  WE GO WITH THE HEMISPHERIC CONSTANT APPROACH
300C  AS DEFINED BY M&W - THIS IS THE WAY THE IR IS DONE
301      DO J=1,NAYER
302c        Optimization: ALPHA not used
303c        ALPHA(J)=SQRT( (1.-W0(J))/(1.-W0(J)*COSBAR(J)) )
304C  SET OF CONSTANTS DETERMINED BY DOM
305c      G1(J)= (SQRT(3.)*0.5)*(2. - W0(J)*(1.+COSBAR(J)))
306c      G2(J)= (SQRT(3.)*W0(J)*0.5)*(1.-COSBAR(J))
307c      G3(J)=0.5*(1.-SQRT(3.)*COSBAR(J)*UBAR0)
308c  We use delta-Eddington instead
309        G1(J)=0.25*(7.-W0(j)*(4.+3*cosbar(j)))
310        G2(J)=-0.25*(1.-W0(j)*(4.-3*cosbar(j)))
311        G3(J)=0.5*(1.-SQRT(3.)*COSBAR(J)*UBAR0)
312        LAMDA(J)=SQRT(G1(J)**2 - G2(J)**2)
313        GAMA(J)=(G1(J)-LAMDA(J))/G2(J)
314      END DO
315
316      DO J=1,NAYER
317        G4=1.-G3(J)
318        DENOM=LAMDA(J)**2 - 1./UBAR0**2
319C  NOTE THAT THE ALGORITHM DONOT ACCEPT UBAR0 .eq. 0
320C  THERE IS A POTENTIAL PROBLEM HERE IF W0=0 AND UBARV=UBAR0
321C  THEN DENOM WILL VANISH. THIS ONLY HAPPENS PHYSICALLY WHEN
322C  THE SCATTERING GOES TO ZERO
323C  PREVENT THIS WITH AN IF STATEMENT
324        IF ( DENOM .EQ. 0.) THEN
325          DENOM=1.E-6
326        END IF
327        DENOM = W0(J)/DENOM
328        AM=DENOM*(G4   *(G1(J)+1./UBAR0) +G2(J)*G3(J) )
329        AP=DENOM*(G3(J)*(G1(J)-1./UBAR0) +G2(J)*G4    )
330C  CPM1 AND CMM1 ARE THE CPLUS AND CMINUS TERMS EVALUATED
331C  AT THE TOP OF THE LAYER, THAT IS LOWER OPTICAL DEPTH TAU(J)
332        CPM1(J)=AP*TAU(J)
333        CMM1(J)=AM*TAU(J)
334C  CP AND CM ARE THE CPLUS AND CMINUS TERMS EVALUATED AT THE
335C  BOTTOM OF THE LAYER. THAT IS AT HIGHER OPTICAL DEPTH TAU(J+1)
336        CP(J)=AP*TAU(J+1)
337        CM(J)=AM*TAU(J+1)
338      END DO
339
340C  NOW CALCULATE THE EXPONENTIAL TERMS NEEDED
341C  FOR THE TRIDIAGONAL ROTATED LAYERED METHOD
342C  WARNING IF DTAU(J) IS GREATER THAN ABOUT 35
343C  WE CLIPP IT TO AVOID OVERFLOW.
344C  EXP (TAU) - EXP(-TAU) WILL BE NONSENSE THIS IS
345C  CORRECTED IN THE DSOLVER ROUTINE. ??FLAG?
346      DO J=1,NAYER
347c        EXPTRM(J) = MIN(35.,LAMDA(J)*DTAU(J))
348        EP=EXP(MIN(35.0_8,LAMDA(J)*DTAU(J)))
349        EM=1.0/EP
350        AM = GAMA(J)*EM
351        E1(J)=EP+AM
352        E2(J)=EP-AM
353        AP = GAMA(J)*EP
354        E3(J)=AP+EM
355        E4(J)=AP-EM
356      END DO
357
358      CALL DSOLVER(NAYER,GAMA,CP,CM,CPM1,CMM1
359     &            ,E1,E2,E3,E4,0.0_8,BSURF,RSF,XK1,XK2)
360
361C  EVALUATE THE NAYER FLUXES THROUGH THE NAYER LAYERS
362C  USE THE TOP (TAU=0) OPTICAL DEPTH EXPRESSIONS TO EVALUATE FP AND FM
363C  AT THE THE TOP OF EACH LAYER,J = LEVEL J
364      DO J=1,NAYER
365        FP(J)= XK1(J) + GAMA(J)*XK2(J) + CPM1(J)
366        FM(J)= GAMA(J)*XK1(J) + XK2(J) + CMM1(J)
367      END DO
368
369C  USE EXPRESSION FOR BOTTOM FLUX TO GET THE FP AND FM AT NLEV
370c     Optimization: no need this step since result of last
371c     loop at about EP above give this
372c      EP=EXP(EXPTRM(NAYER))
373c      EM=1.0/EP
374      FP(NLEV)=XK1(NAYER)*EP + XK2(NAYER)*AM + CP(NAYER)
375      FM(NLEV)=XK1(NAYER)*AP + XK2(NAYER)*EM + CM(NAYER)
376
377C  ADD THE DIRECT FLUX TERM TO THE DOWNWELLING RADIATION, LIOU 182
378      DO J=1,NLEV
379        FM(J)=FM(J)+UBAR0*TAU(J)
380      END DO
381
382      RETURN
383      END
384
385CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
386
387      SUBROUTINE DSOLVER(NL,GAMA,CP,CM,CPM1,CMM1,E1,E2,E3,E4,BTOP,
388     *                   BSURF,RSF,XK1,XK2)
389
390C DOUBLE PRECISION VERSION OF SOLVER
391
392cc      PARAMETER (NMAX=201)
393cc AS+JBM 03/2010
394      IMPLICIT REAL*8  (A-H,O-Z)
395      DIMENSION GAMA(NL),CP(NL),CM(NL),CPM1(NL),CMM1(NL),XK1(NL),
396     *          XK2(NL),E1(NL),E2(NL),E3(NL),E4(NL)
397cc AS+JBM 03/2010     
398cc      DIMENSION AF(NMAX),BF(NMAX),CF(NMAX),DF(NMAX),XK(NMAX)
399      DIMENSION AF(2*NL),BF(2*NL),CF(2*NL),DF(2*NL),XK(2*NL)
400
401C*********************************************************
402C* THIS SUBROUTINE SOLVES FOR THE COEFFICIENTS OF THE    *
403C* TWO STREAM SOLUTION FOR GENERAL BOUNDARY CONDITIONS   *
404C* NO ASSUMPTION OF THE DEPENDENCE ON OPTICAL DEPTH OF   *
405C* C-PLUS OR C-MINUS HAS BEEN MADE.                      *
406C* NL     = NUMBER OF LAYERS IN THE MODEL                *
407C* CP     = C-PLUS EVALUATED AT TAO=0 (TOP)              *
408C* CM     = C-MINUS EVALUATED AT TAO=0 (TOP)             *
409C* CPM1   = C-PLUS  EVALUATED AT TAOSTAR (BOTTOM)        *
410C* CMM1   = C-MINUS EVALUATED AT TAOSTAR (BOTTOM)        *
411C* EP     = EXP(LAMDA*DTAU)                              *
412C* EM     = 1/EP                                         *
413C* E1     = EP + GAMA *EM                                *
414C* E2     = EP - GAMA *EM                                *
415C* E3     = GAMA*EP + EM                                 *
416C* E4     = GAMA*EP - EM                                 *
417C* BTOP   = THE DIFFUSE RADIATION INTO THE MODEL AT TOP  *
418C* BSURF  = THE DIFFUSE RADIATION INTO THE MODEL AT      *
419C*          THE BOTTOM: INCLUDES EMMISION AND REFLECTION *
420C*          OF THE UNATTENUATED PORTION OF THE DIRECT    *
421C*          BEAM. BSTAR+RSF*FO*EXP(-TAOSTAR/U0)          *
422C* RSF    = REFLECTIVITY OF THE SURFACE                  *
423C* XK1    = COEFFICIENT OF THE POSITIVE EXP TERM         *
424C* XK2    = COEFFICIENT OF THE NEGATIVE EXP TERM         *
425C*********************************************************
426C THIS ROUTINE CALLS ROUTINE DTRIDGL TO SOLVE TRIDIAGONAL
427C SYSTEMS
428C======================================================================C
429
430      L=2*NL
431 
432C     ************MIXED COEFFICENTS**********
433C     THIS VERSION AVOIDS SINGULARITIES ASSOC.
434C     WITH W0=0 BY SOLVING FOR XK1+XK2, AND XK1-XK2.
435
436      AF(1) = 0.0
437      BF(1) = GAMA(1)+1.
438      CF(1) = GAMA(1)-1.
439      DF(1) = BTOP-CMM1(1)
440      N     = 0
441      LM2   = L-2
442
443C     EVEN TERMS
444 
445      DO I=2,LM2,2
446        N     = N+1
447        AF(I) = (E1(N)+E3(N))*(GAMA(N+1)-1.)       
448        BF(I) = (E2(N)+E4(N))*(GAMA(N+1)-1.)
449        CF(I) = 2.0*(1.-GAMA(N+1)**2)
450        DF(I) = (GAMA(N+1)-1.) * (CPM1(N+1) - CP(N)) +
451     *            (1.-GAMA(N+1))* (CM(N)-CMM1(N+1))
452      END DO
453 
454      N   = 0
455      LM1 = L-1
456      DO I=3,LM1,2
457        N     = N+1
458        AF(I) = 2.0*(1.-GAMA(N)**2)
459        BF(I) = (E1(N)-E3(N))*(1.+GAMA(N+1))
460        CF(I) = (E1(N)+E3(N))*(GAMA(N+1)-1.)
461        DF(I) = E3(N)*(CPM1(N+1) - CP(N)) + E1(N)*(CM(N) - CMM1(N+1))
462      END DO
463 
464      AF(L) = E1(NL)-RSF*E3(NL)
465      BF(L) = E2(NL)-RSF*E4(NL)
466      CF(L) = 0.0
467      DF(L) = BSURF-CP(NL)+RSF*CM(NL)
468 
469      CALL DTRIDGL(L,AF,BF,CF,DF,XK)
470 
471C     ***UNMIX THE COEFFICIENTS****
472
473      DO 28 N=1,NL
474        XK1(N) = XK(2*N-1)+XK(2*N)
475        XK2(N) = XK(2*N-1)-XK(2*N)
476
477C       NOW TEST TO SEE IF XK2 IS REALLY ZERO TO THE LIMIT OF THE
478C       MACHINE ACCURACY  = 1 .E -30
479C       XK2 IS THE COEFFICIENT OF THE GROWING EXPONENTIAL AND MUST
480C       BE TREATED CAREFULLY
481
482        IF(XK2(N) .EQ. 0.0) GO TO 28
483        IF (ABS (XK2(N)/XK(2*N-1)) .LT. 1.E-30) XK2(N)=0.0
484
485   28 CONTINUE
486 
487      RETURN
488      END
489
490CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
491
492      SUBROUTINE DTRIDGL(L,AF,BF,CF,DF,XK)
493
494C     DOUBLE PRECISION VERSION OF TRIDGL
495
496cc AS+JBM 03/2010 : OBSOLETE MAINTENANT     
497cc      PARAMETER (NMAX=201)
498      IMPLICIT REAL*8  (A-H,O-Z)
499      DIMENSION AF(L),BF(L),CF(L),DF(L),XK(L)
500cc AS+JBM 03/2010 : OBSOLETE MAINTENANT
501cc      DIMENSION AS(NMAX),DS(NMAX)
502      DIMENSION AS(L),DS(L)
503
504C*    THIS SUBROUTINE SOLVES A SYSTEM OF TRIDIAGIONAL MATRIX
505C*    EQUATIONS. THE FORM OF THE EQUATIONS ARE:
506C*    A(I)*X(I-1) + B(I)*X(I) + C(I)*X(I+1) = D(I)
507C*    WHERE I=1,L  LESS THAN 103.
508C* ..............REVIEWED -CP........
509
510C======================================================================C
511
512      AS(L) = AF(L)/BF(L)
513      DS(L) = DF(L)/BF(L)
514
515      DO I=2,L
516        X         = 1./(BF(L+1-I) - CF(L+1-I)*AS(L+2-I))
517        AS(L+1-I) = AF(L+1-I)*X
518        DS(L+1-I) = (DF(L+1-I)-CF(L+1-I)*DS(L+2-I))*X
519      END DO
520 
521      XK(1)=DS(1)
522      DO I=2,L
523        XK(I) = DS(I)-AS(I)*XK(I-1)
524      END DO
525
526      RETURN
527      END
528     
Note: See TracBrowser for help on using the repository browser.