-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.m
More file actions
186 lines (128 loc) · 4.65 KB
/
analysis.m
File metadata and controls
186 lines (128 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
% analysis
% analyses:
% sweeps
% hf spectra -> power spectral density
% downsamples files
t_start_analysis = clock; % NOTE: Not number of seconds, but [year month day hour minute seconds].
global an_tabindex an_debug NEL_tabindex NED_tabindex usc_tabindex;
NEL_tabindex=[];
NED_tabindex=[];
usc_tabindex=[];
an_tabindex = zeros(0, 9);
an_debug = 0; %debugging on or off!
antype = cellfun(@(x) x(end-6:end-4),tabindex(:,2),'un',0);
XXP =[];
XXP2=[];
%find datasets of different modes
ind_I1L= find(strcmp('I1L', antype));
ind_I2L= find(strcmp('I2L', antype));
ind_I3L= find(strcmp('I3L', antype));
ind_V1L= find(strcmp('V1L', antype));
ind_V2L= find(strcmp('V2L', antype));
ind_V3L= find(strcmp('V3L', antype));
ind_V1H= find(strcmp('V1H', antype));
ind_V2H= find(strcmp('V2H', antype));
ind_V3H= find(strcmp('V3H', antype));
ind_I1H= find(strcmp('I1H', antype));
ind_I2H= find(strcmp('I2H', antype));
ind_I3H= find(strcmp('I3H', antype));
ind_I1S= find(strcmp('I1S', antype));
ind_I2S= find(strcmp('I2S', antype));
spath=sprintf('%s/XXP_save.mat',derivedpath);
%
% try
%
% load(spath,'XXP')
% fprintf(1,'load XXP successful')
%
% catch err
fprintf(1,'Analysing sweeps\n')
if(~isempty(ind_I1S))
[XXP]=an_sweepmain_v2(ind_I1S,tabindex,targetfullname);
end
save(spath,'XXP');
if(~isempty(ind_I2S))
% fprintf(1,' Analysing LAP2 sweeps\n')
% [XXP2]=an_sweepmain_v2(ind_I2S,tabindex,targetfullname);
% save(spath,'XXP','XXP2');
end
fprintf(1,'Outputting Science\n')
if(~isempty(XXP))
try
an_outputscience(XXP);
catch err
fprintf(1,'Error: an_outputscience failed \n')
err.identifier
err.message
len = length(err.stack);
if (~isempty(len))
for i=1:len
fprintf(1,'%s, %i; ',err.stack(i).name,err.stack(i).line);
end
end
end
else
fprintf(1,'Error: an empty XXP was loaded, or no sweeps were analysed. aborting\n')
end
fprintf(1,'Downsampling low frequency measurements\n')
if(~isempty(ind_I1L))
an_NEL(ind_I1L,tabindex,index)
an_downsample(ind_I1L,32,tabindex,index)
end
if(~isempty(ind_I2L))
an_NEL(ind_I2L,tabindex,index)
an_downsample(ind_I2L,32,tabindex,index)
end
ind_VL=[ind_V1L;ind_V2L];
if(~isempty(ind_VL))
ind_VL=sort(ind_VL,'ascend');
an_downsample(ind_VL,32,tabindex,index)
an_NEL(ind_VL,tabindex,index)
end
fprintf(1,'Generating spectra\n')
if(ind_I1H) an_hf(ind_I1H,tabindex,'I1H'); end
if(ind_I2H) an_hf(ind_I2H,tabindex,'I2H'); end
if(ind_I3H) an_hf(ind_I3H,tabindex,'I3H'); end
if(ind_V1H) an_hf(ind_V1H,tabindex,'V1H'); end
if(ind_V2H) an_hf(ind_V2H,tabindex,'V2H'); end
if(ind_V3H) an_hf(ind_V3H,tabindex,'V3H'); end
try
if ~isempty(usc_tabindex) % some USC (Vz) files might be overwritten by our routine, and creates duplicate entries in usc_tabindex. We should find these and delete them
%usc_tabindex(:).fname
[Uniquefname,junk,k] = unique({usc_tabindex(:).fname});
% Uniquefname is a sorted list of usc_tabindex.fname
% k is indices of uniqueC that represents usc_tabindex.fname, some of them might be
% duplicates
N_Uniquefname = histc(k,1:numel(Uniquefname)); %
% N > 1 corresponds to indices of duplicates in the sorted list
% uniqueC
if any(N_Uniquefname>1)
fprintf(1,'Deleting duplicates in USC_TABINDEX \n')
vz_inds= strcmp('Vz',{usc_tabindex.type});
dupindz= find(N_Uniquefname>1);
delindz=[];
for i=1:length(dupindz)
checkindz=strcmp(Uniquefname(dupindz(i)),{usc_tabindex.fname}); %this should only find two files, but it works for more.
delthis= find(checkindz & vz_inds); %all duplicates that are also Vz files should be deleted. (this should keep the Vfloat files)
%delthis= find(strcmp(usc_tabindex(checkindz).type,'Vz')); %all duplicates that are also Vz files should be deleted. (this should keep the Vfloat files)
delindz=[delindz;delthis];%append to list of deletion indices
end
usc_tabindex(delindz)=[];
NED_tabindex(delindz)=[];
%loop finished, make deletion
end
end
catch err
fprintf(1,'Error: Deleting of duplicate USC_TABINDEX failed \n')
err.identifier
err.message
len = length(err.stack);
if (~isempty(len))
for i=1:len
fprintf(1,'%s, %i; ',err.stack(i).name,err.stack(i).line);
end
end
end
%fprintf(1, 'Best estimates\n')
%an_tabindex = best_estimates(an_tabindex, tabindex, index, obe);
%fprintf(1, '%s (incl. best_estimates): %.0f s (elapsed wall time)\n', mfilename, etime(clock, t_start_analysis));