Vous êtes sur la page 1sur 5

Compiling Your Program

1 de 5

http://127.0.0.1:50893/help/advanced/print.jsp?topic=/com.rsi.idl.doc.co...

Compiling Your Program


Contents
1. Automatic Compilation
2. Manual Compilation
3. Compilation Errors
4. Setting Compilation Options

Compiling Your Program


Before a procedure or function can be executed, it must be compiled. When a system routine (a function or procedure built into IDL, such as iPLOT) is called, either from the command line or from another procedure, IDL already knows about this routine and compiles it automatically. When a user-defined function or procedure is
called, IDL must find the routine and then compile it. Compilation can be either automatic or manual, as described below.

Warning
User-written functions must be defined before they are referenced, unless they:
1) Exist in the IDL !PATH.
2) Exist in a .pro file with the same name as the function.
3) Are reserved using the FORWARD_FUNCTION statement.
Defining the function is necessary to distinguish between function calls and subscripted variable references. See About Calling and Compiling Functions for details.

Automatic Compilation
When you enter the name of an uncompiled user-defined routine at the command line or call the routine from another routine, IDL searches the current directory for filename.pro, then filename.sav, where filename is the name of the specified routine. If no file is found in the current directory, IDL searches each directory
specified by !PATH. (For more on the IDL path, see "!PATH" (IDL Reference Guide).)
If no file matching the routine name is found, IDL issues an error:
% Attempt to call undefined procedure/function: 'routine'
where routine is the name of the routine you specified.
If a file is found, IDL automatically compiles the contents of the file up to the routine with the same name of the file (excluding the suffix), and then executes the routine. If the file does not contain the definition of a routine with the same name as the file, IDL issues the same error as when the no file with the correct name is found.
For example, suppose a file named proc1.pro contains the following procedure definitions:
PRO proc1
PRINT, 'This is proc1'
END
PRO proc2
PRINT, 'This is proc2'
END
PRO proc3
PRINT, 'This is proc3'
END
If you enter proc1 at the IDL command line, only the proc1 procedure will be compiled and executed. If you enter proc2 or proc3 at the command line, you will get an error informing you that you attempted to call an undefined procedure.
In general, the name of the IDL program file should be the same as the name of the last routine within the file. This last routine is usually the main routine, which calls all the other routines within the IDL program file (or, in the case of object classes, the class definition). Using this convention for your IDL program files ensures that all
the related routines within the file are compiled before being called by the last main routine.
Program files within the IDL distribution use this formatting style. For example, open the program file for the XLOADCT procedure, xloadct.pro, in the IDL Editor. This file is in the lib/utilities subdirectory of the IDL distribution. This file contains several routines. The main routine (XLOADCT) is at the bottom of the file.
When this file is compiled, the IDL Console notes all the routines within this file that are compiled:
IDL> .COMPILE XLOADCT
% Compiled module: XLCT_PSAVE.
% Compiled module: XLCT_ALERT_CALLER.
% Compiled module: XLCT_SHOW.
% Compiled module: XLCT_DRAW_CPS.
% Compiled module: XLCT_TRANSFER.
% Compiled module: XLOADCT_EVENT.
% Compiled module: XLOADCT.
Note that the main XLOADCT procedure is compiled last.

Tip
When editing a program file containing multiple functions and/or procedures in the IDL Editor, you can easily move to the desired function or procedure in the Outline view by selecting the Outline tab next to the Project Explorer tab. Select the function or procedure name from the list, and the Editor highlights and displays it.

Manual Compilation
There are several ways to manually compile a procedure or function.
Use the .COMPILE executive command at the IDL command line:
.COMPILE myFile

