Google FeedBurner is phasing out its RSS-to-email subscription service. While we are currently working on the implementation of a new system, you may experience an interruption in your email subscription service.
Please stay tuned for further communications.
I would like to generate a command as a string, perhaps based on local variables or something, and then run it in Ocean _as if_ I typed the contents of the string at an Ocean prompt. If I denote the function I am looking for as OCN_COMMAND( input_string ) then running:
OCN_COMMAND( "vtest = 5" )
will run, and after this there will be a variable named vtest with a value of 5.
A better example could be:
sprintf( str_to_run, "vtest = %d + %d", 5, 6 )
OCN_COMMAND( str_to_run )
after these two lines, a variable vtest would be created and have the value of 11.
I have seen similar abilities to run UNIX commands with the system( ) command, but not a means to generate commands within Ocean and then have it executed
Thanks in advance!
evalstring() will do this. In general building code by creating strings and evaluating it is not usually the right way to do anything - I've seen all sorts of odd code done that way when there is…
evalstring() will do this. In general building code by creating strings and evaluating it is not usually the right way to do anything - I've seen all sorts of odd code done that way when there is a better approach. It would be good to know precisely what you are wanting to do here - the above is a very general description rather than the high level goal.
This is exactly what I wanted, thank you! Clearly I did not know that this function already existed. As a more real-world example, sometimes when I am post-processing a set of data I may want to create a waveform with a more meaningful name, such as vout_n40_0p9 (representing an output waveform at a particular temperature corner), and within the post-processing loop I can create this meaningful string name. Thus now I could form the string then use evalstring() to execute the command, so that later I can: plot( vout_n40_0p9 ) and know exactly which corner that pertains to.
In that case, I would do:
sprintf(name "..." ...) ; so that name="vout_n40_0p9"measurement=...set(stringToSymbol(name) measurement)
That way you're just using the set() function to set the variable. That would be cleaner than building commands as strings and then evaluating them.