/* VnmrJ/VNMR macro to process 2D rtACQ data acquired with droppts (2nd gen pulse seq for rt-HSQC)

Developed By NMR Methodology Group
School of Chemistry, University of Manchester
United Kingdom
Apr 2017
Peter Kiraly

This macro will use exp5 (or the one that was choosen by setting addsubexp) to create a new FID by dropping the unwanted points from each trace of a 2D experiment inclusing phase=1,2.
The resulting FID can be processed by ft2da 

*/


$kp_exp_str=''
jexp:$exp_num,$kp_exp_str

$sw1=sw1 
$kp_ni=ni
$samplename=samplename
$arraydim=arraydim


cptmp('pureshift')
clradd

exists('addsubexp','parameter'):$e
if ($e=0) then $addsubexp=5 else $addsubexp=addsubexp endif


$imag=0.0
$real=0.0

$kp_srcfid=curexp+'/kp_srcfid'
exists($kp_srcfid,'file'):$e
if $e=1 then rm($kp_srcfid) endif
$kp_newfid=curexp+'/kp_newfid'
exists($kp_newfid,'file'):$e
if $e=1 then rm($kp_newfid) endif





$i=1	
repeat
	rttmp('pureshift')


	exists($kp_srcfid,'file'):$e
	if $e=1 then rm($kp_srcfid) endif
	writefid($kp_srcfid,$i)

	lookup('file',$kp_srcfid)

	exists($kp_newfid,'file'):$e
	if $e=1 then rm($kp_newfid) endif
	write('reset',$kp_newfid)


	lookup('skip',droppts1) $j=1+droppts1
	repeat
	    lookup('read',2):$real,$imag 
	    write('file',$kp_newfid,'%s %s',$real/ct,$imag/ct) 
	  $j=$j+2
	until ($j>(droppts1+kp_npoints/2))

	lookup('skip',droppts2) $j=$j+droppts2
repeat
	lookup('skip',droppts1) $j=$j+droppts1
		$k=1
		repeat
		  lookup('read',2):$real,$imag 
		  write('file',$kp_newfid,'%s %s',$real/ct,$imag/ct) 
		  $k=$k+2
		  $j=$j+2
		until ($k>kp_npoints)

	lookup('skip',droppts2) $j=$j+droppts2
until ($j > (np-droppts1-kp_npoints/2-droppts2))

	lookup('skip',droppts1) $j=$j+droppts1
	$l=1
	repeat 
	    lookup('read',2):$real,$imag 
	    write('file',$kp_newfid,'%s %s',$real/ct,$imag/ct) 
	  $l=$l+2
	  $j=$j+2
	until ($l>kp_npoints/2)

rm(curexp+'/acqfil/fid')

exists('console','parameter'):$e
if ($e=0) then 
	makefid($kp_newfid,'float')
else 
	if (console='inova') then makefid($kp_newfid) else makefid($kp_newfid,'float') endif
endif

setvalue('np',kp_npoints*kp_cycles)
groupcopy('current','processed','acquisition')
add('new')


 $i=$i+1
until ($i>arraydim)


mf($addsubexp,$exp_num)

setvalue('at',np/sw/2)

sw1=$sw1 
setvalue('ni',$kp_ni)
setvalue('droppts1',0)
setvalue('droppts2',0)
calcdim
gc

UoM_nowt 
gf=at/2 gf1=ni/sw1/2
fn=32k fn1=1k





