Esempio n. 1
0
void get_wsparameters2() {
  getstrnwarn("wss",wss);
  gcrushws = getvalnwarn("gcrushws");
  tcrushws = getvalnwarn("tcrushws");
  ws_delay = getvalnwarn("ws_delay");
  wsflipf  = getvalnwarn("wsflipf");
  wsflipf_last  = getval("wsflipf_last");
  getstrnwarn("wsrf", wsrf);
  restol = getvalnwarn("restol");
}
Esempio n. 2
0
void get_ovsparameters2() {
  getstrnwarn("ovs",ovs);
  ovsthk  = getvalnwarn("ovsthk");
  ovsgap  = getvalnwarn("ovsgap");  /* convert from mm to cm */
  csd_ppm = getvalnwarn("csd_ppm");
  ovsflipf  = getvalnwarn("ovsflipf");

  tpwrdx  = getval("tpwrdx");
  tpwrdy  = getval("tpwrdy");
  tpwrdz  = getval("tpwrdz");
  
}
Esempio n. 3
0
void calc_grad_duty(double time)
   {
   double  gradenergy[3],gradduty[3];
   double  mult=1.0;
   double  currentlimit,RMScurrentlimit;
   double  sglduty,dutylimit;
   int     checksilent,r,nrcvrs,arraydim,error=0;
   char    rcvrs[MAXSTR];

   currentlimit = getval("currentlimit");
   RMScurrentlimit = getval("RMScurrentlimit");
   getRealSetDefault(GLOBAL, "sglduty", &sglduty,0.0);
   dutylimit = RMScurrentlimit/currentlimit;
   checksilent = option_check("checksilent");

   /* Adjust array dimenstion for multiple receivers */
   nrcvrs = 0;
   getstr("rcvrs",rcvrs);
   arraydim = getvalnwarn("arraydim");
   for (r = 0; r < strlen(rcvrs); r++) {
     if (rcvrs[r] == 'y') nrcvrs++;
   }
   arraydim /= nrcvrs;

   if (seqcon[2] == 'c')
     mult *= nv;
   if (seqcon[3] == 'c')
     mult *= nv2;

   if (!checkflag)
     mult *= arraydim;

   getgradpowerintegral(gradenergy);
   gradduty[0] = sqrt(gradenergy[0]/(mult*time));
   gradduty[1] = sqrt(gradenergy[1]/(mult*time));
   gradduty[2] = sqrt(gradenergy[2]/(mult*time));

   if (sglduty && ((checkflag && !checksilent) || (!checksilent && ix == arraydim))) {
     text_message("Grad energy X: %.3g    Grad energy Y: %.3g    Grad energy Z: %.3g",gradenergy[0],gradenergy[1],gradenergy[2]);
     text_message("Grad duty X: %.3g%%    Grad duty Y: %.3g%%    Grad duty Z: %.3g%%",100*gradduty[0],100*gradduty[1],100*gradduty[2]);
   }

   if ((gradduty[0] > dutylimit) && ((checkflag && !checksilent) || (!checksilent && ix == arraydim))) {
     text_message("%s: X gradient duty cycle %5.1f%% exceeds allowed limit of %5.1f%%",seqfil,100*gradduty[0],100*dutylimit);
     error = 1;
   }
   if ((gradduty[1] > dutylimit) && ((checkflag && !checksilent) || (!checksilent && ix == arraydim))) {
     text_message("%s: Y gradient duty cycle %5.1f%% exceeds allowed limit of %5.1f%%",seqfil,100*gradduty[1],100*dutylimit);
     error = 1;
   }
   if ((gradduty[2] > dutylimit) && ((checkflag && !checksilent) || (!checksilent && ix == arraydim))) {
     text_message("%s: Z gradient duty cycle %5.1f%% exceeds allowed limit of %5.1f%%",seqfil,100*gradduty[2],100*dutylimit);
     error = 1;
   }
   if (error) {
     if (sglduty)
       warn_message("%s: Duty cycle exceeds allowed limit",seqfil);
     else
       abort_message("%s: Duty cycle exceeds allowed limit",seqfil);
   }
   }
