The IDL procedures <tt>loadanim</tt> and <tt>runanim</tt>



next up previous contents
Next: The IDL procedure Up: 3D Redshift Space Visualization Previous: The IDL procedure

The IDL procedures loadanim and runanim

PRO runanim,nend,delay,backward=backward,nstart=nstart

  if n_params() eq 0 then begin
    print,'runanim,nend,delay,backward=backward,nmin=nmin'
    print,'nend    : number of the last frame to show'
    print,'delay   : wait between frames'
    print,'backward: show frames backward'
    print,'nstart  : number of start frame (default=0)'
    return
  endif

  COMMON canim, s, nx, ny, dx, dy
  if keyword_set(nstart) eq 0 then nstart = 0

  wset,0
  if keyword_set(backward) eq 0 then begin
     step = 1
     is = 0
     ie = nx-1
     js = 0
     je = ny-1
     test = 0
  endif else begin
     step = -1
     ie = 0
     is = nx-1
     je = 0
     js = ny-1
     test = nx*ny
  endelse

  k=1
  for i=is,ie,step do begin 
    for j=js,je,step do begin
      if(test le nend and test ge nstart) then begin
	device,copy=[i*s(2),j*s(3),s(2),s(3),dx,dy,1]
        wait,delay
        if k ge nend then goto, finis
        k=k+1
      endif
      test = test + step
    end
  end
finis:
END

PRO loadanim,nstart,nfile,file,ext,compress=compress,temp=temp,$
	     no_zero=no_zero, nu=nu, m=m

; stone age/Aake init version
; 25.05-94/Bo    included 8 bit conversion
; 26.05-94/kg	 included file and ext to the input
; 26.05-94/kg,Bo included nstart, /compress, /no_zero
; 26.05-94/Bo    included temp=temp
; 26.05-94/kg    included backward frame stepping in runanim
; ??.06-94/kg    included nu=nu    

  COMMON canim, s, nx, ny, dx, dy

  if n_params() eq 0 then begin
     print,'loadanim,nstart,nfile,file,ext,/compress,temp=temp,/no_zero,/nu'
     print,'nstart    : number of the first data file
     print,'nfile     : last file to read'
     print,'file      : main file name'
     print,"ext       : extension on file name, e.g. '.tiff'"
     print,'/compress : used when the data files are compressed'
     print,"temp      : temporary filename when uncompressing, e.g. '/tmp/blaaa'"
     print,'/no_zero  : used when no leading zeros in numbers'
     print,'/nu       : when set numbers appear on the animation'
     return
  endif
  COMMON c_fade,r,g,b
  set_plot,'X'
  device,pseudo=8
  !order=1

  ny=7l
  nx=long((nfile+1-nstart)/ny)+1l
  print,nfile-nstart+1,nx,ny

  k=nstart
  if keyword_set(no_zero) ne 0 then begin
     file_name=strcompress(file+str(k)+ext)
  endif else begin
      if (k lt 10) then file_name =strcompress(file+'00'+str(k)+ext)
      if (k ge 10 and k lt 100) then file_name =strcompress(file+'0'+str(k)+ext)
      if (k ge 100 and k lt 1000) then file_name =strcompress(file+str(k)+ext)
  endelse
  if keyword_set(compress) ne 0 then begin
     if n_elements(temp) eq 0 then temp='tmp' ; default is 'tmp'
     cmd='zcat '+file_name+'.Z > '+ temp
     print,cmd
     spawn,cmd
     file_name=temp
  endif

  im=tiff_read(file_name)

  s=size(im)
  im=reform(color_quan(im, 1, R, G, B, COLORS=256, GET_TRANSLATION=ctrans, /MAP_ALL))

  window,1,/pix,xsize=nx*s(2),ysize=ny*s(3)

  m=0
  xsize=775>s(2)
  ysize=580>s(3)
  dx=((xsize-s(2)+2*m)>0)/2
  dy=((ysize-s(3)+2*m)>0)/2
  window,0,xsize=xsize,ysize=ysize
  tvlct, R, G, B

  wset,1 & erase
  for i=0,nx-1l do begin 
    for j=0,ny-1l do begin
      if keyword_set(no_zero) ne 0 then begin
         file_name=strcompress(file+str(k)+ext)
      endif else begin
          if (k lt 10) then file_name =strcompress(file+'00'+str(k)+ext)
          if (k ge 10 and k lt 100) then file_name =strcompress(file+'0'+str(k)+ext)
          if (k ge 100 and k lt 1000) then file_name =strcompress(file+str(k)+ext)
      endelse
      if keyword_set(compress) ne 0 then begin
         cmd='zcat '+file_name+'.Z > '+ temp
         print,cmd
         spawn,cmd
	 file_name=temp
      endif
      im=tiff_read(file_name)
      im=reform(color_quan(im, 1, R, G, B, COLORS=256, TRANSLATION=ctrans))
;      im = rotate(rotate(im,2),5)
      wset,0
      if (k ne nstart) then xyouts,.1,.1,/nor,str(k-1),col=0
      tv,im(m:s(2)-m-1,m:s(3)-m-1),dx,dy
      xyouts,.1,.1,/nor,str(k),col=10
      wset,1
      tv,im(m:s(2)-m-1,m:s(3)-m-1),i*s(2),j*s(3)
      if keyword_set(nu) ne 0 then xyouts,10+i*s(2),10+j*s(3),/dev,str(k)
      if k ge nfile then goto, display
      k=k+1
    end
  end
   
display:

  if keyword_set(compress) ne 0 then begin
    cmd='\rm '+temp
    print,cmd
    spawn,cmd
  endif

  wset,0
  erase
  wset,1
  runanim,nfile-nstart+1,.1

  print, 'there are '+str(nfile-nstart+1)+' frames in the sequence'

END



Bo Milvang-Jensen
Wed Jan 18 05:44:35 MET 1995