; peak_pick  - interactive
;
; (replaces pp)
;
; sets - up every thing for peak picking and realizes it
; permits peakpicking in a interactive, graphical manner.
;
if ($noise == 0) evaln.g  ; zoom 0
if (!exist('pp_fact')) set pp_fact := 10
refmacro 1
if ($dim==1) then
  if ($disp1d == 0) error ' Display should be on'
  if ($itype_1d != 0) then
        gm/al_yesno ' Data should be real, do you want to throw imaginaries away ?'
        if ($returned s! 'yes') exit
        real
  endif
  message 'Enter mult. factor for the noise level (typically 10)'
  set pp_fact :=
  max minimax ($pp_fact*$noise) (%+1)
  alert 'Zoom on the region to peak-pick then click on Ok'
  zoom 1 $zone[1] $zone[2]
  peak
  if ($npk1d > 0 ) then
    showpeaks
  else
    alert "No peak detected in selected region"
  endif
else
  if ($disp2d == 0 & $cdisp2d == 0 ) error 'Display should be on'
  if ($itype_2d != 0) then
        gm/al_yesno ' Data should be real, do you want to throw imaginaries away ?'
        if ($returned s! 'yes') exit
        real f12
  endif
  message 'Enter mult. factor for the noise level (typically 10)'
  set pp_fact := $_
  max minimax ($pp_fact*$noise) (1+ % )
  alert 'Zoom on the region to peak-pick then click on Ok'
refmacro 1
  zoom 1 $zone[1] $zone[2] $zone[3] $zone[4]
  peak %
  if ($npk2d > 0 ) then
    showpeaks
  else
    alert "No peak detected in selected region"
  endif
endif
print ' You can list the peak table with the   PKLIST %% command'
print ' If there are too many (or too few) peaks detected'
print ' try to raise (lower) the value of the mult. factor'
refmacro 0
exit

