seqfil = 'ahYX'

//------------------------------
// Axis Assign and bioref
//------------------------------

exists('axAssgn','parameter'):$e
if $e < 0.5 then
   create('axAssgn','flag')
   setvalue('axAssgn','31')
endif 

exists('bioref','parameter'):$e
if $e < 0.5 then
   create('bioref','flag')
endif
setvalue('bioref','y') 

exists('BPautonoisecheck','parameter'):$e
if $e < 0.5 then
   create('BPautonoisecheck','real')
   BPautonoisecheck = 0.0
endif 

exists('BPclassic','parameter'):$e
if $e < 0.5 then
   create('BPclassic','string')
   BPclassic='n'
endif 

//-----------------------------
// ND Referencing Parameters
//-----------------------------

exists('refsource1','parameter'):$e
if $e < 0.5 then
   create('refsource1','flag')
   refsource1='sfrq' 
endif

exists('axis','parameter'):$e
if $e < 0.5 then
   create('axis','flag')
   axis='p2' 
endif

//------------------------------
// Receiver Delays
//------------------------------

exists('rd','parameter'):$e
if $e < 0.5 then
   create('rd','pulse')
   setlimit('rd',8192,0,0.0125)
   rd = 4.0  
endif 

exists('ad','parameter'):$e
if $e < 0.5 then
   create('ad','pulse')
   setlimit('ad',8192,0,0.0125)
   ad = 4.0  
endif

exists('ddrtc','parameter'):$e
if $e < 0.5 then
   create('ddrtc','pulse')
   setlimit('ddrtc',8192,0,0.0125)
   ddrtc = 8.0  
endif

exists('roff','parameter'):$e
if $e < 0.5 then
   create('roff','frequency')
   roff = 0.0
endif

//------------------------------
// Spin Rate
//------------------------------

exists('srate','parameter'):$e
if $e < 0.5 then
   create('srate','frequency')
   srate = 5000
endif 

exists('hsrotor','parameter'):$e
if $e < 0.5 then
   create('hsrotor','flag')
   setvalue('hsrotor','n') 
endif

//==================
// 2D acq parameters
//==================

exists('ni','parameter'):$e
if ($e = 0) then
   create('ni','integer')
   setlimit('ni',32767,0,1)
   ni = 1
endif

exists('sw1','parameter'):$e
if ($e = 0) then
   create('sw1','real')
   setlimit('sw1',5.0e6,1,parstep[5])
   sw1 = 50000.0
endif

exists('phase','parameter'):$e
if ($e = 0) then
   create('phase','integer')
   phase = 1,2
endif

exists('d2','parameter'):$e
if ($e < 0.5) then 
   create('d2','delay')
   parunits('set','d2','us')
   d2 = 0.0
endif

exists('d2acqret','parameter'):$e
if ($e < 0.5) then 
   create('d2acqret','delay')
   parunits('set','d2acqret','us')
   d2acqret = 0.0
endif

exists('d2dwret','parameter'):$e
if ($e < 0.5) then 
   create('d2dwret','delay')
   parunits('set','d2dwret','us')
   d2dwret = 0.0
endif

//------------------------------
// Basic Transmitter Properties
//------------------------------

exists('aX90','parameter'):$e
if $e < 0.5 then
   create('aX90','real')
   setlimit('aX90',4095,0,0)
   aX90 = 2000.0 
endif 

exists('aH90','parameter'):$e
if $e < 0.5 then
   create('aH90','real')
   setlimit('aH90',4095,0,0)
   aH90 = 2000.0  
endif 

exists('aY90','parameter'):$e
if $e < 0.5 then
   create('aY90','real')
   setlimit('aY90',4095,0,0) 
   aY90 = 2000.0
endif

exists('aZ90','parameter'):$e
if $e < 0.5 then
   create('aZ90','real')
   setlimit('aZ90',4095,0,0) 
   aZ90 = 2000.0 
endif

exists('pwX90','parameter'):$e
if $e < 0.5 then
   create('pwX90','pulse')
   setlimit('pwX90',8192,0,0.0125)
   pwX90 = 4.0
endif 

exists('pwH90','parameter'):$e
if $e < 0.5 then
   create('pwH90','pulse')
   setlimit('pwH90',8192,0,0.0125)
   pwH90 = 4.0
endif 

exists('pwY90','parameter'):$e
if $e < 0.5 then
   create('pwY90','pulse')
   setlimit('pwY90',8192,0,0.0125)
   pwY90 = 4.0
endif

