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

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

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

Initial import of Stark code.

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