forked from MarineBioAcousticsRC/DetEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeSFilesTimes.m
65 lines (51 loc) · 2.03 KB
/
writeSFilesTimes.m
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
function writeSFilesTimes(cDir,saveDir)
secInDay = 60*60*24;
% get folder names
folders = dir(cDir) ;
folders = ({folders.name})' ;
folders = folders(3:end);
% get deployment names
siteDiskList = cell(length(folders),1);
for s = 1: length(folders)
a = cell2mat(strfind(folders(s),'_disk'));
siteDiskList{s,1} = folders{s}(1:a-1);
end
siteDisk = unique(siteDiskList);
for i = 1:length(siteDisk)
% loop over files from the same site (e.g., MC01)
disp(['loading times from: ', siteDisk{i}]);
index = strfind(siteDiskList, siteDisk{i});
siteDiskIdx = find(not(cellfun('isempty', index)));
% return detection times from the same site
times = [];
allfolders = [];
for j = 1:length(siteDiskIdx)
f = siteDiskIdx(j);
fold = fullfile(cDir,folders{f});
disp([' ', folders{f}]);
SearchFileMask = {'*.s'};
SearchPathMask = {fold};
SearchRecursiv = 1;
[PathFileList, FileList, ~] = ...
utFindFiles(SearchFileMask, SearchPathMask, SearchRecursiv);
for idx = 1:length(PathFileList)
[sNoise, eNoise, Labels] = ioReadLabelFile(PathFileList{idx});
if ~isempty(sNoise)
detShip = strmatch('ship', Labels);
Starts = sNoise(detShip);
Stops = eNoise(detShip);
undscr = strfind(FileList{idx},'_');
t = FileList{idx}(undscr(end-1)+1:end-2);
timeNum = datenum(t,'yymmdd_HHMMSS');
StartTimes = timeNum + Starts/secInDay;
StopTimes = timeNum + Stops/secInDay;
times = [times;[StartTimes, StopTimes]];
allfolders = [allfolders;repmat(folders(siteDiskIdx(j)),length(StartTimes),1)];
end
end
end
% write times in mat file
FileName = [siteDisk{i},'_',allfolders{1}(end-5:end),'-',allfolders{end}(end-1:end),'.mat'];
save(fullfile(saveDir,FileName),'times');
end
disp('Done writing ship file times')