function [theta] = erik_angle(B_ds, str)
%
% function [theta] = erik_angle(B_ds, str)
%
% Input:  B-field in despun coordinates, str = what angle
% Output: Angle between spinplane and B-field if str = "xy"
%         Angle between B-field in xy-plane and x-axis if str = "x"
%
%   All references are to Parallel Electric Fields in Space
%   thesis paper by Erik Bergman, 2003


% Angle between B-field and xy-plane, see Eq. (4.4)
if str == 'xy'
  B = av_abs(B_ds); % B is B_ds with an added column 5 that has values of |B_ds|
  theta = [B(:,1) asin(B(:,4)./B(:,5))*180/pi];

% Angle between B-field in xy-plane and x-axis, see Eq. (4.5)
elseif str == 'x'
  theta = [B_ds(:,1) atan(B_ds(:,3)./B_ds(:,2))*180/pi];
else
  theta = [Nan NaN];
  disp('Error in str in erik_angle(B_ds, str): not valid string');
end
