Re: FOR LOOP problem [message #31041 is a reply to message #30976] |
Tue, 04 June 2002 14:35   |
skd6
Messages: 4 Registered: May 2002
|
Junior Member |
|
|
Hi,
I am actually working on IONJava. I have a strange problem. This is
the .pro file that i have written :
************************************************************ ********
band4_image = bytarr(420, 345)
band3_image = bytarr(420, 345)
final_image = bytarr(420, 345)
OPENR, 1, FILEPATH(SUB=['examples','data'], 'band_4')
OPENR, 2, FILEPATH(SUB=['examples','data'], 'band_3')
READU, 1, band4_image
READU, 2, band3_image
FOR i = 0,419 DO BEGIN
FOR j = 0,344 DO final_image[i,j] = band4_image[i,j]
ENDFOR
CLOSE, 1
CLOSE, 2
TV, final_image
END
************************************************************ ********
When i compile and run this program from the IDL command prompt, it
runs absolutely fine. But when i run this file through IONJava using
the "executeIDLCommand()" (method in the IONGraphicsClient class of
IONJava) it gives the following error message :
************************************************************ *******
% Attempt to subscript BAND3_IMAGE with I is out of range.
% Execution halted at: $MAIN$
ENDFOR
^
% Syntax error.
At: D:\webpages\IONJava\examples\ndvi_pro.pro, Line 10
END
^
% Syntax error.
At: D:\webpages\IONJava\examples\ndvi_pro.pro, Line 14
************************************************************ *******
I tried eliminating "ENDFOR" by modiying the code to :
************************************************************ ******
band4_image = bytarr(420, 345)
band3_image = bytarr(420, 345)
final_image = bytarr(420, 345)
OPENR, 1, FILEPATH(SUB=['examples','data'], 'band_4')
OPENR, 2, FILEPATH(SUB=['examples','data'], 'band_3')
READU, 1, band4_image
READU, 2, band3_image
FOR i = 0,419 DO FOR j = 0,344 DO final_image[i,j] = band4_image[i,j]
CLOSE, 1
CLOSE, 2
TV, final_image
END
************************************************************ ******
When i do that it says :
************************************************************ ******
END
^
% Syntax error.
At: D:\webpages\IONJava\examples\ndvi_pro.pro, Line 12
************************************************************ ******
I then removed END in the last line and tried running it again. It
worked absolutely fine. I am not able to guess what the problem could
be. I was wondering if it had anything to do with the indentation as
it said Syntax error. But i could not correct it. Could anyone please
help? Any suggestions given on this would be of great help to me.
Thanks,
Shravan Kumar Durvasula
David Fanning <david@dfanning.com> wrote in message news:<MPG.176198a6982878fc989905@news.frii.com>...
> 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
|
|
|