1 |
%LOADGRID4 load principle gridfiles for a given domain name (input) |
---|
2 |
% |
---|
3 |
% Input: gridname - name of domain to load grid files |
---|
4 |
% |
---|
5 |
% Output: LOADGRID4 returns the following in this order (ALL OUTPUT |
---|
6 |
% ARGUMENTS ARE REQUIRED!!): |
---|
7 |
% 1) 3-column element list (columns 2-4 of .ele file ) |
---|
8 |
% 2) x-coordinate node list ( col 2 of .nod file ) |
---|
9 |
% 3) y-coordinate node list ( col 3 of .nod file ) |
---|
10 |
% 4) bathymetry list (col 2 of .bat) file |
---|
11 |
% 5) boundary node/pair list (.bnd file ) |
---|
12 |
% |
---|
13 |
% LOADGRID4 with no input gridname checks to see if the global |
---|
14 |
% variable DOMAIN has been set. If so, LOADGRID4 uses this |
---|
15 |
% name to load files for. If DOMAIN does NOT exist or is |
---|
16 |
% empty, the input gridname must be specified. |
---|
17 |
% |
---|
18 |
% If the boundary list (.bnd) exists locally, LOADGRID4 |
---|
19 |
% attempts to load the remaining files locally. If the .bnd |
---|
20 |
% file does NOT exist locally, LOADGRID4 searches the |
---|
21 |
% GRIDS and GRIDDIRS global variables for the grid data. |
---|
22 |
% |
---|
23 |
% If any of the principle grids files does not exist, LOADGRID4 |
---|
24 |
% displays the appropriate message and exits, returning empty |
---|
25 |
% arrays for missing variables. |
---|
26 |
% |
---|
27 |
% In a call to LOADGRID4, space must be provided for the |
---|
28 |
% output data to be returned. Therefore, call LOADGRID4 |
---|
29 |
% as follows: |
---|
30 |
% >> [ele,x,y,z,bnd]=loadgrid4(gridname); |
---|
31 |
% There are 5 variables in the output list, one for each |
---|
32 |
% returned array. |
---|
33 |
% |
---|
34 |
% Call as: [ele,x,y,z,bnd]=loadgrid4(gridname); |
---|
35 |
% |
---|
36 |
% Written by : Brian O. Blanton |
---|
37 |
% |
---|
38 |
|
---|
39 |
function [ele,x,y,z,bnd]=loadgrid4(gridname) |
---|
40 |
|
---|
41 |
% DEFINE ERROR STRINGS |
---|
42 |
err1=str2mat('You must specify 5 output arguments; call LOADGRID',... |
---|
43 |
'as [ele,x,y,z,bnd]=loadgrid(gridname)'); |
---|
44 |
err2=['gridname not supplied and global DOMAIN is empty']; |
---|
45 |
|
---|
46 |
global DOMAIN GRIDS GRIDDIRS |
---|
47 |
|
---|
48 |
if nargout ~=5 |
---|
49 |
disp('??? Error using ==> loadgrid'); |
---|
50 |
disp(err1); |
---|
51 |
return |
---|
52 |
end |
---|
53 |
|
---|
54 |
if ~exist('gridname') |
---|
55 |
if isempty(DOMAIN) |
---|
56 |
error(err2); |
---|
57 |
else |
---|
58 |
gridname=DOMAIN; |
---|
59 |
end |
---|
60 |
else |
---|
61 |
slashes=findstr(gridname,'/'); |
---|
62 |
if length(slashes)==0 |
---|
63 |
fpath=[]; |
---|
64 |
else |
---|
65 |
lastslash=slashes(length(slashes)); |
---|
66 |
fpath=gridname(1:lastslash); |
---|
67 |
gridname=gridname(lastslash+1:length(gridname)); |
---|
68 |
end |
---|
69 |
DOMAIN=gridname; |
---|
70 |
end |
---|
71 |
|
---|
72 |
% Is there a dot in the gridname? |
---|
73 |
% |
---|
74 |
dots=findstr(gridname,'.'); |
---|
75 |
if length(dots)~=0 |
---|
76 |
lastdot=dots(length(dots)); |
---|
77 |
dotname=gridname(1:lastdot-1); |
---|
78 |
end |
---|
79 |
|
---|
80 |
% check current working directory or fpath/cwd for principle gridfiles |
---|
81 |
% |
---|
82 |
if isempty(fpath) |
---|
83 |
disp('Searching locally ...'); |
---|
84 |
else |
---|
85 |
disp([ 'Searching ' fpath]); |
---|
86 |
end |
---|
87 |
|
---|
88 |
bndname=[deblank(gridname) '.bnd']; |
---|
89 |
nodname=[deblank(gridname) '.nod']; |
---|
90 |
elename=[deblank(gridname) '.ele']; |
---|
91 |
batname=[deblank(gridname) '.bat']; |
---|
92 |
|
---|
93 |
gsum=0; |
---|
94 |
if exist([fpath bndname])==2 |
---|
95 |
loadfn=['load ' fpath bndname]; |
---|
96 |
eval(loadfn); |
---|
97 |
if ~isempty(dots) |
---|
98 |
bnd=eval(dotname); |
---|
99 |
else |
---|
100 |
bnd=eval(gridname); |
---|
101 |
end |
---|
102 |
bndfound=1; |
---|
103 |
gsum=gsum+1; |
---|
104 |
disp(['Got ' bndname]) |
---|
105 |
else |
---|
106 |
bndfound=0; |
---|
107 |
bnd=[]; |
---|
108 |
end |
---|
109 |
|
---|
110 |
if exist([fpath nodname])==2 |
---|
111 |
loadfn=['load ' fpath nodname]; |
---|
112 |
eval(loadfn); |
---|
113 |
if ~isempty(dots) |
---|
114 |
nodes=eval(dotname); |
---|
115 |
else |
---|
116 |
nodes=eval(gridname); |
---|
117 |
end |
---|
118 |
x=nodes(:,2); |
---|
119 |
y=nodes(:,3); |
---|
120 |
nodfound=1; |
---|
121 |
gsum=gsum+1; |
---|
122 |
disp(['Got ' nodname]) |
---|
123 |
else |
---|
124 |
nodfound=0; |
---|
125 |
x=[]; |
---|
126 |
y=[]; |
---|
127 |
end |
---|
128 |
|
---|
129 |
if exist([fpath elename])==2 |
---|
130 |
loadfn=['load ' fpath elename]; |
---|
131 |
eval(loadfn); |
---|
132 |
if ~isempty(dots) |
---|
133 |
ele=eval(dotname); |
---|
134 |
else |
---|
135 |
ele=eval(gridname); |
---|
136 |
end |
---|
137 |
ele=ele(:,2:4); |
---|
138 |
elefound=1; |
---|
139 |
gsum=gsum+1; |
---|
140 |
disp(['Got ' elename]) |
---|
141 |
else |
---|
142 |
elefound=0; |
---|
143 |
ele=[]; |
---|
144 |
end |
---|
145 |
|
---|
146 |
if exist([fpath batname])==2 |
---|
147 |
loadfn=['load ' fpath batname]; |
---|
148 |
eval(loadfn); |
---|
149 |
if ~isempty(dots) |
---|
150 |
z=eval(dotname); |
---|
151 |
else |
---|
152 |
z=eval(gridname); |
---|
153 |
end |
---|
154 |
z=z(:,2); |
---|
155 |
batfound=1; |
---|
156 |
gsum=gsum+1; |
---|
157 |
disp(['Got ' batname]) |
---|
158 |
else |
---|
159 |
batfound=0; |
---|
160 |
z=[]; |
---|
161 |
end |
---|
162 |
|
---|
163 |
% If all gridfiles found locally, return |
---|
164 |
if gsum==4 |
---|
165 |
lnod=length(x); |
---|
166 |
lbat=length(z); |
---|
167 |
maxe=max(max(ele)); |
---|
168 |
if lnod~=lbat,disp(['WARNING!! Lengths of node list and depth list'... |
---|
169 |
' are NOT equal']),end |
---|
170 |
if lnod~=maxe,disp(['WARNING!! Max node number in element list does NOT'... |
---|
171 |
' equal length of node list']),end |
---|
172 |
return |
---|
173 |
elseif bndfound==0&elefound==1&gsum==3 |
---|
174 |
disp([' ' bndname ' not found; computing from ' elename '.']) |
---|
175 |
bnd=detbndy(ele); |
---|
176 |
return |
---|
177 |
elseif gsum~=0 |
---|
178 |
disp(' ') |
---|
179 |
disp(' NOT ALL FILES FOUND LOCALLY.') |
---|
180 |
if ~nodfound,disp([' ' nodname ' not found locally.']),end |
---|
181 |
if ~elefound,disp([' ' elename ' not found locally.']),end |
---|
182 |
if ~batfound,disp([' ' batname ' not found locally.']),end |
---|
183 |
str=str2mat(' ',' This is a problem. The files ',... |
---|
184 |
[' ' nodname ' ' elename ' & ' batname],... |
---|
185 |
' must all exist locally or all in one of',... |
---|
186 |
' the following directories (as set in ',... |
---|
187 |
' the global GRIDDIRS):',... |
---|
188 |
GRIDDIRS,... |
---|
189 |
' '); |
---|
190 |
disp(str); |
---|
191 |
% DOMAIN=[]; |
---|
192 |
return |
---|
193 |
end |
---|
194 |
|
---|
195 |
if isempty(fpath) |
---|
196 |
disp(['Gridfiles not found in ' pwd]) |
---|
197 |
else |
---|
198 |
disp(['Gridfiles not found in ' fpath]) |
---|
199 |
end |
---|
200 |
|
---|
201 |
if isempty(GRIDDIRS) |
---|
202 |
disp('No places in GRIDDIRS to search.'); |
---|
203 |
return |
---|
204 |
else |
---|
205 |
disp('Searching GRIDS for gridname match.'); |
---|
206 |
end |
---|
207 |
|
---|
208 |
% Check GRIDS list for gridname |
---|
209 |
% |
---|
210 |
if ~isempty(GRIDS) |
---|
211 |
igrid=0; |
---|
212 |
[m,n]=size(GRIDS); |
---|
213 |
for i=1:m |
---|
214 |
if strcmp(deblank(GRIDS(i,:)),gridname)==1 |
---|
215 |
igrid=i; |
---|
216 |
end |
---|
217 |
end |
---|
218 |
end |
---|
219 |
if ~igrid |
---|
220 |
disp([gridname ' not in GRIDS list']); |
---|
221 |
DOMAIN=[]; |
---|
222 |
return |
---|
223 |
end |
---|
224 |
disp('Got it.') |
---|
225 |
|
---|
226 |
% gridname found in GRIDS. Now, check GRIDDIRS for gridfiles |
---|
227 |
% |
---|
228 |
fpath=deblank(GRIDDIRS(igrid,:)); |
---|
229 |
|
---|
230 |
bn=[fpath '/' gridname '.bnd']; |
---|
231 |
nn=[fpath '/' gridname '.nod']; |
---|
232 |
en=[fpath '/' gridname '.ele']; |
---|
233 |
zn=[fpath '/' gridname '.bat']; |
---|
234 |
|
---|
235 |
if ~exist(nn) |
---|
236 |
disp([nn ' does not exist.']); |
---|
237 |
return |
---|
238 |
end |
---|
239 |
disp(['Got ' nodname]) |
---|
240 |
loadfn=['load ' nn]; |
---|
241 |
eval(loadfn); |
---|
242 |
if ~isempty(dots) |
---|
243 |
nodes=eval(dotname); |
---|
244 |
else |
---|
245 |
nodes=eval(gridname); |
---|
246 |
end |
---|
247 |
x=nodes(:,2); |
---|
248 |
y=nodes(:,3); |
---|
249 |
|
---|
250 |
if ~exist(en) |
---|
251 |
disp([en ' does not exist.']); |
---|
252 |
return |
---|
253 |
end |
---|
254 |
disp(['Got ' elename]) |
---|
255 |
loadfn=['load ' en]; |
---|
256 |
eval(loadfn); |
---|
257 |
if ~isempty(dots) |
---|
258 |
ele=eval(dotname); |
---|
259 |
else |
---|
260 |
ele=eval(gridname); |
---|
261 |
end |
---|
262 |
ele=ele(:,2:4); |
---|
263 |
|
---|
264 |
if ~exist(zn) |
---|
265 |
disp([zn ' does not exist.']); |
---|
266 |
return |
---|
267 |
end |
---|
268 |
disp(['Got ' batname]) |
---|
269 |
loadfn=['load ' zn]; |
---|
270 |
eval(loadfn); |
---|
271 |
if ~isempty(dots) |
---|
272 |
z=eval(dotname); |
---|
273 |
else |
---|
274 |
z=eval(gridname); |
---|
275 |
end |
---|
276 |
z=z(:,2); |
---|
277 |
|
---|
278 |
if exist(bn) |
---|
279 |
disp(['Got ' bndname]) |
---|
280 |
loadfn=['load ' bn]; |
---|
281 |
eval(loadfn); |
---|
282 |
if ~isempty(dots) |
---|
283 |
bnd=eval(dotname); |
---|
284 |
else |
---|
285 |
bnd=eval(gridname); |
---|
286 |
end |
---|
287 |
else |
---|
288 |
disp([bn ' does not exist. Computing from ' elename]); |
---|
289 |
bnd=detbndy(ele); |
---|
290 |
end |
---|
291 |
return; |
---|
292 |
% |
---|
293 |
% Brian O. Blanton |
---|
294 |
% Department of Marine Sciences |
---|
295 |
% 15-1A Venable Hall |
---|
296 |
% CB# 3300 |
---|
297 |
% University of North Carolina |
---|
298 |
% Chapel Hill, NC |
---|
299 |
% 27599-3300 |
---|
300 |
% |
---|
301 |
% 919-962-4466 |
---|
302 |
% blanton@marine.unc.edu |
---|
303 |
% |
---|
304 |
|
---|