#ifndef LINT
static char SCCSid[] = "@(#)HMBC.c 14.1 12/08/98 Copyright (c) 1991-1998 Varian Assoc.,Inc. All Rights Reserved";
#endif
/* 
 * Varian Assoc.,Inc. All Rights Reserved.
 * This software contains proprietary and confidential
 * information of Varian Assoc., Inc. and its contributors.
 * Use, disclosure and reproduction is prohibited without
 * prior consent.
 */
/* HMBC - Heteronuclear Multiple Bond Correlation 

	Features included:
		State-TPPI in F1
		Randomization of Magnetization prior to relaxation delay
			trim(x)-trim(y) - if no PFG
			G-90-G		- with PFG
			[selected by sspul and PFGflg flags]
		J-filter to suppress one-bond correlations
		Solvent suppression during relaxation  delay
			[selected by satmode flag]
		
	Paramters:
		sspul :		y - selects magnetization randomization option
		PFGflg:		y - selects G-90-G method for magnetization
				     randomization. 
		hsglvl:		Homospoil gradient level (DAC units)
		hsgt	:	Homospoil gradient time
		satmode	:	y - selects presaturation option during relax
					delay
		satfrq	:	presaturation frequency
		satdly	:	presaturation delay
		satpwr	:	presaturation power
		j1xh	:	One-bond XH coupling constant
		jnxh	:	Multiple bond XH coupling constant
		pwxlvl  :	X-nucleus pulse power
		pwx	:	X-nucleus 90 deg pulse width
		d1	:	relaxation delay
		d2	:	Evolution delay
		selpwr	:	sel power level
		selpw	:	sel pulse width
		selflg	:	y - selects gauss pulse for C13
KrishK	-	Last revision	: June 1997

*/


#include <standard.h>

static int ph1[1] = {0};
static int ph2[2] = {0,2};
static int ph3[4] = {0,0,2,2};
static int ph4[1] = {0};
static int ph5[8] = {0,0,0,0,2,2,2,2};
static int ph6[8] = {0,0,2,2,2,2,0,0};

pulsesequence()
{
  double j1xh,
         jnxh,
	 pwxlvl,
	 pwx,
	 hsglvl,
	 hsgt,
	 tau,
         taumb,
	 satfrq,
	 satdly,selpwr,selpw,
	 satpwr;
  char	 sspul[MAXSTR],
	PFGflg[MAXSTR],shape[MAXSTR],selflg[MAXSTR],
 	 satmode[MAXSTR];
  int	 iphase;

  j1xh = getval("j1xh");
  jnxh = getval("jnxh");
  pwxlvl = getval("pwxlvl");
  hsglvl = getval("hsglvl");
  hsgt = getval("hsgt");
  pwx = getval("pwx");
  getstr("PFGflg",PFGflg);
  getstr("selflg",selflg);
  getstr("shape",shape);
	selpwr = getval("selpwr");
	selpw = getval("selpw");
        satfrq = getval("satfrq");
        satdly = getval("satdly");
        satpwr = getval("satpwr");
        getstr("satmode",satmode);

  getstr("sspul",sspul);
  iphase = (int)(getval("phase")+0.5);
  taumb = 1/(2*jnxh);
  tau=1/(2.0*j1xh);

  settable(t1,1,ph1);
  settable(t2,2,ph2);
  settable(t3,4,ph3);
  settable(t4,1,ph4);
  settable(t5,8,ph5);
  settable(t6,8,ph6);
 
  getelem(t3,ct,v3);
  getelem(t6,ct,oph);

  if (iphase == 2)
    incr(v3);

  initval(2.0*(double)((int)(d2*getval("sw1")+0.5)%2),v10);
  add(v3,v10,v3);
  add(oph,v10,oph);

  status(A);
     decpower(pwxlvl);
   if (sspul[0] == 'y')
   {
        if (PFGflg[0] == 'y')
        {
         zgradpulse(hsglvl,hsgt);
         rgpulse(pw,zero,rof1,rof1);
         zgradpulse(hsglvl,hsgt);
        }
        else
        {
        obspower(tpwr-12);
        rgpulse(500*pw,zero,rof1,rof1);
        rgpulse(500*pw,one,rof1,rof1);
        obspower(tpwr);
        }
   }

     delay(d1);

        if (satmode[0] == 'y')
        {
                if (satfrq != tof)
                obsoffset(satfrq);
                obspower(satpwr);
                rgpulse(satdly,zero,rof1,rof1);
                obspower(tpwr);
                if (satfrq != tof)
                obsoffset(tof);
        }

     rcvroff();

  status(B);
     rgpulse(pw,t1,rof1,rof2);
     delay(tau - rof2 - rof1-0.5*selpw);
     decrgpulse(pwx, t2, rof1, rof1);
     delay(taumb - rof1 - pwx); 
     if (selflg[0]=='y')
	{
	 decpower(selpwr);
	 decshaped_pulse(shape,selpw,v3,rof1,rof1);
	 decpower(pwxlvl);
	}
     else
     decrgpulse(pwx,v3,rof1,rof1);
     if (d2/2 > 0.0)
      delay(d2/2 - pwx/PI - pw - 2*rof1);
     else
     delay(d2/2);
     rgpulse(pw*2.0,t4,rof1,rof1);
     if (d2/2 > 0.0)
      delay(d2/2 - pwx/PI - pw - 2*rof1);
     else
     delay(d2/2);
     decrgpulse(pwx,t5,rof1,rof2);
     decpower(dpwr);
     rcvron();
 
  status(C);
} 

