% edited on 04/25/2016
% have different setting for different recording room
% use new recording room and new system
% also get output: distance from center for each location
% not distinguish clockwise or counterclockwise

fs_sin=8000;
fs0=800;
t=0 : 1/fs_sin : 0.1;
beep0 = sin(fs0*2*pi*t);

Ang_RewardLoc=nan(max(Ind_loc),1);
X_RewardLoc=nan(max(Ind_loc),1);
Y_RewardLoc=nan(max(Ind_loc),1);
Dist_RewardLoc=nan(max(Ind_loc),1);
pause(10);
for ind=Ind_loc
    % Starting reward loc(ind)
    sound(beep0,fs_sin);
    pause(5);
    [~, ~, locationArray, ~, VTRecsReturned, ~] = NlxGetNewVTData(vt_acq_ent);
    x_loc = locationArray(end - 1);
    y_loc = locationArray(end);
    while ~x_loc && ~y_loc %% if x_loc=0, y_loc=0 means it's a missing data from the video
        pause(0.1)
        [~, ~, locationArray, ~, VTRecsReturned, ~] = NlxGetNewVTData(vt_acq_ent);
        x_loc = locationArray(end - 1);
        y_loc = locationArray(end);
    end
    x0_RewardLoc = x_sign*double(x_loc).*scale_x;
    y0_RewardLoc = y_sign*double(y_loc).*scale_y;
    x1_RewardLoc = x0_RewardLoc-x_center;
    y1_RewardLoc = y0_RewardLoc-y_center;
    if x1_RewardLoc>=0
        if x1_RewardLoc==0 x1_RewardLoc=0.1; end
        ang1_RewardLoc=mod(atan(-y1_RewardLoc./x1_RewardLoc),2*pi);
    else
        ang1_RewardLoc=mod(atan(-y1_RewardLoc./x1_RewardLoc)+pi,2*pi);
    end
    
    Ang_RewardLoc(ind,1)=ang1_RewardLoc;
    X_RewardLoc(ind,1)=x1_RewardLoc;
    Y_RewardLoc(ind,1)=y1_RewardLoc;
    Dist_RewardLoc(ind,1)=sqrt(x1_RewardLoc^2+y1_RewardLoc^2);
end
sound(beep0,fs_sin);