subr append_plane(name, x)
 ;first call starts the file, $file_init can be zeroed to start another, i.e.,
 ;a new file is started if $file_init = 0 or is undefined
 ;after that, we check for consistency with the first plane and then
 ;append the file with the new plane, data is stored as a 3-D array
 zeroifnotdefined, $file_init
 if $file_init eq 0 then {
 ;open the file and write first image (plane)
 nx = dimen(x, 0)	ny = dimen(x, 1)
 redim, x, nx, ny, 1
 fzwrite, x, name, '3-D image plane file created by append_plane'
 redim, x, nx, ny
 type = symdtype(x)
 $file_init = 1
 plane = 1
 return
 }
 plane += 1
 ;are we being consistent?
 if nx ne dimen(x,0) or ny ne dimen(x,1) or type ne symdtype(x) then {
 	ty,'append_plane has an inconsistency!'
	return
	}
 lun = get_lun()
 openu, lun, name
 fileread,lun, h,0,512,0
 kq = long(plane)
 if bigendian() eq 1 then swapl, kq
 h(200) = bmap(kq)
 filewrite,lun,h,0
 
 ncase type
 hsize = 512
 hsize = 256
 hsize = 128
 hsize = 128
 hsize = 64
 endcase
 ;now the data
 filewrite, lun, x, nx*ny*(plane-1) + hsize
 close, lun
 endsubr
