Hi,
I have to manipulate a data file which say reads like this
{$index $value $error_on_value}

aa 4.56 0.7
bb 123.456 0.00987
cc 987654 321
.
.
in easily human readable format of type

aa 4.6(7)
bb 123.456(1)
cc 9.877(3)e+05

value rounded to 4.6 with error of 0.7 on the last significant digit.
In 2nd row, error is rounded off
in 3rd, exponential form suits better for this. but this is optional. (In awk, its printf with "%g" option )


I tried to play with awk, where I formatted first with say
'{printf "%d\t1.3e\t%1.0e\n",$1,$2,$3}'
then can manipulate to get it dirty way to the type mentioned in row 3.

I am sure there is smart way to do this. If I get any suggestion, it would greatly improve my experience, so thanks in advance.

ps: My actual data file has (2n+1) number of columns. 1st being index, then even ones are value and odd ones are error on that. Should there be smart way to ask script to sense "n" (say using awk NF), and aumate that, that would be cool.

Let me try a bit to clarify how I want to round off etc.

Suppose your a output file that contains value of some observable and error-bar on that. look like this:
$cat datafile.txt
123.4567 0.0098
.
.

re-writing the first row
123.4567
000.0098

should be read as 123.46(1)... If you ask me to read it, for better human comprehension.

error determine at which place the rounding should occur in the mean/main value(1st col). this case is little non-trivial as error itself is rounded off to nearer value. We look for only one (significant) digit from error, that rounds 0.0098 as 0.01. Now in the mean value (123.4567) its useless to go with precision better than 0.01. so we would round off the value upto two digits after decimal. that makes it 123.46.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.