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" );