%% Step 1: Run this script to mark cues of click trains of interest.
% Before this can be done, the .dtg files needs to be decompressed and
% the .prh files need to be made (see www.animaltags.org for tools). Furthermore, 
% you should have the cal-file for the given animal.

clear all
path = mfilename('fullpath');
hdd = path(1);
spath = [hdd,':\d3\scripts'];
% spath = ['E:\d3\scripts'];
global recdir prefix

% prefix is the notation for the animal that is currently being worked on:

% prefix = 'hp12_272a';
% prefix = 'hp12_293a'; %mother-calf 
% prefix = 'hp13_102a';
% prefix = 'hp14_226b';
  prefix = 'hp15_218a'; 
% prefix = 'hp16_264a'; %mother-calf 

recoveries = spath;
NS = 5; % number of seconds to display 
channel = 1;
recdir = [hdd,':\d3\data\',prefix(1:4),'\',prefix];
caldir = [hdd,':\d3\d3matlab\cal'];

deploy_name = prefix;
prhdir = [hdd,':\d3\data\metadata\prh']; % Path to your prh-files
auddir = [hdd,':\d3\data\metadata\aud']; % Path to where the audit .txt files are going to be saved

settagpath('cal',caldir,'prh',prhdir, 'audit', auddir);

% if starting fresh (not after the audit tool crashing):%
R = loadaudit(deploy_name);

% if the tool crashes use these lines instead of the one above (but ONLY if it crashes):
% load(fullfile(recoveries,'d3audit_RECOVER.mat'))% 1. step. 
% R = RES; % Only use this if the tool crashes! 2. step

R = d3audithp(recdir,prefix,8600,R,NS,channel,recoveries); % 3) skridt followed by quit %Nået til 21770 (100517) 36100
 
% if you want to find and load the cues for a specific sound (in the example below, the audit tool will load the last buzz)
% ix = strmatch('pc',R.stype);
% pc_cues = R.cue(ix,:);
% R = d3audithp(recdir,prefix,R.cue(ix(end),1),R)

saveaudit(deploy_name,R) % 4. skridt
