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

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

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

Initial import of Stark code.

Line 
1 function [data,nnv]=read_v3c(fname);
2 %READ_V3C read a FEM output file of .v3c filetype.
3 %   READ_V3C 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_V3C reads the FEM filetype .v3c, 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_V3C enables a file browser
18 %             with which the user can specify the .v3c file.
19 %
20 %             Otherwise, fname is the name of the .v3c file, relative
21 %             or absolute (fullpath), including the suffix '.v3c'.
22 %             This input is a string so it must be enclosed in single
23 %             quotes. The header lines are discarded.
24 %  Output :   The data part is returned in the variable data.
25 %
26 %             Call READ_V3C as:
27 %             >> [data,nnv]=read_v3c(fname);
28 %
29 %             If READ_V3C cannot locate the file, it exits, returning
30 %             a -1 instead of the data matrix.
31 %
32 %   NOTES :   The v3c filetype contains 3-D data; i.e., complex-valued
33 %             velocity data at each vertical node per horizontal node.
34 %             The v3c format has phase in degrees while related .vel
35 %             file has phase in radians.
36 %
37 % Call as: [data,nnv]=read_v3c(fname);
38 %
39 % Written by : Brian O. Blanton
40 %
41
42 if nargin==0 & nargout==0
43    disp('Call as: [data,nnv]=read_v3c(fname);')
44    return
45 end
46
47 if ~exist('fname')
48    [fname,fpath]=uigetfile('*.v3c','Which .v3c');
49    if fname==0,return,end
50 else
51    fpath=[];
52 end
53
54 % get filetype from tail of fname
55 ftype=fname(length(fname)-2:length(fname));
56
57 % make sure this is an allowed filetype
58 if ~strcmp(ftype,'v3c')
59    error(['READ_V3C cannot read ' ftype ' filetype'])
60 end
61
62 % open fname
63 [pfid,message]=fopen([fpath fname]);
64 if pfid==-1
65    error([fpath fname,' not found. ',message]);
66 end
67
68 % In all filetypes there is always a gridname and description line
69 % as lines #1 and #2 of the file.
70 % read grid name from top of file; header line #1
71 gridname=fgets(pfid);
72 gridname=blank(gridname);
73
74 % read description line from top of file; header line #2
75 descline=fgets(pfid);
76
77 % read number of vertical nodes (line #3) and frequency (line #4)
78 nnv=fscanf(pfid,'%d',1);
79 freq=fscanf(pfid,'%f',1);
80
81 % read data segment
82 data=fscanf(pfid,'%d %f %f %f %f %f %f %f',[8 inf])';
83 fclose(pfid);
84 %
85 %        Brian O. Blanton
86 %        Department of Marine Sciences
87 %        15-1A Venable Hall
88 %        CB# 3300
89 %        Uni. of North Carolina
90 %        Chapel Hill, NC
91 %                 27599-3300
92 %
93 %        919-962-4466
94 %        blanton@marine.unc.edu
95 %
Note: See TracBrowser for help on using the browser.