-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoints_with_temps.m
122 lines (112 loc) · 5.99 KB
/
points_with_temps.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
%
% Add simulated temperatures to the points output from tseries_to_points.m
%
params;
JCOPEDIR = '/home/share/T_DATA';
% Must be identical to parameters in convertJCOPE.f
IM = 86;
JM = 122;
KLEV = 141;
xlon = [ ...
138.958328 139.041656 139.124985 139.208313 139.291641 139.374969 ...
139.458298 139.541626 139.624954 139.708282 139.791611 139.874939 ...
139.958267 140.041595 140.124924 140.208252 140.291580 140.374908 ...
140.458237 140.541565 140.624893 140.708221 140.791550 140.874878 ...
140.958206 141.041534 141.124863 141.208191 141.291519 141.374847 ...
141.458176 141.541504 141.624832 141.708160 141.791489 141.874817 ...
141.958145 142.041473 142.124802 142.208130 142.291458 142.374786 ...
142.458115 142.541443 142.624771 142.708099 142.791428 142.874756 ...
142.958084 143.041412 143.124741 143.208069 143.291397 143.374725 ...
143.458054 143.541382 143.624710 143.708038 143.791367 143.874695 ...
143.958023 144.041351 144.124680 144.208008 144.291336 144.374664 ...
144.457993 144.541321 144.624649 144.707977 144.791306 144.874634 ...
144.957962 145.041290 145.124619 145.207947 145.291275 145.374603 ...
145.457932 145.541260 145.624588 145.707916 145.791245 145.874573 ...
145.957901 146.041229];
ylat = [ ...
33.958332 34.041664 34.124996 34.208328 34.291660 34.374992 ...
34.458324 34.541656 34.624989 34.708321 34.791653 34.874985 ...
34.958317 35.041649 35.124981 35.208313 35.291645 35.374977 ...
35.458309 35.541641 35.624973 35.708305 35.791637 35.874969 ...
35.958302 36.041634 36.124966 36.208298 36.291630 36.374962 ...
36.458294 36.541626 36.624958 36.708290 36.791622 36.874954 ...
36.958286 37.041618 37.124950 37.208282 37.291615 37.374947 ...
37.458279 37.541611 37.624943 37.708275 37.791607 37.874939 ...
37.958271 38.041603 38.124935 38.208267 38.291599 38.374931 ...
38.458263 38.541595 38.624928 38.708260 38.791592 38.874924 ...
38.958256 39.041588 39.124920 39.208252 39.291584 39.374916 ...
39.458248 39.541580 39.624912 39.708244 39.791576 39.874908 ...
39.958241 40.041573 40.124905 40.208237 40.291569 40.374901 ...
40.458233 40.541565 40.624897 40.708229 40.791561 40.874893 ...
40.958225 41.041557 41.124889 41.208221 41.291553 41.374886 ...
41.458218 41.541550 41.624882 41.708214 41.791546 41.874878 ...
41.958210 42.041542 42.124874 42.208206 42.291538 42.374870 ...
42.458202 42.541534 42.624866 42.708199 42.791531 42.874863 ...
42.958195 43.041527 43.124859 43.208191 43.291523 43.374855 ...
43.458187 43.541519 43.624851 43.708183 43.791515 43.874847 ...
43.958179 44.041512];
zdep = [ ...
-700.000 -695.000 -690.000 -685.000 -680.000 -675.000 ...
-670.000 -665.000 -660.000 -655.000 -650.000 -645.000 ...
-640.000 -635.000 -630.000 -625.000 -620.000 -615.000 ...
-610.000 -605.000 -600.000 -595.000 -590.000 -585.000 ...
-580.000 -575.000 -570.000 -565.000 -560.000 -555.000 ...
-550.000 -545.000 -540.000 -535.000 -530.000 -525.000 ...
-520.000 -515.000 -510.000 -505.000 -500.000 -495.000 ...
-490.000 -485.000 -480.000 -475.000 -470.000 -465.000 ...
-460.000 -455.000 -450.000 -445.000 -440.000 -435.000 ...
-430.000 -425.000 -420.000 -415.000 -410.000 -405.000 ...
-400.000 -395.000 -390.000 -385.000 -380.000 -375.000 ...
-370.000 -365.000 -360.000 -355.000 -350.000 -345.000 ...
-340.000 -335.000 -330.000 -325.000 -320.000 -315.000 ...
-310.000 -305.000 -300.000 -295.000 -290.000 -285.000 ...
-280.000 -275.000 -270.000 -265.000 -260.000 -255.000 ...
-250.000 -245.000 -240.000 -235.000 -230.000 -225.000 ...
-220.000 -215.000 -210.000 -205.000 -200.000 -195.000 ...
-190.000 -185.000 -180.000 -175.000 -170.000 -165.000 ...
-160.000 -155.000 -150.000 -145.000 -140.000 -135.000 ...
-130.000 -125.000 -120.000 -115.000 -110.000 -105.000 ...
-100.000 -95.000 -90.000 -85.000 -80.000 -75.000 ...
-70.000 -65.000 -60.000 -55.000 -50.000 -45.000 ...
-40.000 -35.000 -30.000 -25.000 -20.000 -15.000 ...
-10.000 -5.000 -0.000];
eval(['load ''' inputfile_Temp '''']);
ndata = length(points);
for n = 1:ndata
since = points(n).since + TIMEORIGIN;
until = points(n).until + TIMEORIGIN;
timefish = (since + until) * 0.5; % midpoint in time
[y, m, d, hour, minute, second] = datevec(timefish);
jcopefile = sprintf('%s/%04d%02d%02d.bin', JCOPEDIR, y, m, d);
% We compiled converJCOPE.f with `-fconvert=big=endian`
% the file is therefore in Big-Endian
[fid, msg] = fopen(jcopefile, 'r', 'ieee-be');
if fid < 0, error(msg); end
buf = fread(fid, IM*JM*KLEV, 'float32');
fclose(fid);
buf(find(abs(buf + 99.9999) < 0.1)) = NaN;
temperature = reshape(buf, IM, JM, KLEV);
z0 = zdep + points(n).depthfish;
lower = max(find(z0 <= 0.0));
upper = lower + 1; if z0(upper) < 0, error('depth inconsistency'); end
tlower = NaN; tupper = NaN;
longitudeHere = points(n).longitude; stepHere = 1.0 / 12.0;
while 1
tlower = myinterp2(xlon, ylat, squeeze(temperature(:,:,lower)), ...
longitudeHere, points(n).latitude);
tupper = myinterp2(xlon, ylat, squeeze(temperature(:,:,upper)), ...
longitudeHere, points(n).latitude);
if isnan(tlower) || isnan(tupper)
longitudeHere = longitudeHere + stepHere;
else
break;
end
end
% linear interpolation
tHere = (z0(upper) * tlower - z0(lower) * tupper) / (z0(upper) - z0(lower));
% if out of model region, tlower and/or tupper = NaN and tHere = NaN
points(n).tempmodel = tHere;
end
command = ['mv /tmp/tmp.mat ', outputfile_Temp];
save '/tmp/tmp.mat' points;
system(command);