COMPILE Procedure
Saves compiled user-written procedures and functions in a file.
 
note
If large LONG integers are hard-coded into a routine, the COMPILE command will fail even if !XDR_LONG is set to 64, i.e., .cpr files cannot contain hard-coded LONG integers greater than 231–1. The reason for this restriction is to ensure that any .cpr file runs correctly on 32-bit and 64-bit platforms.
Usage
COMPILE, routine1 [ , ..., routinen ]
Input Parameters
routinei—A string containing the name of the compiled function or procedure that you want to save.
Keywords
All—If nonzero, all currently compiled user-written functions and procedures are saved.
Filename—Specifies the name of a file in which to save specified compiled routines. By default, a file named  routine.cpr is saved in the current working directory.
Verbose—If present and nonzero, prints a message for each saved function and procedure.
Discussion
The COMPILE procedure saves compiled routines in a format (XDR) that is recognized by all the platforms on which PV-WAVE runs.
When a compiled routine is called in a PV‑WAVE application, the directories in the !Path system variable are searched for a .cpr file with the same name as the called routine. If the .cpr file is found, it is loaded and immediately executed. If a .cpr file is not found, PV‑WAVE searches !Path for a .pro file with the same name. If the .pro file is found, it is executed instead.
With a special runtime license, saved compiled applications can be executed from the operating system level using the runtime mode flag. For example:
wave -r filename
The -r flag signifies “runtime” mode. It is possible to set an environment variable so that the -r flag is not needed.
To do this enter the following command:
(UNIX) setenv WAVE_FEATURE_TYPE RT
(WIN) set WAVE_FEATURE= RT
Then, you can execute compiled routines from the operating system prompt by entering:
wave filename
Note that you do not use the .cpr extension when you execute compiled routines from the operating system prompt.
 
note
To execute a runtime mode application, you must have a runtime license. Without a runtime license for PV‑WAVE, you will be unable to start PV‑WAVE in runtime mode as described in this section. For information on obtaining a runtime license for PV‑WAVE, please contact Rogue Wave.
Example 1
This example demonstrates how to save a single compiled procedure. Assume the following procedure is saved in the current working directory in the file log_plot.pro:
PRO log_plot
   x = FLTARR(256)
   x(80:120) = 1
   freq = FINDGEN(256)
   freq = freq < (256-freq)
   fil = 1. / (1+(freq / 20) ^2)
   PLOT_IO, freq, ABS(FFT(X,1)), Xtitle =  $
      'Relative Frequency', Ytitle ='Power', Xstyle = 1
   OPLOT, freq, fil
   WAIT, 3
   WDELETE
END
Now start PV‑WAVE. At the WAVE> prompt:, compile the procedure with .RUN, and save the compiled procedure in a file using the COMPILE procedure. Then, delete the compiled procedure from memory and run the compiled procedure that is stored in the file.
; Compile the procedure.
.RUN log_plot
; Save the compiled procedure. The file log_plot.cpr is created.
; This contains the compiled procedure.
COMPILE, 'log_plot'
; Verify that log_plot.cpr was created.
IF STRMATCH(GETPLATFORM(), 'win') THEN cmd='dir log_plot.cpr' $
ELSE cmd='ls log_plot.cpr'
SPAWN, cmd
; Delete the log_plot procedure that is currently in memory.
DELPROC, 'log_plot'
; Run the compiled procedure log_plot.cpr.
log_plot
At the system prompt, enter the following:
% wave -r -nohome log_plot
This command runs the compiled procedure from the operating system prompt. The -r flag signifies “runtime” mode.
Example 2
This example demonstrates how several files from a single application can be compiled and saved in one file. This simple application creates a Command Tool widget and includes three separate callback routines.
Place the following code in a file called comtool.pro, and save the file in the current working directory:
PRO CbuttonCB, wid, data
   command = WwCommand(wid, 'CommandOK',  $
      'CommandDone', Position=[300,300],  $
      Title = 'Command Entry Window')
END
 
PRO CommandOK, wid, shell
   value = WwGetValue(wid)
   PRINT, value
END
 
PRO CommandDone, wid, shell
   status = WwSetValue(shell, /Close)
END
 
PRO ComTool
   top=WwInit('example2', 'Examples', layout)
   button=WwButtonBox(layout, 'Command', 'CbuttonCB')
   status=WwSetValue(top, /Display)
   WwLoop
END
Now start PV‑WAVE and enter the following commands at the WAVE> prompt:
; Compile the application.
.RUN comtool
; Save the compiled procedures in the file comtool.cpr. The file
; comtool.cpr is created. This file contains compiled procedures.
COMPILE, 'ComTool', 'CbuttonCB', 'CommandOK', 'CommandDone',  $
   Filename = 'comtool'
; Verify that comtool.cpr was created.
IF STRMATCH(GETPLATFORM(), 'win') THEN cmd='dir comtool.cpr' $
ELSE cmd='ls comtool.cpr'
SPAWN, cmd
At the system prompt, enter the following:
% wave -r comtool
This command runs the compiled comtool application from the operating system command line. Note that the filename must be the same as the main procedure in the file for the application to run successfully from the operating system prompt. The -r flag signifies “runtime” mode.
See Also
See the PV‑WAVE Programmer’s Guide for more information about runtime mode.