help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Comparing GSL Vector Elements with Double Precision Value


From: Matthew Boulton
Subject: Re: [Help-gsl] Comparing GSL Vector Elements with Double Precision Values
Date: Sat, 25 Aug 2007 23:44:51 +0100
User-agent: Thunderbird 2.0.0.6 (Windows/20070728)

Thanks for the reply.

A bit of inexperience on my part showing through there. Having now introduced gsl_vector_get/set whenever I'm working with the GSL vectors, I'm now left with a problem concerning the FITSIO library when used with GSL vectors.

Basically I now 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 given below.

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.

I am in the process of producing a test programme which I shall post up in a separate thread shortly. However if you have any ideas given the information I've been able to give above then please don't hesitate to get back to me.

Kind Regards,

Matt


John Gehman wrote:
Hello Matt,

I didn't think gsl_vectors could be indexed like usual dynamically allocated vectors, i.e. by [index]. You need gsl_vector_get( gsl_vector, index). But I might have guessed that the errors would have more to do with that than the operators. Insofar as your code goes (I guess there's nested loops over i and j which aren't shown), all vector values are zero by using gsl_vector_calloc. Unless you do some kind of conversion of your data into gsl vectors, you'll also want to use gsl_vector_set for to set individual elements.

Cheers,
john



On 26/08/2007, at 1:38 AM, Matthew Boulton wrote:

Hello. I'm having difficult making comparisons between the elements in my GSL vectors and some double precision values in my programmes. I've produced a test programme below which illustrates the problem I am having:

#include <stdio.h>

#include <gsl/gsl_vector.h>

gsl_vector *sub_ref;
gsl_vector *sub_image;

int main()

{

 int i,j;
 int sub_width = 1536;
 int sub_height = 1536;
 int width = 10000;

 double PIX_MIN = 100.0, SATURATION = 59000.0;

 sub_ref = gsl_vector_calloc( sub_width * sub_height );
 sub_image = gsl_vector_calloc( sub_width * sub_height );

if ( sub_image[ i + width * j ] < PIX_MIN || sub_ref[ i + width * j ] < PIX_MIN )
 {
     printf("IF 1 executed\n");

 }
if (sub_image[ i + width * j ] >= SATURATION || sub_ref[ i + width * j ] >= SATURATION )
 {
     printf("IF 2 executed\n");

 }

 return 0;

}

The GSL vectors are being declared as double precision, yet I am getting the following errors:

PIX_MIN_test.c: In function 'main':
PIX_MIN_test.c:22: error: invalid operands to binary <
PIX_MIN_test.c:22: error: invalid operands to binary <
PIX_MIN_test.c:30: error: invalid operands to binary >=
PIX_MIN_test.c:30: error: invalid operands to binary >=

Can anyone advise me on what I'm doing wrong?

Kind Regards,

Matt

_______________________________________________
Help-gsl mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-gsl


---------------------------------------------------------

Dr John Gehman (address@hidden)
Research Fellow; Separovic Lab
School of Chemistry
University of Melbourne (Australia)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]