function Cordnt = getifo(detId)

% GETIFO - get detector coordinates
%
% Cordnt = getifo(detId)
%
% detId      detector identifier string in any form of mixed case
%
% Cordnt    structure containing coordinate info for IFO
%   .V         X-arm unit vector in Cartesian coordinates
%   .W         Y-arm unit vector in Cartesian coordinates
%   .LAT       beam splitter latitude in rad
%   .CODEC     cosine of the beam splitter co-declination
%   .LONG      beam splitter longitude in rad
%   .WGS84     beam splitter location in WGS-84 coordinates in m
%   .R         beam splitter distance from center of the earth in m
%
% Currently supported detectors are:
%       'H1'    LIGO 4km IFO at LHO
%       'H2'    LIGO 2km IFO at LHO
%       'L1'    LIGO 4km IFO at LLO
%
% SEE ALSO: GRAVEN, IFODELAY, DETPROJ, MAKELIST

% $Id: getifo.m,v 1.6 2004/05/07 19:57:37 stuver Exp $

% DETERMINE desired detector
% GENERATE structure containing coordinates
% RETURN structure

% Initalize Cordnt struct
Cordnt = deal(struct('V', [], 'W', [], 'LAT', [], 'CODEC', [], 'LONG', ...
    [], 'WGS84', [], 'R', []));

% Define converstion constant from degrees to radians
DEG2RAD = pi/180;

% Make detId all uppercase
detId = upper(detId);

% All LIGO coordinates (except CODEC & R) are verbatim from LIGO-P000006-D-E:
%   Rev. Sci. Instrum., Vol. 72, No. 7, July 2001

if strcmp(detId, 'H1') | strcmp(detId, 'H2')
    % Generate coordinates for LHO:
    
    % X-arm unit vector
    Cordnt.V = [-0.223891216, 0.799830697, 0.556905359];
    % Y-arm unit vector
    Cordnt.W = [-0.913978490, 0.0260953206, -0.404922650];
    % Beam splitter latitude
    Cordnt.LAT = dms2dec('N', [46, 27, 18.527841])*DEG2RAD; % rad
    % Beam splitter co-declination determined from latitude
    Cordnt.CODEC = cos((pi/2)-Cordnt.LAT);
    % Beam splitter longitude
    Cordnt.LONG = dms2dec('W', [119, 24, 27.565681])*DEG2RAD; % rad
    % WGS-84 coordinates of beam splitter (Only one coordinate specified in
    % the document for both H1 and H2)
    Cordnt.WGS84 = [-2.161414928e+6, -3.834695183e+6, 4.600350224e+6]; % m
    % Beam splitter distance from center of the Earth determined from
    % WGS-84 coordinates
    Cordnt.R = sqrt(sum(Cordnt.WGS84.^2)); % m
elseif strcmp(detId, 'L1')
    % Generate coordinates for LLO:
    
    % X-arm unit vector
    Cordnt.V = [-0.954574615, -0.141579994, -0.262187738];
    % Y-arm unit vector
    Cordnt.W = [0.297740169, -0.487910627, -0.820544948]; % rad
    % Beam splitter latitude
    Cordnt.LAT = dms2dec('N', [30, 33, 46.419531])*DEG2RAD; % rad
    % Beam splitter co-declination determined from latitude
    Cordnt.CODEC = cos((pi/2)-Cordnt.LAT);
    % Beam splitter longitude
    Cordnt.LONG = dms2dec('W', [90, 46, 27.265294])*DEG2RAD; % rad
    % WGS-84 coordinates of beam splitter
    Cordnt.WGS84 = [-74276.04192, -5.496283721e+6, 3.224257016e+6]; % m
    % Beam splitter distance from center of the Earth determined from
    % WGS-84 coordinates
    Cordnt.R = sqrt(sum(Cordnt.WGS84.^2)); % m
else
    error('getifo: The detId you entered is not currently listed.')
end

return

% ~~~ END MAIN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function degdec = dms2dec(nsew, coord);

% DMS2DEC - convert longitude and latitude in dms to degrees decimal
%
% deg2dec = dms2dec(nsew, coord)
%
% nsew    string indicating whether longitude is measured east ('E') or 
%         west ('W') or latitude is measured north ('N') or south ('S')
% coord   1x3 vector defining the coordinates in degrees (coord(1)),
%         minutes (coord(2)) and seconds (coord(3))
%
% degdec    coordinates in degrees decimal.  A negative longiude indicates
%           Western Hemisphere while a negative latitude value indicates 
%           Southern Hemisphere

% MAKE nsew upper case for ease of comparison
% DEFINE sign of converted coordinates
% CONVERT coordinates

% Initialize degdec
degdec = [];

% Make nsew all upper case for ease in using strcmp
nsew = upper(nsew);

% Define sign of converted coordinates
if strcmp(nsew, 'S')
    % If in Southern Hemisphere, the coordinates will be negative
    pm = -1;
elseif strcmp(nsew, 'N')
    % If in the Northern Hemisphere, the coordinates will be positive
    pm = 1;
elseif strcmp(nsew, 'W')
    % If in the Western Hemisphere, the coordinates will be negative
    pm = -1;
elseif strcmp(nsew, 'E')
    % If in the Eastern Hemisphere, the coordinates will be postive
    pm = 1;
else
    error(['getifo -> dms2dec: Please enter ''N'', ''S'', ''E'' ' ...
            'or ''W'' for nsew'])
end

% Convert dms into degrees decimal
degdec = pm*(coord(1)+(coord(2)/60)+(coord(3)/3600));

return