pulsesequence()
{
/* DECLARE VARIABLES */

 char       autocal[MAXSTR],  /* auto-calibration flag */
            fsat[MAXSTR],
	    fscuba[MAXSTR],
            f1180[MAXSTR],    /* Flag to start t1 @ halfdwell             */
            f2180[MAXSTR],    /* Flag to start t2 @ halfdwell             */
            f3180[MAXSTR],    /* Flag to start t3 @ halfdwell             */
            fco180[MAXSTR],    /* Flag for checking sequence              */
            fca180[MAXSTR],    /* Flag for checking sequence              */
            spca180[MAXSTR],  /* string for the waveform Ca 180 */
            spco180[MAXSTR],  /* string for the waveform Co 180 */
            spchirp[MAXSTR],  /* string for the waveform reburp 180 */
            ddseq[MAXSTR],    /* 2H decoupling seqfile */
            shp_sl[MAXSTR],   /* string for seduce shape */
            sel_flg[MAXSTR];

 int         phase, phase2, phase3, ni2, ni3, icosel,
             t1_counter,   /* used for states tppi in t1           */ 
             t2_counter,   /* used for states tppi in t2           */ 
             t3_counter;   /* used for states tppi in t3           */ 

 double      tau1,         /*  t1 delay */
             tau2,         /*  t2 delay */
             tau3,         /*  t2 delay */
             taua,         /*  ~ 1/4JNH =  2.25 ms */
             taub,         /*  ~ 1/4JNH =  2.25 ms */
             zeta,        /* time for C'-N to refocuss set to 0.5*24.0 ms */
             bigTN,       /* nitrogen T period */
             pwc90,       /* PW90 for c nucleus @ d_c90         */
             pwc180on,    /* PW180 at @ d_c180         */
             pwchirp,     /* PW180 for ca nucleus @ d_creb         */
             pwc180off,     /* PW180 at d_c180 + pad              */
             tsatpwr,     /* low level 1H trans.power for presat  */
             d_c90,       /* power level for 13C pulses(pwc90 = sqrt(15)/4delta)
                             delta is the separation between Ca and Co  */
             d_c180,      /* power level for 180 13C pulses
				(pwc180on=sqrt(3)/2delta   */
	     d_chirp,
             sw1,          /* sweep width in f1                    */             
             sw2,          /* sweep width in f2                    */             
             sw3,          /* sweep width in f3                    */             
             pw_sl,        /* pw90 for H selective pulse on water ~ 2ms */
             phase_sl,     /* phase for pw_sl */
             tpwrsl,       /* power level for square pw_sl       */

	     pwDlvl,	   /* Power for D decoupling */
	     pwD,	   /* pw90 at pwDlvl  */

	     pwC, pwClvl,  /* C-13 calibration */
	     compC, 

             pwN,         /* PW90 for 15N pulse              */
             pwNlvl,       /* high dec2 pwr for 15N hard pulses    */

             gstab,       /* delay to compensate for gradient gt5 */

             gt1,
             gt2,
             gt3,
             gt4,
             gt5,
             gt6,
             gt7,
             gt8,
             gt9,
             gzlvl1,
             gzlvl2,
             gzlvl3,
             gzlvl4,
             gzlvl5,
             gzlvl6,
             gzlvl7, 
             gzlvl8, 
             gzlvl9; 

/* LOAD VARIABLES */


  getstr("autocal",autocal);
  getstr("fsat",fsat);
  getstr("fco180",fco180);
  getstr("fca180",fca180);
  getstr("f1180",f1180);
  getstr("f2180",f2180);
  getstr("f3180",f3180);
  getstr("fscuba",fscuba);
  getstr("ddseq",ddseq);
  getstr("shp_sl",shp_sl);

  getstr("sel_flg",sel_flg);

  taua   = getval("taua"); 
  taub   = getval("taub"); 
  zeta  = getval("zeta");
  bigTN = getval("bigTN");
  tpwr = getval("tpwr");
  tsatpwr = getval("tsatpwr");
  dpwr = getval("dpwr");
  pwN = getval("pwN");
  pwNlvl = getval("pwNlvl");
  pwD = getval("pwD");
  pwDlvl = getval("pwDlvl");
  phase = (int) ( getval("phase") + 0.5);
  phase2 = (int) ( getval("phase2") + 0.5);
  phase3 = (int) ( getval("phase3") + 0.5);
  sw1 = getval("sw1");
  sw2 = getval("sw2");
  sw3 = getval("sw3");
  ni2 = getval("ni2");
  ni3 = getval("ni3");
  pw_sl = getval("pw_sl");
  phase_sl = getval("phase_sl");
  tpwrsl = getval("tpwrsl");

  gstab = getval("gstab");

  gt1 = getval("gt1");
  if (getval("gt2") > 0) gt2=getval("gt2");
    else gt2=gt1*0.1;
  gt3 = getval("gt3");
  gt4 = getval("gt4");
  gt5 = getval("gt5");
  gt6 = getval("gt6");
  gt7 = getval("gt7");
  gt8 = getval("gt8");
  gt9 = getval("gt9");

  gzlvl1 = getval("gzlvl1");
  gzlvl2 = getval("gzlvl2");
  gzlvl3 = getval("gzlvl3");
  gzlvl4 = getval("gzlvl4");
  gzlvl5 = getval("gzlvl5");
  gzlvl6 = getval("gzlvl6");
  gzlvl7 = getval("gzlvl7");
  gzlvl8 = getval("gzlvl8");
  gzlvl9 = getval("gzlvl9");

  if(autocal[0]=='n')
  {     
    getstr("spca180",spca180);
    getstr("spco180",spco180);
    getstr("spchirp",spchirp);
    pwc90 = getval("pwc90");
    pwc180on = getval("pwc180on");
    pwc180off = getval("pwc180off");
    d_c90 = getval("d_c90");
    d_c180 = getval("d_c180");
    pwchirp = getval("pwchirp");
    d_chirp = getval("d_chirp");    
  }
  else
  {    
    strcpy(spca180,"Phard180ca");
    strcpy(spco180,"Phard180co");    
    strcpy(spchirp,"Pchirp180");    
    
    if (FIRST_FID)
    {
      pwC = getval("pwC");
      compC = getval("compC");
      pwClvl = getval("pwClvl");
      co90 = pbox("cal", CO90, CO180ps, dfrq, pwC*compC, pwClvl);          
      co180 = pbox("cal", CO180, CO180ps, dfrq, pwC*compC, pwClvl);          
      ca180 = pbox(spca180, CA180, CA180ps, dfrq, pwC*compC, pwClvl);  
      co180a = pbox(spco180, CO180a, CA180ps, dfrq, pwC*compC, pwClvl);                        
      chirp = pbox(spchirp, CHIRP, CHIRPps, dfrq, pwC*compC, pwClvl);
    }
    pwc90 = co90.pw;         d_c90 = co90.pwr;
    pwc180on = co180.pw;     d_c180 = co180.pwr;    
    pwc180off = ca180.pw;            
    pwchirp = chirp.pw;      d_chirp = chirp.pwr;    
  }   

/* LOAD PHASE TABLE */

  settable(t1,2,phi1);
  settable(t2,2,phi2);
  settable(t3,4,phi3);
  settable(t4,1,phi4);
  settable(t5,4,phi5);
  settable(t6,4,rec);

/* CHECK VALIDITY OF PARAMETER RANGES */


    if( bigTN - (ni3-1)*0.5/sw3 - WFG3_START_DELAY < 0.2e-6 )
    {
        text_error(" ni3 is too big\n");
        text_error(" please set ni3 smaller or equal to %d\n",
			(int) ((bigTN -WFG3_START_DELAY)*sw3*2.0) +1 );
        psg_abort(1);
    }


    if((dm[A] == 'y' || dm[B] == 'y' || dm[C] == 'y' || dm[D] == 'y' ))
    {
        text_error("incorrect dec1 decoupler flags!  ");
        psg_abort(1);
    }

    if((dm2[A] == 'y' || dm2[B] == 'y' || dm2[C] == 'y' || dm2[D] == 'y'))
    {
        text_error("incorrect dec2 decoupler flags! Should be 'nnnn' ");
        psg_abort(1);
    }


    if( tsatpwr > 6 )
    {
        text_error("TSATPWR too large !!!  ");
        psg_abort(1);
    }

    if( dpwr > 46 )
    {
        text_error("don't fry the probe, DPWR too large!  ");
        psg_abort(1);
    }

    if( dpwr2 > 46 )
    {
        text_error("don't fry the probe, DPWR2 too large!  ");
        psg_abort(1);
    }

    if( dpwr3 > 50 )
    {
        text_error("don't fry the probe, dpwr3 too large!  ");
        psg_abort(1);
    }

    if( d_c90 > 62 )
    {
        text_error("don't fry the probe, DHPWR too large!  ");
        psg_abort(1);
    }

    if( pw > 200.0e-6 )
    {
        text_error("dont fry the probe, pw too high ! ");
        psg_abort(1);
    } 
    if( pwN > 200.0e-6 )
    {
        text_error("dont fry the probe, pwN too high ! ");
        psg_abort(1);
    } 
    if( pwc90 > 200.0e-6 )
    {
        text_error("dont fry the probe, pwc90 too high ! ");
        psg_abort(1);
    } 
    if( pwc180off > 200.0e-6 )
    {
        text_error("dont fry the probe, pwc180 too high ! ");
        psg_abort(1);
    } 

    if( gt3 > 2.5e-3 ) 
    {
        text_error("gt3 is too long\n");
        psg_abort(1);
    }
    if( gt1 > 10.0e-3 || gt2 > 10.0e-3 || gt4 > 10.0e-3 || gt5 > 10.0e-3
        || gt6 > 10.0e-3 || gt7 > 10.0e-3 || gt8 > 10.0e-3
	|| gt9 > 10.0e-3)
    {
        text_error("gt values are too long. Must be < 10.0e-3 or gt11=50us\n");
        psg_abort(1);
    } 

    if((fca180[A] == 'y') && (ni2 > 1))
    {
        text_error("must set fca180='n' to allow Calfa evolution (ni2>1)\n");
        psg_abort(1);
    } 

    if((fco180[A] == 'y') && (ni > 1))
    {
        text_error("must set fco180='n' to allow CO evolution (ni>1)\n");
        psg_abort(1);
    } 


/*  Phase incrementation for hypercomplex 2D data */

    if (phase == 2) tsadd(t1,1,4);

    if (phase2 == 2) tsadd(t5,1,4);

    if (phase3 == 2) { tsadd(t4, 2, 4); icosel = 1; }
      else icosel = -1;

/*  Set up f1180  tau1 = t1               */
   
    tau1 = d2;
    if((f1180[A] == 'y') && (ni > 1)) {
      if (pwc180off > 2.0*pwN) 
        tau1 += (1.0/(2.0*sw1) - 4.0*pwc90/PI - pwc180off 
	      - WFG3_START_DELAY - WFG3_STOP_DELAY - 4.0e-6 - 2.0*POWER_DELAY - 4.0e-6);
      else 
        tau1 += (1.0/(2.0*sw1) - 4.0*pwc90/PI - 2.0*pwN 
              - WFG3_START_DELAY - WFG3_STOP_DELAY - 4.0e-6 - 2.0*POWER_DELAY - 4.0e-6);

        if(tau1 < 0.2e-6) {
         tau1 = 0.4e-6;
	 text_error("tau1 could be negative");
	}
    }
    else
    {

      if (pwc180off > 2.0*pwN)
        tau1 = tau1 - 4.0*pwc90/PI - pwc180off
              - WFG3_START_DELAY - WFG3_STOP_DELAY - 4.0e-6 - 2.0*POWER_DELAY - 4.0e-6;
      else
        tau1 = tau1 - 4.0*pwc90/PI - 2.0*pwN 
              - WFG3_START_DELAY - WFG3_STOP_DELAY - 4.0e-6 - 2.0*POWER_DELAY - 4.0e-6;
 
        if(tau1 < 0.2e-6) tau1 = 0.4e-6;
     }

        tau1 = tau1/2.0;

/*  Set up f2180  tau2 = t2               */

    tau2 = d3;
    if((f2180[A] == 'y') && (ni2 > 1)) {
	if (pwc180off > 2.0*pwN)
          tau2 += ( 1.0 / (2.0*sw2) - 4.0*pwc90/PI - 4.0e-6
		 - 2.0*POWER_DELAY
		 - WFG3_START_DELAY - pwc180off - WFG3_STOP_DELAY - 4.0e-6);
	else
          tau2 += ( 1.0 / (2.0*sw2) - 4.0*pwc90/PI - 4.0e-6
                 - 2.0*POWER_DELAY
                 - WFG3_START_DELAY - 2.0*pwN - WFG3_STOP_DELAY - 4.0e-6);
        if(tau2 < 0.2e-6) {
	  tau2 = 0.4e-6;
	  text_error("tau2 could be negative");
 	} 

    }
    else
    {
        if (pwc180off > 2.0*pwN)
          tau2 = tau2 - 4.0*pwc90/PI - 4.0e-6
                 - 2.0*POWER_DELAY
                 - WFG3_START_DELAY - pwc180off - WFG3_STOP_DELAY - 4.0e-6;
        else
          tau2 = tau2 - 4.0*pwc90/PI - 4.0e-6
                 - 2.0*POWER_DELAY
                 - WFG3_START_DELAY - 2.0*pwN - WFG3_STOP_DELAY - 4.0e-6;
        if(tau2 < 0.2e-6) tau2 = 0.4e-6;
    }

        tau2 = tau2/2.0;

/*  Set up f3180  tau3 = t3               */
 
    tau3 = d4;
    if ((f3180[A] == 'y') && (ni3 > 1)) {
        tau3 += ( 1.0 / (2.0*sw3) );
        if(tau3 < 0.2e-6) tau3 = 0.4e-6;
    }
        tau3 = tau3/2.0;

/* Calculate modifications to phases for States-TPPI acquisition          */

   if( ix == 1) d2_init = d2 ;
   t1_counter = (int) ( (d2-d2_init)*sw1 + 0.5 );
   if(t1_counter % 2) {
      tsadd(t1,2,4);     
      tsadd(t6,2,4);    
    }

   if( ix == 1) d3_init = d3 ;
   t2_counter = (int) ( (d3-d3_init)*sw2 + 0.5 );
   if(t2_counter % 2) {
      tsadd(t5,2,4);
      tsadd(t6,2,4);
    }

   if( ix == 1) d4_init = d4 ;
   t3_counter = (int) ( (d4-d4_init)*sw3 + 0.5 );
   if(t3_counter % 2) {
      tsadd(t2,2,4);  
      tsadd(t6,2,4);    
    }

/* BEGIN ACTUAL PULSE SEQUENCE */

status(A);
   obsoffset(tof);
   decoffset(dof);		/* set Dec1 carrier at Co		      */
   obspower(tsatpwr);      /* Set transmitter power for 1H presaturation */
   decpower(d_chirp);      /* Set Dec1 power for hard 13C pulses         */
   dec2power(pwNlvl);      /* Set Dec2 power for 15N hard pulses         */

/* Presaturation Period */

   if (fsat[0] == 'y')
     {
      delay(2.0e-5);
      rgpulse(d1,zero,2.0e-6,2.0e-6); /* presaturation */
      obspower(tpwr);      /* Set transmitter power for hard 1H pulses */
      delay(2.0e-5);
      if (fscuba[0] == 'y')
        {
         delay(2.2e-2);
         rgpulse(pw,zero,2.0e-6,0.0);
         rgpulse(2*pw,one,2.0e-6,0.0);
         rgpulse(pw,zero,2.0e-6,0.0);
         delay(2.2e-2);
        }
     }
    else
     {
      delay(d1);
     }

   obspower(tpwr);           /* Set transmitter power for hard 1H pulses */
   txphase(zero);
   dec2phase(zero);
   delay(1.0e-5);

/* Begin Pulses */

status(B);

   rcvroff();
   lk_hold();
   delay(20.0e-6);

   initval(1.0,v2);
   obsstepsize(phase_sl);
   xmtrphase(v2);

   /* shaped pulse */
   obspower(tpwrsl);
   shaped_pulse(shp_sl,pw_sl,one,4.0e-6,0.0);
   xmtrphase(zero);
   obspower(tpwr);  txphase(zero);  
   delay(4.0e-6);
   /* shaped pulse */

   rgpulse(pw,zero,0.0,0.0);                    /* 90 deg 1H pulse */

   delay(0.2e-6);
   zgradpulse(gzlvl5,gt5);
   delay(2.0e-6);

   delay(taua - gt5 - 2.2e-6);   /* taua <= 1/4JNH */ 

   sim3pulse(2*pw,0.0e-6,2*pwN,zero,zero,zero,0.0,0.0);

   txphase(three); dec2phase(zero); decphase(zero); 

   delay(0.2e-6);
   zgradpulse(gzlvl5,gt5);
   delay(200.0e-6);

   delay(taua - gt5 - 200.2e-6 - 2.0e-6); 

   if (sel_flg[A] == 'n') 
     {
      rgpulse(pw,three,2.0e-6,0.0);

      delay(0.2e-6);
      zgradpulse(gzlvl3,gt3);
      delay(200.0e-6);

      dec2rgpulse(pwN,zero,0.0,0.0);

      delay( zeta );
  
      dec2rgpulse(2.0*pwN,zero,0.0,0.0);
      decshaped_pulse(spchirp,pwchirp,zero,0.0,0.0);

      delay(zeta -WFG_START_DELAY -pwchirp -WFG_STOP_DELAY -2.0e-6);

     dec2rgpulse(pwN,zero,2.0e-6,0.0);

    }
   else 
    {
     rgpulse(pw,one,2.0e-6,0.0);

     initval(1.0,v3);
     dec2stepsize(45.0); 
     dcplr2phase(v3);

     delay(0.2e-6);
     zgradpulse(gzlvl3,gt3);
     delay(200.0e-6);

     dec2rgpulse(pwN,zero,0.0,0.0);
     dcplr2phase(zero);

     delay(1.34e-3 - SAPS_DELAY - 2.0*pw);

     rgpulse(pw,one,0.0,0.0);
     rgpulse(2.0*pw,zero,0.0,0.0);
     rgpulse(pw,one,0.0,0.0);

     delay( zeta - 1.34e-3 - 2.0*pw);
  
     dec2rgpulse(2.0*pwN,zero,0.0,0.0);
     decshaped_pulse(spchirp,pwchirp,zero,0.0,0.0);

     delay(zeta -WFG_START_DELAY -pwchirp -WFG_STOP_DELAY -2.0e-6);

     dec2rgpulse(pwN,zero,2.0e-6,0.0);
    }

   dec2phase(zero); decphase(t1);
   decpower(d_c90);

   delay(0.2e-6);
   zgradpulse(gzlvl8,gt8);
   delay(200.0e-6);

   decrgpulse(pwc90,t1,2.0e-6,0.0);
/* t1 period for Co evolution begins */
   if (fco180[A]=='n')  
     {
      decpower(d_c180);

      delay(tau1);
      sim3shaped_pulse("",spca180,"",0.0,pwc180off,2.0*pwN,zero,zero,zero,4.0e-6,0.0);

      decpower(d_c90);

       delay(tau1);
     }
   else /* for checking sequence */
     {
      decpower(d_c180);
      decrgpulse(pwc180on,zero,4.0e-6,0.0);
      decpower(d_c90);
     }
/* t1 period for Co evolution ends */
   decrgpulse(pwc90,zero,4.0e-6,0.0);

   decoffset(dof-(174-56)*dfrq);   /* change Dec1 carrier to Ca (55 ppm) */
   delay(0.2e-6);
   zgradpulse(gzlvl4,gt4);
   delay(150.0e-6);

   /* Turn on D decoupling using the third decoupler */
   dec3phase(one);
   dec3power(pwDlvl);
   dec3rgpulse(pwD,one,4.0e-6,0.0);
   dec3phase(zero);
   dec3power(dpwr3);
   dec3unblank();
   setstatus(DEC3ch, TRUE, 'w', FALSE, dmf3);
   /* Turn on D decoupling */

   decrgpulse(pwc90,t5,2.0e-6,0.0);
/* t2 period  for Ca evolution begins */
  if (fca180[A]=='n')
    {
     decphase(zero); dec2phase(zero);
     decpower(d_c180); 
     delay(tau2);
     sim3shaped_pulse("",spco180,"",0.0,pwc180off,2.0*pwN,zero,zero,zero,4.0e-6,0.0);
     decpower(d_c90); 
     delay(tau2);
    }
   else /* for checking sequence */
    {
     decpower(d_c180);
     decrgpulse(pwc180on,zero,4.0e-6,0.0);
     decpower(d_c90);
    }
/* t2 period  for Ca evolution ends */
   decrgpulse(pwc90,zero,4.0e-6,0.0);
 
   /* Turn off D decoupling */
   setstatus(DEC3ch, FALSE, 'c', FALSE, dmf3);
   dec3blank();
   dec3phase(three);
   dec3power(pwDlvl);
   dec3rgpulse(pwD,three,4.0e-6,0.0);
   /* Turn off D decoupling */

   decoffset(dof);   /* set carrier back to Co */
   decpower(d_chirp);

   delay(0.2e-6);
   zgradpulse(gzlvl9,gt9);
   delay(150.0e-6);

/* t3 period begins */
   dec2rgpulse(pwN,t2,2.0e-6,0.0);

   dec2phase(t3);

   delay(bigTN - tau3);

   dec2rgpulse(2.0*pwN,t3,0.0,0.0);
   decshaped_pulse(spchirp,pwchirp,zero,0.0,0.0);

   txphase(zero);
   dec2phase(t4);

   delay(0.2e-6);
   zgradpulse(gzlvl1,gt1);
   delay(500.0e-6);

   delay(bigTN - WFG_START_DELAY - pwchirp - WFG_STOP_DELAY
         -gt1 -500.2e-6 -2.0*GRADIENT_DELAY);

   delay(tau3);

   sim3pulse(pw,0.0e-6,pwN,zero,zero,t4,0.0,0.0);
/* t3 period ends */

   decpower(d_c90);
   decrgpulse(pwc90,zero,4.0e-6,0.0);
   decoffset(dof-(174-56)*dfrq);
   decrgpulse(pwc90,zero,20.0e-6,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl6,gt6);
   delay(2.0e-6);

   dec2phase(zero);
   delay(taub - POWER_DELAY - 4.0e-6 - pwc90 - 20.0e-6 - pwc90 - gt6 - 2.2e-6);

   sim3pulse(2*pw,0.0e-6,2*pwN,zero,zero,zero,0.0,0.0);

   decoffset(dof);
   delay(0.2e-6);
   zgradpulse(gzlvl6,gt6);
   delay(200.0e-6);
   
   txphase(one);
   dec2phase(one);

   delay(taub - gt6 - 200.2e-6);

   sim3pulse(pw,0.0e-6,pwN,one,zero,one,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl7,gt7);
   delay(2.0e-6);
 
   txphase(zero);
   dec2phase(zero);

   delay(taub - gt7 - 2.2e-6);

   sim3pulse(2*pw,0.0e-6,2*pwN,zero,zero,zero,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl7,gt7);
   delay(200.0e-6);

   delay(taub - gt7 - 200.2e-6);

   sim3pulse(pw,0.0e-6,pwN,zero,zero,zero,0.0,0.0);

   delay(gt2 +gstab -0.5*(pwN -pw) -2.0*pw/PI);

   rgpulse(2*pw,zero,0.0,0.0);

   delay(2.0e-6);
   zgradpulse(icosel*gzlvl2,gt2);
   decpower(dpwr);
   dec2power(dpwr2);
   delay(gstab -2.0e-6 -2.0*GRADIENT_DELAY -2.0*POWER_DELAY);

   lk_sample();
/* BEGIN ACQUISITION */
status(C);
   setreceiver(t6);

}
Esempio n. 2
0
pulsesequence()
{

char        sel_flg[MAXSTR],
            autocal[MAXSTR],
            glyshp[MAXSTR];

int         icosel, t1_counter, ni = getval("ni");

double
   d2_init=0.0, 
   tau1, tau2, 
   tau3,  
   glypwr,glypwrf,                    /* Power levels for Cgly selective 90 */
   pwgly,                              /* Pulse width for Cgly selective 90 */

   waltzB1  = getval("waltzB1"),     /* 1H decoupling strength (in Hz) */
   timeTN  = getval("timeTN"),     /* constant time for 15N evolution */
   tauCaCb = getval("tauCaCb"),    
   tauNCa  = getval("tauNCa"),
   tauNCo  = getval("tauNCo"),
   tauCaCo = getval("tauCaCo"),
            
   compH = getval("compH"),        /* adjustment for H1 amplifier compression */
   tpwrs,                        /* power for the pwHs ("H2Osinc") pulse */
   bw,ppm,

   pwClvl = getval("pwClvl"),              /* coarse power for C13 pulse */
   compC = getval("compC"),      /* amplifier compression for C13 pulse */
   pwC = getval("pwC"),          /* C13 90 degree pulse length at pwClvl */

   pwNlvl = getval("pwNlvl"),                   /* power for N15 pulses */
   pwN = getval("pwN"),          /* N15 90 degree pulse length at pwNlvl */
   dpwr2 = getval("dpwr2"),            /* power for N15 decoupling */

   pwCa90,                          /* length of square 90 on Ca */
   pwCa180,
   pwCab90,
   pwCab180,
   phshift,        /*  phase shift induced on Ca by 180 on CO in middle of t1 */
   pwCO180,                                /* length of 180 on CO */
   pwS = getval("pwS"), /* used to change 180 on CO in t1 for 1D calibrations */
   pwZ,                            /* the largest of pwCO180 and 2.0*pwN */
   pwZ1,             /* the largest of pwCO180 and 2.0*pwN for 1D experiments */

   sw1 = getval("sw1"),   
   swCb = getval("swCb"),
   swCa = getval("swCa"),
   swN  = getval("swN"),
   swTilt,                     /* This is the sweep width of the tilt vector */

   cos_N, cos_Ca, cos_Cb,
   angle_N, angle_Ca, angle_Cb,      /* angle_N is calculated automatically */

  gstab = getval("gstab"),
   gt0 = getval("gt0"),             gzlvl0 = getval("gzlvl0"),
   gt1 = getval("gt1"),             gzlvl1 = getval("gzlvl1"),
                                    gzlvl2 = getval("gzlvl2"),
   gt3 = getval("gt3"),             gzlvl3 = getval("gzlvl3"),
   gt4 = getval("gt4"),             gzlvl4 = getval("gzlvl4"),
   gt5 = getval("gt5"),             gzlvl5 = getval("gzlvl5"),
   gt6 = getval("gt6"),             gzlvl6 = getval("gzlvl6"),
   gt7 = getval("gt7"),             gzlvl7 = getval("gzlvl7"),
   gt10= getval("gt10"),            gzlvl10= getval("gzlvl10"),
   gt11= getval("gt11"),            gzlvl11= getval("gzlvl11"),
   gt12= getval("gt12"),            gzlvl12= getval("gzlvl12");

   angle_N = 0;
   glypwr = getval("glypwr");
   pwgly = getval("pwgly");
   tau1 = 0;
   tau2 = 0;
   tau3 = 0;
   cos_N = 0;
   cos_Cb = 0;
   cos_Ca = 0;
   getstr("autocal", autocal);
   getstr("glyshp", glyshp);
   getstr("sel_flg",sel_flg);

   pwHs = getval("pwHs");          /* H1 90 degree pulse length at tpwrs */
 
/*   LOAD PHASE TABLE    */

   settable(t2,1,phy);
   settable(t3,2,phi3);     settable(t4,1,phx);     settable(t5,4,phi5);
   settable(t8,1,phy);      settable(t9,8,phi9);    settable(t10,1,phx);
   settable(t11,1,phy);     settable(t12,4,rec);

/*   INITIALIZE VARIABLES   */

   kappa = 5.4e-3;     lambda = 2.4e-3;

/* selective H20 one-lobe sinc pulse */

   
   tpwrs = tpwr - 20.0*log10(pwHs/(compH*pw*1.69));   /*needs 1.69 times more*/
   tpwrs = (int) (tpwrs);                        /*power than a square pulse */

   pwHs = 1.7e-3*500.0/sfrq;
   widthHd = 2.861*(waltzB1/sfrq);   /* bandwidth of H1 WALTZ16 decoupling in ppm */
   pwHd = h1dec90pw("WALTZ16", widthHd, 0.0);     /* H1 90 length for WALTZ16 */
 
/* get calculated pulse lengths of shaped C13 pulses */
   pwCa90  = c13pulsepw("ca", "co", "square", 90.0); 
   pwCa180 = c13pulsepw("ca", "co", "square", 180.0);
   pwCO180 = c13pulsepw("co", "cab", "sinc", 180.0); 
   pwCab90 = c13pulsepw("cab","co", "square", 90.0);
   pwCab180= c13pulsepw("cab","co", "square", 180.0);

/* the 180 pulse on CO at the middle of t1 */
   if (pwCO180 > 2.0*pwN) pwZ = pwCO180; else pwZ = 2.0*pwN;
   if ((pwS==0.0) && (pwCO180>2.0*pwN)) pwZ1=pwCO180-2.0*pwN; else pwZ1=0.0;
   if ( ni > 1 )     pwS = 180.0;
   if ( pwS > 0 )   phshift = 320.0;
     else             phshift = 0.0;

/* CHECK VALIDITY OF PARAMETER RANGES */

   if ( dm[A] == 'y' || dm[B] == 'y' || dm[C] == 'y' )
      { printf("incorrect dec1 decoupler flags! Should be 'nnn' "); psg_abort(1);}

   if ( dm2[A] == 'y' || dm2[B] == 'y' )
      { printf("incorrect dec2 decoupler flags! Should be 'nny' "); psg_abort(1);}

   if ( dm3[A] == 'y' || dm3[C] == 'y' )
      { printf("incorrect dec3 decoupler flags! Should be 'nyn' or 'nnn' ");
                                                psg_abort(1);}     
   if ( dpwr2 > 46 )
      { printf("dpwr2 too large! recheck value  ");               psg_abort(1);}

   if ( pw > 20.0e-6 )
      { printf(" pw too long ! recheck value ");                  psg_abort(1);} 
  
   if ( pwN > 100.0e-6 )
      { printf(" pwN too long! recheck value ");                  psg_abort(1);} 


/* PHASES AND INCREMENTED TIMES */

   /* Set up angles and phases */

   angle_Cb=getval("angle_Cb");  cos_Cb=cos(PI*angle_Cb/180.0);
   angle_Ca=getval("angle_Ca");  cos_Ca=cos(PI*angle_Ca/180.0);

   if ( (angle_Cb < 0) || (angle_Cb > 90) )
   {  printf ("angle_Cb must be between 0 and 90 degree.\n"); psg_abort(1); }

   if ( (angle_Ca < 0) || (angle_Ca > 90) )
   {  printf ("angle_Ca must be between 0 and 90 degree.\n"); psg_abort(1); }

   if ( 1.0 < (cos_Cb*cos_Cb + cos_Ca*cos_Ca) )
   {
       printf ("Impossible angles.\n"); psg_abort(1);
   }
   else
   {
           cos_N=sqrt(1.0- (cos_Cb*cos_Cb + cos_Ca*cos_Ca));
           angle_N = 180.0*acos(cos_N)/PI;
   }

   swTilt=swCb*cos_Cb + swCa*cos_Ca + swN*cos_N;

   if (ix ==1)
   {
      printf("\n\nn\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
      printf ("Maximum Sweep Width: \t\t %f Hz\n", swTilt);
      printf ("Angle_Cb:\t%6.2f\n", angle_Cb);
      printf ("Angle_Ca:\t%6.2f\n", angle_Ca);
      printf ("Angle_N :\t%6.2f\n", angle_N );
   }

/* Set up hyper complex */

   /* sw1 is used as symbolic index */
   if ( sw1 < 1000 ) { printf ("Please set sw1 to some value larger than 1000.\n"); psg_abort(1); }

   if (ix == 1) d2_init = d2;
   t1_counter = (int) ( (d2-d2_init)*sw1 + 0.5 );
   if (t1_counter % 2)  { tsadd(t8,2,4); tsadd(t12,2,4); }

   if (phase1 == 1)  { ;}                                                  /* CC */
   else if (phase1 == 2)  { tsadd(t3,3,4); tsadd(t2,3,4);}                 /* SC */
   else if (phase1 == 3)  { tsadd(t5,1,4); }                               /* CS */
   else if (phase1 == 4)  { tsadd(t3,3,4); tsadd(t2,3,4); tsadd(t5,1,4);}  /* SS */
   else { printf ("phase1 can only be 1,2,3,4. \n"); psg_abort(1); }

   if (phase2 == 2)  { tsadd(t10,2,4); icosel = +1; }                      /* N  */
            else                       icosel = -1;

   tau1 = 1.0*t1_counter*cos_Cb/swTilt;
   tau2 = 1.0*t1_counter*cos_Ca/swTilt;
   tau3 = 1.0*t1_counter*cos_N/swTilt;

   tau1 = tau1/2.0;  tau2 = tau2/2.0;  tau3 = tau3/2.0;


/* CHECK VALIDITY OF PARAMETER RANGES */

    if (0.5*ni*(cos_N/swTilt) > timeTN - WFG3_START_DELAY)
       { printf(" ni is too big. Make ni equal to %d or less.\n",
         ((int)((timeTN - WFG3_START_DELAY)*2.0*swTilt/cos_N)));       psg_abort(1);}


/* BEGIN PULSE SEQUENCE */

status(A);
      delay(d1);
      if ( dm3[B] == 'y' ) lk_hold();  

      rcvroff();
      obsoffset(tof);          obspower(tpwr);        obspwrf(4095.0);
      set_c13offset("cab");     decpower(pwClvl);      decpwrf(4095.0);
      dec2power(pwNlvl);

      txphase(zero);           delay(1.0e-5);

      decrgpulse(pwC, zero, 0.0, 0.0);
      zgradpulse(gzlvl0, gt0);
      delay(gstab);

      decrgpulse(pwC, one, 0.0, 0.0);
      zgradpulse(0.7*gzlvl0, gt0);
      delay(gstab);


      txphase(one);      delay(1.0e-5);
      shiftedpulse("sinc", pwHs, 90.0, 0.0, one, 2.0e-6, 0.0);

      txphase(zero);  decphase(zero); dec2phase(zero);
      delay(2.0e-6);

/* pulse sequence starts */


   rgpulse(pw,zero,0.0,0.0);                      /* 1H pulse excitation */
      dec2phase(zero);
      zgradpulse(gzlvl3, gt3);
      delay(lambda - gt3);

   sim3pulse(2.0*pw, 0.0, 2.0*pwN, zero, zero, zero, 0.0, 0.0);
      if (sel_flg[A] == 'n') txphase(three);
          else txphase(one);

      zgradpulse(gzlvl3, gt3);
      delay(lambda - gt3);

if (sel_flg[A] == 'n')
{
   rgpulse(pw, three, 0.0, 0.0);
      txphase(zero);
      zgradpulse(gzlvl4, gt4);                       /* Crush gradient G4 */
      delay(gstab);
                                             /* Begin of N to Ca transfer */
     dec2rgpulse(pwN, one, 0.0, 0.0);
     decphase(zero);      dec2phase(zero);
     delay(tauNCo - pwCO180/2 - 2.0e-6 - WFG3_START_DELAY);
}
else  /* active suppresion */
{
   rgpulse(pw,one,2.0e-6,0.0);

      initval(1.0,v6);   dec2stepsize(45.0);   dcplr2phase(v6);
      zgradpulse(gzlvl4, gt4);                       /* Crush gradient G4 */
      delay(gstab);
                                             /* Begin of N to Ca transfer */
   dec2rgpulse(pwN,one,0.0,0.0);
      dcplr2phase(zero);                                    /* SAPS_DELAY */
      delay(1.34e-3 - SAPS_DELAY - 2.0*pw);

      rgpulse(pw,one,0.0,0.0);
      rgpulse(2.0*pw,zero,0.0,0.0);
      rgpulse(pw,one,0.0,0.0);

      delay(tauNCo - pwCO180/2 - 1.34e-3 - 2.0*pw - WFG3_START_DELAY);
}

/* Begin transfer from HzNz to N(i)zC'(i-1)zCa(i)zCa(i-1)z */

      c13pulse("co", "cab", "sinc", 180.0, zero, 2.0e-6, 0.0);
      delay(tauNCa - tauNCo - pwCO180/2 - WFG3_START_DELAY -
            WFG3_STOP_DELAY - 2.0e-6);

                                     /* WFG3_START_DELAY */
   sim3_c13pulse("", "cab", "co", "square", "", 0.0, 180.0, 2.0*pwN,
                             zero, zero, zero, 2.0e-6, 2.0e-6);
      delay(tauNCa - 2.0e-6 - WFG3_STOP_DELAY);

   dec2rgpulse(pwN, zero, 0.0, 0.0);

/* End transfer from HzNz to N(i)zC'(i-1)zCa(i)zCa(i-1)z */

      zgradpulse(gzlvl5, gt5);
      delay(gstab);

/* Begin removal of Ca(i-1) */

   c13pulse("co", "cab", "sinc", 90.0, zero, 2.0e-6, 2.0e-6);
      zgradpulse(gzlvl6, gt6);
      delay(tauCaCo - gt6 - pwCab180 - pwCO180/2 - 6.0e-6);

      c13pulse("cab","co", "square", 180.0, zero, 2.0e-6, 2.0e-6);
   c13pulse("co","cab", "sinc", 180.0, zero, 2.0e-6, 2.0e-6);

      zgradpulse(gzlvl6, gt6);
      delay(tauCaCo - gt6 - pwCab180 - pwCO180/2 - 6.0e-6);

      c13pulse("cab","co", "square", 180.0, zero, 2.0e-6, 2.0e-6);
   c13pulse("co", "cab", "sinc", 90.0, one, 2.0e-6, 2.0e-6);

/* End removal of Ca(i-1) */

      /* xx Selective glycine pulse xx */
      set_c13offset("gly");
      setautocal();
      if (autocal[A] == 'y')
      {
        if(FIRST_FID)
        {
         ppm = getval("dfrq"); bw=9*ppm;
         gly90 = pbox_make("gly90","eburp1",bw,0.0,compC*pwC,pwClvl);
                               /* Gly selective 90 with null at 50ppm */
        }
        pwgly=gly90.pw; glypwr=gly90.pwr; glypwrf=gly90.pwrf;
        decpwrf(glypwrf);
        decpower(glypwr);                           
        decshaped_pulse("gly90",pwgly,zero,2.0e-6,0.0);
      }
      else
      {
       decpwrf(4095.0);
       decpower(glypwr);                           
       decshaped_pulse(glyshp,pwgly,zero,2.0e-6,0.0);
      }
      /* xx End of glycine selecton xx */

      zgradpulse(gzlvl7, gt7);
      set_c13offset("cab");
      delay(gstab);
      decphase(t3);

      if ( dm3[B] == 'y' )     /* begins optional 2H decoupling */
      {
         dec3unblank();
         dec3rgpulse(1/dmf3,one,10.0e-6,2.0e-6);
         dec3unblank();
         dec3phase(zero);
         delay(2.0e-6);
         setstatus(DEC3ch, TRUE, 'w', FALSE, dmf3);
      }


/* ========== Ca to Cb transfer =========== */

   c13pulse("cab", "co", "square", 90.0, t3, 2.0e-6, 2.0e-6);
      decphase(zero);
      delay(tauCaCb - 4.0e-6);

   c13pulse("cab", "co", "square", 180.0, zero, 2.0e-6, 2.0e-6);
      decphase(t2);
      delay(tauCaCb - 4.0e-6 );

/*   xxxxxxxxxxxxxxxxxxxxxx   13Cb EVOLUTION        xxxxxxxxxxxxxxxxxx    */

     c13pulse("cab", "co", "square", 90.0, t2, 2.0e-6, 0.0);      /*  pwCa90  */
     decphase(zero);

     if ((ni>1.0) && (tau1>0.0))
      {
         if (tau1 - 2.0*pwCab90/PI - WFG_START_DELAY - pwN - 2.0e-6
                 - PWRF_DELAY - POWER_DELAY > 0.0)
         {
            delay(tau1 - 2.0*pwCab90/PI - pwN - 2.0e-6 );

            dec2rgpulse(2.0*pwN, zero, 2.0e-6, 0.0);
            delay(tau1 - 2.0*pwCab90/PI  - pwN - WFG_START_DELAY
                                - 2.0e-6 - PWRF_DELAY - POWER_DELAY);
         }
         else
         {
            tsadd(t12,2,4);
            delay(2.0*tau1);
            delay(10.0e-6);                                    /* WFG_START_DELAY */
         sim3_c13pulse("", "cab", "co", "square", "", 0.0, 180.0, 2.0*pwN,
                     zero, zero, zero, 2.0e-6, 0.0);
            delay(10.0e-6);
         }
      }
      else
      {
         tsadd(t12,2,4);
         delay(10.0e-6);                                    /* WFG_START_DELAY */
         sim3_c13pulse("", "cab", "co", "square", "", 0.0, 180.0, 2.0*pwN,
                        zero, zero, zero, 2.0e-6, 0.0);
         delay(10.0e-6);
      }

   decphase(one);
   c13pulse("cab", "co", "square", 90.0, one, 2.0e-6, 0.0);      /*  pwCa90  */

/*   xxxxxxxxxxx End of 13Cb EVOLUTION - Start 13Ca EVOLUTION   xxxxxxxxxxxx    */

        decphase(zero);
        delay(tau2);

        sim3_c13pulse("", "co", "cab", "sinc", "", 0.0, 180.0, 2.0*pwN,
                    zero, zero, zero, 2.0e-6, 0.0);
        decphase(zero);

        delay(tauCaCb - 2*pwN - pwCab180/2 - WFG2_START_DELAY - 2.0*PWRF_DELAY -
              2.0*POWER_DELAY - WFG2_STOP_DELAY - 4.0e-6 );
   c13pulse("cab", "co", "square", 180.0, zero, 2.0e-6, 0.0);

        delay(tauCaCb- tau2 - pwCO180 - pwCab180/2 - WFG2_START_DELAY - 2.0*PWRF_DELAY
              -2.0*POWER_DELAY - WFG2_STOP_DELAY - 4.0e-6);

        c13pulse("co", "cab", "sinc", 180.0, zero, 2.0e-6, 0.0);
        decphase(t5);

   c13pulse("cab", "co", "square", 90.0, t5, 2.0e-6, 0.0);

/*   xxxxxxxxxxxxxxxxxxx End of 13Ca EVOLUTION        xxxxxxxxxxxxxxxxxx    */


      if ( dm3[B] == 'y' )   /* turns off 2H decoupling  */
      {
          dec3rgpulse(1/dmf3,three,2.0e-6,2.0e-6);
          dec3blank();
          setstatus(DEC3ch, FALSE, 'c', FALSE, dmf3);
          dec3blank();
      }
/*  xxxxxxxxxxxxxxxxxxxx  N15 EVOLUTION & SE TRAIN   xxxxxxxxxxxxxxxxxxxxxxx  */     

      dcplrphase(zero);     dec2phase(t8);
      zgradpulse(gzlvl10, gt10);
      delay(gstab);

   dec2rgpulse(pwN, t8, 2.0e-6, 0.0);
      c13pulse("co", "cab", "sinc", 180.0, zero, 2.0e-6, 0.0); /*pwCO180*/
      decphase(zero);     dec2phase(t9);
      delay(timeTN - pwCO180 - WFG3_START_DELAY - tau3 - 4.0e-6);
                                    /* WFG3_START_DELAY  */
   sim3_c13pulse("", "cab", "co", "square", "", 0.0, 180.0, 2.0*pwN, 
                              zero, zero, t9, 2.0e-6, 2.0e-6);
     c13pulse("co", "cab", "sinc", 180.0, zero, 2.0e-6, 0.0); /*pwCO180*/

      dec2phase(t10);
      txphase(t4);

      delay(timeTN - pwCO180 + tau3 - 500.0e-6 - gt1 - 2.0*GRADIENT_DELAY-
             WFG_START_DELAY - WFG_STOP_DELAY );

      delay(0.2e-6);
      zgradpulse(gzlvl1, gt1);
      delay(gstab);

   sim3pulse(pw, 0.0, pwN, t4, zero, t10, 0.0, 0.0);
      txphase(zero);     dec2phase(zero);
      zgradpulse(gzlvl11, gt11);
      delay(lambda - 1.3*pwN - gt11);

   sim3pulse(2.0*pw, 0.0, 2.0*pwN, zero, zero, zero, 0.0, 0.0);
      zgradpulse(gzlvl11, gt11);     txphase(one);
      dec2phase(t11);
      delay(lambda - 1.3*pwN - gt11);

   sim3pulse(pw, 0.0, pwN, one, zero, t11, 0.0, 0.0);
      txphase(zero);     dec2phase(zero);
      zgradpulse(gzlvl12, gt12);
      delay(lambda - 1.3*pwN - gt12);

   sim3pulse(2.0*pw, 0.0, 2.0*pwN, zero, zero, zero, 0.0, 0.0);
      dec2phase(zero);
      zgradpulse(gzlvl12, gt12);
      delay(lambda - 1.3*pwN - gt12);

   sim3pulse(pw, 0.0, pwN, zero, zero, zero, 0.0, 0.0);
      delay((gt1/10.0) + 1.0e-4 + 2.0*GRADIENT_DELAY + POWER_DELAY);

   rgpulse(2.0*pw, zero, 0.0, 0.0);
      dec2power(dpwr2);                           /* POWER_DELAY */
      zgradpulse(icosel*gzlvl2, gt1/10.0);            /* 2.0*GRADIENT_DELAY */

statusdelay(C, 1.0e-4 );
   setreceiver(t12);
   if (dm3[B]=='y') lk_sample();
}
pulsesequence()
{
/* DECLARE VARIABLES */

 char       satmode[MAXSTR],
	    fscuba[MAXSTR],
            fc180[MAXSTR],    /* Flag for checking sequence              */
            ddseq[MAXSTR],    /* 2H decoupling seqfile */
            fCTCa[MAXSTR],    /* Flag for CT or non_CT on Ca dimension */
            sel_flg[MAXSTR],
	    cbdecseq[MAXSTR];

 int         icosel,
             ni = getval("ni"),
             t1_counter;   /* used for states tppi in t1           */ 

 double      tau1,         /*  t1 delay */
             tau2,         /*  t2 delay */
             tau3,         /*  t2 delay */
             taua,         /*  ~ 1/4JNH =  2.25 ms */
             taub,         /*  ~ 1/4JNH =  2.25 ms */
             tauc,         /*  ~ 1/4JCaC' =  4 ms */
             taud,         /*  ~ 1/4JCaC' =  4.5 ms if bigTCo can be set to be
				less than 4.5ms and then taud can be smaller*/
             zeta,        /* time for C'-N to refocuss set to 0.5*24.0 ms */
             bigTCa,      /* Ca T period */
             bigTCo,      /* Co T period */
             bigTN,       /* nitrogen T period */
             BigT1,       /* delay to compensate for gradient gt5 */
             sw1,          /* sweep width in f1                    */             
             sw2,          /* sweep width in f2                    */             
	     sphase,       /* small angle phase shift */
	     sphase1,
	     sphase2,      /* used only for constant t2 period */
             pwS4,         /* selective CO 180 */
             pwS3,         /* selective Ca 180 */
             pwS1,         /* selecive Ca 90 */
             pwS2,         /* selective CO 90 */
	     cbpwr,        /* power level for selective CB decoupling */
	     cbdmf,        /* pulse width for selective CB decoupling */
             cbres,        /* decoupling resolution of CB decoupling */

             gt1,
             gt2,
             gt3,
             gt4,
             gt5,
             gt6,
             gt7,
             gt8,
             gt9,
             gt10,
             gt11,
             gt12,
             gstab,
             gzlvl1,
             gzlvl2,
             gzlvl3,
             gzlvl4,
             gzlvl5,
             gzlvl6,
             gzlvl7, 
             gzlvl8, 
             gzlvl9, 
             gzlvl10, 
             gzlvl11, 
             gzlvl12,

             compH = getval("compH"),         /* adjustment for amplifier compression */
             pwHs = getval ("pwHs"),         /* H1 90 degree pulse at tpwrs */
             tpwrs,                          /* power for pwHs ("H2osinc") pulse */

             pwClvl = getval("pwClvl"),                 /* coarse power for C13 pulse */
             pwC = getval("pwC"),             /* C13 90 degree pulse length at pwClvl */

             pwNlvl = getval("pwNlvl"),                       /* power for N15 pulses */
             pwN = getval("pwN"),             /* N15 90 degree pulse length at pwNlvl */

	     swCa = getval("swCa"),
	     swCO = getval("swCO"),
	     swN  = getval("swN"),
	     swTilt,      /* This is the sweep width of the tilt vector */

	     cos_N, cos_CO, cos_Ca,
	     angle_N, angle_CO, angle_Ca;
             angle_N=0.0;                      /*initialize variable*/

/* LOAD VARIABLES */


  getstr("satmode",satmode);
  getstr("fc180",fc180);
  getstr("fscuba",fscuba);
  getstr("ddseq",ddseq);
  getstr("fCTCa",fCTCa);

  getstr("sel_flg",sel_flg);

  taua   = getval("taua"); 
  taub   = getval("taub"); 
  tauc   = getval("tauc"); 
  taud   = getval("taud"); 
  zeta  = getval("zeta");
  bigTCa = getval("bigTCa");
  bigTCo = getval("bigTCo");
  bigTN = getval("bigTN");
  BigT1 = getval("BigT1");
  tpwr = getval("tpwr");
  dpwr = getval("dpwr");
  dpwr3 = getval("dpwr3");
  sw1 = getval("sw1");
  sw2 = getval("sw2");
  sphase = getval("sphase");
  sphase1 = getval("sphase1");
  sphase2 = getval("sphase2");

  gt1 = getval("gt1");
  gt2 = getval("gt2");
  gt3 = getval("gt3");
  gt4 = getval("gt4");
  gt5 = getval("gt5");
  gt6 = getval("gt6");
  gt7 = getval("gt7");
  gt8 = getval("gt8");
  gt9 = getval("gt9");
  gt10 = getval("gt10");
  gt11 = getval("gt11");
  gt12 = getval("gt12");

  gstab = getval("gstab");
  gzlvl1 = getval("gzlvl1");
  gzlvl2 = getval("gzlvl2");
  gzlvl3 = getval("gzlvl3");
  gzlvl4 = getval("gzlvl4");
  gzlvl5 = getval("gzlvl5");
  gzlvl6 = getval("gzlvl6");
  gzlvl7 = getval("gzlvl7");
  gzlvl8 = getval("gzlvl8");
  gzlvl9 = getval("gzlvl9");
  gzlvl10 = getval("gzlvl10");
  gzlvl11 = getval("gzlvl11");
  gzlvl12 = getval("gzlvl12");

  /* Load variable */
     cbpwr = getval("cbpwr");
     cbdmf = getval("cbdmf");
     cbres = getval("cbres");
     tau1 = 0;
     tau2 = 0;
     tau3 = 0;
     cos_N = 0;
     cos_CO = 0;
     cos_Ca = 0;

     getstr("cbdecseq", cbdecseq);

/* LOAD PHASE TABLE */

  settable(t1,1,phi1);
  settable(t2,1,phi2);
  settable(t3,4,phi3);
  settable(t4,1,phi4);
  settable(t5,1,phi5);
  settable(t7,4,phi7);
  settable(t8,4,phi8);
  settable(t6,4,rec);

   pwS1=c13pulsepw("ca", "co", "square", 90.0);
   pwS2=c13pulsepw("co", "ca", "sinc", 90.0);
   pwS3=c13pulsepw("ca", "co", "square", 180.0);
   pwS4=c13pulsepw("co", "ca", "sinc", 180.0);

   tpwrs = tpwr - 20.0*log10(pwHs/(compH*pw*1.69));   /*needs 1.69 times more*/
   tpwrs = (int) (tpwrs);                          /*power than a square pulse */


/* CHECK VALIDITY OF PARAMETER RANGES */

    if((dm[A] == 'y' || dm[B] == 'y' || dm[C] == 'y' ))
    {
        printf("incorrect dec1 decoupler flags!  ");
        psg_abort(1);
    }

    if((dm2[A] == 'y' || dm2[B] == 'y' || dm2[C] == 'y'))
    {
        printf("incorrect dec2 decoupler flags! Should be 'nnn' ");
        psg_abort(1);
    }

    if( satpwr > 6 )
    {
        printf("TSATPWR too large !!!  ");
        psg_abort(1);
    }

    if( dpwr > 46 )
    {
        printf("don't fry the probe, DPWR too large!  ");
        psg_abort(1);
    }

    if( dpwr2 > 46 )
    {
        printf("don't fry the probe, DPWR2 too large!  ");
        psg_abort(1);
    }

    if( pwClvl > 62 )
    {
        printf("don't fry the probe, pwClvl too large!  ");
        psg_abort(1);
    }

    if( pw > 200.0e-6 )
    {
        printf("dont fry the probe, pw too high ! ");
        psg_abort(1);
    } 
    if( pwN > 200.0e-6 )
    {
        printf("dont fry the probe, pwN too high ! ");
        psg_abort(1);
    } 
    if( pwC > 200.0e-6 )
    {
        printf("dont fry the probe, pwC too high ! ");
        psg_abort(1);
    } 

    if( gt3 > 2.5e-3 ) 
    {
        printf("gt3 is too long\n");
        psg_abort(1);
    }
    if( gt1 > 10.0e-3 || gt2 > 10.0e-3 || gt4 > 10.0e-3 || gt5 > 10.0e-3
        || gt6 > 10.0e-3 || gt7 > 10.0e-3 || gt8 > 10.0e-3
	|| gt9 > 10.0e-3 || gt10 > 10.0e-3 || gt11 > 50.0e-6)
    {
        printf("gt values are too long. Must be < 10.0e-3 or gt11=50us\n");
        psg_abort(1);
    } 


/* PHASES AND INCREMENTED TIMES */


   /* Set up angles and phases */

   angle_CO=getval("angle_CO");  cos_CO=cos(PI*angle_CO/180.0);
   angle_Ca=getval("angle_Ca");  cos_Ca=cos(PI*angle_Ca/180.0);

   if ( (angle_CO < 0) || (angle_CO > 90) )
   {  printf ("angle_CO must be between 0 and 90 degree.\n"); psg_abort(1); }

   if ( (angle_Ca < 0) || (angle_Ca > 90) )
   {  printf ("angle_Ca must be between 0 and 90 degree.\n"); psg_abort(1); }

   if ( 1.0 < (cos_CO*cos_CO + cos_Ca*cos_Ca) )
   {
       printf ("Impossible angles.\n"); psg_abort(1);
   }
   else
   {
           cos_N=sqrt(1.0- (cos_CO*cos_CO + cos_Ca*cos_Ca));
           angle_N = 180.0*acos(cos_N)/PI;
   }

   swTilt=swCO*cos_CO + swCa*cos_Ca + swN*cos_N;

   if (ix ==1)
   {
      printf("\n\nn\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
      printf ("Maximum Sweep Width: \t\t %f Hz\n", swTilt);
      printf ("Anlge_CO:\t%6.2f\n", angle_CO);
      printf ("Anlge_Ca:\t%6.2f\n", angle_Ca);
      printf ("Anlge_N :\t%6.2f\n", angle_N );
   }

/* Set up hyper complex */

   /* sw1 is used as symbolic index */
   if ( sw1 < 1000 ) { printf ("Please set sw1 to some value larger than 1000.\n"); psg_abort(1); }

   if (ix == 1) d2_init = d2;
   t1_counter = (int) ( (d2-d2_init)*sw1 + 0.5 );
   if (t1_counter % 2)  { tsadd(t2,2,4); tsadd(t6,2,4); }

   if (phase1 == 1)  { ;}                                                  /* CC */
   else if (phase1 == 2)  { tsadd(t5,1,4);}                                /* SC */
   else if (phase1 == 3)  { tsadd(t1,1,4); }                               /* CS */
   else if (phase1 == 4)  { tsadd(t5,1,4); tsadd(t1,1,4); }                /* SS */
   else { printf ("phase1 can only be 1,2,3,4. \n"); psg_abort(1); }

   if (phase2 == 2)  { tsadd(t4,2,4); icosel = 1; }                      /* N  */
            else                       icosel = -1;

   tau1 = 1.0*t1_counter*cos_Ca/swTilt;
   tau2 = 1.0*t1_counter*cos_CO/swTilt;
   tau3 = 1.0*t1_counter*cos_N/swTilt;

   tau1 = tau1/2.0;  tau2 = tau2/2.0;  tau3 = tau3/2.0;


/* CHECK VALIDITY OF PARAMETER RANGES */

    if (bigTN - 0.5*ni*(cos_N/swTilt) + pwS4 < 0.2e-6)
       { printf(" ni is too big. Make ni equal to %d or less.\n",
         ((int)((bigTN + pwS4)*2.0*swTilt/cos_N)));              psg_abort(1);}

    if ((fCTCa[A]=='y') && (bigTCa - 0.5*ni*(cos_Ca/swTilt) - WFG_STOP_DELAY 
             - POWER_DELAY - gt11 - 50.2e-6 < 0.2e-6))
       {
         printf(" ni is too big for Ca. Make ni equal to %d or less.\n",
            (int) ((bigTCa -WFG_STOP_DELAY
              - POWER_DELAY - gt11 - 50.2e-6)/(0.5*cos_Ca/swTilt)) );
         psg_abort(1);
       }

     if (bigTCo - 0.5*ni*(cos_CO/swTilt) - 4.0e-6 - POWER_DELAY < 0.2e-6)
       {
        printf(" ni is too big for CO. Make ni equal to %d or less.\n",
        (int) ((bigTCo -  4.0e-6 - POWER_DELAY) / (0.5*cos_CO/swTilt)) );
        psg_abort(1);
        }


/* BEGIN ACTUAL PULSE SEQUENCE */

status(A);
   obsoffset(tof);
   obspower(satpwr);      /* Set transmitter power for 1H presaturation */
   obspwrf(4095.0);
   decpower(pwClvl);       /* Set Dec1 power for hard 13C pulses         */
   decpwrf(4095.0);
   dec2power(pwNlvl);      /* Set Dec2 power for 15N hard pulses         */
   dec2pwrf(4095.0);
   set_c13offset("ca");		/* set Dec1 carrier at Ca		      */
   sim3_c13pulse("", "ca", "co", "square", "", 0.0, 180.0, 0.0,
                             zero, zero, zero, 2.0e-6, 0.0);
   set_c13offset("co");		/* set Dec1 carrier at Co		      */

/* Presaturation Period */

   if (satmode[0] == 'y')
   {
	delay(2.0e-5);
        rgpulse(d1,zero,2.0e-6,2.0e-6); /* presaturation */
   	obspower(tpwr);      /* Set transmitter power for hard 1H pulses */
	delay(2.0e-5);
	if(fscuba[0] == 'y')
	{
		delay(2.2e-2);
		rgpulse(pw,zero,2.0e-6,0.0);
		rgpulse(2*pw,one,2.0e-6,0.0);
		rgpulse(pw,zero,2.0e-6,0.0);
		delay(2.2e-2);
	}
   }
   else
   {
    delay(d1);
   }
   obspower(tpwr);           /* Set transmitter power for hard 1H pulses */
   txphase(one);
   dec2phase(zero);
   delay(1.0e-5);

/* Begin Pulses */

status(B);

   rcvroff();
   lk_hold();

   shiftedpulse("sinc", pwHs, 90.0, 0.0, one, 2.0e-6, 0.0);
   txphase(zero);
   delay(2.0e-6);


/*   xxxxxxxxxxxxxxxxxxxxxx    1HN to 15N TRANSFER   xxxxxxxxxxxxxxxxxx    */

   rgpulse(pw,zero,0.0,0.0);                    /* 90 deg 1H pulse */

   delay(0.2e-6);
   zgradpulse(gzlvl1, gt1);
   delay(2.0e-6);

   delay(taua - gt1 - 2.2e-6);   /* taua <= 1/4JNH */ 

   sim3pulse(2*pw,0.0,2*pwN,zero,zero,zero,0.0,0.0);

   txphase(three); dec2phase(zero); decphase(zero); 

   delay(taua - gt1 - gstab -0.2e-6 - 2.0e-6);

   delay(0.2e-6);
   zgradpulse(gzlvl1, gt1);
   delay(gstab);

/*   xxxxxxxxxxxxxxxxxxxxxx    15N to 13CO TRANSFER   xxxxxxxxxxxxxxxxxx    */

   if(sel_flg[A] == 'n') {

   rgpulse(pw,three,2.0e-6,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl2, gt2);
   delay(gstab);

   dec2rgpulse(pwN,zero,0.0,0.0);

   delay( zeta + pwS4 );

   dec2rgpulse(2*pwN,zero,0.0,0.0);
   c13pulse("co", "ca", "sinc", 180.0, zero, 0.0, 0.0);
   dec2phase(one);

   delay(zeta - 2.0e-6);

   dec2rgpulse(pwN,one,2.0e-6,0.0);

  }

   else {

   rgpulse(pw,one,2.0e-6,0.0);

   initval(1.0,v6);
   dec2stepsize(45.0);
   dcplr2phase(v6);


   delay(0.2e-6);
   zgradpulse(gzlvl2, gt2);
   delay(gstab);

   dec2rgpulse(pwN,zero,0.0,0.0);
   dcplr2phase(zero); dec2phase(zero);

   delay(1.34e-3 - SAPS_DELAY - 2.0*pw);

   rgpulse(pw,one,0.0,0.0);
   rgpulse(2.0*pw,zero,0.0,0.0);
   rgpulse(pw,one,0.0,0.0);

   delay( zeta - 1.34e-3 - 2.0*pw + pwS4 );

   dec2rgpulse(2*pwN,zero,0.0,0.0);
   c13pulse("co", "ca", "sinc", 180.0, zero, 0.0, 0.0);
   dec2phase(one);

   delay(zeta - 2.0e-6);

   dec2rgpulse(pwN,one,2.0e-6,0.0);

  }

   dec2phase(zero); decphase(zero);

   delay(0.2e-6);
   zgradpulse(gzlvl3, gt3);
   delay(gstab);

/* xxxxxxxxxxxxxxxxxxxxx 13CO to 13CA TRANSFER xxxxxxxxxxxxxxxxxxxxxxx  */

   c13pulse("co", "ca", "sinc", 90.0, zero, 2.0e-6, 0.0);

                delay(2.0e-7);
                zgradpulse(gzlvl10, gt10);
                delay(100.0e-6);

  delay(tauc - POWER_DELAY - gt10 - 100.2e-6 - (0.5*10.933*pwC));

        decrgpulse(pwC*158.0/90.0, zero, 0.0, 0.0);
        decrgpulse(pwC*171.2/90.0, two, 0.0, 0.0);
        decrgpulse(pwC*342.8/90.0, zero, 0.0, 0.0);      /* Shaka 6 composite */
        decrgpulse(pwC*145.5/90.0, two, 0.0, 0.0);
        decrgpulse(pwC*81.2/90.0, zero, 0.0, 0.0);
        decrgpulse(pwC*85.3/90.0, two, 0.0, 0.0);

                delay(2.0e-7);
                zgradpulse(gzlvl10, gt10);
                delay(100.0e-6);

      delay(tauc - POWER_DELAY - 4.0e-6 - gt10 - 100.2e-6 - (0.5*10.933*pwC));

   c13pulse("co", "ca", "sinc", 90.0, one, 4.0e-6, 0.0);

   set_c13offset("ca");   /* change Dec1 carrier to Ca (55 ppm) */
   delay(0.2e-6);
   zgradpulse(gzlvl9, gt9);
   delay(gstab);

/* xxxxxxxxxxxxxxxxxx 13CA EVOLUTION xxxxxxxxxxxxxxxxxxxxxx */
                /* Turn on D decoupling using the third decoupler */
                dec3unblank(); dec3rgpulse(1/dmf3, one, 0.0, 0.0);
                dec3unblank(); setstatus(DEC3ch, TRUE, 'w', FALSE, dmf3);
                /* Turn on D decoupling */

   c13pulse("ca", "co", "square", 90.0, t5, 2.0e-6, 0.0);

if (fCTCa[A]=='y')  
{
/* Constant t2 */
   decpower(cbpwr);
   decphase(zero);
   decprgon(cbdecseq,1/cbdmf,cbres);
   decon();
	   
   delay(tau1);

   decoff();
   decprgoff();
   decpower(pwClvl);

   dec2rgpulse(pwN,one,0.0,0.0);
   dec2rgpulse(2*pwN,zero,0.0,0.0);
   dec2rgpulse(pwN,one,0.0,0.0);
   c13pulse("co", "ca", "sinc", 180.0, zero, 0.0, 0.0);

   decpower(cbpwr);
   decphase(zero);
   decprgon(cbdecseq,1/cbdmf,cbres);
   decon();

   delay(bigTCa - 4.0*pwN - WFG_START_DELAY - pwS4
         - WFG_STOP_DELAY - POWER_DELAY - WFG_START_DELAY - gt11 - gstab -0.2e-6);

   decoff();
   decprgoff();
   decpower(pwClvl);

   delay(0.2e-6);
   zgradpulse(gzlvl11, gt11);
   delay(gstab);

       initval(1.0,v3);
       decstepsize(140);
       dcplrphase(v3);

   c13pulse("ca", "co", "square", 180.0, zero, 0.0, 0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl11, gt11);
   delay(gstab);

   decpower(cbpwr);
   decphase(zero);
   decprgon(cbdecseq,1/cbdmf,cbres);
   decon();

   delay(bigTCa - tau1 - WFG_STOP_DELAY - POWER_DELAY - gt11 - gstab -0.2e-6);

   decoff();
   decprgoff();
}

/* non_constant t2 */
else
{
  if (fc180[A]=='n')
   {
    if ((ni>1.0) && (tau1>0.0))
    {
    if (tau1 - 2.0*pwS1/PI - PRG_START_DELAY - 2*POWER_DELAY -
        PRG_STOP_DELAY - pwN > 0.0)
     {
   decpower(cbpwr);
   decphase(zero);
   decprgon(cbdecseq,1/cbdmf,cbres);
   decon();

   delay(tau1 - 2.0*pwS1/PI - PRG_START_DELAY - 2*POWER_DELAY -
        PRG_STOP_DELAY - pwN);
   decoff();
   decprgoff();

   decphase(zero); dec2phase(zero);
   decpower(pwClvl);

   sim3_c13pulse("", "co", "ca", "sinc", "", 0.0, 180.0, 2.0*pwN,
                             zero, zero, zero, 0.0, 0.0);

   decpower(cbpwr);
   decphase(zero);
   decprgon(cbdecseq,1/cbdmf,cbres);
   decon();

   delay(tau1 - 2.0*pwS1/PI - PRG_START_DELAY - 2*POWER_DELAY -
        PRG_STOP_DELAY - pwN);
   decoff();
   decprgoff();

   decstepsize(1.0);
   initval(sphase1, v3);
   dcplrphase(v3);

     }
    else
     {
       tsadd(t6,2,4);
       delay(2.0*tau1);
       delay(10.0e-6); 
       sim3_c13pulse("", "ca", "co", "square", "", 0.0, 180.0, 2.0*pwN,
                             zero, zero, zero, 2.0e-6, 0.0);
       delay(10.0e-6);
     }
   }
   else
   {

       tsadd(t6,2,4);
       delay(10.0e-6);
       sim3_c13pulse("", "ca", "co", "square", "", 0.0, 180.0, 2.0*pwN,
                             zero, zero, zero, 2.0e-6, 0.0);
       delay(10.0e-6);
   }
 }
   else
  {
   /* for checking sequence */
   c13pulse("ca", "co", "square", 180.0, zero, 2.0e-6, 0.0);
  }
}

   decpower(pwClvl);
   decphase(t7);
   c13pulse("ca", "co", "square", 90.0, t7, 4.0e-6, 0.0);
   dcplrphase(zero);
 
                /* Turn off D decoupling */
                dec3rgpulse(1/dmf3, three, 0.0, 0.0); dec3blank();
                setstatus(DEC3ch, FALSE, 'w', FALSE, dmf3); dec3blank();
                /* Turn off D decoupling */
 

   set_c13offset("co");   /* set carrier back to Co */

   delay(0.2e-6);

   zgradpulse(gzlvl12, gt12);
   delay(gstab);


/* xxxxxxxxxxxxxxx  13CA to 13CO TRANSFER and CT 13CO EVOLUTION xxxxxxxxxxxxxxxxx */

   c13pulse("co", "ca", "sinc", 90.0, t1, 2.0e-6, 0.0);

   delay(tau2);
   dec2rgpulse(pwN,one,0.0,0.0);
   dec2rgpulse(2*pwN,zero,0.0,0.0);
   dec2rgpulse(pwN,one,0.0,0.0);

   delay(taud - 4.0*pwN - POWER_DELAY
         - 0.5*(WFG_START_DELAY + pwS3 + WFG_STOP_DELAY));

   c13pulse("ca", "co", "square", 180.0, zero, 0.0, 0.0);
       decphase(t8);

                initval(1.0,v4);
                decstepsize(sphase);
                dcplrphase(v4);

      delay(bigTCo - taud
            - 0.5*(WFG_START_DELAY + pwS3 + WFG_STOP_DELAY) );

      c13pulse("co", "ca", "sinc", 180.0, t8, 0.0, 0.0);
      dcplrphase(zero); decphase(one);

    delay(bigTCo - tau2 - POWER_DELAY - 4.0e-6);

   c13pulse("co", "ca", "sinc", 90.0, one, 4.0e-6, 0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl4, gt4);
   delay(gstab);

/* t3 period */
   dec2rgpulse(pwN,t2,2.0e-6,0.0);

   dec2phase(t3);

   delay(bigTN - tau3 + pwS4);

     dec2rgpulse(2*pwN,t3,0.0,0.0);
     c13pulse("co", "ca", "sinc", 180.0, zero, 0.0, 0.0);

   txphase(zero);
   dec2phase(t4);

  delay(bigTN - gt5 - gstab -0.2e-6 - 2.0*GRADIENT_DELAY
	- 4.0e-6 - WFG_START_DELAY - pwS3 - WFG_STOP_DELAY);

   delay(0.2e-6);
   zgradpulse(icosel*gzlvl5, gt5);
   delay(gstab);

      c13pulse("ca", "co", "square", 180.0, zero, 4.0e-6, 0.0);

   delay(tau3);

   sim3pulse(pw,0.0,pwN,zero,zero,t4,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl6, gt6);
   delay(2.0e-6);

   dec2phase(zero);
   delay(taub - gt6 - 2.2e-6);

   sim3pulse(2*pw,0.0,2*pwN,zero,zero,zero,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl6, gt6);
   delay(200.0e-6);
   
   txphase(one);
   dec2phase(one);

   delay(taub - gt6 - 200.2e-6);

   sim3pulse(pw,0.0,pwN,one,zero,one,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl7, gt7);
   delay(2.0e-6);
 
   txphase(zero);
   dec2phase(zero);

   delay(taub - gt7 - 2.2e-6);

   sim3pulse(2*pw,0.0,2*pwN,zero,zero,zero,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl7, gt7);
   delay(200.0e-6);

   delay(taub - gt7 - 200.2e-6);

   sim3pulse(pw,0.0,pwN,zero,zero,zero,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(-gzlvl8, gt8/2.0);
   delay(50.0e-6);

   delay(BigT1 - gt8/2.0 - 50.2e-6 - 0.5*(pwN - pw) - 2.0*pw/PI);

   rgpulse(2*pw,zero,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl8, gt8/2.0);
   delay(50.0e-6);
   
   dec2power(dpwr2);
   decpower(dpwr);
   
   delay(BigT1 - gt8/2.0 - 50.2e-6 - 2.0*POWER_DELAY);

lk_sample();
/*   rcvron();  */          /* Turn on receiver to warm up before acq */ 

/* BEGIN ACQUISITION */

status(C);
         setreceiver(t6);

}
pulsesequence()
{
/* DECLARE VARIABLES */

 char       satmode[MAXSTR],
	    fscuba[MAXSTR],
            cbdecseq[MAXSTR],
            chirp_shp[MAXSTR],  /* name of variable containing name of Pbox shape */
            fco180[MAXSTR],    /* Flag for checking sequence              */
            fca180[MAXSTR],    /* Flag for checking sequence              */
            sel_flg[MAXSTR];

 int         icosel,
             ni = getval("ni"),
             t1_counter;   /* used for states tppi in t1           */ 

 double      d2_init=0.0,                        /* used for states tppi in t1 */
             tau1,         /*  t1 delay */
             tau2,         /*  t2 delay */
             tau3,         /*  t2 delay */
             taua,         /*  ~ 1/4JNH =  2.25 ms */
             taub,         /*  ~ 1/4JNH =  2.25 ms */
             zeta,        /* time for C'-N to refocuss set to 0.5*24.0 ms */
             bigTN,       /* nitrogen T period */
             BigT1,       /* delay to compensate for gradient gt5 */
             satpwr,     /* low level 1H trans.power for presat  */
             sw1,          /* sweep width in f1                    */             
             sw2,          /* sweep width in f2                    */             
             cophase,      /* phase correction for CO evolution  */
             caphase,      /* phase correction for Ca evolution  */
             cbpwr,        /* power level for selective CB decoupling */
             cbdmf,        /* pulse width for selective CB decoupling */
             cbres,        /* decoupling resolution of CB decoupling */
             pwS1,         /* length of  90 on Ca */
             pwS2,         /* length of  90 on CO */
             pwS3,         /* length of 180 on Ca  */
             pwS4,         /* length of 180 on CO  */
             pwS5,         /* CHIRP inversion pulse on CO and CA  */
             pwrS5=0.0,        /* power of CHIRP pulse */

             gt1,
             gt2,
             gt3,
             gt4,
             gt5,
             gt6,
             gt7,
             gt8,
             gt9,
             gstab,
             gzlvl1,
             gzlvl2,
             gzlvl3,
             gzlvl4,
             gzlvl5,
             gzlvl6,
             gzlvl7, 
             gzlvl8, 
             gzlvl9, 

             compH = getval("compH"),         /* adjustment for amplifier compression */
             pwHs = getval ("pwHs"),         /* H1 90 degree pulse at tpwrs */
             tpwrs,                          /* power for pwHs ("H2osinc") pulse */
             waltzB1 = getval("waltzB1"),

             pwClvl = getval("pwClvl"),                 /* coarse power for C13 pulse */
             pwC = getval("pwC"),             /* C13 90 degree pulse length at pwClvl */
             compC = getval("compC"),             /* ampl. compression */

             pwNlvl = getval("pwNlvl"),                       /* power for N15 pulses */
             pwN = getval("pwN"),             /* N15 90 degree pulse length at pwNlvl */

  swCa = getval("swCa"),
  swCO = getval("swCO"),
  swN  = getval("swN"),
  swTilt,                     /* This is the sweep width of the tilt vector */

  cos_N, cos_CO, cos_Ca,
  angle_N, angle_CO, angle_Ca;
  angle_N=0.0;


/* LOAD VARIABLES */


  getstr("satmode",satmode);
  getstr("fco180",fco180);
  getstr("fca180",fca180);
  getstr("fscuba",fscuba);

  getstr("sel_flg",sel_flg);

  taua   = getval("taua"); 
  taub   = getval("taub"); 
  zeta  = getval("zeta");
  bigTN = getval("bigTN");
  BigT1 = getval("BigT1");
  tpwr = getval("tpwr");
  satpwr = getval("tsatpwr");
  dpwr = getval("dpwr");
  sw1 = getval("sw1");
  sw2 = getval("sw2");
  cophase = getval("cophase");
  caphase = getval("caphase");

  gt1 = getval("gt1");
  gt2 = getval("gt2");
  gt3 = getval("gt3");
  gt4 = getval("gt4");
  gt5 = getval("gt5");
  gt6 = getval("gt6");
  gt7 = getval("gt7");
  gt8 = getval("gt8");
  gt9 = getval("gt9");

  gstab = getval("gstab");
  gzlvl1 = getval("gzlvl1");
  gzlvl2 = getval("gzlvl2");
  gzlvl3 = getval("gzlvl3");
  gzlvl4 = getval("gzlvl4");
  gzlvl5 = getval("gzlvl5");
  gzlvl6 = getval("gzlvl6");
  gzlvl7 = getval("gzlvl7");
  gzlvl8 = getval("gzlvl8");
  gzlvl9 = getval("gzlvl9");

/* Load variable */
        cbpwr = getval("cbpwr");
        cbdmf = getval("cbdmf");
        cbres = getval("cbres");
        tau1 = 0;
        tau2 = 0;
        tau3 = 0;
        cos_N = 0;
        cos_CO = 0;
        cos_Ca = 0;

    getstr("cbdecseq", cbdecseq);

/* LOAD PHASE TABLE */

  settable(t1,2,phi1);
  settable(t2,2,phi2);
  settable(t3,1,phi3);
  settable(t4,8,phi4);
  settable(t5,4,phi5);
  settable(t6,8,rec);

  /* get calculated pulse lengths of shaped C13 pulses */
        pwS1 = c13pulsepw("ca", "co", "square", 90.0);
        pwS2 = c13pulsepw("co", "ca", "sinc", 90.0);
        pwS3 = c13pulsepw("ca","co","square",180.0);
        pwS4 = c13pulsepw("co","ca","sinc",180.0);


  /*this section creates the chirp pulse inverting both co and ca*/
  /*Pcoca180 is the name of the shapelib file created            */
  /*chirp180 is a file produced by Pbox psg containing parameter values from shape*/

  strcpy(chirp_shp,"Pcoca180");
   if (FIRST_FID)                  /* make shape once */
    chirp180 = pbox(chirp_shp, CHIRP180, CHIRP180ps, dfrq, compC*pwC, pwClvl);
   pwrS5 = chirp180.pwr;             /* get pulse power from file */
   pwS5 = chirp180.pw;             /* get pulse width from file */

   tpwrs = tpwr - 20.0*log10(pwHs/(compH*pw*1.69));   /*needs 1.69 times more*/
   tpwrs = (int) (tpwrs);                          /*power than a square pulse */
   widthHd = 2.681*waltzB1/sfrq;  /* bandwidth of H1 WALTZ16 decoupling */
   pwHd = h1dec90pw("WALTZ16", widthHd, 0.0);     /* H1 90 length for WALTZ16 */


/* CHECK VALIDITY OF PARAMETER RANGES */


    if((dm[A] == 'y' || dm[B] == 'y' || dm[C] == 'y' ))
    {
        printf("incorrect dec1 decoupler flags!  ");
        psg_abort(1);
    }

    if((dm2[A] == 'y' || dm2[B] == 'y' || dm2[C] == 'y' ))
    {
        printf("incorrect dec2 decoupler flags! Should be 'nnn' ");
        psg_abort(1);
    }


    if( satpwr > 6 )
    {
        printf("SATPWR too large !!!  ");
        psg_abort(1);
    }

    if( dpwr > 46 )
    {
        printf("don't fry the probe, DPWR too large!  ");
        psg_abort(1);
    }

    if( dpwr2 > 46 )
    {
        printf("don't fry the probe, DPWR2 too large!  ");
        psg_abort(1);
    }

    if( pwClvl > 62 )
    {
        printf("don't fry the probe, pwClvl too large!  ");
        psg_abort(1);
    }

    if( pw > 200.0e-6 )
    {
        printf("dont fry the probe, pw too high ! ");
        psg_abort(1);
    } 
    if( pwN > 200.0e-6 )
    {
        printf("dont fry the probe, pwN too high ! ");
        psg_abort(1);
    } 
    if( pwC > 200.0e-6 )
    {
        printf("dont fry the probe, pwC too high ! ");
        psg_abort(1);
    } 

    if( gt3 > 2.5e-3 ) 
    {
        printf("gt3 is too long\n");
        psg_abort(1);
    }
    if( gt1 > 10.0e-3 || gt2 > 10.0e-3 || gt4 > 10.0e-3 || gt5 > 10.0e-3
        || gt6 > 10.0e-3 || gt7 > 10.0e-3 || gt8 > 10.0e-3
	|| gt9 > 10.0e-3)
    {
        printf("gt values are too long. Must be < 10.0e-3 or gt11=50us\n");
        psg_abort(1);
    } 


/* PHASES AND INCREMENTED TIMES */


   /* Set up angles and phases */

   angle_CO=getval("angle_CO");  cos_CO=cos(PI*angle_CO/180.0);
   angle_Ca=getval("angle_Ca");  cos_Ca=cos(PI*angle_Ca/180.0);

   if ( (angle_CO < 0) || (angle_CO > 90) )
   {  printf ("angle_CO must be between 0 and 90 degree.\n"); psg_abort(1); }

   if ( (angle_Ca < 0) || (angle_Ca > 90) )
   {  printf ("angle_Ca must be between 0 and 90 degree.\n"); psg_abort(1); }

   if ( 1.0 < (cos_CO*cos_CO + cos_Ca*cos_Ca) )
   {
       printf ("Impossible angles.\n"); psg_abort(1);
   }
   else
   {
           cos_N=sqrt(1.0- (cos_CO*cos_CO + cos_Ca*cos_Ca));
           angle_N = 180.0*acos(cos_N)/PI;
   }

   swTilt=swCO*cos_CO + swCa*cos_Ca + swN*cos_N;

   if (ix ==1)
   {
      printf("\n\nn\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
      printf ("Maximum Sweep Width: \t\t %f Hz\n", swTilt);
      printf ("Anlge_CO:\t%6.2f\n", angle_CO);
      printf ("Anlge_Ca:\t%6.2f\n", angle_Ca);
      printf ("Anlge_N :\t%6.2f\n", angle_N );
   }

/* Set up hyper complex */

   /* sw1 is used as symbolic index */
   if ( sw1 < 1000 ) { printf ("Please set sw1 to some value larger than 1000.\n"); psg_abort(1); }

   if (ix == 1) d2_init = d2;
   t1_counter = (int) ( (d2-d2_init)*sw1 + 0.5 );
   if (t1_counter % 2)  { tsadd(t2,2,4); tsadd(t6,2,4); }

   if (phase1 == 1)  { ;}                                                  /* CC */
   else if (phase1 == 2)  { tsadd(t1,1,4);}                                /* SC */
   else if (phase1 == 3)  { tsadd(t5,1,4); }                               /* CS */
   else if (phase1 == 4)  { tsadd(t1,1,4); tsadd(t5,1,4); }                /* SS */
   else { printf ("phase1 can only be 1,2,3,4. \n"); psg_abort(1); }

   if (phase2 == 2)  { tsadd(t4,2,4); icosel = +1; }                      /* N  */
            else                       icosel = -1;

   tau1 = 1.0*t1_counter*cos_CO/swTilt;
   tau2 = 1.0*t1_counter*cos_Ca/swTilt;
   tau3 = 1.0*t1_counter*cos_N/swTilt;

   tau1 = tau1/2.0;  tau2 = tau2/2.0;  tau3 = tau3/2.0;


/* CHECK VALIDITY OF PARAMETER RANGES */

    if (bigTN - 0.5*ni*(cos_N/swTilt) < 0.2e-6)
       { printf(" ni is too big. Make ni equal to %d or less.\n",
         ((int)((bigTN )*2.0*swTilt/cos_N)));         psg_abort(1);}


/* BEGIN ACTUAL PULSE SEQUENCE */

status(A);
   set_c13offset("co");		/* set Dec1 carrier at Co		      */
   obspower(satpwr);      /* Set transmitter power for 1H presaturation */
   obspwrf(4095.0);
   decpower(pwClvl);      /* Set Dec1 power for hard 13C pulses         */
   decpwrf(4095.0);
   dec2power(pwNlvl);      /* Set Dec2 power for 15N hard pulses         */
   dec2pwrf(4095.0);

/* Presaturation Period */

   if (satmode[0] == 'y')
   {
	delay(2.0e-5);
        rgpulse(d1,zero,2.0e-6,2.0e-6); /* presaturation */
   	obspower(tpwr);      /* Set transmitter power for hard 1H pulses */
	delay(2.0e-5);
	if(fscuba[0] == 'y')
	{
		delay(2.2e-2);
		rgpulse(pw,zero,2.0e-6,0.0);
		rgpulse(2*pw,one,2.0e-6,0.0);
		rgpulse(pw,zero,2.0e-6,0.0);
		delay(2.2e-2);
	}
   }
   else
   {
    delay(d1);
   }
   obspower(tpwr);           /* Set transmitter power for hard 1H pulses */
   txphase(one);
   dec2phase(zero);
   delay(1.0e-5);

/* Begin Pulses */

status(B);

   rcvroff();
   lk_hold();
   delay(20.0e-6);
   shiftedpulse("sinc", pwHs, 90.0, 0.0, one, 2.0e-6, 2.0e-6);
   txphase(zero);

   rgpulse(pw,zero,0.0,0.0);                    /* 90 deg 1H pulse */

   delay(0.2e-6);
   zgradpulse(gzlvl1, gt1);
   delay(2.0e-6);

   delay(taua - gt1 - 2.2e-6);   /* taua <= 1/4JNH */ 

   sim3pulse(2*pw,0.0,2*pwN,zero,zero,zero,0.0,0.0);

   txphase(three); dec2phase(zero); decphase(zero); 

   delay(0.2e-6);
   zgradpulse(gzlvl1, gt1);
   delay(gstab);

   delay(taua - gt1 - gstab - 2.0e-6); 

   if(sel_flg[A] == 'n') {

   rgpulse(pw,three,2.0e-6,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl2, gt2);
   delay(gstab);

   dec2rgpulse(pwN,zero,0.0,0.0);
   decpower(pwrS5);
   delay( zeta -POWER_DELAY);
  
   dec2rgpulse(2.0*pwN,zero,0.0,0.0);
   decshapedpulse(chirp_shp, pwS5, zero, 0.0, 0.0);
   decpower(pwClvl);

   delay(zeta - pwS5 - POWER_DELAY - 2.0e-6);

   dec2rgpulse(pwN,zero,2.0e-6,0.0);

  }

  else {

   rgpulse(pw,one,2.0e-6,0.0);

   initval(1.0,v3);
   dec2stepsize(45.0); 
   dcplr2phase(v3);

   delay(0.2e-6);
   zgradpulse(gzlvl2, gt2);
   delay(gstab);

   dec2rgpulse(pwN,zero,0.0,0.0);
   dcplr2phase(zero);

   delay(1.34e-3 - SAPS_DELAY - 2.0*pw);

   rgpulse(pw,one,0.0,0.0);
   rgpulse(2.0*pw,zero,0.0,0.0);
   rgpulse(pw,one,0.0,0.0);

   decpower(pwrS5);
   delay( zeta - 1.34e-3 - 2.0*pw -POWER_DELAY);
  
   dec2rgpulse(2.0*pwN,zero,0.0,0.0);
   decshapedpulse(chirp_shp, pwS5, zero, 0.0, 0.0);
   decpower(pwClvl);

   delay(zeta - pwS5 - POWER_DELAY - 2.0e-6);

   dec2rgpulse(pwN,zero,2.0e-6,0.0);

   }

   dec2phase(zero); decphase(t1);

   delay(0.2e-6);
   zgradpulse(gzlvl3, gt3);
   delay(gstab);

/* t1 period for CO evolution */
   c13pulse("co", "ca", "sinc", 90.0, t1, 0.0, 0.0);

    if (!strcmp(fco180, "y"))
    {
      delay(10.0e-6);
      sim3_c13pulse("", "ca", "co", "square", "", 0.0, 180.0, 2.0*pwN,
                             zero, zero, zero, 2.0e-6, 2.0e-6);
      decstepsize(1.0);
      initval(cophase,v4);
      dcplrphase(v4);
      delay(10.0e-6);
    }
    else
    {
     if (tau1-2.0*pwS2/PI-pwN-WFG3_START_DELAY-POWER_DELAY-2.0e-6 > 0.0)
     {
      delay(tau1-2.0*pwS2/PI-pwN-WFG3_START_DELAY-POWER_DELAY-2.0e-6);
      sim3_c13pulse("", "ca", "co", "square", "", 0.0, 180.0, 2.0*pwN,
                             zero, zero, zero, 2.0e-6, 2.0e-6);

      decstepsize(1.0);
      initval(cophase,v4);
      dcplrphase(v4);

      delay(tau1-2.0*pwS2/PI-pwN-SAPS_DELAY-WFG3_STOP_DELAY-POWER_DELAY-2.0e-6);
     }
    else
     {
     c13pulse("co", "ca", "sinc", 180.0, zero, 0.0, 0.0);
     }
    }

   c13pulse("co", "ca", "sinc", 90.0, zero, 4.0e-6, 0.0);
   dcplrphase(zero);

   set_c13offset("ca");   /* change Dec1 carrier to Ca (55 ppm) */
   delay(0.2e-6);
   zgradpulse(gzlvl4, gt4);
   delay(gstab);

/*  t2 period  for Ca evolution*/
 
                /* Turn on D decoupling using the third decoupler */
                dec3unblank(); dec3rgpulse(1/dmf3, one, 0.0, 0.0);
                dec3unblank(); setstatus(DEC3ch, TRUE, 'w', FALSE, dmf3);
                /* Turn on D decoupling */

   c13pulse("ca", "co", "square", 90.0, t5, 0.0, 0.0);

    if (!strcmp(fca180, "y"))
    {
      delay(10.0e-6);
      sim3_c13pulse("", "co", "ca", "sinc", "", 0.0, 180.0, 2.0*pwN,
                             zero, zero, zero, 2.0e-6, 2.0e-6);
      decstepsize(1.0);
      initval(caphase,v5);
      dcplrphase(v5);
      delay(10.0e-6);
    }
    else
    {

    if (tau2-pwN-2.0*pwS1/PI-WFG3_START_DELAY-2*POWER_DELAY-
        -WFG_STOP_DELAY-WFG_START_DELAY-2.0e-6 > 0.0)
    {
      decpower(cbpwr);
      decphase(zero);
      decprgon(cbdecseq,1/cbdmf,cbres);
      decon();

     delay(tau2-pwN-2.0*pwS1/PI-WFG3_START_DELAY-2*POWER_DELAY-
           WFG_STOP_DELAY-WFG_START_DELAY-2.0e-6);

      decoff();
      decprgoff();

     decphase(zero); dec2phase(zero);
     decpower(pwClvl);
     sim3_c13pulse("", "co", "ca", "sinc", "", 0.0, 180.0, 2.0*pwN,
                             zero, zero, zero, 2.0e-6, 2.0e-6);

      decpower(cbpwr);
      decphase(zero);
      decprgon(cbdecseq,1/cbdmf,cbres);
      decon();

     delay(tau2-pwN-2.0*pwS1/PI-SAPS_DELAY-WFG3_STOP_DELAY-2*POWER_DELAY-
           WFG_STOP_DELAY-WFG_START_DELAY-2.0e-6);

      decoff();
      decprgoff();

      decstepsize(1.0);
      initval(caphase,v5);
      dcplrphase(v5);

     decpower(pwClvl);

    }
     else 
     {
     c13pulse("ca", "co", "square", 180.0, zero, 0.0, 0.0);
     }
    }
 
   c13pulse("ca", "co", "square", 90.0, zero, 4.0e-6, 0.0);
   dcplrphase(zero);
 
                /* Turn off D decoupling */
                dec3rgpulse(1/dmf3, three, 0.0, 0.0); dec3blank();
                setstatus(DEC3ch, FALSE, 'w', FALSE, dmf3); dec3blank();
                /* Turn off D decoupling */
 
   set_c13offset("co");   /* set carrier back to Co */

   delay(0.2e-6);
   zgradpulse(gzlvl9, gt9);
   delay(gstab);


/* t3 period */
   dec2rgpulse(pwN,t2,2.0e-6,0.0);

   dec2phase(t3);
   decpower(pwrS5);
   delay(bigTN - tau3 -POWER_DELAY);

   dec2rgpulse(2.0*pwN,t3,0.0,0.0);
   decshapedpulse(chirp_shp, pwS5, zero, 0.0, 0.0);
   decpower(pwClvl);

   txphase(zero);
   dec2phase(t4);

   delay(0.2e-6);
   zgradpulse(icosel*gzlvl5, gt5);
   delay(gstab);

 
  delay(bigTN - WFG_START_DELAY - pwS5 - WFG_STOP_DELAY
         - gt5 - gstab - 2.0*GRADIENT_DELAY);

   delay(tau3);

   sim3pulse(pw,0.0,pwN,zero,zero,t4,0.0,0.0);

   c13pulse("co", "ca", "sinc", 90.0, zero, 4.0e-6, 0.0);
      set_c13offset("ca");
   c13pulse("ca", "co", "square", 90.0, zero, 20.0e-6, 0.0);


   delay(0.2e-6);
   zgradpulse(gzlvl6, gt6);
   delay(2.0e-6);

   dec2phase(zero);
   delay(taub - POWER_DELAY - 4.0e-6 - pwS1 - 20.0e-6 - pwS2 - gt6 - 2.2e-6);

   sim3pulse(2*pw,0.0,2*pwN,zero,zero,zero,0.0,0.0);

   set_c13offset("co");
   delay(0.2e-6);
   zgradpulse(gzlvl6, gt6);
   delay(gstab);
   
   txphase(one);
   dec2phase(one);

   delay(taub - gt6 - gstab);

   sim3pulse(pw,0.0,pwN,one,zero,one,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl7, gt7);
   delay(2.0e-6);
 
   txphase(zero);
   dec2phase(zero);

   delay(taub - gt7 - 2.2e-6);

   sim3pulse(2*pw,0.0,2*pwN,zero,zero,zero,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl7, gt7);
   delay(gstab);

   delay(taub - gt7 - gstab);

   sim3pulse(pw,0.0,pwN,zero,zero,zero,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(-gzlvl8, gt8/2.0);
   delay(gstab);

   delay(BigT1 - gt8/2.0 - gstab - 0.5*(pwN - pw) - 2.0*pw/PI);

   rgpulse(2*pw,zero,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl8, gt8/2.0);
   delay(gstab);
   
   dec2power(dpwr2);
   decpower(dpwr);
   
   delay(BigT1 - gt8/2.0 - gstab - 2.0*POWER_DELAY);

lk_sample();

status(C);
         setreceiver(t6);

}
Esempio n. 5
0
pulsesequence()
{

/* DECLARE AND LOAD VARIABLES; parameters used in the last half of the */
/* sequence are declared and initialized as 0.0 in bionmr.h, and       */
/* reinitialized below  */

char        sel_flg[MAXSTR], autocal[MAXSTR],
            glyshp[MAXSTR];
   
int         t1_counter,                       /* used for states tppi in t1 */
            ni = getval("ni");

double      d2_init=0.0,                      /* used for states tppi in t1 */
            tau1,         
            tau2,
            tau3,
   glypwr,glypwrf,                    /* Power levels for Cgly selective 90 */
   pwgly,                              /* Pulse width for Cgly selective 90 */
   bw,ppm,                             /* Used for autocal Cgly selective 90*/

   tauCC = getval("tauCC"),                      /* delay for Ca to Cb cosy */
   timeTN = getval("timeTN"),            /* constant time for 15N evolution */
   waltzB1 = getval("waltzB1"),
   pwC = getval("pwC"),                              /* C13 pulse at pwClvl */
   pwClvl = getval("pwClvl"),                 /* coarse power for C13 pulse */
   compC  = getval("compC"),         /* correction for amplifier compression*/
   pwCa180,
   pwCO180,
   pwCab90,
   pwCab180,

   pwS1,                                      /* length of square 90 on Cab */
   phshift = getval("phshift"),    /* phase shift on Cab by 180 on CO in t1 */
   pwS2,                                             /* length of 180 on CO */
   pwS3,
   pwS = getval("pwS"), /*used to change 180 on CO in t1 for 1D calibration */
   pwZ,                                  /* the largest of pwS2 and 2.0*pwN */
   pwZ1,              /* the largest of pwS2 and 2.0*pwN for 1D experiments */

   pwNlvl = getval("pwNlvl"),                       /* power for N15 pulses */
   pwN = getval("pwN"),             /* N15 90 degree pulse length at pwNlvl */

   sw1 = getval("sw1"),
   swCb = getval("swCb"),
   swCa = getval("swCa"),
   swN  = getval("swN"),
   swTilt,                     /* This is the sweep width of the tilt vector */

   cos_N, cos_Ca, cos_Cb,
   angle_N, angle_Ca, angle_Cb,      /* angle_N is calculated automatically */
   gstab = getval("gstab"),
   gt1 = getval("gt1"),     gzlvl1 = getval("gzlvl1"),
                            gzlvl2 = getval("gzlvl2"),
   gt3 = getval("gt3"),     gzlvl3 = getval("gzlvl3"),
   gt4 = getval("gt4"),     gzlvl4 = getval("gzlvl4"),
   gt5 = getval("gt5"),     gzlvl5 = getval("gzlvl5"),
   gt6 = getval("gt6"),     gzlvl6 = getval("gzlvl6"),
   gt7 = getval("gt7"),     gzlvl7 = getval("gzlvl7"),
   gt8 = getval("gt8"),     gzlvl8 = getval("gzlvl8");
   angle_N=0.0;

/* Load variables */
   glypwrf = getval("glypwrf");
   glypwr = getval("glypwr");
   pwgly = getval("pwgly");
   tau1 = 0;    tau2 = 0;      tau3 = 0;
   cos_N = 0;   cos_Ca = 0;    cos_Cb = 0;
   getstr("autocal", autocal);
   getstr("glyshp", glyshp);
   getstr("sel_flg",sel_flg);

/* LOAD PHASE TABLE */
   settable(t2,1,phy);    settable(t3,2,phi3);   
   settable(t5,4,phi5);   settable(t6,8,phi6);

   settable(t8,1,phy);    settable(t9,1,phx);    settable(t10,1,phx);
   settable(t11,1,phx);   settable(t12,8,recT);

/*   INITIALIZE VARIABLES   */
   lambda = 2.4e-3;

   pwCa180=c13pulsepw("ca", "co", "square", 180.0);
   pwCO180=c13pulsepw("co", "ca", "sinc", 180.0);
   pwCab90=c13pulsepw("cab","co","square",90.0);
   pwCab180=c13pulsepw("cab","co","square",180.0);

   pwHs = 1.7e-3*500.0/sfrq;       /* length of H2O flipback, 1.7ms at 500 MHz*/
   widthHd = 2.861*(waltzB1/sfrq); /* bw of H1 WALTZ16 decoupling */
   pwHd = h1dec90pw("WALTZ16", widthHd, 0.0);     /* H1 90 length for WALTZ16 */
 
/* get calculated pulse lengths of shaped C13 pulses */
   pwS1 = c13pulsepw("cab", "co", "square", 90.0); 
   pwS2 = c13pulsepw("co", "cab", "sinc", 180.0); 
   pwS3 = c13pulsepw("cab", "co", "square", 180.0);

/* the 180 pulse on CO at the middle of t1 */
   if (pwS2 > 2.0*pwN) pwZ = pwS2; else pwZ = 2.0*pwN;
   if ((pwS==0.0) && (pwS2>2.0*pwN)) pwZ1=pwS2-2.0*pwN; else pwZ1=0.0;
   if ( ni > 1 )     pwS = 180.0;
   if ( pwS > 0 )   phshift = 140.0;
     else           phshift = 0.0;

/* CHECK VALIDITY OF PARAMETER RANGES */

    if ( dm[A] == 'y' || dm[B] == 'y' || dm[C] == 'y' )
       { printf("incorrect dec1 decoupler flags! Should be 'nnn' "); psg_abort(1);}

    if ( dm2[A] == 'y' || dm2[B] == 'y' || dm3[C] == 'y' )
       { printf("incorrect dec2 decoupler flags! Should be 'nnn' "); psg_abort(1);}

    if ( dm3[A] == 'y' || dm3[C] == 'y' )
       { printf("incorrect dec3 decoupler flags! Should be 'nyn' or 'nnn' ");
                                                psg_abort(1);}     
    if ( dpwr2 > 46 )
       { printf("dpwr2 too large! recheck value  ");               psg_abort(1);}

    if ( pw > 20.0e-6 )
       { printf(" pw too long ! recheck value ");                  psg_abort(1);} 
  
    if ( pwN > 100.0e-6 )
       { printf(" pwN too long! recheck value ");                  psg_abort(1);} 

 
/* PHASES AND INCREMENTED TIMES */

   /* Set up angles and phases */

   angle_Cb=getval("angle_Cb");  cos_Cb=cos(PI*angle_Cb/180.0);
   angle_Ca=getval("angle_Ca");  cos_Ca=cos(PI*angle_Ca/180.0);

   if ( (angle_Cb < 0) || (angle_Cb > 90) )
   {  printf ("angle_Cb must be between 0 and 90 degree.\n"); psg_abort(1); }

   if ( (angle_Ca < 0) || (angle_Ca > 90) )
   {  printf ("angle_Ca must be between 0 and 90 degree.\n"); psg_abort(1); }

   if ( 1.0 < (cos_Cb*cos_Cb + cos_Ca*cos_Ca) )
   {
       printf ("Impossible angles.\n"); psg_abort(1);
   }
   else
   {
           cos_N=sqrt(1.0- (cos_Cb*cos_Cb + cos_Ca*cos_Ca));
           angle_N = 180.0*acos(cos_N)/PI;
   }

   swTilt=swCb*cos_Cb + swCa*cos_Ca + swN*cos_N;

   if (ix ==1)
   {

      if ( 0.5*ni*(cos_N/swTilt) > timeTN - WFG3_START_DELAY)
      { printf(" ni is too big. Make ni equal to %d or less.\n",
        ((int)((timeTN - WFG3_START_DELAY)*2.0*swTilt/cos_N)));     psg_abort(1);}

      if ( (0.5*ni*cos_Ca/swTilt) > (tauCC - pwCO180 - pwCab180/2 - WFG2_START_DELAY -
           2.0*PWRF_DELAY - 2.0*POWER_DELAY - WFG2_STOP_DELAY - 4.0e-6))
      { printf (" ni is too big. Make ni equal to %d or less. \n",
        (int) ((tauCC - pwCO180 - pwCab180/2 - WFG2_START_DELAY - 2.0*PWRF_DELAY
           -2.0*POWER_DELAY - WFG2_STOP_DELAY -14.0e-6)/(0.5*cos_Ca/swTilt))); 
         psg_abort(1); }

      printf("\n\nn\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
      printf ("Maximum Sweep Width: \t\t %f Hz\n", swTilt);
      printf ("Angle_Cb:\t%6.2f\n", angle_Cb);
      printf ("Angle_Ca:\t%6.2f\n", angle_Ca);
      printf ("Angle_N :\t%6.2f\n", angle_N );
   }

/* Set up hyper complex */

   /* sw1 is used as symbolic index */
   if ( sw1 < 1000 ) { printf ("Please set sw1 to some value larger than 1000.\n"); psg_abort(1); }

   if (ix == 1) d2_init = d2;
   t1_counter = (int) ( (d2-d2_init)*sw1 + 0.5 );
   if (t1_counter % 2)  { tsadd(t8,2,4); tsadd(t12,2,4); }

   if (phase1 == 1)  { ;}                                                  /* CC */
   else if (phase1 == 2)  { tsadd(t3,3,4); tsadd(t2,3,4);}                 /* SC */
   else if (phase1 == 3)  { tsadd(t5,1,4); }                               /* CS */
   else if (phase1 == 4)  { tsadd(t3,3,4); tsadd(t2,3,4); tsadd(t5,1,4); } /* SS */
   else { printf ("phase1 can only be 1,2,3,4. \n"); psg_abort(1); }

   if (phase2 == 2)  { tsadd(t10,2,4); icosel = +1; }                      /* N  */
            else                       icosel = -1;

   tau1 = 1.0*t1_counter*cos_Cb/swTilt;
   tau2 = 1.0*t1_counter*cos_Ca/swTilt;
   tau3 = 1.0*t1_counter*cos_N/swTilt;

   tau1 = tau1/2.0;  tau2 = tau2/2.0;  tau3 = tau3/2.0;


/* BEGIN PULSE SEQUENCE */

status(A);
      delay(d1);
      if (dm3[B] == 'y') lk_hold();
      rcvroff();

      obsoffset(tof);          obspower(tpwr);       obspwrf(4095.0);
      set_c13offset("cab");    decpower(pwClvl);     decpwrf(4095.0);
      dec2power(pwNlvl);

      txphase(one);      delay(1.0e-5);
      shiftedpulse("sinc", pwHs, 90.0, 0.0, one, 2.0e-6, 0.0);

      txphase(zero);  decphase(zero); dec2phase(zero); 
      delay(2.0e-6);

/*   xxxxxxxxxxxxxxxxxxxxxx HN to N to Ca TRANSFER xxxxxxxxxxxxxxxxxx    */

   rgpulse(pw, zero, 0.0, 0.0);                   /* 1H pulse excitation */
      dec2phase(zero);
      zgradpulse(gzlvl3, gt3);                                     /* G3 */
      delay(lambda - gt3);

   sim3pulse(2.0*pw, 0.0, 2.0*pwN, zero, zero, zero, 0.0, 0.0);
      if (sel_flg[A] == 'n') txphase(three);
          else txphase(one); 
      zgradpulse(gzlvl3, gt3);                                     /* G3 */
      delay(lambda - gt3);

if (sel_flg[A] == 'n') 
{
   rgpulse(pw, three, 0.0, 0.0);
                                            
      zgradpulse(gzlvl4, gt4);                       /* Crush gradient G4 */
      delay(gstab);
                                             /* Begin of N to Ca transfer */
   dec2rgpulse(pwN, zero, 0.0, 0.0);
      delay(timeTN - WFG3_START_DELAY);
}
else  /* active suppresion */
{
   rgpulse(pw,one,2.0e-6,0.0);
                                            
      initval(1.0,v6);   dec2stepsize(45.0);   dcplr2phase(v6);
      zgradpulse(gzlvl4, gt4);                       /* Crush gradient G4 */
      delay(gstab);
                                             /* Begin of N to Ca transfer */
   dec2rgpulse(pwN,zero,0.0,0.0);
      dcplr2phase(zero);                                    /* SAPS_DELAY */
      delay(1.34e-3 - SAPS_DELAY - 2.0*pw);

      rgpulse(pw,one,0.0,0.0);
      rgpulse(2.0*pw,zero,0.0,0.0);
      rgpulse(pw,one,0.0,0.0);

      delay(timeTN -1.34e-3 - 2.0*pw - WFG3_START_DELAY);
}

   sim3_c13pulse("", "ca", "co", "square", "", 0.0, 180.0, 2.0*pwN,
                                zero, zero, zero, 2.0e-6, 2.0e-6);
      dec2phase(one);
      delay(timeTN);

   dec2rgpulse(pwN, one, 0.0, 0.0);
/*  xxxxxxxxxxxxxxxxxxxxxxxx END of N to CA TRANSFER xxxxxxxxxxxxxxxxxxxx */


      setautocal();
      set_c13offset("gly");
      if (autocal[A] == 'n')
      {
       decpower(glypwr);    
       decpwrf(4095.0);
       decphase(zero);
       decshaped_pulse(glyshp,pwgly,zero,2.0e-6,0.0);
      }
      else
      {
        if(FIRST_FID)
        {
         ppm = getval("dfrq"); bw=9*ppm;
         gly90 = pbox_make("gly90","eburp1",bw,0.0,compC*pwC,pwClvl);
                               /* Gly selective 90 with null at 50ppm */
        }
        pwgly=gly90.pw; glypwr=gly90.pwr; glypwrf=gly90.pwrf;
        decpwrf(glypwrf);
        decpower(glypwr);                           
        decshaped_pulse("gly90",pwgly,zero,2.0e-6,0.0);
      }
      zgradpulse(gzlvl5, gt5);                       /* Crush gradient G5 */
      set_c13offset("cab");
      decphase(t3);
      delay(gstab);

      if (dm3[B] == 'y')                      /*optional 2H decoupling on */
      {
         dec3unblank(); dec3rgpulse(1/dmf3, one, 0.0, 0.0); 
         dec3unblank(); setstatus(DEC3ch, TRUE, 'w', FALSE, dmf3);
      } 

/*   xxxxxxxxxxxxxxxxxxxxxx    13CA to 13CB TRANSFER   xxxxxxxxxxxxxxxxxx    */

     c13pulse("cab", "co", "square", 90.0, t3, 2.0e-6, 0.0);   
     decphase(zero);
     delay(tauCC);

     c13pulse("cab", "co", "square", 180.0, zero, 2.0e-6, 0.0); 
     decphase(t2);
     delay(tauCC - POWER_DELAY - PWRF_DELAY - PRG_START_DELAY);

/*   xxxxxxxxxxxxxxxxxxxxxx       13CB EVOLUTION       xxxxxxxxxxxxxxxxxx    */

   c13pulse("cab", "co", "square", 90.0, t2, 2.0e-6, 0.0);      /*  pwS1  */
      decphase(zero);

      if ((ni>1.0) && (tau1>0.0))
      {
         if (tau1 - 2.0*pwCab90/PI - WFG_START_DELAY - pwN - 2.0e-6
                 - PWRF_DELAY - POWER_DELAY > 0.0)
         {
            delay(tau1 - 2.0*pwCab90/PI - pwN - 2.0e-6 );

            dec2rgpulse(2.0*pwN, zero, 2.0e-6, 0.0);
            delay(tau1 - 2.0*pwS1/PI  - pwN - WFG_START_DELAY
                                - 2.0e-6 - PWRF_DELAY - POWER_DELAY);
         }
         else
         {
            tsadd(t12,2,4);
            delay(2.0*tau1);
            delay(10.0e-6);                                    /* WFG_START_DELAY */
         sim3_c13pulse("", "cab", "co", "square", "", 0.0, 180.0, 2.0*pwN, 
                     zero, zero, zero, 2.0e-6, 0.0);
            delay(10.0e-6);
         }
      }
      else
      {
         tsadd(t12,2,4);
         delay(10.0e-6);                                    /* WFG_START_DELAY */
         sim3_c13pulse("", "cab", "co", "square", "", 0.0, 180.0, 2.0*pwN, 
                        zero, zero, zero, 2.0e-6, 0.0);
         delay(10.0e-6);
      }

   decphase(t6);
   c13pulse("cab", "co", "square", 90.0, t6, 2.0e-6, 0.0);      /*  pwS1  */
  
/* xxxxxxxxxxxx  13CB to 13CA BACK TRANSFER - CA EVOLUTION  xxxxxxxxxxxxxx  */

         decphase(zero);
         delay(tau2);

      sim3_c13pulse("", "co", "ca", "sinc", "", 0.0, 180.0, 2.0*pwN,
                    zero, zero, zero, 2.0e-6, 0.0);
         decphase(zero);

         delay(tauCC- 2*pwN - pwCab180/2 - WFG2_START_DELAY - 2.0*PWRF_DELAY -
               2.0*POWER_DELAY - WFG2_STOP_DELAY - 4.0e-6 );
   c13pulse("cab", "co", "square", 180.0, zero, 2.0e-6, 0.0);

         delay(tauCC - tau2 - pwCO180 - pwCab180/2 - WFG2_START_DELAY - 2.0*PWRF_DELAY
               -2.0*POWER_DELAY - WFG2_STOP_DELAY - 4.0e-6 );

      c13pulse("co", "ca", "sinc", 180.0, zero, 2.0e-6, 0.0);
         decphase(t5);

   c13pulse("cab", "co", "square", 90.0, t5, 2.0e-6, 0.0);      /*  pwS1  */
/* xxxxxxxxxxx  END of 13CB to 13CA BACK TRANSFER - CA EVOLUTION  xxxxxxxxxxxx */
                                               
      if (dm3[B] == 'y')                        /*optional 2H decoupling off */
      {
         dec3rgpulse(1/dmf3, three, 0.0, 0.0); dec3blank();
         setstatus(DEC3ch, FALSE, 'w', FALSE, dmf3); dec3blank();
      }
      dec2phase(t8);

      zgradpulse(gzlvl6, gt6);                             /* Crush gradient G6 */
      delay(gstab);

/* xxxxxxxxxxxxxxxx  13CA to 15N BACK TRANSFER - 15N EVOLUTION  xxxxxxxxxxxxxx  */
                                             
   dec2rgpulse(pwN, t8, 2.0e-6, 2.0e-6);
      decphase(zero);
      dec2phase(t9);
      delay(timeTN - WFG3_START_DELAY - tau3);
                                                           /* WFG3_START_DELAY  */
   sim3_c13pulse("", "ca", "co", "square", "", 0.0, 180.0, 2.0*pwN,
                                             zero, zero, t9, 2.0e-6, 2.0e-6);
      dec2phase(t10);
      delay (timeTN - pwCO180 - WFG_START_DELAY - 2.0*POWER_DELAY
        - 2.0*PWRF_DELAY - 2.0e-6 - gt1 - 2.0*GRADIENT_DELAY - gstab);

      zgradpulse(gzlvl1, gt1);                     /* 2.0*GRADIENT_DELAY */
      delay(gstab - POWER_DELAY - PWRF_DELAY);

      c13pulse("co", "ca", "sinc", 180.0, zero, 2.0e-6, 0.0);          /*pwCO180*/
      delay(tau3);

   sim3pulse(pw, 0.0, pwN, zero, zero, t10, 0.0, 0.0);  /* t4??*/
      zgradpulse(gzlvl7, gt7);                                            /* G7 */
      txphase(zero);
      dec2phase(zero);
      delay (lambda - 1.3*pwN - gt7);

   sim3pulse(2.0*pw, 0.0, 2.0*pwN, zero, zero, zero, 0.0, 0.0);
      zgradpulse(gzlvl7, gt7);                                            /* G7 */
      txphase(one); 
      dec2phase(one);
      delay (lambda - 1.3*pwN - gt7);                        

   sim3pulse(pw, 0.0, pwN, one, zero, one, 0.0, 0.0);
      zgradpulse(gzlvl8, gt8);                                            /* G8 */
      txphase(zero);
      dec2phase(zero);
      delay (lambda - 1.3*pwN - gt8);

   sim3pulse(2.0*pw, 0.0, 2.0*pwN, zero, zero, zero, 0.0, 0.0);
      zgradpulse(gzlvl8, gt8);                                            /* G8 */
      delay (lambda - 1.3*pwN - gt8);

   sim3pulse(pw, 0.0, pwN, zero, zero, zero, 0.0, 0.0);
      dec2power(dpwr2);   decpower(dpwr);
      delay ( (gt1/10.0) + 1.0e-4 + 2.0*GRADIENT_DELAY + POWER_DELAY);  

   rgpulse(2.0*pw, zero, 0.0, 0.0);
      zgradpulse(icosel*gzlvl2, gt1/10.0);           /* 2.0*GRADIENT_DELAY */

statusdelay(C, 1.0e-4);
   setreceiver(t12);
   if (dm3[B] == 'y') lk_sample();
}
Esempio n. 6
0
pulsesequence()

{

/* DECLARE VARIABLES */

 char       autocal[MAXSTR],  /* auto-calibration flag */
            fsat[MAXSTR],
	    fscuba[MAXSTR],
            f1180[MAXSTR],    /* Flag to start t1 @ halfdwell             */
            f2180[MAXSTR],    /* Flag to start t2 @ halfdwell             */
            ddseq[MAXSTR],    /* deuterium decoupling sequence */
            shp_sl[MAXSTR],

            shcreb[MAXSTR],  /* reburp shape for center of t1 period */
            shcgcob[MAXSTR], /* g3 inversion at 154 ppm (350 us) */
            shcgcoib[MAXSTR],  /* g3 time inversion at 154 ppm (350 us) */
            shca180[MAXSTR],   /* Ca 180 [D/sq(3)] during 15N CT */
            shco180[MAXSTR],   /* Co 180 [D/sq(15)] during 15N CT */
            sel_flg[MAXSTR],   /* active/passive purging of undesired 
                                  component  */ 
            fCT[MAXSTR],	       /* Flag for constant time C13 evolution */
            fc180[MAXSTR],
            cal_sphase[MAXSTR],
            shared_CT[MAXSTR],
            nietl_flg[MAXSTR];

 int         phase, phase2, ni2, icosel, 
             t1_counter,   /* used for states tppi in t1           */ 
             t2_counter;   /* used for states tppi in t2           */ 

 double      tau1,         /*  t1 delay */
             tau2,         /*  t2 delay */
             taua,         /*  ~ 1/4JNH =  2.25 ms */
             del1,       /* time for C'-N to refocus set to 0.5*24.0 ms */
             bigTN,        /* nitrogen T period */
             bigTC,        /* carbon T period */
             zeta,         /* delay for transfer from ca to cb = 3.5 ms */
             tsatpwr,      /* low level 1H trans.power for presat  */
             sw1,          /* sweep width in f1                    */             
             sw2,          /* sweep width in f2                    */             
             tauf,         /* 1/2J NH value                     */
             pw_sl,        /* selective pulse on water      */
             phase_sl,     /* phase on water      */
             tpwrsl,       /* power for pw_sl               */
             at,

             d_cgcob,     /* power level for g3 pulses at 154 ppm */
             d_creb,      /* power level for reburp 180 at center of t1 */
             pwcgcob,     /* g3 ~ 35o us 180 pulse */
             pwcreb,      /* reburp ~ 400us 180 pulse */ 
 
             pwD,        /* 2H 90 pulse, about 125 us */
             pwDlvl,        /* 2H 90 pulse, about 125 us */

             pwca180,     /* Ca 180 during N CT at d_ca180 */
             pwco180,     /* Co 180 during N CT at d_co180 */

             d_ca180,
             d_co180,

             compC = getval("compC"),	/* C-13 RF calibration parameters */
             pwC = getval("pwC"),
             pwClvl = getval("pwClvl"),

             pwN,
             pwNlvl,

             sphase,

             pw_sl1,
             tpwrsl1,

             gstab,

             gt1,
             gt2,
             gt3,
             gt4,
             gt5,
             gt6,
             gt7,
             gt8,
             gt9,
             gt11,
             gt13,
             gt14,

             gzlvl1,
             gzlvl2,
             gzlvl3,
             gzlvl4,
             gzlvl5,
             gzlvl6,
             gzlvl7,
             gzlvl8,
             gzlvl9,
             gzlvl11,
             gzlvl13,
             gzlvl14;
            
/*  variables commented out are already defined by the system      */


/* LOAD VARIABLES */


  getstr("autocal",autocal);
  getstr("fsat",fsat);
  getstr("f1180",f1180);
  getstr("f2180",f2180);
  getstr("fscuba",fscuba);
  getstr("ddseq",ddseq);
  getstr("shp_sl",shp_sl);

  getstr("sel_flg",sel_flg);
  
  getstr("fCT",fCT);
  getstr("fc180",fc180);
  getstr("cal_sphase",cal_sphase);

  getstr("shared_CT",shared_CT);

  getstr("nietl_flg",nietl_flg);

  taua   = getval("taua"); 
  del1  = getval("del1");
  bigTN = getval("bigTN");
  bigTC = getval("bigTC");
  zeta = getval("zeta");
  pwN = getval("pwN");
  tpwr = getval("tpwr");
  tsatpwr = getval("tsatpwr");
  dpwr = getval("dpwr");
  pwNlvl = getval("pwNlvl");
  pwD = getval("pwD");
  pwDlvl = getval("pwDlvl");
  phase = (int) ( getval("phase") + 0.5);
  phase2 = (int) ( getval("phase2") + 0.5);
  sw1 = getval("sw1");
  sw2 = getval("sw2");
  ni2 = getval("ni2");
  tauf = getval("tauf");
  pw_sl = getval("pw_sl");
  phase_sl = getval("phase_sl");
  tpwrsl = getval("tpwrsl");
  at = getval("at");

  sphase = getval("sphase");

  pw_sl1 = getval("pw_sl1");
  tpwrsl1 = getval("tpwrsl1");

  gstab = getval("gstab");

  gt1 = getval("gt1");
  if (getval("gt2") > 0) gt2=getval("gt2");
    else gt2=gt1*0.1;
  gt3 = getval("gt3");
  gt4 = getval("gt4");
  gt5 = getval("gt5");
  gt6 = getval("gt6");
  gt7 = getval("gt7");
  gt8 = getval("gt8");
  gt9 = getval("gt9");
  gt11 = getval("gt11");
  gt13 = getval("gt13");
  gt14 = getval("gt14");

  gzlvl1 = getval("gzlvl1");
  gzlvl2 = getval("gzlvl2");
  gzlvl3 = getval("gzlvl3");
  gzlvl4 = getval("gzlvl4");
  gzlvl5 = getval("gzlvl5");
  gzlvl6 = getval("gzlvl6");
  gzlvl7 = getval("gzlvl7");
  gzlvl8 = getval("gzlvl8");
  gzlvl9 = getval("gzlvl9");
  gzlvl11 = getval("gzlvl11");
  gzlvl13 = getval("gzlvl13");
  gzlvl14 = getval("gzlvl14");

  if(autocal[0]=='n')
  {     
    getstr("shcgcob",shcgcob);
    getstr("shcgcoib",shcgcoib);
    getstr("shcreb",shcreb);
    getstr("shca180",shca180);
    getstr("shco180",shco180);
    
    d_ca180 = getval("d_ca180");
    d_co180 = getval("d_co180");
    d_cgcob = getval("d_cgcob");
    d_creb = getval("d_creb");
    pwca180 = getval("pwca180");
    pwco180 = getval("pwco180");
    pwcgcob = getval("pwcgcob");
    pwcreb = getval("pwcreb");
  }
  else
  {        
    strcpy(shcgcob,"Pg3_107p");    
    strcpy(shcgcoib,"Pg3i_107p");    
    strcpy(shcreb,"Preb_on");    
    strcpy(shca180,"Phard_15p");    
    strcpy(shco180,"Phard_133p");    
    if (FIRST_FID)  
    {
      cgcob = pbox(shcgcob, G3CGCOB, CAB180ps, dfrq, compC*pwC, pwClvl);
      cgcoib = pbox(shcgcoib, G3CGCOBi, CAB180ps, dfrq, compC*pwC, pwClvl);  
      creb = pbox(shcreb, CREB180, CAB180ps, dfrq, compC*pwC, pwClvl);      
      ca180 = pbox(shca180, CA180, CA180ps, dfrq, compC*pwC, pwClvl);        
      co180 = pbox(shco180, CO180, CA180ps, dfrq, compC*pwC, pwClvl);  
    }   
    d_ca180 = ca180.pwr;
    d_co180 = co180.pwr;
    d_cgcob = cgcob.pwr;
    d_creb = creb.pwr;
    pwca180 = ca180.pw;
    pwco180 = co180.pw;
    pwcgcob = cgcob.pw;
    pwcreb = creb.pw;
  }   

/* LOAD PHASE TABLE */

  settable(t1,2,phi1);
  settable(t2,4,phi2);
  settable(t3,8,phi3);
  settable(t4,1,phi4);
  settable(t5,16,phi5);
  settable(t6,8,phi6);
  settable(t7,1,phi7);
  settable(t8,16,rec); 

/* CHECK VALIDITY OF PARAMETER RANGES */

   if(shared_CT[A] == 'n')
    if(bigTN - 0.5*(ni2 -1)/sw2 - POWER_DELAY < 0.2e-6)
    {
        text_error(" ni2 is too big\n");
        text_error(" please set ni2 smaller or equal to %d\n",
    			(int) ((bigTN -POWER_DELAY)*sw2*2.0) +1 );
        psg_abort(1);
    }

   if(fCT[A] == 'y')
    if(bigTC - 0.5*(ni-1)/sw1 - WFG_STOP_DELAY - gt14 - 102.0e-6
        - POWER_DELAY - 4.0e-6 - pwD - POWER_DELAY - PRG_START_DELAY
        - POWER_DELAY - WFG_START_DELAY - 4.0e-6 - pwcgcob - WFG_STOP_DELAY
        - POWER_DELAY - 4.0e-6 < 0.2e-6) {

          text_error("ni is too big\n");
          text_error(" please set ni smaller or equal to %d\n",
    			(int) ((bigTC - WFG_STOP_DELAY - gt14 - 102.0e-6
        			- POWER_DELAY - 4.0e-6 - pwD - POWER_DELAY - PRG_START_DELAY
        			- POWER_DELAY - WFG_START_DELAY - 4.0e-6 - pwcgcob - WFG_STOP_DELAY
        			- POWER_DELAY - 4.0e-6)*sw1*2.0) +1 );
          psg_abort(1);
    }

    if((dm[A] == 'y' || dm[B] == 'y' || dm[C] == 'y'))
    {
        text_error("incorrect dec1 decoupler flags!  ");
        psg_abort(1);
    }

    if((dm2[A] == 'y' || dm2[B] == 'y' || dm2[C] == 'y'))
    {
        text_error("incorrect dec2 decoupler flags! Should be 'nnn' ");
        psg_abort(1);
    }

    if( tsatpwr > 6 )
    {
        text_error("TSATPWR too large !!!  ");
        psg_abort(1);
    }

    if( dpwr > 46 )
    {
        text_error("don't fry the probe, DPWR too large!  ");
        psg_abort(1);
    }

    if( dpwr2 > 47 )
    {
        text_error("don't fry the probe, DPWR2 too large!  ");
        psg_abort(1);
    }

    if( pwClvl > 63 )
    {
        text_error("don't fry the probe, pwClvl too large!  ");
        psg_abort(1);
    }

    if( pwNlvl > 63 )
    {
        text_error("don't fry the probe, pwNlvl too large!  ");
        psg_abort(1);
    }

    if( pw > 200.0e-6 )
    {
        text_error("dont fry the probe, pw too high ! ");
        psg_abort(1);
    } 
    if( pwN > 200.0e-6 )
    {
        text_error("dont fry the probe, pwN too high ! ");
        psg_abort(1);
    } 
    if( pwC > 200.0e-6 )
    {
        text_error("dont fry the probe, pwC too high ! ");
        psg_abort(1);
    } 

    if( f1180[A] != 'n' && f2180[A] != 'n' ) {
        text_error("flags may be set wrong: set f1180=n and f2180=n for 3d\n");
        psg_abort(1);
    }

    if(d_ca180 > 58) 
    {
        text_error("dont fry the probe, d_ca180 too high ! ");
        psg_abort(1);
    }

    if(d_co180 > 58) 
    {
        text_error("dont fry the probe, d_ca180 too high ! ");
        psg_abort(1);
    }

    if( gt1 > 15e-3 || gt2 > 15e-3 || gt3 > 15e-3 
        || gt4 > 15e-3 || gt5 > 15e-3 || gt6 > 15e-3 
        || gt7 > 15e-3 || gt8 > 15e-3 || gt9 > 15e-3 
        || gt11 > 15e-3 || gt13 > 15e-3  
        || gt14 > 15e-3)
    {
       text_error("gti values must be < 15e-3\n");
       psg_abort(1);
    } 

    if(tpwrsl > 25) {
       text_error("tpwrsl must be less than 25\n");
       psg_abort(1);
    }

    if(tpwrsl1 > 25) {
       text_error("tpwrsl1 must be less than 25\n");
       psg_abort(1);
    }

    if( dpwr3 > 50) {
       text_error("dpwr3 too high\n");
       psg_abort(1);
    }
    if( del1 > 0.1 ) {
       text_error("too long del1\n");
       psg_abort(1);
    }
    if( zeta > 0.1 ) {
       text_error("too long zeta\n");
       psg_abort(1);
    }
    if( bigTN > 0.1) {
       text_error("too long bigTN\n");
       psg_abort(1);
    }
    if( bigTC > 0.1) {
       text_error("too long bigTC\n");
       psg_abort(1);
    }
    if( pw_sl > 10e-3) {
       text_error("too long pw_sl\n");
       psg_abort(1);
    }
    if( pw_sl1 > 10e-3) {
       text_error("too long pw_sl1\n");
       psg_abort(1);
    }
    if( at > 0.1 && dm2[D] == 'y') {
       text_error("too long at with dec2\n");
       psg_abort(1);
    }

    if(pwDlvl > 59) {
        text_error("pwDlvl is too high; <= 59\n");
        psg_abort(1);
    }

    if(d_creb > 62) {
        text_error("d_creb is too high; <= 62\n");
        psg_abort(1);
    }

    if(d_cgcob > 60) {
        text_error("d_cgcob is too high; <=60\n");
        psg_abort(1);
    }

    if(cal_sphase[A] == 'y') {
      text_error("Use only to calibrate sphase\n");
      text_error("Set zeta to 600 us, gt11=gt13=0, fCT=y, fc180=n\n");
    }

    if(nietl_flg[A] == 'y' && sel_flg[A] == 'y') {
       text_error("Both nietl_flg and sel_flg cannot by y\n");
       psg_abort(1);
    }

    if (fCT[A] == 'n' && fc180[A] =='y' && ni > 1.0) {
       text_error("must set fc180='n' to allow Calfa/Cbeta evolution (ni>1)\n");
       psg_abort(1);
   }


/*  Phase incrementation for hypercomplex 2D data */

    /* changed from 1 to 3; spect. rev. not needed */
    if (phase == 2) { tsadd(t2,3,4); tsadd(t3,3,4); }

    if (shared_CT[A] == 'n') 
      {
       if (phase2 == 2) { tsadd(t7,2,4); icosel = 1; }
         else icosel = -1;
      }
     else 
      {
       if (phase2 == 2) { tsadd(t7,2,4); icosel = -1; }
         else icosel = 1;
      }

    if (nietl_flg[A] == 'y') icosel = -1*icosel;

/* Calculate modifications to phases for States-TPPI acquisition          */

   if( ix == 1) d2_init = d2 ;
   t1_counter = (int) ( (d2-d2_init)*sw1 + 0.5 );
   if(t1_counter % 2) {
      tsadd(t2,2,4);     
      tsadd(t8,2,4);    
    }

   if( ix == 1) d3_init = d3 ;
   t2_counter = (int) ( (d3-d3_init)*sw2 + 0.5 );
   if(t2_counter % 2) {
      tsadd(t5,2,4);  
      tsadd(t8,2,4);    
    }

/*  Set up f1180  tau1 = t1         */

      tau1 = d2;
      if(f1180[A] == 'y' && fCT[A] == 'y') 
          tau1 += ( 1.0 / (2.0*sw1) );

      if(f1180[A] == 'y' && fCT[A] == 'n') 
          tau1 += (1.0 / (2.0*sw1) - 4.0/PI*pwC - POWER_DELAY
                    - 4.0e-6);

      if(f1180[A] == 'n' && fCT[A] == 'n') 
          tau1 = (tau1 - 4.0/PI*pwC - POWER_DELAY
                    - 4.0e-6);

      if(tau1 < 0.2e-6) tau1 = 4.0e-7; 
      tau1 = tau1/2.0;

/*  Set up f2180  tau2 = t2         */

    tau2 = d3;
    if(f2180[A] == 'y') {
        tau2 += ( 1.0 / (2.0*sw2) ); 
        if(tau2 < 0.2e-6) tau2 = 0.2e-6;
    }
        tau2 = tau2/2.0;

/* BEGIN ACTUAL PULSE SEQUENCE */

status(A);
   obspower(tsatpwr);     /* Set transmitter power for 1H presaturation */
   decpower(pwClvl);      /* Set Dec1 power to high power          */
   dec2power(pwNlvl);     /* Set Dec2 power for 15N hard pulses         */
   dec3power(pwDlvl);     /* Set Dec3 for 2H hard pulses */

/* Presaturation Period */

   if (fsat[0] == 'y')
     {
      delay(2.0e-5);
      rgpulse(d1,zero,0.0,2.0e-6);
      obspower(tpwr);      /* Set transmitter power for hard 1H pulses */
      delay(2.0e-5);
      if (fscuba[0] == 'y')
	{
	 delay(2.2e-2);
	 rgpulse(pw,zero,2.0e-6,0.0);
	 rgpulse(2*pw,one,2.0e-6,0.0);
	 rgpulse(pw,zero,2.0e-6,0.0);
	 delay(2.2e-2);
        }
     }
    else
     {
      delay(d1);
     }
   obspower(tpwr);           /* Set transmitter power for hard 1H pulses */
   txphase(zero);
   dec2phase(zero);
   delay(1.0e-5);

/* Begin Pulses */

status(B);

   rcvroff();
   lk_hold();
   delay(20.0e-6);

   rgpulse(pw,zero,0.0,0.0);                    /* 90 deg 1H pulse */

   delay(0.2e-6);
   zgradpulse(gzlvl5,gt5);
   delay(2.0e-6);

   delay(taua - gt5 - 2.2e-6);   /* taua <= 1/4JNH */ 

   sim3pulse(2*pw,0.0,2*pwN,zero,zero,zero,0.0,0.0);

   dec2phase(t1); decphase(zero); 

   delay(taua - gt5 - 200.2e-6); 

   delay(0.2e-6);
   zgradpulse(gzlvl5,gt5);
   delay(200.0e-6);

   if (sel_flg[A] == 'y') 
     {
      rgpulse(pw,one,4.0e-6,0.0);

      initval(1.0,v2);
      obsstepsize(phase_sl);
      xmtrphase(v2);

      /* shaped pulse */
      obspower(tpwrsl);
      shaped_pulse(shp_sl,pw_sl,two,2.0e-6,0.0);
      xmtrphase(zero);
      delay(2.0e-6);
      obspower(tpwr);
      /* shaped pulse */

      initval(1.0,v6);
      dec2stepsize(45.0);
      dcplr2phase(v6);

      delay(0.2e-6);
      zgradpulse(gzlvl3,gt3);
      delay(200.0e-6);

      dec2rgpulse(pwN,t1,0.0,0.0);
      dcplr2phase(zero);

      delay(1.34e-3 - SAPS_DELAY);
   
      rgpulse(pw,zero,0.0,0.0);
      rgpulse(2.0*pw,one,2.0e-6,0.0);
      rgpulse(pw,zero,2.0e-6,0.0);

      decpower(d_ca180);

        dec2phase(zero);
   
        delay(del1 - 1.34e-3 - 4.0*pw - 4.0e-6 
              - POWER_DELAY + WFG_START_DELAY + pwca180 + WFG_STOP_DELAY);
     }
    else  
     {
      rgpulse(pw,three,4.0e-6,0.0);

      initval(1.0,v2);
      obsstepsize(phase_sl);
      xmtrphase(v2);
   
      /* shaped pulse */
      obspower(tpwrsl);
      shaped_pulse(shp_sl,pw_sl,zero,2.0e-6,0.0);
      xmtrphase(zero);
      delay(2.0e-6);
      obspower(tpwr);
      /* shaped pulse */
   
      delay(0.2e-6);
      zgradpulse(gzlvl3,gt3);
      delay(200.0e-6);

      dec2rgpulse(pwN,t1,0.0,0.0);
      dec2phase(zero);

      decpower(d_ca180);

      delay(del1 - POWER_DELAY + WFG_START_DELAY
      		+ pwca180 + WFG_STOP_DELAY);
     }

   decphase(zero);
   dec2rgpulse(2*pwN,zero,0.0,0.0);
   decshaped_pulse(shca180,pwca180,zero,0.0,0.0);

   dec2phase(one);

   delay(del1);

   dec2rgpulse(pwN,one,0.0,0.0);

   decpower(pwClvl);

   decphase(t2); 

   delay(0.2e-6);
   zgradpulse(gzlvl4,gt4);
   delay(200.0e-6);

   dec2phase(t5); 

   /* Turn on D decoupling using the third decoupler */
   dec3phase(one);
   dec3power(pwDlvl);
   dec3rgpulse(pwD,one,4.0e-6,0.0);
   dec3phase(zero);
   dec3power(dpwr3);
   dec3unblank();
   setstatus(DEC3ch, TRUE, 'w', FALSE, dmf3);
   /* Turn on D decoupling */

   decrgpulse(pwC,t2,0.0,0.0);

   delay(zeta
	- PRG_STOP_DELAY - DELAY_BLANK - POWER_DELAY - 4.0e-6
        - pwD
        - gt11 - 102.0e-6 - POWER_DELAY - WFG_START_DELAY); 
      
   /* Turn off D decoupling */
   setstatus(DEC3ch, FALSE, 'c', FALSE, dmf3);
   dec3blank(); 
   dec3phase(three);
   dec3power(pwDlvl);
   dec3rgpulse(pwD,three,4.0e-6,0.0);
   /* Turn off D decoupling */

    decphase(zero);

   delay(2.0e-6);
   zgradpulse(gzlvl11,gt11);
   delay(100.0e-6);

   if (cal_sphase[A] == 'y') 
     {
      decpower(pwClvl);
      decshaped_pulse("hard",2.0*pwC,zero,4.0e-6,4.0e-6);
     }
    else 
     {
      initval(1.0,v3);
      decstepsize(sphase);
      dcplrphase(v3);
      decpower(d_creb);
      decshaped_pulse(shcreb,pwcreb,zero,4.0e-6,4.0e-6);
      dcplrphase(zero);
     }

   delay(2.0e-6);
   zgradpulse(gzlvl11,gt11);
   delay(100.0e-6);

   /* Turn on D decoupling using the third decoupler */
   dec3phase(one);
   dec3power(pwDlvl);
   dec3rgpulse(pwD,one,4.0e-6,0.0);
   dec3phase(zero);
   dec3power(dpwr3);
   dec3unblank();
   setstatus(DEC3ch, TRUE, 'w', FALSE, dmf3);
   /* Turn on D decoupling */

   delay(zeta - WFG_STOP_DELAY - gt11 - 102.0e-6 
	- POWER_DELAY - 4.0e-6 - pwD - POWER_DELAY - PRG_START_DELAY
        - DELAY_BLANK - POWER_DELAY - 4.0e-6);

   decpower(pwClvl);
   decrgpulse(pwC,t3,4.0e-6,0.0);

   if (fCT[A] == 'y') 
     {
      delay(tau1);

      decpower(d_cgcob);
      decshaped_pulse(shcgcob,pwcgcob,zero,4.0e-6,0.0);

      delay(bigTC - POWER_DELAY - WFG_START_DELAY - 4.0e-6
            - pwcgcob - WFG_STOP_DELAY 
            - 102.0e-6 - gt14 
            - PRG_STOP_DELAY - DELAY_BLANK
            - POWER_DELAY - 4.0e-6 - pwD - POWER_DELAY - WFG_START_DELAY);
 
      /* Turn off D decoupling */
      setstatus(DEC3ch, FALSE, 'c', FALSE, dmf3);
      dec3blank();
      dec3phase(three);
      dec3power(pwDlvl);
      dec3rgpulse(pwD,three,4.0e-6,0.0);
      /* Turn off D decoupling */

      delay(2.0e-6);
      zgradpulse(gzlvl14,gt14);
      delay(100.0e-6);

      initval(1.0,v4);
      decstepsize(sphase);
      dcplrphase(v4);
      decpower(d_creb);
      decshaped_pulse(shcreb,pwcreb,zero,4.0e-6,4.0e-6);
      dcplrphase(zero);
    
      delay(2.0e-6);
      zgradpulse(gzlvl14,gt14);
      delay(100.0e-6);

      /* Turn on D decoupling using the third decoupler */
      dec3phase(one);
      dec3power(pwDlvl);
      dec3rgpulse(pwD,one,4.0e-6,0.0);
      dec3phase(zero);
      dec3power(dpwr3);
      dec3unblank(); 
      setstatus(DEC3ch, TRUE, 'w', FALSE, dmf3);
      /* Turn on D decoupling */


      delay(bigTC - tau1 - WFG_STOP_DELAY - gt14
            - 102.0e-6 - POWER_DELAY - 4.0e-6 - pwD - POWER_DELAY
            - PRG_START_DELAY - POWER_DELAY - WFG_START_DELAY
            - 4.0e-6 - pwcgcob - WFG_STOP_DELAY - POWER_DELAY 
            - 4.0e-6);

      decpower(d_cgcob);
      decshaped_pulse(shcgcoib,pwcgcob,zero,4.0e-6,0.0);
      decphase(t4);
     }
    else if(fCT[A] == 'n' && fc180[A] == 'n') 
     {
      delay(tau1);
      delay(tau1);
     }
    else if(fCT[A] == 'n' && fc180[A] == 'y') 
     {
      initval(1.0,v4);
      decstepsize(sphase);
      dcplrphase(v4);

      decpower(d_creb);
      decshaped_pulse(shcreb,pwcreb,zero,4.0e-6,0.0);

      dcplrphase(zero);
     }

   decpower(pwClvl);
   decrgpulse(pwC,t4,4.0e-6,0.0);

   delay(zeta - POWER_DELAY - 4.0e-6
          - pwD - PRG_STOP_DELAY - DELAY_BLANK
          - gt13
          - 102.0e-6 - POWER_DELAY - WFG_START_DELAY); 

   /* Turn off D decoupling */
   setstatus(DEC3ch, FALSE, 'c', FALSE, dmf3);
   dec3blank(); 
   dec3power(pwDlvl);
   dec3rgpulse(pwD,three,4.0e-6,0.0);
   /* Turn off D decoupling */

   delay(2.0e-6);
   zgradpulse(gzlvl13,gt13);
   delay(100.0e-6);

   if (cal_sphase[A] == 'y') 
     {
      decpower(pwClvl);
      decshaped_pulse("hard",2.0*pwC,zero,4.0e-6,4.0e-6);
     }
    else 
     {
      initval(1.0,v5);
      decstepsize(sphase);
      dcplrphase(v5);
      decpower(d_creb);
      decshaped_pulse(shcreb,pwcreb,zero,4.0e-6,4.0e-6);
      dcplrphase(zero);
     }

   delay(2.0e-6);
   zgradpulse(gzlvl13,gt13);
   delay(100.0e-6);

   /* Turn on D decoupling using the third decoupler */
   dec3phase(one);
   dec3power(pwDlvl);
   dec3rgpulse(pwD,one,4.0e-6,0.0);
   dec3phase(zero);
   dec3power(dpwr3);
   dec3unblank();
   setstatus(DEC3ch, TRUE, 'w', FALSE, dmf3);
   /* Turn on D decoupling */


   delay(zeta - WFG_STOP_DELAY - gt13 - 102.0e-6  
        - POWER_DELAY - 4.0e-6 - pwD - POWER_DELAY
        - PRG_START_DELAY - DELAY_BLANK
        - POWER_DELAY - 4.0e-6);

   decpower(pwClvl);
   decrgpulse(pwC,zero,4.0e-6,0.0);

   /* Turn off D decoupling */
   setstatus(DEC3ch, FALSE, 'c', FALSE, dmf3);
   dec3blank();
   dec3phase(three);
   dec3power(pwDlvl);
   dec3rgpulse(pwD,three,4.0e-6,0.0);
   /* Turn off D decoupling */

   delay(0.2e-6);
   zgradpulse(gzlvl9,gt9);
   delay(200.0e-6);

   if (shared_CT[A] == 'n') 
     {
      dec2rgpulse(pwN,t5,2.0e-6,0.0);

      decpower(d_ca180);

      dec2phase(t6); 

      delay(bigTN - tau2 - POWER_DELAY);

      dec2rgpulse(2*pwN,t6,0.0,0.0);
      decshaped_pulse(shca180,pwca180,zero,0.0,0.0);
      dec2phase(t7);

      delay(bigTN - WFG_START_DELAY - pwca180 - WFG_STOP_DELAY
            - gt1 - 2.0*GRADIENT_DELAY - 500.2e-6 
            - POWER_DELAY - 4.0e-6 - WFG_START_DELAY
            - pwco180 - WFG_STOP_DELAY);

      delay(0.2e-6);
      zgradpulse(gzlvl1,gt1);
      delay(500.0e-6);

      decpower(d_co180);
      decshaped_pulse(shco180,pwco180,zero,4.0e-6,0.0);

      delay(tau2);
   
      sim3pulse(pw,0.0,pwN,zero,zero,t7,0.0,0.0);
     }
    else if (shared_CT[A] == 'y') 
     {
      dec2rgpulse(pwN,t5,2.0e-6,0.0);

      decpower(d_co180);
      dec2phase(t6); 

      if (bigTN - tau2 >= 0.2e-6) 
        {
         delay(tau2);

         decshaped_pulse(shco180,pwco180,zero,4.0e-6,0.0);
         decpower(d_ca180);

         delay(0.2e-6);
         zgradpulse(gzlvl1,gt1);
         delay(500.0e-6);

         delay(bigTN - 4.0e-6 - WFG_START_DELAY - pwco180 - WFG_STOP_DELAY
               - POWER_DELAY - gt1 - 500.2e-6 - 2.0*GRADIENT_DELAY
               - WFG_START_DELAY - pwca180 - WFG_STOP_DELAY);

         decshaped_pulse(shca180,pwca180,zero,0.0,0.0);
         dec2rgpulse(2*pwN,t6,0.0,0.0);

         delay(bigTN - tau2);
        }
       else 
        {
         delay(tau2);
         decshaped_pulse(shco180,pwco180,zero,4.0e-6,0.0);

         delay(0.2e-6);
         zgradpulse(gzlvl1,gt1);
         delay(500.0e-6);
     
         decpower(d_ca180);
         delay(bigTN - 4.0e-6 - WFG_START_DELAY - pwco180
               - WFG_STOP_DELAY - gt1 - 500.2e-6 - 2.0*GRADIENT_DELAY
               - POWER_DELAY - WFG_START_DELAY - pwca180 - WFG_STOP_DELAY); 
   
         decshaped_pulse(shca180,pwca180,zero,0.0,0.0);
    
         delay(tau2 - bigTN);
         dec2rgpulse(2.0*pwN,t6,0.0,0.0);
        }
      sim3pulse(pw,0.0,pwN,zero,zero,t7,0.0,0.0);
     }
/* end of shared_CT */

   if (nietl_flg[A] == 'n') 
     {
      decpower(pwClvl);
      decrgpulse(pwC,zero,4.0e-6,0.0);

      delay(0.2e-6);
      zgradpulse(gzlvl6,gt6);
      delay(2.0e-6);

      dec2phase(zero);
      delay(tauf - POWER_DELAY - 4.0e-6 
                 - pwC - gt6 - 2.2e-6);

      sim3pulse(2*pw,0.0,2*pwN,zero,zero,zero,0.0,0.0);

      txphase(one);
      dec2phase(one);
   
      delay(tauf - gt6 - 200.2e-6);

      delay(0.2e-6);
      zgradpulse(gzlvl6,gt6);
      delay(200.0e-6);

      sim3pulse(pw,0.0,pwN,one,zero,one,0.0,0.0);
      
      delay(0.2e-6);
      zgradpulse(gzlvl7,gt7);
      delay(2.0e-6);
 
      txphase(zero);
      dec2phase(zero);
      delay(tauf - gt7 - 2.2e-6);

      sim3pulse(2*pw,0.0,2*pwN,zero,zero,zero,0.0,0.0);

      delay(tauf - gt7 - 200.2e-6);

      delay(0.2e-6);
      zgradpulse(gzlvl7,gt7);
      delay(200.0e-6);
   
      sim3pulse(pw,0.0e-6,pwN,zero,zero,zero,0.0,0.0);
     }
    else  
     {   /* nietl_flg == y */
      /* shaped pulse */
      obspower(tpwrsl1);
      shaped_pulse(shp_sl,pw_sl1,zero,2.0e-6,0.0);
      delay(2.0e-6);
      obspower(tpwr);
      /* shaped pulse */

      decpower(pwClvl);
      decrgpulse(pwC,zero,4.0e-6,0.0);

      delay(0.2e-6);
      zgradpulse(gzlvl6,gt6);
      delay(2.0e-6);
   
      dec2phase(zero);
      delay(tauf 
                 - POWER_DELAY - 2.0e-6 - WFG_START_DELAY
                 - pw_sl1 - WFG_STOP_DELAY - 2.0e-6 - POWER_DELAY
                 - POWER_DELAY - 4.0e-6 
                 - pwC - gt6 - 2.2e-6);

      sim3pulse(2*pw,0.0,2*pwN,zero,zero,zero,0.0,0.0);

      txphase(one);
      dec2phase(zero);

      delay(tauf - gt6 - 200.2e-6);

      delay(0.2e-6);
      zgradpulse(gzlvl6,gt6);
      delay(200.0e-6);

      sim3pulse(pw,0.0,pwN,one,zero,zero,0.0,0.0);
   
      delay(0.2e-6);
      zgradpulse(gzlvl7,gt7);
      delay(2.0e-6);
 
      txphase(zero);
      dec2phase(zero);
      delay(tauf - gt7 - 2.2e-6);

      sim3pulse(2*pw,0.0,2*pwN,zero,zero,zero,0.0,0.0);
      txphase(one);
      dec2phase(one);
   
      delay(tauf - gt7 - 200.2e-6);

      delay(0.2e-6);
      zgradpulse(gzlvl7,gt7);
      delay(200.0e-6);
   
      sim3pulse(pw,0.0e-6,pwN,one,zero,one,0.0,0.0);
      txphase(zero);
     }  /* end of nietl_flg == y  */

   delay(gt2 +gstab -0.5*(pwN-pw) -2.0*pw/PI);

   rgpulse(2*pw,zero,0.0,0.0);

   delay(2.0e-6);
   zgradpulse(icosel*gzlvl2,gt2);
   decpower(dpwr);    /* NO  13C decoupling */
   dec2power(dpwr2);  /* NO  15N decoupling */
   delay(gstab -2.0e-6 -2.0*GRADIENT_DELAY -2.0*POWER_DELAY);

   lk_sample();
/* BEGIN ACQUISITION */
status(C);
   setreceiver(t8);

}
Esempio n. 7
0
pulsesequence()

{

    /* DECLARE VARIABLES */

    char       autocal[MAXSTR],  /* auto-calibration flag */
               fsat[MAXSTR],
               fscuba[MAXSTR],
               f1180[MAXSTR],    /* Flag to start t1 @ halfdwell             */
               f2180[MAXSTR],    /* Flag to start t2 @ halfdwell             */
               fc180[MAXSTR],    /* Flag for checking sequence               */
               ddseq[MAXSTR],    /* deuterium decoupling sequence */
               spcosed[MAXSTR],  /* waveform Co seduce 180 */
               spcareb[MAXSTR],  /* waveform Ca reburp 180 */
               spca180[MAXSTR],  /* waveform Ca hard 180   */
               sel_flg[MAXSTR],
               shp_sl[MAXSTR],
               cacb_dec[MAXSTR],
               cacbdecseq[MAXSTR],
               nietl_flg[MAXSTR];

    int         phase, phase2, ni, icosel,
                t1_counter,   /* used for states tppi in t1           */
                t2_counter;   /* used for states tppi in t2           */

    double      tau1,         /*  t1 delay */
                tau2,         /*  t2 delay */
                taua,         /*  ~ 1/4JNH =  2.25 ms */
                taub,         /*  ~ 1/4JNH =  2.25 ms */
                tauc,         /*  ~ 1/4JNCa =  ~13 ms */
                taud,         /*  ~ 1/4JCaC' =  3~4.5 ms ms */
                bigTN,        /* nitrogen T period */
                pwc90,       /* PW90 for ca nucleus @ d_c90         */
                pwca180,      /* PW180 for ca nucleus @ d_c180         */
                pwca180dec,   /* pwca180+pad         */
                pwcareb,      /* pw180 at d_creb  ~ 1.6 ms at 600 MHz */
                pwcosed,      /* PW180 at d_csed  ~ 200us at 600 MHz  */
                tsatpwr,      /* low level 1H trans.power for presat  */
                d_c90,        /* power level for 13C pulses(pwc90=sqrt(15)/4delta
			      delta is the separation between Ca and Co */
                d_c180,	   /* power level for pwca180(sqrt(3)/2delta) */
                d_creb,	   /* power level for pwcareb */
                d_csed,       /* power level for pwcosed */
                sw1,          /* sweep width in f1                    */
                sw2,          /* sweep width in f2                    */
                pw_sl,        /* selective pulse on water      */
                tpwrsl,       /* power for pw_sl               */
                at,
                sphase,	   /* small angle phase shift  */
                sphase1,
                phase_sl,

                d_cacbdec,
                pwcacbdec,
                dres_dec,

                pwD,          /* PW90 for higher power (pwDlvl) deut 90 */
                pwDlvl,       /* high power for deut 90 hard pulse */

                compC,       /* C-13 RF calibration parameters */
                pwC,
                pwClvl,

                pwN,          /* PW90 for 15N pulse              */
                pwNlvl,       /* high dec2 pwr for 15N hard pulses    */

                gstab,

                gt1,
                gt2,
                gt3,
                gt4,
                gt5,
                gt6,
                gt7,
                gt8,
                gt9,
                gt10,

                gzlvl1,
                gzlvl2,
                gzlvl3,
                gzlvl4,
                gzlvl5,
                gzlvl6,
                gzlvl7,
                gzlvl8,
                gzlvl9,
                gzlvl10;

    /* LOAD VARIABLES */

    getstr("autocal",autocal);
    getstr("fsat",fsat);
    getstr("f1180",f1180);
    getstr("f2180",f2180);
    getstr("fc180",fc180);
    getstr("fscuba",fscuba);
    getstr("ddseq",ddseq);
    getstr("shp_sl",shp_sl);
    getstr("sel_flg",sel_flg);
    getstr("cacb_dec",cacb_dec);

    getstr("nietl_flg",nietl_flg);

    taua   = getval("taua");
    taub   = getval("taub");
    tauc   = getval("tauc");
    taud   = getval("taud");
    bigTN = getval("bigTN");
    pwN = getval("pwN");
    tpwr = getval("tpwr");
    tsatpwr = getval("tsatpwr");
    dpwr = getval("dpwr");
    pwNlvl = getval("pwNlvl");
    pwD = getval("pwD");
    pwDlvl = getval("pwDlvl");
    phase = (int) ( getval("phase") + 0.5);
    phase2 = (int) ( getval("phase2") + 0.5);
    sw1 = getval("sw1");
    sw2 = getval("sw2");
    ni = getval("ni");
    pw_sl = getval("pw_sl");
    tpwrsl = getval("tpwrsl");
    at = getval("at");
    sphase = getval("sphase");
    sphase1 = getval("sphase1");
    phase_sl = getval("phase_sl");

    gstab = getval("gstab");

    gt1 = getval("gt1");
    if (getval("gt2") > 0) gt2=getval("gt2");
    else gt2=gt1*0.1;
    gt3 = getval("gt3");
    gt4 = getval("gt4");
    gt5 = getval("gt5");
    gt6 = getval("gt6");
    gt7 = getval("gt7");
    gt8 = getval("gt8");
    gt9 = getval("gt9");
    gt10 = getval("gt10");

    gzlvl1 = getval("gzlvl1");
    gzlvl2 = getval("gzlvl2");
    gzlvl3 = getval("gzlvl3");
    gzlvl4 = getval("gzlvl4");
    gzlvl5 = getval("gzlvl5");
    gzlvl6 = getval("gzlvl6");
    gzlvl7 = getval("gzlvl7");
    gzlvl8 = getval("gzlvl8");
    gzlvl9 = getval("gzlvl9");
    gzlvl10 = getval("gzlvl10");


    if(autocal[0]=='n')
    {
        getstr("spcosed",spcosed);
        getstr("spcareb",spcareb);
        getstr("spca180",spca180);
        getstr("cacbdecseq",cacbdecseq);

        d_c90 = getval("d_c90");
        d_c180 = getval("d_c180");
        d_creb = getval("d_creb");
        d_csed = getval("d_csed");

        pwc90 = getval("pwc90");
        pwca180 = getval("pwca180");
        pwca180dec = getval("pwca180dec");
        pwcareb = getval("pwcareb");
        pwcosed = getval("pwcosed");

        d_cacbdec = getval("d_cacbdec");
        pwcacbdec = getval("pwcacbdec");
        dres_dec = getval("dres_dec");
    }
    else
    {
        strcpy(spcosed,"Phard_118p");
        strcpy(spcareb,"Preburp_-15p");
        strcpy(spca180,"Phard_-118p");
        strcpy(cacbdecseq,"Pcb_dec");
        if (FIRST_FID)
        {
            compC = getval("compC");
            pwC = getval("pwC");
            pwClvl = getval("pwClvl");
            co180 = pbox(spcosed, CO180, CA180ps, dfrq, compC*pwC, pwClvl);
            creb = pbox(spcareb, CREB180, CAB180ps, dfrq, compC*pwC, pwClvl);
            ca180 = pbox(spca180, CA180, CA180ps, dfrq, compC*pwC, pwClvl);
            cbdec = pbox(cacbdecseq, CBDEC,CBDECps, dfrq, compC*pwC, pwClvl);
            c90 = pbox("Phard90", C90, CA180ps, dfrq, compC*pwC, pwClvl);
        }
        d_c90 = c90.pwr;
        d_c180 = ca180.pwr;
        d_creb = creb.pwr;
        d_csed = co180.pwr;
        pwc90 = c90.pw;
        pwca180 = ca180.pw;
        pwca180dec = ca180.pw;
        pwcareb = creb.pw;
        pwcosed = co180.pw;

        d_cacbdec = cbdec.pwr;
        pwcacbdec = 1.0/cbdec.dmf;
        dres_dec = cbdec.dres;
    }

    /* LOAD PHASE TABLE */

    settable(t1,2,phi1);
    settable(t2,4,phi2);
    settable(t3,8,phi3);
    settable(t4,2,phi4);
    settable(t5,1,phi5);
    settable(t6,8,rec);

    /* CHECK VALIDITY OF PARAMETER RANGES */

    if(ix==1)
        printf("Uses shared AT in the N dimension. Choose ni2 as desired\n");


    if((dm[A] == 'y' || dm[B] == 'y' || dm[C] == 'y' ))
    {
        printf("incorrect dec1 decoupler flags!  ");
        psg_abort(1);
    }

    if((dm2[A] == 'y' || dm2[B] == 'y' || dm2[C] == 'y'))
    {
        printf("incorrect dec2 decoupler flags! Should be 'nnn' ");
        psg_abort(1);
    }


    if( tsatpwr > 6 )
    {
        printf("TSATPWR too large !!!  ");
        psg_abort(1);
    }

    if( dpwr > -16 )
    {
        printf("DPWR too large!  ");
        psg_abort(1);
    }

    if( dpwr2 > -16 )
    {
        printf("DPWR2 too large!  ");
        psg_abort(1);
    }

    if( pw > 200.0e-6 )
    {
        printf("dont fry the probe, pw too high ! ");
        psg_abort(1);
    }

    if( pwN > 200.0e-6 )
    {
        printf("dont fry the probe, pwN too high ! ");
        psg_abort(1);
    }

    if( gt1 > 3e-3 || gt2 > 3e-3 || gt3 > 3e-3
            || gt4 > 3e-3 || gt5 > 3e-3 || gt6 > 3e-3
            || gt7 > 3e-3 || gt8 > 3e-3 || gt9 > 3e-3 || gt10 > 3e-3)
    {
        printf("gti values must be < 3e-3\n");
        psg_abort(1);
    }

    if(tpwrsl > 30) {
        printf("tpwrsl must be less than 25\n");
        psg_abort(1);
    }

    if( pwDlvl > 59) {
        printf("pwDlvl too high\n");
        psg_abort(1);
    }

    if( dpwr3 > 50) {
        printf("dpwr3 too high\n");
        psg_abort(1);
    }

    if( pw_sl > 10e-3) {
        printf("too long pw_sl\n");
        psg_abort(1);
    }

    if(d_cacbdec > 40) {
        printf("d_cacbdec is too high; < 41\n");
        psg_abort(1);
    }

    if(nietl_flg[A] == 'y' && sel_flg[A] == 'y') {
        printf("nietl_flg and sel_flg cannot both be y\n");
        psg_abort(1);
    }

    if (fc180[A] =='y' && ni > 1.0) {
        text_error("must set fc180='n' to allow C' evolution (ni>1)\n");
        psg_abort(1);
    }


    /*  Phase incrementation for hypercomplex 2D data */

    if (phase == 2) tsadd(t2,1,4);

    if (phase2 == 2) {
        tsadd(t5,2,4);
        icosel = 1;
    }
    else icosel = -1;

    if (nietl_flg[A] == 'y') icosel = -1*icosel;

    /*  Set up f1180  tau2 = t1               */

    tau1 = d2;
    if(f1180[A] == 'y') {
        tau1 += ( 1.0 / (2.0*sw1)
                  - 4.0/PI*pwc90 - POWER_DELAY - 4.0e-6 - WFG_START_DELAY
                  - pwca180dec - WFG_STOP_DELAY - 2.0*pwN - POWER_DELAY
                  - 4.0e-6);
    }

    if(f1180[A] == 'n')
        tau1 = ( tau1
                 - 4.0/PI*pwc90 - POWER_DELAY - 4.0e-6 - WFG_START_DELAY
                 - pwca180dec - WFG_STOP_DELAY - 2.0*pwN - POWER_DELAY
                 - 4.0e-6);

    if(tau1 < 0.2e-6) tau1 = 0.2e-6;
    tau1 = tau1/2.0;

    /*  Set up f2180  tau2 = t2               */

    tau2 = d3;
    if(f2180[A] == 'y') {
        tau2 += ( 1.0 / (2.0*sw2) );
        if(tau2 < 0.2e-6) tau2 = 0.2e-6;
    }
    tau2 = tau2/2.0;

    /* Calculate modifications to phases for States-TPPI acquisition          */

    if( ix == 1) d2_init = d2 ;
    t1_counter = (int) ( (d2-d2_init)*sw1 + 0.5 );
    if(t1_counter % 2) {
        tsadd(t2,2,4);
        tsadd(t6,2,4);
    }

    if( ix == 1) d3_init = d3 ;
    t2_counter = (int) ( (d3-d3_init)*sw2 + 0.5 );
    if(t2_counter % 2) {
        tsadd(t3,2,4);
        tsadd(t6,2,4);
    }

    /* BEGIN ACTUAL PULSE SEQUENCE */

    status(A);
    obspower(tsatpwr);     /* Set transmitter power for 1H presaturation */
    decpower(d_c180);       /* Set Dec1 power to high power          */
    dec2power(pwNlvl);     /* Set Dec2 power for 15N hard pulses         */
    decoffset(dof);


    /* Presaturation Period */

    if (fsat[0] == 'y')
    {
        delay(2.0e-5);
        rgpulse(d1,zero,2.0e-6,2.0e-6);
        obspower(tpwr);      /* Set transmitter power for hard 1H pulses */
        delay(2.0e-5);
        if(fscuba[0] == 'y')
        {
            delay(2.2e-2);
            rgpulse(pw,zero,2.0e-6,0.0);
            rgpulse(2*pw,one,2.0e-6,0.0);
            rgpulse(pw,zero,2.0e-6,0.0);
            delay(2.2e-2);
        }
    }
    else
    {
        delay(d1);
    }
    obspower(tpwr);           /* Set transmitter power for hard 1H pulses */
    txphase(zero);
    dec2phase(zero);
    delay(1.0e-5);

    /* Begin Pulses */

    status(B);

    rcvroff();
    lk_hold();
    delay(20.0e-6);

    initval(1.0,v2);
    obsstepsize(phase_sl);
    xmtrphase(v2);

    /* shaped pulse */
    obspower(tpwrsl);
    shaped_pulse(shp_sl,pw_sl,one,4.0e-6,0.0);
    xmtrphase(zero);
    obspower(tpwr);
    txphase(zero);
    delay(4.0e-6);
    /* shaped pulse */

    rgpulse(pw,zero,0.0,0.0);                    /* 90 deg 1H pulse */

    delay(0.2e-6);
    zgradpulse(gzlvl5,gt5);
    delay(2.0e-6);

    delay(taua - gt5 - 2.2e-6);   /* taua <= 1/4JNH */

    sim3pulse(2*pw,0.0,2*pwN,zero,zero,zero,0.0,0.0);

    txphase(three);
    dec2phase(zero);
    decphase(zero);

    delay(taua - gt5 - 200.2e-6 - 2.0e-6);

    delay(0.2e-6);
    zgradpulse(gzlvl5,gt5);
    delay(200.0e-6);

    if (sel_flg[A] == 'n')
    {
        rgpulse(pw,three,2.0e-6,0.0);

        decpower(d_c180);

        delay(0.2e-6);
        zgradpulse(gzlvl3,gt3);
        delay(200.0e-6);

        dec2rgpulse(pwN,zero,0.0,0.0);

        delay(tauc);

        dec2rgpulse(2*pwN,zero,0.0,0.0);
        decrgpulse(pwca180,zero,0.0,0.0);
        dec2phase(one);

        delay(tauc - pwca180);

        dec2rgpulse(pwN,one,0.0,0.0);
    }
    else
    {
        rgpulse(pw,one,2.0e-6,0.0);

        decpower(d_c180);

        initval(1.0,v5);
        dec2stepsize(45.0);
        dcplr2phase(v5);

        delay(0.2e-6);
        zgradpulse(gzlvl3,gt3);
        delay(200.0e-6);

        dec2rgpulse(pwN,zero,0.0,0.0);
        dcplr2phase(zero);

        delay(1.34e-3 - SAPS_DELAY - 2.0*pw);

        rgpulse(pw,one,0.0,0.0);
        rgpulse(2.0*pw,zero,0.0,0.0);
        rgpulse(pw,one,0.0,0.0);

        delay(tauc - 1.34e-3 - 2.0*pw);

        dec2rgpulse(2*pwN,zero,0.0,0.0);
        decrgpulse(pwca180,zero,0.0,0.0);
        dec2phase(one);

        delay(tauc - pwca180);

        dec2rgpulse(pwN,one,0.0,0.0);
    }
    /* END sel_flg */

    decphase(t1);

    decpower(d_c90);

    delay(0.2e-6);
    zgradpulse(gzlvl8,gt8);
    delay(200.0e-6);

    /* Cay to CaxC'z  */
    dec2phase(zero);
    txphase(zero);

    /* Turn on D decoupling using the third decoupler */
    dec3phase(one);
    dec3power(pwDlvl);
    dec3rgpulse(pwD,one,4.0e-6,0.0);
    dec3phase(zero);
    dec3power(dpwr3);
    dec3unblank();
    setstatus(DEC3ch, TRUE, 'w', FALSE, dmf3);
    /* Turn on D decoupling */

    if (cacb_dec[A] == 'n')
    {
        decrgpulse(pwc90,t1,2.0e-6,0.0);

        delay(taud -POWER_DELAY -4.0e-6 -WFG_START_DELAY);

        initval(1.0,v3);
        decstepsize(sphase);
        dcplrphase(v3);

        decpower(d_creb);
        decshaped_pulse(spcareb,pwcareb,zero,4.0e-6,0.0);
        dcplrphase(zero);

        decpower(d_csed);
        decshaped_pulse(spcosed,pwcosed,zero,4.0e-6,0.0);

        delay(taud - WFG_STOP_DELAY
              - POWER_DELAY - 4.0e-6 - WFG_START_DELAY - pwcosed - WFG_STOP_DELAY
              - POWER_DELAY - 2.0e-6);

        decpower(d_c90);
        decrgpulse(pwc90,one,2.0e-6,0.0);
    }
    else
    {
        decrgpulse(pwc90,t1,2.0e-6,0.0);

        /* CaCb dec on */
        decpower(d_cacbdec);
        decprgon(cacbdecseq,pwcacbdec,dres_dec);
        decon();
        /* CaCb dec on */

        delay(taud - POWER_DELAY - PRG_START_DELAY
              - PRG_STOP_DELAY
              - POWER_DELAY - 4.0e-6 - WFG_START_DELAY);

        /* CaCb dec off */
        decoff();
        decprgoff();
        /* CaCb dec off */

        initval(1.0,v3);
        decstepsize(sphase);
        dcplrphase(v3);

        decpower(d_creb);
        decshaped_pulse(spcareb,pwcareb,zero,4.0e-6,0.0);
        dcplrphase(zero);

        decpower(d_csed);
        decshaped_pulse(spcosed,pwcosed,zero,4.0e-6,0.0);

        /* CaCb dec on */
        decpower(d_cacbdec);
        decprgon(cacbdecseq,pwcacbdec,dres_dec);
        decon();
        /* CaCb dec on */

        delay(taud - WFG_STOP_DELAY
              - POWER_DELAY - 4.0e-6 - WFG_START_DELAY - pwcosed - WFG_STOP_DELAY
              - POWER_DELAY - PRG_START_DELAY
              - PRG_STOP_DELAY
              - POWER_DELAY - 2.0e-6);

        /* CaCb dec off */
        decoff();
        decprgoff();
        /* CaCb dec off */

        decpower(d_c90);
        decrgpulse(pwc90,one,2.0e-6,0.0);
    }
    /* END cacb_dec */

    /* Turn off D decoupling */
    setstatus(DEC3ch, FALSE, 'c', FALSE, dmf3);
    dec3blank();
    dec3phase(three);
    dec3power(pwDlvl);
    dec3rgpulse(pwD,three,4.0e-6,0.0);
    /* Turn off D decoupling */

    decoffset(dof+(174-56)*dfrq);   /* change Dec1 carrier to Co  */

    delay(2.0e-7);
    zgradpulse(gzlvl4,gt4);
    delay(100.0e-6);

    /*  t1 period for C' chemical shift evolution; Ca 180 and N 180 are used
        to decouple  */

    decrgpulse(pwc90,t2,2.0e-6,0.0);
    if (fc180[A]=='n')
    {
        decpower(d_c180);
        delay(tau1);
        decshaped_pulse(spca180,pwca180dec,zero,4.0e-6,0.0);
        dec2rgpulse(2*pwN,zero,0.0,0.0);
        delay(tau1);
        decpower(d_c90);
    }
    else
        decrgpulse(2*pwc90,zero,0.0,0.0);

    decrgpulse(pwc90,zero,4.0e-6,0.0);

    decoffset(dof);  /* set carrier to Ca */


    delay(2.0e-7);
    zgradpulse(gzlvl9,gt9);
    delay(100.0e-6);

    /*  Refocusing  CayC'z to Cax  */

    /* Turn on D decoupling using the third decoupler */
    dec3phase(one);
    dec3power(pwDlvl);
    dec3rgpulse(pwD,one,4.0e-6,0.0);
    dec3phase(zero);
    dec3power(dpwr3);
    dec3unblank();
    setstatus(DEC3ch, TRUE, 'w', FALSE, dmf3);
    /* Turn on D decoupling */

    if (cacb_dec[A] == 'n')
    {
        decrgpulse(pwc90,zero,0.0e-6,0.0);

        delay(taud - POWER_DELAY
              - 4.0e-6 - WFG_START_DELAY - pwcosed - WFG_STOP_DELAY
              - POWER_DELAY - 4.0e-6 - WFG_START_DELAY);

        decpower(d_csed);
        decshaped_pulse(spcosed,pwcosed,zero,4.0e-6,0.0);

        decpower(d_creb);
        initval(1.0,v4);
        decstepsize(sphase1);
        dcplrphase(v4);

        decshaped_pulse(spcareb,pwcareb,zero,4.0e-6,0.0);
        dcplrphase(zero);

        delay(taud - WFG_STOP_DELAY
              - POWER_DELAY
              - 4.0e-6);

        decpower(d_c90);
        decrgpulse(pwc90,one,4.0e-6,0.0);
    }
    else
    {
        decrgpulse(pwc90,zero,0.0e-6,0.0);

        /* CaCb dec on */
        decpower(d_cacbdec);
        decprgon(cacbdecseq,pwcacbdec,dres_dec);
        decon();
        /* CaCb dec on */

        delay(taud
              - POWER_DELAY - PRG_START_DELAY
              - PRG_STOP_DELAY
              - POWER_DELAY
              - 4.0e-6 - WFG_START_DELAY - pwcosed - WFG_STOP_DELAY
              - POWER_DELAY - 4.0e-6 - WFG_START_DELAY);

        /* CaCb dec off */
        decoff();
        decprgoff();
        /* CaCb dec off */

        decpower(d_csed);
        decshaped_pulse(spcosed,pwcosed,zero,4.0e-6,0.0);

        decpower(d_creb);
        initval(1.0,v4);
        decstepsize(sphase1);
        dcplrphase(v4);

        decshaped_pulse(spcareb,pwcareb,zero,4.0e-6,0.0);
        dcplrphase(zero);

        /* CaCb dec on */
        decpower(d_cacbdec);
        decprgon(cacbdecseq,pwcacbdec,dres_dec);
        decon();
        /* CaCb dec on */

        delay(taud - WFG_STOP_DELAY
              - POWER_DELAY - PRG_START_DELAY
              - PRG_STOP_DELAY
              - POWER_DELAY
              - 4.0e-6);

        /* CaCb dec off */
        decoff();
        decprgoff();
        /* CaCb dec off */

        decpower(d_c90);
        decrgpulse(pwc90,one,4.0e-6,0.0);
    }
    /* END cacb_dec */

    /* Turn off D decoupling */
    setstatus(DEC3ch, FALSE, 'c', FALSE, dmf3);
    dec3blank();
    dec3phase(three);
    dec3power(pwDlvl);
    dec3rgpulse(pwD,three,4.0e-6,0.0);
    /* Turn off D decoupling */

    decpower(d_c180);
    txphase(zero);

    delay(2.0e-7);
    zgradpulse(gzlvl10,gt10);
    delay(100.0e-6);

    /* Constant t2 period  */

    if (bigTN - tau2 >= 0.2e-6)
    {
        dec2rgpulse(pwN,t3,2.0e-6,0.0);

        dec2phase(t4);

        delay(bigTN - tau2 + pwca180);

        dec2rgpulse(2*pwN,t4,0.0,0.0);
        decrgpulse(pwca180,zero,0.0,0.0);
        dec2phase(t5);

        decpower(d_csed);

        delay(bigTN - gt1 - 502.0e-6 - 2.0*GRADIENT_DELAY - POWER_DELAY
              - WFG_START_DELAY - pwcosed - WFG_STOP_DELAY);

        delay(2.0e-6);
        zgradpulse(gzlvl1,gt1);
        delay(500.0e-6);

        decshaped_pulse(spcosed,pwcosed,zero,0.0,0.0);

        delay(tau2);

        sim3pulse(pw,0.0e-6,pwN,zero,zero,t5,0.0,0.0);
    }
    else
    {
        dec2rgpulse(pwN,t3,2.0e-6,0.0);

        dec2rgpulse(2.0*pwN,t4,2.0e-6,2.0e-6);
        dec2phase(t5);

        delay(tau2 - bigTN);
        decrgpulse(pwca180,zero,0.0,0.0);

        decpower(d_csed);

        delay(bigTN - pwca180 - POWER_DELAY
              - gt1 - 502.0e-6 - 2.0*GRADIENT_DELAY
              - WFG_START_DELAY - pwcosed - WFG_STOP_DELAY);

        delay(2.0e-6);
        zgradpulse(gzlvl1,gt1);
        delay(500.0e-6);

        decshaped_pulse(spcosed,pwcosed,zero,0.0,0.0);

        delay(tau2);

        sim3pulse(pw,0.0e-6,pwN,zero,zero,t5,0.0,0.0);
    }

    if (nietl_flg[A] == 'n')
    {
        delay(0.2e-6);
        zgradpulse(gzlvl6,gt6);
        delay(2.0e-6);

        dec2phase(zero);
        delay(taub - gt6 - 2.2e-6);

        sim3pulse(2*pw,0.0e-6,2*pwN,zero,zero,zero,0.0,0.0);

        delay(0.2e-6);
        zgradpulse(gzlvl6,gt6);
        delay(200.0e-6);

        delay(taub - gt6 - 200.2e-6);
        txphase(one);
        dec2phase(one);

        sim3pulse(pw,0.0e-6,pwN,one,zero,one,0.0,0.0);

        delay(0.2e-6);
        zgradpulse(gzlvl7,gt7);
        delay(2.0e-6);

        txphase(zero);
        dec2phase(zero);

        delay(taub - gt7 - 2.2e-6);

        sim3pulse(2*pw,0.0e-6,2*pwN,zero,zero,zero,0.0,0.0);

        delay(0.2e-6);
        zgradpulse(gzlvl7,gt7);
        delay(200.0e-6);

        delay(taub - gt7 - 200.2e-6);

        sim3pulse(pw,0.0e-6,pwN,zero,zero,zero,0.0,0.0);

    }
    else
    {

        /* shaped pulse */
        obspower(tpwrsl);
        shaped_pulse(shp_sl,pw_sl,zero,4.0e-6,0.0);
        obspower(tpwr);
        txphase(zero);
        delay(4.0e-6);
        /* shaped pulse */

        delay(0.2e-6);
        zgradpulse(gzlvl6,gt6);
        delay(2.0e-6);

        dec2phase(zero);
        delay(taub - POWER_DELAY - 4.0e-6 - WFG_START_DELAY - pw_sl
              - WFG_STOP_DELAY - POWER_DELAY - 4.0e-6
              - gt6 - 2.2e-6);

        sim3pulse(2*pw,0.0e-6,2*pwN,zero,zero,zero,0.0,0.0);
        txphase(one);
        dec2phase(zero);

        delay(0.2e-6);
        zgradpulse(gzlvl6,gt6);
        delay(200.0e-6);

        delay(taub - gt6 - 200.2e-6);

        sim3pulse(pw,0.0e-6,pwN,one,zero,zero,0.0,0.0);

        delay(0.2e-6);
        zgradpulse(gzlvl7,gt7);
        delay(2.0e-6);

        txphase(zero);
        dec2phase(zero);

        delay(taub - gt7 - 2.2e-6);

        sim3pulse(2*pw,0.0e-6,2*pwN,zero,zero,zero,0.0,0.0);
        txphase(one);
        dec2phase(one);

        delay(0.2e-6);
        zgradpulse(gzlvl7,gt7);
        delay(200.0e-6);

        delay(taub - gt7 - 200.2e-6);

        sim3pulse(pw,0.0e-6,pwN,one,zero,one,0.0,0.0);
        txphase(zero);
    }

    delay(gt2 +gstab -0.5*(pwN -pw) -2.0*pw/PI);

    rgpulse(2*pw,zero,0.0,0.0);

    delay(2.0e-6);
    zgradpulse(icosel*gzlvl2, gt2);
    decpower(dpwr);
    dec2power(dpwr2);
    delay(gstab -2.0e-6 -2.0*GRADIENT_DELAY -2.0*POWER_DELAY);

    lk_sample();
    status(C);
    setreceiver(t6);

}
Esempio n. 8
0
pulsesequence()
{
/* DECLARE VARIABLES */

 char       autocal[MAXSTR],
	    fsat[MAXSTR],
	    fscuba[MAXSTR],
            f1180[MAXSTR],    /* Flag to start t1 @ halfdwell             */
            f2180[MAXSTR],    /* Flag to start t2 @ halfdwell             */
            spca180[MAXSTR],  /* string for the waveform 180 */
            fc180[MAXSTR], 
            shp_sl[MAXSTR],   /* string for shape of water pulse */
            sel_flg[MAXSTR];

 int         phase, phase2, ni2, icosel, /* icosel changes sign with gds  */ 
             t1_counter,   /* used for states tppi in t1           */ 
             t2_counter;   /* used for states tppi in t2           */ 

 double      pwC,
             pwClvl,
	     compC,
             compN,
	     tau1,         /*  t1 delay */
             tau2,         /*  t2 delay */
             taua,         /*  ~ 1/4JNH =  2.25 ms */
             taub,         /*  ~ 1/4JNH =  2.25 ms */
             zeta,         /* time for C'-N to refocuss set to 0.5*24.0 ms */
             timeTN,        /* nitrogen T period */
             BigT1,        /* delay to compensate for gradient */
             pwN,          /* PW90 for 15N pulse              */
             pwco90,       /* PW90 for co nucleus @ dhpwr         */
             pwca180h,     /* PW180 for ca at dvhpwr               */
             pwco180,      /* PW180 for co at dhpwr180               */
             tsatpwr,      /* low level 1H trans.power for presat  */
             dhpwr,        /* power level for 13C pulses on dec1 - 64 us 
                              90 for part a of the sequence  */
             dhpwr180,     /* power level for 13C pulses on dec1 - 64 us 
                              180 for part a of the sequence  */
             dvhpwr,       /* power level for 180 13C pulses at 54 ppm
                                using a 55.6 us 180 so that get null in
                                co at 178 ppm */
             pwNlvl,       /* high dec2 pwr for 15N hard pulses    */
             sw1,          /* sweep width in f1                    */             
             sw2,          /* sweep width in f2                    */             
             pw_sl,        /* pw90 for H selective pulse on water ~ 2ms */
             phase_sl,     /* pw90 for H selective pulse on water ~ 2ms */
             tpwrsl,       /* power level for square pw_sl       */
 	     Jf,	   /* scale factor for JNCo, set to 4-5 */
             gt0,
             gt1,
             gt2,
             gt3,
             gt4,
             gt5,
             gt6,
             gt7,
             gt8,
             gstab,
             gzlvl0,
             gzlvl1,
             gzlvl2,
             gzlvl3,
             gzlvl4,
             gzlvl5,
             gzlvl6,
             gzlvl7, 
             gzlvl8; 

/* LOAD VARIABLES */

  getstr("autocal",autocal);
  getstr("fsat",fsat);
  getstr("f1180",f1180);
  getstr("f2180",f2180);
  getstr("fscuba",fscuba);
  getstr("spca180",spca180);
  getstr("fc180",fc180);
  getstr("shp_sl",shp_sl);
  getstr("sel_flg",sel_flg);

  taua   = getval("taua"); 
  taub   = getval("taub"); 
  zeta  = getval("zeta");
  timeTN = getval("timeTN");
  BigT1 = getval("BigT1");
  pwca180h = getval("pwca180h");
  pwco180 = getval("pwco180");
  pwco90 = getval("pwco90");
  pwN = getval("pwN");
  tpwr = getval("tpwr");
  tsatpwr = getval("tsatpwr");
  dhpwr = getval("dhpwr");
  dhpwr180 = getval("dhpwr180");
  dpwr = getval("dpwr");
  pwNlvl = getval("pwNlvl");
  phase = (int) ( getval("phase") + 0.5);
  phase2 = (int) ( getval("phase2") + 0.5);
  sw1 = getval("sw1");
  sw2 = getval("sw2");
  dvhpwr = getval("dvhpwr");
  ni = getval("ni");
  ni2 = getval("ni2");
  pw_sl = getval("pw_sl");
  phase_sl = getval("phase_sl");
  tpwrsl = getval("tpwrsl");
  Jf = getval("Jf");

  gt0 = getval("gt0");
  gt1 = getval("gt1");
  gt2 = getval("gt2");
  gt3 = getval("gt3");
  gt4 = getval("gt4");
  gt5 = getval("gt5");
  gt6 = getval("gt6");
  gt7 = getval("gt7");
  gt8 = getval("gt8");
  gstab = getval("gstab");

  gzlvl0 = getval("gzlvl0");
  gzlvl1 = getval("gzlvl1");
  gzlvl2 = getval("gzlvl2");
  gzlvl3 = getval("gzlvl3");
  gzlvl4 = getval("gzlvl4");
  gzlvl5 = getval("gzlvl5");
  gzlvl6 = getval("gzlvl6");
  gzlvl7 = getval("gzlvl7");
  gzlvl8 = getval("gzlvl8");
 
  if (autocal[0] == 'y')
   {
    strcpy(spca180,"Phard_-118p");
    if (FIRST_FID)
    {
      compC = getval("compC");
      pwC = getval("pwC");
      pwClvl = getval("pwClvl");
      ca180 = pbox(spca180, CA180, CA180ps, dfrq, compC*pwC, pwClvl);
      co90 = pbox("Phard90", CO90, CA180ps, dfrq, compC*pwC, pwClvl);
      co180 = pbox("Phard180",CO180,CA180ps, dfrq, compC*pwC, pwClvl);
      pwN = getval("pwN"); compN = getval("compN"); pwNlvl = getval("pwNlvl");
    }

    pwca180h = ca180.pw;
    dvhpwr = ca180.pwr;
    pwco90 = co90.pw;
    dhpwr = co90.pwr;
    pwco180 = co180.pw;
    dhpwr180 = co180.pwr;
   }


/* LOAD PHASE TABLE */

  settable(t1,4,phi1);
  settable(t2,2,phi2);
  settable(t3,4,phi3);
  settable(t4,1,phi4);
  settable(t6,4,rec);

/* CHECK VALIDITY OF PARAMETER RANGES */


    if((dm[A] == 'y' || dm[B] == 'y' || dm[C] == 'y' ))
    {
        printf("incorrect dec1 decoupler flags!  ");
        psg_abort(1);
    }

    if((dm2[A] == 'y' || dm2[B] == 'y' || dm2[C] == 'y' ))
    {
        printf("incorrect dec2 decoupler flags! Should be 'nnn' ");
        psg_abort(1);
    }


    if( tsatpwr > 6 )
    {
        printf("TSATPWR too large !!!  ");
        psg_abort(1);
    }

    if( dpwr > 46 )
    {
        printf("don't fry the probe, DPWR too large!  ");
        psg_abort(1);
    }

    if( dpwr2 > 46 )
    {
        printf("don't fry the probe, DPWR2 too large!  ");
        psg_abort(1);
    }

    if( dhpwr > 62 )
    {
        printf("don't fry the probe, DHPWR too large!  ");
        psg_abort(1);
    }

    if( pw > 200.0e-6 )
    {
        printf("dont fry the probe, pw too high ! ");
        psg_abort(1);
    } 
    if( pwN > 200.0e-6 )
    {
        printf("dont fry the probe, pwN too high ! ");
        psg_abort(1);
    } 
    if( pwco90 > 200.0e-6 )
    {
        printf("dont fry the probe, pwco90 too high ! ");
        psg_abort(1);
    } 
    if( pwca180h > 200.0e-6 )
    {
        printf("dont fry the probe, pwca180h too high ! ");
        psg_abort(1);
    } 

    if( gt3 > 2.5e-3 ) 
    {
        printf("gt3 is too long\n");
        psg_abort(1);
    }
    if( gt0 > 10.0e-3 || gt1 > 10.0e-3 || gt2 > 10.0e-3 ||
        gt4 > 10.0e-3 || gt5 > 10.0e-3 || gt6 > 10.0e-3 || 
        gt7 > 10.0e-3 || gt8 > 10.0e-3)
    {
        printf("gti values are too long. Must be < 10.0e-3\n");
        psg_abort(1);
    } 

/*  Phase incrementation for hypercomplex 2D data */

    if (phase == 2)
      tsadd(t1,1,4);
    if (phase2 == 2) {
       tsadd(t4, 2, 4);
       icosel = 1; 
       }               /* change sign of gradient */
    else icosel = -1;

/*  Set up f1180  tau1 = t1               */
   
    tau1 = d2;
    if(f1180[A] == 'y') {
        tau1 += ( 1.0 / (2.0*sw1) - 2*pwN - pwca180h - 4.0/PI*pwco90 - 2*POWER_DELAY
		  - WFG_START_DELAY - 8.0e-6 - WFG_STOP_DELAY );
        if(tau1 < 0.2e-6) tau1 = 0.4e-6;
    }
        tau1 = tau1/2.0;

/*  Set up f2180  tau2 = t2               */

    tau2 = d3;
    if(f2180[A] == 'y') {
        tau2 += ( 1.0 / (2.0*sw2) ); 
        if(tau2 < 0.2e-6) tau2 = 0.4e-6;
    }
        tau2 = tau2/2.0;

/* Calculate modifications to phases for States-TPPI acquisition          */

   if( ix == 1) d2_init = d2 ;
   t1_counter = (int) ( (d2-d2_init)*sw1 + 0.5 );
   if(t1_counter % 2) {
      tsadd(t1,2,4);     
      tsadd(t6,2,4);    
    }

   if( ix == 1) d3_init = d3 ;
   t2_counter = (int) ( (d3-d3_init)*sw2 + 0.5 );
   if(t2_counter % 2) {
      tsadd(t2,2,4);  
      tsadd(t6,2,4);    
    }

/* BEGIN ACTUAL PULSE SEQUENCE */

status(A);
   obspower(tsatpwr);      /* Set transmitter power for 1H presaturation */
   decpower(dvhpwr);        /* Set Dec1 power for hard 13C pulses         */
   dec2power(pwNlvl);      /* Set Dec2 power for 15N hard pulses         */

/* Presaturation Period */

   if (fsat[0] == 'y')
   {
        rgpulse(d1,zero,2.0e-6,2.0e-6); /* presaturation */
   	obspower(tpwr);      /* Set transmitter power for hard 1H pulses */
	delay(2.0e-5);
	if(fscuba[0] == 'y')
	{
		delay(2.2e-2);
		rgpulse(pw,zero,2.0e-6,0.0);
		rgpulse(2*pw,one,2.0e-6,0.0);
		rgpulse(pw,zero,2.0e-6,0.0);
		delay(2.2e-2);
	}
   }
   else
   {
    delay(d1);
   }
   obspower(tpwr);           /* Set transmitter power for hard 1H pulses */
   txphase(zero);
   dec2phase(zero);
   delay(1.0e-5);

/* Begin Pulses */

status(B);

   rcvroff();
   delay(20.0e-6);

   initval(1.0,v2);
   obsstepsize(phase_sl);
   xmtrphase(v2);

   /* shaped pulse  */
   obspower(tpwrsl);
   shaped_pulse(shp_sl,pw_sl,one,2.0e-6,0.0);
   xmtrphase(zero);
   delay(2.0e-6);
   obspower(tpwr);
   txphase(zero);
   /* shaped pulse  */

   rgpulse(pw,zero,0.0,0.0);                    /* 90 deg 1H pulse */

   delay(0.2e-6);
   zgradpulse(gzlvl5*1.3,gt5);

   delay(taua - gt5 - 0.2e-6);   /* taua <= 1/4JNH */ 

   sim3pulse(2*pw,0.0e-6,2*pwN,zero,zero,zero,0.0,0.0);

   dec2phase(zero); decphase(zero); 

   delay(taua -gt5 -gstab -4.0e-6); 

   zgradpulse(gzlvl5*1.3,gt5);
   delay(gstab);


   if(sel_flg[A] == 'y') {    /* active suppression of one of 
                                 the two components */

   rgpulse(pw,one,4.0e-6,0.0);

   /* shaped pulse  */
   initval(1.0,v3);
   obsstepsize(45.0);
   dcplr2phase(v3);

   delay(0.2e-6);
   zgradpulse(gzlvl3,gt3);
   delay(gstab);

   dec2rgpulse(pwN,zero,0.0,0.0);
   dcplr2phase(zero);

   delay( 1.34e-3 - SAPS_DELAY - 2.0*pw);
   rgpulse(pw,one,0.0,0.0);
   rgpulse(2*pw,zero,0.0,0.0);
   rgpulse(pw,one,0.0,0.0);

   delay( zeta - 1.34e-3 - 2.0*pw + pwco180 );


   }

   else {

   rgpulse(pw,three,4.0e-6,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl4,gt4);
   delay(gstab);

   dec2rgpulse(pwN,zero,0.0,0.0);

   delay( zeta + pwco180 );

   }
  
   dec2rgpulse(2*pwN,zero,0.0,0.0);
   decpower(dhpwr180);
   decrgpulse(pwco180,zero,0.0,0.0);

   delay(zeta - 2.0e-6);

   dec2rgpulse(pwN,one,2.0e-6,0.0);

   dec2phase(zero); decphase(t1);
   decpower(dhpwr);

   delay(0.2e-6);
   zgradpulse(gzlvl7,gt7);
   delay(gstab);
   decpower(dhpwr);
   decrgpulse(pwco90,t1,2.0e-6,0.0);

   if( fc180[A] == 'n' ) {
      decphase(zero);
      delay(tau1);

      dec2rgpulse(2*pwN,zero,0.0,0.0);
      decpower(dvhpwr);
      decshaped_pulse(spca180,pwca180h,zero,4.0e-6,0.0);
      decpower(dhpwr);

      delay(tau1);
   }

   else
     decrgpulse(2*pwco90,zero,2.0e-7,2.0e-7);

   decrgpulse(pwco90,zero,4.0e-6,0.0);

      decpower(dvhpwr);
   delay(0.2e-6);
   zgradpulse(gzlvl3,gt3);
   delay(gstab);


   dec2rgpulse(pwN,t2,2.0e-6,0.0);

   delay(tau2);
      decshaped_pulse(spca180,pwca180h,zero,0.0,0.0);
   delay(tau2);
   decpower(dhpwr180);
   delay(tau2*Jf);
   decrgpulse(pwco180,zero,0.0,0.0);

   delay(0.2e-6); 
   zgradpulse(-icosel*gzlvl1,gt1/2.0);
   delay(50.0e-6);

   delay(timeTN - 50.0e-6 -0.2e-6 - 2.0*GRADIENT_DELAY - gt1/2.0);

   dec2rgpulse(2*pwN,t3,0.0,0.0);
   delay(0.2e-6); 
   zgradpulse(icosel*gzlvl1,gt1/2.0);
   delay(50.0e-6);

   delay(tau2*Jf + timeTN - 50.0e-6 -0.2e-6 - 2.0*GRADIENT_DELAY - gt1/2.0
	 + WFG_START_DELAY + pwca180h + WFG_STOP_DELAY + pwco180 );

   sim3pulse(pw,0.0e-6,pwN,zero,zero,t4,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl6,gt6);
   delay(2.0e-6);

   dec2phase(zero);
   delay(taub - gt6 - 2.2e-6);

   sim3pulse(2*pw,0.0e-6,2*pwN,zero,zero,zero,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl6,gt6);
   delay(gstab);
   
   txphase(one);
   dec2phase(one);

   delay(taub - gt6 - gstab -0.2e-6);

   sim3pulse(pw,0.0e-6,pwN,one,zero,one,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl5,gt5);
   delay(2.0e-6);
 
   txphase(zero);
   dec2phase(zero);

   delay(taub - gt5 - 2.2e-6);

   sim3pulse(2*pw,0.0e-6,2*pwN,zero,zero,zero,0.0,0.0);

   delay(0.2e-6);
   zgradpulse(gzlvl5,gt5);
   delay(gstab);

   delay(taub - gt5 - gstab -0.2e-6);

   sim3pulse(pw,0.0e-6,pwN,zero,zero,zero,0.0,0.0);

   delay(gt2 +gstab +2.0*GRADIENT_DELAY +2.0*POWER_DELAY -0.5*(pwN - pw) -2.0*pw/PI);

   rgpulse(2.0*pw,zero,0.0,0.0);

   dec2power(dpwr2);
   decpower(dpwr);
   zgradpulse(gzlvl2,gt2);
   delay(gstab);

status(C);
         setreceiver(t6);

}