exists('pwZ90','parameter'):$e
if $e < 0.5 then
   create('pwZ90','pulse')
   setlimit('pwZ90',8192,0,0.0125)
   pwZ90 = 4.0
endif

//---------------
// cpHY elements
//---------------

exists('shHY','parameter'):$e
if $e < 0.5 then
    create('shHY','flag')
    setvalue('shHY','c') 
endif

exists('toHY','parameter'):$e
if $e < 0.5 then
   create('toHY','flag')
endif 
setvalue('toHY','dec2')

exists('frHY','parameter'):$e
if $e < 0.5 then
   create('frHY','flag')
endif
setvalue('frHY','dec')  

exists('chHY','parameter'):$e
if $e < 0.5 then
   create('chHY','flag')
   setvalue('chHY','fr') 
endif 

exists('aHhy','parameter'):$e
if $e < 0.5 then
   create('aHhy','real')
   setlimit('aHhy',4095,0,0)
   aHhy = 2000.0
endif 

exists('aYhy','parameter'):$e
if $e < 0.5 then
   create('aYhy','real')
   setlimit('aYhy',4095,0,0)
   aYhy = 2000.0
endif   

exists('bHY','parameter'):$e
if $e < 0.5 then
   create('bHY','real')
   setlimit('bHY',1000000,1.0e-6,0)
   bHY = 1.0e-6
endif 

exists('dHY','parameter'):$e
if $e < 0.5 then
   create('dHY','real')
   setlimit('dHY',4095,-4095,0)
   dHY = 0.0
endif 

exists('tHY','parameter'):$e
if $e < 0.5 then
   create('tHY','pulse')
   setlimit('tHY',50000,0.0,0.0125)
   tHY = 1000.0
endif

exists('ofHY','parameter'):$e
if $e < 0.5 then
   create('ofHY','frequency')
   ofHY = 0.0
endif  

//--------------------------
// N Constant Time Elements
//--------------------------

exists('ctN','parameter'):$e
if $e < 0.5 then
    create('ctN','flag')
    setvalue('ctN','n')
endif

exists('t2max','parameter'):$e
if $e < 0.5 then
   create('t2max','pulse')
   setlimit('t2max',50000,0,0.0125)
   t2max = 2000.0
endif

//---------------
// cpYX elements
//---------------

exists('shYX','parameter'):$e
if $e < 0.5 then
    create('shYX','flag')
    setvalue('shYX','c') 
endif

exists('toYX','parameter'):$e
if $e < 0.5 then
   create('toYX','flag')
endif 
setvalue('toYX','obs')

exists('frYX','parameter'):$e
if $e < 0.5 then
   create('frYX','flag')
endif
setvalue('frYX','dec2')  

exists('chYX','parameter'):$e
if $e < 0.5 then
   create('chYX','flag')
   setvalue('chYX','from') 
endif 

exists('aXyx','parameter'):$e
if $e < 0.5 then
   create('aXyx','real')
   setlimit('aXyx',4095,0,0)
   aXyx = 2000.0
endif 

exists('aYyx','parameter'):$e
if $e < 0.5 then
   create('aYyx','real')
   setlimit('aYyx',4095,0,0)
   aYyx = 2000.0
endif   

exists('bYX','parameter'):$e
if $e < 0.5 then
   create('bYX','real')
   setlimit('bYX',1000000,1.0e-6,0)
   bYX = 1.0e-6
endif 

exists('dYX','parameter'):$e
if $e < 0.5 then
   create('dYX','real')
   setlimit('dYX',4095,-4095,0)
   dYX = 0.0
endif 

exists('tYX','parameter'):$e
if $e < 0.5 then
   create('tYX','pulse')
   setlimit('tYX',50000,0.0,0.0125)
   tYX = 1000.0
endif

exists('ofYX','parameter'):$e
if $e < 0.5 then
   create('ofYX','frequency')
   ofYX = 0.0
endif 

//=====================
// decoupling options
//======================

exists('Hseq','parameter'):$e
if $e < 0.5 then
   create('Hseq','flag')
   setvalue('Hseq','spinal')  
endif

//-----------
// tppm
//-----------

exists('aHtppm','parameter'):$e
if $e < 0.5 then
   create('aHtppm','real')
   setlimit('aHtppm',4095,0,0)
   aHtppm = 2000.0
endif

exists('pwHtppm','parameter'):$e
if $e < 0.5 then
   create('pwHtppm','pulse')
   setlimit('pwHtppm',8192,0,0.0125)
   pwHtppm = 8.0
