/
eop_proc.c
142 lines (123 loc) · 5.48 KB
/
eop_proc.c
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
/* Copyright (C) 2018, Project Pluto
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. */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
/* Code to translate the EOP (Earth Orientation Parameter) file
'finals.all', provided at
ftp://maia.usno.navy.mil/ser7/finals.all
into a form that is considerably easier to use, in the file
'all_eops.txt'.
First problem this fixes : 'finals.all' gives you UT1-UTC, when one
would really like to have TDT-UT1 = Delta-T. This code corrects for
the leap seconds, noting them as instances where UT1-UTC makes a
sudden jump.
'finals.all' gives you IERS values for all five parameters from
Bulletin A, right up to within a couple of weeks of the time the file
was made. Then it switches over to predictions for the nutation
parameters Psi and dEps (i.e., you get a 'P' in column 96).
After that, the next couple of weeks (leading up to roughly the day
the file was made) still give IERS data for polar motion and Delta-T.
But then, predictions are used for the remaining three values as well
(i.e., columns 17 and 58 also switch from 'I' to 'P').
You then get about 70 days with predictions for all five EOPs. After
that, dPsi and dEps get blanked.
Predictions then continue for about ten months for the remaining three
values, after which you get nada.
So we keep track of 'n_iersl' (number of lines where all five values
came from IERS); 'n_part_iers' (number of lines where the first three
values are IERS); 'n_predicts' (number of lines for which predictions
are given for all five values); and 'n_part_predicts' (number of lines
where you get predictions for the first three values, but not necessarily
anything else).
There's a squirrelly thing in that the data up through late 1980 has
'predicts' for the nutation values. I think this just means they don't
have data, and are computing estimated values going backward. Since
those values aren't changing anyway, I'm treating them as IERS. */
int main( const int argc, const char **argv)
{
const char *output_filename = "all_eops.txt";
const char *input_filename = "finals.all";
FILE *ifile, *ofile;
char buff[200];
int starting_mjd = 0, stepsize = 1, i;
int n_iers = 0, n_part_iers = 0, n_predicts = 0, n_part_predicts = 0;
double tdt_minus_utc = 44.184;
double prev_ut1_minus_utc = 0.808;
const char *header_line = " PM-x (arcsec) PM-y TDT-UT1 dPsi (mas) dEps\n";
for( i = 1; i < argc; i++)
if( argv[i][0] == '-')
switch( argv[i][1])
{
case 'i':
input_filename = argv[i] + 2;
break;
case 'o':
output_filename = argv[i] + 2;
break;
case 's':
stepsize = atoi( argv[i] + 2);
break;
default:
printf( "Command-line option '%s' unrecognized\n", argv[i]);
return( -1);
}
ifile = fopen( input_filename, "rb");
assert( ifile);
ofile = fopen( output_filename, "wb");
assert( ofile);
/* Header is 70 bytes. Write garbage; we'll come back and */
/* write the 'correct' header when we're done. */
fwrite( buff, 70, 1, ofile);
fprintf( ofile, "%s", header_line);
for( i = 0; fgets( buff, sizeof( buff), ifile) && buff[16] != ' '; i++)
if( !(i % stepsize))
{
const double ut1_minus_utc = atof( buff + 58);
if( !i)
starting_mjd = atoi( buff + 7);
if( prev_ut1_minus_utc - ut1_minus_utc < -0.5)
tdt_minus_utc += 1.; /* leap second happened here */
prev_ut1_minus_utc = ut1_minus_utc;
fprintf( ofile, "%.9s %.9s %10.7f %.8s %.8s\n",
buff + 18, buff + 37, /* polar motion x & y */
tdt_minus_utc - ut1_minus_utc, /* Delta-T = TDT-UT1 */
buff + 98, buff + 117);
if( buff[95] == 'I' || i < 2900)
n_iers++;
if( buff[16] == 'I')
n_part_iers++;
if( buff[95] != ' ')
n_predicts++;
n_part_predicts++;
}
fprintf( ofile, "%s", header_line);
fprintf( ofile, "Above was derived from\n"
"ftp://maia.usno.navy.mil/ser7/finals.all\n"
"with only the five Bulletin A earth orientation parameters\n"
"extracted (no sigmas, BullB, etc.)\n"
"Run with 'eop_proc' version " __DATE__ " " __TIME__ "\n");
/* Now go back and write out a correct header : */
fseek( ofile, 0L, SEEK_SET);
fprintf( ofile, "See bottom of file for description\n");
fprintf( ofile, "%5d %5d %5d %5d %5d %5d\n",
starting_mjd, stepsize,
starting_mjd + stepsize * n_iers,
starting_mjd + stepsize * n_part_iers,
starting_mjd + stepsize * n_predicts,
starting_mjd + stepsize * n_part_predicts);
fclose( ofile);
return( 0);
}