1subroutine plotsave(swide,nw,nh,irow)
2
3  real, dimension(:,:), allocatable :: sw
4  real swide(0:nw-1)
5  data nw0/-1/,nh0/-1/
6  save nw0,nh0,sw
7
8  if(irow.eq.-99) then
9     if(allocated(sw)) deallocate(sw)
10     go to 900
11  endif
12
13  if(nw.ne.nw0 .or. nh.ne.nh0 .or. (.not.allocated(sw))) then
14     if(allocated(sw)) deallocate(sw)
15!     if(nw0.ne.-1) deallocate(sw)
16     allocate(sw(0:nw-1,0:nh-1))
17     sw=0.
18     nw0=nw
19     nh0=nh
20  endif
21  df=12000.0/16384
22  if(irow.lt.0) then
23! Push a new row of data into sw
24     do j=nh-1,1,-1
25        sw(0:nw-1,j)=sw(0:nw-1,j-1)
26     enddo
27     sw(0:nw-1,0)=swide
28  else
29! Return the saved "irow" as swide(), for a waterfall replot.
30     swide=sw(0:nw-1,irow)
31  endif
32
33900 return
34end subroutine plotsave
35