// cpHXprobe - A macro to get or set calibrations from the probe
//             file for standard cross polarization with AhHX. 

//             Argument 1 is:
//                        'set' loads values into the probe file. 
//                        'get' sets values into the workspace. 
//                        'init' creates a complete set of parameter entries. 

//             Argument 2 is the nucleus, 'C13' or 'N15'.

//             Argument 3 is the region:
//                   'alpha' (13C alpha carbons or glycine methylene), code 'HCa'
//                   'carbonyl' (13C carbonyl), code 'HCO
//                   'adam' (13C adamantane 37.77p), code 'HC'
//                   'amide'(15N amide), code 'HNai'
//                   'amine' (15N glycine, code 'HNam'
//                   'amino' (15N glycine, code 'HN' 

//             Argument 4 is a label: 
//                        '' is forced as the default, not used in this macro. 
//             Argument 5 (1) forces the spectral center and width as noted 
//                            for argument 3. 
//                        (0) uses the spectral center saved in the probe file. 
//
//             Parameters: 
//                         tof,dof,dof2,tpwr,dpwr,dpwr2,aY90,pwY90 (general)
//                         aH90,pwH90 (region - H1 - hp), aX90,pwX90 (region X - C13 or 15N) 
//                         chHX,shHX,toHX,frHX,aHhx,bHX,dHX,tHX,ofHX (region - H1)
//                         aXhx (region X - C13 or N15)
//                         aHtppm,pwHtppm,phHtppm (region - H1)
//                         aHspinal,pwHspinal,phHspinal,alpHspinal (region - H1)
//                         Hseq forced to 'spinal'. 
//             Parameters ('set' only and forced to 0.0 in probe file): 
//                         pwH180,R,F (region - H1 - hp) pwH180,R,F (region - H1 - mp)
//                         pwX180,R,F (region - X - C13 or N15)
//                         

// Initialize CP Parameters in the Probe File

