;sapphire
;
;	Sideband Averaging by Periodic PHase
;	Incrementation of Residual J Evolution
;	for the acquisition of clean ZS pure shift spectra
;
;	Developed by:
;	NMR Methodology Group
;	University of Manchester
;
;	The pulse sequence involves a 3D acquisition scheme. 
;	F3 is the direct dimension. F1 is the incremented dimension for the reconstruction of the pure shift interferogram.
;	F2 is the incremented dimension for the J-evolution.
;
;	The data can be reconstructed using the two following AU programs (downloaded from: http://nmr.chemistry.manchester.ac.uk)
;		1) pm_pshift (produces pure shift spectra for each different J-evolution time, adjusting the length of the first chunk appropriately)
;		2) pm_fidadd (averages the pure shift spectra acquired with differente J-evolution times)
;
;
;$CLASS=HighRes
;$DIM=3D
;$TYPE=
;$SUBTYPE=
;$COMMENT=

#include <Avance.incl>
#include <Grad.incl>
#include <Delay.incl>

define delay tauA
define delay tauAA
define delay tauB
define delay tauBB
define delay tauBBB
define delay tauBBBB
define delay tauC
define delay tauD

"p2=p1*2"

"l0=0"
"l8=0"

"in0=inf1/2"
"in10=inf2"

"d0=inf1/2"
"d10=inf2"
"d30=in0/2"
"d40=in0/2-in10"

"cnst5=(td2/2)+1"

"tauA=0"
"tauAA=inf1/4"
"tauB=d2-p17-2*d16-20u"
"tauBB=d2-p17-2*d16-20u-inf2"
"tauBBB=d2-p17-2*d16-20u"
"tauBBBB=d2-p17-2*d16-20u+inf2"
"tauC=inf2"
"tauD=(dw*2*cnst4)"


aqseq 312

1 ze
2 50m
	d1 pl1:f1
3 50u UNBLKGRAD


 if "l8 < cnst5" 		
   { 
		"tauA=0"
		"tauB=d2-p17-2*d16-20u"
		"tauA=tauA+(l8*in10)"
		"tauB=tauB-(l8*in10)"
		"d30=in0/2+(l8*in10)"
		"d30=d30+((l0-1)*in0)"
		"tauBBB=d2-p17-2*d16-20u"
		"tauBBB=tauBBB-(l8*in10)"

		p1 ph1 

		if "l0==0" 
			{	
		 		tauA
			}
		else 
			{
		 		tauAA
			}
		 		p16:gp1
		 		d16
		 		p2 ph2
				p16:gp1
		 		d16

		if "l0==0" 
			{	
		 		tauA
			}
		else 
			{
		 		tauAA
			}


		if "l0==0" 
			{	
		 
			}
		else 
			{
		 		d30
			}

		if "l0==0" 
			{	
		 		tauB
			}
		else 
			{
		 		tauBBB
			}

		 		d16
		 		p17:gp2
		 		d16
	  		20u gron0 pl0:f1
				;
  			(p11:sp11 ph3):f1
				;
  			20u groff pl1:f1
		 		d16
		 		p17:gp2
		 		d16

		if "l0==0" 
			{	
		 		tauB
			}
	 else 
			{
		 		tauBBB
			}
 
		 		tauD	
		 		p18:gp3
		 		d16 
		 		p2 ph4
		 		p18:gp3
		 		d16 BLKGRAD
		if "l0==0" 
			{	
		 
			}
		else 
			{
		 		d30
			}
		

lab1, goto lab7
	
	}

else
		{

		"tauC=in10"
		"tauBB=d2-p17-2*d16-20u-in10"
		"tauC=tauC+((l8-cnst5)*in10)"
		"tauBB=tauBB-((l8-cnst5)*in10)" 
		"d40=(in0/2-in10)-((l8-cnst5)*in10)"
		"d40=d40+((l0-1)*in0)"
		"tauBBBB=d2-p17-2*d16-20u+in10"
		"tauBBBB=tauBBBB+((l8-cnst5)*in10)"
    
		p1 ph1 
		if "l0==0" 
			{	
		 		
			}
	 else 
			{
		 		tauAA
			}
		 		p16:gp1
		 		d16
		 		p2 ph2
		 		p16:gp1
		 		d16
		 if "l0==0" 
			{	
		 		
			}
	 else 
			{
		 		tauAA
			}

	  if "l0==0" 
			{	
		 
			}
		else 
			{
		 		d40
			}

		if "l0==0" 
			{	
		 		tauBB
			}
	 else 
			{
		 		tauBBBB
			}
		
		 		d16
		 		p17:gp2
		 		d16
  			20u gron0 pl0:f1
				;
  			(p11:sp11 ph3):f1
				;
  			20u groff pl1:f1
		 		d16
		 		p17:gp2
		 		d16
		if "l0==0" 
			{	
		 		tauBB
			}
	 else 
			{
		 		tauBBBB
			}

		 tauD	

		if "l0==0" 
			{	
		 		tauC
			}
	 else 
			{
		 		
			}

		 		p18:gp3
		 		d16 
		 		p2 ph4
		 		p18:gp3
		 		d16 BLKGRAD
	 if "l0==0" 
			{	
		 		tauC
			}
	 else 
			{
		 		
			}
	 
   if "l0==0" 
			{	
		 
			}
		else 
			{
		 		d40
			}
		


lab2, goto lab7
	  }
 
lab7, go=2 ph31
50m mc #0 to 2 
	F1QF(calclc(l0,1)) 
  F2QF(calclc(l8,1)) 
exit


ph1 =0 0 0 0 1 1 1 1 
ph2 =0 0 1 1 0 0 1 1 
ph3 =0 1 0 1 0 1 0 1
ph4 =0 0 0 0 0 0 0 0
ph31=0 2 2 0 3 1 1 3 


;POWER LEVEL
;pl0  : zero power (0W)
;pl1  : power level for pulse (default)
;sp11 : power level of ZS selective pulse

;PULSE DURATION
;p1: high power 90 pulse width
;p2: high power 180 pulse width
;p11: duration of ZS selective pulse

;PULSE SHAPE
;spnam11: file name of ZS selective pulse

;GRADIENT DURATION
;p16: CTP gradient pulse width
;p17: CTP gradient pulse width
;p18: CTP gradient pulse width

;GRADIENT SHAPE
;gpnam1: SINE.100
;gpnam2: SINE.100
;gpnam3: SINE.100

;GRADIENT STRENGTH
;gpz1  : CTP gradient [77%]
;gpz2  : CTP gradient [49%]
;gpz3  : CTP gradient [63%]
;gpz0: weak gradient during SSI element (1-4%)

;DELAYS
;d1: relaxation delay; 1-5 * T1
;d16: gradient stabilisation delay
;d2: delay to keep the T2 weighting constant between the pure shift experiments acquired with different evolution time [greater than 1/4SW1+p16+2*d16]


;CONSTANTS
;cnst4: number of points to drop when collecting FID
;cnst5:(td2/2)+1

;OTHERS
;td1: number of chunks to be acquired
;td2: number of different J evolution times to be averaged (N)
;ns: 8 * n, total number of scans								
;ds: 8, number of dummy scans 			
;sw1: sw3/n (n has to be an integer number) 	
;sw2: 2*N*sw1 where N is the steps in the SAPPHIRE suppression (this pulse sequence works when N is an even number)
;2sw3/sw2 should be integer 
;in0: 1/(2 * sw1) 
;in10: 1/sw2
;l8: loop counter for F2 dimension
;l0: loop counter for F1 dimension
;FnMODE1: QF
;FnMODE2: QF