where myFile is the name of a .pro file located either in IDL's current working directory or in one of the directories specified by !PATH. All the routines included in the specified file will be compiled, but none will be executed automatically. If you are using the IDL Workbench, the .pro file will also be opened in the IDL Editor.
If the file is open in the IDL Editor, select Run Compile or click the Compile button on the toolbar. All routines within the file will be compiled, but none will be executed automatically.
Use the .RUN or .RNEW executive command at the IDL command line:
.RUN myFile
where myFile is the name of a .pro file located either in IDL's current working directory or in one of the directories specified by !PATH. All the routines included in the specified file will be compiled, and any $MAIN$ level programs will be executed automatically. If you are using the IDL Workbench, the .pro file will also be opened
in the IDL Editor.
Use the .RUN, .RNEW, or .COMPILE executive command with no filename argument to interactively create and compile a $MAIN$ level program. The Command line prompt changes from IDL > prompt toe - so that you can start entering the $MAIN$ level program. See Creating $MAIN$ Programs for additional details.
Note
Only .pro files can be compiled using the manual compilation mechanisms. Attempting to compile a SAVE ( .sav) file using one of these mechanisms will result in an error.
The "Hello World" example shown in Compiling Your Program has a user-defined procedure that contains a call to a user-defined function. If you enter the name of the user-defined procedure, hello_main, at the command line, IDL will compile and execute the hello_main procedure. After you provide the requested input, a
call to the hello_who function is made. IDL searches for hello_who.pro, and compiles and executes the function.

Compilation Errors
If an error occurs during compilation, the error is reported in the IDL Workbench Console view. For example, because the END statement is commented out, the following user-defined procedure will result in a compilation error:
PRO procedure_without_END
PRINT, 'Hello World'
;END
When trying to compile this procedure (after saving it into a file named procedure_without_END.pro), you will receive an error similar to the following the IDL Console view:
IDL> .COMPILE procedure_without_END
% End of file encountered before end of program.
At: C:\ITT\workspace\Default\procedure_without_end.pro, Line 4
% 1 Compilation error(s) in module PROCEDURE_WITHOUT_END.
Note
The IDL Editor displays a red dot to the left of each line that contains an error.

Setting Compilation Options


The COMPILE_OPT statement allows you to give the IDL compiler information that changes some of the default rules for compiling the function or procedure within which the COMPILE_OPT statement appears. The syntax of COMPILE_OPT is as follows:
COMPILE_OPT opt1 [,opt2, ..., optn]
where opt is any of the available options documented in "COMPILE_OPT" (IDL Reference Guide). These options allow you to change default values of true and false, hide routines from HELP, and reserve the use of parentheses for functions. See COMPILE_OPT for complete details.
n

Send us a comment on this topic

24-07-2014 17:21

Compiling Your Program

2 de 5

http://127.0.0.1:50893/help/advanced/print.jsp?topic=/com.rsi.idl.doc.co...

1. Compiling Your Program


Before a procedure or function can be executed, it must be compiled. When a system routine (a function or procedure built into IDL, such as iPLOT) is called, either from the command line or from another procedure, IDL already knows about this routine and compiles it automatically. When a user-defined function or procedure is
called, IDL must find the routine and then compile it. Compilation can be either automatic or manual, as described below.

Warning
User-written functions must be defined before they are referenced, unless they:
1) Exist in the IDL !PATH.
2) Exist in a .pro file with the same name as the function.
3) Are reserved using the FORWARD_FUNCTION statement.
Defining the function is necessary to distinguish between function calls and subscripted variable references. See About Calling and Compiling Functions for details.

