25 module stock_constants_mod
30 use time_manager_mod,
only :
operator(+),
operator(-)
32 use platform_mod,
only : r8_kind
37 #include<file_version.h>
39 integer,
public,
parameter :: NELEMS=3
40 integer,
parameter :: NELEMS_report=3
41 integer,
public,
parameter :: ISTOCK_WATER=1, istock_heat=2, istock_salt=3
42 integer,
public,
parameter :: ISTOCK_TOP=1, istock_bottom=2, istock_side=3
43 integer,
public :: stocks_file
54 real(r8_kind) :: q_start = 0.0_r8_kind
55 real(r8_kind) :: q_now = 0.0_r8_kind
60 real(r8_kind) :: dq(
nsides) = 0.0_r8_kind
61 real(r8_kind) :: dq_in(
nsides) = 0.0_r8_kind
66 type(
stock_type),
save,
public,
dimension(NELEMS) :: atm_stock, ocn_stock, lnd_stock, ice_stock
73 integer,
private,
parameter :: ncomps=4
74 integer,
private,
parameter :: istock_atm=1,istock_lnd=2,istock_ice=3,istock_ocn=4
75 character(len=3),
parameter,
dimension(NCOMPS) :: comp_names=(/
'ATM',
'LND',
'ICE',
'OCN'/)
78 character(len=5) ,
parameter,
dimension(NELEMS) :: stock_names=(/
'water',
'heat ',
'salt '/)
79 character(len=12),
parameter,
dimension(NELEMS) :: stock_units=(/
'[Kg] ',
'[Joules]',
'[Kg] '/)
88 character(len=80) :: formatstring,space
90 real(r8_kind),
dimension(NELEMS) :: val_atm, val_lnd, val_ice, val_ocn
95 do i = 1, nelems_report
96 val_atm(i) = atm_stock(i)%q_start
97 val_lnd(i) = lnd_stock(i)%q_start
98 val_ice(i) = ice_stock(i)%q_start
99 val_ocn(i) = ocn_stock(i)%q_start
108 if(
mpp_pe() == mpp_root_pe())
then
111 write(stocks_file,*)
'================Stocks Report Guide====================================='
112 write(stocks_file,*)
' '
113 write(stocks_file,*)
'S(t) = Total amount of a tracer in the component model at time t.'
114 write(stocks_file,*)
' Calculated via the component model itself.'
115 write(stocks_file,*)
' '
116 write(stocks_file,*)
'F(t) = Cumulative input of a tracer to the component model at time t.'
117 write(stocks_file,*)
' Calculated via interchange of fluxes with other component models.'
118 write(stocks_file,*)
' '
119 write(stocks_file,*)
'S(t) - S(0) = Cumulative increase of the component stocks at time t'
120 write(stocks_file,*)
' Calculated by the component itself.'
121 write(stocks_file,*)
' '
122 write(stocks_file,*)
'In a conserving component F(t)=S(t)-S(0) to within numerical accuracy.'
123 write(stocks_file,*)
' '
124 write(stocks_file,*)
'Component Model refers to one of OCN, ATM, LND or ICE'
125 write(stocks_file,*)
''
126 write(stocks_file,*)
'NOTE: When use_lag_fluxes=.true. is used in coupler, the ocean stocks '
127 write(stocks_file,*)
' calculations are in error by an order which scales as the inverse'
128 write(stocks_file,*)
' of the number of time steps.'
129 write(stocks_file,*)
' '
130 write(stocks_file,*)
'======================================================================='
133 write(stocks_file,*)
'======================Initial Stock S(0)==============================='
137 s = 25-len_trim(stock_names(i))-len_trim(stock_units(i))
138 write(space,
'(i2)') s
139 formatstring= trim(formatstring)//
',a,a,'//trim(space)
140 formatstring= trim(formatstring)//trim(
'x')
142 formatstring= trim(formatstring)//
')'
144 write(stocks_file,formatstring) (trim(stock_names(i)),trim(stock_units(i)), i=1,nelems_report)
149 write(space,
'(i2)') s
150 formatstring= trim(formatstring)//
',es22.15,3x'
152 formatstring= trim(formatstring)//
')'
155 write(stocks_file,formatstring)
'ATM', (val_atm(i), i=1,nelems_report)
156 write(stocks_file,formatstring)
'LND', (val_lnd(i), i=1,nelems_report)
157 write(stocks_file,formatstring)
'ICE', (val_ice(i), i=1,nelems_report)
158 write(stocks_file,formatstring)
'OCN', (val_ocn(i), i=1,nelems_report)
160 write(stocks_file,*)
'========================================================================'
161 write(stocks_file,
'(a)' )
' '
174 real(r8_kind),
dimension(NCOMPS) :: f_value, f_ice_grid, f_ocn_grid, f_ocn_btf, q_start, q_now,c_value
175 character(len=80) :: formatstring
176 integer :: iday0, isec0, iday, isec, hours
177 real(r8_kind) :: days
178 integer :: diagid , comp,elem,i
179 integer,
parameter :: initid = -2
184 integer,
dimension(NCOMPS,NELEMS),
save :: f_valuediagid = initid
185 integer,
dimension(NCOMPS,NELEMS),
save :: c_valuediagid = initid
186 integer,
dimension(NCOMPS,NELEMS),
save :: fmc_valuediagid = initid
187 integer,
dimension(NCOMPS,NELEMS),
save :: f_lostdiagid = initid
189 real(r8_kind) :: diagfield
191 character(len=30) :: field_name, units
193 if(
mpp_pe()==mpp_root_pe())
then
194 call get_time(init_time, isec0, iday0)
197 hours = iday*24 + isec/3600 - iday0*24 - isec0/3600
198 days = real(hours, r8_kind)/24.0_r8_kind
199 write(stocks_file,*)
'==============================================='
200 write(stocks_file,
'(a,f12.3)')
't = TimeSinceStart[days]= ',days
201 write(stocks_file,*)
'==============================================='
204 do elem = 1,nelems_report
208 if(comp == istock_atm) stck = atm_stock(elem)
209 if(comp == istock_lnd) stck = lnd_stock(elem)
210 if(comp == istock_ice) stck = ice_stock(elem)
211 if(comp == istock_ocn) stck = ocn_stock(elem)
214 f_ice_grid(comp) = sum(stck%dq)
215 f_ocn_grid(comp) = sum(stck%dq_IN)
216 f_ocn_btf(comp) = stck%dq_IN( istock_bottom )
218 q_start(comp) = stck%q_start
219 q_now(comp) = stck%q_now
227 c_value(comp) = q_now(comp) - q_start(comp)
229 if(
mpp_pe() == mpp_root_pe())
then
231 if(f_valuediagid(comp,elem) == initid)
then
232 field_name = trim(comp_names(comp)) // trim(stock_names(elem))
233 field_name = trim(field_name) //
'StocksChange_Flux'
234 units = trim(stock_units(elem))
239 if(c_valuediagid(comp,elem) == initid)
then
240 field_name = trim(comp_names(comp)) // trim(stock_names(elem))
241 field_name = trim(field_name) //
'StocksChange_Comp'
242 units = trim(stock_units(elem))
247 if(fmc_valuediagid(comp,elem) == initid)
then
248 field_name = trim(comp_names(comp)) // trim(stock_names(elem))
249 field_name = trim(field_name) //
'StocksChange_Diff'
250 units = trim(stock_units(elem))
255 f_value(comp) = f_ice_grid(comp)
257 if(comp == istock_ocn)
then
259 f_value(comp) = f_ocn_grid(comp)
261 if(f_lostdiagid(comp,elem) == initid)
then
262 field_name = trim(comp_names(comp)) // trim(stock_names(elem))
263 field_name = trim(field_name) //
'StocksExchangeLost'
264 units = trim(stock_units(elem))
269 diagid=f_lostdiagid(comp,elem)
270 diagfield = f_ice_grid(comp) - f_ocn_grid(comp)
271 if (diagid > 0) used =
send_data(diagid, diagfield, time)
276 diagid=f_valuediagid(comp,elem)
277 diagfield = f_value(comp)
278 if (diagid > 0) used =
send_data(diagid, diagfield, time)
279 diagid=c_valuediagid(comp,elem)
280 diagfield = c_value(comp)
281 if (diagid > 0) used =
send_data(diagid, diagfield, time)
282 diagid=fmc_valuediagid(comp,elem)
283 diagfield = f_value(comp)-c_value(comp)
284 if (diagid > 0) used =
send_data(diagid, diagfield, time)
298 if(
mpp_pe()==mpp_root_pe())
then
307 write(stocks_file,
'(a,a,40x,a,20x,a,20x,a,20x,a)')
'Stocks of ',trim(stock_names(elem)),
'ATM',
'LND', &
309 formatstring =
'(a,a,2x,es22.15,2x,es22.15,2x,es22.15,2x,es22.15)'
311 write(stocks_file,formatstring)
'Total =S(t) ',stock_units(elem),&
312 ( q_now(i), i=1,ncomps)
313 write(stocks_file,formatstring)
'Change=S(t)-S(0) ',stock_units(elem),&
314 ( q_now(i)-q_start(i), i=1,ncomps)
315 write(stocks_file,formatstring)
'Input =F(t) ',stock_units(elem),&
316 ( f_value(i), i=1,ncomps)
317 write(stocks_file,formatstring)
'Diff =F(t) - (S(t)-S(0)) ',stock_units(elem),&
318 ( f_value(i) - c_value(i), i=1,ncomps)
319 write(stocks_file,formatstring)
'Error =Diff/S(0) ',
'[NonDim] ', &
320 ((f_value(i) - c_value(i))/(1+q_start(i)), i=1,ncomps)
323 write(stocks_file,
'(a)' )
' '
324 formatstring =
'(a,a,a,6x,es22.15)'
325 write(stocks_file,formatstring)
'Lost Stocks in the exchange between Ice and Ocean ',trim(stock_names(elem))&
326 &,trim(stock_units(elem)), f_ice_grid(istock_ocn) - f_ocn_grid(istock_ocn) + f_ocn_btf(istock_ocn)
328 write(stocks_file,
'(a)')
' '
329 write(stocks_file,
'(a)')
' '
342 end module stock_constants_mod
Register a diagnostic field for a given module.
Send data over to output fields.
subroutine, public write_version_number(version, tag, unit)
Prints to the log file (or a specified unit) the version id string and tag name.
integer function mpp_pe()
Returns processor ID.
subroutine, public stocks_report(Time)
Writes update to stock report.
subroutine, public stocks_report_init(Time)
Starts a stock report.
subroutine, public stocks_set_init_time(Time)
integer, parameter nsides
top, bottom, side
Holds stocks amounts per PE values.
subroutine, public get_time(Time, seconds, days, ticks, err_msg)
Returns days and seconds ( < 86400 ) corresponding to a time. err_msg should be checked for any error...
Type to represent amounts of time. Implemented as seconds and days to allow for larger intervals.