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

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

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

Initial import of Stark code.

Line 
1 function [data,gridname]=read_s2r(fname)
2 %READ_S2R read a FEM output file of s2r filetype.
3 %   READ_S2R 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_S2R reads the FEM filetype s2r, as detailed in
10 %   "Data File Standards for the Gulf of Maine Project"
11 %   from the Numerical Methods Laboratory at Dartmouth
12 %   College.  (This document is located in the OPNML
13 %   notebook under External Documents.)  There are two
14 %   columns, the first of which is the node number.  The
15 %   second column is floating point. 
16 %
17 %   Input :   If fname is omitted, READ_S2R enables a file browser
18 %             with which the user can specify the .s2r file.
19 %
20 %             Otherwise, fname is the name of the s2r file, relative
21 %             or absolute (fullpath), including the suffix 's2r'.
22 %             This input is a string so it must be enclosed in single
23 %             quotes. The header lines are discarded.
24 %
25 %  Output :   The data part is returned in the variable data.
26 %             The domain name is returned in gname
27 %
28 %             Call READ_S2R as:
29 %             >> [data,gname]=read_s2r(fname);
30 %
31 %             If READ_S2R cannot locate the file, it exits, returning
32 %             a -1 instead of the data matrix.
33 %
34 % Call as: >> [data,gname]=read_s2r(fname);
35 %
36 % Written by : Brian O. Blanton
37 %
38
39 if nargin==0 & nargout==0
40    disp('Call as: [data,gname]=read_s2r(fname);')
41    return
42 end
43
44 if ~exist('fname')
45    [fname,fpath]=uigetfile('*.s2r','Which .s2r');
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,'s2r')
56       error(['READ_S2R cannot read ' ftype ' filetype'])
57 end
58
59 % open fname
60 [pfid,message]=fopen([fpath fname]);
61 if pfid==-1
62    disp([fpath fname,' not found. ',message]);
63    data=-1;
64    return
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 data segment
77 data=fscanf(pfid,'%d %f',[2 inf])';
78 fclose(pfid);
79
80 %
81 %        Brian O. Blanton
82 %        Department of Marine Sciences
83 %        15-1A Venable Hall
84 %        CB# 3300
85 %        Uni. of North Carolina
86 %        Chapel Hill, NC
87 %                 27599-3300
88 %
89 %        919-962-4466
90 %        blanton@marine.unc.edu
91 %
Note: See TracBrowser for help on using the browser.