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

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

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

Initial import of Stark code.

Line 
1 function [data,nnv,freq]=read_vel(fname);
2 %RWRITE_VEL write a FEM output file of .vel filetype.
3 %   WRITE_VEL is part of a suite of OPNML I/O functions 
4 %   to I/O specific filetypes pertaining to FEM model 
5 %   input and output.   These functions allow the user to
6 %   get these data files into/out of MATLAB without copying the
7 %   files and removing the header info by hand.
8 %
9 %   WRITE_VEL writes 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 %   NOTES :   The .vel filetype contains 3-D data; i.e., complex-valued
35 %             velocity data at each vertical node per horizontal node.
36 %             The .vel file has phase in radians while the related .v3c
37 %             format has phase in degrees.
38 %
39 % Call as: [data,nnv,freq]=read_vel(fname);
40 %
41 % Written by : Brian O. Blanton
42 %
43 if nargin==0 & nargout==0
44    disp('Call as:  [data,nnv,freq]=read_vel(fname);')
45    return
46 end
47
48
49 if ~exist('fname')
50    [fname,fpath]=uigetfile('*.vel','Which .vel');
51    if fname==0,return,end
52 else
53    fpath=[];
54 end
55
56 if nargin > 1
57    error(['READ_VEL requires 0 or 1 input argument; type "help READ_VEL"']);
58 end
59
60 % get filetype from tail of fname
61 ftype=fname(length(fname)-2:length(fname));
62
63 % make sure this is an allowed filetype
64 if ~strcmp(ftype,'vel')
65    error(['READ_VEL cannot read ' ftype ' filetype'])
66 end
67
68 % open fname
69 [pfid,message]=fopen([fpath fname]);
70 if pfid==-1
71    error([fpath fname,' not found. ',message]);
72 end
73
74 % In all filetypes there is always a gridname and description line
75 % as lines #1 and #2 of the file.
76 % read grid name from top of file; header line #1
77 gridname=fgets(pfid);
78 gridname=blank(gridname);
79
80 % read description line from top of file; header line #2
81 descline=fgets(pfid);
82
83 % read number of vertical nodes (line #3) number of frequencies (line #4)
84 % and the frequency (line #5)
85 nnv=fscanf(pfid,'%d',1);
86 nfreq=fscanf(pfid,'%f',1);
87 freq=fscanf(pfid,'%f',1);
88
89 % read data segment
90 data=fscanf(pfid,'%d %f %f %f %f %f %f %f',[8 inf])';
91 fclose(pfid);
92 %
93 %        Brian O. Blanton
94 %        Curr. in Marine Science
95 %        15-1A Venable Hall
96 %        CB# 3300
97 %        Uni. of North Carolina
98 %        Chapel Hill, NC
99 %                 27599-3300
100 %
101 %        919-962-4466
102 %        blanton@marine.unc.edu
103 %
Note: See TracBrowser for help on using the browser.