FOR LOOP problem [message #30977] |
Fri, 31 May 2002 13:44  |
skd6
Messages: 4 Registered: May 2002
|
Junior Member |
|
|
Hi,
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
************************************************************ *********
Thanks,
Shravan Kumar Durvasula
|
|
|
Re: FOR LOOP problem [message #31030 is a reply to message #30977] |
Wed, 05 June 2002 13:27   |
skd6
Messages: 4 Registered: May 2002
|
Junior Member |
|
|
Hi,
I think it is finally working. It all depends on the way you run it. I
took the idea from David Fanning when he suggested to run the .pro
file as
IDL> .Run ndvi_pro
Actually in IONJava the way we run it is like this :
************************************************************ ******
igclient.executeIDLCommand("@ndvi_pro.pro");
************************************************************ ******
where "igclient" is an "IONGraphicsClient" object. When i replaced
this statement with :
************************************************************ *****
igclient.executeIDLCommand(".run ndvi_pro");
************************************************************ *****
it is working fine. Could anyone please tell what is the difference in
runing a ndvi_pro.pro file in these two different ways :
@ndvi_pro.pro
.Run ndvi_pro
Thanks to all those who helped me solve the problem.
Best Regards,
SKD
Reimar Bauer <r.bauer@fz-juelich.de> wrote in message news:<3CFDB27C.7825A25A@fz-juelich.de>...
> Shravan Kumar Durvasula wrote:
>>
>> Hi,
>>
>> I am actually working on IONJava. I have a strange problem. This is
>> the .pro file that i have written :
>
> Dear Shravan
>
> are aou sure that it is really the same file for ion and idl?
>
> Reimar
>>
>> ************************************************************ ********
>> 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
>
> --
> Reimar Bauer
>
> Institut fuer Stratosphaerische Chemie (ICG-I)
> Forschungszentrum Juelich
> email: R.Bauer@fz-juelich.de
> ------------------------------------------------------------ -------
> a IDL library at ForschungsZentrum Juelich
> http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml
> ============================================================ =======
|
|
|
Re: FOR LOOP problem [message #31031 is a reply to message #30977] |
Wed, 05 June 2002 12:46   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
skd6@ra.msstate.edu (Shravan Kumar Durvasula) writes:
> Hi,
>
> I am actually working on IONJava. I have a strange problem. This is
> the .pro file that i have written :
>
...
>
> 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 :
...
>
> I tried eliminating "ENDFOR" by modiying the code to :
>
...
> 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.
IDL makes the distinction of what can be run on the command line, and
what can be placed in a compiled procedure. Items that appear on the
command line are more restricted. For example you can't have
multi-line BEGIN/END clauses, which is exactly what you are seeing.
This is also the distinction between the "@" command, and the ".RUN"
command. The former accepts only simple commands, while the latter
expects a fully formed procedure, finished with END, but is able to
take BEGIN/END clauses. The EXECUTE() statement, upon which
executeIDLCommand() must be based, also falls in the former category,
so that's why you are getting errors. Why don't you just stuff all
this into its own procedure?
Good luck,
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: FOR LOOP problem [message #31032 is a reply to message #30977] |
Wed, 05 June 2002 11:28   |
skd6
Messages: 4 Registered: May 2002
|
Junior Member |
|
|
Hi Reimar,
Thank you vesy much for your help.
Well I am very new to this. But as far as i understand IONJava just
uses the file written in IDL. All that IONJava does is gets the IDL on
to the net. You do that by running the IDL file (*.pro file) with the
statement "executeIDLCommand()". Also, i have looked at some of the
example IONJava files that use the .pro file. They basically use the
same file written in IDL.
Thanks,
Shravan Kumar Durvasula
Reimar Bauer <r.bauer@fz-juelich.de> wrote in message news:<3CFDB27C.7825A25A@fz-juelich.de>...
> Shravan Kumar Durvasula wrote:
>>
>> Hi,
>>
>> I am actually working on IONJava. I have a strange problem. This is
>> the .pro file that i have written :
>
> Dear Shravan
>
> are aou sure that it is really the same file for ion and idl?
>
> Reimar
>>
>> ************************************************************ ********
>> 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
>
> --
> Reimar Bauer
>
> Institut fuer Stratosphaerische Chemie (ICG-I)
> Forschungszentrum Juelich
> email: R.Bauer@fz-juelich.de
> ------------------------------------------------------------ -------
> a IDL library at ForschungsZentrum Juelich
> http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml
> ============================================================ =======
|
|
|
Re: FOR LOOP problem [message #31040 is a reply to message #30977] |
Tue, 04 June 2002 23:41   |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Shravan Kumar Durvasula wrote:
>
> Hi,
>
> I am actually working on IONJava. I have a strange problem. This is
> the .pro file that i have written :
Dear Shravan
are aou sure that it is really the same file for ion and idl?
Reimar
>
> ************************************************************ ********
> 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
--
Reimar Bauer
Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml
============================================================ =======
|
|
|
Re: FOR LOOP problem [message #31143 is a reply to message #30977] |
Mon, 10 June 2002 09:04  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Paul Sorenson wrote:
>
> "Reimar Bauer" <r.bauer@fz-juelich.de> wrote in message
> news:3CFB1297.BAC0ACAE@fz-juelich.de...
>> Doug Rowland wrote:
>>>
>>> What happens if the image you are reading in is only 400x400 bytes (as
> seems
>>> to be implied by the filename)?
>>> Does readu then redefine image to be a 400x400 array or does it just
> leave
>>> the rest of the 462x350 array blank?
>>
>> Dear Doug,
>>
>> the rest 1700 bytes will be 0b and the size is (462, 350).
>> This gaves no new information.
>>
>> It's not easy to examine the right size of a binary file.
>> First step could be to examine by fstat the byte size.
>> Then the data could be read as byte vector.
>
> You can do this with one command:
>
> IDL> vector = read_binary()
I know
but this is not working in runtime because of execute.
>> If you have an idea how it is organized you can use a reform
>> to put it in the correct size.
>
> You can read it and reform it in one command:
>
> IDL> array = read_binary(data_dims=[400, 400])
>
> -Paul Sorenson
>>
>> Reimar
>>
>>
>>
>>
>>
>>
>>
>>>
>>> How about trying this:
>>>
>>> image = bytarr(462, 350)
>>> image_mod = bytarr(462, 350)
>>> openr, 1, FILEPATH(SUB=['examples','data'], '400_400_gb')
>>> readu, 1, image
>>> print,size(image)
>>> close,1
>>> end
>>>
>>> Doug Rowland
>>> rowland@fields.space.umn.edu
>>>
>>> On 05/31/02 4:27 PM, in article
> MPG.176198a6982878fc989905@news.frii.com,
>>> "David Fanning" <david@dfanning.com> wrote:
>>>
>>>> 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
>>
>> --
>> Reimar Bauer
>>
>> Institut fuer Stratosphaerische Chemie (ICG-I)
>> Forschungszentrum Juelich
>> email: R.Bauer@fz-juelich.de
>> ------------------------------------------------------------ -------
>> a IDL library at ForschungsZentrum Juelich
>> http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml
>> ============================================================ =======
>
> -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
> http://www.newsfeed.com The #1 Newsgroup Service in the World!
> -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
--
Reimar Bauer
Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml
============================================================ =======
|
|
|