#!/usr/bin/python
import re
import sys
import os
from decimal import Decimal, getcontext

if (len(sys.argv) < 6):
  print "Error: pass i/d/a dim x y z filename"
  sys.exit(-1)

interpol = (sys.argv[1] == 'i')
all_aforms = (sys.argv[1] == 'a')
dim = int(sys.argv[1])
pdim1 = int(sys.argv[2])
pdim2 = int(sys.argv[3])
pdim3 = int(sys.argv[4])
infilename = sys.argv[5]

def floatify (sd):
  return float(sd.replace('~','-'))

now = False or all_aforms
while 1:
  try:
    line = sys.stdin.readline()
  except KeyboardInterrupt:
    break
  if not line:
    break
  if line.strip() == '':
    continue
  if (not all_aforms and (interpol and line.startswith('= interpolated step:')) or (not interpol and line.startswith('= discrete step:'))):
    now = True
    continue
  if not (line.startswith('rect(')) or not now:
    continue
  now = False or all_aforms

  ds = dre.findall(line)
  l1 = ds[2+pdim1]
  l2 = ds[2+pdim2]
  col = int (ds[2+pdim3] * 10000000)
  u1 = ds[2+dim+pdim1]
  u2 = ds[2+dim+pdim2]

  outfile.write(str(col) + ", ")
  for d in [l1, l2, u1, u2]:
    outfile.write(str(floatify(d)) + ", ")
  outfile.write("\n")

  [dim, aform] = line.split('rect(', 1)[1].split('):', 1)
  dim = int(dim)
  aform = aform.replace('--','');
  aform = aform.replace('(','');
  aform = aform.replace(')','');
  aform = aform.replace(',','');
  pdevs = [floatify(sd) for sd in aform.split()];
  print str(sortidx) + ' ' + line.strip()