1 |
function DDS=check_data(DDS,type) |
---|
2 |
% internal DIWASP1.1 function |
---|
3 |
% checks data structures |
---|
4 |
% |
---|
5 |
% DDS=check_data(DDS,type) |
---|
6 |
% DDS is the data structure |
---|
7 |
% type:1, Instrument data structure 2, Spectral matrix structure 3, Estimation parameters structure |
---|
8 |
|
---|
9 |
|
---|
10 |
%defaults: |
---|
11 |
SM.xaxisdir=90; |
---|
12 |
EP.dres=180;EP.nfft=[];EP.method='EMEP';EP.iter=100; |
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 |
switch type |
---|
17 |
%Instrument data structure |
---|
18 |
case 1 |
---|
19 |
if ~isstruct(DDS) |
---|
20 |
disp('DIWASP data_check: Instrument data type is not a structure'); |
---|
21 |
end |
---|
22 |
error='';nc=1; |
---|
23 |
if ( isfield(DDS,'layout') ) |
---|
24 |
[nr,nc]=size(getfield(DDS,'layout')); |
---|
25 |
if nr<3 |
---|
26 |
if nr==2 DDS.layout(3,:)=0; |
---|
27 |
;else;error='layout';end |
---|
28 |
;end;else;error='layout';end |
---|
29 |
if ( isfield(DDS,'datatypes') ) & all(size(getfield(DDS,'datatypes'))==[1 nc])==1 |
---|
30 |
;else;error='datatypes';end |
---|
31 |
if ( isfield(DDS,'depth') ) & length(getfield(DDS,'depth'))==1 |
---|
32 |
;else;error='depth';end |
---|
33 |
if ( isfield(DDS,'fs') ) & length(getfield(DDS,'fs'))==1 |
---|
34 |
;else;error='fs';end |
---|
35 |
|
---|
36 |
if ( isfield(DDS,'data') ) |
---|
37 |
if size(getfield(DDS,'data'),2)==nc; ;else;error='data';end |
---|
38 |
else |
---|
39 |
DDS.data=zeros(1,nc); |
---|
40 |
end |
---|
41 |
|
---|
42 |
if length(error)>0 |
---|
43 |
disp(['Instrument data structure error: ' error ' not specified correctly']); |
---|
44 |
DDS=[];return; |
---|
45 |
end |
---|
46 |
%Spectral matrix |
---|
47 |
case 2 |
---|
48 |
if ~isstruct(DDS) |
---|
49 |
disp('DIWASP data_check: Spectral matrix data type is not a structure'); |
---|
50 |
end |
---|
51 |
error=''; |
---|
52 |
if ( isfield(DDS,'freqs') )& min(size(getfield(DDS,'freqs')))==1 |
---|
53 |
nf=length(DDS.freqs); |
---|
54 |
;else;error='freqs';end |
---|
55 |
if ( isfield(DDS,'dirs') )& min(size(getfield(DDS,'dirs')))==1 |
---|
56 |
nd=length(DDS.dirs); |
---|
57 |
;else;error='dirs';end |
---|
58 |
if ( isfield(DDS,'S') ) |
---|
59 |
if ~((size(DDS.S,1)==nf & size(DDS.S,2)==nd) | isempty(DDS.S)) |
---|
60 |
error='S';end |
---|
61 |
;else;DDS.S=[];end |
---|
62 |
if ( isfield(DDS,'xaxisdir') ) |
---|
63 |
if ~length(DDS.xaxisdir)==1 |
---|
64 |
error='xaxisdir';end |
---|
65 |
;else;DDS.xaxisdir=SM.xaxisdir;end |
---|
66 |
|
---|
67 |
if length(error)>0 |
---|
68 |
disp(['Spectral matrix structure error: ' error ' not specified correctly']); |
---|
69 |
DDS=[];return; |
---|
70 |
end |
---|
71 |
|
---|
72 |
%Estimation parameters |
---|
73 |
case 3 |
---|
74 |
if ~isstruct(DDS) |
---|
75 |
disp('DIWASP data_check: Estimation parameter data type is not a structure'); |
---|
76 |
end |
---|
77 |
error=''; |
---|
78 |
if ( isfield(DDS,'dres') ) |
---|
79 |
if ~length(DDS.dres)==1 |
---|
80 |
error='dres'; |
---|
81 |
elseif DDS.dres<10 |
---|
82 |
DDS.dres=10; |
---|
83 |
end |
---|
84 |
;else;DDS.dres=EP.dres;end |
---|
85 |
if ( isfield(DDS,'nfft') ) |
---|
86 |
if ~length(DDS.nfft)==1 |
---|
87 |
error='nfft'; |
---|
88 |
elseif DDS.nfft<64 |
---|
89 |
DDS.nfft=64; |
---|
90 |
end |
---|
91 |
;else;DDS.nfft=EP.nfft;end |
---|
92 |
if ( isfield(DDS,'iter') ) |
---|
93 |
if ~length(DDS.iter)==1 |
---|
94 |
error='iter';end |
---|
95 |
;else;DDS.iter=EP.iter;end |
---|
96 |
if ( isfield(DDS,'smooth') ) |
---|
97 |
if ~strcmp(DDS.smooth,'OFF') |
---|
98 |
DDS.smooth='ON';end |
---|
99 |
;else;DDS.smooth='ON';end |
---|
100 |
if ( isfield(DDS,'method') ) |
---|
101 |
if ~(any(strcmp(DDS.method,{'DFTM','EMLM','IMLM','EMEP','BDM'}))) |
---|
102 |
error='method';end |
---|
103 |
;else;DDS.method=EP.method;end |
---|
104 |
|
---|
105 |
if length(error)>0 |
---|
106 |
disp(['Estimation parameters structure error: ' error ' not specified correctly']); |
---|
107 |
DDS=[];return; |
---|
108 |
end |
---|
109 |
|
---|
110 |
otherwise |
---|
111 |
warning('DIWASP data_check: Data type unknown'); |
---|
112 |
DDS=[]; |
---|
113 |
end |
---|
114 |
|
---|
115 |
|
---|