Hi Juan,
There is a way to do this but there are some restrictions. The file must be in an IDL default search path and it must have been resolved at least once, prior to running in the code it is injected into. The contents of the file can change after resolution though, I'll explain what I mean:
The following code creates a function, then passes data to it:
pro test
name = 'addFive'
openw, lun, name + '.pro', /get_lun
printf, lun, 'function ' + name + ', input'
printf, lun, ''
printf, lun, 'return, input + 5'
printf, lun, ''
printf, lun, 'end'
close, lun
free_lun, lun
resolve_routine, name, /is_function
print, addFive(4)
end
When I run this code, it outputs 9 to the console. I could edit that print statement and make the function do whatever I want to the input, then run it again and it will produce the desired output. However, if the compiler has never seen the addFive.pro routine before, it can't resolve it and use it in the same routine. One way around this is to have this be some general file name like externalFunction.pro in a default directory, and compile it once, that way, IDL already knows it's there.
The resolve_routine procedure can recompile a file, even if it's already defined. So if some other procedure has modified this file, the function that is called will be updated before calling. The reason it needs to be in a default path is because resolve_routine can't except paths in the string you pass to it.
Hope that helps,
Mike
|