def ppvt(dirname):

    import pickle
    from pylab import *
    from operators import *
    from pf2d_ztitvar import pf2d_ztitvar
    
    from readjet2h import readjet2h
    vardict=readjet2h(dirname)
    locals().update(vardict)

    predir='/data/ilebras/twolayer-jets-climate/'

    [psi,q,qfull,u,v,x,y]=pickle.load(open(predir+'pickles/quickfields/'+dirname+'_qfield_tm.p', 'r' ))

    dx=(xmax-xmin)/(n-1)
    dy=(ymax-ymin)/(m-1)

    dx2=dx**2

    tdx=1.0/(2.0*dx)
    tdy= 1.0/(2.0*dy)
    t4dx=1.0/(8.0*dx)
    t4dy=1.0/(8.0*dy)
    t4dx2=1.0/(4.0*dx2)
    t4dxdy=1.0/(4.0*dx*dy)
    t4dy2=1.0/(4.0*dy**2)
    twdx2=1.0/(12.0*dx2)

    ######### calculate ubar grad q #########
    
    dqx1=gradx(qfull['m1'],tdx,n,m)
    dqy1=grady(qfull['m1'],tdy,n,m)

    dqx2=gradx(qfull['m2'],tdx,n,m)
    dqy2=grady(qfull['m2'],tdy,n,m)

    pvt={}

    pvt['m1']=u['m1']*dqx1+v['m1']*dqy1

    pvt['m2']=u['m2']*dqx2+v['m2']*dqy2


    ######### calculate A del^2 zeta #########

    d2xz1=gradxx(q['m1'],t4dx2,n,m)
    d2yz1=gradyy(q['m1'],t4dy2,n,m)

    d2xz2=gradxx(q['m2'],t4dx2,n,m)
    d2yz2=gradyy(q['m2'],t4dy2,n,m)
    
    pvt['i1']=akap*(d2xz1+d2yz1)

    pvt['i2']=akap*(d2xz2+d2yz2)

    xlow=250
    xhigh=-250
    ylow=250

    pf2d_ztitvar(pvt,'meanpvterms',x,y,dirname,(18,6),xlow,xhigh,ylow,'mean advection term','viscous term',1)
def loadTEM(dirname):

      import numpy as np
      import fortranfile
      from pylab import *
      import pickle
      import os
      from pf2d_ztitvar import pf2d_ztitvar

      from readjet2h import readjet2h
      vardict=readjet2h(dirname)
      locals().update(vardict)

      [L,beta_dim,f0_dim,h1]=pickle.load(open('/data/ilebras/twolayer-jets-climate/pickles/dimize.p','r'))

      U=beta_dim*L**2/beta1
      gprime=f0_dim**2*L**2/h1/fr1
      h2=f0_dim**2*L**2/gprime/fr2
      f0_nd=f0_dim*L/U

      #define x and y (m)
      x=arange(xmin,xmax,(xmax-xmin)/n)*L
      y=arange(ymin,ymax,(ymax-ymin)/m)*L

      betay_vec=beta1*y/L
      betay=tile(betay_vec,(n,1))

      predir='/data/ilebras/twolayer-jets-climate/'
      rundir=predir+'testing/'+dirname+'/'

      #--------load eddy forcing terms--------------

      uq_TEM={}

      pload=fortranfile.FortranFile(rundir+'Tr1.dat')
      pvec=pload.readReals()
      ppp=pvec.reshape(n,m,order='F')
      uq_TEM['m1']=ppp

      pload=fortranfile.FortranFile(rundir+'Tr2.dat')
      pvec=pload.readReals()
      ppp=pvec.reshape(n,m,order='F')
      uq_TEM['m2']=ppp

      pload=fortranfile.FortranFile(rundir+'TM1.dat')
      pvec=pload.readReals()
      ppp=pvec.reshape(n,m,order='F')
      uq_TEM['i1']=ppp

      pload=fortranfile.FortranFile(rundir+'TM2.dat')
      pvec=pload.readReals()
      ppp=pvec.reshape(n,m,order='F')
      uq_TEM['i2']=ppp

      #--------plot eddy forcing terms--------------

      xlow=200
      xhigh=-3
      ylow=250

      pf2d_ztitvar(uq_TEM,'uqTEM_fromsaved_no',x,y,dirname,(18,6),xlow,xhigh,ylow,'relative vorticity portion','total eddy forcing',1)