Automatic Compilation
When you enter the name of an uncompiled user-defined routine at the command line or call the routine from another routine, IDL searches the current directory for filename.pro, then filename.sav, where filename is the name of the specified routine. If no file is found in the current directory, IDL searches each directory
specified by !PATH. (For more on the IDL path, see "!PATH" (IDL Reference Guide).)
If no file matching the routine name is found, IDL issues an error:
% Attempt to call undefined procedure/function: 'routine'
where routine is the name of the routine you specified.
If a file is found, IDL automatically compiles the contents of the file up to the routine with the same name of the file (excluding the suffix), and then executes the routine. If the file does not contain the definition of a routine with the same name as the file, IDL issues the same error as when the no file with the correct name is found.
For example, suppose a file named proc1.pro contains the following procedure definitions:
PRO proc1
PRINT, 'This is proc1'
END
PRO proc2
PRINT, 'This is proc2'
END
PRO proc3
PRINT, 'This is proc3'
END
If you enter proc1 at the IDL command line, only the proc1 procedure will be compiled and executed. If you enter proc2 or proc3 at the command line, you will get an error informing you that you attempted to call an undefined procedure.
In general, the name of the IDL program file should be the same as the name of the last routine within the file. This last routine is usually the main routine, which calls all the other routines within the IDL program file (or, in the case of object classes, the class definition). Using this convention for your IDL program files ensures that all
the related routines within the file are compiled before being called by the last main routine.
Program files within the IDL distribution use this formatting style. For example, open the program file for the XLOADCT procedure, xloadct.pro, in the IDL Editor. This file is in the lib/utilities subdirectory of the IDL distribution. This file contains several routines. The main routine (XLOADCT) is at the bottom of the file.
When this file is compiled, the IDL Console notes all the routines within this file that are compiled:
IDL> .COMPILE XLOADCT
% Compiled module: XLCT_PSAVE.
% Compiled module: XLCT_ALERT_CALLER.
% Compiled module: XLCT_SHOW.
% Compiled module: XLCT_DRAW_CPS.
% Compiled module: XLCT_TRANSFER.
% Compiled module: XLOADCT_EVENT.
% Compiled module: XLOADCT.
Note that the main XLOADCT procedure is compiled last.

Tip
When editing a program file containing multiple functions and/or procedures in the IDL Editor, you can easily move to the desired function or procedure in the Outline view by selecting the Outline tab next to the Project Explorer tab. Select the function or procedure name from the list, and the Editor highlights and displays it.

Manual Compilation
There are several ways to manually compile a procedure or function.
Use the .COMPILE executive command at the IDL command line:
.COMPILE myFile

where myFile is the name of a .pro file located either in IDL's current working directory or in one of the directories specified by !PATH. All the routines included in the specified file will be compiled, but none will be executed automatically. If you are using the IDL Workbench, the .pro file will also be opened in the IDL Editor.
If the file is open in the IDL Editor, select Run Compile or click the Compile button on the toolbar. All routines within the file will be compiled, but none will be executed automatically.
Use the .RUN or .RNEW executive command at the IDL command line:
.RUN myFile
where myFile is the name of a .pro file located either in IDL's current working directory or in one of the directories specified by !PATH. All the routines included in the specified file will be compiled, and any $MAIN$ level programs will be executed automatically. If you are using the IDL Workbench, the .pro file will also be opened
in the IDL Editor.
Use the .RUN, .RNEW, or .COMPILE executive command with no filename argument to interactively create and compile a $MAIN$ level program. The Command line prompt changes from IDL > prompt toe - so that you can start entering the $MAIN$ level program. See Creating $MAIN$ Programs for additional details.
Note
Only .pro files can be compiled using the manual compilation mechanisms. Attempting to compile a SAVE ( .sav) file using one of these mechanisms will result in an error.
The "Hello World" example shown in Compiling Your Program has a user-defined procedure that contains a call to a user-defined function. If you enter the name of the user-defined procedure, hello_main, at the command line, IDL will compile and execute the hello_main procedure. After you provide the requested input, a
call to the hello_who function is made. IDL searches for hello_who.pro, and compiles and executes the function.

