#!/usr/bin/python

import sys, re, os, math

if len(sys.argv) < 2 :
        print "Usage: %s  file.dat" % sys.argv[0]
        sys.exit(0)

datfile = sys.argv[1]
datfile_handle = open(datfile, "r")              #Open the file for reading only
#datfile_content = datfile_handle.readlines()     #function that convert each line in a string of a list
datfile_content = datfile_handle
#datfile_handle.close()

logfile = open("new_"+datfile, "w");             #Open the file for writing only


time=0
#print(len(sum_ord))
#print(sum_ord)
for line in datfile_content:
        timestep = re.match("(^\s[0-9]?)", line)
#        timestep = re.match("(?:^(?:\s*\d*\.?\d*\s*)*$)", line)
        if timestep:
                item=line.split()
                length = len(item)

                i=3
                while (i<length):
#                        print (time + item(i))
                        logfile.write("%s %s\n" % (str(time), str(item[i])))
                        time += 2
                        i += 3
print (length)

logfile.close()
