Re: parser ? [message #10031] |
Tue, 07 October 1997 00:00 |
R. Bauer
Messages: 137 Registered: November 1996
|
Senior Member |
|
|
Martin Schultz wrote:
>
> Hi,
>
> now that I have written this little widget "calculator" which works
> really fine and computes almost anything I want (which is not much
> more than the occasional +,-,*,/ or logarithm, I must admit), I am
> slowly getting sick of clicking my way through a bit more nested
> formulas, especially when I have to repeat the same calculation with
> different data sets. I already designed my calculator to return a
> formatted string describing the arithmetic operations that it performed,
> but now I am looking for a way to read these strings back in and do
> calculations as a batch job. Is there any way to use the build in parser
> of IDL ? Or has anyone written something like this (which is well enough
> documented so that I could adapt it to my needs) ? I have also briefly
> thought about writing out the equations in a file tmp_func.pro or
> something alike, and then use EXECUTE (or whatever would serve the
> purpose) in order to compile and call the procedure/function that has
> been automatically produced.
>
> Any ideas appreciated,
> Thanks,
> Martin.
>
>
Hi Martin,
I have done something in the same way to calculate units.
Here is my idea how to handle it:
value=5000.
term=trans_unit('cm','km')
help,term
TERM STRING = '*0.0100/1000.'
IF strpos(term,')') GE 0 THEN a=execute('result=(value(*)'+term) $
ELSE $
a=execute('result=value(*)'+term)
IF n_elements(result) EQ 1 THEN result = (result)(0)
help,result
RESULT FLOAT = 0.0500000
Re
--
R.Bauer
Institut fuer Stratosphaerische Chemie (ICG-1)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
|
|
|