1 |
% IS_VALID_STRUCT - Determine if the input structure is "valid" |
---|
2 |
% |
---|
3 |
% IS_VALID_STRUCT determines whether or not the input |
---|
4 |
% structure is valid or invalid according to the |
---|
5 |
% description of FEM_GRID_STRUCT. A valid FEM_GRID_STRUCT |
---|
6 |
% contains (atleast) the following (NOT EMPTY) fields: |
---|
7 |
% |
---|
8 |
% .name - the domain name of the FEM grid |
---|
9 |
% .e - node connectivity list (linear, triangular) [ne x 3 double] |
---|
10 |
% .x - x-horizontal node coordinates [nn x 1 double] |
---|
11 |
% .y - y-horizontal node coordinates [nn x 1 double] |
---|
12 |
% .z - bathymetry list [nn x 1 double] |
---|
13 |
% .bnd - boundary segment list [nb x 2 double] |
---|
14 |
% |
---|
15 |
% As a (not very rigorous) check, the maximum node number in the |
---|
16 |
% element and boundary lists must not exceed the length of the node |
---|
17 |
% list, and the node list ane bathymetry lists must be the same length. |
---|
18 |
% |
---|
19 |
% There is no way to guarantee that the data in the fields actually |
---|
20 |
% all came from the same domain (mesh). However, if the |
---|
21 |
% FEM_GRID_STRUCT was output from LOADGRID or LOADG, then it is guaranteed. |
---|
22 |
% |
---|
23 |
% CALL: errflag=is_valid_struct(fem_grid_struct) |
---|
24 |
% |
---|
25 |
% Written by : Brian O. Blanton |
---|
26 |
% Summer 1997 |
---|
27 |
% |
---|
28 |
function errflag=is_valid_struct(fem_grid_struct) |
---|
29 |
|
---|
30 |
errflag=0; |
---|
31 |
|
---|
32 |
% Make sure input argument is actually a structure |
---|
33 |
% |
---|
34 |
if ~isstruct(fem_grid_struct) |
---|
35 |
disp(' Argument to IS_VALID_STRUCT must be a structure.');return |
---|
36 |
end |
---|
37 |
|
---|
38 |
% now, make sure the structure contains the minimum FEM_GRID_STRUCT fields |
---|
39 |
% |
---|
40 |
if ~isfield(fem_grid_struct,'name') |
---|
41 |
disp(' Domain name field not part of fem_grid_struct');return |
---|
42 |
elseif ~isfield(fem_grid_struct,'e') |
---|
43 |
disp(' Element list field not part of fem_grid_struct');return |
---|
44 |
elseif ~isfield(fem_grid_struct,'x') |
---|
45 |
disp(' X-node list field not part of fem_grid_struct');return |
---|
46 |
elseif ~isfield(fem_grid_struct,'y') |
---|
47 |
disp(' Y-node list field not part of fem_grid_struct');return |
---|
48 |
elseif ~isfield(fem_grid_struct,'z') |
---|
49 |
disp(' Bathymetry list field not part of fem_grid_struct');return |
---|
50 |
elseif ~isfield(fem_grid_struct,'bnd') |
---|
51 |
disp(' Boundary list field not part of fem_grid_struct');return |
---|
52 |
end |
---|
53 |
|
---|
54 |
% now, make sure the minimum FEM_GRID_STRUCT fields are NOT EMPTY |
---|
55 |
% |
---|
56 |
if isempty(fem_grid_struct.name) |
---|
57 |
disp(' Domain name field in fem_grid_struct is EMPTY');return |
---|
58 |
elseif isempty(fem_grid_struct.e) |
---|
59 |
disp(' Element list field in fem_grid_struct is EMPTY');return |
---|
60 |
elseif isempty(fem_grid_struct.x) |
---|
61 |
disp(' X-node list field in fem_grid_struct is EMPTY');return |
---|
62 |
elseif isempty(fem_grid_struct.y) |
---|
63 |
disp(' Y-node list field in fem_grid_struct is EMPTY');return |
---|
64 |
elseif isempty(fem_grid_struct.z) |
---|
65 |
disp(' Bathymetry list field in fem_grid_struct is EMPTY');return |
---|
66 |
elseif isempty(fem_grid_struct.bnd) |
---|
67 |
disp(' Boundary list field in fem_grid_struct is EMPTY');return |
---|
68 |
end |
---|
69 |
|
---|
70 |
% Check the max node numbers in .bnd and .e fields |
---|
71 |
% |
---|
72 |
len_x=length(fem_grid_struct.x); |
---|
73 |
len_y=length(fem_grid_struct.y); |
---|
74 |
len_z=length(fem_grid_struct.z); |
---|
75 |
max_e=max(max(fem_grid_struct.e)); |
---|
76 |
max_b=max(max(fem_grid_struct.bnd)); |
---|
77 |
|
---|
78 |
if(len_x~=len_y) |
---|
79 |
disp(' Lengths of .x and .y fields NOT equal');return |
---|
80 |
elseif(len_x~=len_z) |
---|
81 |
disp(' Lengths of .x, .y and .z fields NOT equal');return |
---|
82 |
elseif(max_e>len_x) |
---|
83 |
disp(' Maximum node number in .e field exceeds length of .xy field');return |
---|
84 |
elseif(max_b>len_x) |
---|
85 |
disp(' Maximum node number in .bnd field exceeds length of .xy field');return |
---|
86 |
end |
---|
87 |
|
---|
88 |
errflag=1; |
---|
89 |
|
---|
90 |
% These are non-fatal warnings! |
---|
91 |
% |
---|
92 |
%if(max_e<len_xy) |
---|
93 |
% disp('OPNML: non-fatal warning!!') |
---|
94 |
% disp(' Maximum node number in .e field LESS THAN length of .xy field');return |
---|
95 |
%elseif(max_b<len_xy) |
---|
96 |
% disp('OPNML: non-fatal warning!!') |
---|
97 |
% disp(' Maximum node number in .bnd field LESS THAN length of .xy field');return |
---|
98 |
%end |
---|
99 |
|
---|
100 |
% |
---|
101 |
% Brian O. Blanton |
---|
102 |
% Curr. in Marine Science |
---|
103 |
% 15-1A Venable Hall |
---|
104 |
% CB# 3300 |
---|
105 |
% Uni. of North Carolina |
---|
106 |
% Chapel Hill, NC |
---|
107 |
% 27599-3300 |
---|
108 |
% |
---|
109 |
% 919-962-4466 |
---|
110 |
% blanton@marine.unc.edu |
---|
111 |
% |
---|
112 |
% Summer 1997 |
---|