1 |
function [DATA,FREQ,PERNAMES]=read_adcirc_ha_elev(fname,flag,gname) |
---|
2 |
%READ_ADCIRC_HA_ELEV read ADCIRC elevation output file |
---|
3 |
% This routine reads in the contents of an ADCIRC elevation file, |
---|
4 |
% as typically output from an harmonic analysis output to a fort.53 |
---|
5 |
% file. fort.53 is the default output file for the global harmonic |
---|
6 |
% analysis of the elevation field. |
---|
7 |
% |
---|
8 |
% Input : fname - filename to read elevation from. If empty, |
---|
9 |
% routine reads from fort.53. Analysis from |
---|
10 |
% specified stations (fort.51) can be read in |
---|
11 |
% by providing fname='fort.51'. |
---|
12 |
% flag - if flag==1, the contents of the elevation file |
---|
13 |
% are output to disk in .s2c file format, one file |
---|
14 |
% per period. |
---|
15 |
% gname - if flag==1, then gname provides the grid name |
---|
16 |
% for the .s2c file output format. |
---|
17 |
% Output : DATA - matrix of amplitudes and phases, as in |
---|
18 |
% DATA = [amp1 amp2 ... pha1 pha2 ...]; |
---|
19 |
% FREQ - vector of component frequencies |
---|
20 |
% PERNAMES - string vector of component names |
---|
21 |
% |
---|
22 |
% Call as: [DATA,FREQ,PERNAMES]=read_adcirc_ha_elev(fname,flag,gname); |
---|
23 |
% |
---|
24 |
% Written by: Brian Blanton, Spring '99 |
---|
25 |
|
---|
26 |
% if no arguments, assume fort.53... |
---|
27 |
|
---|
28 |
if nargin==0 |
---|
29 |
fname='fort.53'; |
---|
30 |
flag=0; % no .s2c output to disk |
---|
31 |
gname=''; |
---|
32 |
elseif nargin==1 |
---|
33 |
% See if fname is string |
---|
34 |
if ~isstr(fname) |
---|
35 |
fname='fort.53'; |
---|
36 |
if flag~=0 | flag~=1 |
---|
37 |
error('FLAG to READ_ADCIRC_HA_ELEV must be 0|1') |
---|
38 |
end |
---|
39 |
else |
---|
40 |
% Try to open fname |
---|
41 |
[fid,message]=fopen(fname,'r'); |
---|
42 |
if fid==-1 |
---|
43 |
error(['Could not open ' fname ' because ' message]) |
---|
44 |
end |
---|
45 |
fclose(fid); |
---|
46 |
flag=0; |
---|
47 |
gname=''; |
---|
48 |
end |
---|
49 |
end |
---|
50 |
|
---|
51 |
% Determine if there is a path on the fname, that may have been |
---|
52 |
% passed in. |
---|
53 |
[fpath,fname,ext,ver] = fileparts(fname); |
---|
54 |
|
---|
55 |
if isempty(fpath) |
---|
56 |
filename=[fname ext] |
---|
57 |
fid=fopen([fname ext],'r'); |
---|
58 |
else |
---|
59 |
fid=fopen([fpath '/' fname ext],'r'); |
---|
60 |
end |
---|
61 |
ncomp=fscanf(fid,'%d',1); |
---|
62 |
|
---|
63 |
for i=1:ncomp |
---|
64 |
temp=fscanf(fid,'%f %f %f',[1 3]); |
---|
65 |
FREQ(i)=temp(1); |
---|
66 |
PERNAMES{i}=fscanf(fid,'%s',[1]); |
---|
67 |
end |
---|
68 |
|
---|
69 |
nnodes=fscanf(fid,'%d',1); |
---|
70 |
|
---|
71 |
A=NaN*ones(nnodes,ncomp); |
---|
72 |
G=NaN*ones(nnodes,ncomp); |
---|
73 |
|
---|
74 |
for i=1:nnodes |
---|
75 |
n=fscanf(fid,'%d',1); |
---|
76 |
for j=1:ncomp |
---|
77 |
temp=fscanf(fid,'%f %f',[1 2]); |
---|
78 |
A(n,j)=temp(1); |
---|
79 |
G(n,j)=temp(2); |
---|
80 |
end |
---|
81 |
end |
---|
82 |
|
---|
83 |
DATA=[A G]; |
---|
84 |
|
---|
85 |
% if flag==1,output constituents into .s2c files |
---|
86 |
if flag |
---|
87 |
disp('Writing individual components to disk...') |
---|
88 |
for i=1:ncomp |
---|
89 |
if isempty(fpath) |
---|
90 |
fname=[PERNAMES{i} '.s2c']; |
---|
91 |
else |
---|
92 |
fname=[fpath '/' PERNAMES{i} '.s2c']; |
---|
93 |
end |
---|
94 |
disp([' Writing ' fname '...']) |
---|
95 |
comment=[PERNAMES{i} ' HA RESULTS']; |
---|
96 |
err=write_s2c([DATA(:,i) DATA(:,i+ncomp)],gname,comment,FREQ(i),fname); |
---|
97 |
end |
---|
98 |
end |
---|