X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 04 Jul 2013 04:17 AM by  anon
Injecting code from an external file?
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
04 Jul 2013 04:17 AM
    Hi, I am trying to code an extension which would apply a logical expression to a serie of data; this expression is not known in advance and the extension should take it from an external file provided by the user. Is there any way of "injecting" this external code/logical expression into the main flow of the program while it is running? Also, I have thought about taking an expression in another language (e.g. in SQL) to attempt an automatized "translation", but to achieve this I would need some macro definition (like #define in C++) and I cannot find an equivalent. Has IDL a way to do so? Thank you very much, Juan

    Deleted User



    New Member


    Posts:
    New Member


    --
    23 Jul 2013 02:41 PM
    Hi Juan, What do you mean by "logical expression"? If you are thinking of applying an expression, like an function or equation, to some data, but the expression is written as a text form (something like symbolic expression), IDL will not be able to interpret it just like that. You will need to write the expression in IDL. I guess what you could do is to input the expression into IDL as a string of characters. Then, you will need to break the string into it's components and build the expression within IDL. String manipulation is explain here: http://www.exelisvis.com/docs/String_... I hope this helps. Cheers. Fernando

    Deleted User



    New Member


    Posts:
    New Member


    --
    01 Aug 2013 04:00 PM
    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
    You are not authorized to post a reply.