if (($#>0) and ($1='init')) then 

// Set the Region

   $reg='' $pwr='' $nuc='' $4=''
   $macroname = $0 + '(\'region\',$2,$3,$4,0):$reg,$pwr,$nuc'
   exec($macroname)

// Initialize the Probe File with Standard CP and Decoupling Parameters

   probeparamgroup('setlocal',$reg,$nuc,'','ofX90',tof,'dbX90',tpwr)
   probeparamgroup('setlocal',$reg,'H1','','ofX90',dof,'dbX90',dpwr)
   probeparamgroup('setlocal','hp'+$reg,'H1','','aH90',aH90,
                                                'pwH90',pwH90,
                                                'pwH180',0.0,
                                                'R',0.0,
                                                'F',0.0)

   probeparamgroup('setlocal','mp'+$reg,'H1','','aH90',aH90*pwH90/pwX90,
                                                'pwH90',pwX90,
                                                'pwH180',0.0,
                                                'R',0.0,
                                                'F',0.0)

   probeparamgroup('set',$reg,'H1','HX','ch','sh','to','fr',
                                         'aH','b','d','t','of')
   probeparamgroup('setlocal',$reg,$nuc,'', 'aX90',aX90,
                                            'pwX90',pwX90,
                                            'pwX180',0.0,
                                            'R',0.0,
                                            'F',0.0)

   probeparamgroup('set',$reg,$nuc,'HX','aX')
   probeparamgroup('set',$reg,'H1','tppmH','a','pw','ph')
   probeparamgroup('set',$reg,'H1','spinalH','a','pw','ph','alp')
   probeparamgroup('set',$reg,'H1','','Hseq')

   probeparamgroup('setlocal',$reg,$nuc,'', 'aX32wr',0.0,
                                            'aX52wr',0.0)
   probeparamgroup('setstring',$reg,$nuc,'','baserefX','0.0')
endif

// Set CP Parameters to the Probe File

if (($#>0) and ($1='set')) then 

// Set the Region

   $reg='' $pwr='' $nuc='' $4=''
   $macroname = $0 + '(\'region\',$2,$3,$4,0):$reg,$pwr,$nuc'
   exec($macroname)

// Set the Probe File with Standard CP and Decoupling Parameters

   probeparamgroup('setlocal',$reg,$nuc,'','ofX90',tof,'dbX90',tpwr)
   probeparamgroup('setlocal',$reg,'H1','','ofX90',dof,'dbX90',dpwr)
   probeparamgroup('set',$reg,'H1','HX','ch','sh','to','fr',
                                         'aH','b','d','t','of') 
   probeparamgroup('set',$reg,$nuc,'HX','aX')
   probeparamgroup('set','hp'+$reg,'H1','90H','a','pw')
   probeparamgroup('set',$reg,$nuc,'90X','a','pw')
   probeparamgroup('set',$reg,'H1','tppmH','a','pw','ph')
   probeparamgroup('set',$reg,'H1','spinalH','a','pw','ph','alp')
   probeparamgroup('set',$reg,'H1','','Hseq')
endif

// Get CP Parameters from the Probe File

if (($#>0) and ($1='get')) then

// Set the Region

   $reg='' $pwr='' $nuc='' $4=''
   $macroname = $0 + '(\'region\',$2,$3,$4,0):$reg,$pwr,$nuc'
   exec($macroname)

// Obtain Standard CP and Decoupling Parameters from Probe File

   probeparamgroup('getlocal',$reg,$nuc,'','ofX90','dbX90'):tof,tpwr
   probeparamgroup('getlocal',$reg,'H1','','ofX90','dbX90'):dof,dpwr
   probeparamgroup('get',$reg,'H1','HX','ch','sh','to','fr',
                                         'aH','b','d','t','of') 
   probeparamgroup('get',$reg,$nuc,'HX','aX')
   probeparamgroup('get','hp'+$reg,'H1','90H','a','pw')
   probeparamgroup('get',$reg,$nuc,'90X','a','pw')
   probeparamgroup('get',$reg,'H1','tppmH','a','pw','ph')
   probeparamgroup('get',$reg,'H1','spinalH','a','pw','ph','alp')
   Hseq = 'spinal'
endif

//-------------------
// The Region Macro
//-------------------

if (($# > 0) and ($1 = 'region')) then
   $nuc=$2
   $reg=''
   $pwr=$4
   if (($# > 4) and ($5 = 1)) then 
      if ($2='C13') then 
         tn='C13' dn='H1' dn2='N15' dn3=''   
         wc = 200 sc =10
         ad=4.0 rd=4.0 ddrtc=8.0 rp=0 lp=0 d1=2.0 nt=1 ss=2 bs=4
         sw=100000.0 at=0.01 fn=16.0*np sb=at/2.0 sb='y' sbs='n' lb=50 gain=30
         ofHX=0.0
         if ($3='alpha') then
            setref setoffset('C13',60):tof tof=0.1*trunc(tof/0.1 + 0.5) sp=35p wp=50p
            $reg='HCa'
         elseif ($3='carbonyl') then 
            setref setoffset('C13',175):tof tof=0.1*trunc(tof/0.1 + 0.5) sp=165p wp=20p
            $reg='HCO'
         elseif ($3='adam') then 
            setref setoffset('C13',38):tof tof=0.1*trunc(tof/0.1 + 0.5) sp=28p wp=20p
            $reg='HC'
         endif
      elseif ($2='N15') then 
         tn='N15' dn='H1' dn2='C13'  dn3=''   
         wc = 200 sc =10
         ad=16.0 rd=4.0 ddrtc=20.0 rp=0 lp=0 d1=2.0 nt=1 ss=2 bs=4
         sw=100000.0 at=0.01 fn=16.0*np sb=at/2.0 sb='y' sbs='n' lb=50 gain=30  
         ofHX=0.0
         if ($3='amide') then
            setref setoffset('N15',115):tof tof=0.1*trunc(tof/0.1 + 0.5) sp=90p wp=50p
            $reg='HNai'
         elseif ($3='amine') then 
            setref setoffset('N15',35):tof tof=0.1*trunc(tof/0.1 + 0.5) sp=15p wp=40p
            $reg='HNam'
         elseif ($3='amino') then 
            setref setoffset('N15',35):tof tof=0.1*trunc(tof/0.1 + 0.5) sp=15p wp=40p
            $reg='HN'
         endif
      endif
   else
      if ($2='C13') then 
         if ($3='alpha') then
            $reg='HCa'
         elseif ($3='carbonyl') then 
            $reg='HCO'
         elseif ($3='adam') then 
            $reg='HC'
         endif
      elseif ($2='N15') then 
         if ($3='amide') then
            $reg='HNai'
         elseif ($3='amine') then 
            $reg='HNam'
         elseif ($3='amino') then 
            $reg='HN'
         endif
      endif
   endif
   return($reg,$pwr,$nuc)
endif

