data format from (4.56 0.7) -> 4.6(7) awk?!

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 automate that, that would be cool.

Please look at this problem, and let me know if something can be done or not clear. I am shamelessly bumping it up, for I need help.

thanks.

I don't understand your 'rounding' logic.
Could you elaborate abit more, pls

Thanks for asking...
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 (exp. format. %1.5e)
123.4567 1.234567 e+02
000.0098 9.80000 e-03
-----------------
If you ask me to read it, for better human comprehension, I would perhaps round off the values appropriately and say the value is 123.457 with error of +-1 on the last digit. that I write as 123.457(1).

I am a new user here.. do not know how that thumbs down symbol got attached in the prev. reply. dont mean disrespect none to nobody :slight_smile:
also I noticed that i did not give right example.

123.4567
000.0098

should be 123.46(1).

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.