; $Id: rslice_file.pro,v 1.1 2019/05/13 04:55:06 brandenb Exp $
if !d.name eq 'PS' then begin
  device,xsize=18,ysize=22,yoffset=3
  !p.charthick=3 & !p.thick=3 & !x.thick=3 & !y.thick=3
end
;
;  mv idl.ps ~/tex/x/x/fig/rslice_xy.ps
;
;  this file is a copy from ../../stratified/waves/2d/idl/
;
!p.charsize=1.7
!x.margin=[8.8,1.5]
!y.margin=[3.2,.5]
@parameters
;
;  reads xy slices
;  this routine is not very general yet and needs to be adjusted
;  before it can be general purpose.
;
spawn,'ls data/proc*/slice_uu3.xy'
;file_slice='data/proc0/slice_uu3.xy'
;file_slice='data/proc7/slice_uu3.xy'
;file_slice='data/proc13/slice_uu3.xy'
;file_slice='data/proc14/slice_uu3.xy'
;file_slice='data/proc15/slice_uu3.xy'
;file_slice='data/slice_uu3.xy'
;file_slice='data/proc6/slice_uu3.xy'
file_slice='data/proc13/slice_uu3.xy'
file_slice='data/proc7/slice_uu3.xy'
file_slice='data/slice_uu3.xy'
file_slice='data/proc55/slice_uu3.xy'
;file_slice='data/proc31/slice_uu3.xy'
;
pc_read_param,obj=param
pc_read_dim,obj=dim
pc_read_ts,obj=ts
nx=dim.nx
;
t=0.
default,w,.0
default,iplot,1
default,t1,10.0
slice_zpos=0.
xy_slice=fltarr(nx)
Lx=param.Lxyz(0)
dk=2.*!pi/Lx
;
it=0
;nx=nx/2
;ix1=nx/2-1
;ix2=ix1+nx-1
ix1=0
ix2=nx-1
close,1
;openr,1,file_slice,'unformatted',/f77
openr,1,file_slice,/f77
print,'test: t1,t2=',t1,t2
while not eof(1) do begin
  readu,1,xy_slice,t,slice_zpos
  if t gt t1 and t le t2 then begin
    if iplot eq 1 then begin
      print,t,min(xy_slice),max(xy_slice), slice_zpos
      plot,xy_slice,yr=[-1,1]*.01
      wait,w
    endif
    ;
    if it eq 0 then begin
      tt=t
      xt=xy_slice(ix1:ix2)
    endif else begin
      tt=[tt,t]
      xt=[xt,xy_slice(ix1:ix2)]
    endelse
    if (it mod 50) eq 0 then print,it,t,max(ts.t)
    it=it+1L
  ;plot,xy_slice(11,*),yr=[-1,1]*1e-3
  ;tvscl,xy_slice
  ;tvscl,congrid(xy_slice,2*nx,2*ny)
  end else if t ge t2 then begin
    print,'ENDING',t,t2
    goto,ending
  end
end
ending:
nt=it
print,'ENDED',t,t2
;
dt=(max(tt)-min(tt))/(nt-1)
Ttotal=nt*dt
dom=2.*!pi/Ttotal
omega=findgen(nt)*dom
kk=findgen(nx)*dk
xt=reform(xt,nx,nt)
ko=fft(xt,-1)
!x.title='!8k!6'
!y.title='!7x!6'
contour,(alog(abs(ko)))(0:nx/2,0:nt/2),/fil,nlev=30,kk(0:nx/2),omega(0:nt/2)
;stop
;
;grav=-param.gravz
fff=(alog(abs(ko)))(0:nx/2,0:nt/2)
kkk=kk(0:nx/2)
ooo=omega(0:nt/2)
;fff=(alog(abs(ko)))
;kkk=kk
;ooo=omega
;contour,(alog(abs(ko)))(0:nx/2,0:nt/2),/fil,nlev=30,kk(0:nx/2),omega(0:nt/2)
;contour,/fil,nlev=10,fff,kkk,ooo
;contour,/fil,nlev=10,fff,kkk,ooo,xr=[0,10]
;save,file='ko_diagram.sav',fff,kkk,ooo
;oplot,kk(0:nx/2),kk(0:nx/2)*.5,col=255
;oplot,kk(0:nx/2),sqrt(grav*kk(0:nx/2)),col=188
close,1
END