Compilation Errors
If an error occurs during compilation, the error is reported in the IDL Workbench Console view. For example, because the END statement is commented out, the following user-defined procedure will result in a compilation error:
PRO procedure_without_END
PRINT, 'Hello World'
;END
When trying to compile this procedure (after saving it into a file named procedure_without_END.pro), you will receive an error similar to the following the IDL Console view:
IDL> .COMPILE procedure_without_END
% End of file encountered before end of program.
At: C:\ITT\workspace\Default\procedure_without_end.pro, Line 4
% 1 Compilation error(s) in module PROCEDURE_WITHOUT_END.
Note
The IDL Editor displays a red dot to the left of each line that contains an error.

Setting Compilation Options


The COMPILE_OPT statement allows you to give the IDL compiler information that changes some of the default rules for compiling the function or procedure within which the COMPILE_OPT statement appears. The syntax of COMPILE_OPT is as follows:
COMPILE_OPT opt [,opt , ..., opt ]
1

where opt is any of the available options documented in "COMPILE_OPT" (IDL Reference Guide). These options allow you to change default values of true and false, hide routines from HELP, and reserve the use of parentheses for functions. See COMPILE_OPT for complete details.
n

2. Compiling Your Program


Before a procedure or function can be executed, it must be compiled. When a system routine (a function or procedure built into IDL, such as iPLOT) is called, either from the command line or from another procedure, IDL already knows about this routine and compiles it automatically. When a user-defined function or procedure is
called, IDL must find the routine and then compile it. Compilation can be either automatic or manual, as described below.

Warning
User-written functions must be defined before they are referenced, unless they:
1) Exist in the IDL !PATH.
2) Exist in a .pro file with the same name as the function.
3) Are reserved using the FORWARD_FUNCTION statement.
Defining the function is necessary to distinguish between function calls and subscripted variable references. See About Calling and Compiling Functions for details.

Automatic Compilation
When you enter the name of an uncompiled user-defined routine at the command line or call the routine from another routine, IDL searches the current directory for filename.pro, then filename.sav, where filename is the name of the specified routine. If no file is found in the current directory, IDL searches each directory
specified by !PATH. (For more on the IDL path, see "!PATH" (IDL Reference Guide).)
If no file matching the routine name is found, IDL issues an error:
% Attempt to call undefined procedure/function: 'routine'
where routine is the name of the routine you specified.
If a file is found, IDL automatically compiles the contents of the file up to the routine with the same name of the file (excluding the suffix), and then executes the routine. If the file does not contain the definition of a routine with the same name as the file, IDL issues the same error as when the no file with the correct name is found.
For example, suppose a file named proc1.pro contains the following procedure definitions:
PRO proc1
PRINT, 'This is proc1'
END
PRO proc2
PRINT, 'This is proc2'
END
Send us a comment on this topic

24-07-2014 17:21

Compiling Your Program

3 de 5

http://127.0.0.1:50893/help/advanced/print.jsp?topic=/com.rsi.idl.doc.co...

PRINT, 'This is proc3'


END
If you enter proc1 at the IDL command line, only the proc1 procedure will be compiled and executed. If you enter proc2 or proc3 at the command line, you will get an error informing you that you attempted to call an undefined procedure.
In general, the name of the IDL program file should be the same as the name of the last routine within the file. This last routine is usually the main routine, which calls all the other routines within the IDL program file (or, in the case of object classes, the class definition). Using this convention for your IDL program files ensures that all
the related routines within the file are compiled before being called by the last main routine.
Program files within the IDL distribution use this formatting style. For example, open the program file for the XLOADCT procedure, xloadct.pro, in the IDL Editor. This file is in the lib/utilities subdirectory of the IDL distribution. This file contains several routines. The main routine (XLOADCT) is at the bottom of the file.
When this file is compiled, the IDL Console notes all the routines within this file that are compiled:
IDL> .COMPILE XLOADCT
% Compiled module: XLCT_PSAVE.
% Compiled module: XLCT_ALERT_CALLER.
% Compiled module: XLCT_SHOW.
% Compiled module: XLCT_DRAW_CPS.
% Compiled module: XLCT_TRANSFER.
% Compiled module: XLOADCT_EVENT.
% Compiled module: XLOADCT.
Note that the main XLOADCT procedure is compiled last.

