Pergunta

Usually when I want to compile a file I can use

.compile /home/.../file.pro

But assume I have this path in variable only. Then the code below

path = '/home/.../file.pro'
.compile path

returns error because compiler thinks path is a file and it can't find it. How can I avoid this?

Foi útil?

Solução

What you want to use is the RESOLVE_ROUTINE command. It takes the file name as a string, (So you can pass it inside a variable), and has a few keywords; IS_FUNCTION being the one you're probably going to need to use the most. Use /IS_FUNCTION to compile functions, and leave it out to compile procedures.

Here's the documentation:

http://www.physics.nyu.edu/grierlab/idl_html_help/R45.html#wp1073539

Outras dicas

It's a little goofy that you have to do this so often in IDL, but another strategy for mixing variables and executive commands (.run etc.) is to use the IDL_IDLBridge() object.

oBridge = IDL_IDLBridge()
oBridge->execute, '.compile ' + some_var

The difference between this and CALL_PROCEDURE or CALL_FUNCTION or EXECUTE is that the IDL_IDLBridge instantiates an interactive process, or command line like environment. That means you can include executive commands, and therefore embed a .COMPILE inside of a foreach loop that is iterating over the results of a file search to compile all .PRO files in a directory.

You can also use this to package up multiple .PRO files into a .SAV file. Note that the IDL_IDLBridge is a child process, so you won't get access to whatever it has compiled, but you can use SAVE/RESTORE with a passed variable.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top