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

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

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

Initial import of Stark code.

Line 
1 function errno=write_nei(x,y,bc,z,nbs,fname)
2 %WRITE_NEI Write a FEM neighbor file in .nei format.
3 %   WRITE_NEI requires 5 input arguments, with 1 optional argument:
4 %      1) x   - x-coordinates of the grid (REQ)           
5 %      2) y   - y-coordinates of the grid (REQ)           
6 %      3) bc  - boundary codes for each horizontal node (REQ)
7 %      4) z   - bathymetry of the grid (REQ)             
8 %      5) nbs - neighbor list of grid's nodes (REQ)
9 %      6) fname - output filename (OPT)                   
10 %
11 %   If fname is omitted, WRITE_NEI enables a file browser
12 %   with which the user can specify the .NEI file.
13 %   Otherwise, fname is the name of the .nei file, relative
14 %   or absolute (fullpath), including the suffix .'nei'.
15 %   This input is a string so it must be enclosed in
16 %   single quotes.
17 %
18 %   WRITE_NEI checks the lengths of input arrays and the
19 %   structure of the neighbor list for some minimal
20 %   error checking.  This is not, however, very rigorous.
21 %
22 % CALL: err=write_nei(x,y,bc,z,nbs,fname);
23 %          err=write_nei(x,y,bc,z,nbs);
24 %
25 % Written by : Brian O. Blanton
26 %              March 1996
27 %
28
29 if nargin==0 & nargout==0
30    disp('Call as:  err=write_nei(x,y,bc,z,nbs,fname);')
31    return
32 end
33
34
35 if nargout > 1
36    error(['WRITE_NEI requires 0 or 1 output argument; type "help WRITE_NEI"']);
37 end
38
39 if nargin < 5 & nargin > 6
40    error(['WRITE_NEI requires 5 or 6 input arguments; type "help WRITE_NEI"']);
41 end
42
43 if ~exist('fname')
44    [fname,fpath]=uigetfile('*.nei','Which .nei');
45    if fname==0,return,end
46 else
47    fpath=[];
48 end
49
50 % get filetype from tail of fname
51 ftype=fname(length(fname)-2:length(fname));
52
53 % make sure this is an allowed filetype
54 if ~strcmp(ftype,'nei')
55    error(['WRITE_NEI cannot write ' ftype ' filetype'])
56 end
57
58 % open fname
59 [pfid,message]=fopen([fpath fname],'w');
60 if pfid==-1
61    error([fpath fname,' not found. ',message]);
62 end
63
64 fprintf(pfid,'%d\n',length(x));
65 [nn,nnb]=size(nbs);
66 fprintf(pfid,'%d\n',nnb);
67
68 xmin=min(x);xmax=max(x);
69 ymin=min(y);ymax=max(y);
70 maxmin=fprintf(pfid,'%.3f   %.3f   %.3f   %.3f\n',[xmax ymax xmin ymin]);
71
72 fmt1='%5d %14.6f %14.6f %1d %8.3f ';
73 fmt2='%5d ';
74 for i=2:nnb
75    fmt2=[fmt2 '%5d '];
76 end
77 fmtstr=[fmt1 fmt2 '\n'];
78 nwrite=nnb+5;
79 nnn=1:nn;
80 fprintf(pfid,eval('fmtstr'),[nnn(:) x(:) y(:) bc(:) z(:) nbs]');
81
82 err=0;
83 return
84
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 %
97
Note: See TracBrowser for help on using the browser.