Re: IDL and me! [message #45558] |
Wed, 21 September 2005 08:40 |
Timm Weitkamp
Messages: 66 Registered: August 2002
|
Member |
|
|
David Fanning wrote:
> Liberum writes:
>
>> As a nascent IDL user I have come across a little problem that really
>> chaps my hide!
>
> You need more detective work here. Learn how to set breakpoints and
> step through your code.
As a start, even without setting any breakpoints, typing "HELP, D" at
the command line just after the error occurs will tell you how many
elements D actually has at that point. And, just like the others here,
I should think the answer is not 4, not even 3 or 2.
As an aside: shouldn't the "i += 1" line before ENDFOR better be left
out?
Happy debugging
Timm
Timm Weitkamp, ESRF, Grenoble, France
|
|
|
Re: IDL and me! [message #45559 is a reply to message #45558] |
Wed, 21 September 2005 08:30  |
Paolo Grigis
Messages: 171 Registered: December 2003
|
Senior Member |
|
|
Liberum wrote:
> Hi Guys and Gals,
>
> As a nascent IDL user I have come across a little problem that really
> chaps my hide! Any help would really be appreciated!
> Consider the following file-reading code:
>
> OPENR, LUN, file, /GET_LUN
> s = ""
> FOR i = 0, n_lines -1 DO BEGIN
> READF, LUN, s ; reads the file line by line into string s
> d = STRSPLIT(s, /EXTRACT)
> col1 = d[0] & col2 = d[1] & col3 = d[2] & col4 = d[3]
> IF FIX(col1) EQ -10 THEN bias[i] = 0
> IF FIX(col1) EQ -5 THEN bias[i] = 1
> IF FIX(col1) EQ -1 THEN bias[i] = 2
> IF FIX(col1) EQ 0 THEN bias[i] = 3
> IF FIX(col1) EQ 1 THEN bias[i] = 4
> IF FIX(col1) EQ 5 THEN bias[i] = 5
> IF FIX(col1) EQ 10 THEN bias[i] = 6
> cth[i] = LONG(col2)
> occur[i] = LONG(col3)
> pixels[i] = LONG(col4)
> hist_data[bias[i], cth[i] - 1] = FLOAT(occur[i])/pixels[i]*100.
Maybe unrelated... but are you sure you need the following line
in a for-loop over i? It is usually quite dangerous to change
the values of loop counter variables.
Ciao,
Paolo
> i += 1
> ENDFOR
> FREE_LUN, LUN
>
> Now all I'm trying to do is to read the contents of this file into an
> array. Now when I run this script I get:
>
> % Attempt to subscript D with <INT ( 1)> is out of range.
>
> Now how can this be when d has 4 elements and I have not looped outside
> of [0, 3] ????????????
>
> Sincerely,
> Lib
>
|
|
|
Re: IDL and me! [message #45560 is a reply to message #45559] |
Wed, 21 September 2005 08:11  |
Antonio Santiago
Messages: 201 Registered: February 2004
|
Senior Member |
|
|
Liberum wrote:
> Hi Guys and Gals,
>
> As a nascent IDL user I have come across a little problem that really
> chaps my hide! Any help would really be appreciated!
> Consider the following file-reading code:
>
> OPENR, LUN, file, /GET_LUN
> s = ""
> FOR i = 0, n_lines -1 DO BEGIN
> READF, LUN, s ; reads the file line by line into string s
> d = STRSPLIT(s, /EXTRACT)
> col1 = d[0] & col2 = d[1] & col3 = d[2] & col4 = d[3]
> IF FIX(col1) EQ -10 THEN bias[i] = 0
> IF FIX(col1) EQ -5 THEN bias[i] = 1
> IF FIX(col1) EQ -1 THEN bias[i] = 2
> IF FIX(col1) EQ 0 THEN bias[i] = 3
> IF FIX(col1) EQ 1 THEN bias[i] = 4
> IF FIX(col1) EQ 5 THEN bias[i] = 5
> IF FIX(col1) EQ 10 THEN bias[i] = 6
> cth[i] = LONG(col2)
> occur[i] = LONG(col3)
> pixels[i] = LONG(col4)
> hist_data[bias[i], cth[i] - 1] = FLOAT(occur[i])/pixels[i]*100.
> i += 1
> ENDFOR
> FREE_LUN, LUN
>
> Now all I'm trying to do is to read the contents of this file into an
> array. Now when I run this script I get:
>
> % Attempt to subscript D with <INT ( 1)> is out of range.
>
> Now how can this be when d has 4 elements and I have not looped outside
> of [0, 3] ????????????
>
> Sincerely,
> Lib
>
Perhaps ASCII_TEMPLATE can be useful for you.
--
-----------------------------------------------------
Antonio Santiago P�rez
( email: santiago<<at>>grahi.upc.edu )
( www: http://www.grahi.upc.edu/santiago )
( www: http://asantiago.blogsite.org )
-----------------------------------------------------
GRAHI - Grup de Recerca Aplicada en Hidrometeorologia
Universitat Polit�cnica de Catalunya
-----------------------------------------------------
|
|
|
Re: IDL and me! [message #45561 is a reply to message #45560] |
Wed, 21 September 2005 07:45  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Liberum writes:
> As a nascent IDL user I have come across a little problem that really
> chaps my hide!
In my experience, 99% of the time this problem is a problem
with assumptions. That is to say, programmer error. You need
more detective work here. Learn how to set breakpoints and
step through your code.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: IDL and me! [message #45562 is a reply to message #45561] |
Wed, 21 September 2005 07:36  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
"Liberum" <shejo284@gmail.com> writes:
> Hi Guys and Gals,
>
> As a nascent IDL user I have come across a little problem that really
> chaps my hide! Any help would really be appreciated!
> Consider the following file-reading code:
>
> OPENR, LUN, file, /GET_LUN
> s = ""
> FOR i = 0, n_lines -1 DO BEGIN
> READF, LUN, s ; reads the file line by line into string s
> d = STRSPLIT(s, /EXTRACT)
> col1 = d[0] & col2 = d[1] & col3 = d[2] & col4 = d[3]
> IF FIX(col1) EQ -10 THEN bias[i] = 0
> IF FIX(col1) EQ -5 THEN bias[i] = 1
> IF FIX(col1) EQ -1 THEN bias[i] = 2
> IF FIX(col1) EQ 0 THEN bias[i] = 3
> IF FIX(col1) EQ 1 THEN bias[i] = 4
> IF FIX(col1) EQ 5 THEN bias[i] = 5
> IF FIX(col1) EQ 10 THEN bias[i] = 6
> cth[i] = LONG(col2)
> occur[i] = LONG(col3)
> pixels[i] = LONG(col4)
> hist_data[bias[i], cth[i] - 1] = FLOAT(occur[i])/pixels[i]*100.
> i += 1
> ENDFOR
> FREE_LUN, LUN
>
> Now all I'm trying to do is to read the contents of this file into an
> array. Now when I run this script I get:
>
> % Attempt to subscript D with <INT ( 1)> is out of range.
>
> Now how can this be when d has 4 elements and I have not looped outside
> of [0, 3] ????????????
You might have to consider the case when D does *not* have four
elements. For example, a blank line at the end of the file might do
that. A simple, "IF N_ELEMENTS(D) LT 4 THEN CONTINUE" at the right
place might do the trick.
Good luck,
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|