Re: Problem Compiling and Using Functions [message #46804] |
Wed, 04 January 2006 16:13  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
someone@someplace.com writes:
> DOH!... Doh!... doh!... (echoing off into the distance) :)
>
> Thanks for your fast response. It works now.
>
> I'm new to IDL and I'm not used there being this difference between
> functions and procedures.
>
> So, procedures don't return anything and functions *always* have to
> return something and the calling function/procedure has handle them
> correctly.
Yes, this is correct. But if you are going to write your
functions to return 0s, you have surmised correctly that
you could just as well use a procedure. All arguments
to procedures and function alike (including keyword
arguments) can be passed by reference, so getting things
into and out of procedure (as well as functions) is
reasonably trivial.
Just keep chanting to yourself "IDL is NOT C, IDL is NOT C."
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
|
Re: Problem Compiling and Using Functions [message #46806 is a reply to message #46805] |
Wed, 04 January 2006 14:48   |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
David Fanning wrote:
> someone@someplace.com writes:
>
>
>> I'm having trouble getting simple functions to work. I have the code
>> below in a single file named extract_tiles.pro. When I try and compile
>> it gives me a syntax error on the line containing
>> "extract_tiles_get_tile(fid)" in the extract_tiles procedure. If I
>> change the function to a procedure, comment out the return statement
>> and change the function call to a procedure call it works perfectly.
>>
>> It's probably a simple error, but I can't figure it out. I'm using IDL
>> 5.6 and ENVI 3.6.
>>
>> FUNCTION extract_tiles_get_tile, fImg
>> ENVI_FILE_QUERY, fImg, ns=ns, nl=nl
>> print, 'Samples: ', ns
>> print, 'Lines: ', nl
>> RETURN, 0
>> END
>>
>> PRO extract_tiles
>> ENVI_OPEN_FILE, 'image.dat', r_fid=fid
>> extract_tiles_get_tile(fid)
>> END
>
>
> Functions return a value. Try writing the function call like this:
>
> void = extract_tiles_get_tile(fid)
Man, I heard the "D'OH!" all the way over here!
:o)
--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
|
|
|
Re: Problem Compiling and Using Functions [message #46807 is a reply to message #46806] |
Wed, 04 January 2006 14:09   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
someone@someplace.com writes:
> I'm having trouble getting simple functions to work. I have the code
> below in a single file named extract_tiles.pro. When I try and compile
> it gives me a syntax error on the line containing
> "extract_tiles_get_tile(fid)" in the extract_tiles procedure. If I
> change the function to a procedure, comment out the return statement
> and change the function call to a procedure call it works perfectly.
>
> It's probably a simple error, but I can't figure it out. I'm using IDL
> 5.6 and ENVI 3.6.
>
> FUNCTION extract_tiles_get_tile, fImg
> ENVI_FILE_QUERY, fImg, ns=ns, nl=nl
> print, 'Samples: ', ns
> print, 'Lines: ', nl
> RETURN, 0
> END
>
> PRO extract_tiles
> ENVI_OPEN_FILE, 'image.dat', r_fid=fid
> extract_tiles_get_tile(fid)
> END
Functions return a value. Try writing the function call like this:
void = extract_tiles_get_tile(fid)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Problem Compiling and Using Functions [message #46875 is a reply to message #46804] |
Sat, 07 January 2006 15:04  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
David Fanning wrote:
> someone@someplace.com writes:
>
>> DOH!... Doh!... doh!... (echoing off into the distance) :)
>>
>> Thanks for your fast response. It works now.
>>
>> I'm new to IDL and I'm not used there being this difference between
>> functions and procedures.
>>
>> So, procedures don't return anything and functions *always* have to
>> return something and the calling function/procedure has handle them
>> correctly.
>
> Yes, this is correct. But if you are going to write your
> functions to return 0s, you have surmised correctly that
> you could just as well use a procedure. All arguments
> to procedures and function alike (including keyword
> arguments) can be passed by reference, so getting things
> into and out of procedure (as well as functions) is
> reasonably trivial.
>
> Just keep chanting to yourself "IDL is NOT C, IDL is NOT C."
>
> Cheers,
>
> David
Hmm I think there was a change you could write a function which does not
need a return inside. It's not that's I like this. I like a clear
definition as above.
IDL> $more test.pro
function test
end
IDL> a=test()
IDL> help,a
A INT = 0
cheers
Reimar
|
|
|