comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: explain THIS one
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: explain THIS one [message #58532] Mon, 04 February 2008 07:23
cmancone is currently offline  cmancone
Messages: 30
Registered: May 2007
Member
On Feb 4, 9:51 am, Spon <christoph.b...@gmail.com> wrote:
> On Feb 4, 2:31 pm, cmanc...@ufl.edu wrote:
>
>
>
>> On Feb 4, 9:29 am, cmanc...@ufl.edu wrote:
>
>>> I'm having an error in my code and I stop it to check out what is
>>> going on. Here's the three relevant lines of code:
>
>>> minmag = min(sims[mag,*],max=maxmag)
>>> nbins = (maxmag-minmag)/magbinsize
>>> magres = fltarr(3*nfilters,nbins)
>
>>> Here's some commands I type into a command line to investigate my
>>> issues:
>
>>> IDL> help,nbins
>>> NBINS FLOAT = 7.00000
>>> IDL> help,magres
>>> MAGRES FLOAT = Array[6, 6]
>
>>> Anyone see a problem here? nbins is a float of size 7.0, and yet
>>> magres ends up with 6 rows!!!! To add to the fun I then type the
>>> following:
>
>>> IDL> nbins = 7.0
>>> IDL> magres = fltarr(3*nfilters,nbins)
>>> IDL> help,magres
>>> MAGRES FLOAT = Array[6, 7]
>
>>> To summarize, my array is created with the wrong dimensions, so I re-
>>> assign one of the variables with the exact same value that it had
>>> before, recreate my array, and it works! ?????? Looks like a bug to
>>> me...
>
>> And in case anyone thinks this might be part of the problem:
>
>> IDL> help,nbins
>> NBINS FLOAT = 7.00000
>> IDL> help,nfilters
>> NFILTERS LONG = 2
>> IDL> magres = fltarr(3*nfilters,long(nbins))
>> IDL> help,magres
>> MAGRES FLOAT = Array[6, 6]
>
> help,fltarr(6,6.99)
> <Expression> FLOAT = Array[6, 6]
>
> nbins = (maxmag-minmag)/magbinsize
> If this ever returns a value just under 7.00000 it'll always be
> rounded down when it's converted . I suspect this is what's happening
> to you.
>
> To test it, you could try:
> magres = fltarr(3*nfilters,round(nbins))
>
> Does this fix your problem?
> Chris

Arrgh!! I should have seen that one coming, I've read that article
before and have even explained to others the dangers of floating-point
representation. Oh well. Thanks for the help guys!
Re: explain THIS one [message #58533 is a reply to message #58532] Mon, 04 February 2008 06:51 Go to previous message
Spon is currently offline  Spon
Messages: 178
Registered: September 2007
Senior Member
On Feb 4, 2:31 pm, cmanc...@ufl.edu wrote:
> On Feb 4, 9:29 am, cmanc...@ufl.edu wrote:
>
>
>
>> I'm having an error in my code and I stop it to check out what is
>> going on. Here's the three relevant lines of code:
>
>> minmag = min(sims[mag,*],max=maxmag)
>> nbins = (maxmag-minmag)/magbinsize
>> magres = fltarr(3*nfilters,nbins)
>
>> Here's some commands I type into a command line to investigate my
>> issues:
>
>> IDL> help,nbins
>> NBINS FLOAT = 7.00000
>> IDL> help,magres
>> MAGRES FLOAT = Array[6, 6]
>
>> Anyone see a problem here? nbins is a float of size 7.0, and yet
>> magres ends up with 6 rows!!!! To add to the fun I then type the
>> following:
>
>> IDL> nbins = 7.0
>> IDL> magres = fltarr(3*nfilters,nbins)
>> IDL> help,magres
>> MAGRES FLOAT = Array[6, 7]
>
>> To summarize, my array is created with the wrong dimensions, so I re-
>> assign one of the variables with the exact same value that it had
>> before, recreate my array, and it works! ?????? Looks like a bug to
>> me...
>
> And in case anyone thinks this might be part of the problem:
>
> IDL> help,nbins
> NBINS FLOAT = 7.00000
> IDL> help,nfilters
> NFILTERS LONG = 2
> IDL> magres = fltarr(3*nfilters,long(nbins))
> IDL> help,magres
> MAGRES FLOAT = Array[6, 6]

help,fltarr(6,6.99)
<Expression> FLOAT = Array[6, 6]

nbins = (maxmag-minmag)/magbinsize
If this ever returns a value just under 7.00000 it'll always be
rounded down when it's converted . I suspect this is what's happening
to you.

To test it, you could try:
magres = fltarr(3*nfilters,round(nbins))

Does this fix your problem?
Chris
Re: explain THIS one [message #58534 is a reply to message #58533] Mon, 04 February 2008 06:48 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
cmancone@ufl.edu writes:

> To summarize, my array is created with the wrong dimensions, so I re-
> assign one of the variables with the exact same value that it had
> before, recreate my array, and it works! ?????? Looks like a bug to
> me...

I think this article might shed some light:

http://www.dfanning.com/math_tips/sky_is_falling.html

I'm thinking a ROUND() might solve some problems here. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: explain THIS one [message #58535 is a reply to message #58534] Mon, 04 February 2008 06:31 Go to previous message
cmancone is currently offline  cmancone
Messages: 30
Registered: May 2007
Member
On Feb 4, 9:29 am, cmanc...@ufl.edu wrote:
> I'm having an error in my code and I stop it to check out what is
> going on. Here's the three relevant lines of code:
>
> minmag = min(sims[mag,*],max=maxmag)
> nbins = (maxmag-minmag)/magbinsize
> magres = fltarr(3*nfilters,nbins)
>
> Here's some commands I type into a command line to investigate my
> issues:
>
> IDL> help,nbins
> NBINS FLOAT = 7.00000
> IDL> help,magres
> MAGRES FLOAT = Array[6, 6]
>
> Anyone see a problem here? nbins is a float of size 7.0, and yet
> magres ends up with 6 rows!!!! To add to the fun I then type the
> following:
>
> IDL> nbins = 7.0
> IDL> magres = fltarr(3*nfilters,nbins)
> IDL> help,magres
> MAGRES FLOAT = Array[6, 7]
>
> To summarize, my array is created with the wrong dimensions, so I re-
> assign one of the variables with the exact same value that it had
> before, recreate my array, and it works! ?????? Looks like a bug to
> me...

And in case anyone thinks this might be part of the problem:

IDL> help,nbins
NBINS FLOAT = 7.00000
IDL> help,nfilters
NFILTERS LONG = 2
IDL> magres = fltarr(3*nfilters,long(nbins))
IDL> help,magres
MAGRES FLOAT = Array[6, 6]
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: explain THIS one
Next Topic: How to perform the 1-D signal filter?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:15:31 PDT 2025

Total time taken to generate the page: 0.00584 seconds