endif

exists('phHtppm','parameter'):$e
if $e < 0.5 then
   create('phHtppm','real')
   setlimit('phHtppm',180.0,-180.0,0.0)
   phHtppm = 10.0
endif

exists('chHtppm','parameter'):$e
if $e < 0.5 then
   create('chHtppm','flag')
endif 
setvalue('chHtppm','dec')

//------------------------------
//  spinal 
//------------------------------

exists('aHspinal','parameter'):$e
if $e < 0.5 then
   create('aHspinal','real')
   setlimit('aHspinal',4095,0,0)
   aHspinal = 2000.0
endif

exists('pwHspinal','parameter'):$e
if $e < 0.5 then
   create('pwHspinal','pulse')
   setlimit('pwHspinal',8192,0,0.0125)
   pwHspinal = 8.0
endif

exists('phHspinal','parameter'):$e
if $e < 0.5 then
   create('phHspinal','real')
   setlimit('phHspinal',180.0,-180.0,0.0)
   phHspinal = 10.0
endif

exists('alpHspinal','parameter'):$e
if $e < 0.5 then
   create('alpHspinal','real')
   setlimit('alpHspinal',180.0,-180.0,0.0)
   alpHspinal = 5.0
endif

exists('chHspinal','parameter'):$e
if $e < 0.5 then
   create('chHspinal','flag')
endif 
setvalue('chHspinal','dec')

//========================================
// SPINAL, TPPM or WALTZ for Y decoupling
//========================================

exists('ddec2','parameter'):$e
if $e < 0.5 then
    create('ddec2','flag')
    setvalue('ddec2','n')
endif

exists('Yseq','parameter'):$e
if $e < 0.5 then
    create('Yseq','flag')
    setvalue('Yseq','waltz')
endif

//-----------
// dec2 tppm
//-----------

exists('aYtppm','parameter'):$e
if $e < 0.5 then
   create('aYtppm','real')
   setlimit('aYtppm',4095,0,0)
   aYtppm = 2000.0
endif

exists('pwYtppm','parameter'):$e
if $e < 0.5 then
   create('pwYtppm','pulse')
   setlimit('pwYtppm',10000,0,0.0125)
   pwYtppm = 8.0
endif

exists('phYtppm','parameter'):$e
if $e < 0.5 then
   create('phYtppm','real')
   setlimit('phYtppm',180.0,-180.0,0.0)
   phYtppm = 10.0
endif

exists('chYtppm','parameter'):$e
if $e < 0.5 then
   create('chYtppm','flag')
endif 
setvalue('chYtppm','dec2')

//------------------------------
//  dec2 spinal 
//------------------------------

exists('aYspinal','parameter'):$e
if $e < 0.5 then
   create('aYspinal','real')
   setlimit('aYspinal',4095,0,0)
   aYspinal = 2000.0
endif

exists('pwYspinal','parameter'):$e
if $e < 0.5 then
   create('pwYspinal','pulse')
   setlimit('pwYspinal',10000,0,0.0125)
   pwYspinal = 8.0
endif

exists('phYspinal','parameter'):$e
if $e < 0.5 then
   create('phYspinal','real')
   setlimit('phYspinal',180.0,-180.0,0.0)
   phYspinal = 10.0
endif

exists('chYspinal','parameter'):$e
if $e < 0.5 then
   create('chYspinal','flag')
endif 
setvalue('chYspinal','dec2')

exists('alpYspinal','parameter'):$e
if $e < 0.5 then
   create('alpYspinal','real')
   setlimit('alpYspinal',180.0,-180.0,0.0)
   alpYspinal = 5.0
endif

//------------------------------
//  dec2 waltz 
//------------------------------

exists('aYwaltz','parameter'):$e
if $e < 0.5 then
   create('aYwaltz','real')
   setlimit('aYwaltz',4095,0,0)
   aYwaltz = 2000.0
endif

exists('pwYwaltz','parameter'):$e
if $e < 0.5 then
   create('pwYwaltz','pulse')
   setlimit('pwYwaltz',10000,0,0.0125)
   pwYwaltz = 4.0
endif

exists('chYwaltz','parameter'):$e
if $e < 0.5 then
   create('chYwaltz','flag')
endif 
setvalue('chYwaltz','dec2')

//---------------------
//  DARR Mxing Period 
//--------------------

exists('aHmix','parameter'):$e
if $e < 0.5 then
   create('aHmix','real')
   setlimit('aHmix',4095,0,0)
   aHmix = 2000.0
