Re: [patch] Add physical units support for comedilib demo programs

On 19/07/06 21:51, David MacMahon wrote:
> The attached patch adds a "-p" option to common.c that programs can use
> to decide whether to output raw values or physical values.  The patch
> also includes modifications to the cmd and inp programs to use this
> flag.  Here is what the output looks like without -p and with -p...
> 
> $ ./cmd -f /dev/comedi1 -s 0 -r 1 -g -c 16 -n 5 -N 4 2>/dev/null
> 50959 48145 49835 49755 50823
> 50961 48146 49838 49757 50821
> 50957 48147 49837 49749 50823
> 50961 48143 49833 49754 50823
> 
> $ ./cmd -f /dev/comedi1 -s 0 -r 1 -g -c 16 -n 5 -N 4 -p 2>/dev/null
> 2.77676 2.34615 2.60494 2.59182 2.75494
> 2.77661 2.34585 2.60464 2.59289 2.75433
> 2.77646 2.3463  2.60418 2.59197 2.75555
> 2.77646 2.34585 2.60388 2.59319 2.75525
> 
> $ ./inp -f /dev/comedi1 -s 0 -r 1 -g -c 16
> 50960
> 
> $ inp -f /dev/comedi1 -s 0 -r 1 -g -c 16 -p
> 2.77523 V
> 
> $ inp -f /dev/comedi1 -s 0 -r 1 -g -c 16 -v
> measuring device=/dev/comedi1 subdevice=0 channel=16 range=1 analog
> reference=0
> 50957
> 
> $ inp -f /dev/comedi1 -s 0 -r 1 -g -c 16 -p -v
> measuring device=/dev/comedi1 subdevice=0 channel=16 range=1 analog
> reference=0
> [0,65535] -> [-5,5]
> 2.77554 V (50957 raw units)
> 
> FWIW, the patch also sets OOR behavior to OOR_NUMBER for cmd and OOR_NAN
> for inp...
> 
> $ inp -f /dev/comedi1 -s 0 -r 4 -g -c 16 -p
> Out of range [-0.5,0.5]
> 
> $ cmd -f /dev/comedi1 -s 0 -r 4 -g -c 16 -n 5 -N 4 -p 2>/dev/null
> 0.5     0.5     0.5     0.5     0.5
> 0.5     0.5     0.5     0.5     0.5
> 0.5     0.5     0.5     0.5     0.5
> 0.5     0.5     0.5     0.5     0.5
> 
> 
> I chose OOR_NUMBER for cmd to make it easier to import the data dump
> into other programs (e.g. octave).  You'll also notice that I used a tab
> instead of a space as the delimiter in cmd's physical output (raw output
> remains unchanged).  It lines things up more neatly, but I don't really
> care whether it's a space or tab.  Might also want to include a '+' in
> the format specifier to line up + and - values better.

It all looks jolly useful and uncontroversial, thanks!  I've applied to
CVS with a minor change to that format string.  I changed it from this:

		printf("%.6g\t",physical_value);

to this:

		printf("%#8.6g ",physical_value);

The '#' pads the value out with trailing zeroes.  The field width of 8
is sufficient for 6 digits plus decimal point and a possible '-' sign.
It should all line up nicely (well, the decimal points might not line
up) unless any values need exponents, which is unlikely.

-- 
-=( Ian Abbott _at_ MEV Ltd.    E-mail: <abbotti_at_mev.co.uk>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-

Received on 2006-07-20Z11:09:40