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

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

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


Revision 1.2 - (show annotations) (download)
Sat Aug 14 19:31:09 2004 UTC (20 years, 11 months ago) by edhill
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +14 -13 lines
 o now the averaging scales nicely across 6 nodes (2yrs of data per node)

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

  ViewVC Help
Powered by ViewVC 1.1.22