endif 

exists('tXmix','parameter'):$e
if $e < 0.5 then
   create('tXmix','pulse')
   setlimit('tXmix',500000.0,0.0,0.0125)
   tXmix = 200.0
endif

//=================================================
// Set Constant-time Decoupling 
//=================================================

exists('ctd','parameter'):$e
if $e < 0.5 then
   create('ctd','flag')
   setvalue('ctd','y')
endif

exists('tRFmax','parameter'):$e
if $e < 0.5 then
   create('tRFmax','pulse')
   setlimit('tRFmax',500000.0,0,0.0125)
   tRFmax = 5000.0
endif

//==============================
// Choose a Mixing Sequence 
//==============================

exists('mMix','parameter'):$e
if $e < 0.5 then
    create('mMix','flag')
    setvalue('mMix','darr')
endif

//------------------------------
//  Additional 
//------------------------------

exists('aHyx','parameter'):$e
if $e < 0.5 then
   create('aHyx','real')
   setlimit('aHyx',4095,0,0)
   aHyx = 2000.0
endif 

// --------------------------------------------------
// Set parameters specific to the experiment
// --------------------------------------------------

exists('wrtp','parameter'):$e
if ($e < 0.5) then 
   create('wrtp','string')
endif
wrtp = 'reset_ahYX'
reset_ahYX

//------------------------------------------------
//  Set Bit 14 for new parameters of the .par file 
//------------------------------------------------

$params = 'frHY toHY frYX toYX chHspinal chHtppm chYspinal chYtppm chYwaltz '
$params = $params + 'refsource1 axis BPautonoisecheck BPclassic wrtp '
$params = $params + 'roff sw1 ni phase d2 d2acqret d2dwret '
$params = $params + 'shHY chHY aHhy aYhy bHY dHY tHY ofHY '
$params = $params + 'shYX chYX aYyx aXyx bYX dYX tYX ofYX '
$params = $params + 'alpHspinal '
$params = $params + 'aYspinal pwYspinal alpYspinal phYspinal Yseq ddec2 '
$params = $params + 'aYtppm pwYtppm phYtppm aYwaltz pwYwaltz '
$params = $params + 'aHyx t2max tRFmax ctN ctd '
$params = $params + 'aHmix tXmix mMix'
setprotect('','clear',16384)
setprotect($params, 'on', 16384)

//--------------------------------------------------------
//  Clear parameters in 'clearparams' in the apptype macro
//--------------------------------------------------------

exists('clearparams','parameter'):$e
if $e < 0.5 then
   create('clearparams','string')
endif
setprotect('clearparams','on',16384)
$clearparams = 'frHY toHY frYX toYX chHspinal chHtppm chYspinal chYtppm chYwaltz ' 
$clearparams = $clearparams + 'refsource1 axis '
setvalue('clearparams',$clearparams)

//------------------------------------------------
//  Set the parameter templates
//------------------------------------------------

setprotect('dg','clear',4)
$dg = '1:ACQUISITION:sw:1,at:6,np:0,d1:6,nt:0,ct:0,bs:0,'
$dg = $dg + 'ss:0,rd:1,ad:1,ddrtc:1,rof3(rof3):1,gain:0,roff:1,temp:0,srate:1;'
$dg = $dg + '1:cpHY:shHY,chHY,aHhy:0,aYhy:0,bHY:6,dHY:6,tHY:1,ofHY:3;'
$dg = $dg + '1:cpYX:shYX,chYX,aYyx:0,aXyx:0,bYX:6,dYX:6,tYX:1,ofYX:3,aHyx:0;'
$dg = $dg + '1(Hseq=\'tppm\'):tppmH:aHtppm:0,pwHtppm:1,phHtppm:2;'
$dg = $dg + '1(Hseq=\'spinal\'):spinalH:aHspinal:0,pwHspinal:1,phHspinal:2;'
$dg = $dg + '1(Yseq=\'tppm\' and ddec2=\'y\'):tppmY:aYtppm:0,pwHtppm:1,phHtppm:2;'
$dg = $dg + '1(Yseq=\'spinal\' and ddec2=\'y\'):spinalY:aYspinal:0,pwYspinal:1,phYspinal:2,alpYspinal:2;'
$dg = $dg + '1(Yseq=\'waltz\' and ddec2=\'y\'):waltzY:aYwaltz:0,pwYwaltz:1;'
$dg = $dg + '1(ctN=\'y\'):CONSTANT Y d2:t2max:1;'
$dg = $dg + '1(ctN<>\'y\'):STANDARD Y d2:;'
$dg = $dg + '1(ctd=\'y\'):CONSTANT DECOUPLE:tRFmax:1;'
$dg = $dg + '1(ctd<>\'y\'):STANDARD DECOUPLE:;'
dg[1] = $dg
$dg = ''
$dg = $dg + '1(mMix=\'darr\'):DARR MIXING:tXmix:1,aHmix:1;'
$dg = $dg + '1:FLAGS:ctN,ctd,ddec2;'
dg[2] = $dg

