#! /usr/bin/python3
import sys
import matplotlib.pyplot as plt
from math import *
import numpy as np

def forward(a):
    return np.log(a)

def inverse(a):
    return np.exp(a)

if len(sys.argv) == 1 or len(sys.argv) > 2:
    print("usage:", sys.argv[0], "<filename>")
    exit()

# open file and remove newlines. readlines is okay b/c
# the input file shouldn't be thaaaat big
f=open(sys.argv[1])
lines = [line.strip() for line in f.readlines()]
f.close()


# first column defines the inputs
steps = [float(x.split(" ")[0]) for x in lines]
gen_by_step = [float(x.split(" ")[1]) for x in lines]
gen_by_file = [float(x.split(" ")[2]) for x in lines]


fig, axs = plt.subplots(1,2)
fig.set_size_inches(8, 2.5, forward=True)

axs[0].loglog(steps, gen_by_step, label="generate_by_step")
axs[0].loglog(steps, gen_by_file, label="generate_by_file")

zoom = 5
axs[1].plot(steps[:zoom], gen_by_step[:zoom], label="generate_by_step")
axs[1].plot(steps[:zoom], gen_by_file[:zoom], label="generate_by_file")

axs[1].set(title="Smallest stepsizes with a linear scale")
axs[0].set(xlabel='Step size')
axs[1].set(xlabel='Step size')
axs[0].set(ylabel='Time (s)')


#loc={'best', 'upper right', 'upper left', 'lower left', 'lower right', 'right', 'center left', 'center right', 'lower center', 'upper center', 'center'}
axs[1].legend(loc="best",fancybox=True, shadow=True)
axs[0].grid(True, which='both',color='0.95')
axs[1].grid(True, which='both',color='0.95')

outputname = sys.argv[1].split(".")[0]
plt.subplots_adjust(left=0.07, right=0.995, top=0.995,
                    bottom=0.11,wspace=0.1)
plt.savefig(outputname + ".eps", bbox_inches='tight')
plt.show()

