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

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

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

Initial import of Stark code.

Line 
1 function [data,freq,nnv]=read_s3c(fname)
2 %READ_S3C read a FEM output file of s3c filetype.
3 %
4 % [data,freq,nnv]=read_s3c(fname)
5 %
6 %             READ_S3C is part of a suite of OPNML I/O functions 
7 %             to read specific filetypes pertaining to FEM model 
8 %             input and output.   These functions allow the user to
9 %             get these data files into MATLAB without copying the
10 %             files and removing the header info by hand.
11 %
12 %             READ_S3C reads the FEM filetype s3c, as
13 %             detailed in "Data File Standards for the Gulf of Maine
14 %             Project" from the Numerical Methods Laboratory at
15 %             Dartmouth College.  (This document is located in the OPNML
16 %             notebook under External Documents.)  There are four
17 %             columns, the first of which is the node number.  The
18 %             remaining columns are floating point. 
19 %
20 %   Input :   If fname is omitted, READ_S3C enables a file browser
21 %             with which the user can specify the .s3c file.
22 %
23 %             Otherwise, fname is the name of the s3c file, relative
24 %             or absolute (fullpath), including the suffix 's3c'.
25 %             This input is a string so it must be enclosed in single
26 %             quotes. The header lines are discarded.
27 %  Output :   The data part is returned in the variable data.
28 %
29 %             Call READ_S3C as:
30 %             >> [data,freq,nnv]=read_s3c(fname);
31 %             s3c filetypes contain both the frequency and the number
32 %             of vertical nodes as header info, which will be returned
33 %             to the user.
34 %
35 %             If READ_S3C cannot locate the file, it exits, returning
36 %             a -1 instead of the data matrix.
37 %             
38 %   NOTES :   The .s3c filetype contains 3-D data; i.e., complex-valued
39 %             scalar data at each vertical node per horizontal node.
40 %
41 % Call as: [data,freq,nnv]=read_s3c(fname);
42 %
43 % Written by : Brian O. Blanton
44 %
45
46 if ~exist('fname')
47    [fname,fpath]=uigetfile('*.s3c','Which .s3c');
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,'s3c')
58    error(['READ_S3C 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 and number of vertical nodes from lines #3 and #4
77 nnv=fscanf(pfid,'%d',1);
78 freq=fscanf(pfid,'%f',1);
79
80 % read data segment
81 data=fscanf(pfid,'%d %f %f %f',[4 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.