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

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

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

Initial import of Stark code.

Line 
1 function [data,freq,gridname]=read_v2c(fname)
2 %READ_V2C read a FEM output file of .v2c filetype.
3 %   READ_V2C 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_V2C reads the FEM filetype .v2c, as
10 %   detailed in "Data File Standards for the Gulf of Maine
11 %   Project" from the Numerical Methods Laboratory at
12 %   Dartmouth College.  (This document is located in the OPNML
13 %   notebook under External Documents.)  There are five
14 %   columns, the first of which is the node number.  The
15 %   remaining columns are floating point. The filetype
16 %   suffix ('.v2c') must be included in the input file name. 
17 %
18 %   Input :   If fname is omitted, READ_V2C enables a file browser
19 %             with which the user can specify the .v2c file.
20 %
21 %             Otherwise, fname is the name of the file, relative or
22 %             absolute (fullpath).  This input is a string so it must
23 %             must be enclosed in single quotes. The comment line
24 %             is discarded.
25 %
26 %  Output :   Call READ_V2C as:
27 %             >> [data,freq,gname]=read_v2c(fname);
28 %             The domain name will be returned in "gname".
29 %             The frequency in rads/secs is returned in "freq".
30 %             The node counter and amplitude and phase of the
31 %             u and v components of the vector field are returned
32 %             in "data".
33 %
34 %             If READ_V2C cannot locate the file, it exits, returning
35 %             a -1 instead of the data matrix.
36 %
37 % Call as: [data,freq,gname]=read_v2c(fname);
38 %
39 % Written by : Brian O. Blanton
40 %
41
42 if nargin==0 & nargout==0
43    disp('Call as: [data,freq,gname]=read_v2c(fname);')
44    return
45 end
46
47 if ~exist('fname')
48    [fname,fpath]=uigetfile('*.v2c','Which .v2c ?');
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,'v2c')
59    error(['READ_V2C 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 frequency line (#3)
78 freq=fscanf(pfid,'%f',1);
79
80 % read data segment
81 data=fscanf(pfid,'%d %f %f %f %f',[5 inf])';
82 fclose(pfid);
83 %
84 %        Brian O. Blanton
85 %        Department of Marine Sciences
86 %        15-1A Venable Hall
87 %        CB# 3300
88 %        Uni. of North Carolina
89 %        Chapel Hill, NC
90 %                 27599-3300
91 %
92 %        919-962-4466
93 %        blanton@marine.unc.edu
94 %
Note: See TracBrowser for help on using the browser.