#!/bin/sh
# The next line restarts using nmrWish \
exec nmrWish "$0" -- "$@"

message .msg -relief raised -bg blue -fg white \
 -width 30c -text "Detecting Peaks ..."

pack    .msg
update

set tabName  hbhaconh.tab
set specName ft/test%03d.ft3
set tabCount 1

set tabDir [file dirname $tabName]

if {![file exists $tabDir]} {file mkdir $tabDir}


set thisSpecName $specName
set thisTabName  $tabName

set x1      1
set xN      256
set xInc    256
set xExtra  1
set xLast   [expr $xN + $xExtra + 1]

set y1      1
set yN      345
set yInc    345
set yExtra  1
set yLast   [expr $yN + $yExtra + 1]

set z1      1
set zN      128
set zInc    128
set zExtra  1
set zLast   [expr $zN + $zExtra + 1]

    set zFirst  $z1

while {$zFirst <= 1 + $zN - $zExtra} \
   {
    set zNext [expr $zFirst+$zInc+2*$zExtra-1]
    if {$zNext > $zLast} {set zNext $zLast}

    set yFirst  $y1

while {$yFirst <= 1 + $yN - $yExtra} \
   {
    set yNext [expr $yFirst+$yInc+2*$yExtra-1]
    if {$yNext > $yLast} {set yNext $yLast}

    set xFirst  $x1

while {$xFirst <= 1 + $xN - $xExtra} \
   {
    set xNext [expr $xFirst+$xInc+2*$xExtra-1]
    if {$xNext > $xLast} {set xNext $xLast}

    readROI -roi 1 -ndim 3 -in $thisSpecName \
       -x X_AXIS $xFirst $xNext           \
       -y Y_AXIS $yFirst $yNext           \
       -z Z_AXIS $zFirst $zNext           \
       -verb

    pkFindROI -roi 1 \
      -sigma 65185.7 -pChi 1e-04 -plus 391114 -minus -391114 \
      -dx        1     1     1 \
      -idx       1     1     1 \
      -tol    2.00  2.00  2.00 \
      -hiAdj  1.80  1.20  1.80 \
      -lw     5.00 15.00  0.00 \
      -reject  -sinc -mask -out $thisTabName -verb

    set xFirst [expr 1 + $xNext - 2*$xExtra]
   }
    set yFirst [expr 1 + $yNext - 2*$yExtra]
   }
    set zFirst [expr 1 + $zNext - 2*$zExtra]
   }

exit
