How to read grid file GOT4.7 format ocean tide model?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi everyone,
I've tried to modify and got confused on the script that has given to me in order to read another format of grid file.
Can anyone help me to solve this matter? Attached here is an example of grid file to be read.
And also this is the script that had been given. I tried to modify and get confused on it.
clc;clear all; close all;
filename = 'k1.txt';
file ='K1GOT.txt';
fid = fopen(filename);
L = cell(5,1);
for K = 1 : 7; L{K} = fgetl(fid); end
longrange = sscanf(L{5}, '%f');
latrange = sscanf(L{4}, '%f');
widths = sscanf(L{3}, '%f');
indicates_missing = sscanf(L{6}, '%f');
%undefined = sscanf(L{7}, '%f');
per_line = 11;
partwidth = widths(1);
nparts = widths(2);
parts = cell(nparts,1);
colgroups = floor(partwidth / per_line);
leftover = partwidth - colgroups * per_line;
failed = false;
for P = 1 : nparts
data1 = fscanf(fid, '%f', [per_line colgroups]);
if isempty(data1); failed = true; break; end
data1 = reshape(data1, [per_line colgroups]);
data2 = fscanf(fid, '%f', [leftover]);
data = [reshape(permute(data1, [1 3 2]), [], 2); data2];
parts{P} = data;
end
if failed
fprintf('Only got %d of %d parts successfully\n', P, npars);
end
if ~failed
L = fgetl(fid);
if ischar(L) && ~isempty(L)
fprintf('Not empty at apparent EOF, content is:\n%s\n', L);
failed = true;
end
end
if ~failed
lats = linspace(latrange(1), latrange(2), widths(2));
longs = linspace(longrange(1), longrange(2), widths(1));
data = permute(cat(3, parts{:}),[1 3 2]);
amps = data(:,:,1) .';
amps(amps == indicates_missing(1)) = nan;
phases = data(:,:,2) .';
phases(phases == indicates_missing(2)) = nan;
subplot(2,1,1);
[xq,yq] = meshgrid(0:.25:360, -90:.25:90);
surf(xq,yq,amps, 'edgecolor', 'none');
xlim(longrange);
ylim(latrange);
xlabel('long'); ylabel('lat'); zlabel('amp');
title('amplitudes');
subplot(2,1,2);
[xq,yq] = meshgrid(0:.25:360, -90:.25:90);
surf(xq,yq,phases,'edgecolor', 'none')
xlim(longrange);
ylim(latrange);
xlabel('long'); ylabel('lat'); zlabel('phase');
title('phases');
end
Model = [yq(:) xq(:) amps(:) phases(:)];
fid1 = fopen(file, 'wt');
fprintf(fid1,'%.4f \t %.4f \t %.3f \t %.3f\n',Model.');
fclose(fid1);
fclose(fid);
I shall be most grateful if anyone can solve my problem. Thank you.
0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Oceanography and Hydrology in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!