-
Notifications
You must be signed in to change notification settings - Fork 1
/
ACCESS_PIcontrol_Closure.m
168 lines (148 loc) · 5.71 KB
/
ACCESS_PIcontrol_Closure.m
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
% This script checks the closure of the Eulerian heat budget
base = '/g/data/p66/cm2704/archive/bi889/history/ocn/';
fname = [base 'ocean_month.nc-08500630'];
area = ncread(fname,'area_t');
[xL,yL] = size(area);
zL = 50;
rho0 = 1035;
Cp = 3992.10322329649; % J kg-1 degC-1
% $$$ %%% HEAT BUDGET CLOSURE
% $$$
% $$$ hfds_prior = [];
% $$$ hfds_new = [];
% $$$ temp_tend = [];
% $$$ OHC = [];
% $$$ time = [];
% $$$ DT_A = [];
% $$$
% $$$ vars2D = {'sfc_hflux_pme','sfc_hflux_coupler', ...
% $$$ 'sfc_hflux_from_runoff', 'sfc_hflux_from_water_evap', ...
% $$$ 'sfc_hflux_from_water_prec', 'frazil_2d'};
% $$$ vars3D = {'frazil_3d','temp_tendency'};
% $$$
% $$$ files = dir(base);
% $$$
% $$$ for fi = 1:length(files)
% $$$ if (strfind(files(fi).name,'month'))
% $$$
% $$$ fname = [base files(fi).name];
% $$$ sprintf('Doing %03d of %03d',fi,length(files))
% $$$ time_t = ncread(fname,'time');
% $$$ DT_A_t = ncread(fname,'average_DT')*86400;
% $$$
% $$$ time = cat(1,time,time_t);
% $$$ DT_A = cat(1,DT_A,DT_A_t);
% $$$
% $$$ tL = length(time_t);
% $$$
% $$$ for vi = 1:length(vars2D)
% $$$ tmp = nansum(nansum(ncread(fname,vars2D{vi},[1 1 1],[xL yL tL]).*area,1),2);
% $$$ eval([vars2D{vi} ' = squeeze(tmp);']);
% $$$ end
% $$$
% $$$ for vi = 1:length(vars3D)
% $$$ tmp = nansum(nansum(nansum(ncread(fname,vars3D{vi},[1 1 1 1],[xL yL zL tL]),3).*area,1),2);
% $$$ eval([vars3D{vi} ' = squeeze(tmp);']);
% $$$ end
% $$$
% $$$ OHC_t = squeeze(Cp*nansum(nansum(nansum(ncread(fname,'temp_rhodzt',[1 1 1 1],[xL yL zL ...
% $$$ tL]),3).*area,1),2));
% $$$
% $$$ hfds_prior_t = sfc_hflux_from_runoff + ...
% $$$ sfc_hflux_coupler + ...
% $$$ sfc_hflux_from_water_evap + ...
% $$$ sfc_hflux_from_water_prec + ...
% $$$ frazil_2d;
% $$$ hfds_prior_t = hfds_prior_t.*DT_A_t;
% $$$
% $$$ hfds_new_t = sfc_hflux_from_runoff + ...
% $$$ sfc_hflux_coupler + ...
% $$$ sfc_hflux_pme + ...
% $$$ frazil_3d;
% $$$ hfds_new_t = hfds_new_t.*DT_A_t;
% $$$
% $$$ temp_tend_t = temp_tendency.*DT_A_t;
% $$$
% $$$ OHC = cat(1,OHC,OHC_t);
% $$$ hfds_prior = cat(1,hfds_prior,hfds_prior_t);
% $$$ hfds_new = cat(1,hfds_new,hfds_new_t);
% $$$ temp_tend = cat(1,temp_tend,temp_tend_t);
% $$$
% $$$ if (mod(fi,20)==0)
% $$$ save('ACCESS-CM2_PIcontrol_Closure.mat','OHC','time','DT_A','temp_tend','hfds_new','hfds_prior');
% $$$ end
% $$$ end
% $$$ end
%%% MASS BUDGET CLOSURE
OM = [];
OMeta = [];
time = [];
DT_A = [];
vars2D = {'pme_river','pme_mass','pme_net',...
'wfimelt','wfiform'};
for vi=1:length(vars2D)
eval([vars2D{vi} ' = [];']);
end
files = dir(base);
for fi = 1:length(files)
if (strfind(files(fi).name,'month'))
fname = [base files(fi).name];
sprintf('Doing %03d of %03d',fi,length(files))
time_t = ncread(fname,'time');
DT_A_t = ncread(fname,'average_DT')*86400;
time = cat(1,time,time_t);
DT_A = cat(1,DT_A,DT_A_t);
tL = length(time_t);
for vi = 1:length(vars2D)
tmp = nansum(nansum(ncread(fname,vars2D{vi},[1 1 1],[xL yL tL]).*area,1),2);
eval([vars2D{vi} ' = cat(1,' vars2D{vi} ',squeeze(tmp).*DT_A_t);']);
end
OM_t = squeeze(nansum(nansum(nansum(ncread(fname,'rho_dzt',[1 1 1 1],[xL yL zL ...
tL]),3).*area,1),2));
OMeta_t = rho0*squeeze(nansum(nansum(ncread(fname,'eta_t',[1 ...
1 1],[xL yL tL]).*area,1),2));
OM = cat(1,OM,OM_t);
OMeta = cat(1,OMeta,OMeta_t);
if (mod(fi,20)==0)
save('ACCESS-CM2_PIcontrol_Mass_Closure.mat','OM','time','DT_A','OMeta');
for vi=1:length(vars2D)
save('ACCESS-CM2_PIcontrol_Mass_Closure.mat',vars2D{vi},'-append');
end
end
end
end
% $$$ for vi = 1:length(vars2D)
% $$$ eval(['var = ' vars2D{vi} ';']);
% $$$ fprintf(['Total Flux = %6.6e, ' vars2D{vi} '\n'],var);
% $$$ end
% $$$
% $$$ for vi = 1:length(vars3D)
% $$$ eval(['var = ' vars3D{vi} ';']);
% $$$ fprintf(['Total Flux = %6.6e, ' vars3D{vi} '\n'],var);
% $$$ end
% $$$
% $$$ total_sfc_from2D = frazil_3d+sfc_hflux_coupler+sfc_hflux_pme+sfc_hflux_from_runoff;
% $$$ fprintf(['Total Flux = %6.6e, total_sfc_from2D = frazil_3d+sfc_hflux_coupler+sfc_hflux_pme+sfc_hflux_from_runoff \n'],total_sfc_from2D);
% $$$
% $$$ % $$$ total_sfc_from3D = temp_vdiffuse_sbc+temp_rivermix+frazil_3d+sfc_hflux_pme;
% $$$ % $$$ fprintf(['Total Flux = %6.6e, total_sfc_from3D = temp_vdiffuse_sbc+temp_rivermix+frazil_3d+sfc_hflux_pme \n'],total_sfc_from3D);
% $$$
% $$$ hfds_prior = sfc_hflux_from_runoff + ...
% $$$ sfc_hflux_coupler + ...
% $$$ sfc_hflux_from_water_evap + ...
% $$$ sfc_hflux_from_water_prec + ...
% $$$ frazil_2d;
% $$$ fprintf(['Total Flux = %6.6e, hfds_prior = sfc_hflux_from_runoff+sfc_hflux_coupler+sfc_hflux_from_water_evap+sfc_hflux_from_water_prec+frazil_2d \n'],hfds_prior);
% $$$
% $$$ hfds_prior_with_frazil3d = hfds_prior-frazil_2d+frazil_3d;
% $$$ fprintf(['Total Flux = %6.6e, hfds_prior_with_frazil3d = hfds_prior ' ...
% $$$ '-frazil_2d+frazil_3d \n'],hfds_prior_with_frazil3d);
% $$$
% $$$ hfds_new = sfc_hflux_from_runoff + ...
% $$$ sfc_hflux_coupler + ...
% $$$ sfc_hflux_pme + ...
% $$$ frazil_3d;
% $$$ fprintf(['Total Flux = %6.6e, hfds_new = sfc_hflux_from_runoff+sfc_hflux_coupler+sfc_hflux_pm+frazil_3d \n'],hfds_new);
% $$$
% $$$
% $$$