NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/IO_Functions/read_adcirc_ha_vel.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 function [DATA,FREQ,PERNAMES]=read_adcirc_ha_vel(fname,flag,gname)
2 %READ_ADCIRC_HA_VEL read ADCIRC velocity 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.54
5 % file.  fort.54 is the default output file for the global harmonic
6 % analysis of the velocity field. 
7 %
8 %  Input : fname - filename to read velocity from.  If empty,
9 %                  routine reads from fort.54.  Analysis from
10 %                  specified stations (fort.52) can be read in
11 %                  by providing fname='fort.52'.
12 %          flag  - if flag==1, the contents of the velocity file
13 %                  are output to disk in .v2c file format, one file
14 %                  per period.
15 %          gname - if flag==1, then gname provides the grid name
16 %                  for the .v2c file output format.
17 % Output : DATA     -  matrix of amplitudes and phases, as in
18 %                      DATA = [uamp1 ... upha1 ... vamp1 ... vpha1 ...];
19 %          FREQ     -  vector of component frequencies
20 %          PERNAMES -  string vector of component names
21 %
22 % Call as: [DATA,FREQ,PERNAMES]=read_adcirc_ha_vel(fname,flag,gname);
23 %
24 % Written by: Brian Blanton, Spring '99
25
26 % if no arguments, assume fort.54...
27
28 if nargin==0
29    fname='fort.54';
30    flag=0;  % no .v2c output to disk
31    gname='';
32 elseif nargin==1
33    % See if fname is string
34    if ~isstr(fname)
35       fname='fort.54';
36       if flag~=0 | flag~=1
37          error('FLAG to READ_ADCIRC_HA_VEL 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    fid=fopen([fname ext],'r');
57 else
58    fid=fopen([fpath '/' fname ext],'r');
59 end
60
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 UA=NaN*ones(nnodes,ncomp);
72 UG=NaN*ones(nnodes,ncomp);
73 VA=NaN*ones(nnodes,ncomp);
74 VG=NaN*ones(nnodes,ncomp);
75
76 for i=1:nnodes
77    n=fscanf(fid,'%d',1);
78    for j=1:ncomp
79       temp=fscanf(fid,'%f %f %f %f',[1 4]);
80       UA(n,j)=temp(1);
81       UG(n,j)=temp(2);
82       VA(n,j)=temp(3);
83       VG(n,j)=temp(4);
84    end
85 end
86
87 DATA=[UA UG VA VG];
88
89
90
91 % if flag==1,output comstituents into .v2c files
92 if flag
93    disp('Writing individual components to disk...')
94    for i=1:ncomp
95       if isempty(fpath)
96          fname=[PERNAMES{i} '.v2c'];
97       else
98          fname=[fpath '/' PERNAMES{i} '.v2c'];   
99       end
100       disp(['   Writing ' fname '...'])
101       comment=[PERNAMES{i} ' HA RESULTS'];
102       D=[DATA(:,i) DATA(:,i+ncomp) DATA(:,i+2*ncomp) DATA(:,i+3*ncomp)];
103       err=write_s2c(D,gname,comment,FREQ(i),fname);
104    end
105 end   
106
107
108
109
Note: See TracBrowser for help on using the browser.