Tip
When editing a program file containing multiple functions and/or procedures in the IDL Editor, you can easily move to the desired function or procedure in the Outline view by selecting the Outline tab next to the Project Explorer tab. Select the function or procedure name from the list, and the Editor highlights and displays it.

Manual Compilation
There are several ways to manually compile a procedure or function.
Use the .COMPILE executive command at the IDL command line:
.COMPILE myFile

where myFile is the name of a .pro file located either in IDL's current working directory or in one of the directories specified by !PATH. All the routines included in the specified file will be compiled, but none will be executed automatically. If you are using the IDL Workbench, the .pro file will also be opened in the IDL Editor.
If the file is open in the IDL Editor, select Run Compile or click the Compile button on the toolbar. All routines within the file will be compiled, but none will be executed automatically.
Use the .RUN or .RNEW executive command at the IDL command line:
.RUN myFile
where myFile is the name of a .pro file located either in IDL's current working directory or in one of the directories specified by !PATH. All the routines included in the specified file will be compiled, and any $MAIN$ level programs will be executed automatically. If you are using the IDL Workbench, the .pro file will also be opened
in the IDL Editor.
Use the .RUN, .RNEW, or .COMPILE executive command with no filename argument to interactively create and compile a $MAIN$ level program. The Command line prompt changes from IDL > prompt toe - so that you can start entering the $MAIN$ level program. See Creating $MAIN$ Programs for additional details.
Note
Only .pro files can be compiled using the manual compilation mechanisms. Attempting to compile a SAVE ( .sav) file using one of these mechanisms will result in an error.
The "Hello World" example shown in Compiling Your Program has a user-defined procedure that contains a call to a user-defined function. If you enter the name of the user-defined procedure, hello_main, at the command line, IDL will compile and execute the hello_main procedure. After you provide the requested input, a
call to the hello_who function is made. IDL searches for hello_who.pro, and compiles and executes the function.

Compilation Errors
If an error occurs during compilation, the error is reported in the IDL Workbench Console view. For example, because the END statement is commented out, the following user-defined procedure will result in a compilation error:
PRO procedure_without_END
PRINT, 'Hello World'
;END
When trying to compile this procedure (after saving it into a file named procedure_without_END.pro), you will receive an error similar to the following the IDL Console view:
IDL> .COMPILE procedure_without_END
% End of file encountered before end of program.
At: C:\ITT\workspace\Default\procedure_without_end.pro, Line 4
% 1 Compilation error(s) in module PROCEDURE_WITHOUT_END.
Note
The IDL Editor displays a red dot to the left of each line that contains an error.

Setting Compilation Options


The COMPILE_OPT statement allows you to give the IDL compiler information that changes some of the default rules for compiling the function or procedure within which the COMPILE_OPT statement appears. The syntax of COMPILE_OPT is as follows:
COMPILE_OPT opt1 [,opt2, ..., optn]
where optn is any of the available options documented in "COMPILE_OPT" (IDL Reference Guide). These options allow you to change default values of true and false, hide routines from HELP, and reserve the use of parentheses for functions. See COMPILE_OPT for complete details.

3. Compiling Your Program


Before a procedure or function can be executed, it must be compiled. When a system routine (a function or procedure built into IDL, such as iPLOT) is called, either from the command line or from another procedure, IDL already knows about this routine and compiles it automatically. When a user-defined function or procedure is
called, IDL must find the routine and then compile it. Compilation can be either automatic or manual, as described below.

Warning
User-written functions must be defined before they are referenced, unless they:
1) Exist in the IDL !PATH.
2) Exist in a .pro file with the same name as the function.
3) Are reserved using the FORWARD_FUNCTION statement.
Defining the function is necessary to distinguish between function calls and subscripted variable references. See About Calling and Compiling Functions for details.

