Re: Beginer question about the @ usage [message #44994 is a reply to message #44850] |
Wed, 27 July 2005 12:50   |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
Mathieu Malaterre wrote:
>
>> What is the correct way to run testlib.pro ?
>
>
> ok I found a working example:
>
> http://groups-beta.google.com/group/comp.lang.idl-pvwave/msg /f539ce41dda7574b
>
>
> Still don't understand why PRO is needed...
The usual recommendation is to put any procedure/function that you will ever want to call in a file
with the same name as the function.
e.g. bananas.pro contains
pro BaNaNaS, input, output
output = input * 2
end
and applesandoranges.pro contains
function AppleSandOrangeS, input
return, input^2
end
(note the filenames are all lower case, whereas the routine names can be upper, lower, or mixture)
When IDL searches for a routine (if it hasn't already been compiled) it looks for a file with the
same name as the routine name.
If you do this, there is limited utility to using the @ functionality to stick code in other files
(exceptions, of course, exist). I use the @ include stuff for files containing just numbers that I
treat as unmodifiable parameters (i.e. parameters in the Fortran sense, not the IDL argument sense)
The usual exception to the each-function-in-its-own-file rule is things like widget code where event
handlers are placed in the same file as the widget creation code, e.g. mywidget.pro contains:
PRO Exit_Event, Event
WIDGET_CONTROL, Event.Top, /DESTROY
END
PRO mywidget
Top_Level_Base_ID = WIDGET_BASE( COLUMN = 1, $
MAP = Map, $
MBAR = Menu_Bar_ID, $
TITLE = 'MyWidget' )
File_Menu_ID = WIDGET_BUTTON( Menu_Bar_ID, $
VALUE = 'File', $
/MENU )
File_Exit_ID = WIDGET_BUTTON( File_Menu_ID, $
VALUE = 'Exit', $
EVENT_PRO = 'Exit_Event', $
/SEPARATOR, $
UVALUE = 'Exit' )
WIDGET_CONTROL, Top_Level_Base_ID, MAP = Map, $
REALIZE = 1, $
UPDATE = 1
XMANAGER, 'mywidget', Top_Level_Base_ID
END
Note that the MAIN routine, mywidget, is AFTER the event handler. This ensures that the dependent
"Exit_Event" routine is compiled whenever the "mywidget" procedure is invoked. If you put the event
handler after the main routine, it would not get compiled.
paulv
--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
|
|
|