Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Idl-pvware > Why doesn't thi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 5433 of 6022
Post > Topic >>

Why doesn't this return the correct value?

by chloesharrocks@[EMAIL PROTECTED] Feb 14, 2008 at 02:59 AM

Dear all

I currently have an array called good_index.  Some of the elements are
>=3D0 and others are <0.  I want to write a code that firstly finds how
many of these elements are greater than zero and use this number to
produce another array (called good_indexed_precip) with that number of
elements.  Then I want it to search through each element of good_index
in turn.  If upon searching it finds that the element is >=3D0 I want it
to find the value of that element in good_index.  I then want to find
the data stored in the index given by that value in another array
called precip_change.  The code I've written is below:

=3D=3D=3D=3D=3D
counter_2 =3D 0
number =3D total(good_index ge 0, /int) ;this counts how many elements
in good_index are >=3D zero
print, number     ;this gives the correct answer 6

	FOR s=3D0, (N_ELEMENTS(good_index)-1) DO BEGIN
		good_indexed_precip=3Dfltarr(number)
		IF good_index[s] ge 0 THEN BEGIN
				good_indexed_precip[counter_2] =3D precip_change[good_index[s]]
				counter_2++
		ENDIF
	ENDFOR
=3D=3D=3D=3D=3D

Unfortunately, it then prints good_indexed_precip with all 6 elements
zero, even though the values of precip_change[good_index[s]] are non-
zero.

If I were to put in the data by hand, eg say
good_indexed_precip[0] =3D precip_change[good_index[0]]
good_indexed_precip[1] =3D precip_change[good_index[13]]
This works fine, so I can't see why my loop isn't working correctly.
I know that the 0th &1st element of good_index are both >=3Dzero, yet if
I run the loop: FOR s=3D0, 1 DO BEGIN etc and print good_indexed_precip
it only has a non-zero value in the 1st element and not the 0th
element!

Thanks for all your help in advance.
Chlo=E9
 




 3 Posts in Topic:
Why doesn't this return the correct value?
chloesharrocks@[EMAIL PRO  2008-02-14 02:59:24 
Re: Why doesn't this return the correct value?
Spon <christoph.blau@[  2008-02-14 03:22:53 
Re: Why doesn't this return the correct value?
Spon <christoph.blau@[  2008-02-14 03:25:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 22:34:21 CDT 2008.