Next: Library Routines, Previous: Introduction, Up: Top
#include <stdio.h> #include <stdlib.h> #include <bsplineval.h> #include <spline_coef.h> /* This program illustrates the sequences of calls to make to evaluate a spline. */ int use_selected_Bspline_evaluator( BsplineInput* bspline_input ) { double tt = 3.14, zz = 0.0; BsplineResult result; /* Algorithm B then Algorithm A will be used in the call to Algorithm C */ bspline_input->method1 = 'b'; bspline_input->method2 = 'a'; if ( Bspline_Success != BsplineAlgo_c_derivs( tt, zz, bspline_input, &result ) ) { fprintf( stderr, "BsplineAlgo_c_derivs returned with an error t=%.14f, " "z=%.14f\n", tt, zz ); return EXIT_FAILURE; } return EXIT_SUCCESS; } /* This is the recommended used of the call to the library */ int use_optimized_Bspline( BsplineInput* bspline_input ) { double tt = 3.14, zz = 0.0; BsplineResult result; if ( Bspline_Success != Bspline_eval_derivs( tt, zz, bspline_input, &result ) ) { fprintf( stderr, "Bspline_eval_derivs returned with an error t=%.14f, " "z=%.14f\n", tt, zz ); return EXIT_FAILURE; } return EXIT_SUCCESS; } int main( int argc, char** argv ) { /* Common c; */ BsplineInput* bspline_input = NULL; /* * The user is responsible for supplying the information necessary to * evaluate the B-spline: the knots in theta and z, the order of knots etc.. * This structure must be filled in by the user before making any more calls * to the library. */ spline_coef scoef; /* * It is the user's responsibilty to read in the Bspline coefficients. * read_spline_data_( c->input, &input_unit, &c->rms_amplitude ); */ /* Allocate the memory used by the library */ bspline_input = (BsplineInput*) Bspline_init( &scoef ); if ( NULL == bspline_input ) { fprintf( stderr, "process( ) : Unable to allocate memory for eval_spline\n" ); return EXIT_FAILURE; } /* This is the recommended used of the call to the library */ if ( EXIT_FAILURE == use_optimized_Bspline( bspline_input ) ) { Bspline_free( bspline_input ); return EXIT_FAILURE; } /* If the user insists on using one of the slow routines */ if ( EXIT_FAILURE == use_selected_Bspline_evaluator( bspline_input ) ) { Bspline_free( bspline_input ); return EXIT_FAILURE; } /* Must free memory which was allocated in the call to Bspline_init */ Bspline_free( bspline_input ); return EXIT_SUCCESS; }