Internal: How to pass command line arguments to IDL batch mode and runtime applications on UNIX
Anonym
IDL does not allow users to directly pass in command line arguments to be interpreted by their code. To get around this, users can write a shell script that sets environment variables based on the command line arguments, and use IDL’s GETENV() function to retrieve the values from within their IDL code.
In many cases, it would be useful to be able to pass command line arguments to an IDL runtime application. IDL does not directly support command line arguments in this manner, but it is easy to work around by writing a shell script that converts the command line arguments into environment variables (which are easy to retrieve from IDL). To do this, you should write a shell script that converts the command line arguments into environment variables, and then starts the IDL program. For example, in tcsh or csh you would write:
#!/bin/csh
setenv PARAM_ONE $1
setenv PARAM_TWO $2
#etc…
#now start the runtime app.
idl -rt=runtime.sav
#or for batch mode:
#idl batch.pro
#end
The syntax will vary depending on what shell you decide to use. You should also be careful to choose unique names for your environment variables, so that they do not confuse other programs. For example, changing the value of the IDL_DIR, LM_LICENSE_FILE, or DISPLAY environment variables could cause unexpected results when IDL starts.
Now, to retrieve the values in your IDL code you would just call GETENV():
param_one = GETENV(‘PARAM_ONE’) ;create an IDL string variable set to the value of PARAM_ONESolution: