############################
# Looking at the VAR files #
############################


# Import modules
import pencil as pc
import numpy as np
import pylab as plt
import matplotlib

# Open figure environment
f = plt.figure()

# Find the maximum number of VAR files:
numberofvarfiles = len(open('../data/proc0/varN.list').readlines(  ))-1

# Begin to loop over all var files:
for i in range(0, numberofvarfiles, 1):
   plt.ylabel('$\\mathrm{ln}(\\rho)$')
   plt.xlabel('$x$')

   plt.axhline(y=0, color='grey', linewidth=0.5)

   # read in var files:
   var = pc.read.var(ivar=i,trimall=True, datadir='../data')  
   minx = np.min(var.x)
   maxx = np.max(var.x)
   plt.axis([minx,maxx, -0.025,0.025])
   
   #plot var files:
   plt.plot(var.x, var.lnrho[0,0,:], color='blue')
   plt.title('t=%s' % var.t)
   
   plt.pause(0.003)

   # possibility to safe snapshots as pdf:
   # f.savefig("./snapshot_%s_%s.pdf" % (str(sys.argv[1]),i), bbox_inches='tight')
   plt.clf()

