test-002.c 4.84 KB
Newer Older
Jeroen Vreeken's avatar
Jeroen Vreeken committed
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
    Gpredict: Real-time satellite tracking and orbit prediction program

    Copyright (C)  2001-2008  Alexandru Csete.

    Authors: Alexandru Csete <csete@users.sourceforge.net>

    Comments, questions and bugreports should be submitted via
    http://sourceforge.net/projects/gpredict/
    More details can be found at the project home page:

            http://gpredict.oz9aec.net/
 
    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.,
      59 Temple Place, Suite 330,
      Boston, MA  02111-1307
      USA
*/
/** \defgroup test001 Unit test for SGP4
 *  \ingroup tests
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "sgp4sdp4.h"

#define TEST_STEPS 5

/* structure to hold a set of data */
typedef struct {
    double t;
    double x;
    double y;
    double z;
    double vx;
    double vy;
    double vz;
} dataset_t;


const dataset_t expected[TEST_STEPS] = {
    { 0.0,
      7473.37066650, 428.95261765, 5828.74786377,
      5.1071513, 6.44468284, -0.18613096 },
    { 360.0,
      -3305.22537232, 32410.86328125, -24697.17675781,
      -1.30113538, -1.15131518, -0.28333528 },
    { 720.0,
      14271.28759766, 24110.46411133, -4725.76837158,
      -0.32050445, 2.67984074, -2.08405289 },
    { 1080.0,
      -9990.05883789, 22717.35522461, -23616.890662501,
      -1.01667246, -2.29026759, 0.72892364 },
    { 1440.0,
      9787.86975097, 33753.34667969, -15030.81176758,
      -1.09425966, 0.92358845, -1.52230928}
};


char   tle_str[3][80];
sat_t  sat;

int
main (int argc, char **argv)
{
    FILE *fp;
    int i;
    char *tle_ptrs[3];
    
    tle_ptrs[0] = tle_str[0];
    tle_ptrs[1] = tle_str[1];
    tle_ptrs[2] = tle_str[2];

    /* read tle file */
    fp = fopen ("test-002.tle", "r");
    if (fp != NULL) {
 
        fgets (tle_str[0], 80, fp);
        fgets (tle_str[1], 80, fp);
        fgets (tle_str[2], 80, fp);
        fclose (fp);

        if (Get_Next_Tle_Set (tle_ptrs, &sat.tle) == 1) {
            printf ("TEST DATA:\n");
        }
        else {
            printf("Could not read TLE data 2\n");
            return 1;
        }
    }
    else {
        printf("Could not open test-001.tle\n");
        return 1;
    }
    
    printf ("%s", tle_str[0]);
    printf ("%s", tle_str[1]);
    printf ("%s", tle_str[2]);

    select_ephemeris (&sat);

    printf ("\nDEEP_SPACE_EPHEM: %d (expected %d)\n\n",
        (sat.flags & DEEP_SPACE_EPHEM_FLAG), DEEP_SPACE_EPHEM_FLAG);


    printf ("                          RESULT            EXPECTED            DELTA\n");
    printf ("---------------------------------------------------------------------------------\n");

    for (i = 0; i < TEST_STEPS; i++) {
    
        SDP4 (&sat, expected[i].t);
        Convert_Sat_State (&sat.pos, &sat.vel);

        printf ("STEP %d  t: %6.1f  X: %15.8f   %15.8f   %.8f (%.5f%%)\n",
            i+1, expected[i].t, sat.pos.x, expected[i].x,
            fabs (sat.pos.x - expected[i].x),
            100.0 * fabs (sat.pos.x - expected[i].x) / fabs (expected[i].x));
        printf ("                   Y: %15.8f   %15.8f   %.8f (%.5f%%)\n",
            sat.pos.y, expected[i].y,
            fabs (sat.pos.y - expected[i].y),
            100.0 * fabs (sat.pos.y - expected[i].y) / fabs (expected[i].y));
        printf ("                   Z: %15.8f   %15.8f   %.8f (%.5f%%)\n",
            sat.pos.z, expected[i].z,
            fabs (sat.pos.z - expected[i].z),
            100.0 * fabs (sat.pos.z - expected[i].z) / fabs (expected[i].z));
        printf ("                  VX: %15.8f   %15.8f   %.8f (%.5f%%)\n",
            sat.vel.x, expected[i].vx,
            fabs (sat.vel.x - expected[i].vx),
            100.0 * fabs (sat.vel.x - expected[i].vx) / fabs (expected[i].vx));
        printf ("                  VY: %15.8f   %15.8f   %.8f (%.5f%%)\n",
            sat.vel.y, expected[i].vy,
            fabs (sat.vel.y - expected[i].vy),
            100.0 * fabs (sat.vel.y - expected[i].vy) / fabs (expected[i].vy));
        printf ("                  VZ: %15.8f   %15.8f   %.8f (%.5f%%)\n",
            sat.vel.z, expected[i].vz,
            fabs (sat.vel.z - expected[i].vz),
            100.0 * fabs (sat.vel.z - expected[i].vz) / fabs (expected[i].vz));

    }

    return 0;
}