Esempio n. 4
0
/********************************************************************
* Function Name: set_pe_order
* Example:	table = set_pe_order();
* Purpose: 	define the phase encode order based on a VnmrJ parameter petype.
*           petype is evaluated, and an appropriate phase encoding table i
*				written to tablib as required. The VnmrJ parameter, petable, is
*				set according to the name of the phase encoding table
*				that was generated.
*
*				defined values of petype:
*						0 - linear phase encoding - no table generated
*						1 - user defined pe - users set petable explicitly
*						2 - center to max phase encoding
*						3 - max to center phase encoding
*						other values undefined
* Input
*	Formal:	none
*	Private:	none
*	Public:	none
* Output
*	Return:	1 if a table was generated, 0 otherwise
*	Formal:	none
*	Private:	none
*	Public:	none
* Notes:		none
*********************************************************************/
int set_pe_order()
{
	/* short routine to set the phase encoding order
	 	petype = 0 is standard linear
	 	petype = 1 is user defined. This means that the user
						defines their own pe table from a macro 
						and set "petable" to be the tabfile name 
		petype = 2 is center-out - generated from nv 
	   other petype to be defined as required for types > 2
	*/

	int pe_type;
	int *pe_order;
	int i;
	int inv;
	int table = 0;
	int numPESteps;

	pe_type = getvalnwarn("petype");
	
	switch( pe_type )
	{
		case 1: 
			/*  Check for external PE table ***************************/
			if (strcmp(petable,"n") && strcmp(petable,"N") && strcmp(petable,"")) {
				loadtable(petable);
				table = 1;
			}			
			break;
		case 2:
			/*center to max phase encoding */
			/* sets t1 to the phase encoding order */
			numPESteps = nv;
			if(( pe_order = (int *)malloc(numPESteps*sizeof(int)))==NULL)
			{
				abort_message("set_pe_order: Memory allocation problem!");
			}
			inv = 1;
			pe_order[0] = 0;
			for(i=1;i<numPESteps;i++)
			{
				inv = -inv;
				pe_order[i] = pe_order[i-1] + inv*i;
			}
			strcpy(petable,"centertomax");
			write_tab_file(petable,1,1,numPESteps,pe_order);
			settable(t1,numPESteps,pe_order);
			putstring("petable",petable);
			table=1;
			break;
		case 3:
			/* max to center phase encoding*/
			numPESteps = nv;
			if(( pe_order = (int *)malloc(numPESteps*sizeof(int)))==NULL)
			{
				abort_message("set_pe_order: Memory allocation problem!");
			}
			inv = 1;
			pe_order[numPESteps-1] = 0;
			for(i=1;i<numPESteps;i++)
			{
				inv = -inv;
				pe_order[numPESteps-i-1] = pe_order[numPESteps-i] + inv*i;
			}
			strcpy(petable,"maxtocenter");
			write_tab_file(petable,1,1,numPESteps,pe_order);
			settable(t1,numPESteps,pe_order);
			putstring("petable",petable);
			table=1;
			break;

		default:
			/* this the default of center-out so make sure that petable is an empty string */
			putstring("petable","");
			table = 0;			
			break;
	}
	return table;
}
Esempio n. 5
0
pulsesequence()
{
   double 	d3 = getval("d3"),
                vtcomplvl = getval("vtcomplvl"),
		gzlvl = getval("gzlvl"),
		shapedpw90 = getvalnwarn("shapedpw90"),
		shapedpw180 = getvalnwarn("shapedpw180"),
		shapedpwr90 = getvalnwarn("shapedpwr90"),
		shapedpwr180 = getvalnwarn("shapedpwr180"),
		gt,gts,lvlf;
   int		hs_gradtype;
   char		shaped[MAXSTR], shapename90[MAXSTR], shapename180[MAXSTR];

   getstrnwarn("shaped", shaped);
   getstrnwarn("shapename90", shapename90);
   getstrnwarn("shapename180", shapename180);
   settmpgradtype("tmpgradtype");
   hs_gradtype = ((specialGradtype == 'h') || (specialGradtype == 'a'));

   if ((p1==0.0) && ((vtcomplvl>0.5) || (hs_gradtype)))
   {
      p1 = 2.0*pw;
   }
   if ((vtcomplvl==2) && ((hs_gradtype) || (spin>0)))
   {
      vtcomplvl = 1;
      if (ix==1)
      {
         text_message("gmapz: vtcomplvl set to 1\n");
         putCmd("setvalue('vtcomplvl',%.0f)\n",vtcomplvl);
         putCmd("setvalue('vtcomplvl',%.0f,'processed')\n",vtcomplvl);
      }
   }

/* lvlf, gt, gts only used for convection compensation */
   if (gradtype[2]=='l') 
     lvlf=2.5;
   else
     lvlf=3.0;
   if ((hs_gradtype) || (spin>0))
     lvlf=1.0;

   gt = (0.5*at + d2)/lvlf;
   gts=0.18*at/lvlf;
   gts = 0.2*at/lvlf;
   if (vtcomplvl==2)
      gt += gts;
   gt *= 2.0;

   settable(t1,16,ph1);
   settable(t2,2,ph2);
   settable(t3,8,ph3);
   settable(t4,16,ph4);

   sub(ct,ssctr,v12);
   getelem(t1,v12,v1);
   getelem(t2,v12,v2);
   getelem(t3,v12,v3);
   getelem(t4,v12,oph); 

   if (vtcomplvl < 0.5)
   {
      getelem(t4,v12,v1); 
      getelem(t1,v12,v2);
   }

/* --- equilibration period --- */
   status(A);
      delay(d1);

/* --- initial pulse --- */
   status(B);
      if (shaped[A] == 'y') {
	obspower(shapedpwr90);
	shaped_pulse(shapename90,shapedpw90,v1,rof1,rof2);
	obspower(tpwr);
	}
      else
        pulse(pw,v1);
/*    instead of hard pulse, could use shapedpulse("gauss",pw,oph,rof1,rof2);
        or "bir4_90_512" or other shape for selective excitation.
        selective inversion pulses may or may not work as well. */

/* --- shim phase encode, not during PFG recovery --- */
      delay(2e-5+d3);

/* First case: No convection compensation, traditional sequence */
   if (vtcomplvl < 0.5)
   {
      if (p1 > 0) 
      {
         zgradpulse(gzlvl,at/2+d2);
         delay(d2);
         if (shaped[A] == 'y') {
	   obspower(shapedpwr180);
	   shaped_pulse(shapename180,shapedpw180,v2,rof1,rof2);
	   obspower(tpwr);
	   }
         else
           pulse(p1,v2);
         delay(d2);
      }
      else
      {
         zgradpulse(-gzlvl,at/2+d2);
         delay(d2*2);
      }
   }
   else  /* (vtcomplvl > 0.5) */
   {
/* Second case: convection compensation  */

      zgradpulse(gzlvl,at/2+d2);
      delay(d2);
      if (vtcomplvl==2)
      {
         zgradpulse(lvlf*gzlvl,gts);
         delay(d2);
      }
      if (shaped[A] == 'y') {
	obspower(shapedpwr180);
	shaped_pulse(shapename180,shapedpw180,v2,rof1,rof2);
      }
      else
        pulse(p1,v2); 
      delay(d2);
      zgradpulse(lvlf*gzlvl,gt);
      delay(d2);
      if (shaped[A] == 'y') {
	shaped_pulse(shapename180,shapedpw180,v3,rof1,rof2);
	obspower(tpwr);
      }
      else
        pulse(p1,v3);
      delay(d2);
      if (vtcomplvl==2)
      {
         zgradpulse(lvlf*gzlvl,gts); 
         delay(d2);
      }
   }

/* --- acq. of echo during gradient --- */
   rgradient('z',gzlvl);
   delay(d2);
/* gradient switches off at end of acq. */

}
Esempio n. 6
0
pulsesequence()
{
	/* declaration of SGL kernel structures */
	SGL_KERNEL_INFO_T read, phase, slice, ss_pre, ss_post;


	/* declaration of internal variables */
	double freqlist[MAXNSLICE];
	double pe_steps;
	int shapelist1, table;
	double xtime, grad_duration, ror_pad,rod_pad;
	double temp_tr;

	double readAmp, phaseAmp, sliceAmp;
	double tepad, tepad2, temin2, htrmin, delayToRF, delayRFToAcq, delayAcqToRF;
	double rof_pad, delRof;

	double sliceRephTrim, sliceDephTrim;
	double readRephTrim, readDephTrim;

	int rfPhase[2] = {0,2};
	
	/* declaration of realtime variables */
	int  vpe_steps  = v1;
	int  vpe_ctr    = v2;
	int  vms_slices = v3;
	int  vms_ctr    = v4;
	int  vpe_offset = v5;
	int  vpe_index  = v6;
	int  vss        = v7;
	int  vssc       = v8;
	int  vacquire   = v9;
	int  vphase	= v10;
	
	settable(t2,2,rfPhase);

	/* setup phase encoding order */
	table = set_pe_order();

	init_mri();

	if( (sliceRephTrim = getvalnwarn("sliceRephTrim")) == 0.0 ) {
		sliceRephTrim = 1.0;
	}	
	
	if( (sliceDephTrim = getvalnwarn("sliceDephTrim")) == 0.0 ) {
		sliceDephTrim = 1.0;
	}	

	if( (readRephTrim = getvalnwarn("readRephTrim")) == 0.0 ) {
		readRephTrim = 1.0;
	}	
	
	if( (readDephTrim = getvalnwarn("readDephTrim")) == 0.0 ) {
		readDephTrim = 1.0;
	}	

	shape_rf( &p1_rf, "p1", p1pat, p1, flip1, rof1, rof2 );	// excitation pulse

	init_slice( &ss_grad, "ss", thk );					// slice gradient
	init_slice_refocus( &ssr_grad, "ssr" );				// slice refocus
	init_slice_refocus( &ssd_grad, "ssd" );				// slice refocus

	init_readout( &ro_grad, "ro", lro, np, sw );		// read gradient
	init_readout_refocus( &ror_grad, "ror" );			// read dephase
	init_readout_refocus( &rod_grad, "ror" );			// read dephase

	init_phase( &pe_grad, "pe", lpe, nv );				// phase gradient

	ss_grad.maxGrad = gmax * 0.57;
	ssr_grad.maxGrad = gmax * 0.57;
	ssd_grad.maxGrad = gmax * 0.57;
	ro_grad.maxGrad = gmax * 0.57;
	ror_grad.maxGrad = gmax * 0.57;
	rod_grad.maxGrad = gmax * 0.57;
	pe_grad.maxGrad = glimpe < 0.57? gmax*glimpe : gmax * 0.57;

	/* calculate the RF pulses, gradient pulses and their interdependencies */
	calc_rf( &p1_rf, "tpwr1", "tpwr1f" );
	calc_slice( &ss_grad, &p1_rf, NOWRITE, "gss" );

	ssr_grad.amp = ss_grad.amp;	
	ssr_grad.gmult = sliceRephTrim;
	ssr_grad.calcFlag = DURATION_FROM_MOMENT_AMPLITUDE;
	calc_slice_refocus( &ssr_grad, &ss_grad, NOWRITE, "gssr" );
	ssd_grad.amp = ss_grad.amp;	
	ssd_grad.gmult = sliceDephTrim; 
	ssd_grad.calcFlag = DURATION_FROM_MOMENT_AMPLITUDE;
	calc_slice_dephase( &ssd_grad, &ss_grad, NOWRITE, "gssd" ); 
	
	calc_readout( &ro_grad, NOWRITE, "gro", "sw", "at" );

	ror_grad.amp = ro_grad.amp;	
	ror_grad.calcFlag = DURATION_FROM_MOMENT_AMPLITUDE;

	rod_grad.amp = ro_grad.amp;	
	rod_grad.calcFlag = DURATION_FROM_MOMENT_AMPLITUDE;

	ror_grad.gmult = readRephTrim;
	calc_readout_refocus( &ror_grad, &ro_grad, NOWRITE, "gror" );
	rod_grad.gmult = readDephTrim;
	calc_readout_rephase( &rod_grad, &ro_grad, NOWRITE, "grod" );

	calc_phase( &pe_grad, NOWRITE, "gpe", "tpe" );

	/* work out the position of the markers */
	/* markerA */
	/* ss_grad.rfDelayFront indicates the starting point of the
	   RF pulse measured from the start of the slice gradient
       ( rof1:pulse length:rof2 ) */	

	double granulatedRFDelayFront = granularity( ss_grad.rfDelayFront, GRADIENT_RES );
	if( granulatedRFDelayFront > ss_grad.rfDelayFront ) {
		granulatedRFDelayFront -= GRADIENT_RES;
	}

	/* ss_grad.rfDelayBack indicates the end point of the
	   RF pulse measured to the end of the slice gradient
       ( rof1:pulse length:rof2 ) */	

	double granulatedRFDelayBack = granularity( ss_grad.rfDelayBack, GRADIENT_RES );
	if( granulatedRFDelayBack > ss_grad.rfDelayBack ) {
		granulatedRFDelayBack -= GRADIENT_RES;
	}
	
	double granulatedRFDelay = granulatedRFDelayFront < granulatedRFDelayBack ? granulatedRFDelayFront : granulatedRFDelayBack;

	double markerADelay = granulatedRFDelay;

	/* read and phase gradients can overlap the start or end of the slice gradient by max of granulatedRFDElay */

	double granulatedATDelayFront = granularity(ro_grad.atDelayFront, GRADIENT_RES);
	if( granulatedATDelayFront > ro_grad.atDelayFront ) {
		granulatedATDelayFront -= GRADIENT_RES;
	}
	double granulatedATDelayBack = granularity(ro_grad.atDelayBack, GRADIENT_RES);
	if( granulatedATDelayBack > ro_grad.atDelayBack ) {
		granulatedATDelayBack -= GRADIENT_RES;
	}
	double granulatedATDelay = granulatedATDelayFront < granulatedATDelayBack ? granulatedATDelayFront : granulatedATDelayBack;

	/* longest gradient between RF pulse and acquire dominates */

	xtime = ssr_grad.duration + granulatedRFDelay;
	xtime = xtime > ssd_grad.duration + granulatedRFDelay ? xtime : ssd_grad.duration + granulatedRFDelay;
	xtime = xtime > ror_grad.duration + granulatedATDelay ? xtime : ror_grad.duration + granulatedATDelay;
	xtime = xtime > rod_grad.duration + granulatedATDelay ? xtime : rod_grad.duration + granulatedATDelay;
	xtime = xtime > pe_grad.duration ? xtime : pe_grad.duration;

	ror_pad = xtime - ror_grad.duration - granulatedATDelay;
	rod_pad = xtime - rod_grad.duration - granulatedATDelay;

	/* make a gradient list */
	start_kernel( &sk );
	add_gradient( (void*)&ss_grad,  "slice",    	SLICE, START_TIME,	"",         0.0,	PRESERVE );
	add_gradient( (void*)&ssr_grad, "sliceReph", 	SLICE, BEHIND,		"slice",    0.0,	INVERT );
	add_gradient( (void*)&ror_grad, "readDeph", 	READ,  BEHIND,		"slice",   -granulatedRFDelay + ror_pad, INVERT );
	add_gradient( (void*)&ro_grad,  "read",     	READ,  BEHIND,		"readDeph", 0.0,	PRESERVE );	
	add_gradient( (void*)&pe_grad,  "phase",    	PHASE, SAME_START,	"readDeph", 0.0,	PRESERVE );
	add_gradient( (void*)&rod_grad, "readReph", 	READ,  BEHIND,		"read",     0.0,	INVERT );
	add_gradient( (void*)&pe_grad,  "rewind",		PHASE, SAME_END,	"readReph", 0.0, INVERT );
	add_gradient( (void*)&ss_grad,	"nextSlice",	SLICE, BEHIND,		"readReph", rod_pad - granulatedRFDelay, PRESERVE );
	add_gradient( (void*)&ssd_grad,	"sliceDeph",	SLICE, BEFORE,		"nextSlice",    0, INVERT );

	add_marker( "markerA", SAME_START, "slice", granulatedRFDelay );
	add_marker( "markerB", SAME_START, "nextSlice", granulatedRFDelay );

	/* get the minimum echo time */
	temin = get_timing( FROM_RF_CENTER_OF, "slice", TO_ECHO_OF, "read" );
	temin2 = get_timing( FROM_ECHO_OF, "read", TO_RF_CENTER_OF, "nextSlice" );
	
	htrmin = MAX( temin, temin2 );
	
	if( minte[0] == 'y' ){
		te = htrmin;
	}
	
	tepad = granularity( te - temin, GRADIENT_RES );
	tepad2 = granularity( te - temin2, GRADIENT_RES );

	te = temin + tepad;	
	putCmd("setvalue('te', %f, 'current')\n", te );

	if( tepad>0.0 )		change_timing( "readDeph", tepad );
	if( tepad2>0.0 )	change_timing( "nextSlice", tepad2 );

	tr = get_timing( FROM_START_OF, "slice", TO_START_OF, "nextSlice" );
	putvalue("tr", tr );

	delayRFToAcq = get_timing( FROM_RF_PULSE_OF, "slice", TO_ACQ_OF, "read" );
	delayAcqToRF = get_timing( FROM_ACQ_OF, "read", TO_RF_PULSE_OF, "nextSlice" );

	set_comp_info( &ss_pre, "ss_pre" );
	write_comp_grads_snippet( NULL, NULL, &ss_pre, "START_OF_KERNEL", "markerA" );

	set_comp_info( &read, "ro" );
	set_comp_info( &phase, "pe" );
	set_comp_info( &slice, "ss" );
	write_comp_grads_snippet( &read, &phase, &slice, "markerA", "markerB" );

	set_comp_info( &ss_post, "ss_post" );
	write_comp_grads_snippet( NULL, NULL, &ss_post, "markerB", "END_OF_KERNEL" );

	/* Set up frequency offset pulse shape list ********/   	
	offsetlist(pss,ss_grad.ssamp,0,freqlist,ns,seqcon[1]);
	shapelist1 = shapelist(p1_rf.pulseName,ss_grad.rfDuration,freqlist,ns,ss_grad.rfFraction, seqcon[1]);

	/* Set pe_steps for profile or full image **********/   	
	pe_steps = prep_profile(profile[0],nv,&pe_grad,&pe_grad);/* profile[0] is n y or r */
	F_initval(pe_steps/2.0,vpe_offset);

	g_setExpTime(trmean*(ntmean*pe_steps*arraydim + (1+fabs(ssc))*arraydim));

	/* Shift DDR for pro *******************************/   	
	roff = -poffset(pro,ro_grad.roamp);

	/* PULSE SEQUENCE */
	status( A );
	rotate();
        triggerSelect(trigger);
	obsoffset( resto );
	delay( GRADIENT_RES );
	initval( 1+fabs( ssc ), vss );
	
	obspower( p1_rf.powerCoarse );
	obspwrf( p1_rf.powerFine );
	delay( GRADIENT_RES );

	assign(one,vacquire);         // real-time acquire flag
	setacqvar(vacquire);          // Turn on acquire when vacquire is zero 
					
	obl_shapedgradient(ss_pre.name,ss_pre.dur,0,0,ss_pre.amp,NOWAIT);		
	sp1on();
	delay(GRADIENT_RES);
	sp1off();
	delay(ss_pre.dur-GRADIENT_RES );
	msloop( seqcon[1], ns, vms_slices, vms_ctr );
		
		assign(vss,vssc);

		peloop( seqcon[2], pe_steps, vpe_steps, vpe_ctr );

			sub(vpe_ctr,vssc,vpe_ctr);     // vpe_ctr counts up from -ssc
			assign(zero,vssc);
			if (seqcon[2] == 's')
				assign(zero,vacquire); // Always acquire for non-compressed loop
			else {
				ifzero(vpe_ctr);
				assign(zero,vacquire); // Start acquiring when vpe_ctr reaches zero
				endif(vpe_ctr);
			}
		
			if (table)
				getelem(t1,vpe_ctr,vpe_index);
			else {
				ifzero(vacquire);
					sub(vpe_ctr,vpe_offset,vpe_index);
				elsenz(vacquire);
					sub(zero,vpe_offset,vpe_index);
				endif(vacquire);
			}		
			
			pe_shaped3gradient( read.name, phase.name, slice.name,
								read.dur, read.amp, 0, slice.amp,
								-pe_grad.increment, vpe_index, NOWAIT );
			delay(ss_grad.rfDelayFront - granulatedRFDelay);
			shapedpulselist( shapelist1, ss_grad.rfDuration, oph, rof1, rof2, seqcon[1], vms_ctr );

			delay( delayRFToAcq - alfa );
			startacq(alfa);
			acquire( np, 1/ro_grad.bandwidth );
			endacq();
			delay( delayAcqToRF - ss_grad.rfDelayFront + granulatedRFDelay - GRADIENT_RES );
			sp1on();
			delay(GRADIENT_RES);
			sp1off();
			
		endpeloop( seqcon[2], vpe_ctr ); 

	endmsloop( seqcon[1], vms_ctr );

	obl_shapedgradient(ss_post.name,ss_post.dur,0,0,ss_post.amp,WAIT);
}
Esempio n. 7
0
pulsesequence()
{
  /* Internal variable declarations *********************/
  double  freq90[MAXNSLICE],freq180[MAXNSLICE];
  double  te_delay1,te_delay2,tr_delay,tau1,tau2,thk2fact,te_delay3=0.0,te_delay4=0.0,navTime=0.0;
  double  crushm0,pem0,gcrushr,gcrushp,gcrushs,pecrush;
  double  refsign=1,crushsign=1,navsign=1;
  int     shape90,shape180,table=0,sepRefocus;
  char    slprofile[MAXSTR];

  /* sequence dependent diffusion variables */
  double Gro,Gss;          // "gdiff" for readout/readout refocus and slice/slice refocus
  double dgro,dgss;        // "delta" for readout/readout refocus and slice/slice refocus
  double Dgro,Dgss;        // "DELTA" for readout/readout refocus and slice/slice refocus
  double dcrush,dgss2;     // "delta" for crusher and gss2 gradients
  double Dcrush,Dgss2;     // "DELTA" for crusher and gss2 gradients

  int    i;

  /* Real-time variables used in this sequence **********/
  int  vpe_steps  = v1;    // Number of PE steps
  int  vpe_ctr    = v2;    // PE loop counter
  int  vms_slices = v3;    // Number of slices
  int  vms_ctr    = v4;    // Slice loop counter
  int  vpe_offset = v5;    // PE/2 for non-table offset
  int  vpe_mult   = v6;    // PE multiplier, ranges from -PE/2 to PE/2
  int  vph180     = v7;    // Phase of 180 pulse
  int  vph2       = v8;    // alternate phase of 180 on odd transients
  int  vssc       = v9;    // Compressed steady-states
  int  vtrimage   = v10;   // Counts down from nt, trimage delay when 0
  int  vacquire   = v11;   // Argument for setacqvar, to skip steady state acquires
  int  vtrigblock = v12;   // Number of slices per trigger block

  /*  Initialize paramaters *****************************/
  init_mri();

  thk2fact=getval("thk2fact");
  pecrush=getval("pecrush");
  sepRefocus=getvalnwarn("sepRefocus");
  getstrnwarn("slprofile",slprofile);

  /*  Check for external PE table ***********************/
  init_tablepar("pelist");          // Initialize pelist parameter
  if (strcmp(petable,"n") && strcmp(petable,"N") && strcmp(petable,"")) {
    loadtable(petable);
    writetabletopar(t1,"pelist");   // Write t1 table to pelist parameter
    table = 1;
  }

  /* RF Power & Bandwidth Calculations ******************/
  shape_rf(&p1_rf,"p1",p1pat,p1,flip1,rof1,rof2);
  shape_rf(&p2_rf,"p2",p2pat,p2,flip2,rof1,rof2);
  calc_rf(&p1_rf,"tpwr1","tpwr1f");
  calc_rf(&p2_rf,"tpwr2","tpwr2f");

  /* Initialize gradient structures *********************/
  init_slice(&ss_grad,"ss",thk);
  init_slice(&ss2_grad,"ss2",thk*thk2fact);
  init_dephase(&crush_grad,"crush");
  init_slice_refocus(&ssr_grad,"ssr");
  if (FP_LT(tcrushro,alfa)) tcrushro=alfa;
  init_readout_butterfly(&ro_grad,"ro",lro,np,sw,gcrushro,tcrushro);
  init_readout_refocus(&ror_grad,"ror");
  init_phase(&pe_grad,"pe",lpe,nv);
  init_generic(&spoil_grad,"spoil",gspoil,tspoil);

  /* Gradient calculations ******************************/
  calc_readout(&ro_grad, WRITE,"gro","sw","at");
  ro_grad.m0ref *= grof;
  calc_readout_refocus(&ror_grad,&ro_grad,NOWRITE,"gror");
  calc_phase(&pe_grad,NOWRITE,"gpe","tpe");
  calc_slice(&ss_grad,&p1_rf,WRITE,"gss");
  calc_slice(&ss2_grad,&p2_rf,WRITE,"gss2");
  calc_slice_refocus(&ssr_grad,&ss_grad,WRITE,"gssr");
  calc_generic(&spoil_grad,WRITE,"","");

  /* Make sure crushing in PE dimension does not refocus signal from 180 */
  crushm0=fabs(gcrush*tcrush);
  pem0=0.0; gcrushp=0.0;
  if (pecrush) pem0=pe_grad.m0;
  calc_dephase(&crush_grad,WRITE,crushm0+pem0,"","");
  gcrushr = crush_grad.amp*crushm0/crush_grad.m0;
  if (pecrush) gcrushp = crush_grad.amp;
  gcrushs = crush_grad.amp*crushm0/crush_grad.m0;

  /* Allow phase encode and read dephase to be separated from slice refocus */
  if (sepRefocus) {
    /* Equalize read dephase and PE gradient durations */
    calc_sim_gradient(&ror_grad,&pe_grad,&null_grad,0,WRITE);
    crushsign=-1;
  } else {
    if (slprofile[0] == 'y') {
      /* Combined slice refocusing and read dephasing,
         reverse gradient sign if ror > ssr integral */
      refsign = (ss_grad.m0ref > ro_grad.m0ref) ? 1.0 : -1.0;
      ss_grad.m0ref -= ro_grad.m0ref;
      calc_slice_refocus(&ssr_grad,&ss_grad,NOWRITE,"gssr");
    }
    /* Equalize both refocus and PE gradient durations */
    calc_sim_gradient(&ror_grad,&pe_grad,&ssr_grad,0,WRITE);
  }

  /* Create optional prepulse events ********************/
  if (fsat[0] == 'y') create_fatsat();
  if (sat[0] == 'y')  create_satbands();
  if (mt[0] == 'y')   create_mtc();
  if (ir[0] == 'y')   create_inversion_recovery();
  if (diff[0] == 'y') init_diffusion(&diffusion,&diff_grad,"diff",gdiff,tdelta);

  sgl_error_check(sglerror);

  /* Min TE *********************************************/
  te = granularity(te,2*GRADIENT_RES);
  /* tau1, tau2 are the sum of events in each half echo period */
  /* tau1, tau2 include a GRADIENT_RES as this is minimum delay time */
  tau1 = ss_grad.rfCenterBack + ssr_grad.duration + crush_grad.duration + ss2_grad.rfCenterFront + 2*GRADIENT_RES;
  tau2 = ss2_grad.rfCenterBack + crush_grad.duration + ro_grad.timeToEcho + GRADIENT_RES;
  if (sepRefocus) tau2 += ror_grad.duration;
  temin = 2*MAX(tau1,tau2);

  /* Diffusion ******************************************/
  if (diff[0] == 'y') {
    /* granulate tDELTA */
    tDELTA = granularity(tDELTA,GRADIENT_RES);
    /* taudiff is the duration of events between diffusion gradients */
    taudiff = ss2_grad.duration + 2*crush_grad.duration + GRADIENT_RES;
    /* set minimum diffusion structure requirements for gradient echo: taudiff, tDELTA, te and minte[0] */
    set_diffusion(&diffusion,taudiff,tDELTA,te,minte[0]);
    /* set additional diffusion structure requirements for spin echo: tau1 and tau2 */
    set_diffusion_se(&diffusion,tau1,tau2);
    /* calculate the diffusion structure delays.
       address &temin is required in order to update temin accordingly */
    calc_diffTime(&diffusion,&temin);
  }

  /* TE delays ******************************************/
  if (minte[0] == 'y') {
    te = temin;
    putvalue("te",te);
  }
  if (FP_LT(te,temin)) {
    abort_message("TE too short, minimum TE = %.3f ms\n",temin*1000);
  }
  te_delay1 = te/2 - tau1 + GRADIENT_RES;
  te_delay2 = te/2 - tau2 + GRADIENT_RES;

  if (navigator[0] == 'y') {
    /* tau1, tau2 are the sum of events in each half echo period */
    tau1 = ro_grad.timeFromEcho + pe_grad.duration + crush_grad.duration + ss2_grad.rfCenterFront;
    tau2 = ss2_grad.rfCenterBack + crush_grad.duration + ro_grad.timeToEcho;
    if (FP_GT(tau1,tau2)) {
      te_delay3 = GRADIENT_RES;
      te_delay4 = tau1-tau2+GRADIENT_RES;
    } else {
      te_delay3 = tau2-tau1+GRADIENT_RES;
      te_delay4 = GRADIENT_RES;
    }
    navTime = te_delay3 + ss2_grad.duration + 2*crush_grad.duration + ro_grad.duration + te_delay4 + 2*GRADIENT_RES;
  }

  /* Check nsblock, the number of slices blocked together
     (used for triggering and/or inversion recovery) */
  check_nsblock();

  /* Min TR *********************************************/   	
  trmin = ss_grad.rfCenterFront  + te + ro_grad.timeFromEcho + pe_grad.duration + 2*GRADIENT_RES;

  /* Increase TR if any options are selected ************/
  if (spoilflag[0] == 'y') trmin += spoil_grad.duration;
  if (navigator[0] == 'y') trmin += navTime;
  if (sat[0] == 'y')       trmin += satTime;
  if (fsat[0] == 'y')      trmin += fsatTime;
  if (mt[0] == 'y')        trmin += mtTime;
  if (ticks > 0)           trmin += GRADIENT_RES;

  /* Adjust for all slices ******************************/
  trmin *= ns;

  /* Inversion recovery *********************************/
  if (ir[0] == 'y') {
    /* tauti is the additional time beyond IR component to be included in ti */
    /* satTime, fsatTime and mtTime all included as those modules will be after IR */
    tauti = satTime + fsatTime + mtTime + GRADIENT_RES + ss_grad.rfCenterFront;
    /* calc_irTime checks ti and returns the time of all IR components */
    trmin += calc_irTime(tauti,trmin,mintr[0],tr,&trtype);
  }

  if (mintr[0] == 'y') {
    tr = trmin;
    putvalue("tr",tr);
  }
  if (FP_LT(tr,trmin)) {
    abort_message("TR too short, minimum TR = %.3f ms\n",trmin*1000);
  }

  /* TR delay *******************************************/
  tr_delay = granularity((tr-trmin)/ns,GRADIENT_RES);

  /* Calculate B values *********************************/
  if (ix == 1) {
    /* Calculate bvalues according to main diffusion gradients */
    calc_bvalues(&diffusion,"dro","dpe","dsl");
    /* Add components from additional diffusion encoding imaging gradients peculiar to this sequence */
    /* Initialize variables */
    dgro = 0.5*(ror_grad.duration+ro_grad.timeToEcho);
    Gro = ro_grad.m0ref/dgro; Dgro = dgro;
    if (!sepRefocus) Dgro = te-ss_grad.rfCenterBack-ro_grad.timeToEcho;
    dgss = 0.5*(ss_grad.rfCenterBack+ssr_grad.duration);
    Gss = ss_grad.m0ref/dgss; Dgss = dgss;
    dgss2 = ss2_grad.duration/2; Dgss2 = dgss2;
    dcrush = crush_grad.duration-crush_grad.tramp; Dcrush = crush_grad.duration+ss2_grad.duration;
    for (i = 0; i < diffusion.nbval; i++)  {
      /* set droval, dpeval and dslval */
      set_dvalues(&diffusion,&droval,&dpeval,&dslval,i);
      /* Readout */
      diffusion.bro[i] += bval(Gro,dgro,Dgro);
      diffusion.bro[i] += bval(crushsign*gcrushr,dcrush,Dcrush);
      diffusion.bro[i] += bval_nested(gdiff*droval,tdelta,tDELTA,crushsign*gcrushr,dcrush,Dcrush);
      if (!sepRefocus) {
        diffusion.bro[i] += bval_nested(Gro,dgro,Dgro,gdiff*droval,tdelta,tDELTA);
        diffusion.bro[i] += bval_nested(Gro,dgro,Dgro,crushsign*gcrushr,dcrush,Dcrush);
      }
      /* Phase */
      if (pecrush) {
        diffusion.bpe[i] += bval(gcrushp,dcrush,Dcrush);
        diffusion.bpe[i] += bval_nested(gdiff*dpeval,tdelta,tDELTA,gcrushp,dcrush,Dcrush);
      }
      /* Slice */
      diffusion.bsl[i] += bval(Gss,dgss,Dgss);
      diffusion.bsl[i] += bval(gcrushs,dcrush,Dcrush);
      diffusion.bsl[i] += bval(ss2_grad.ssamp,dgss2,Dgss2);
      diffusion.bsl[i] += bval_nested(gdiff*dslval,tdelta,tDELTA,gcrushs,dcrush,Dcrush);
      diffusion.bsl[i] += bval_nested(gdiff*dslval,tdelta,tDELTA,ss2_grad.ssamp,dgss2,Dgss2);
      diffusion.bsl[i] += bval_nested(gcrushs,dcrush,Dcrush,ss2_grad.ssamp,dgss2,Dgss2);
      /* Readout/Phase Cross-terms */
      diffusion.brp[i] += bval_cross(gdiff*dpeval,tdelta,tDELTA,crushsign*gcrushr,dcrush,Dcrush);
      diffusion.brp[i] += bval_cross(gdiff*dpeval,tdelta,tDELTA,crushsign*gcrushr,dcrush,Dcrush);
      if (pecrush) diffusion.brp[i] += bval_cross(gdiff*droval,tdelta,tDELTA,gcrushp,dcrush,Dcrush);
      if (!sepRefocus) {
        diffusion.brp[i] += bval_cross(Gro,dgro,Dgro,gdiff*dpeval,tdelta,tDELTA);
        if (pecrush) diffusion.brp[i] += bval_cross(Gro,dgro,Dgro,gcrushp,dcrush,Dcrush);
      }
      /* Readout/Slice Cross-terms */
      diffusion.brs[i] += bval2(crushsign*gcrushr,gcrushs,dcrush,Dcrush);
      diffusion.brs[i] += bval_cross(gdiff*droval,tdelta,tDELTA,gcrushs,dcrush,Dcrush);
      diffusion.brs[i] += bval_cross(gdiff*dslval,tdelta,tDELTA,crushsign*gcrushr,dcrush,Dcrush);
      diffusion.brs[i] += bval_cross(gdiff*droval,tdelta,tDELTA,ss2_grad.ssamp,dgss2,Dgss2);
      if (!sepRefocus) {
        diffusion.brs[i] += bval_cross(Gro,dgro,Dgro,gdiff*dslval,tdelta,tDELTA);
        diffusion.brs[i] += bval_cross(Gro,dgro,Dgro,gcrushs,dcrush,Dcrush);
        diffusion.brs[i] += bval_cross(Gro,dgro,Dgro,ss2_grad.ssamp,dgss2,Dgss2);
      }
      /* Slice/Phase Cross-terms */
      diffusion.bsp[i] += bval_cross(gdiff*dpeval,tdelta,tDELTA,gcrushs,dcrush,Dcrush);
      diffusion.bsp[i] += bval_cross(gdiff*dpeval,tdelta,tDELTA,ss2_grad.ssamp,dgss2,Dgss2);
      if (pecrush) { 
        diffusion.bsp[i] += bval2(gcrushs,gcrushp,dcrush,Dcrush);
        diffusion.bsp[i] += bval_cross(gdiff*dslval,tdelta,tDELTA,gcrushp,dcrush,Dcrush);
        diffusion.bsp[i] += bval_cross(gcrushp,dcrush,Dcrush,ss2_grad.ssamp,dgss2,Dgss2);
      }
    }  /* End for-all-directions */
    /* Write the values */
    write_bvalues(&diffusion,"bval","bvalue","max_bval");
  }

  /* Generate phase-ramped pulses ***********************/
  offsetlist(pss,ss_grad.ssamp,0,freq90,ns,seqcon[1]);
  offsetlist(pss,ss2_grad.ssamp,0,freq180,ns,seqcon[1]);
  shape90 = shapelist(p1_rf.pulseName,ss_grad.rfDuration,freq90,ns,ss_grad.rfFraction,seqcon[1]);
  shape180 = shapelist(p2_rf.pulseName,ss2_grad.rfDuration,freq180,ns,ss2_grad.rfFraction,seqcon[1]);

  /* Set pe_steps for profile or full image *************/   	
  pe_steps = prep_profile(profile[0],nv,&pe_grad,&null_grad);
  F_initval(pe_steps/2.0,vpe_offset);

  /* Shift DDR for pro **********************************/
  roff = -poffset(pro,ro_grad.roamp);

  /* Adjust experiment time for VnmrJ *******************/
  if (ssc<0) {
    if (seqcon[2] == 'c') g_setExpTime(trmean*(ntmean*pe_steps*arraydim - ssc*arraydim));
    else g_setExpTime(trmean*(ntmean*pe_steps*arraydim - ssc*pe_steps*arraydim));
  }
  else g_setExpTime(trmean*ntmean*pe_steps*arraydim + tr*ssc);

  /* Slice profile **************************************/
  if (slprofile[0] == 'y' && !sepRefocus) ror_grad.amp = 0;

  /* Set phase cycle table ******************************/
  if (sepRefocus) settable(t2,1,ph180); // Phase encode is just before readout
  else settable(t2,2,ph180);

  /* PULSE SEQUENCE *************************************/
  status(A);                          // Set status A
  rotate();                           // Set gradient rotation according to psi, phi and theta
  triggerSelect(trigger);             // Select trigger input 1/2/3
  obsoffset(resto);                   // Set spectrometer frequency
  delay(GRADIENT_RES);                // Delay for frequency setting
  initval(fabs(ssc),vssc);            // Compressed steady-state counter
  if (seqcon[2]=='s') assign(zero,vssc); // Zero for standard peloop
  assign(one,vacquire);               // real-time acquire flag
  setacqvar(vacquire);                // Turn on acquire when vacquire is zero 

  /* trigger */
  if (ticks > 0) F_initval((double)nsblock,vtrigblock);

  /* Begin phase-encode loop ****************************/       
  peloop(seqcon[2],pe_steps,vpe_steps,vpe_ctr);

    if (trtype) delay(ns*tr_delay);   // relaxation delay

    /* Compressed steady-states: 1st array & transient, all arrays if ssc is negative */
    if ((ix > 1) && (ssc > 0))
      assign(zero,vssc);
    sub(vpe_ctr,vssc,vpe_ctr);        // vpe_ctr counts up from -ssc
    assign(zero,vssc);
    if (seqcon[2] == 's')
      assign(zero,vacquire);          // Always acquire for non-compressed loop
    else {
      ifzero(vpe_ctr);
        assign(zero,vacquire);        // Start acquiring when vpe_ctr reaches zero
      endif(vpe_ctr);
    }

    /* Read external kspace table if set ******************/       
    if (table)
      getelem(t1,vpe_ctr,vpe_mult);
    else {
      ifzero(vacquire);
        sub(vpe_ctr,vpe_offset,vpe_mult);
      elsenz(vacquire);
        sub(zero,vpe_offset,vpe_mult);      // Hold PE mult at initial value for steady states
      endif(vacquire);
    }

    /* Phase cycle ****************************************/       
    getelem(t2,vpe_ctr,vph180);             // For phase encoding with slice rephase
    add(oph,vph180,vph180);                 // 180 deg pulse phase alternates +/- 90 from receiver
    mod2(ct,vph2);
    dbl(vph2,vph2);
    add(vph180,vph2,vph180);                // Alternate phase for 180 on odd transients

    /* Begin multislice loop ******************************/       
    msloop(seqcon[1],ns,vms_slices,vms_ctr);

      if (!trtype) delay(tr_delay);         // Relaxation delay

      if (ticks > 0) {
        modn(vms_ctr,vtrigblock,vtest);
        ifzero(vtest);                      // if the beginning of an trigger block
          xgate(ticks);
          grad_advance(gpropdelay);
          delay(GRADIENT_RES);
        elsenz(vtest);
          delay(GRADIENT_RES);
        endif(vtest);
      }

      sp1on(); delay(GRADIENT_RES); sp1off();     // Scope trigger

      /* Prepulse options ***********************************/
      if (ir[0] == 'y')   inversion_recovery();
      if (sat[0] == 'y')  satbands();
      if (fsat[0] == 'y') fatsat();
      if (mt[0] == 'y')   mtc();

      /* Slice select RF pulse ******************************/ 
      obspower(p1_rf.powerCoarse);
      obspwrf(p1_rf.powerFine);
      delay(GRADIENT_RES);
      obl_shapedgradient(ss_grad.name,ss_grad.duration,0,0,ss_grad.amp,NOWAIT);
      delay(ss_grad.rfDelayFront);
      shapedpulselist(shape90,ss_grad.rfDuration,oph,rof1,rof2,seqcon[1],vms_ctr);
      delay(ss_grad.rfDelayBack);

      /* Slice refocus gradient *****************************/
      if (sepRefocus) 
        obl_shapedgradient(ssr_grad.name,ssr_grad.duration,0,0,-ssr_grad.amp,WAIT);
      else
        /* Include phase encode and readout dephase gradient if refocus gradients not separated */
        pe_shapedgradient(pe_grad.name,pe_grad.duration,ror_grad.amp,0,-ssr_grad.amp*refsign,pe_grad.increment,vpe_mult,WAIT);

      if (diff[0] == 'y') {
        delay(diffusion.d1);
        diffusion_dephase(&diffusion,dro,dpe,dsl);
        delay(diffusion.d2);
      } 
      else 
        delay(te_delay1);

      /* Refocusing RF pulse ********************************/ 
      obspower(p2_rf.powerCoarse);
      obspwrf(p2_rf.powerFine);
      delay(GRADIENT_RES);
      obl_shapedgradient(crush_grad.name,crush_grad.duration,crushsign*gcrushr,gcrushp,gcrushs,WAIT);
      obl_shapedgradient(ss2_grad.name,ss2_grad.duration,0,0,ss2_grad.amp,NOWAIT);
      delay(ss2_grad.rfDelayFront);
      shapedpulselist(shape180,ss2_grad.rfDuration,vph180,rof2,rof2,seqcon[1],vms_ctr);
      delay(ss2_grad.rfDelayBack);
      obl_shapedgradient(crush_grad.name,crush_grad.duration,crushsign*gcrushr,gcrushp,gcrushs,WAIT);

      if (diff[0] == 'y') {
        delay(diffusion.d3);
        diffusion_rephase(&diffusion,dro,dpe,dsl);
        delay(diffusion.d4);
      } 
      else 
        delay(te_delay2);

      /* Readout dephase, phase encode & readout gradients **/
      roff = -poffset(pro,ro_grad.roamp);  // incase inverted navigator is acquired
      if (slprofile[0] == 'y') {
        /* Readout gradient only if refocus gradients not separated */
        if (sepRefocus)
          obl_shapedgradient(ror_grad.name,ror_grad.duration,0,0,-ror_grad.amp,WAIT);
        obl_shapedgradient(ro_grad.name,ro_grad.duration,0,0,ro_grad.amp,NOWAIT);
      } else {
        /* Readout gradient only if refocus gradients not separated */
        if (sepRefocus) 
          pe_shapedgradient(pe_grad.name,pe_grad.duration,-ror_grad.amp,0,0,-pe_grad.increment,vpe_mult,WAIT);
        obl_shapedgradient(ro_grad.name,ro_grad.duration,ro_grad.amp,0,0,NOWAIT);
      }

      /* Acquisition ****************************************/
      delay(ro_grad.atDelayFront-alfa);
      startacq(alfa);
      acquire(np,1.0/sw);
      delay(ro_grad.atDelayBack);
      endacq();

      /* Rewind Phase encoding ******************************/
      pe_shapedgradient(pe_grad.name,pe_grad.duration,0,0,0,pe_grad.increment,vpe_mult,WAIT);

      /* Navigator acquisition ******************************/
      if (navigator[0] == 'y') {
        delay(te_delay3);
        obl_shapedgradient(crush_grad.name,crush_grad.duration,-crushsign*gcrushr,0,-gcrushs,WAIT);
        obl_shapedgradient(ss2_grad.name,ss2_grad.duration,0,0,ss2_grad.amp,NOWAIT);
        delay(ss2_grad.rfDelayFront);
        shapedpulselist(shape180,ss2_grad.rfDuration,vph180,rof2,rof2,seqcon[1],vms_ctr);
        delay(ss2_grad.rfDelayBack);
        obl_shapedgradient(crush_grad.name,crush_grad.duration,-crushsign*gcrushr,0,-gcrushs,WAIT);
        delay(te_delay4);
        obl_shapedgradient(ro_grad.name,ro_grad.duration,navsign*ro_grad.amp,0,0,NOWAIT);
        delay(ro_grad.atDelayFront-alfa);
        startacq(alfa);
        acquire(np,1.0/sw);
        delay(ro_grad.atDelayBack);
        endacq();
      }

      if (spoilflag[0] == 'y') {
        obl_shapedgradient(spoil_grad.name,spoil_grad.duration,navsign*spoil_grad.amp,0,spoil_grad.amp,WAIT);
      }

    endmsloop(seqcon[1],vms_ctr);

  endpeloop(seqcon[2],vpe_ctr);

  /* Inter-image delay **********************************/
  sub(ntrt,ct,vtrimage);
  decr(vtrimage);
  ifzero(vtrimage);
    delay(trimage);
  endif(vtrimage);

  /* Duty cycle *****************************************/
  calc_grad_duty(tr);

}
void phase_encode3_oblshapedgradient(char *pat1, char *pat2, char *pat3, double width, \
                                     double stat1, double stat2, double stat3,         \
                                     double step1, double step2, double step3,         \
                                     int vmult1, int vmult2, int vmult3,               \
                                     double lim1, double lim2, double lim3,            \
                                     int loops, int wait4me, int tag)
{

    if (gradtype[0] != gradtype[1])
       abort_message("error in gradient or pfg configuration parameter gradtype. abort!\n");
    if (gradtype[0] != gradtype[2])
       abort_message("error in gradient or pfg configuration parameter gradtype. abort!\n");

    int divs1=0, divs2=0, divs3=0, duration=0;
    long long ticks;
    int peR_step,peP_step,peS_step, peR_lim,peP_lim,peS_lim;

    GradientBase *gC = P2TheConsole->getConfiguredGradient();

    if (ix == 1) gC->errorCheck(0,stat1,stat2,stat3,step1,step2,step3);

    P2TheConsole->eventStartAction();

    if (gC->isNoWaitMode())
       abort_message("gradient event requested too soon after previous one in NOWAIT mode. abort!\n");

    cPatternEntry *tmp1=NULL, *tmp2=NULL, *tmp3=NULL;


   /* set the GRADSCALE here, for GRADIENT it is all 0x4000; for Triax PFG they may be different */

   gC->setGradScale("X",gC->GXSCALE);
   gC->setGradScale("Y",gC->GYSCALE);
   gC->setGradScale("Z",gC->GZSCALE);

    int buffer[9];


       if (step1 != 0.0)
       {
           if (! validrtvar(vmult1))
              abort_message("invalid real time variable specified for phase encode multiplier. abort!\n");
           // send SETPEVALUE
           buffer[0] = 1;                        // destination  RO
           buffer[1] = (int)(step1*(gC->GMAX_TO_DAC));
           buffer[2] = vmult1;
           buffer[3] = (int) (lim1+0.5);
           gC->outputACode(SETPEVALUE,4,buffer);
           peR_step  = buffer[1];
           peR_lim   = buffer[3];
       }
       else
       {
           peR_step  = 0;
           peR_lim   = 0;
       }

       if (step2 != 0.0)
       {
           if (! validrtvar(vmult2))
              abort_message("invalid real time variable specified for phase encode multiplier. abort!\n");
           // send SETPEVALUE
           buffer[0] = 2;                        // destination  PE
           buffer[1] = (int)(step2*(gC->GMAX_TO_DAC));
           buffer[2] = vmult2;
           buffer[3] = (int) (lim2+0.5);
           gC->outputACode(SETPEVALUE,4,buffer);
           peP_step  = buffer[1];
           peP_lim   = buffer[3];
       }
       else
       {
           peP_step  = 0;
           peP_lim   = 0;
       }

       if (step3 != 0.0)
       {
           if (! validrtvar(vmult3))
              abort_message("invalid real time variable specified for phase encode multiplier. abort!\n");
           // send SETPEVALUE
           buffer[0] = 3;                       // destination  SS
           buffer[1] = (int)(step3*(gC->GMAX_TO_DAC));
           buffer[2] = vmult3;
           buffer[3] = (int) (lim3+0.5);
           gC->outputACode(SETPEVALUE,4,buffer);
           peS_step  = buffer[1];
           peS_lim   = buffer[3];
       }
       else
       {
           peS_step  = 0;
           peS_lim   = 0;
       }

   /* figure out which logical gradients are active? */
   int tempType=0;

   char gradPwrId[512], swidth[256];
   strcpy(gradPwrId,"OblPEShp ");

   // if shape name blank, that logical axis has no gradient

   if (strcmp(pat1,"") != 0)
   {
     tempType |= 0x1;
     strcat(gradPwrId,pat1);
     strcat(gradPwrId," ");
   }

   if (strcmp(pat2,"") != 0)
   {
     tempType |= 0x2;
     strcat(gradPwrId,pat2);
     strcat(gradPwrId," ");
   }

   if (strcmp(pat3,"") != 0)
   {
     tempType |= 0x4;
     strcat(gradPwrId,pat3);
     strcat(gradPwrId," ");
   }
   sprintf(swidth,"%5.4f",width);
   strcat(gradPwrId,swidth);

    P2TheConsole->newEvent();
    gC->clearSmallTicker();
    if (wait4me)
      gC->setActive();
    else
      gC->setNOWAITMode();

    // axisCode=7 for oblique shaped gradient


    // Gradient Logical Axis READOUT (R)
    if (tempType & 0x1)
    {
      // OblShpGrd pattern has only 16 bits amp info; no KEYS or latch bit
      tmp1 = gC->resolveOblShpGrdPattern(pat1,7,"oblpeshapedgradient",1);
      divs1 = tmp1->getNumberStates();
      duration = gC->calcTicksPerState(width,divs1,4,0.1,"PE Shaped Gradient",0);
      if (duration < 320)   // 4 us is lower limit.
         abort_message("PFG Pattern duration too short. abort!\n");
    }


    if (tempType & 0x2)
    {
      // OblShpGrd pattern has only 16 bits amp info; no KEYS or latch bit
      tmp2 = gC->resolveOblShpGrdPattern(pat2,7,"oblpeshapedgradient",1);
      divs2 = tmp2->getNumberStates();
      if ( (divs1 != 0) && (divs1 != divs2) )
         abort_message("phase_encode3_oblshapedgradient: number of steps in waveforms must be the same. abort!\n");

      duration = gC->calcTicksPerState(width,divs2,4,0.1,"PE Shaped Gradient",0);
      if (duration < 320)   // 4 us is lower limit.
         abort_message("PFG Pattern duration too short. abort!\n");
      divs1 = divs2;
    }

    if (tempType & 0x4)
    {
      // OblShpGrd pattern has only 16 bits amp info; no KEYS or latch bit
      tmp3 = gC->resolveOblShpGrdPattern(pat3,7,"oblpeshapedgradient",1);
      divs3 = tmp3->getNumberStates();
      if ( (divs1 != 0) && (divs1 != divs3) )
         abort_message("phase_encode3_oblshapedgradient: number of steps in waveforms must be the same. abort!\n");

      duration = gC->calcTicksPerState(width,divs3,4,0.1,"PE Shaped Gradient",0);
      if (duration < 320)   // 4 us is lower limit.
         abort_message("PFG Pattern duration too short. abort!\n");
      divs1 = divs3;
    }


    /* ACode
       OBLPESHAPEDGRD  (9 args)
       Type Info
       patID 1
       pat1D 2
       patID 3
       stat1
       stat2
       stat3
       Duration Count
       Loops
     */

   buffer[0] = tempType;

   if (tempType & 0x1)
      buffer[1] = tmp1->getReferenceID();
   else
      buffer[1] = 0;

   if (tempType & 0x2)
      buffer[2] = tmp2->getReferenceID();
   else
      buffer[2] = 0;

   if (tempType & 0x4)
      buffer[3] = tmp3->getReferenceID();
   else
      buffer[3] = 0;

   buffer[4] = (int)(stat1*gC->GMAX_TO_DAC);
   buffer[5] = (int)(stat2*gC->GMAX_TO_DAC);
   buffer[6] = (int)(stat3*gC->GMAX_TO_DAC);

   buffer[7] = duration;                  // DURATION COUNT
   buffer[8] = 1;                         // LOOPS

   gC->oblpegrad_limit_check(buffer[4],buffer[5],buffer[6],  \
         peR_step,peP_step,peS_step, peR_lim,peP_lim,peS_lim);

   gC->computeOBLPESHPGradPower(START,tmp1,tmp2,tmp3,tempType,buffer[4],buffer[5],buffer[6], \
                             peR_step,peP_step,peS_step,vmult1,vmult2,vmult3,                \
                             peR_lim,peP_lim,peS_lim, 1);

   gC->outputACode(OBLPESHAPEDGRD, 9, buffer);

   if (bgflag)
   {
      printf("OBLPESHAPEDGRD\n");
      for(int i=0; i<9; i++)
         printf("%d  ",buffer[i]);
      printf("\n");
   }

   gC->noteDelay(duration*divs1);
   ticks = gC->getSmallTicker();
   if (wait4me)
      P2TheConsole->update4Sync(ticks);
   else
      gC->incr_NOWAIT_eventTicker(ticks);

   gC->computeOBLPESHPGradPower(END,tmp1,tmp2,tmp3,tempType,buffer[4],buffer[5],buffer[6], \
                             peR_step, peP_step, peS_step, peR_lim,peP_lim, peS_lim,       \
                             peR_lim, peP_lim, peS_lim, 1);

  int gradenergyaction = (int)(getvalnwarn("gradenergyaction")+0.49);
  if ( (gradenergyaction & 0x2) ) P2TheConsole->showEventPowerIntegral(gradPwrId);

  grad_flag = TRUE;
  return;
}
Esempio n. 9
0
File: cps.c Progetto: timburrow/ovj3
/*-----------------------------------------------------------------
|	initparms()/
|	initializes the main variables used
+------------------------------------------------------------------*/
void initparms()
{
    double tmpval;
    char   tmpstr[36];
    int    tmp, getchan;

    sw = getval("sw");
    np = getval("np");

    if ( P_getreal(CURRENT,"nf",&nf,1) < 0 )
    {
        nf = 0.0;                /* if not found assume 0 */
    }
    if (nf < 2.0)
	nf = 1.0;

    nt = getval("nt");
    sfrq = getval("sfrq");

    filter = getval("filter");		/* pulse Amp filter setting */
    tof = getval("tof");
    bs = getval("bs");
    if (!var_active("bs",CURRENT))
	bs = 0.0;
    pw = getval("pw");
    pw90 = getval("pw90");
    p1 = getval("p1");

    pwx = getvalnwarn("pwx");
    pwxlvl = getvalnwarn("pwxlvl");
    tau = getvalnwarn("tau");
    satdly = getvalnwarn("satdly");
    satfrq = getvalnwarn("satfrq");
    satpwr = getvalnwarn("satpwr");
    getstrnwarn("satmode",satmode);

    /* ddr */
    roff=getvalnwarn("roff");

    /* --- delays --- */
    d1 = getval("d1"); 		/* delay */
    d2 = getval("d2"); 		/* a delay: used in 2D experiments */
    d3 = getvalnwarn("d3");	/* a delay: used in 3D experiments */
    d4 = getvalnwarn("d4");	/* a delay: used in 4D experiments */
    phase1 = (int) sign_add(getvalnwarn("phase"),0.005);
    phase2 = (int) sign_add(getvalnwarn("phase2"),0.005);
    phase3 = (int) sign_add(getvalnwarn("phase3"),0.005);
    rof1 = getval("rof1"); 	/* Time receiver is turned off before pulse */
    rof2 = getval("rof2");	/* Time after pulse before receiver turned on */
    alfa = getval("alfa"); 	/* Time after rec is turned on that acqbegins */
    pad = getval("pad"); 	/* Pre-acquisition delay */
    padactive = var_active("pad",CURRENT);
    hst = getval("hst"); 	/* HomoSpoil delay */


    tpwr = getval("tpwr");
    if ( P_getreal(CURRENT,"tpwrm",&tpwrf,1) < 0 )
       if ( P_getreal(CURRENT,"tpwrf",&tpwrf,1) < 0 )
          tpwrf = 4095.0;

    //getstr("rfband",rfband);	/* RF band, high or low */

    getstr("hs",hs);
    hssize = strlen(hs);
    /* setlockmode(); */		/* set up lockmode variable,h**o bits */
    if (bgflag)
    {
      fprintf(stderr,"sw = %lf, sfrq = %10.8lf\n",sw,sfrq);
      fprintf(stderr,"hs='%s',%d\n",hs,hssize);
    }
    gain = getval("gain");

    gainactive = var_active("gain",CURRENT); /* non arrayable */
    /* InterLocks is set by go.  It will have three chars.
     * char 0 is for lock
     * char 1 is for spin
     * char 2 is for temp
     */
    getstr("interLocks",interLock); /* non arrayable */
    spin = (int) sign_add(getval("spin"),0.005);
    spinactive = var_active("spin",CURRENT); /* non arrayable */
    HSrotor = 0;  /* high speed spinner selected */
    /* spinTresh is created and set by go.c inside Vnmrbg */
    if (spin >= (int) sign_add(getval("spinThresh"),0.005))
    {
       /* Selected Solids spinner */
       HSrotor = 1;
    }
    vttemp = getval("temp");	/* get vt temperature */
    tempactive = var_active("temp",CURRENT); /* non arrayable */
    vtwait = getval("vtwait");	/* get vt timeout setting */
    vtc = getval("vtc");	/* get vt timeout setting */
    if (getparm("traymax","real",GLOBAL,&tmpval,1))
    {
      traymax=0;
    }
    else
    {
      traymax= (int) (tmpval + 0.5);
    }

    if (getparm("loc","real",GLOBAL,&tmpval,1))
	psg_abort(1);
    loc = (int) sign_add(tmpval,0.005);
    if (!var_active("loc",GLOBAL) || (loc<0) )
    {
        locActive = 0;
        loc = 0;
        tmpval = 0.0;
        if (setparm("loc","real",GLOBAL,&tmpval,1))
          psg_abort(1);
    }
    else
      locActive = 1;

    /* if using Gilson Liquid Handler Racks then gilpar is defined
     * and is an array of 4 values */
    if ((traymax == 96) || (traymax == (8*96)))  /* test for Gilson/Hermes */
    {
       int trayloc=1;
       int trayzone=1;

       if ( P_getreal(GLOBAL, "vrack", &tmpval, 1) >= 0 )
          trayloc = (int) (tmpval + 0.5);

       if ( P_getreal(GLOBAL, "vzone", &tmpval, 1) >= 0 )
          trayzone = (int) (tmpval + 0.5);

       /* rrzzllll */
       loc = loc + (10000 * trayzone) + (1000000 * trayloc);
       if (bgflag)
          fprintf(stderr,"GILSON: ----- vrack: %d, vzone: %d, Encoded Loc = %d\n",trayloc,trayzone,loc);
    }

    getstr("alock",alock);
    getstr("wshim",wshim);
    getlockmode(alock,&lockmode);		/* type of autolocking */
    whenshim = setshimflag(wshim,&shimatanyfid); /* when to shim */
    if ( ( tmp=P_getstring(CURRENT, "sampling", tmpstr, 1, 20)) >= 0)
    {
       samplingScale = 1.01;
       samplingAngle = 0.0;
       samplingTransX = 0.0;
       samplingTransY = 0.0;
       if (tmpstr[0] == 'e')
       {
          double rtmp = 0.0;
          sampling = SAMPLING_ELLIPTICAL;
          P_getreal(CURRENT, "ni", &rtmp, 1);
          samplingRows = (int) rtmp;
          rtmp = 0.0;
          P_getreal(CURRENT, "ni2", &rtmp, 1);
          samplingCols = (int) rtmp;
          if ((samplingRows < 2) || (samplingCols < 2))
             sampling = SAMPLING_STANDARD;
          if (sampling == SAMPLING_ELLIPTICAL)
          {
             if ( P_getreal(CURRENT, "samplingEScale", &rtmp, 1) >= 0)
                samplingScale = rtmp;
             if ( P_getreal(CURRENT, "samplingEAngle", &rtmp, 1) >= 0)
                samplingAngle = rtmp;
             if ( P_getreal(CURRENT, "samplingETransX", &rtmp, 1) >= 0)
                samplingTransX = rtmp;
             if ( P_getreal(CURRENT, "samplingETransY", &rtmp, 1) >= 0)
                samplingTransY = rtmp;
          }
       }
       else
          sampling = SAMPLING_STANDARD;
    }
    else
       sampling = SAMPLING_STANDARD;
// this looks REDUNDANT to instantiation...
    // but is not completely dpwrf
    if ( ( tmp=P_getstring(CURRENT, "dn", tmpstr, 1, 9)) >= 0)
       getchan = TRUE;
    else
       getchan = FALSE;
    /* if "dn" does not exist, don't bother with the rest of channel 2 */
    getchan = (NUMch > 1) && getchan && (tmpstr[0]!='\000');
    if (getchan)		/* variables associated with 2nd channel */
    {
       dfrq = getval("dfrq");
       dmf  = getval("dmf");		/* 1st decoupler modulation freq */
       dof  = getval("dof");
       dres = getvalnwarn("dres");	/* prg decoupler digital resolution */
       if (dres < 1.0) dres = 1.0;
       getstrnwarn("dseq",dseq);

          dpwr = getval("dpwr");
          dhp     = 0.0;
          dlp     = 0.0;

       if ( P_getreal(CURRENT,"dpwrm",&dpwrf,1) < 0 )
          if ( P_getreal(CURRENT,"dpwrf",&dpwrf,1) < 0 )
             dpwrf = 4095.0;
       getstr("dm",dm);
       dmsize = strlen(dm);
       getstr("dmm",dmm);
       dmmsize = strlen(dmm);
       getstr("h**o",h**o);
       homosize = strlen(h**o);
    }
    else
    {
       dfrq    = 1.0;
       dmf     = 1000;
       dof     = 0.0;
       dres    = 1.0;
       dseq[0] = '\000';
       dhp     = 0.0;
       dlp     = 0.0;
       dpwr    = 0.0;
       dpwrf   = 0.0;
       strcpy(dm,"n");
       dmsize  = 1;
       strcpy(dmm,"c");
       dmmsize = 1;
       strcpy(h**o,"n");
       homosize= 1;
    }
    if (bgflag)
    {
       if (!getchan)
          fprintf(stderr,"next line are default values for chan 2\n");
       fprintf(stderr,"dm='%s',%d, dmm='%s',%d\n",dm,dmsize,dmm,dmmsize);
       fprintf(stderr,"h**o='%s',%d\n",h**o,homosize);
    }

    if ( (tmp=P_getstring(CURRENT, "dn2", tmpstr, 1, 9)) >= 0)
       getchan = TRUE;
    else
       getchan = FALSE;
    /* if "dn2" does not exist, don't bother with the rest of channel 3 */
    getchan = (NUMch > 2) && getchan && (tmpstr[0]!='\000');
    if (getchan)			/* variables associated with 3rd channel */
    {
      dfrq2 = getval("dfrq2");
      dmf2  = getval("dmf2");		/* 2nd decoupler modulation freq */
      dof2  = getval("dof2");
      dres2 = getvalnwarn("dres2");	/* prg decoupler digital resolution */
      if (dres2 < 1.0) dres2 = 1.0;
      getstrnwarn("dseq2",dseq2);
      dpwr2 = getval("dpwr2");
      if ( P_getreal(CURRENT,"dpwrm2",&dpwrf2,1) < 0 )
         if ( P_getreal(CURRENT,"dpwrf2",&dpwrf2,1) < 0 )
            dpwrf2 = 4095.0;
      getstr("dm2",dm2);
      dm2size = strlen(dm2);
      getstr("dmm2",dmm2);
      dmm2size = strlen(dmm2);
      getstr("homo2",homo2);
      homo2size = strlen(homo2);
    }
    else
    {
       dfrq2    = 1.0;
       dmf2     = 1000;
       dof2     = 0.0;
       dres2    = 1.0;
       dseq2[0] = '\000';
       dpwr2    = 0.0;
       dpwrf2   = 0.0;
       strcpy(dm2,"n");
       dm2size  = 1;
       strcpy(dmm2,"c");
       dmm2size = 1;
       strcpy(homo2,"n");
       homo2size= 1;
    }
    if (bgflag)
    {
       if (!getchan)
          fprintf(stderr,"next two lines are default values for chan 3\n");
       fprintf(stderr,"dfrq2 = %10.8lf, dof2 = %10.8lf, dpwr2 = %lf\n",
	   dfrq2,dof2,dpwr2);
       fprintf(stderr,"dmf2 = %10.8lf, dm2='%s',%d, dmm2='%s',%d\n",
	   dmf2,dm2,dm2size,dmm2,dmm2size);
       fprintf(stderr,"homo2='%s',%d\n",homo2,homo2size);
    }

    if ( (tmp=P_getstring(CURRENT, "dn3", tmpstr, 1, 9)) >= 0)
       getchan = TRUE;
    else
       getchan = FALSE;
    /* if "dn3" does not exist, don't bother with the rest of channel 3 */
    getchan = (NUMch > 3) && getchan && (tmpstr[0]!='\000');
    if (getchan)			/* variables associated with 3rd channel */
    {
      dfrq3 = getval("dfrq3");
      dmf3  = getval("dmf3");		/* 3nd decoupler modulation freq */
      dof3  = getval("dof3");
      dres3 = getvalnwarn("dres3");	/* prg decoupler digital resolution */
      if (dres3 < 1.0) dres3 = 1.0;
      getstrnwarn("dseq3",dseq3);
      dpwr3 = getval("dpwr3");
      if ( P_getreal(CURRENT,"dpwrm3",&dpwrf3,1) < 0 )
         if ( P_getreal(CURRENT,"dpwrf3",&dpwrf3,1) < 0 )
            dpwrf3 = 4095.0;
      getstr("dm3",dm3);
      dm3size = strlen(dm3);
      getstr("dmm3",dmm3);
      dmm3size = strlen(dmm3);
      getstr("homo3",homo3);
      homo3size = strlen(homo3);
    }
    else
    {
       dfrq3    = 1.0;
       dmf3     = 1000;
       dof3     = 0.0;
       dres3    = 1.0;
       dseq3[0] = '\000';
       dpwr3    = 0.0;
       dpwrf3   = 0.0;
       strcpy(dm3,"n");
       dm3size  = 1;
       strcpy(dmm3,"c");
       dmm3size = 1;
       strcpy(homo3,"n");
       homo3size= 1;
    }

    if (bgflag)
    {
       if (!getchan)
          fprintf(stderr,"next two lines are default values for chan 3\n");
       fprintf(stderr,"dfrq3 = %10.8lf, dof3 = %10.8lf, dpwr3 = %lf\n",
	   dfrq3,dof3,dpwr3);
       fprintf(stderr,"dmf3 = %10.8lf, dm3='%s',%d, dmm3='%s',%d\n",
	   dmf3,dm3,dm3size,dmm3,dmm3size);
       fprintf(stderr,"homo3='%s',%d\n",homo3,homo3size);
    }

    if ( (tmp=P_getstring(CURRENT, "dn4", tmpstr, 1, 9)) >= 0)
       getchan = TRUE;
    else
       getchan = FALSE;
    /* if "dn4" does not exist, don't bother with the rest of channel 4 */
    getchan = (NUMch > 4) && getchan && (tmpstr[0]!='\000');
    if (getchan)			/* variables associated with 4th channel */
    {
      dfrq4 = getval("dfrq4");
      dmf4  = getval("dmf4");		/* 4nd decoupler modulation freq */
      dof4  = getval("dof4");
      dres4 = getvalnwarn("dres4");	/* prg decoupler digital resolution */
      if (dres4 < 1.0) dres4 = 1.0;
      getstrnwarn("dseq4",dseq4);
      dpwr4 = getval("dpwr4");
      if ( P_getreal(CURRENT,"dpwrm4",&dpwrf4,1) < 0 )
         if ( P_getreal(CURRENT,"dpwrf4",&dpwrf4,1) < 0 )
            dpwrf4 = 4095.0;
      getstr("dm4",dm4);
      dm4size = strlen(dm4);
      getstr("dmm4",dmm4);
      dmm4size = strlen(dmm4);
      getstr("homo4",homo4);
      homo4size = strlen(homo4);
    }
    else
    {
       dfrq4    = 1.0;
       dmf4     = 1000;
       dof4     = 0.0;
       dres4    = 1.0;
       dseq4[0] = '\000';
       dpwr4    = 0.0;
       dpwrf4   = 0.0;
       strcpy(dm4,"n");
       dm4size  = 1;
       strcpy(dmm4,"c");
       dmm4size = 1;
       strcpy(homo4,"n");
       homo4size= 1;
    }

    if (bgflag)
    {
       if (!getchan)
          fprintf(stderr,"next two lines are default values for chan 4\n");
       fprintf(stderr,"dfrq4 = %10.8lf, dof4 = %10.8lf, dpwr4 = %lf\n",
	   dfrq4,dof4,dpwr4);
       fprintf(stderr,"dmf4 = %10.8lf, dm4='%s',%d, dmm4='%s',%d\n",
	   dmf4,dm4,dm4size,dmm4,dmm4size);
       fprintf(stderr,"homo4='%s',%d\n",homo4,homo4size);
    }
// end of REDUNDANT ???
}
Esempio n. 10
0
/**************************************************************
    initparms_img()

    Read in all parameters used by the Imaging 
    SEQD applications package. Build the array 
    of slice positions used in multislice loops.
 *************************************************************/
