; dosy2d type size thres 
;
; implements the complete DOSY processing for 2D
;
; DOSY data are in-memory, diffusion dimension is in F1,
; NMR spectra in F2
;
; type : tabulated or regular   : determines the type of sampling
; size : size after Laplace inversion
; thres : multiplier used to determine the processing threshold
;         only columns which first point is larger
;         than the noise level by this ratio, will be processed
;
; see also :  INVLAP, INVTLAP, dosy3d, dosy.g, dosy_setup

gm/test2d

message "Enter type (regular/tabulated)"
set type = $_
set type = (toupper($type))
if ($type s! "REGULAR" & $type s! "TABULATED")   error "Wrong DOSY type"

message "Enter final size"
set sz = $_
if ($sz < 4) error "Size too small"
if ($sz > $MEM_PRO_1D) error "Size too large'

message "Enter noise factor used for thresholding"
set thresh = $_

; compute sizes to be used before and after
set szbf = $si1_2d

if ($sz > $szbf) then
        chsize $sz %
        set szaf = $sz
else
        set szaf = $szbf
endif

initinprogress $si2_2d

; do the processing
col 1
for i = 1 to $si2_2d
        inprogress $i
        if (val2d(1,$i) > $thresh * $noise) then
                col $i dim 1
                chsize $szbf
                if ($type s= "TABULATED") then
                        invtlap $sz
                else
                        invlap $sz
                endif
		chsize $szaf
        else
                dim 1 chsize $szaf zero
        endif
        dim 2 put col $i
endfor
dim 2

chsize $sz %
