-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgridded_bin.m
40 lines (37 loc) · 1.35 KB
/
gridded_bin.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
function gridded_bin(gds, fname, ll_grid, pr_grid)
%
% Output reported_data (`gds`) to GrADS readable binary
%
fid = fopen(fname, 'w', 'ieee-be');
if fid < 0
error(['gridded_bin.m: cannot open ' fname]);
end
for n = 1:length(gds)
fwrite(fid, gds(n).CTDtem', 'float32');
fwrite(fid, gds(n).CTDsal', 'float32');
fwrite(fid, gds(n).CTDoxy', 'float32');
fwrite(fid, gds(n).CTDCT', 'float32');
fwrite(fid, gds(n).CTDSA', 'float32');
end
fclose(fid);
% tentative control file for GrADS
fid = fopen([fname '.ctl'], 'w');
fprintf(fid, '* Automatically generated by gridded_bin.m\n');
[dumb, name, ext] = fileparts(fname);
fprintf(fid, 'DSET ^%s%s\n', name, ext);
fprintf(fid, 'UNDEF -999\n');
fprintf(fid, 'OPTIONS big_endian\n');
fprintf(fid, 'XDEF %d linear %f %f\n', length(ll_grid), ll_grid(1), ll_grid(2) - ll_grid(1));
fprintf(fid, 'YDEF %d linear %f %f\n', length(pr_grid), pr_grid(1), ...
(pr_grid(2) - pr_grid(1)) / 100.0);
fprintf(fid, 'ZDEF 1 levels 0\n');
fprintf(fid, 'TDEF %d linear 9sep9999 9yr\n', length(gds));
fprintf(fid, 'vars 5\n');
fprintf(fid, 't 1 0 Temperature [deg C]\n');
fprintf(fid, 's 1 0 Salinity [PSS-78]\n');
fprintf(fid, 'o 1 0 Oxygen [umol/kg]\n');
fprintf(fid, 'ct 1 0 Conservative Temperature [deg C]\n');
fprintf(fid, 'sa 1 0 Absolute Salinity [g/kg]\n');
fprintf(fid, 'endvars\n');
fclose(fid);
end