/*  
 *  - - - - - - - - - - - 
 *   g a l _ s g p 4 r s  
 *  - - - - - - - - - - -
 *  
 *  This routine is part of the General Astrodynamics Library  
 *
 *  Description:
 *
 *     This routine computes the rise and set parameters
 *     for an Earth orbiting spacecraft and terrestrial
 *     observer using the Ernandes algorithm and the SGP4 propagtor
 *  
 *  Status: 
 *  
 *     Support routine  
 *  
 *  Given:  
 *
 *     utc1             d           UTC date part 1 ( see Note 1 )
 *     utc2             d           UTC date part 2 ( see Note 1 )
 *     latitude         d           Observer latitude ( radians )
 *     longitude        d           Observer longitude ( radians )
 *     height           d           Observer height ASL ( meters )
 *     minel            d           Minimum elevation ( radians )
 *     timefwd          d           Max time forward ( days )
 *     gm               d           Gravitational parameter
 *     re               d           Earth equatorial radius ( meters )
 *     inf              d           Earth inverse flattening factor
 *     *sgp4        gal_sgp4_t      Initialised SGP4 structure
 *  
 *  Returned:  
 *  
 *     pass           d[3][3]       AOS, CUL, & LOS details ( see Note 2 ) 
 *     gal_sgp4rs       i           Status
 *                                   0 = success
 *                                  -1 = satellite never sets
 *
 *  Notes:
 *
 *  1) The epoch epoch1+epoch2 is a Julian Date, apportioned in  
 *     any convenient way between the two arguments.  For example,  
 *     JD(UTC)=2450123.7 could be expressed in any of these ways,  
 *     among others:  
 *  
 *            epoch1       epoch2  
 *  
 *         2450123.7          0.0        (JD method)  
 *         2451545.0      -1421.3        (J2000 method)  
 *         2400000.5      50123.2        (MJD method)  
 *         2450123.5          0.2        (date & time method)  
 *  
 *     The JD method is the most natural and convenient to use in  
 *     cases where the loss of several decimal digits of resolution  
 *     is acceptable.  The J2000 method is best matched to the way  
 *     the argument is handled internally and will deliver the  
 *     optimum resolution.  The MJD method and the date & time methods  
 *     are both good compromises between resolution and convenience.  
 *     However, the accuracy of the result is more likely to be  
 *     limited by the algorithm itself than the way the epoch has been  
 *     expressed. 
 *
 *  2) The rise and set parameters are the time, elevation, and azimuth
 *     for Aquisition of Signal (AOS), Loss of Signal (LOS), and 
 *     Culmination (maximum elevation). On return the array pass 
 *     is populated as follows:
 *
 *         pass[0][0] - AOS JD ( UTC ) date+time
 *         pass[0][1] - AOS Elevation ( radians )
 *         pass[0][2] - AOS Azimuth   ( radians )
 *         pass[1][0] - CUL JD ( UTC ) date+time
 *         pass[1][1] - CUL Elevation ( radians )
 *         pass[1][2] - CUL Azimuth   ( radians )
 *         pass[2][0] - LOS JD ( UTC ) date+time
 *         pass[2][1] - LOS Elevation ( radians )
 *         pass[2][2] - LOS Azimuth   ( radians )
 *
 *  3) This routine is based upon the rise/set algorithm devised
 *     and developed by Ernandes. 
 *  
 *  Called:
 *
 *     gal_anp          Normalise angle into the range 0 <= a < 2pi
 *     gal_anpm         Normalise angle into the range -pi <= a < pi
 *     gal_sgp4         SGP4 propagator
 *     gal_gmst82       Greenwich Mean Sidereal Time IAU 1982
 *     gal_pm           p-vector modulus
 *     gal_pn           p-vector modulus and normalise
 *     gal_rxp          r-matrix, p-vector product
 *     gal_pmp          p-vector subtraction
 *     gal_pdp          p-vector dot product
 *     gal_latlon2t     latitude & longitude to ITRF
 *     gal_pvm          pv-vector modulus 
 *     gal_me2bf        Transform from mean equator to body fixed frame 
 *     gal_sezm         Form SEZ transformation matrix
 *  
 *  References:
 *
 *     Kenneth J. Ernandes, private communication, December 17, 1997
 *
 *  This revision:  
 * 
 *     2009 January 9 
 *  
 *  Copyright (C) 2009 Paul C. L. Willmott. See notes at end. 
 *  
 *-----------------------------------------------------------------------  
 */  

#ifndef _GAL_SGP4RS_H_  
#define _GAL_SGP4RS_H_ 1  

#include "gal_sgp4t.h"
  
#undef  __BEGIN_DECLS  
#undef  __END_DECLS  
#ifdef  __cplusplus  
#define __BEGIN_DECLS extern "C" {  
#define __END_DECLS }  
#else  
#define __BEGIN_DECLS /* empty */  
#define __END_DECLS   /* empty */  
#endif
  
__BEGIN_DECLS  

int
gal_sgp4rs
  (
    double utc1,
    double utc2,
    double latitude,
    double longitude,
    double height,
    double minel,
    double timefwd,
    double gm,
    double re,
    double inf,
    gal_sgp4_t *sgp4,
    double pass[3][3] 
  ) ;
 
__END_DECLS  
  
#endif /* !_GAL_SGP4RS_H_ */ 

/*
 *  gal - General Astrodynamics Library  
 *  Copyright (C) 2009 Paul C. L. Willmott  
 *  
 *  This program is free software; you can redistribute it and/or modify  
 *  it under the terms of the GNU General Public License as published by  
 *  the Free Software Foundation; either version 2 of the License, or  
 *  (at your option) any later version.  
 *  
 *  This program is distributed in the hope that it will be useful,  
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of  
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
 *  GNU General Public License for more details.  
 *  
 *  You should have received a copy of the GNU General Public License along  
 *  with this program; if not, write to the Free Software Foundation, Inc.,  
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.  
 *    
 *  Contact:  
 *    
 *  Paul Willmott  
 *  vp9mu@amsat.org  
 */  
  
