function rho = testdetproj(detId, varargin)

% $Id: testdetproj.m,v 1.8 2004/05/11 15:08:06 stuver Exp $

addpath ../

if length(varargin) ~= 0
    if length(varargin) == 1
        plotSwitch = varargin{:};
        if strcmp(lower(plotSwitch), 'off')
            off = true;
        else
            off = ~true;
        end
        
    else
        error('testdetproj: varargin = plotSwitch')
    end
else
    off = ~true;
end

xx=0:pi/100:pi; % rad
yy=-pi:pi/50:pi; % rad
psi=0; %:2:90;

htt=[1/sqrt(2); 1/sqrt(2)];

b=waitbar(0,['Calculating antenna pattern for ' detId '...']);

for f=1:length(psi)
    External.psi=psi(f)*(pi/180);
    for g=1:length(xx)
        External.x=cos(xx(g));
        for h=1:length(yy)
            External.phi=yy(h);
            [aitch, fPlus, fCross] = ...
                detproj(htt, detId, External);
            H(g,h,f)=aitch;
            Fp(g,h)=fPlus;
            Fc(g,h)=fCross;
        end
    end
    waitbar(f/length(psi),b)
end

close(b)
% 
% load ligomapdata
% if ~off 
%     % Animate resulting strain for different values of psi
%     clear f
%     for f=1:length(psi)
%         
%         figure(1)
%         
%         subplot(121)
%         surf(-pi:pi/50:pi,-pi/2:pi/100:pi/2,flipud(H(:,:,f)),'linestyle','none')
%         title(['h for \psi = ' num2str(f-1) '^o at ' upper(detId)])
%         shading('interp');
%         colorbar('horiz');
%         view(0,90);
%         hold on;
%         plot(Coast.map(1,1:end), Coast.map(2,1:end), 'w');
%         plot(Llo.map(1,:), Llo.map(2,:), 'gx');
%         plot(Lho.map(1,:), Lho.map(2,:), 'wx');
%         axis equal;
%         axis([-pi, pi, -pi/2, pi/2]);
%         xlabel('Longitude');
%         ylabel('Latitude');
%         xlim([-pi, pi]);
%         ylim([-pi/2, pi/2]);
%         set(gca, 'XTick', -pi:pi/4:pi);
%         set(gca, 'XTickLabel', {'180 W', '135 W', '90 W', '45 W', '0', '45 E', ...
%                 '90 E', '135 E', '180 E'});
%         set(gca, 'YTick', -pi/2:pi/4:pi/2);
%         set(gca, 'YTickLabel', {'90 S', '45 S', '0', '45 N', '90 N'});
%         
%         subplot(122)
%         sphere(36)
%         h1 = findobj('Type', 'surface');
%         set(h1, 'CData', flipud(H(:,:,f)), 'FaceColor', 'texturemap')
%         set(gca, 'CameraPosition', 1.4*[Lho.globe(1,:), Lho.globe(2,:), Lho.globe(3,:)], 'CameraTarget', ...
%             [0, 0, 0])
%         axis off;
%         axis square;
%         hold on;
%         plot3(Coast.globe(1,1:end), Coast.globe(2,1:end), Coast.globe(3,1:end), 'w');
%         plot3(Llo.globe(1,:), Llo.globe(2,:), Llo.globe(3,:), 'gx');
%         plot3(Lho.globe(1,:), Lho.globe(2,:), Lho.globe(3,:), 'wx');
%         
%         figure(1), shg
%         
%         pause(0.01)
%     end
% end
% clf

rho=Fp.^2+Fc.^2;

if ~off
    ligomap(-pi:pi/50:pi,-pi/2:pi/100:pi/2,flipud(rho));
    
    figure(1)
    title(['Antanna Pattern for ' upper(detId)])
    figure(2)
    title(['Antanna Pattern for ' upper(detId)])
end

return