-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreported_WHPX.m
66 lines (64 loc) · 2.2 KB
/
reported_WHPX.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
function reported_WHPX(rd, fname)
%
% Output reported_data (`rd`) to WHP-Exchange format file `fname_n_ct1.csv`
%
nstn = length(rd.Station);
for n = 1:nstn
% good data
ig = find(isfinite(rd.CTDprs(:,n)) | isfinite(rd.CTDtem(:,n)) ...
| isfinite(rd.CTDsal(:,n)) | isfinite(rd.CTDoxy(:,n)) ...
| isfinite(rd.CTDCT(:,n)) | isfinite(rd.CTDSA(:,n)));
if isempty(ig) % do not output empty files
continue;
end
filename = sprintf('%s_%04d_ct1.csv', fname, n)
fid = fopen(filename, 'w');
if fid < 0
error(['rd_WHPX.m: cannot open ' filename]);
end
% header
d0 = datestr(now, 30); % must be YYYYMMDD
fprintf(fid, 'CTD,%8s%s\n', d0([1:8]), 'AAABBBCCC');
fprintf(fid, '# Generated by reported_WHPX.m\n');
fprintf(fid, '# at %s\n', d0);
fprintf(fid, 'NUMBER_HEADERS = 8\n');
fprintf(fid, 'EXPOCODE = %s\n', rd.Station{n}.EXPO);
fprintf(fid, 'STNNBR = %s\n', rd.Station{n}.Stnnbr);
fprintf(fid, 'CASTNO = %d\n', rd.Station{n}.Cast);
d1 = datestr(rd.Station{n}.Time, 30);
fprintf(fid, 'DATE = %s\n', d1([1:8]));
fprintf(fid, 'TIME = %s\n', d1([10:13]));
fprintf(fid, 'LATITUDE = %.4f\n', rd.Station{n}.Lat);
fprintf(fid, 'LONGITUDE = %.4f\n', rd.Station{n}.Lon);
fprintf(fid, 'CTDPRS, CTDTMP, CTDSAL, CTDOXY, CTDCT, CTDSA\n');
fprintf(fid, 'DBAR, ITS-90, PSS-78, UMOL/KG, ITS-90, G/KG\n');
% body
m = max(ig);
for i = 1:m
prs = rd.CTDprs(i,n); tem = rd.CTDtem(i,n); sal = rd.CTDsal(i,n);
oxy = rd.CTDoxy(i,n); CT = rd.CTDCT(i,n); SA = rd.CTDSA(i,n);
if all(~isfinite([prs tem sal oxy CT SA]))
continue;
end
print_num(fid, '%5.1f,', '%5d,', prs);
print_num(fid, '%11.4f,', '%11d,', tem);
print_num(fid, '%11.4f,', '%11d,', sal);
print_num(fid, '%11.4f,', '%11d,', oxy);
print_num(fid, '%12.4f,', '%12d,', CT);
print_num(fid, '%12.4f', '%12d', SA);
fprintf(fid, '\n');
end
fprintf(fid, 'END_DATA');
fclose(fid);
end % for n = 1:nstn
end
function print_num(fi, goodform, badform, x)
%
% print according to format
%
if isfinite(x)
fprintf(fi, goodform, x);
else
fprintf(fi, badform, -999);
end
end