/** Header for mopsephem library

$Id: mopsod.h 1784 2007-08-15 19:25:34Z fpierfed $
*/

#ifndef __MOPSOD__
#define __MOPSOD__

#ifdef __cplusplus
extern "C" {
#endif

enum {
    EMOPSODBADINPUT = 100,          ///< bad orbital input params (general)
    EMOPSODNOMEM,                   ///< out of memory
    EMOPSODJPL = 200,               ///< 200+ == failure in JPL OD lib
};


// Really should use miti.h MITI_MAX_ID here
//#define ORBIT_ID_LEN 39             ///< max len of an orbit ID string
#define ORBIT_ID_LEN 99             ///< max len of an orbit ID string
#define ORBIT_OBSCODE_LEN 9
#define NUM_COVARIANCE 21           ///< num elements in UT covariance matrix


typedef struct {
    char id[ORBIT_ID_LEN + 1];
    double epoch_mjd;
    double ra_deg;
    double dec_deg;
    double mag;
    char obscode[ORBIT_OBSCODE_LEN + 1];
    double ra_sigma_arcsec;
    double dec_sigma_arcsec;
    double mag_sigma;
} OBSERVATION_STRUCT;


///< Struct to hold input IOD orbital parameters.
typedef struct {
    double q_au;            ///< perihelion distance
    double e;               ///< eccentricity
    double i_deg;           ///< inclination
    double node_deg;        ///< node of ascending longitude
    double arg_peri_deg;    ///< argument of perihelion
    double time_peri_mjd;   ///< time of perihelion
    double h_v;             ///< absolute magnitude
    double t_epoch_mjd;     ///< epoch of orbital elements

    char id[ORBIT_ID_LEN + 1];      ///< generic ID

    int cov_valid;          ///< 0 => covariance invalid, 1 => valid
    double covariance[21];  ///< square root covariance matrix

    // Statistics
    int ccode;                      ///< generic convergence code for IOD or DC
    double residual_arcseconds;     ///< residual of fitted orbit
    double arc_length_days;
} ORBIT_BLK;


///< Struct to hold input observations.
typedef struct {
    OBSERVATION_STRUCT *obs;    ///< pointer to observation data
    int nobs;                   ///< number of obs
} OBSERVATION_BLK;


///< Initialize JPL stuff.
int mopsod_init(void);

///< Differentially correct an IOD.
int mopsod_diffcor(
    ORBIT_BLK *iod,         ///< input IOD
    OBSERVATION_BLK *obs,   ///< input observations
    ORBIT_BLK *orbit        ///< output orbit
);

#ifdef __cplusplus
}
#endif

#endif