Automatic Compilation
When you enter the name of an uncompiled user-defined routine at the command line or call the routine from another routine, IDL searches the current directory for filename.pro, then filename.sav, where filename is the name of the specified routine. If no file is found in the current directory, IDL searches each directory
specified by !PATH. (For more on the IDL path, see "!PATH" (IDL Reference Guide).)
If no file matching the routine name is found, IDL issues an error:
% Attempt to call undefined procedure/function: 'routine'
where routine is the name of the routine you specified.
If a file is found, IDL automatically compiles the contents of the file up to the routine with the same name of the file (excluding the suffix), and then executes the routine. If the file does not contain the definition of a routine with the same name as the file, IDL issues the same error as when the no file with the correct name is found.
For example, suppose a file named proc1.pro contains the following procedure definitions:
PRO proc1
PRINT, 'This is proc1'
END
PRO proc2
PRINT, 'This is proc2'
END
PRO proc3
PRINT, 'This is proc3'
END
If you enter proc1 at the IDL command line, only the proc1 procedure will be compiled and executed. If you enter proc2 or proc3 at the command line, you will get an error informing you that you attempted to call an undefined procedure.
In general, the name of the IDL program file should be the same as the name of the last routine within the file. This last routine is usually the main routine, which calls all the other routines within the IDL program file (or, in the case of object classes, the class definition). Using this convention for your IDL program files ensures that all
the related routines within the file are compiled before being called by the last main routine.
Program files within the IDL distribution use this formatting style. For example, open the program file for the XLOADCT procedure, xloadct.pro, in the IDL Editor. This file is in the lib/utilities subdirectory of the IDL distribution. This file contains several routines. The main routine (XLOADCT) is at the bottom of the file.
When this file is compiled, the IDL Console notes all the routines within this file that are compiled:
IDL> .COMPILE XLOADCT
% Compiled module: XLCT_PSAVE.
% Compiled module: XLCT_ALERT_CALLER.
% Compiled module: XLCT_SHOW.
% Compiled module: XLCT_DRAW_CPS.
% Compiled module: XLCT_TRANSFER.
% Compiled module: XLOADCT_EVENT.
% Compiled module: XLOADCT.
Note that the main XLOADCT procedure is compiled last.

Tip
When editing a program file containing multiple functions and/or procedures in the IDL Editor, you can easily move to the desired function or procedure in the Outline view by selecting the Outline tab next to the Project Explorer tab. Select the function or procedure name from the list, and the Editor highlights and displays it.

Manual Compilation
There are several ways to manually compile a procedure or function.
Use the .COMPILE executive command at the IDL command line:
.COMPILE myFile

where myFile is the name of a .pro file located either in IDL's current working directory or in one of the directories specified by !PATH. All the routines included in the specified file will be compiled, but none will be executed automatically. If you are using the IDL Workbench, the .pro file will also be opened in the IDL Editor.
Send us a comment on this topic

24-07-2014 17:21

Compiling Your Program

4 de 5

http://127.0.0.1:50893/help/advanced/print.jsp?topic=/com.rsi.idl.doc.co...

Use the .RUN or .RNEW executive command at the IDL command line:
.RUN myFile
where myFile is the name of a .pro file located either in IDL's current working directory or in one of the directories specified by !PATH. All the routines included in the specified file will be compiled, and any $MAIN$ level programs will be executed automatically. If you are using the IDL Workbench, the .pro file will also be opened
in the IDL Editor.
Use the .RUN, .RNEW, or .COMPILE executive command with no filename argument to interactively create and compile a $MAIN$ level program. The Command line prompt changes from IDL > prompt toe - so that you can start entering the $MAIN$ level program. See Creating $MAIN$ Programs for additional details.
Note
Only .pro files can be compiled using the manual compilation mechanisms. Attempting to compile a SAVE ( .sav) file using one of these mechanisms will result in an error.
The "Hello World" example shown in Compiling Your Program has a user-defined procedure that contains a call to a user-defined function. If you enter the name of the user-defined procedure, hello_main, at the command line, IDL will compile and execute the hello_main procedure. After you provide the requested input, a
call to the hello_who function is made. IDL searches for hello_who.pro, and compiles and executes the function.

