aboutsummaryrefslogtreecommitdiff
path: root/src/libcf/set_orbit_parms.c
blob: 65baca68aaddebe3e50c98d75102719da6c4fecc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*****************************************************************************
 *	      Johns Hopkins University
 *	      Center For Astrophysical Sciences
 *	      FUSE
 *****************************************************************************
 *
 * Synopsis:	SGP4 set_orbit_parms(fitsfile *infits)
 *
 * Description: Initialized the sgp4 structure and reads the orbital 
 *              paramaters from the infits header and places the data 
 *              in the sgp4 structure.  It also calculates a number of
 *              time invariant quantities in the sgp4 structure.
 *
 * Arguments:	fitsfile   *infits        Input FITS file.
 *
 * Return:      SGP4       sgp4	          Structure with orb parms.
 *
 * History:	07/07/99	emurphy	 Begin and finished work
 *              07/14/99        emurphy  Fixed minor bugs
 *              07/21/99        peb      Changed function to return SGP4
 *                                       pointer. (This fixes a bug.)
 *              08/05/99        emurphy  Converted to use set_orbit_parms_calc
 *                                       so that FES pipeline can use these 
 *                                       routines.
 *              12/18/03        bjg      Change calfusettag.h to calfuse.h
 *              04/07/07  1.4	wvd	 Delete CF_PRGM_ID and CF_VER_NUM, 
 *					 as they are not used.
 *
 ****************************************************************************/

#include <stdio.h>
#include "calfuse.h"
#include "sgp4.h"

SGP4 set_orbit_parms_calc(fitsfile *infits)
{
    int    status=0;
    char   comment[FLEN_CARD];
    double epchtime, td, tf, inclinat, eccentry, meananom, argperig, rascascn;
    double n0dt, n0dt2, bstar, mean_motion;
    SGP4   sgp4;
             
    /*  Get the orbital data from the header of the infits file. */
    FITS_read_key(infits, TDOUBLE, "EPCHTIMD", &td, comment, &status);
    FITS_read_key(infits, TDOUBLE, "EPCHTIMF", &tf, comment, &status);
    epchtime=td+tf;    
    FITS_read_key(infits, TDOUBLE, "INCLINAT", &inclinat, comment, &status);
    FITS_read_key(infits, TDOUBLE, "ECCENTRY", &eccentry, comment, &status);
    FITS_read_key(infits, TDOUBLE, "MEANANOM", &meananom, comment, &status);
    FITS_read_key(infits, TDOUBLE, "ARGPERIG", &argperig, comment, &status);
    FITS_read_key(infits, TDOUBLE, "RASCASCN", &rascascn, comment, &status);
    FITS_read_key(infits, TDOUBLE, "FDM2COEF", &n0dt, comment, &status);
    FITS_read_key(infits, TDOUBLE, "SDM6COEF", &n0dt2, comment, &status);
    FITS_read_key(infits, TDOUBLE, "DRAGCOEF", &bstar, comment, &status);
    FITS_read_key(infits, TDOUBLE, "MEANMOTN", &mean_motion, comment, &status);

    sgp4 = SGP4_create();

    SGP4_set(sgp4, epchtime, n0dt, n0dt2,  bstar, inclinat,
	     rascascn, eccentry, argperig, meananom, mean_motion);

    /* do time invariant initializations */
    SGP4_init(sgp4);
    return sgp4;
}

SGP4 set_orbit_parms(fitsfile *infits)
{
    int    status=0, hdunum=0, hdutype;
    SGP4   sgp4;
    /*
     *  The infits file pointer may be down in one of the extensions
     *  whereas the orbital info is in the primary hdu.  Therefore,
     *  record the current position, move to the primary header, 
     *  set the orbital data, and return to the previous hdu.
     */
    FITS_get_hdu_num(infits, &hdunum);
    FITS_movabs_hdu(infits, 1, &hdutype, &status);

    sgp4=set_orbit_parms_calc(infits);

    FITS_movabs_hdu(infits, hdunum, &hdutype, &status);

    return sgp4;

}