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

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

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

Initial import of Stark code.

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