Compilation Errors
If an error occurs during compilation, the error is reported in the IDL Workbench Console view. For example, because the END statement is commented out, the following user-defined procedure will result in a compilation error:
PRO procedure_without_END
PRINT, 'Hello World'
;END
When trying to compile this procedure (after saving it into a file named procedure_without_END.pro), you will receive an error similar to the following the IDL Console view:
IDL> .COMPILE procedure_without_END
% End of file encountered before end of program.
At: C:\ITT\workspace\Default\procedure_without_end.pro, Line 4
% 1 Compilation error(s) in module PROCEDURE_WITHOUT_END.
Note
The IDL Editor displays a red dot to the left of each line that contains an error.

Setting Compilation Options


The COMPILE_OPT statement allows you to give the IDL compiler information that changes some of the default rules for compiling the function or procedure within which the COMPILE_OPT statement appears. The syntax of COMPILE_OPT is as follows:
COMPILE_OPT opt [,opt , ..., opt ]
1

where opt is any of the available options documented in "COMPILE_OPT" (IDL Reference Guide). These options allow you to change default values of true and false, hide routines from HELP, and reserve the use of parentheses for functions. See COMPILE_OPT for complete details.
n

4. Compiling Your Program


Before a procedure or function can be executed, it must be compiled. When a system routine (a function or procedure built into IDL, such as iPLOT) is called, either from the command line or from another procedure, IDL already knows about this routine and compiles it automatically. When a user-defined function or procedure is
called, IDL must find the routine and then compile it. Compilation can be either automatic or manual, as described below.

Warning
User-written functions must be defined before they are referenced, unless they:
1) Exist in the IDL !PATH.
2) Exist in a .pro file with the same name as the function.
3) Are reserved using the FORWARD_FUNCTION statement.
Defining the function is necessary to distinguish between function calls and subscripted variable references. See About Calling and Compiling Functions for details.

Automatic Compilation
When you enter the name of an uncompiled user-defined routine at the command line or call the routine from another routine, IDL searches the current directory for filename.pro, then filename.sav, where filename is the name of the specified routine. If no file is found in the current directory, IDL searches each directory
specified by !PATH. (For more on the IDL path, see "!PATH" (IDL Reference Guide).)
If no file matching the routine name is found, IDL issues an error:
% Attempt to call undefined procedure/function: 'routine'
where routine is the name of the routine you specified.
If a file is found, IDL automatically compiles the contents of the file up to the routine with the same name of the file (excluding the suffix), and then executes the routine. If the file does not contain the definition of a routine with the same name as the file, IDL issues the same error as when the no file with the correct name is found.
For example, suppose a file named proc1.pro contains the following procedure definitions:
PRO proc1
PRINT, 'This is proc1'
END
PRO proc2
PRINT, 'This is proc2'
END
PRO proc3
PRINT, 'This is proc3'
END
If you enter proc1 at the IDL command line, only the proc1 procedure will be compiled and executed. If you enter proc2 or proc3 at the command line, you will get an error informing you that you attempted to call an undefined procedure.
In general, the name of the IDL program file should be the same as the name of the last routine within the file. This last routine is usually the main routine, which calls all the other routines within the IDL program file (or, in the case of object classes, the class definition). Using this convention for your IDL program files ensures that all
the related routines within the file are compiled before being called by the last main routine.
Program files within the IDL distribution use this formatting style. For example, open the program file for the XLOADCT procedure, xloadct.pro, in the IDL Editor. This file is in the lib/utilities subdirectory of the IDL distribution. This file contains several routines. The main routine (XLOADCT) is at the bottom of the file.
When this file is compiled, the IDL Console notes all the routines within this file that are compiled:
IDL> .COMPILE XLOADCT
% Compiled module: XLCT_PSAVE.
% Compiled module: XLCT_ALERT_CALLER.
% Compiled module: XLCT_SHOW.
% Compiled module: XLCT_DRAW_CPS.
% Compiled module: XLCT_TRANSFER.
% Compiled module: XLOADCT_EVENT.
% Compiled module: XLOADCT.
Note that the main XLOADCT procedure is compiled last.