void initparms_img()
{
    int k;                  /*index for loops*/

/*-------------------------------------------------------------
    INITIALIZE PARAMETERS
-------------------------------------------------------------*/

/*--------------------------------------
    RFPULSES
--------------------------------------*/
    p2 = getvalnwarn("p2");
    p3 = getvalnwarn("p3");
    p4 = getvalnwarn("p4");
    p5 = getvalnwarn("p5");
    pi = getvalnwarn("pi");
    psat = getvalnwarn("psat");
    pmt = getvalnwarn("pmt");
    pwx2 = getvalnwarn("pwx2");
    psl = getvalnwarn("psl");

    getstrnwarn("pwpat",pwpat);
    getstrnwarn("p1pat",p1pat);
    getstrnwarn("p2pat",p2pat);
    getstrnwarn("p3pat",p3pat);
    getstrnwarn("p4pat",p4pat);
    getstrnwarn("p5pat",p5pat);
    getstrnwarn("pipat",pipat);
    getstrnwarn("satpat",satpat);
    getstrnwarn("mtpat",mtpat);
    getstrnwarn("pslpat",pslpat);

    tpwr1 = getvalnwarn("tpwr1");
    tpwr2 = getvalnwarn("tpwr2");
    tpwr3 = getvalnwarn("tpwr3");
    tpwr4 = getvalnwarn("tpwr4");
    tpwr5 = getvalnwarn("tpwr5");
    tpwri = getvalnwarn("tpwri");
    mtpwr = getvalnwarn("mtpwr");
    pwxlvl2 = getvalnwarn("pwxlvl2");
    tpwrsl = getvalnwarn("tpwrsl");

/*--------------------------------------
    DECOUPLER PULSES
--------------------------------------*/
    getstrnwarn("decpat",decpat);
    getstrnwarn("decpat1",decpat1);
    getstrnwarn("decpat2",decpat2);
    getstrnwarn("decpat3",decpat3);
    getstrnwarn("decpat4",decpat4);
    getstrnwarn("decpat5",decpat5);

    dpwr = getvalnwarn("dpwr");
    dpwr1 = getvalnwarn("dpwr1");
    dpwr4 = getvalnwarn("dpwr4");
    dpwr5 = getvalnwarn("dpwr5");

/*--------------------------------------
    GRADIENTS
--------------------------------------*/
    gradunit = getvalnwarn("gradunit");
    gro = getvalnwarn("gro");
    gro2 = getvalnwarn("gro2");
    gro3 = getvalnwarn("gro3");
    gpe = getvalnwarn("gpe");
    gpe2 = getvalnwarn("gpe2");
    gpe3 = getvalnwarn("gpe3");
    gss = getvalnwarn("gss");
    gss2 = getvalnwarn("gss2");
    gss3 = getvalnwarn("gss3");
    gror = getvalnwarn("gror");
    gssr = getvalnwarn("gssr");
    grof = getvalnwarn("grof");
    gssf = getvalnwarn("gssf");
    g0 = getvalnwarn("g0");
    g1 = getvalnwarn("g1");
    g2 = getvalnwarn("g2");
    g3 = getvalnwarn("g3");
    g4 = getvalnwarn("g4");
    g5 = getvalnwarn("g5");
    g6 = getvalnwarn("g6");
    g7 = getvalnwarn("g7");
    g8 = getvalnwarn("g8");
    g9 = getvalnwarn("g9");
    gx = getvalnwarn("gx");
    gy = getvalnwarn("gy");
    gz = getvalnwarn("gz");
    gvox1 = getvalnwarn("gvox1");
    gvox2 = getvalnwarn("gvox2");
    gvox3 = getvalnwarn("gvox3");
    gdiff = getvalnwarn("gdiff");
    gflow = getvalnwarn("gflow");
    gspoil = getvalnwarn("gspoil");
    gspoil2 = getvalnwarn("gspoil2");
    gcrush = getvalnwarn("gcrush");
    gcrush2 = getvalnwarn("gcrush2");
    gtrim = getvalnwarn("gtrim");
    gtrim2 = getvalnwarn("gtrim2");
    gramp = getvalnwarn("gramp");
    gramp2 = getvalnwarn("gramp2");
    gxscale = getvalnwarn("gxscale");
    gyscale = getvalnwarn("gyscale");
    gzscale = getvalnwarn("gzscale");
    gpemult = getvalnwarn("gpemult");

    /* Get gmax or gxmax, gymax, gzmax */
    if ( P_getreal(CURRENT,"gxmax",&gxmax,1) < 0 )
    {
    	if ( P_getreal(CURRENT,"gmax",&gmax,1) < 0 )
    	{
		gmax = 0;
    	}
	gxmax = gmax;
    }
    if ( P_getreal(CURRENT,"gymax",&gymax,1) < 0 )
    {
    	if ( P_getreal(CURRENT,"gmax",&gmax,1) < 0 )
    	{
		gmax = 0;
	}
	gymax = gmax;
    }
    if ( P_getreal(CURRENT,"gzmax",&gzmax,1) < 0 )
    {
    	if ( P_getreal(CURRENT,"gmax",&gmax,1) < 0 )
    	{
		gmax = 0;
	}
	gzmax = gmax;
    }
    if (gxmax < gzmax)
	if (gxmax < gymax)
	   gmax = gxmax;
	else
	   gmax = gymax;
    else
	if (gxmax < gymax)
	   gmax = gxmax;
	else
	   gmax = gymax;

    /* --- Get gradient limit parameters --- */
    if ( P_getreal(CURRENT,"gtotlimit",&gtotlimit,1) < 0 )
	gtotlimit = gxmax + gymax + gzmax;
    if (gtotlimit <= 0.0) gtotlimit = gxmax + gymax + gzmax;

    if ( P_getreal(CURRENT,"gxlimit",&gxlimit,1) < 0 )
	gxlimit = gxmax;
    if (gxlimit <= 0.0) gxlimit = gxmax;

    if ( P_getreal(CURRENT,"gylimit",&gylimit,1) < 0 )
	gylimit = gymax;
    if (gylimit <= 0.0) gylimit = gymax;

    if ( P_getreal(CURRENT,"gzlimit",&gzlimit,1) < 0 )
	gzlimit = gzmax;
    if (gzlimit <= 0.0) gzlimit = gzmax;

    /* --- Get gradstepsz if Present --- */
    /* if gradstepsz is 32767 gradient waveshaping is being used  */
    if ( P_getreal(GLOBAL,"gradstepsz",&gradstepsz,1) >= 0 )
    {
	if (gradstepsz < 1.0)
	{
	    if ((anygradcrwg) || (anygradwg) || (anypfga) || (anypfgw))
		gradstepsz = 32767.0;
	    else
		gradstepsz = 2047.0;
	}
    }
    else
    {
	if ((anygradcrwg) || (anygradwg) || (anypfga) || (anypfgw))
	    gradstepsz = 32767.0;
	else
	    gradstepsz = 2047.0;
    }

    getstrnwarn("gpatup",gpatup);
    getstrnwarn("gpatdown",gpatdown);
    getstrnwarn("gropat",gropat);
    getstrnwarn("gpepat",gpepat);
    getstrnwarn("gsspat",gsspat);
    getstrnwarn("gpat",gpat);
    getstrnwarn("gpat1",gpat1);
    getstrnwarn("gpat2",gpat2);
    getstrnwarn("gpat3",gpat3);
    getstrnwarn("gpat4",gpat4);
    getstrnwarn("gpat5",gpat5);

/*--------------------------------------
    DELAYS
--------------------------------------*/
    tr = getvalnwarn("tr");
    te = getvalnwarn("te");
    ti = getvalnwarn("ti");
    tm = getvalnwarn("tm");
    at = getvalnwarn("at");
    tpe = getvalnwarn("tpe");
    tpe2 = getvalnwarn("tpe2");
    tpe3 = getvalnwarn("tpe3");
    tcrush = getvalnwarn("tcrush");
    tdiff = getvalnwarn("tdiff");
    tdelta = getvalnwarn("tdelta");
    tDELTA = getvalnwarn("tDELTA");
    tflow = getvalnwarn("tflow");
    tspoil = getvalnwarn("tspoil");
    hold = getvalnwarn("hold");
    trise = getvalnwarn("trise");
    if (trise > 10e-3) abort_message("trise: %5.0f usec is excessive!",trise*1e6);

/*--------------------------------------
    FREQUENCIES
--------------------------------------*/
    resto = getvalnwarn("resto");
    wsfrq = getvalnwarn("wsfrq");
    chessfrq = getvalnwarn("chessfrq");
    mtfrq = getvalnwarn("mtfrq");

/*--------------------------------------
    PHYSICAL POSITIONS AND FOV
--------------------------------------*/
    fovunit = getvalnwarn("fovunit");
    pro = getvalnwarn("pro");
    ppe = getvalnwarn("ppe");
    ppe2 = getvalnwarn("ppe2");
    ppe3 = getvalnwarn("ppe3");
    pos1 = getvalnwarn("pos1");
    pos2 = getvalnwarn("pos2");
    pos3 = getvalnwarn("pos3");
    lro = getvalnwarn("lro");
    lpe = getvalnwarn("lpe");
    lpe2 = getvalnwarn("lpe2");
    lpe3 = getvalnwarn("lpe3");
    lss = getvalnwarn("lss");

/*--------------------------------------
    PHYSICAL SIZES
--------------------------------------*/
    thkunit = getvalnwarn("thkunit");
    vox1 = getvalnwarn("vox1");
    vox2 = getvalnwarn("vox2");
    vox3 = getvalnwarn("vox3");
    thk = getvalnwarn("thk");

/*--------------------------------------
    BANDWIDTHS
--------------------------------------*/
    sw1 = getvalnwarn("sw1");
    sw2 = getvalnwarn("sw2");
    sw3 = getvalnwarn("sw3");

/*--------------------------------------
    ORIENTATION PARAMETERS
--------------------------------------*/
    getstrnwarn("orient",orient);
    getstrnwarn("vorient",vorient);
    getstrnwarn("dorient",dorient);
    getstrnwarn("sorient",sorient);
    getstrnwarn("orient2",orient2);
        
    psi = getvalnwarn("psi");
    phi = getvalnwarn("phi");
    theta = getvalnwarn("theta");
    vpsi = getvalnwarn("vpsi");
    vphi = getvalnwarn("vphi");
    vtheta = getvalnwarn("vtheta");
    dpsi = getvalnwarn("dpsi");
    dphi = getvalnwarn("dphi");
    dtheta = getvalnwarn("dtheta");
    spsi = getvalnwarn("spsi");
    sphi = getvalnwarn("sphi");
    stheta = getvalnwarn("stheta");

    offsetx = getvalnwarn("offsetx");
    offsety = getvalnwarn("offsety");
    offsetz = getvalnwarn("offsetz");
    gxdelay = getvalnwarn("gxdelay");
    gydelay = getvalnwarn("gydelay");
    gzdelay = getvalnwarn("gzdelay");

/*--------------------------------------
    COUNTS AND FLAGS
--------------------------------------*/
    nD = getvalnwarn("nD");
    ns = getvalnwarn("ns");
    ne = getvalnwarn("ne");
    ni = getvalnwarn("ni");
    nv = getvalnwarn("nv");
    nv2 = getvalnwarn("nv2");
    nv3 = getvalnwarn("nv3");
    ssc = getvalnwarn("ssc");
    ticks = getvalnwarn("ticks");
        
    getstrnwarn("ir",ir);
    getstrnwarn("ws",ws);
    getstrnwarn("mt",mt);
    getstrnwarn("pilot",pilot);
    getstrnwarn("seqcon",seqcon);
    getstrnwarn("petable",petable);
    getstrnwarn("acqtype",acqtype);
    getstrnwarn("exptype",exptype);
    getstrnwarn("apptype",apptype);
    getstrnwarn("seqfil",seqfil);
    getstrnwarn("rfspoil",rfspoil);
    getstrnwarn("verbose",verbose);

/*--------------------------------------
    Miscellaneous
--------------------------------------*/
    rfphase = getvalnwarn("rfphase");
    B0 = getvalnwarn("B0");
    gpropdelay = getvalnwarn("gpropdelay");
    kzero = getvalnwarn("kzero");
    aqtm = getvalnwarn("aqtm");
    getstrnwarn("volumercv",volumercv);


/*--------------------------------------
    Build slice position array
--------------------------------------*/
    if (ns > MAXSLICE) {
        text_error("ns exceeds maximum limit.\n");
        psg_abort(1);
    }

    for (k = 0; k < MAXSLICE; k++) {
        pss[k] = 0.0;
    }

    if (seqcon[1] == 's')
	pss[0] = getval("pss");
    else if (seqcon[1] == 'c')
    	getarray("pss",pss);
    else
	pss[0] = getvalnwarn("pss");	/* get it anyway but with no warning */


/*--------------------------------------
    Old SISCO Imaging Parameters
--------------------------------------*/
    slcto = getvalnwarn("slcto");    /* slice selection offset */
    delto = getvalnwarn("delto");    /* slice spacing frequency */
    tox = getvalnwarn("tox");
    toy = getvalnwarn("toy");
    toz = getvalnwarn("toz");
    griserate = getvalnwarn("griserate");

}