Rev 475 | Rev 3265 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
475 | georgesk | 1 | !! -*- coding: iso-8859-1 -*- |
20 | reyssat | 2 | !if $wims_read_parm!=slib_header |
3 | !goto proc |
||
4 | !endif |
||
5 | slib_title=make a representation of a physical quantity with a given number of significative digits |
||
6 | slib_parms=4\ |
||
7 | 1m, physical quantity\ |
||
8 | 3, number of significative digits\ |
||
9 | , optional: order of magnitude of the digit before the decimal dot; only valid if the quantity is dimensionless, just a number with no unit.\ |
||
10 | , optional: the desired physical unit to show (possibly a multiple or sub-multiple). |
||
11 | slib_author=Georges Khaznadar |
||
12 | 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. |
||
13 | 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. |
||
14 | slib_example=1.2345A,2\ |
||
15 | 1.2V,5\ |
||
16 | 12,3\ |
||
17 | 12,3,4\ |
||
18 | 0.50A.h\ |
||
475 | georgesk | 19 | 1800C,3,,A.h\ |
20 | 1.8°,5,,rad |
||
20 | reyssat | 21 | !exit |
22 | |||
23 | :proc |
||
24 | slib_data=$wims_read_parm |
||
25 | !distribute items $slib_data into slib_qty, slib_sig, slib_order, slib_wanted_unit |
||
26 | |||
27 | !default slib_qty=1m |
||
28 | !default slib_sig=3 |
||
29 | !default slib_order= |
||
30 | !default slib_wanted_unit= |
||
31 | |||
32 | units_option=o |
||
33 | slib_u= !charcnt $slib_wanted_unit |
||
34 | !if $slib_u > 0 |
||
35 | slib_out= !exec units-filter $(slib_qty)#$(slib_sig):$(slib_wanted_unit) |
||
36 | !else |
||
37 | slib_out= !exec units-filter $(slib_qty)#$(slib_sig) |
||
38 | !endif |
||
39 | slib_n= !charcnt $slib_order |
||
40 | !if $slib_n > 0 |
||
41 | slib_test= !eval $slib_out/1e$slib_order |
||
42 | !if $slib_test <> NaN |
||
835 | georgesk | 43 | !if $slib_order <> 0 |
44 | slib_out=$(slib_test)e$slib_order |
||
45 | !else |
||
46 | slib_out=$slib_test |
||
47 | !endif |
||
20 | reyssat | 48 | !endif |
49 | !endif |
||
50 | |||
51 |