function [R_A, Z_A, ang_A,varargout]=sxrageometry(varargin);
%
% [R_A, Z_A, ang_A]=sxrageometry;
%
% returns angles for A SXR camera from AUG
% The R values at a given z=zmag are then given by:
% zmag>Z_A: only ang_A<180
% R= R_A - (zmag-Z_A)./tan(pi-ang_A.*pi/180);
% zmag<Z_A: only ang_A>180
% R= R_A - (zmag-Z_A)./tan(pi-ang_A.*pi/180);
%
% varargin{1}: zmag(t) (scalar or array)
%
% output
%  R_A, Z_A scalars
%  ang_A(nbchannels,1);
%  varargout: R(nbchannels,time), with NaN depending on conditions above
%

R_A=1.411;
Z_A=-1.075;
ang_A= [...
      47.852, ...
      49.967, ...
      52.151 , ...
      54.266  , ...
      56.449    , ...
      58.565    , ...
      60.748    , ...
      62.863    , ...
      65.047      , ...
      67.162   , ...
      69.345     , ...
      71.460    , ...
      73.644   , ...
      75.759     , ...
      77.942  , ...
      80.058      , ...
      82.241    , ...
      84.356   , ...
      86.540    , ...
      88.655    , ...
      90.838    , ...
      92.953    , ...
      95.137    , ...
      97.252    , ...
      99.435   , ...
      101.551   , ...
      103.734   , ...
      105.849   , ...
      108.033   , ...
      110.148]';

varargout{1}=[];
if nargin <1 | isempty(varargin{1})
  return
end

% compute R
zmag=varargin{1};
varargout{1}=NaN*ones(length(ang_A),length(zmag));
for i=1:length(ang_A)
  varargout{1}(i,:) = R_A - (zmag'-Z_A)./tan(pi-ang_A(i).*pi/180);
end
iiout=find(varargout{1}<=0 | varargout{1}>=2.5);
varargout{1}(iiout)=NaN;
