/[MITgcm]/MITgcm_contrib/high_res_cube/eddy_flux/calcUVBave.m
ViewVC logotype

Contents of /MITgcm_contrib/high_res_cube/eddy_flux/calcUVBave.m

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


Revision 1.5 - (show annotations) (download)
Fri Aug 13 01:45:49 2004 UTC (20 years, 11 months ago) by edhill
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +2 -1 lines
 o fix a few small bugs

1 function m = calcUVBave(Spat, Tpat, Upat, Vpat, ilist, nlay, ne)
2
3 % Function m = calcTBave(Spat, Tpat, Upat, Vpat, ilist, nlay, ne)
4 %
5 %
6 % INPUTS
7 % Tpat string containing T-data file pattern
8 % Upat string containing U-data file pattern
9 % Vpat string containing V-data file pattern
10 % ilist list of iteration values
11 % nlay number of z layers
12 % ne number of values alone each edge of each face
13 %
14 % OUTPUTS
15 % m output array of dimension ns*nps
16
17 if nargin ~= 7
18 disp('Error: wrong number of arguments')
19 exit
20 end
21
22 deltatT = 1200; % model time step size (s)
23 tavefreq = 259200; % averaging period (s)
24 startDate = datenum(1992,1,1); % model integration starting date
25
26 oldyear = -1;
27 newyear = oldyear;
28
29 nps = 6 * ne*ne;
30 tx = 85;
31 ty = 85;
32 nt = ne*ne*6/(tx*ty);
33 cx = ne;
34 cy = ne;
35 nz = 1;
36
37 delR = [
38 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.01, ...
39 10.03, 10.11, 10.32, 10.80, 11.76, 13.42, 16.04 , 19.82, 24.85, ...
40 31.10, 38.42, 46.50, 55.00, 63.50, 71.58, 78.90, 85.15, 90.18, ...
41 93.96, 96.58, 98.25, 99.25,100.01,101.33,104.56,111.33,122.83, ...
42 139.09,158.94,180.83,203.55,226.50,249.50,272.50,295.50,318.50, ...
43 341.50,364.50,387.50,410.50,433.50,456.50 ];
44 R = cumsum(delR) - 0.5*delR;
45
46 vnam = [ 'U_'; 'V_'; 'T_'; 'S_'; 'B_'; 'B1'; ...
47 'UT'; 'VT'; 'US'; 'VS'; 'UB'; 'VB' ];
48
49 il = 1;
50 for il = 1:nlay
51
52 a = sprintf('Slice: %g',il);
53 % disp(a);
54
55 % Zero the accumulators
56 nm = 0;
57 for io = 1:size(vnam,1)
58 comm = sprintf('%s_acc = zeros(ne,ne,6);', vnam(io,:));
59 eval(comm)
60 end
61
62 it = 1;
63 for it = 1:length(ilist)
64
65 iter = ilist(it);
66 str = datestr(startDate + (iter*deltatT-tavefreq/2)/60/60/24);
67 dv = datevec(startDate + (iter*deltatT-tavefreq/2)/60/60/24);
68 newyear = dv(1);
69
70 sfname = sprintf(Spat, ilist(it));
71 tfname = sprintf(Tpat, ilist(it));
72 ufname = sprintf(Upat, ilist(it));
73 vfname = sprintf(Vpat, ilist(it));
74 disp([ a ' ' str ' ' tfname ]);
75 sfid = fopen(sfname, 'r', 'ieee-be');
76 tfid = fopen(tfname, 'r', 'ieee-be');
77 ufid = fopen(ufname, 'r', 'ieee-be');
78 vfid = fopen(vfname, 'r', 'ieee-be');
79 offset = (il - 1)*nps*4;
80
81 % Convert the horrible JPL mdsio layout to six sane faces
82 fseek(sfid, offset, 'bof');
83 scube = unmangleJPL1( reshape(fread(sfid, nps, 'real*4'),tx*nt,ty), ...
84 ne, tx );
85
86 fseek(tfid, offset, 'bof');
87 tcube = unmangleJPL1( reshape(fread(tfid, nps, 'real*4'),tx*nt,ty), ...
88 ne, tx );
89
90 fseek(ufid, offset, 'bof');
91 ucube = unmangleJPL1( reshape(fread(ufid, nps, 'real*4'),tx*nt,ty), ...
92 ne, tx );
93
94 fseek(vfid, offset, 'bof');
95 vcube = unmangleJPL1( reshape(fread(vfid, nps, 'real*4'),tx*nt,ty), ...
96 ne, tx );
97
98 fclose(sfid);
99 fclose(tfid);
100 fclose(ufid);
101 fclose(vfid);
102
103 % Compute the density
104 bcube = zeros(size(scube));
105 bcubem1 = zeros(size(scube));
106 for icf = 1:6
107 % pressure_for_eos.F :
108 % locPres(i,j) = -rhoConst*rC(k)*gravity*maskC(i,j,k,bi,bj)
109 % rhoConst = 9.997999999999999E+02 /* Ref density ( kg/m^3 ) */
110 % gravity = 9.810000000000000E+00 /* Grav accel ( m/s^2 ) */
111 p = 0.09998 * 9.81 * R(il);
112 bcube(:,:,icf) = ...
113 eh3densjmd95( squeeze(scube(:,:,icf)), ...
114 squeeze(tcube(:,:,icf)), p ) * -9.81 / 1000;
115 if il > 1
116 p = 0.09998 * 9.81 * R(il-1);
117 bcubem1(:,:,icf) = ...
118 eh3densjmd95( scube(:,:,icf), ...
119 tcube(:,:,icf), p ) * -9.81 / 1000;
120 end
121 end
122 tmask = double(tcube ~= 0.0);
123 scube = scube .* tmask;
124 bcube = bcube .* tmask;
125 bcubem1 = bcubem1 .* tmask;
126
127 % Fill the (ne+1)*(ne+1) grid with T,S,B values
128 ni = ne; nip1 = ni + 1;
129 nj = ne; njp1 = nj + 1;
130 tcubep1 = zeros( [ nip1 njp1 6 ] );
131 scubep1 = zeros( [ nip1 njp1 6 ] );
132 bcubep1 = zeros( [ nip1 njp1 6 ] );
133 for icf = 1:6
134 tcubep1(2:nip1,2:njp1,icf) = tcube(:,:,icf);
135 scubep1(2:nip1,2:njp1,icf) = scube(:,:,icf);
136 bcubep1(2:nip1,2:njp1,icf) = bcube(:,:,icf);
137 end
138
139 % Do the upwind-edge T exchanges
140 tcubep1(1,2:njp1,1) = tcube(ni:-1:1,nj,5); % -
141 tcubep1(2:nip1,1,1) = tcube(1:ni,nj,6); % -
142 tcubep1(1,2:njp1,2) = tcube(ni,1:nj,1); % -
143 tcubep1(2:nip1,1,2) = tcube(ni,nj:-1:1,6); % -
144 tcubep1(1,2:njp1,3) = tcube(ni:-1:1,nj,1); % -
145 tcubep1(2:nip1,1,3) = tcube(1:ni,nj,2); % -
146 tcubep1(1,2:njp1,4) = tcube(ni,1:nj,3); % -
147 tcubep1(2:nip1,1,4) = tcube(ni,nj:-1:1,2); % -
148 tcubep1(1,2:njp1,5) = tcube(ni:-1:1,nj,3); % -
149 tcubep1(2:nip1,1,5) = tcube(1:ni,nj,4); % -
150 tcubep1(1,2:njp1,6) = tcube(ni,1:nj,5); % -
151 tcubep1(2:nip1,1,6) = tcube(ni,nj:-1:1,4); % -
152
153 % Do the upwind-edge S exchanges
154 scubep1(1,2:njp1,1) = scube(ni:-1:1,nj,5); % -
155 scubep1(2:nip1,1,1) = scube(1:ni,nj,6); % -
156 scubep1(1,2:njp1,2) = scube(ni,1:nj,1); % -
157 scubep1(2:nip1,1,2) = scube(ni,nj:-1:1,6); % -
158 scubep1(1,2:njp1,3) = scube(ni:-1:1,nj,1); % -
159 scubep1(2:nip1,1,3) = scube(1:ni,nj,2); % -
160 scubep1(1,2:njp1,4) = scube(ni,1:nj,3); % -
161 scubep1(2:nip1,1,4) = scube(ni,nj:-1:1,2); % -
162 scubep1(1,2:njp1,5) = scube(ni:-1:1,nj,3); % -
163 scubep1(2:nip1,1,5) = scube(1:ni,nj,4); % -
164 scubep1(1,2:njp1,6) = scube(ni,1:nj,5); % -
165 scubep1(2:nip1,1,6) = scube(ni,nj:-1:1,4); % -
166
167 % Do the upwind-edge B exchanges
168 bcubep1(1,2:njp1,1) = bcube(ni:-1:1,nj,5); % -
169 bcubep1(2:nip1,1,1) = bcube(1:ni,nj,6); % -
170 bcubep1(1,2:njp1,2) = bcube(ni,1:nj,1); % -
171 bcubep1(2:nip1,1,2) = bcube(ni,nj:-1:1,6); % -
172 bcubep1(1,2:njp1,3) = bcube(ni:-1:1,nj,1); % -
173 bcubep1(2:nip1,1,3) = bcube(1:ni,nj,2); % -
174 bcubep1(1,2:njp1,4) = bcube(ni,1:nj,3); % -
175 bcubep1(2:nip1,1,4) = bcube(ni,nj:-1:1,2); % -
176 bcubep1(1,2:njp1,5) = bcube(ni:-1:1,nj,3); % -
177 bcubep1(2:nip1,1,5) = bcube(1:ni,nj,4); % -
178 bcubep1(1,2:njp1,6) = bcube(ni,1:nj,5); % -
179 bcubep1(2:nip1,1,6) = bcube(ni,nj:-1:1,4); % -
180
181 % Get T values on the U,V grid points
182 masku = 1.0 - abs(diff(double(tcubep1(2:nip1,:,:) == 0.0),1,2));
183 maskv = 1.0 - abs(diff(double(tcubep1(:,2:nip1,:) == 0.0),1,1));
184 diffu = 0.5*diff(tcubep1(2:nip1,:,:),1,2);
185 diffv = 0.5*diff(tcubep1(:,2:nip1,:),1,1);
186 tonu = tcube(:,:,:) + masku.*diffu;
187 tonv = tcube(:,:,:) + maskv.*diffv;
188
189 % Get S values on the U,V grid points
190 diffu = 0.5*diff(scubep1(2:nip1,:,:),1,2);
191 diffv = 0.5*diff(scubep1(:,2:nip1,:),1,1);
192 sonu = scube(:,:,:) + masku.*diffu;
193 sonv = scube(:,:,:) + maskv.*diffv;
194
195 % Get B values on the U grid points
196 diffu = 0.5*diff(bcubep1(2:nip1,:,:),1,2);
197 diffv = 0.5*diff(bcubep1(:,2:nip1,:),1,1);
198 bonu = bcube(:,:,:) + masku.*diffu;
199 bonv = bcube(:,:,:) + maskv.*diffv;
200
201 if ((newyear ~= oldyear) && (nm > 0)) || (it == length(ilist))
202
203 % Write if its a new year or the last of all entries
204 disp([' ==> Writing files for ==> ' sprintf('%d',oldyear)]);
205 for io = 1:size(vnam,1)
206 comm = sprintf( ...
207 '%s_ido = fopen(''%s_tave_%d'', ''a'', ''ieee-be'');', ...
208 vnam(io,:), vnam(io,:), oldyear );
209 eval(comm)
210 comm = sprintf( '%s_acc = %s_acc ./ nm;',vnam(io,:), ...
211 vnam(io,:));
212 eval(comm)
213 comm = sprintf('fwrite(%s_ido, %s_acc, ''real*4'');', ...
214 vnam(io,:), vnam(io,:) );
215 eval(comm)
216 comm = sprintf( 'fclose(%s_ido);', vnam(io,:) );
217 eval(comm)
218
219 % Re-zero the accumulators
220 comm = sprintf('%s_acc = zeros(ne,ne,6);', vnam(io,:));
221 eval(comm)
222 end
223
224 nm = 0;
225
226 end
227
228 % Accumulate partial sums
229 U__acc = U__acc + ucube;
230 V__acc = V__acc + vcube;
231 T__acc = T__acc + tcube;
232 S__acc = S__acc + scube;
233 B__acc = B__acc + bcube;
234 B1_acc = B1_acc + bcubem1;
235
236 UT_acc = UT_acc + tonu.*ucube;
237 VT_acc = VT_acc + tonv.*vcube;
238 US_acc = US_acc + sonu.*ucube;
239 VS_acc = VS_acc + sonv.*vcube;
240 UB_acc = UB_acc + bonu.*ucube;
241 VB_acc = VB_acc + bonv.*vcube;
242
243 nm = nm + 1;
244
245 oldyear = newyear;
246
247 end
248 end
249

  ViewVC Help
Powered by ViewVC 1.1.22