#!/usr/bin/python

import sys

def is_number(s):
  try:
    float(s)
    return True
  except ValueError:
    return False


if (len(sys.argv) > 1):
  outputStep = int(sys.argv[1])
else:
  outputStep = 1

if(len(sys.argv) > 2):
  source=open(str(sys.argv[2])+".log","r")
  graph=open(str(sys.argv[2])+".graph","w")
  parameters=open(str(sys.argv[2])+".parameters","w")
else:
  source=open("output","r")
  graph=open("output.graph","w")
  parameters=open("output.parameters","w")

line="init"
counter=0
while(line !=""):
  line=source.readline()
  if(line!=""):
    if(is_number(line[0]) or "Sumg" in line):
      line = str(counter) + ", " +  line
      graph.write(line)
      counter+=outputStep
    elif("parameter" in line or "Adding" in line or "Time Elapsed" in line or "iterations" in line):
      parameters.write(line)

graph.close()
parameters.close()
source.close()
