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