; interactive
; permits to phase a 2D in F2 by interactively selecting rows
; and building a composite 1D
;
;
; see also : ph2dc rowint colint PH

; works in memory if small enough, otherwise, goes to file
if ($dim!=2) error 'Works only in 2D'
disp1d 1

; if DATA is used, work on file rather than on memory
if ($si1_2d*$si2_2d > $MEM_PRO_3D+$MEM_PRO_2D) then
	set onfile = (1 == 1)
	set file = ("/usr/tmp/gifa" // int(100000*$random))
else
	set onfile = (1 == 0)
endif

print "Look at rows with left mouse button"
print "Add selected row with middle mouse button"
print "and Exit with right mouse button"

dim 2 row 1
if $onfile then
	dim 1 zero write $file dim 2
else
	dim 1 zero put data dim 2
endif

refmacro 1
=loop
   monopoint
   if ($button==3) goto end
   if ($button==1) set sel = ($pointy[1]) row $sel
   if ($button==2) then
	print ('selected row :';$sel)
	if $onfile then
		dim 1 add $file write $file dim 2 unref
	else
		dim 1 adddata put data dim 2 unref
	endif
   endif
   goto loop
=end
set sc = $scale
dim 1
if $onfile then
	read $file  sh ('rm -f';$file)
else
	get data
endif
ph
dim 2 scale $sc unref
gm/al_yesno ('PH0 :'; $ph0+0; ' PH1 :'; $ph1+0; ' -- Ok to apply ?')
if ($returned s! 'yes') print 'Aborted' exit
print 'phasing in F2 ...'
phase % % f2
refmacro 0 exit

