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

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

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

Initial import of Stark code.

Line 
1 function [data,nnv,gname]=read_v3r(fname)
2 %READ_V3R read a FEM output file of .v3r filetype.
3 %   READ_V3R 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_V3R reads the FEM filetype .v3r, as
10 %   detailed in "Data File Standards for the Gulf of Maine
11 %   Project" from the Numerical Methods Laboratory at
12 %   Dartmouth College.  There are five
13 %   columns, the first of which is the node number.  The
14 %   remaining columns are floating point.  The filetype
15 %   suffix ('.v3r') must be included in the input file name.
16 %
17 %   Input :   If fname is omitted, READ_V3R enables a file browser
18 %             with which the user can specify the .v3r file.
19 %
20 %             Otherwise, fname is the name of the file, relative or
21 %             absolute (fullpath), including the suffix '.v3r'.
22 %             This input is a string so it must be enclosed in single
23 %             quotes. The comment line is discarded.
24 %
25 %  Output :   Call READ_V3R as:
26 %             >> [data,nnv,gname]=read_v3r(fname);
27 %             The domain name will be returned in "gname".
28 %             The number of vertical nodes is returned in "nnv".
29 %             The node counter, depth and amplitudes  of the u,
30 %             v, and w components of the vector field are returned
31 %             in "data".
32 %
33 %             If READ_V3R cannot locate the file, it exits, returning
34 %             a -1 instead of the data matrix.
35 %
36 %   NOTES :   The v3r filetype contains 3-D data; i.e., real-valued
37 %             velocity data at each vertical node per horizontal node.
38 %             
39 % Call as: [data,nnv,gname]=read_v3r(fname);
40 %
41 % Written by : Brian O. Blanton
42 %
43
44 if nargin==0 & nargout==0
45    disp('Call as: [data,nnv,gname]=read_v3r(fname);')
46    return
47 end
48
49 if ~exist('fname')
50    [fname,fpath]=uigetfile('*.v3r','Which .v3r ?');
51    if fname==0,return,end
52 else
53    fpath=[];
54 end
55
56 % get filetype from tail of fname
57 ftype=fname(length(fname)-2:length(fname));
58
59 % make sure this is an allowed filetype
60 if ~strcmp(ftype,'v3r')
61    error(['READ_V3R cannot read ' ftype ' filetype'])
62 end
63
64 % open fname
65 [pfid,message]=fopen([fpath fname]);
66 if pfid==-1
67    error([fpath fname,' not found. ',message]);
68 end
69
70 % In all filetypes there is always a gridname and description line
71 % as lines #1 and #2 of the file.
72 % read grid name from top of file; header line #1
73 gridname=fgets(pfid);
74 gname=blank(gridname);
75
76 % read description line from top of file; header line #2
77 descline=fgets(pfid);
78
79 % read number of vertical nodes (line #3)
80 nnv=fscanf(pfid,'%d',1);
81
82 % read data segment
83 data=fscanf(pfid,'%d %f %f %f %f',[5 inf])';
84 fclose(pfid);
85 %
86 %        Brian O. Blanton
87 %        Department of Marine Sciences
88 %        15-1A Venable Hall
89 %        CB# 3300
90 %        Uni. of North Carolina
91 %        Chapel Hill, NC
92 %                 27599-3300
93 %
94 %        919-962-4466
95 %        blanton@marine.unc.edu
96 %
Note: See TracBrowser for help on using the browser.