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