God save me! [message #87205] |
Wed, 15 January 2014 17:21  |
zbjiang803109
Messages: 5 Registered: January 2014
|
Junior Member |
|
|
I am using IDL 8.2. I wrote the codes below:
if keyword_set(colorbar) then cb = COLORBAR(TARGET = img, ORIENTATION=1, $
POSITION=[0.925,0.25,0.945,0.75], $
border=1,textpos=1)
The system says "Syntax Error" when it is compiled. Even if I retype above lines it doesn't work. But a while later when I add and delete some lines, without changing any part of the codes, this message is gone. This kind of things happen again and again when I restart the IDLDE.
What happened!
Please help me. Thanks, Zhibo
|
|
|
Re: God save me! [message #87206 is a reply to message #87205] |
Wed, 15 January 2014 17:46   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
zbjiang803109@gmail.com writes:
> I am using IDL 8.2. I wrote the codes below:
>
> if keyword_set(colorbar) then cb = COLORBAR(TARGET = img, ORIENTATION=1, $
> POSITION=[0.925,0.25,0.945,0.75], $
> border=1,textpos=1)
>
> The system says "Syntax Error" when it is compiled. Even if I retype above lines it doesn't work. But a while later when I add and delete some lines, without changing any part of the codes, this message is gone. This kind of things happen again and again when I restart the IDLDE.
>
> What happened!
I've seen this! What you have to do is find a newt, and the lair of a
dragonfly. And, then, when the moon is full...Oh, the wife is calling.
Have to go. Sorry!
Cheers,
David
P.S. I'm guessing an invisible character has gotten stuck in the file.
Try opening the file in a basic text editor and see if something jumps
out at you. ;-)
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: God save me! [message #87208 is a reply to message #87205] |
Wed, 15 January 2014 19:22   |
Heinz Stege
Messages: 189 Registered: January 2003
|
Senior Member |
|
|
On Wed, 15 Jan 2014 17:21:04 -0800 (PST), zbjiang803109@gmail.com
wrote:
> I am using IDL 8.2. I wrote the codes below:
>
> if keyword_set(colorbar) then cb = COLORBAR(TARGET = img, ORIENTATION=1, $
> POSITION=[0.925,0.25,0.945,0.75], $
> border=1,textpos=1)
>
> The system says "Syntax Error" when it is compiled. Even if I retype above lines it doesn't work. But a while later when I add and delete some lines, without changing any part of the codes, this message is gone. This kind of things happen again and again when I restart the IDLDE.
>
> What happened!
>
Do you specify the compile option "compile_opt strictarr" or
"compile_opt idl2" to use square brackets for array indexing?
If not IDL will be irritated by using "COLORBAR(...)" for a function
and "colorbar" for a variable (your keyword). Rename your keyword
"colorbar" to "colorbar_keyword" or something else.
Cheers, Heinz
|
|
|
Re: God save me! [message #87210 is a reply to message #87208] |
Thu, 16 January 2014 05:58   |
zbjiang803109
Messages: 5 Registered: January 2014
|
Junior Member |
|
|
>
> wrote:
>
>
>
>> I am using IDL 8.2. I wrote the codes below:
>
>>
>
>> if keyword_set(colorbar) then cb = COLORBAR(TARGET = img, ORIENTATION=1, $
>
>> POSITION=[0.925,0.25,0.945,0.75], $
>
>> border=1,textpos=1)
>
>>
>
>> The system says "Syntax Error" when it is compiled. Even if I retype above lines it doesn't work. But a while later when I add and delete some lines, without changing any part of the codes, this message is gone. This kind of things happen again and again when I restart the IDLDE.
>
>>
>
>> What happened!
>
>>
>
> Do you specify the compile option "compile_opt strictarr" or
>
> "compile_opt idl2" to use square brackets for array indexing?
>
>
>
Thank a lot, Heinz. Adding compile_opt idl2 works. But I wonder why sometimes the compilation passes even without the option. And later when I remove the line (compile_opt idl2) the compilation also passes.
David: I tried open the file with Uedit and emacs, and didn't find any fancy characters.
Cheers, Zhibo
> If not IDL will be irritated by using "COLORBAR(...)" for a function
>
> and "colorbar" for a variable (your keyword). Rename your keyword
>
> "colorbar" to "colorbar_keyword" or something else.
>
>
>
> Cheers, Heinz
|
|
|
Re: God save me! [message #87226 is a reply to message #87210] |
Thu, 16 January 2014 14:08   |
Heinz Stege
Messages: 189 Registered: January 2003
|
Senior Member |
|
|
On Thu, 16 Jan 2014 05:58:28 -0800 (PST), ??? wrote:
> Thank a lot, Heinz. Adding compile_opt idl2 works. But I wonder why sometimes the compilation passes even without the option. And later when I remove the line (compile_opt idl2) the compilation also passes.
>
Zhibo, it is nothing wrong with not using the compile option. However,
if you allow round brackets for array indexing (i.e. no compile
option), the IDL compiler or interpreter has to find out if
"colorbar(...)" is a variable or a function.
I have never read (or investigated) how IDL is doing this. (Because
for me it is convenient, to use square brackets for arrays.) I think,
IDL makes it's decision on basis of it's lists of defined variables
and compiled functions. But I don't really know.
You can try to find it out. Does the compilation pass without an error
message, when the colorbar function is already compiled? (You can
check this with "help,/routines".)
If you allow round brackets for arrays, then you must not use the same
name (in this case "colorbar") for a variable as well for a function.
(This is meant for inside of one routine. You may use "colorbar" for a
function within one routine and for a variable within another
routine.)
If you use the said compile option, everything is simple:
"y=colorbar(...)" is a function call, and "y=colorbar[...]" is array
subscripting. Note that "y=colorbar[0]" and "y=colorbar[*]" are
allowed also for scalar variables.
Hope this helps.
Cheers, Heinz
|
|
|
Re: God save me! [message #87229 is a reply to message #87226] |
Fri, 17 January 2014 06:30   |
Yngvar Larsen
Messages: 134 Registered: January 2010
|
Senior Member |
|
|
On Thursday, 16 January 2014 23:08:19 UTC+1, Heinz Stege wrote:
> On Thu, 16 Jan 2014 05:58:28 -0800 (PST), ??? wrote:
>
>> Thank a lot, Heinz. Adding compile_opt idl2 works. But I wonder why sometimes the compilation passes even without the option. And later when I remove the line (compile_opt idl2) the compilation also passes.
>
> Zhibo, it is nothing wrong with not using the compile option. However,
> if you allow round brackets for array indexing (i.e. no compile
> option), the IDL compiler or interpreter has to find out if
> "colorbar(...)" is a variable or a function.
You can help the IDL interpreter figuring this out:
http://www.exelisvis.com/docs/FORWARD_FUNCTION.html
That being said, it is highly recommended that you use the idl2 compile option. Personally, I think it also more human readable with [] instead of () for the same reason as for the compiler: array indexing vs function call. And using round brackets for array indexing has been deprecated since IDL 5.0 (March 1997!). I'm not sure why this compile option is not default in 2014, almost two decades later. FUD regarding breaking of old code?
--
Yngvar
|
|
|
Re: God save me! [message #87342 is a reply to message #87226] |
Sun, 26 January 2014 06:02  |
zbjiang803109
Messages: 5 Registered: January 2014
|
Junior Member |
|
|
在 2014年1月16日星期四UTC-3下午7时08分19秒,Heinz Stege写道:
> On Thu, 16 Jan 2014 05:58:28 -0800 (PST), ??? wrote:
>
>
>
>> Thank a lot, Heinz. Adding compile_opt idl2 works. But I wonder why sometimes the compilation passes even without the option. And later when I remove the line (compile_opt idl2) the compilation also passes.
>
>>
>
> Zhibo, it is nothing wrong with not using the compile option. However,
>
> if you allow round brackets for array indexing (i.e. no compile
>
> option), the IDL compiler or interpreter has to find out if
>
> "colorbar(...)" is a variable or a function.
>
>
>
> I have never read (or investigated) how IDL is doing this. (Because
>
> for me it is convenient, to use square brackets for arrays.) I think,
>
> IDL makes it's decision on basis of it's lists of defined variables
>
> and compiled functions. But I don't really know.
>
>
>
> You can try to find it out. Does the compilation pass without an error
>
> message, when the colorbar function is already compiled? (You can
>
> check this with "help,/routines".)
>
>
>
> If you allow round brackets for arrays, then you must not use the same
>
> name (in this case "colorbar") for a variable as well for a function.
>
> (This is meant for inside of one routine. You may use "colorbar" for a
>
> function within one routine and for a variable within another
>
> routine.)
>
>
>
> If you use the said compile option, everything is simple:
>
> "y=colorbar(...)" is a function call, and "y=colorbar[...]" is array
>
> subscripting. Note that "y=colorbar[0]" and "y=colorbar[*]" are
>
> allowed also for scalar variables.
>
>
>
> Hope this helps.
>
>
>
> Cheers, Heinz
Yes, you're right. When I use the previous option, the error message appears again. When I run .compile COLORBAR and then compile the program, it passes.
|
|
|