/[MITgcm]/MITgcm/pkg/dic/dic_atmos.F
ViewVC logotype

Annotation of /MITgcm/pkg/dic/dic_atmos.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (hide annotations) (download)
Mon Apr 7 20:31:16 2008 UTC (17 years, 3 months ago) by dfer
Branch: MAIN
Changes since 1.8: +1 -2 lines
Moving dic options to DIC_OPTIONS.h

1 dfer 1.9 C $Header: /u/gcmpack/MITgcm/pkg/dic/dic_atmos.F,v 1.8 2008/04/04 21:32:37 dfer Exp $
2 jmc 1.5 C $Name: $
3    
4 stephd 1.1 #include "DIC_OPTIONS.h"
5     #include "PTRACERS_OPTIONS.h"
6    
7     CBOP
8     C !ROUTINE: DIC_ATMOS
9    
10     C !INTERFACE: ==========================================================
11 jmc 1.5 SUBROUTINE DIC_ATMOS( istate, myTime, myIter, myThid )
12 stephd 1.1
13     C !DESCRIPTION:
14     C Calculate the atmospheric pCO2
15     C gchem_int1:
16     C 0=use default 278.d-6
17 jmc 1.5 C 1=use constant value - gchem_rl1, read in from data.gchem
18     C 2=read in from file
19 stephd 1.1 C 3=interact with atmospheric box
20     C !USES: ===============================================================
21     IMPLICIT NONE
22     #include "SIZE.h"
23     #include "DYNVARS.h"
24     #include "EEPARAMS.h"
25     #include "PARAMS.h"
26     #include "GRID.h"
27     #include "FFIELDS.h"
28 dfer 1.8 #include "DIC_VARS.h"
29 stephd 1.1 #include "PTRACERS_SIZE.h"
30     #include "PTRACERS_FIELDS.h"
31     #include "GCHEM.h"
32     #include "DIC_ATMOS.h"
33    
34     C !INPUT PARAMETERS: ===================================================
35     C myThid :: thread number
36     C myIter :: current timestep
37     C myTime :: current time
38     C istate :: 0=initial call, 1=subsequent calls
39     INTEGER myIter, myThid, istate
40     _RL myTime
41    
42     #ifdef ALLOW_PTRACERS
43     LOGICAL DIFFERENT_MULTIPLE
44     EXTERNAL DIFFERENT_MULTIPLE
45    
46     C !LOCAL VARIABLES: ====================================================
47     INTEGER bi, bj, I,J,k
48     INTEGER it, ntim
49     c
50     _RL total_flux
51     _RL total_ocean_carbon_old
52     _RL total_atmos_carbon_old
53     _RL total_atmos_moles
54     _RL atpco2
55     _RL total_carbon_old, total_carbon, carbon_diff
56     _RL tmp
57     _RL year_diff_ocean, year_diff_atmos, year_total
58     _RL start_diff_ocean, start_diff_atmos, start_total
59     C variables for reading CO2 input files
60     _RL aWght, bWght
61     c
62     CHARACTER*(MAX_LEN_FNAM) fn
63     LOGICAL permCheckPoint
64     CEOP
65    
66     cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
67    
68     c if coupled to atmsopheric model, use the
69     c Co2 value passed from the coupler
70     #ifndef USE_ATMOSCO2
71    
72 jmc 1.6 IF ( nThreads .GT. 1 .AND.
73     & ( gchem_int1.EQ.2 .OR. gchem_int1.EQ.3 ) ) THEN
74 jmc 1.5 C Problem with I/O and global-sum for multi-threaded execution
75     C Needs to be fixed before using this S/R in multi-threaded run
76     STOP 'S/R DIC_ATMOS: multi-threaded not right'
77     ENDIF
78    
79 stephd 1.1 c default - set only once
80     if (gchem_int1.eq.0.and.istate.eq.0) then
81     DO bj=myByLo(myThid),myByHi(myThid)
82     DO bi=myBxLo(myThid),myBxHi(myThid)
83    
84     DO j=1-OLy,sNy+OLy
85     DO i=1-OLx,sNx+OLx
86     AtmospCO2(i,j,bi,bj)=278.0 _d -6
87     ENDDO
88     ENDDO
89    
90     ENDDO
91     ENDDO
92     endif
93    
94     c user specified value - set only once
95     if (gchem_int1.eq.1.and.istate.eq.0) then
96     DO bj=myByLo(myThid),myByHi(myThid)
97     DO bi=myBxLo(myThid),myBxHi(myThid)
98    
99     DO j=1-OLy,sNy+OLy
100     DO i=1-OLx,sNx+OLx
101     AtmospCO2(i,j,bi,bj)=gchem_rl1
102     ENDDO
103     ENDDO
104    
105     ENDDO
106     ENDDO
107 jmc 1.6 endif
108 stephd 1.1
109     c read from a file (note:
110     c gchem_int2=number entries to read
111     c gchem_int3=start timestep,
112     c gchem_int4=timestep between file entries)
113 jmc 1.6 if (gchem_int1.eq.2) then
114 jmc 1.5 if (istate.eq.0) then
115 stephd 1.1 OPEN(28,FILE='co2atmos.dat',STATUS='old')
116     do it=1,gchem_int2
117     READ(28,*) co2atmos(it)
118     print*,'co2atmos',co2atmos(it)
119     enddo
120     endif
121     c linearly interpolate between file entries
122     ntim=int((myIter-gchem_int3)/gchem_int4)+1
123 jmc 1.5 aWght = FLOAT(myIter-gchem_int3)
124     bWght = FLOAT(gchem_int4)
125     aWght = 0.5 _d 0 + aWght/bWght - FLOAT(ntim-1)
126     if (aWght.gt.1. _d 0) then
127 stephd 1.1 ntim=ntim+1
128 jmc 1.5 aWght=aWght-1. _d 0
129 stephd 1.1 endif
130 jmc 1.5 bWght = 1. _d 0 - aWght
131 stephd 1.1 tmp=co2atmos(ntim)*bWght+co2atmos(ntim+1)*aWght
132     c print*,'weights',ntim, aWght, bWght, tmp
133    
134     DO bj=myByLo(myThid),myByHi(myThid)
135     DO bi=myBxLo(myThid),myBxHi(myThid)
136    
137     DO j=1-OLy,sNy+OLy
138     DO i=1-OLx,sNx+OLx
139    
140     AtmospCO2(i,j,bi,bj)=tmp
141     ENDDO
142     ENDDO
143    
144     print*,'AtmospCO2(20,20)',AtmospCO2(20,20,bi,bj)
145 jmc 1.5
146 stephd 1.1 ENDDO
147     ENDDO
148    
149    
150 jmc 1.6 endif
151 stephd 1.1
152    
153     c interactive atmosphere
154     if (gchem_int1.eq.3) then
155    
156 stephd 1.2 c _BEGIN_MASTER(myThid)
157 stephd 1.1
158 stephd 1.3 cMass dry atmosphere = (5.1352+/-0.0003)d18 kg (Trenberth & Smith,
159     cJournal of Climate 2005)
160     cand Mean molecular mass air = 28.97 g/mol (NASA earth fact sheet)
161     total_atmos_moles= 1.77 _d 20
162     c for 278ppmv we need total_atmos_carbon=4.9206e+16
163    
164 stephd 1.1 if (istate.gt.0) then
165     total_ocean_carbon_old=total_ocean_carbon
166     total_atmos_carbon_old=total_atmos_carbon
167     else
168     total_ocean_carbon_old=0. _d 0
169     total_atmos_carbon_old=0. _d 0
170     endif
171    
172     total_flux= 0. _d 0
173     total_ocean_carbon= 0. _d 0
174    
175     DO bj=myByLo(myThid),myByHi(myThid)
176     DO bi=myBxLo(myThid),myBxHi(myThid)
177     DO i=1,sNx
178     DO j=1,sNy
179     if (istate.gt.0) then
180     total_flux=total_flux+FluxCO2(i,j,bi,bj)*rA(i,j,bi,bj)*
181     & hFacC(i,j,1,bi,bj)*dTtracerLev(1)
182 jmc 1.5 endif
183 stephd 1.1 DO k=1,nR
184     total_ocean_carbon= total_ocean_carbon+
185 dfer 1.7 & ( Ptracer(i,j,k,bi,bj,1)
186     #ifdef DIC_BIOTIC
187     & +R_cp*Ptracer(i,j,k,bi,bj,4)
188     #endif
189     & ) * rA(i,j,bi,bj)*
190 stephd 1.1 & drF(k)*hFacC(i,j,k,bi,bj)
191     ENDDO
192     ENDDO
193     ENDDO
194     ENDDO
195     ENDDO
196 stephd 1.2
197 stephd 1.1 _GLOBAL_SUM_R8(total_flux,myThid)
198     _GLOBAL_SUM_R8(total_ocean_carbon,myThid)
199    
200     if (istate.eq.0) then
201     c read state from output file
202     DO i = 1,MAX_LEN_FNAM
203     fn(i:i) = ' '
204     ENDDO
205     WRITE(fn,'(A,I10.10)') 'dic_atmos.',myIter
206     C Going to really do some IO. Make everyone except master thread wait.
207     _BARRIER
208     c read in values from last pickup
209     open(26,file=fn,status='old')
210     read(26,*) total_atmos_carbon, atpco2
211     close(26)
212    
213     else
214     c calculate new atmos pCO2
215     total_atmos_carbon=total_atmos_carbon - total_flux
216     atpco2=total_atmos_carbon/total_atmos_moles
217     c write out if time for a new pickup
218     permCheckPoint = .FALSE.
219     permCheckPoint =
220     & DIFFERENT_MULTIPLE(pChkptFreq,myTime,deltaTClock)
221     if (permCheckPoint) then
222     DO i = 1,MAX_LEN_FNAM
223     fn(i:i) = ' '
224     ENDDO
225     WRITE(fn,'(A,I10.10)') 'dic_atmos.',myIter
226     C Going to really do some IO. Make everyone except master thread wait.
227     _BARRIER
228 stephd 1.3 c write values to new pickup
229 stephd 1.1 open(26,file=fn,status='new')
230     write(26,*) total_atmos_carbon, atpco2
231     close(26)
232    
233     endif
234     endif
235    
236    
237     atpco2=total_atmos_carbon/total_atmos_moles
238    
239 jmc 1.5 c print*,'QQpCO2', total_atmos_carbon, atpco2, total_ocean_carbon,
240 stephd 1.1 c & total_flux
241    
242     DO bj=myByLo(myThid),myByHi(myThid)
243     DO bi=myBxLo(myThid),myBxHi(myThid)
244    
245     DO j=1-OLy,sNy+OLy
246     DO i=1-OLx,sNx+OLx
247     AtmospCO2(i,j,bi,bj)=atpco2
248     ENDDO
249     ENDDO
250    
251     ENDDO
252     ENDDO
253    
254     print*,'QQ atmos C, total, pCo2', total_atmos_carbon, atpco2
255     total_carbon=total_atmos_carbon + total_ocean_carbon
256     total_carbon_old=total_atmos_carbon_old + total_ocean_carbon_old
257     carbon_diff=total_carbon-total_carbon_old
258 jmc 1.5 print*,'QQ total C, current, old, diff', total_carbon,
259 stephd 1.1 & total_carbon_old, carbon_diff
260     carbon_diff=total_ocean_carbon-total_ocean_carbon_old
261     tmp=carbon_diff-total_flux
262     print*,'QQ ocean C, current, old, diff',total_ocean_carbon,
263     & total_ocean_carbon_old, carbon_diff
264     print*,'QQ air-sea flux, addition diff', total_flux, tmp
265    
266     c if end of forcing cycle, find total change in ocean carbon
267     if (istate.eq.0) then
268     total_ocean_carbon_start=total_ocean_carbon
269     total_ocean_carbon_year=total_ocean_carbon
270     total_atmos_carbon_start=total_atmos_carbon
271     total_atmos_carbon_year=total_atmos_carbon
272     else
273     permCheckPoint = .FALSE.
274     permCheckPoint =
275     & DIFFERENT_MULTIPLE(externForcingCycle,myTime,deltaTClock)
276     if (permCheckPoint) then
277     year_diff_ocean=total_ocean_carbon-total_ocean_carbon_year
278     year_diff_atmos=total_atmos_carbon-total_atmos_carbon_year
279     year_total=(total_ocean_carbon+total_atmos_carbon) -
280     & (total_ocean_carbon_year+total_atmos_carbon_year)
281     start_diff_ocean=total_ocean_carbon-total_ocean_carbon_start
282     start_diff_atmos=total_atmos_carbon-total_atmos_carbon_start
283     start_total=(total_ocean_carbon+total_atmos_carbon) -
284     & (total_ocean_carbon_start+total_atmos_carbon_start)
285     print*,'QQ YEAR END'
286     print*,'year diff: ocean, atmos, total', year_diff_ocean,
287     & year_diff_atmos, year_total
288     print*,'start diff: ocean, atmos, total ', start_diff_ocean,
289     & start_diff_atmos, start_total
290     c
291     total_ocean_carbon_year=total_ocean_carbon
292     total_atmos_carbon_year=total_atmos_carbon
293     endif
294     endif
295    
296 stephd 1.2 c _END_MASTER(myThid)
297 stephd 1.1
298 jmc 1.6 endif
299 stephd 1.1
300     #endif
301     #endif
302    
303 jmc 1.6 RETURN
304     END

  ViewVC Help
Powered by ViewVC 1.1.22