[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] Problems Using the FITSIO Library with a GSL Vector
From: |
Matthew Boulton |
Subject: |
[Help-gsl] Problems Using the FITSIO Library with a GSL Vector |
Date: |
Sun, 26 Aug 2007 00:47:54 +0100 |
User-agent: |
Thunderbird 2.0.0.6 (Windows/20070728) |
Hello. I am having difficulty using a GSL vector with a function from
the FITSIO library. I have a test programme below which illustrates this
problem, with further description given further below:
#include <stdio.h>
#include <fitsio.h>
#include <gsl/gsl_vector.h>
gsl_vector *image;
int main()
{
fitsfile *data;
int sub_width = 1536;
int sub_height = 1536;
int i;
char fn[] = "image.fits";
int status = 0 , anynul;
int x1 = 1;
int x2 = sub_width;
int y1 = 1;
int y2 = sub_height;
double nulval = 0.0;
long fpixel[2] = { x1, y1 };
long lpixel[2] = { x2, y2 };
long inc[2] = { 1, 1 };
image = gsl_vector_calloc( sub_width * sub_height );
fits_open_file ( &data , fn , READONLY , &status );
fits_report_error ( stdout , status );
if ( status != 0 )
{
printf ( "Cannot Find File: %s\n" , fn );
exit (0);
}
status = 0;
for( i = 0 ; i < sub_width * sub_height ; i+=1000 ) /* Print every
1000th element */
{
printf("FITSIO_GSL_test.c: 1: sub_ref[%d] = %g\n" , i ,
gsl_vector_get( image , i ) );
}
fits_read_subset( data , TDOUBLE , fpixel , lpixel , inc , &nulval ,
image , &anynul , &status );
for( i = 0 ; i < sub_width * sub_height ; i+=1000 ) /* Print every
1000th element */
{
printf("FITSIO_GSL_test.c: 2: sub_ref[%d] = %g\n" , i ,
gsl_vector_get( image , i ) );
}
return 0;
}
Now the image I am testing this on is rather large (9MB) which can be
found at http://www.dur.ac.uk/m.p.boulton/image.fits .
Sadly I've not been able to quite replicate my original error message
with the program above, but I'm hoping that fixing the Seg Fault error
with this program will fix the same problem in my main program. All the
following applies to my main program.
Basically in my main program I have a GSL vector with all it's elements
initialised and set to zero. It is then read in by the fits_read_subset
function. As I have with other functions I assumed I would need to
change the function declaration to take this change in data type into
account so after finding that "fits_read_subset" is defined as ffgsv in
the fitsio.h file I changed:
int ffgsv(fitsfile *fptr, int datatype, long *blc, long *trc, long *inc,
void *nulval, void *array, int *anynul, int *status);
to:
int ffgsv(fitsfile *fptr, int datatype, long *blc, long *trc, long *inc,
void *nulval, gsl_vector *array, int *anynul, int *status);
where my GSL vector is the 7th argument. I only thought to make this
change because of the error I was getting. However the change had no
effect.
Now as soon as I try to read the vector elements with a FOR loop after
this function has been executed, I get the following error message:
"gsl: vector_source.c:29: ERROR: index out of range"
From what I can tell the FITSIO function is losing my GSL_vector so
when I come to read any elements (and this applies for any element as
none can be read) I get the error.
Kind Regards,
Matt
- [Help-gsl] Problems Using the FITSIO Library with a GSL Vector,
Matthew Boulton <=