#!/usr/bin/env python
"""
Read memory use for each day from cpl.log of an e3sm or screamv0 run
and plot it.
"""

import numpy as np
import pylab as pl
import re

fis=['/global/cscratch1/sd/petercal/e3sm_scratch/cori-knl/20101101.HackKobyFixesLong.F2000-SCREAM-LR.ne4pg2_ne4pg2.cori-knl.2x64x1/run/cpl.log.35855020.201103-110524',
     '/global/cscratch1/sd/petercal/E3SM_runs/20101008.Oct8Master.F2000-SCREAM-LR.ne4pg2_ne4pg2.cori-knl.2x64x1/run/cpl.log.35858036.201103-121727']

cols=['b','r']

i=-1
for fi in fis:
    i+=1
    f=open(fi,'r')

    highwater=[]
    usage=[]
    for line in f:
        if re.search('memory_write: model date =',line):
            highwater.append( np.float(line[58:65]))
            usage.append( np.float(line[88:94]))

    pl.plot(highwater,cols[i]+'-')
    pl.plot(usage,cols[i]+'--')
    
pl.xlabel('day into simulation')
pl.ylabel('Memory Usage (MB)')
pl.legend(['highwater','usage'])

pl.savefig('track_memory_Oct8Nov2.png')
pl.show()
