00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <math.h>
00034 int dspline( double *x, double *y, int n,
00035 int if1, double cond1, int ifn, double condn, double *y2 );
00036
00037
00038
00039
00040
00041
00042 #define MemError1( a ) do { fprintf( stderr, "MEMORY ERROR %d\n" a "\n", __LINE__ ); exit( __LINE__ ); } while ( 0 )
00043
00044 const char header[] = "" \
00045 "/*\n" \
00046 " This file is part of PLplot.\n" \
00047 " \n" \
00048 " PLplot is free software; you can redistribute it and/or modify\n" \
00049 " it under the terms of the GNU Library General Public License as published\n" \
00050 " by the Free Software Foundation; either version 2 of the License, or\n" \
00051 " (at your option) any later version.\n" \
00052 " \n" \
00053 " PLplot is distributed in the hope that it will be useful,\n" \
00054 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
00055 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \
00056 " GNU Library General Public License for more details.\n" \
00057 " \n" \
00058 " You should have received a copy of the GNU Library General Public License\n" \
00059 " along with PLplot; if not, write to the Free Software\n" \
00060 " Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n" \
00061 " \n" \
00062 " \n" \
00063 " This header file contains spline data (xspline, yspline, and y2spline)\n" \
00064 " for converting between UT1 and ephemeris time.\n" \
00065 " It is an automatically generated file, so please do\n" \
00066 " not edit it directly. Make any changes to deltaT.dat then use\n" \
00067 " deltaT-gen to recreate this header file.\n" \
00068 " \n" \
00069 "*/";
00070
00071 int main( int argc, char *argv[] )
00072 {
00073 FILE *fr, *fw;
00074 char readbuffer[256];
00075 double *xspline = NULL;
00076 double *yspline = NULL;
00077 double *y2spline = NULL;
00078 int i = 0;
00079 int number_of_lines = 0;
00080
00081 if ( ( fr = fopen( argv[1], "r" ) ) == NULL )
00082 {
00083 fprintf( stderr, "Cannot open first file as readable\n" );
00084 exit( 1 );
00085 }
00086
00087 if ( ( fw = fopen( argv[2], "w" ) ) == NULL )
00088 {
00089 fprintf( stderr, "Cannot open second file as writable\n" );
00090 exit( 1 );
00091 }
00092
00093
00094
00095
00096
00097 while ( ( fgets( readbuffer, 255, fr ) != NULL ) )
00098 {
00099 ++number_of_lines;
00100 }
00101
00102
00103
00104
00105
00106 if ( ( xspline = (double *) calloc( number_of_lines, (size_t) sizeof ( double ) ) ) == NULL )
00107 MemError1( "Allocating memory to the xspline table" );
00108
00109 if ( ( yspline = (double *) calloc( number_of_lines, (size_t) sizeof ( double ) ) ) == NULL )
00110 MemError1( "Allocating memory to the yspline table" );
00111
00112 if ( ( y2spline = (double *) calloc( number_of_lines, (size_t) sizeof ( double ) ) ) == NULL )
00113 MemError1( "Allocating memory to the y2spline table" );
00114
00115 rewind( fr );
00116
00117
00118
00119
00120
00121 while ( ( fgets( readbuffer, 255, fr ) != NULL ) )
00122 {
00123 sscanf( readbuffer, "%lf %lf", (double *) &xspline[i], (double *) &yspline[i] );
00124 i++;
00125 }
00126
00127 fclose( fr );
00128
00129
00130
00131
00132 dspline( xspline, yspline, number_of_lines, 2, 6.4e-3, 2, 6.4e-3, y2spline );
00133
00134
00135
00136
00137
00138
00139 fprintf( fw, "%s\n", header );
00140
00141 fprintf( fw, "const int number_of_entries_in_spline_tables=%d;\n\n", number_of_lines );
00142
00143 fprintf( fw, "const double xspline[%d] = {\n", number_of_lines );
00144 for ( i = 0; i < number_of_lines; i++ )
00145 {
00146 fprintf( fw, "%10.0f,\n", xspline[i] );
00147 }
00148 fprintf( fw, "};\n" );
00149
00150 fprintf( fw, "const double yspline[%d] = {\n", number_of_lines );
00151 for ( i = 0; i < number_of_lines; i++ )
00152 {
00153 fprintf( fw, "%10.0f,\n", yspline[i] );
00154 }
00155 fprintf( fw, "};\n" );
00156
00157 fprintf( fw, "const double y2spline[%d] = {\n", number_of_lines );
00158 for ( i = 0; i < number_of_lines; i++ )
00159 {
00160 fprintf( fw, "%25.15e,\n", y2spline[i] );
00161 }
00162 fprintf( fw, "};\n" );
00163
00164 fclose( fw );
00165 free( xspline );
00166 free( yspline );
00167 free( y2spline );
00168
00169 return ( 0 );
00170 }
00171