Subversion Repositories wimsdev

Rev

Rev 20 | Rev 835 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

!! -*- coding: iso-8859-1 -*-
!if $wims_read_parm!=slib_header
 !goto proc
!endif
slib_title=make a representation of a physical quantity with a given number of significative digits
slib_parms=4\
1m, physical quantity\
3, number of significative digits\
 , optional: order of magnitude of the digit before the decimal dot; only valid if the quantity is dimensionless, just a number with no unit.\
 , optional: the desired physical unit to show (possibly a multiple or sub-multiple).
slib_author=Georges Khaznadar
slib_out=the physical quantity with the right number of digits, or a numeric value which would be equal to the result with the right number of digits.
slib_comment=the default means: 1 meter with three significative digits. The last example shows how the numeric value may lack some trailing zeros after the dot.<p><b>Known bug:</b><br>if the third parameter is used, the output may have a wrong syntax. Ensure that the resulting number has its decimal dot near its significant digits.
slib_example=1.2345A,2\
1.2V,5\
12,3\
12,3,4\
0.50A.h\
1800C,3,,A.h\
1.8°,5,,rad
!exit

:proc
slib_data=$wims_read_parm
!distribute items $slib_data  into slib_qty, slib_sig, slib_order, slib_wanted_unit

!default slib_qty=1m
!default slib_sig=3
!default slib_order=
!default slib_wanted_unit=

units_option=o
slib_u= !charcnt $slib_wanted_unit
!if $slib_u > 0
  slib_out= !exec units-filter $(slib_qty)#$(slib_sig):$(slib_wanted_unit)
!else
  slib_out= !exec units-filter $(slib_qty)#$(slib_sig)
!endif
slib_n= !charcnt $slib_order
!if $slib_n > 0
 slib_test= !eval $slib_out/1e$slib_order
 !if $slib_test <> NaN
  slib_out=$(slib_test)e$slib_order
 !endif
!endif