#! /usr/bin/python # # todigit.py # # Oct/08/99 # # # ---------------------------------------------------------------- import sys import math import string import regex def main (): sys.stderr.write ("*** start ***\n"); for line in sys.stdin.readlines (): if (0 <= regex.search ("[(%]",line[:1])): print line[0:-1] else: line_parser (line[0:-1]) sys.stderr.write ("*** end ***\n"); # # ---------------------------------------------------------------- # [4]: # def line_parser (line_a): while 1: pos_a = regex.search ("[\(A-Z]",line_a) if (pos_a == -1): break; ch_key = line_a[pos_a:1] if (ch_key == '('): sys.stdout.write (line_a[0:]); break else: line2 = line_a[pos_a + 1:] pos_b = parser_s4 (line2,ch_key) if (0 <=pos_b): line_a = line2[pos_b:] if (pos_b == -1): break sys.stdout.write ('\n') # ---------------------------------------------------------------- # [4-4]: def parser_s4 (line2,ch_key): pos_b = regex.search ("[\(A-Z]",line2) if (pos_b == -1): line3 = line2 else: line3 = line2[:pos_b] if (0 < regex.match ("[XYZIJKR]",ch_key)): sys.stdout.write (ch_key) ovalue = string.atof (line3) / 1000.0 out_value_proc (ovalue) else: sys.stdout.write (ch_key+line3) return pos_b # ---------------------------------------------------------------- # [2-4-4]: def out_value_proc (out_value): i1000 = int (out_value) * 1000 if (i1000 == (out_value * 1000)): out_ch = "%.1f" % out_value else: out_ch = "%.3f" % out_value sys.stdout.write (out_ch) # --------------------------------------------------------------- main () # ---------------------------------------------------------------