source: trunk/LMDZ.TITAN.old/libf/phytitan/gfluxv.F @ 3094

Last change on this file since 3094 was 1461, checked in by emillour, 10 years ago

Titan GCM:
Turned the common block "tgmdat.F" into a module "tgmdat_mod.F90".
This fixes issues in "debug" mode with common variables which seemed to not be correctly shared between routines.
EM

File size: 8.6 KB
Line 
1      SUBROUTINE GFLUXV(NTODO,WAVEN,DTDEL,TDEL,WDEL,CDEL
2     &          , F0PI,RSF,BTOP,BSURF,FP,FM,FMIDP,FMIDM,IPRINT)
3c      PARAMETER (NL=101)
4        USE TGMDAT_MOD, ONLY: UBARI,UBARV,UBAR0
5        IMPLICIT NONE
6      INTEGER IPRINT,I,J,K,IDELTA,NAYER,NL,NTODO
7      PARAMETER (NL=401)
8C ??FLAG? THIS VALUE (101) MUST BE .GE. NTODO
9C* THIS SUBROUTINE TAKES THE OPTICAL CONSTANTS AND BOUNDARY CONDITONS
10C  FOR THE VISIBLE  FLUX AT ONE WAVELENGTH AND SOLVES FOR THE FLUXES AT
11C  THE LEVELS. THIS VERSION IS SET UP TO WORK WITH LAYER OPTICAL DEPTHS
12C  MEASURED FROM THE TOP OF EACH LAEYER.  (DTAU) TOP OF EACH LAYER HAS
13C  OPTICAL DEPTH TAU(N).IN THIS SUB LEVEL N IS ABOVE LAYER N. THAT IS LAYER N
14C  HAS LEVEL N ON TOP AND LEVEL N+1 ON BOTTOM. OPTICAL DEPTH INCREASES
15C  FROM TOP TO BOTTOM. SEE C.P. MCKAY, TGM NOTES.
16C THIS SUBROUTINE DIFFERS FROM ITS IR CONTERPART IN THAT HERE WE SOLVE FOR
17C THE FLUXES DIRECTLY USING THE GENERALIZED NOTATION OF MEADOR AND WEAVOR
18C J.A.S., 37, 630-642, 1980.
19      REAL B81,B82,R81
20      REAL AP,AM,F0PI,DENOM,CMMID,TAUMID,RSF,BTOP
21      REAL EM,EP,PI,WAVEN,CPMID,BSURF,G4
22C THIS NEXT ROW OF VARIABLES ARE THOSE ACTUALLY USED IN THE
23C ROUTINE
24      REAL  W0(NL), COSBAR(NL),DTAU(NL),TAU(NL)
25      REAL wdel(ntodo-1),cdel(ntodo-1),dtdel(ntodo-1)
26          REAL tdel(ntodo),fm(ntodo),fp(ntodo)
27          REAL fmidm(ntodo),fmidp(ntodo)
28      REAL ALPHA(NL),LAMDA(NL),XK1(NL),XK2(NL)
29      REAL G1(NL),G2(NL),G3(NL)
30      REAL GAMA(NL),CP(NL),CM(NL),CPM1(NL),CMM1(NL)
31     &,E1(NL),E2(NL),E3(NL),E4(NL),EXPTRM(NL)
32      DATA PI/3.14159265358979323846/
33      DATA IDELTA/1/
34      NAYER=NTODO-1
35 505  CONTINUE
36C TURN ON THE DELTA-FUNCTION IF REQUIRED HERE
37c      PRINT*,' UBAR0 ',UBARI,UBARV,UBAR0
38
39      IF (IDELTA .EQ. 0) THEN
40         DO 101 J=1,NAYER
41            W0(J)=WDEL(J)
42            COSBAR(J)=CDEL(J)
43            DTAU(J)=DTDEL(J)
44            TAU(J)=TDEL(J)
45101      CONTINUE
46         TAU(NTODO)=TDEL(NTODO)
47      ELSE
48C FOR THE DELTA FUNCTION  HERE...
49         TAU(1)=TDEL(1)*(1.-WDEL(1)*CDEL(1)**2)
50         DO 102 J=1,NAYER
51            W0(J)=WDEL(J)*(1.-CDEL(J)**2)/(1.-WDEL(J)*CDEL(J)**2)
52            COSBAR(J)=CDEL(J)/(1.+CDEL(J))
53            DTAU(J)=DTDEL(J)*(1.-WDEL(J)*CDEL(J)**2)
54            TAU(J+1)=TAU(J)+DTAU(J)
55c         print*,'W0=',W0(J),' COSBAR=',COSBAR(J)
56c         print*,'DTAU=',DTAU(J),' TAU=',TAU(J)
57c         print*,'WDEL=',WDEL(J),' CDEL=',CDEL(J),' DTDEL=',DTDEL(J)
58102      CONTINUE
59      ENDIF
60C WE GO WITH THE HEMISPHERIC CONSTANT APPROACH
61C AS DEFINED BY M&W - THIS IS THE WAY THE IR IS DONE
62      DO 20 J=1,NAYER
63      ALPHA(J)=SQRT( (1.-W0(J))/(1.-W0(J)*COSBAR(J)) )
64C THIS SET OF G'S IS FOR THE TWO STREAM HEMI-CONSTANT
65C      G1(J)=(1.-W0(J)*0.5*(1.+COSBAR(J)))/UBARV
66C      G2(J)=W0(J)*0.5*(1.-COSBAR(J))/UBARV
67C      G3(J)=0.5*(1.-COSBAR(J))
68C SET OF CONSTANTS DETERMINED BY DOM
69      G1(J)= (SQRT(3.)*0.5)*(2. - W0(J)*(1.+COSBAR(J)))
70      G2(J)= (SQRT(3.)*W0(J)*0.5)*(1.-COSBAR(J))
71      G3(J)=0.5*(1.-SQRT(3.)*COSBAR(J)*UBAR0)
72      LAMDA(J)=SQRT(G1(J)**2 - G2(J)**2)
73      GAMA(J)=(G1(J)-LAMDA(J))/G2(J)
74
75   20 CONTINUE
76      DO 7 J=1,NAYER
77          G4=1.-G3(J)
78          DENOM=LAMDA(J)**2 - 1./UBAR0**2
79c              print*,'G1(J)**2- G2(J)**2',G1(J)**2 - G2(J)**2
80c              print*,'SQRT(G1(J)**2 - G2(J)**2)',SQRT(G1(J)**2
81c    &                                              - G2(J)**2)
82c              print*,'DENOM=',LAMDA(J)**2,1./UBAR0**2
83C THERE IS A POTENTIAL PROBLEM HERE IF W0=0 AND UBARV=UBAR0
84C THEN DENOM WILL VANISH. THIS ONLY HAPPENS PHYSICALLY WHEN
85C THE SCATTERING GOES TO ZERO
86C PREVENT THIS WITH A IF STATEMENT
87      IF ( DENOM .EQ. 0.) THEN
88               PRINT*,UBAR0
89               DENOM=1.E-4
90               PRINT*,'G1(J)**2- G2(J)**2',G1(J)**2 - G2(J)**2
91               PRINT*,'SQRT(G1(J)**2 - G2(J)**2)',SQRT(G1(J)**2
92     &                                              - G2(J)**2)
93               PRINT*,'DENOM=',LAMDA(J)**2,1./UBAR0**2
94               WRITE (6,99)
95   99          FORMAT (' DENOM ZERO;  RESET # 1IN GFLUXV, W0=0?')
96               END IF
97          AM=F0PI*W0(J)*(G4   *(G1(J)+1./UBAR0) +G2(J)*G3(J) )/DENOM
98          AP=F0PI*W0(J)*(G3(J)*(G1(J)-1./UBAR0) +G2(J)*G4    )/DENOM
99C* CPM1 AND CMM1 ARE THE CPLUS AND CMINUS TERMS EVALUATED
100C  AT THE TOP OF THE LAYER, THAT IS LOWER   OPTICAL DEPTH TAU(J)
101          CPM1(J)=AP*EXP(-TAU(J)/UBAR0)
102          CMM1(J)=AM*EXP(-TAU(J)/UBAR0)
103C* CP AND CM ARE THE CPLUS AND CMINUS TERMS EVALUATED AT THE
104C  BOTTOM OF THE LAYER.  THAT IS AT HIGHER OPTICAL DEPTH TAU(J+1)
105          CP(J)=AP*EXP(-TAU(J+1)/UBAR0)
106          CM(J)=AM*EXP(-TAU(J+1)/UBAR0)
107c      print*,'AM=',AM,' AP=',AP
108c      print*,'CPM1(J)=',CPM1(J),' CMM1(J)=',CMM1(J)
109c      print*,'CP(J)=',CP(J),' CM(J)=',CM(J)
110  7   CONTINUE
111C*
112C* NOW CALCULATE THE EXPONENTIAL TERMS NEEDED
113C* FOR THE TRIDIAGONAL ROTATED LAYERED METHOD
114C* WARNING IF DTAU(J) IS GREATER THAN ABOUT 35
115C* WE CLIPP IT TO AVOID OVERFLOW.
116C* EXP (TAU) - EXP(-TAU) WILL BE NONSENSE THIS IS
117C* CORRECTED IN THE DSOLVER ROUTINE. ??FLAG?
118      DO 103 J=1,NAYER
119      EXPTRM(J)=35.
120      IF ( LAMDA(J)*DTAU(J) .LT. 35. )  EXPTRM(J)=LAMDA(J)*DTAU(J)
121103   CONTINUE
122C* NEED TO CLIPP THE EXPONENTIAL HERE.
123      DO 8 J=1,NAYER
124      EP=EXP(EXPTRM(J))
125      EM=1.0/EP
126      E1(J)=EP+GAMA(J)*EM
127      E2(J)=EP-GAMA(J)*EM
128      E3(J)=GAMA(J)*EP+EM
129      E4(J)=GAMA(J)*EP-EM
130   8  CONTINUE
131C
132      B81=BTOP
133      B82=BSURF
134      R81=RSF
135      CALL DSOLVER(NAYER,GAMA,CP,CM,CPM1,CMM1
136     &            ,E1,E2,E3,E4,B81,B82,R81,XK1,XK2)
137C
138C EVALUATE THE NTODO FLUXES THROUGH THE NAYER LAYERS
139C USE THE TOP (TAU=0) OPTICAL DEPTH EXPRESSIONS TO EVALUATE FP AND FM
140C AT THE THE TOP OF EACH LAYER,J = LEVEL J
141      DO 46 J=1,NAYER
142           FP(J)= XK1(J) + GAMA(J)*XK2(J) + CPM1(J)
143           FM(J)=GAMA(J)*XK1(J) + XK2(J) + CMM1(J)
144  46  CONTINUE
145C USE EXPRESSION FOR BOTTOM FLUX TO GET THE FP AND FM AT NTODO
146          J=NAYER
147          EP=EXP(EXPTRM(J))
148          EM=1.0/EP
149          FP(J+1)=XK1(J)*EP + GAMA(J)*XK2(J)*EM + CP(J)
150          FM(J+1)=XK1(J)*EP*GAMA(J) + XK2(J)*EM + CM(J)
151C NOTE THAT WE HAVE SOLVED FOR THE FLUXES DIRECTLY AND NO
152C FURTHER INTEGRATION IS NEEDED, THE UBARV TERM IS ABSORBED
153C INTO THE DEFINITION OF G1 THU G4
154C UBARV = .5 IS HEMISPHERIC CONSTANT
155C UBARV = SQRT(3) IS GAUSS QUADRATURE
156C AND OTHER CASES AS PER MEADOR AND WEAVOR, JAS, 37, 630-643,1980.
157C
158C ADD THE DIRECT FLUX TERM TO THE DOWNWELLING RADIATION, LIOU 182
159          DO 80 J=1,NTODO
160          FM(J)=FM(J)+UBAR0*F0PI*EXP(-TAU(J)/UBAR0)
161  80      CONTINUE
162C
163C NOW WE CALCULATE THE FLUXES AT THE MIDPOINTS OF THE LAYERS.
164C EXACLTY ANALOGOUS TO THE ABOVE COMPUTATION
165C
166          DO 1982 J=1,NAYER
167          EP=EXP(0.5*EXPTRM(J))
168          EM=1.0/EP
169          G4=1.-G3(J)
170          DENOM=LAMDA(J)**2 - 1./UBAR0**2
171C THERE IS A POTENTIAL PROBLEM HERE IF W0=0 AND UBARV=UBAR0
172C THEN DENOM WILL VANISH. THIS ONLY HAPPENS PHYSICALLY WHEN
173C THE SCATTERING GOES TO ZERO
174C PREVENT THIS WITH A IF STATEMENT
175      IF ( DENOM .EQ. 0.) THEN
176               DENOM=1.E-4
177               PRINT*,'G1(J)**2- G2(J)**2',G1(J)**2 - G2(J)**2
178               PRINT*,'SQRT(G1(J)**2 - G2(J)**2)',SQRT(G1(J)**2
179     &                                              - G2(J)**2)
180               PRINT*,'DENOM=',LAMDA(J)**2,1./UBAR0**2
181               WRITE (6,78)
182   78          FORMAT (' DENOM ZERO;  RESET # 2 IN GFLUXV, W0=0?')
183               END IF
184          AM=F0PI*W0(J)*(G4   *(G1(J)+1./UBAR0) +G2(J)*G3(J) )/DENOM
185          AP=F0PI*W0(J)*(G3(J)*(G1(J)-1./UBAR0) +G2(J)*G4    )/DENOM
186C* CPMID AND CMMID  ARE THE CPLUS AND CMINUS TERMS EVALUATED
187C  AT THE MIDDLE OF THE LAYER, THAT IS LOWER   OPTICAL DEPTH TAU(J)+
188          TAUMID= (TAU(J)+0.5*DTAU(J) )
189          CPMID=AP*EXP(-TAUMID/UBAR0)
190          CMMID=AM*EXP(-TAUMID/UBAR0)
191          FMIDP(J)=XK1(J)*EP + GAMA(J)*XK2(J)*EM + CPMID
192          FMIDM(J)=XK1(J)*EP*GAMA(J) + XK2(J)*EM + CMMID
193C ADD THE DIRECT FLUX TO THE DOWNWELLING TERM
194          FMIDM(J)= FMIDM(J) +UBAR0*F0PI*EXP(-TAUMID/UBAR0)
195 1982 CONTINUE
196C ** NOW PRINTOUT IF NECESSARY
197      IF (IPRINT .LT. 9) RETURN
198      WRITE(6,601) F0PI,RSF,BTOP,BSURF
199      DO 120 J=1,NAYER
200      WRITE (6,301) TAU(J),FP(J),FM(J),DTAU(J),W0(J),COSBAR(J)
201     &        ,ALPHA(J), LAMDA(J),G1(J),G2(J),G3(J)
202 120  CONTINUE
203      J=NTODO
204      WRITE (6,301) TAU(J),FP(J),FM(J)
205      WRITE (6,602)
206      DO 130 J=1,NAYER
207      WRITE (6,301) CP(J),CM(J),E1(J),E2(J),E3(J),E4(J),CPM1(J)
208     &   ,CMM1(J),GAMA(J)
209  130 CONTINUE
210  301 FORMAT(1X,1P13E10.3)
211  602 FORMAT(' CP(J),CM(J),E1(J),E2(J),EM1(J),EM2(J),CPM1(J),CMM1(J)'
212     &    ,',GAMA(J)')
213  601 FORMAT(1X,'F0PI,RSF,BTOP,BSURF= ',1P4E10.3,/
214     &         ' TAU,FUP,FDOWN,DTAU(J),W0(J),COSBAR(J)'
215     &    ,',ALPHA(J),LAMDA(J),G1,G2,G3')
216C *******************************************************************012
217      RETURN
218      END
Note: See TracBrowser for help on using the repository browser.