;$Id: pkft.pro,v 1.6 2020/06/18 13:57:31 brandenb Exp $
if !d.name eq 'PS' then begin
  device,xsize=16,ysize=24,yoffset=3
  !p.charthick=3 & !p.thick=3 & !x.thick=3 & !y.thick=3
end
;
;  compute various length scales from the spectra and
;  calculate the instantaneous scaling exponents.
;
default,w,0
default,ihydro,0
@parameters
default,iread,0
if iread eq 0 then begin
  power,'_mag','hel_mag',k=k,spec1=spec1,spec2=spec2,i=n,tt=t,/noplot
  pc_read_param,o=param,/param2
  iread=1
  print,n
endif
;
!p.charsize=1.6
!x.margin=[8.8,.5]
!y.margin=[3.2,.5]
!p.multi=[0,3,2]
fo2='(f5.2)'
cwd,run
si2=1.4
;
;eta=param.eta
kLM=t
kIM=t
kTM=t
kM=t
EM=t
LM=t
ELM=t
nt=n_elements(t)
;
;  compute 1/k
;
k1=k & k1(0)=1. & k1=1./k1 & k1(0)=0.
;
;  loop over all times
;
E=t & for it=0,nt-1 do E(it)=total(spec1(*,it))
for it=0,nt-1 do begin
  etat=eta0/t[it]^.43
  kLM(it)=1./(total(spec1(*,it)*k1^8)/total(spec1(*,it)))^.125
  kIM(it)=1./(total(spec1(*,it)*k1)/total(spec1(*,it)))
  kTM(it)=(total(spec1(*,it)*k^2)/total(spec1(*,it)))^.5
  LM(it)=2*etat*total(spec1(*,it)*k^2)
  kM(it)=(total(2*etat*spec1(*,it)*k^2)/etat^3)^.25
  EM(it)=total(spec1(*,it))
  ELM(it)=(spec1(1,it))[0]
  ;ELM(it)=total(spec1(0:3,it))
endfor
cwd,run
;
;  compute new lnt coordinate
;
lnt=alog(t)
;
;  first plot
;
print
!x.title='!6'
!y.title='!8k!6!df!n/!8k!6!d1!n'
!p.title='!6'
yr=[4,3000]
yr=[1,1000]
yr=[.3,10]
lnEM=alog(EM)
lnELM=alog(ELM)
lnkIM=alog(kIM)
pL=+deriv(lnt,lnELM)
pM=-deriv(lnt,lnEM)
qM=-deriv(lnt,lnkIM)
;
plot,lnt,lnELM,xtit='',ytit='lnELM',ps=-1
plot,lnt,lnEM,xtit='',ytit='lnEM',ps=-1
plot,lnt,lnkIM,xtit='',ytit='lnkIM',ps=-1
plot,lnt,pL,xtit='lnt',ytit='pL',ps=-1,yr=[0,3.0]
plot,lnt,pM,xtit='lnt',ytit='pM',ps=-1
plot,lnt,qM,xtit='lnt',ytit='qM',ps=-1
;
print
print,'mv idl.ps ~/tex/tina/Classes/fig/pkft_new_'+run+'.ps'
print,'mv idl.ps ~/tex/tina/heldecay/fig/pkft_new_'+run+'.ps'
print
;
print,'write savefile'
save,file='pq.sav',lnt,pM,qM,pL
save,file='kE.sav',lnt,lnkIM,lnEM,t,kLM,kIM,EM,kTM,LM,ELM
;
!p.multi=0
!x.title=''      
!y.title=''
spawn,'cvs add -kb pq.sav kE.sav'
END
