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
------------------------------------------------------------ --------------
|
|
|