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

Home » Public Forums » archive » Subtracting a single variable from an array
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
Subtracting a single variable from an array [message #71646] Wed, 07 July 2010 10:04
polystethylene is currently offline  polystethylene
Messages: 28
Registered: February 2009
Junior Member
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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: REGRESS and sky background
Next Topic: Padding arrays - vector subscripts not working

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

Current Time: Wed Oct 08 17:41:55 PDT 2025

Total time taken to generate the page: 0.00559 seconds