38 #define MemError1( a ) do { fprintf( stderr, "MEMORY ERROR %d\n" a "\n", __LINE__ ); exit( __LINE__ ); } while ( 0 )
42 " This file is part of PLplot.\n" \
44 " PLplot is free software; you can redistribute it and/or modify\n" \
45 " it under the terms of the GNU Library General Public License as published\n" \
46 " by the Free Software Foundation; either version 2 of the License, or\n" \
47 " (at your option) any later version.\n" \
49 " PLplot is distributed in the hope that it will be useful,\n" \
50 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
51 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \
52 " GNU Library General Public License for more details.\n" \
54 " You should have received a copy of the GNU Library General Public License\n" \
55 " along with PLplot; if not, write to the Free Software\n" \
56 " Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n" \
59 " This header file contains the table containing the linear transforms \n" \
60 " for converting between TAI and UTC.\n" \
61 " It is an automatically generated file, so please do\n" \
62 " not edit it directly. Make any changes to tai-utc.dat then use\n" \
63 " tai-utc-gen to recreate this header file.\n" \
65 " tai-utc.dat contains four essential fields to represent the following\n" \
66 " formula for the linear transformation between TAI and UTC: \n" \
67 " TAI-UTC (seconds) = offset1 + (MJD-offset2)*slope\n" \
68 " There are four essential fields per line in tai-utc.dat to represent\n" \
69 " this formula. They are the Julian date (UTC) where the linear\n" \
70 " transformation implied by the line is first applied;\n" \
71 " offset1 (seconds); offset2 (days), and slope (secs/day).\n" \
80 double *offset1 = NULL;
83 double sec, *leap_sec = NULL;
86 int number_of_lines = 0;
88 if ( ( argc < 2 ) || ( fr = fopen( argv[1],
"r" ) ) == NULL )
90 fprintf( stderr,
"Cannot open first file as readable\n" );
94 if ( ( argc < 3 ) || ( fw = fopen( argv[2],
"w" ) ) == NULL )
96 fprintf( stderr,
"Cannot open second file as writable\n" );
104 while ( ( fgets( readbuffer, 255, fr ) != NULL ) )
113 if ( ( MJDstart = (
int *) calloc( (
size_t) number_of_lines, (
size_t)
sizeof (
int ) ) ) == NULL )
114 MemError1(
"Allocating memory to the MJDstart table" );
116 if ( ( offset1 = (
double *) calloc( (
size_t) number_of_lines, (
size_t)
sizeof (
double ) ) ) == NULL )
117 MemError1(
"Allocating memory to the offset1 table" );
119 if ( ( offset2 = (
int *) calloc( (
size_t) number_of_lines, (
size_t)
sizeof (
int ) ) ) == NULL )
120 MemError1(
"Allocating memory to the offset2 table" );
122 if ( ( slope = (
double *) calloc( (
size_t) number_of_lines, (
size_t)
sizeof (
double ) ) ) == NULL )
123 MemError1(
"Allocating memory to the slope table" );
125 if ( ( leap_sec = (
double *) calloc( (
size_t) number_of_lines, (
size_t)
sizeof (
double ) ) ) == NULL )
126 MemError1(
"Allocating memory to the leap_sec table" );
134 while ( ( fgets( readbuffer, 255, fr ) != NULL ) )
136 sscanf( readbuffer,
"%*s %*s %*s %*s %d.5 %*s %lf %*s %*s %*s %*s %d.) X %lf S", (
int *) &jd, (
double *) &offset1[i], (
int *) &offset2[i], (
double *) &slope[i] );
138 MJDstart[i] = jd - 2400000;
149 fprintf( fw,
"%s\n",
header );
151 fprintf( fw,
"typedef struct {\n\tint base_day;\n\tdouble time_sec_tai;\n\tdouble time_sec_utc;\n\tdouble size_prev_leap_sec;\n\tdouble offset1;\n\tint offset2;\n\tdouble slope;\n} TAI_UTC;\n\n" );
153 fprintf( fw,
"const int number_of_entries_in_tai_utc_table=%d;\n\n", number_of_lines );
155 fprintf( fw,
"const TAI_UTC TAI_UTC_lookup_table[%d] = {\n", number_of_lines );
156 for ( i = 0; i < number_of_lines; i++ )
158 sec = offset1[i] + (double) ( MJDstart[i] - offset2[i] ) * slope[i];
168 leap_sec[i] = sec - ( offset1[i - 1] + (double) ( MJDstart[i] + sec / 86400. - offset2[i - 1] ) * slope[i - 1] ) / ( 1. + slope[i - 1] / 86400. );
169 if ( fabs( leap_sec[i] ) < 1.e-14 )
171 fprintf( fw,
"{%d, %15.8f, 0., %20.14f, %15.8f, %d, %15.8f},\n", MJDstart[i], sec, leap_sec[i], offset1[i], offset2[i], slope[i] );
173 fprintf( fw,
"};\n" );
int main(int argc, char *argv[])