setprotect('dg2','clear',4)
$dg2 = '1:OBSERVE:tn,sfrq:6,tof:1,tpwr:0,aX90:0,pwX90:1;'
$dg2=$dg2+'1:1D Acquisition:sw:1,np:0,at:7;'
$dg2=$dg2+'2:DECOUPLE:dn,dfrq:6,dof:1,dpwr:0,aH90:0,pwH90:1;'
$dg2=$dg2+'2:2D Acquisition:sw1:1,ni:0,phase:0,d2:7,d2acqret:7,d3dwret:7;'
$dg2=$dg2+'3:DECOUPLE2:dn2,dfrq2:6,dof2:1,dpwr2:0,aY90:0,pwY90:1;'
$dg2=$dg2+'3:3D Acquisition:sw2:1,ni2:0,phase2:0,d3:7,d3acqret:7,d3dwret:7;'
dg2 = $dg2
setprotect('dg2','on',4)

setprotect('ap','clear',4)
$ap = '1:SAMPLE:date,temp:1,srate:1,file;'
$ap = $ap + '1:ACQUISITION:sw:1,at:6,np:0,d1:6,nt:0,ct:0,bs:0,'
$ap = $ap + 'ss:0,rd:1,ad:1,ddrtc:1,rof3(rof3):1,gain:0,roff:1;'
$ap = $ap + '1(ni):2D ACQUISITION:d2:6,sw1:1,ni:0,phase:0;'
$ap = $ap + '1(ni2):3D ACQUISITION:d3:6,sw2:1,ni2:0,phase2:0;'
$ap = $ap + '1:DECOUPLE:dn,dfrq:6,dof:1,dpwr:0,aH90:0,pwH90:1;'
$ap = $ap + '1(dfrq2>0):DECOUPLE2:dn2,dfrq2:6,dof2:1,dpwr2:0,aY90:0,pwY90:1;'
$ap = $ap + '1(dfrq3>0):DECOUPLE3:dn3,dfrq3:6,dof3:1,dpwr3:0,aZ90:0,pwZ90:1;'
$ap = $ap + '1:cpHY:shHY,chHY,aHhy:0,aYhy:0,bHY:6,dHY:6,tHY:1,ofHY:3;'
$ap = $ap + '1:cpYX:shYX,chYX,aYyx:0,aXyx:0,bYX:6,dYX:6,tYX:1,ofYX:3,aHyx:0;'
ap[1] = $ap
$ap = ''
$ap = $ap + '1(Hseq=\'tppm\'):tppmH:aHtppm:0,pwHtppm:1,phHtppm:2;'
$ap = $ap + '1(Hseq=\'spinal\'):spinalH:aHspinal:0,pwHspinal:1,phHspinal:2;'
$ap = $ap + '1(Yseq=\'tppm\' and ddec2=\'y\'):tppmY:aYtppm:0,pwHtppm:1,phHtppm:2;'
$ap = $ap + '1(Yseq=\'spinal\' and ddec2=\'y\'):spinalY:aYspinal:0,pwYspinal:1,phYspinal:2,alpYspinal:2;'
$ap = $ap + '1(Yseq=\'waltz\' and ddec2=\'y\'):waltzY:aYwaltz:0,pwYwaltz:1;'
$ap = $ap + '1(ctN=\'y\'):CONSTANT d2:t2max:1;'
$ap = $ap + '1(ctN<>\'y\'):STANDARD d2:;'
$ap = $ap + '1(ctd=\'y\'):CONSTANT DECOUPLE:tRFmax:1;'
$ap = $ap + '1(ctd<>\'y\'):STANDARD DECOUPLE:;'
ap[2] = $ap
$ap = ''
$ap = $ap + '1(mMix=\'darr\'):DARR MIXING:tXmix:1,aHmix:1;'
$ap = $ap + '1:FLAGS:ctN,ctd,ddec2;'
ap[3] = $ap
setvalue('ap',$ap,'processed')
setprotect('ap','on',4)

