// solidsetup - creates basic calibration parameters for SolidsPack and 
// supplies parameters for the sequence tancpx.c.  Generally used to open 
// a SolidsPack setup macro.  Typically "solidsetup" is followed by "paramgroup"
// statements to define parameters and/or group displays. "paramgroup"
// statements are also required to display the parameters for "HX" and "Hspinal"
// and "Htppm" if they are used in the sequence, even though these parameter 
// groups are defined in "solidsetup". "solidsetup" defines and intializes the 
// parameters:

//    dgrowindex - keeps track of the rows in the "dg" template and aborts 
//                   "createparam" if more than 72 rows are defined. 
//    aprowindex - keeps track of the rows in the "ap" template and aborts 
//                  "createparam" if more than 72 rows are defined. 
//    dgcharindex - keeps track of the number of characters in "dg" parameter 
//                  and aborts "createparam" if more than 1023 characters 
//                   are defined. 
//    apcharindex - keeps track of the number of characters in "ap" parameter 
//                  and aborts "createparam" if more than 1023 characters 
//                   are defined.
//    clearparams - a string containing parameter names fow which the protocol 
//                  should clear bit 14.  "clearparams" contains channel parameters
//                  which must be set by the protocol and then cleared to allow 
//                  further change. 
// 
// Close a SolidsPack setup macro with "closesolidsetup". "dgrowindex","aprowindex",
// "dgcharindex" and "apcharindex" are destroyed.  See also: paramgroup and createparam. 


seqfil = 'tancpx'

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

//---------------
// cpHX elements
//---------------

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

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

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

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

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

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

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

exists('dHX','parameter'):$e
if ($e < 0.5) then
   create('dHX','real')
   setlimit('dHX',4095,-4095,1)
endif 

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

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

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

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

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

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

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

exists('phHtppm','parameter'):$e
if ($e < 0.5) then
    create('phHtppm','real')
    setlimit('phHtppm',180,-180,0.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)
endif

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

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

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

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

$params = 'frHX toHX chHspinal chHtppm '
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 = 'frHX toHX chHspinal chHtppm'
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,temp:0,srate:1;'
dg = $dg
setprotect('dg','on',4)

setprotect('dg2','clear',4)
$dg2 = '1:OBSERVE:tn,sfrq:6,tof:1,tpwr:0,aX90:0,pwX90:1;'
$dg2=$dg2+'2:DECOUPLE:dn,dfrq:6,dof:1,dpwr:0,aH90:0,pwH90:1;'
$dg2=$dg2+'3:DECOUPLE2:dn2,dfrq2:6,dof2:1,dpwr2:0,aY90:0,pwY90:1;'
$dg2=$dg2+'4:DECOUPLE3:dn3,dfrq3:6,dof3:1,dpwr3:0,aZ90:0,pwZ90:1;'
dg2 = $dg2
setprotect('dg2','on',4)

setprotect('ap','clear',4)
$ap = '1:SAMPLE:date,temp:1,srate:1;'
$ap = $ap + '1:ACQUISITION:tn,sfrq:6,tof:1,tpwr:0,sw:1,at:6,np:0,d1:6,nt:0,ct:0,ss:0,rd:1,ad:1,aX90:0,pwX90:1;'
$ap = $ap + '1(ni):2D ACQUISITION:d2:6,sw1:1,ni:0,phase: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
setvalue('ap',$ap,'processed')
setprotect('ap','on',4)

//----------------------------------------------
// Set the the number of ap rows and characters
//----------------------------------------------

exists('aprowindex','parameter'):$e
if ($e < 0.5) then
   create('aprowindex','real')
   setlimit('aprowindex',1024,0,1)
   aprowindex = 0
endif

exists('apcharindex','parameter'):$e
if ($e < 0.5) then
   create('apcharindex','real')
   setlimit('apcharindex',1024,0,1)
   apcharindex = 0
endif

length(ap):$apcharindex
apcharindex = $apcharindex
aprowindex = 26
exists('dfrq2','parameter'):$e
if ($e > 0.5) then 
   if (dfrq2 > 0.0) then 
      aprowindex = aprowindex + 6
   endif
endif 
exists('dfrq3','parameter'):$e
if ($e > 0.5) then 
   if (dfrq3 > 0.0) then 
      aprowindex = aprowindex + 6 
   endif
endif 

//---------------------------------------------
// Set the the number of dg rows and characters
//---------------------------------------------

exists('dgrowindex','parameter'):$e
if ($e < 0.5) then
   create('dgrowindex','real')
   setlimit('dgrowindex',1024,0,1)
   dgrowindex = 0
endif

exists('dgcharindex','parameter'):$e
if ($e < 0.5) then
   create('dgcharindex','real')
   setlimit('dgcharindex',1024,0,1)
   dgcharindex = 0
endif

length(dg):$dgcharindex
dgcharindex = $dgcharindex
dgrowindex = 15
exists('rof3','parameter'):$e
if ($e > 0.5) then 
   if (rof3 > 0.0) then
      dgrowindex = dgrowindex + 1
   endif
endif 

