function [X,Y]=llssmi1(along,alat,clon,hemis)
%-----------------------------------------------------------------------
% function [X,Y]=llssmi1(along,alat,clon,hemis)
% 
% function to convert [lon,lat] to [X,Y] in "stereographic projection" 
% with the secant plane intersecting at 70N and centered at [70N,-45E].
% Copied from llssmi1.pro
%
% INPUT: along,alat [Mx1] and [Mx1]
%      : hemis = 1 for northern, -1 for southern
% OUTPUT: X,Y       [Mx1] and [Mx1]
% 
% ATN 11.27.06
%-------------------------------------------------------------------------

t=zeros(2,1);
cdr=57.29577951;
re=6378.273;				% Radius of the Earth (km)
e2=0.006693883;				% Eccentricity square
e=sqrt(e2);
slat=hemis*70.0;			% Standard Parallel (degrees)
%xlam=-45.0;				% Meridian along positive
xlam=clon;
sn=1;
rlat=0;
cm=0;
rho=0;
ii=0;
dtr=acos(0)/(hemis*90);

maxlat=max(alat);
if(maxlat<0);
  sn=-1;
  xlam=0;
end;
alat=sn.*alat;
along=sn.*along;

term1=tan((pi/4)-(alat./(2*cdr)));
term2=(((1-e.*sin(alat.*dtr))./(1+e.*sin(alat.*dtr))).^(e/2));
t0 = term1./term2;

term1=tan((pi/4)-(slat./(2*cdr)));
term2=(((1-e.*sin(slat.*dtr))./(1+e.*sin(slat.*dtr))).^(e/2));
t1 = term1/term2;

cm=cos(slat.*dtr)./sqrt(1-e2*(sin(slat*dtr).^2));
rho=re*cm.*t0./t1;
X=(rho.*sn.*sin((along-xlam).*dtr)).*1e3;
Y=-(rho*sn.*cos((along-xlam).*dtr)).*1e3;

if(hemis==1);
  inx=find(alat>89.995);
else;
  inx=find(alat<-89.995);
end;
if(length(inx)>0);
   X(inx)=0;
   Y(inx)=0;
end;

%alat=alat.*sn;
%along=along.*sn;
return
