- publishing free software manuals
GNU Scientific Library Reference Manual - Third Edition (v1.12)
by M. Galassi, J. Davies, J. Theiler, B. Gough, G. Jungman, P. Alken, M. Booth, F. Rossi
Paperback (6"x9"), 592 pages, 60 figures
ISBN 0954612078
RRP £24.95 ($39.95)

Get a printed copy>>>

3.5 Examples

Here is an example of some code which checks the return value of a function where an error might be reported,

#include <stdio.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_fft_complex.h>

  int status;
  size_t n = 37;


  status = gsl_fft_complex_radix2_forward (data, stride, n);

  if (status) {
    if (status == GSL_EINVAL) {
       fprintf (stderr, "invalid argument, n=%d\n", n);
    } else {
       fprintf (stderr, "failed, gsl_errno=%d\n", 
    exit (-1);

The function gsl_fft_complex_radix2 only accepts integer lengths which are a power of two. If the variable n is not a power of two then the call to the library function will return GSL_EINVAL, indicating that the length argument is invalid. The function call to gsl_set_error_handler_off stops the default error handler from aborting the program. The else clause catches any other possible errors.

ISBN 0954612078GNU Scientific Library Reference Manual - Third Edition (v1.12)See the print edition