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

Home » Public Forums » archive » Re: Subtracting a single variable from an array
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Subtracting a single variable from an array [message #71643 is a reply to message #71639] Wed, 07 July 2010 10:50 Go to previous messageGo to previous message
Brian Daniel is currently offline  Brian Daniel
Messages: 80
Registered: July 2009
Member
On Jul 7, 1:04 pm, polystethylene <polystethyl...@hotmail.com> wrote:
> Hello all,
>
> I'm faced with one of those problems that seems so absurdly simple
> that I have no angle of attack in terms of investigating the blighter;
> it's such a simple thing and yet it's falling over, and I can't for
> the life of me see why.
>
> Here's what's going on:
>
> I'm creating a sin wave out a time array, where the argument is (t-
> t0), where t0 is the first entry of the array.
>
>       tlist   =  input[0,*,a]
>       tfirst  = input[0,0,a]
>       targ  = (tlist - tfirst)
>
>       injectlc = medianflux +
> (lcamp[i]*medianflux)*(sin(lcomega*(targ) + lcphase[i]))
>
> The actual line putting the sine wave together doesn't matter, I put
> it there for completion's sake.
>
> Printing the array gives me:
>
> IDL> print,input[0,*,a]
>        5158.3722
>        5158.3731
>        5158.3740
> etc...
>
> as I'd expect.
>
> Printing tfirst gives me:
>
> IDL> print,tfirst
>        5158.3722
>
> So all is well.
>
> However, if I print:
>
> IDL> print,(input[0,*,a]-tfirst)
>        0.0000000
>
> What's the deal here?
>
> If I print:
> IDL> print,(input[0,*,a]-5158.3722)
>    0.00013553243
>     0.0010267878
>     0.0019064685
>     0.0027861492
>     0.0036774046
> etc...
>
> It works. So how come I can subtract the value by typing it out
> explicitly, but can't type the variable containing the same info?
>
> The array is a double array, and consequently tfirst is a double. I
> presume subtracting the value by typing it means I'm subtracting a
> float instead of a double, but why would that matter? Even if
> consistency was an issue, shouldn't it be subtracting the double that
> works, not the float?
>
> IDL> help,(input[0,*,a])
> <Expression>    DOUBLE    = Array[1, 359]
>
> IDL> help,tfirst
> TFIRST          DOUBLE    = Array[1]
>
> I also tried REFORMing the array to cut out the excess extra dimension
> before subtracting tfirst, but no luck.
>
> I swear I've spent the vast majority of my brief IDL career doing
> subtractions from arrays in much the same way, so what's wrong here?
>
> Advanced thanks to the person who spots my stupid mistake, puts the
> dunce cap on me and sends me to the corner.

We've all been there. In fact, I've had this very same problem
several times.

TFIRST is an array currently. When you're subtracting, IDL thinks
you're doing element by element subtraction. Use [0] on your TFIRST
definition or your subtraction call to make it scalar.

Quick example of your current problem:
IDL> input=[[5158.3722d],[5158.3731d],[5158.3740d]]
IDL> tfirst=[input[0,a]]
IDL> targ=input[0,*]-tfirst
IDL> print,targ
0.0000000
IDL> help,tfirst
TFIRST DOUBLE = Array[1]

Note that I used [] to make my TFIRST match your TFIRST. (Is that a
discrepancy between IDL Versions? I'm using IDL 7.1.)

One solution is in the subtraction call:

IDL> targ=input[0,*]-tfirst[0]
IDL> print,targ
0.0000000
0.00090000000
0.0018000000
IDL> IDL> help,tfirst
TFIRST DOUBLE = Array[1]

Another is in the TFIRST definition:

IDL> tfirst = (input[0,a])[0]
IDL> help,tfirst
TFIRST DOUBLE = 5158.3722

Hope that squashed the bug.
-Brian
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Opinions: passing paths, variables, etc. to compiled IDL routine
Next Topic: Coyote's Colored Line

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

Current Time: Wed Oct 08 19:32:07 PDT 2025

Total time taken to generate the page: 0.00433 seconds