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

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

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

Initial import of Stark code.

Line 
1 function [data,nnv,freq,gridname]=read_vel(fname);
2 %READ_VEL read a FEM output file of .vel filetype.
3 %   READ_VEL is part of a suite of OPNML I/O functions 
4 %   to read specific filetypes pertaining to FEM model 
5 %   input and output.   These functions allow the user to
6 %   get these data files into MATLAB without copying the
7 %   files and removing the header info by hand.
8 %
9 %   READ_VEL reads the FEM filetype .vel, as detailed in
10 %   "Data File Standards for the Gulf of Maine Project"
11 %   from the Numerical Methods Laboratory at Dartmouth
12 %   College.  (This document is located in the OPNML
13 %   notebook under External Documents.)  There are eight
14 %   columns, the first of which is the node number.  The
15 %   remaining columns are floating point. 
16 %
17 %   Input :   If fname is omitted, READ_VEL enables a file browser
18 %             with which the user can specify the .vel file.
19 %
20 %             Otherwise, fname is the name of the .vel file, relative
21 %             or absolute (fullpath), including the suffix '.vel'.
22 %             This input is a string so it must be enclosed in single
23 %             quotes. The header lines are discarded.
24 %
25 %  Output :   The data part is returned in the variable data. 
26 %             There are eight columns, the first of which is the node
27 %             number.  The remaining columns are floating point.
28 %             The number of vertical nodes is returned in nnv, and
29 %             the frequency is returned in freq.
30 %
31 %             Call READ_VEL as:
32 %             >> [data,nnv,freq]=read_vel(fname);
33 %
34 %             If READ_VEL cannot locate the file, it exits, returning
35 %             a -1 instead of the data matrix.
36 %
37 %   NOTES :   The .vel filetype contains 3-D data; i.e., complex-valued
38 %             velocity data at each vertical node per horizontal node.
39 %             The .vel file has phase in radians while the related .v3c
40 %             format has phase in degrees.
41 %
42 % Call as: [data,nnv,freq,gridname]=read_vel(fname);
43 %
44 % Written by : Brian O. Blanton
45 %
46 if nargin==0 & nargout==0
47    disp('Call as:  [data,nnv,freq,gridname]=read_vel(fname);')
48    return
49 end
50
51
52 if ~exist('fname')
53    [fname,fpath]=uigetfile('*.vel','Which .vel');
54    if fname==0,return,end
55 else
56    fpath=[];
57 end
58
59 if nargin > 1
60    error(['READ_VEL requires 0 or 1 input argument; type "help READ_VEL"']);
61 end
62
63 % get filetype from tail of fname
64 ftype=fname(length(fname)-2:length(fname));
65
66 % make sure this is an allowed filetype
67 if ~strcmp(ftype,'vel')
68    error(['READ_VEL cannot read ' ftype ' filetype'])
69 end
70
71 % open fname
72 [pfid,message]=fopen([fpath fname]);
73 if pfid==-1
74    error([fpath fname,' not found. ',message]);
75 end
76
77 % In all filetypes there is always a gridname and description line
78 % as lines #1 and #2 of the file.
79 % read grid name from top of file; header line #1
80 gridname=fgets(pfid);
81 gridname=blank(gridname);
82
83 % read description line from top of file; header line #2
84 descline=fgets(pfid);
85
86 % read number of vertical nodes (line #3) number of frequencies (line #4)
87 % and the frequency (line #5)
88 nnv=fscanf(pfid,'%d',1);
89 nfreq=fscanf(pfid,'%f',1);
90 freq=fscanf(pfid,'%f',1);
91
92 % read data segment
93 data=fscanf(pfid,'%d %f %f %f %f %f %f %f',[8 inf])';
94 fclose(pfid);
95 %
96 %        Brian O. Blanton
97 %        Curr. in Marine Science
98 %        15-1A Venable Hall
99 %        CB# 3300
100 %        Uni. of North Carolina
101 %        Chapel Hill, NC
102 %                 27599-3300
103 %
104 %        919-962-4466
105 %        blanton@marine.unc.edu
106 %
Note: See TracBrowser for help on using the browser.