Tip
When editing a program file containing multiple functions and/or procedures in the IDL Editor, you can easily move to the desired function or procedure in the Outline view by selecting the Outline tab next to the Project Explorer tab. Select the function or procedure name from the list, and the Editor highlights and displays it.

Manual Compilation
There are several ways to manually compile a procedure or function.
Use the .COMPILE executive command at the IDL command line:
.COMPILE myFile

where myFile is the name of a .pro file located either in IDL's current working directory or in one of the directories specified by !PATH. All the routines included in the specified file will be compiled, but none will be executed automatically. If you are using the IDL Workbench, the .pro file will also be opened in the IDL Editor.
If the file is open in the IDL Editor, select Run Compile or click the Compile button on the toolbar. All routines within the file will be compiled, but none will be executed automatically.
Use the .RUN or .RNEW executive command at the IDL command line:
.RUN myFile
where myFile is the name of a .pro file located either in IDL's current working directory or in one of the directories specified by !PATH. All the routines included in the specified file will be compiled, and any $MAIN$ level programs will be executed automatically. If you are using the IDL Workbench, the .pro file will also be opened
in the IDL Editor.
Use the .RUN, .RNEW, or .COMPILE executive command with no filename argument to interactively create and compile a $MAIN$ level program. The Command line prompt changes from IDL > prompt toe - so that you can start entering the $MAIN$ level program. See Creating $MAIN$ Programs for additional details.
Note
Only .pro files can be compiled using the manual compilation mechanisms. Attempting to compile a SAVE ( .sav) file using one of these mechanisms will result in an error.
The "Hello World" example shown in Compiling Your Program has a user-defined procedure that contains a call to a user-defined function. If you enter the name of the user-defined procedure, hello_main, at the command line, IDL will compile and execute the hello_main procedure. After you provide the requested input, a
call to the hello_who function is made. IDL searches for hello_who.pro, and compiles and executes the function.

Compilation Errors
If an error occurs during compilation, the error is reported in the IDL Workbench Console view. For example, because the END statement is commented out, the following user-defined procedure will result in a compilation error:
PRO procedure_without_END
PRINT, 'Hello World'
;END
When trying to compile this procedure (after saving it into a file named procedure_without_END.pro), you will receive an error similar to the following the IDL Console view:
IDL> .COMPILE procedure_without_END
% End of file encountered before end of program.
At: C:\ITT\workspace\Default\procedure_without_end.pro, Line 4
% 1 Compilation error(s) in module PROCEDURE_WITHOUT_END.
Note
The IDL Editor displays a red dot to the left of each line that contains an error.

Setting Compilation Options


Send us a comment on this topic
The COMPILE_OPT statement allows you to give the IDL compiler information that changes some of the default rules for compiling the function or procedure within which the COMPILE_OPT statement appears. The syntax of COMPILE_OPT is as follows:

24-07-2014 17:21

Compiling Your Program

5 de 5

http://127.0.0.1:50893/help/advanced/print.jsp?topic=/com.rsi.idl.doc.co...

COMPILE_OPT opt [,opt , ..., opt ]


1

where opt is any of the available options documented in "COMPILE_OPT" (IDL Reference Guide). These options allow you to change default values of true and false, hide routines from HELP, and reserve the use of parentheses for functions. See COMPILE_OPT for complete details.
n

Send us a comment on this topic

24-07-2014 17:21

Vous aimerez peut-être aussi