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

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

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

Initial import of Stark code.

Line 
1 function [x,y,ic,z,nbs]=read_nei(fname);
2 %READ_NEI read a FEM neighbor file of .nei filetype.
3 %
4 % [x,y,bc,z,nbs]=read_nei(fname);
5 %
6 %   Input :   If fname is omitted, READ_NEI enables a file browser
7 %             with which the user can specify the .NEI file.
8 %
9 %             Otherwise, fname is the name of the .nei file, relative
10 %             or absolute (fullpath), including the suffix .'nei'.
11 %             This input is a string so it must be enclosed in
12 %             single quotes.
13 %
14 %  Output :   Five (5) arrays are returned to the local workspace:
15 %             1) x - x-coordinates of the grid
16 %             2) y - y-coordinates of the grid
17 %             3) bc - boundary codes for each horizontal node
18 %             4) z - bathymetry of the grid
19 %             5) nbs - neighbor list of grid's nodes
20 %
21 % Call as: [x,y,bc,z,nbs]=read_nei(fname);
22 %
23 % Written by Brian Blanton
24 % January 1996
25 %
26
27 if nargin==0&nargout==0
28    disp('Call as: [x,y,bc,z,nbs]=read_nei(fname);')
29    return
30 end
31
32    
33 if ~exist('fname')
34    [fname,fpath]=uigetfile('*.nei','Which .nei');
35    if fname==0,return,end
36 else
37    fpath=[];
38 end
39
40 if nargin > 1
41    error(['READ_NEI requires 0 or 1 input argument; type "help READ_NEI"']);
42 elseif nargout ~=5
43    error(['READ_NEI requires 5 output arguments; type "help READ_NEI"']);
44 end
45
46 % get filetype from tail of fname
47 ftype=fname(length(fname)-2:length(fname));
48
49 % make sure this is an allowed filetype
50 if ~strcmp(ftype,'nei')
51    error(['READ_NEI cannot read ' ftype ' filetype'])
52 end
53
54 % open fname
55 [pfid,message]=fopen([fpath fname]);
56 if pfid==-1
57    error([fpath fname,' not found. ',message]);
58 end
59
60 nnd=fscanf(pfid,'%d',1);
61 nnb=fscanf(pfid,'%d',1);
62 maxmin=fscanf(pfid,'%f %f %f %f',4);
63
64 fmt1='%d %f %f %d %f ';
65 fmt2='%d ';
66 for i=2:nnb
67    fmt2=[fmt2 '%d '];
68 end
69 fmtstr=[fmt1 fmt2];
70 nread=nnb+5;
71 data=fscanf(pfid,eval('fmtstr'),[nread nnd])';
72 x=data(:,2);
73 y=data(:,3);
74 ic=data(:,4);
75 z=data(:,5);
76 nbs=data(:,6:nread);
77
78 return
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 %
92
Note: See TracBrowser for help on using the browser.