Re: FOR LOOP problem [message #30976 is a reply to message #30975] |
Fri, 31 May 2002 14:27   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Shravan Kumar Durvasula (skd6@ra.msstate.edu) writes:
> I am very much new to IDL. Could anyone please tell me what the problem is with
> this .pro file?
>
> ************************************************************ **********
> image = bytarr(462, 350)
> image_mod = bytarr(462, 350)
> openr, 1, FILEPATH(SUB=['examples','data'], '400_400_gb')
> readu, 1, image
> FOR i = 0, 461 DO BEGIN
> FOR j = 0, 349 DO image_mod[i,j] = image[i,j]
> ENDFOR
> close, 1
> ************************************************************ *********
>
> It gives me the following error message :
>
> ************************************************************ *********
> % Attempt to subscript IMAGE with I is out of range.
> % Execution halted at: $MAIN$
> ENDFOR
> ^
> % Syntax error.
> At: D:\webpages\IONJava\examples\ndvi_pro.pro, Line 7
> ************************************************************ *********
I suspect the problem lies in how you are trying to
run this program. I recommend you put another END at the
end of the program file (after the CLOSE statement),
then run it like this from the IDL command line:
IDL> .Run ndvi_pro
Does that work better? This will compile the code before
it tries to run it. I think that will work better for you.
I should point out that you can more easily do what you
want to do (and a hell of lot faster!) by simply writing this:
image_mod = image
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|