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

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

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

Initial import of Stark code.

Line 
1 function [data,nnv,gname]=read_s3r(fname)
2 %READ_S3R read a FEM output file of .s3r filetype.
3 %   READ_S3R 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_S3R reads the ascii filetypes .s3r,
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
14 %   first of which is the node number.  The second and third 
15 %   columns are floating point numbers.  The filetype suffix
16 %   ('.s3r') must be included in the input file name.   
17 %
18 %   Input :   If fname is omitted, READ_S3R enables a file browser
19 %             with which the user can specify the .s3r file.
20 %
21 %             Otherwise, fname is the name of the file, relative or
22 %             absolute (fullpath), including the '.s3r' suffix;
23 %             This input is a string so it must be enclosed in
24 %             single quotes. The comment line is discarded.
25 %
26 %  Output :   Call READ_S3R as:
27 %             >> [data,nnv,gname]=read_s3r(fname);
28 %             The domain name will be returned in "gname".
29 %             The number of vertical nodes is returned in "nnv".
30 %             The node counter, depth and value of the scalar field
31 %             are returned in "data".
32 %
33 %             If READ_S3R cannot locate the file, it exits, returning
34 %             a -1 instead of the data matrix.
35 %
36 %   NOTES :   The .s3r filetype contains 3-D data; i.e., real-valued
37 %             scalar data at each vertical node per horizontal node.
38 %
39 % Call as: [data,nnv,gname]=read_s3r(fname);
40 %
41 % Written by : Brian O. Blanton
42 %
43
44 if nargin==0 & nargout==0
45    disp('Call as:  [data,nnv,gname]=read_s3r(fname);')
46    return
47 end
48
49 if ~exist('fname')
50    [fname,fpath]=uigetfile('*.s3r','Which .s3r ?');
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,'s3r')
61    error(['READ_S3R 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',[3 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.