001/*
002 * $Id: Sidereal.java,v 1.2 2011/03/24 16:06:33 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2011
007 * Space Science and Engineering Center (SSEC)
008 * University of Wisconsin - Madison
009 * 1225 W. Dayton Street, Madison, WI 53706, USA
010 * https://www.ssec.wisc.edu/mcidas
011 * 
012 * All Rights Reserved
013 * 
014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015 * some McIDAS-V source code is based on IDV and VisAD source code.  
016 * 
017 * McIDAS-V is free software; you can redistribute it and/or modify
018 * it under the terms of the GNU Lesser Public License as published by
019 * the Free Software Foundation; either version 3 of the License, or
020 * (at your option) any later version.
021 * 
022 * McIDAS-V is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
025 * GNU Lesser Public License for more details.
026 * 
027 * You should have received a copy of the GNU Lesser Public License
028 * along with this program.  If not, see http://www.gnu.org/licenses.
029 */
030
031package edu.wisc.ssec.mcidasv.data.adde.sgp4;
032
033/**
034 *
035 * @author Shawn
036 */
037public class Sidereal 
038{
039    
040    /**
041     * Calculates the Greenwich mean sidereal time (GMST) on julDate (doesn't have to be 0h).
042     * Used calculations from Meesus 2nd ed. 
043     * @param mjd Modified Julian Date
044     * @return Greenwich mean sidereal time in degrees (0-360)
045     */
046    public static double Greenwich_Mean_Sidereal_Deg(double mjd)
047    {
048        // calculate T
049        double T = (mjd-51544.5)/36525.0;  
050        
051        // do calculation
052        double gmst = ( (280.46061837 + 360.98564736629*(mjd-51544.5)) + 0.000387933*T*T - T*T*T/38710000.0) % 360.0;
053        
054        // make positive
055        if(gmst < 0)
056        {
057            gmst += 360.0;
058        }
059        
060        return gmst;
061    } //Greenwich_Mean_Sidereal_Deg
062    
063    /**
064     * Calculates the mean sidereal time (MST) on julDate (doesn't have to be 0h) for a given longitiude.
065     * @param mjd Modified Julian Date
066     * @param longitude longitude in degrees
067     * @return mean sidereal time in degrees (0-360)
068     */
069    public static double Mean_Sidereal_Deg(double mjd, double longitudeDeg)
070    {
071        return (Greenwich_Mean_Sidereal_Deg(mjd) + longitudeDeg) % 360.0;
072    } // Mean_Sidereal_Deg
073
074    
075    // main testing function
076    public static void main(String[] args)
077    {
078        double mjd = 2449991.875 - AstroConst.JDminusMJD;
079        double longitude = -75; // degrees
080        double latitude = 40;
081        
082        double mst = Sidereal.Mean_Sidereal_Deg(mjd, longitude);
083        
084        System.out.println("For Phily MST: " + mst);
085        
086        // assuming a spherical Earth - calculate ECI vector
087        double [] eciVec = new double[3];
088        eciVec[2] = AstroConst.R_Earth * Math.sin( latitude*Math.PI/180.0 );
089        double r = AstroConst.R_Earth * Math.cos( latitude*Math.PI/180.0 );
090        eciVec[0] = r * Math.cos(mst*Math.PI/180.0);
091        eciVec[1] = r * Math.sin(mst*Math.PI/180.0);
092        
093        System.out.println("ECI: " + eciVec[0] + ", " + eciVec[1] + ", " + eciVec[2]);
094    }
095    
096}