// dcpYXprobe - A macro to get or set YX CP calibrations to or from the
//              probe file for 1D and 2D DCP experiments (AhYX). 

//       Note: (Only CP) Standard parameters are set by cpHXprobe and cpHYprobe. 

//             Argument 1 is:
//                        'set' loads values into the probe file. 
//                        'get' sets values into the workspace. 
//                        'init' creates and loads values inot the probe 
//                               file (identical to 'set'). 
//                        'calc' sets the probe file for DCP based on aX32wr 
//                               (X-region) and aX52wr (Y-region) from the 
//                               probe file. 

//             Argument 2 is the observe X nucleus 'C13' 
//                       (At present: 13C is always the X nucleus)

//             Argument 3 is the region:
//                       'alpha'(13C alpha),DCP code $reg2 = 'NCa', $reg = 'HCa'
//                       'carbonyl(13C carbonyl), DCP code $reg2 = 'NCO', $reg='HCO' 
//                        At present: the 15N region if fixed as 'amide, $reg1 = 'HNai'

//             Argument 4 is a label: 
//                        '' is forced as the default, not used in this macro. 
//             Argument 5 is a numeral:
//                        usually 0 or 1 if present, but not used.
//
//             Set Parameters ('get','set','init'): 
//                      Nucleus                Workspace <-> Probe                 Region
//                     (Y = 15N) chYX,shYX,toYX,frYX,aYyx,bYX,dYX,tYX,ofYX <->
//                                 chYX,shYX,toYX,frYX,aYyx,bYX,dYX,tYX,ofYX   (C13, DCP alpha,DCP carbonyl)
//                     (X = 13C) aXyx <-> aXyx                                 (for all params)
//                           (H) aHyx <-> aHyx                                 
//                         
//        (B)  Calculate Parameters ('calc') 
//                       Nucleus               Value <-> Probe                     Region
//                     (Y = 15N) 'fr','t','obs','dec',$aX52wr,(*1),(*2),3000.0,0.0 <->
//                                 chYX,shYX,toYX,frYX,aYyx,bYX,dYX,tYX,ofYX   (C13, DCP alpha, DCP carbonyl)
//                     (X = 13C) aXyx <-> $aX32wr                              (for all params)
//                           (H) aHyx <-> $aH90_hp                                

//             NOTES: for Calculations Above '$' refers to values obtained 
//                    from the probe file. 

//             $aX32wr is obtained from the X region (C13, alpha, carbonyl only)
//             $aH90_hp is obtained from the X region (C13, alpha, carbonyl only)
//             $aX52wr is obtained from the Y region  (N15, amide only)
//             (*1) = 0.05*$aX52wr   
//             (*2) = 0.05*$aX52wr

// Initialize CP Parameters in the Probe File

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

// Set AhYX

   AhYX

// Set the X Region

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

// Set the Region-code for YX CP, $reg2 from the X Region, $reg

   $reg2=''
   if ($reg = 'HCa') then 
      $reg2 = 'NCa'
   else
      $reg2 = 'NCO'
   endif  

// Calculate the $reg2 Parameters of the Probe File from 
// aX52wr ('N15', amide) and aX32wr of $reg ('C13', alpha, carbonyl)
// Calculate aHyx from aH90 of $reg ('C13', alpha, carbonyl)

   probeparamgroup('getlocal','HNai','N15','','aX52wr'):$aX52wr
   probeparamgroup('setlocal',$reg2,'N15','YX','ch','fr',
                                               'sh','t',
                                               'to','obs',
                                               'fr','dec2',
                                               'aY',$aX52wr,
                                               'b',0.05*$aX52wr,
                                               'd',0.05*$aX52wr,
                                               't',3000.0,
                                               'of',0.0)
   probeparamgroup('getlocal',$reg,'C13','','aX32wr'):$aX32wr
   probeparamgroup('setlocal',$reg2,$nuc,'YX','aX',$aX32wr)
   probeparamgroup('getlocal','hp'+$reg,'H1','','aH90'):$aH90
   probeparamgroup('setlocal',$reg2,'H1','','aHyx',$aH90)
endif

// Initialize CP Parameters in the Probe File

if (($#>0) and ($1='init')) then     //'init' is identical to 'set')

// Set AhYX

   AhYX

// Set the X Region

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

// Set the Region-code for YX CP, $reg2 from the X Region, $reg

   $reg2=''
   if ($reg = 'HCa') then 
      $reg2 = 'NCa'
   else
      $reg2 = 'NCO'
   endif  

// Set $reg2 Parameters of the Probe File from YX CP

   probeparamgroup('set',$reg2,'N15','YX','ch','sh','to','fr',
                                         'aY','b','d','t','of')
   probeparamgroup('set',$reg2,$nuc,'YX','aX')
   probeparamgroup('set',$reg2,'H1','','aHyx')
endif

// Set YX CP Parameters From the Probe File

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

// Set AhYX

   AhYX

// Set the X Region

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

// Set the Region-code for YX CP, $reg2 from the X Region, $reg

   $reg2=''
   if ($reg = 'HCa') then 
      $reg2 = 'NCa'
   else
      $reg2 = 'NCO'
   endif 

// Set $reg2 Parameters of the Probe File from YX CP

   probeparamgroup('set',$reg2,'N15','YX','ch','sh','to','fr',
                                         'aY','b','d','t','of') 
   probeparamgroup('set',$reg2,$nuc,'YX','aX')
   probeparamgroup('set',$reg2,'H1','','aHyx')
endif

// Get YX CP Parameters from the Probe File

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

// Set AhYX

   AhYX

// Set the X Region

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

// Set the Region-code for YX CP from the X Region

   $reg2=''
   if ($reg = 'HCa') then 
      $reg2 = 'NCa'
   else
      $reg2 = 'NCO'
   endif 

// Obtain YX CP Parameters from $reg2 of the Probe File.

   probeparamgroup('get',$reg2,'N15','YX','ch','sh','to','fr',
                                         'aY','b','d','t','of') 
   probeparamgroup('get',$reg2,$nuc,'YX','aX')
   probeparamgroup('get',$reg2,'H1','','aHyx')
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
            d1=2.0 nt=1
            setref setoffset('C13',60):$tof tof=0.1*trunc($tof/0.1 + 0.5) sp=35p wp=50p
            $reg='HCa'
         elseif ($3='carbonyl') then 
            d1=2.0 nt=1
            setref setoffset('C13',175):$tof tof=0.1*trunc($tof/0.1 + 0.5) sp=165p wp=20p
            $reg='HCO'
         elseif ($3='adam') then 
            d1=2.0 nt=1.0
            setref setoffset('C13',33.3):$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 ss=2 bs=4
         sw=100000.0 at=0.01 fn=16.0*np sb=at/2.0 sb='y' sbs='n' lb=0  lb='n' gain=30  
         ofHX=0.0
         if ($3='amide') then
            d1=2.0 nt=1
            setref setoffset('N15',115):$tof tof=0.1*trunc($tof/0.1 + 0.5) sp=90p wp=50p
            $reg='HNai'
         elseif ($3='amine') then
            d1=2.0 nt=1 
            setref setoffset('N15',35):$tof tof=0.1*trunc($tof/0.1 + 0.5) sp=15p wp=40p
            $reg='HNam'
         elseif ($3='amino') then 
            d1=2.0 nt=1
            setref setoffset('N15',35):$tof tof=0.1*trunc($tof/0.1 + 0.5) sp=15p wp=40p
            $reg='HN'
         endif         
      endif
      probeparamgroup('setlocal',$reg,$nuc,'','ofX90',tof)
   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


