function [R,Curv,Pout] = VCM_STS(StationCoord, UTOutPupilu, DLv)
%{ 
This function calculates the STS VCM ROC required to image the pupil at the UT output pupilposition (equation according to STS control soft doc)
                   
 Input arguments:      
         StationCoord           AT station coord  (u,v) in meters
         UTOutPupilu            UT output pupil position along u in meters                 
         DLv                    DL axis position  along v

 Output arguments:
        R                       Computed Radius of curvature of STS-VCM (m)
        Curv                    Computed curvature of VCM (mm^-1)
        Pout                    Pupil distance from Station center (m)
%}

% Taken from PRIMA STS control SW design description VLT-SPE-ESO-15736-386
% constants
% %**** AS DEFINED IN VLT-SPE-ESO-15736-3186 issue 2.8 april 2007
% %STS M15 focal length (m)
fprintf('\n')
fprintf('STS DATA VLT-SPE-ESO-15736-3186 issue 2.8 april 2007 \n')
f1 = -0.75386/2; 
%STS M16 focal length (m)
f2 = 2.0673/2; 
%VCMC1 distance VCM to M15
VCMC1 = 0.679;
%C1C2 distance M15 M16
C1C2 = 0.791;


% 
% % %*** DATA GIVEN BY FDE 
% fprintf('\n')
% fprintf('STS DATA FDE \n')
% %STS M15 focal length (m)
% f1 = -0.7539/2; %+/- 1 mm/2
% %STS M16 focal length (m)
% f2 = 2.0613/2; %+/- 2 mm/2
% %VCMC1 distance VCM to M15
% VCMC1 = 0.67930;
% %C1C2 distance M15 M16
% C1C2 = 0.7873;



% V-Offset between C2 (STS M16) and the center of the station
OFS=398.7e-3;  %assumed to be the same for A or B feed

%P0in distance input pupil to VCM (almost infinity)
P0in = 1e9; % by design of the STS

%Pout OFS+distance from station to the target U coord along Dlv coord
%Note: the station center match the central V axis of the DL (no need to
%worry about which feed of the DL is used

Pout = abs(StationCoord(1)-UTOutPupilu)+abs(StationCoord(2)-DLv)+OFS;

Dint = C1C2+(Pout*f2)./(f2-Pout);
Dout = (f1*Dint)./(f1-Dint)+VCMC1;
R=-2*Dout./(Dout/P0in-1)
Curv = 1./(R*1e3);

fprintf('\n')
fprintf('**************** \n')
fprintf('    VCM_STS \n')
fprintf('**************** \n')
fprintf('V-Offset to station center OFS %e (m)\n', OFS)
fprintf('STS VCM ROC is: %e (m)\n', R)
fprintf('STS VCM curvature is: %e (mm-1)\n', Curv)
fprintf('Pout is: %e (m)\n', Pout)
fprintf(' **************** \n')


end

