Cloudy night shows that it's Magic Time
What does a performance index represent?

Experts show how to use shell from MPE

I am attempting to convert a string into a number for use in timing computations inside an MPEiX job stream. In the Posix shell I can do this:

/SYS/PUB $ echo "21 + 21" | bc
42
/SYS/PUB $

But from the MPE command line this returns blank:

run sh.hpbin.sys;info='-c echo "21 + 21" | bc'

But why? I would like to calculate a formula with containing factors of arbitrary decimal precision and assign the integer result to a variable.  Inside the shell I can do this:

shell/iX> x=$(echo "31.1 * 4.7" | bc)
shell/iX> echo $x
146.1
shell/iX> x=$(echo "31.1 * 4.7 + 2" | bc)
shell/iX> echo $x
148.1
shell/iX> x=$(echo "31.1 * 4.70 + 2" | bc)
shell/iX> echo $x
148.17

What I would like to do is the same thing albeit at the MPE : prompt instead, and assign the result to an MPE variable.

Donna Hofmeister of Allegro replies

CI numeric variables only handle integers (whole numbers).  If your answer needs to be expressed with a decimal value (like 148.17 as shown above) you might be able to do something to express it as a string to the CI (setvar string_x "!x").

This is really sounding like something that's best handled by another solution -- like a compiled program or maybe a perl script.

For what it’s worth, the perl bundle that's available from Allegro has the MPE extensions included.  This means you could do take advantage of perl's 'getoptions' as well as 'hpcicmds' (if you really need to get your result available at the CI level.

Barry Lake of Allegro adds

The answer to your question of why, for the record, is that the first token is what's passed to the shell as the command to execute. In this case, the first token is simply "echo", and the rest of the command is either eaten or ignored.

To fix it, the entire command needs to be a single string passed to the shell, as in:

:run sh.hpbin.sys; info='-c "echo 21 + 21 | bc"'
 42
 END OF PROGRAM
 :

And if you want to clean that up a bit you can use XEQ instead of RUN:

 :xeq sh.hpbin.sys '-c "echo 21 + 21 | bc"'
 42

Or, you can do it with, for example, Vesoft's MPEX:

 : mpex

 MPEX/3000  34N60120  (c) VESOFT Inc, 1980  7.5  04:07407  For help type 'HELP'

 % setvar pi 3.14159
 % setvar r  4.5
 % calc !pi * !r * !r
            63.617191
 % setvar Area !pi * !r * !r
 % showvar Area
 AREA =            63.617191
 % exit

 END OF PROGRAM
 :

But the only thing I want is to be able to use a complied program which handles arbitrary precision variables from inside a job stream — such that I can return the integer part of the result to an MPE/iX variable.

Barry Lake replies

If you're happy with truncating your arithmetic result — that is, lopping off everything to the right of the decimal point, including the decimal point — then here's one way to do it:

/SYS/PUB $ echo "31.1 * 4.7" | bc
 146.1
 /SYS/PUB $ echo "31.1 * 4.7" | bc | cut -f1 -d.
 146
 /SYS/PUB $ callci setvar result $(echo "31.1 * 4.7" | bc | cut -f1 -d.)
 /SYS/PUB $ callci showvar result
 RESULT = 146
 /SYS/PUB $ exit

 END OF PROGRAM
 : showvar result
 RESULT = 146
 :

Perfect! Thank you. And this construct accepts CI VAR values as I require.

:SETVAR V1 "31.1"
:SETVAR v2 "4.7"
:XEQ SH.HPBIN.SYS;INFO='-c "callci setvar result $(echo ""!V1 * !V2"" | bc |
cut -f1 -d.)"'
:SHOWVAR RESULT
RESULT = 146

Comments