#!/usr/bin/env python

"""Loads and plots timestep data for a given run.

Usage: parse_logfile.py out.log
"""

import numpy as np

def print_headers():
    print "cycle, time, dt, iteration count, wallclock avg (s)"

def parse_file(fid, wallclock=False):
    data = []
    faildata = []

    # find number of "cycles"
    total_cycles = 0
    for line in fid:
        if "Cycle =" in line:
            sline = line.split()
            cyc = int(sline[4][:-1])
            time = float(sline[8][:-1])
            dt = float(sline[12])

            if len(data) > 0 and data[-1][0] == cyc:
                faildata.append(data.pop())
            data.append([cyc,time,dt])

    return np.array(data), np.array(faildata)


if __name__ == "__main__":
    import sys
    from matplotlib import pyplot as plt
    fname = sys.argv[-1]
    with open(fname,'r') as fid:
        data = parse_file(fid)
    plt.subplot(121)
    plt.semilogy(data[0][:,1], data[0][:,2], 'b-x')
    plt.semilogy(data[1][:,1], data[1][:,2], 'bx')
    plt.xlabel("time [days]")
    plt.ylabel("dt [days]")
    plt.subplot(122)
    plt.semilogy(data[0][:,0], data[0][:,2], 'b-x')
    plt.semilogy(data[1][:,0], data[1][:,2], 'bx')
    plt.xlabel("cycles [-]")
    plt.ylabel("dt [days]")
    plt.show()



@@ -805,16 +805,17 @@
    fname
+s
  = sys.a
@@ -822,12 +822,384 @@
 rgv%5B
+:%5D%0A%0A    fnames.pop(0) # removes python or potential just executable name%0A    if len(fnames) %3E 0 and fnames%5B0%5D.endswith(%22.py%22):%0A        fnames.pop(0) # removes exectuable name%0A    if len(fnames) == 0:%0A        print %22Usage: parse_logfile.py logfile.out%22%0A        sys.exit(1)%0A%0A    import colors%0A    cm = colors.cm_mapper(0,len(fnames)
 -1
-%5D%0A
+)%0A    for i,fname in enumerate(fnames):%0A    
     
@@ -1231,24 +1231,28 @@
 id:%0A        
+    
 data = parse
@@ -1262,16 +1262,24 @@
 le(fid)%0A
+        
     plt.
@@ -1291,16 +1291,24 @@
 ot(121)%0A
+        
     plt.
@@ -1337,38 +1337,71 @@
  data%5B0%5D%5B:,2%5D, '
-b
 -x'
-)%0A
+, color=cm(i), label=fname)%0A        
     plt.semilogy
@@ -1422,37 +1422,57 @@
  data%5B1%5D%5B:,2%5D, '
-b
 x'
-)%0A
+, color=cm(i))%0A        
     plt.xlabel(%22
@@ -1477,32 +1477,40 @@
 (%22time %5Bdays%5D%22)%0A
+        
     plt.ylabel(%22
@@ -1513,32 +1513,65 @@
 el(%22dt %5Bdays%5D%22)%0A
+            plt.legend()%0A        
     plt.subplot(
@@ -1575,16 +1575,24 @@
 ot(122)%0A
+        
     plt.
@@ -1633,14 +1633,34 @@
 %5D, '
-b
 -x'
-)%0A
+, color=cm(i))%0A        
     
@@ -1705,13 +1705,33 @@
 %5D, '
-b
 x'
-)%0A
+, color=cm(i))%0A        
     
@@ -1751,24 +1751,32 @@
 ycles %5B-%5D%22)%0A
+        
     plt.ylab

enable more than one logfile in plotting