KSFoundation  [April-2021]
A platform for simpler EPIC programming on GE MR systems
ksgre_tutorial: Tutorial GRE sequence (2D)

Data Structures

struct  KSGRE_SEQUENCE
 

Macros

#define KSGRE_DEFAULT_SSI_TIME   500
 
#define KSGRE_INIT_SEQUENCE
 

Functions

STATUS cvinit (void)
 
STATUS cveval (void)
 
STATUS my_cveval (void)
 
STATUS cvcheck (void)
 
STATUS predownload (void)
 
STATUS pulsegen (void)
 
STATUS mps2 (void)
 
STATUS aps2 (void)
 
STATUS scan (void)
 
 abstract ("GRE Tutorial [KSFoundation]")
 
 psdname ("ksgre_tutorial")
 
int ksgre_scan_sliceloop_nargs (int slperpass, int nargs, void **args)
 
float ksgre_scan_acqloop (int passindx)
 
float ksgre_scan_scanloop ()
 
STATUS ksgre_scan_seqstate (SCAN_INFO slice_info, int kyview)
 
void ksgre_init_imagingoptions (void)
 
STATUS ksgre_init_UI (void)
 
STATUS ksgre_eval_UI ()
 
STATUS ksgre_eval_setupobjects ()
 
STATUS ksgre_eval_TErange ()
 
STATUS ksgre_eval_tr (KS_SEQ_COLLECTION *seqcollection)
 
STATUS ksgre_check ()
 
STATUS ksgre_predownload_plot (KS_SEQ_COLLECTION *seqcollection)
 
STATUS ksgre_predownload_setrecon ()
 
STATUS ksgre_pg ()
 
int ksgre_scan_coreslice (const SCAN_INFO *slice_pos, int dabslice, int kyindx, int exc)
 
int ksgre_scan_sliceloop (int slperpass, int passindx, int kyindx, int exc)
 
STATUS ksgre_scan_init (void)
 
STATUS ksgre_scan_prescanloop (int nloops, int dda)
 

Variables

KS_SEQ_COLLECTION seqcollection
 
float ksgre_gscalerfexc = 0.9
 
float ksgre_spoilerarea = 2000.0 with {0.0, 10000.0, 2000.0, VIS, "ksgre spoiler gradient area",}
 
int ksgre_ssi_time = KSGRE_DEFAULT_SSI_TIME with {32, , KSGRE_DEFAULT_SSI_TIME, VIS, "time from eos to ssi in intern trig",}
 
int ksgre_dda = 2 with {0, 200, 2, VIS, "Number of dummy scans for steady state",}
 
KSGRE_SEQUENCE ksgre = KSGRE_INIT_SEQUENCE
 
int sequence_iopts []
 
int volindx
 
int passindx
 

Detailed Description

Macro Definition Documentation

◆ KSGRE_DEFAULT_SSI_TIME

#define KSGRE_DEFAULT_SSI_TIME   500

◆ KSGRE_INIT_SEQUENCE

#define KSGRE_INIT_SEQUENCE
Value:
KS_INIT_PHASER, KS_INIT_TRAP, KS_INIT_SELRF};
#define KS_INIT_READTRAP
Definition: KSFoundation.h:215
#define KS_INIT_TRAP
Definition: KSFoundation.h:212
#define KS_INIT_SELRF
Definition: KSFoundation.h:240
#define KS_INIT_SEQ_CONTROL
Definition: KSFoundation.h:245

Function Documentation

◆ cvinit()

STATUS cvinit ( void  )
57  {
58  STATUS status;
59 
60  status = GEReq_cvinit();
61  if (status != SUCCESS) return status;
62 
63  /* reset debug file ./ks_debug.txt (SIM) or /usr/g/mrraw/ks_debug.txt (HW) */
64  ks_dbg_reset();
65 
66  /* Imaging Options buttons */
68 
69  /* Setup UI buttons */
70  status = ksgre_init_UI();
71  if (status != SUCCESS) return status;
72 
73  return SUCCESS;
74 
75 } /* cvinit() */
STATUS ksgre_init_UI(void)
Initial setup of user interface (UI) with default values for menus and fields
Definition: ksgre_implementation.e:239
void ks_dbg_reset()
Clear debug file content
Definition: KSFoundation_common.c:119
STATUS GEReq_cvinit(void)
Helper function to be called at the beginning of cvinit()
Definition: GERequired.e:2220
void ksgre_init_imagingoptions(void)
Initial handling of imaging options buttons and top-level CVs at the PSD type-in page
Definition: ksgre_implementation.e:195

◆ cveval()

STATUS cveval ( void  )
83  {
84 
85  /*
86  cveval() is called 37+ times per UI button push on the MR system, while cvcheck() is only called once.
87  For a faster execution we have a my_cveval() function that is called in cvcheck() instead
88  */
89 
90  return SUCCESS;
91 }

◆ my_cveval()

STATUS my_cveval ( void  )
94  {
95  STATUS status;
96 
98 
99  status = GEReq_cveval();
100  if (status != SUCCESS) return status;
101 
102  /* User Interface updates & opuserCV sync */
103  status = ksgre_eval_UI();
104  if (status != SUCCESS) return status;
105 
106  /* Setup sequence objects */
107  status = ksgre_eval_setupobjects();
108  if (status != SUCCESS) return status;
109 
110  /* Calculate minimum (and maximum TE) */
111  status = ksgre_eval_TErange();
112  if (status != SUCCESS) return status;
113 
114  /* Run the sequence once (and only once after ksgre_eval_setupobjects()) in cveval() to
115  get the sequence duration and the number of object instances (for grad/rf limits) */
116  status = ksgre_pg();
117  if (status != SUCCESS) return status;
118 
120  if (status != SUCCESS) return status;
121 
122 
123  /*--------- Begin: Additional sequence modules -----------*/
124 
125 
126 
127  /*--------- End: Additional sequence modules -----------*/
128 
129 
130  /* Min TR, #slices per TR, RF/gradient heating & SAR */
131  status = ksgre_eval_tr(&seqcollection);
132  if (status != SUCCESS) return status;
133 
134  /* RF scaling across sequence modules */
136  if (status != SUCCESS) return status;
137 
138  /* scan time */
139  pitscan = ksgre_scan_scanloop();
140 
141  return SUCCESS;
142 
143 } /* my_cveval() */
STATUS ksgre_eval_UI()
Gets the current UI and checks for valid inputs
Definition: ksgre_implementation.e:535
KS_SEQ_COLLECTION seqcollection
Definition: ksgre_tutorial.e:51
STATUS ksgre_pg(int)
The ksgre (main) pulse sequence
Definition: ksgre_implementation.e:1254
STATUS ksgre_eval_TErange()
Sets the min/max TE based on the durations of the sequence objects in KSGRE_SEQUENCE (ksgre)...
Definition: ksgre_implementation.e:757
STATUS ksgre_eval_setupobjects()
Sets up all sequence objects for the main sequence module (KSGRE_SEQUENCE ksgre)
Definition: ksgre_implementation.e:564
STATUS ks_eval_addtoseqcollection(KS_SEQ_COLLECTION *seqcollection, KS_SEQ_CONTROL *seqctrl) WARN_UNUSED_RESULT
Adds a sequence module (KS_SEQ_CONTROL) to the KS_SEQ_COLLECTION struct for later RF scaling and SAR ...
Definition: KSFoundation_host.c:149
float ksgre_scan_scanloop()
Plays out all passes of a single or multi-pass scan
Definition: ksgre_implementation.e:1925
void ks_init_seqcollection(KS_SEQ_COLLECTION *seqcollection)
Resets KS_SEQ_COLLECTION to its default value (KS_INIT_SEQ_COLLECTION)
Definition: KSFoundation_host.c:117
KS_SEQ_CONTROL seqctrl
Definition: ksgre_implementation.e:45
KSGRE_SEQUENCE ksgre
Definition: ksgre_implementation.e:121
STATUS ksgre_eval_tr(KS_SEQ_COLLECTION *seqcollection)
Evaluation of number of slices / TR, set up of slice plan, TR validation and SAR checks
Definition: ksgre_implementation.e:958
STATUS GEReq_cveval(void)
Helper function to be called at the beginning of cveval()
Definition: GERequired.e:2342
STATUS GEReq_eval_rfscaling(KS_SEQ_COLLECTION *seqcollection)
Performs RF scaling of all RF pulses in the KS_SEQ_COLLECTION and Prescan
Definition: GERequired.e:758

◆ cvcheck()

STATUS cvcheck ( void  )
150  {
151  STATUS status;
152 
153  status = my_cveval();
154  if (status != SUCCESS) return status;
155 
156  status = GEReq_cvcheck();
157  if (status != SUCCESS) return status;
158 
159  status = ksgre_check();
160  if (status != SUCCESS) return status;
161 
162  return SUCCESS;
163 
164 } /* cvcheck() */
STATUS GEReq_cvcheck(void)
Helper function to be called at the beginning of cvcheck()
Definition: GERequired.e:2407
STATUS my_cveval(void)
Definition: ksgre_tutorial.e:94
STATUS ksgre_check()
Returns error of various parameter combinations that are not allowed for ksgre
Definition: ksgre_implementation.e:1088

◆ predownload()

STATUS predownload ( void  )
170  {
171  STATUS status;
172 
173  status = GEReq_predownload();
174  if (status != SUCCESS) return status;
175 
176  /* Set filter slot # for SCAN, APS2, MPS2 */
178 
179  /* slice ordering */
180  /* The following GE globals must be set appropriately:
181  data_acq_order[], rsp_info[], rsprot[], rsptrigger[]. This is a must for a main pulse sequence */
183  if (status != SUCCESS) return status;
184 
185  /* generic rh-vars setup */
186  GEReq_predownload_setrecon_readphase(&ksgre.read, &ksgre.phaseenc, NULL, KS_IMSIZE_MIN256, KS_SAVEPFILES * autolock + KS_GERECON * (rhrecon < 1000) /* online recon if rhrecon < 1000 */);
188  GEReq_predownload_setrecon_voldata(opfphases, ks_slice_plan); /* opfphases = number of volumes */
189 
190  /* further sequence specific recon settings that have not been set correctly at this point */
191  status = ksgre_predownload_setrecon();
192  if (status != SUCCESS) return status;
193 
194  /* plotting of sequence modules and slice timing to disk */
196 
197  return SUCCESS;
198 
199 } /* predownload() */
KS_SEQ_COLLECTION seqcollection
Definition: ksgre_tutorial.e:51
void GEReq_predownload_setrecon_readphase(const KS_READTRAP *const readtrap, const KS_PHASER *const phaser, const KS_PHASER *const zphaser, int imsize_policy, int datadestination)
Sets required global rh*** variables for Cartsian imaging
Definition: GERequired.e:1685
STATUS GEReq_predownload_setfilter(FILTER_INFO *filt)
Assigns a global filter slot for a main sequence
Definition: GERequired.e:1149
STATUS GEReq_predownload_store_sliceplan(KS_SLICE_PLAN slice_plan)
Sets mandatory global GE arrays for data acquisition
Definition: GERequired.e:1001
Definition: KSFoundation.h:1948
#define KS_GERECON
Definition: KSFoundation.h:176
STATUS ksgre_predownload_setrecon()
Last-resort function to override certain recon variables not set up correctly already
Definition: ksgre_implementation.e:1222
void GEReq_predownload_setrecon_voldata(int numvols, const KS_SLICE_PLAN slice_plan)
Sets rh*** variables related to multi-volume imaging
Definition: GERequired.e:1973
KS_READTRAP read
Definition: ksgre_implementation.e:46
#define KS_SAVEPFILES
Definition: KSFoundation.h:175
KS_PHASER phaseenc
Definition: ksgre_implementation.e:49
KSGRE_SEQUENCE ksgre
Definition: ksgre_implementation.e:121
FILTER_INFO filt
Definition: KSFoundation.h:735
KS_SLICE_PLAN ks_slice_plan
Definition: GERequired.e:217
KS_READ acq
Definition: KSFoundation.h:1574
void GEReq_predownload_setrecon_annotations_readtrap(KS_READTRAP *readtrap, int echogap)
Sets ih*** variables for TE and rBW annotation based on a KS_READTRAP
Definition: GERequired.e:1917
STATUS GEReq_predownload(void)
Helper function to be called at the beginning of predownload()
Definition: GERequired.e:2451
STATUS ksgre_predownload_plot(KS_SEQ_COLLECTION *seqcollection)
Plotting of sequence modules and slice timing to PNG/SVG/PDF files
Definition: ksgre_implementation.e:1155

◆ pulsegen()

STATUS pulsegen ( void  )
208  {
209 
211 
212  /* Main Pulse Sequence */
213  ksgre_pg();
214  KS_SEQLENGTH(seqcore, ksgre.seqctrl);
215 
217 
218  buildinstr(); /* load the sequencer memory */
219 
220  return SUCCESS;
221 
222 } /* pulsegen() */
STATUS ksgre_pg(int)
The ksgre (main) pulse sequence
Definition: ksgre_implementation.e:1254
KS_SEQLENGTH(seq_name, seq_struct)
Creates a hardware sequence for the current sequence module
Definition: GERequired.e:65
void GEReq_pulsegenEnd(void)
Helper function to be called at the end of pulsegen()
Definition: GERequired.e:2551
KS_SEQ_CONTROL seqctrl
Definition: ksgre_implementation.e:45
KSGRE_SEQUENCE ksgre
Definition: ksgre_implementation.e:121
void GEReq_pulsegenBegin(void)
Helper function to be called at the beginning of pulsegen()
Definition: GERequired.e:2527

◆ mps2()

STATUS mps2 ( void  )
241  {
242  rspent = L_MPS2;
243  strcpy(psdexitarg.text_arg, "mps2");
244 
245  if (ksgre_scan_init() == FAILURE)
246  return rspexit();
247 
248  if (ksgre_scan_prescanloop(30000, ksgre_dda) == FAILURE)
249  return rspexit();
250 
251  rspexit();
252 
253  return SUCCESS;
254 
255 } /* end mps2() */
int ksgre_dda
Definition: ksgre_implementation.e:101
STATUS ksgre_scan_prescanloop(int nloops, int dda)
Prescan loop called from both APS2 and MPS2 entry points
Definition: ksgre_implementation.e:2012
STATUS ksgre_scan_init(void)
Common initialization for prescan entry points MPS2 and APS2 as well as the SCAN entry point...
Definition: ksgre_implementation.e:1984
int rspent
Definition: GERequired.e:2626
PSD_EXIT_ARG psdexitarg

◆ aps2()

STATUS aps2 ( void  )
263  {
264 
265  rspent = L_APS2;
266  strcpy(psdexitarg.text_arg, "aps2");
267 
268  if (ksgre_scan_init() == FAILURE)
269  return rspexit();
270 
271  if (ksgre_scan_prescanloop(100, ksgre_dda) == FAILURE)
272  return rspexit();
273 
274  rspexit();
275 
276  return SUCCESS;
277 
278 } /* aps2() */
int ksgre_dda
Definition: ksgre_implementation.e:101
STATUS ksgre_scan_prescanloop(int nloops, int dda)
Prescan loop called from both APS2 and MPS2 entry points
Definition: ksgre_implementation.e:2012
STATUS ksgre_scan_init(void)
Common initialization for prescan entry points MPS2 and APS2 as well as the SCAN entry point...
Definition: ksgre_implementation.e:1984
int rspent
Definition: GERequired.e:2626
PSD_EXIT_ARG psdexitarg

◆ scan()

STATUS scan ( void  )
287  {
288 
289  rspent = L_SCAN;
290  strcpy(psdexitarg.text_arg, "scan");
291 
292  if (ksgre_scan_init() == FAILURE)
293  return rspexit();
294 
295  /* Scan hierarchy:
296 
297  ksgre_scan_scanloop() - Data for the entire scan
298  ksgre_scan_acqloop() - All data for one set of slices that fit within one TR (one acquisition)
299  ksgre_scan_sliceloop() - One set of slices that fit within one TR played out for one shot
300  ksgre_scan_coreslice() - One slice playout, with optional other sequence modules
301  */
303 
304  GEReq_endofscan();
305 
306  /* So we can see the sequence in plotter after scan completes */
308 
309  rspexit();
310 
311  return SUCCESS;
312 
313 } /* scan() */
void ks_scan_switch_to_sequence(KS_SEQ_CONTROL *ctrl)
Definition: KSFoundation_tgt.c:1356
int GEReq_endofscan()
Sets SSP word in sequence off_GEpass() to tell system that scan is done
Definition: GERequired.e:2590
float ksgre_scan_scanloop()
Plays out all passes of a single or multi-pass scan
Definition: ksgre_implementation.e:1925
STATUS ksgre_scan_init(void)
Common initialization for prescan entry points MPS2 and APS2 as well as the SCAN entry point...
Definition: ksgre_implementation.e:1984
KS_SEQ_CONTROL seqctrl
Definition: ksgre_implementation.e:45
KSGRE_SEQUENCE ksgre
Definition: ksgre_implementation.e:121
int rspent
Definition: GERequired.e:2626
PSD_EXIT_ARG psdexitarg

◆ abstract()

abstract ( "GRE Tutorial "  [KSFoundation])

◆ psdname()

psdname ( "ksgre_tutorial"  )

◆ ksgre_scan_sliceloop_nargs()

int ksgre_scan_sliceloop_nargs ( int  slperpass,
int  nargs,
void **  args 
)

Wrapper function to ksgre_scan_sliceloop() with standardized input arguments

For TR timing heat/SAR calculations of regular 2D multislice sequences, GEReq_eval_TR(), ks_eval_mintr() and GEReq_eval_checkTR_SAR() use a standardized function pointer with a fixed set of input arguments to call the sliceloop of the main sequence with different number of slices to check current slice loop duration. As different pulse sequences may need different number of input arguments (with different meaning) this ksgre_scan_sliceloop_nargs() wrapper function provides the argument translation for ksgre_scan_sliceloop().

The function pointer must have an integer corresponding to the number of slices to use as its first argument while the remaining input arguments (to ksgre_scan_sliceloop()) are stored in the generic void pointer array with nargs elements, which is then unpacked before calling ksgre_scan_sliceloop().

Parameters
[in]slperpassNumber of slices to play in the slice loop
[in]nargsNumber of extra input arguments to ksgre_scan_sliceloop() in range [0,4]
[in]argsVoid pointer array pointing to the variables containing the actual values needed for ksgre_scan_sliceloop()
Return values
slicelooptimeTime taken in [us] to play out slperpass slices
781  {
782  int passindx = 0;
783  int kyindx = KS_NOTSET; /* off */
784  int exc = 0;
785 
786  if (nargs < 0 || nargs > 3) {
787  ks_error("%s: 3rd arg (void **) must contain up to 4 elements: passindx, kyindx, exc", __FUNCTION__);
788  return -1;
789  } else if (nargs > 0 && args == NULL) {
790  ks_error("%s: 3rd arg (void **) cannot be NULL if nargs (2nd arg) != 0", __FUNCTION__);
791  return -1;
792  }
793 
794  if (nargs >= 1 && args[0] != NULL) {
795  passindx = *((int *) args[0]);
796  }
797  if (nargs >= 2 && args[1] != NULL) {
798  kyindx = *((int *) args[1]);
799  }
800  if (nargs >= 3 && args[2] != NULL) {
801  exc = *((int *) args[2]);
802  }
803 
804  return ksgre_scan_sliceloop(slperpass, passindx, kyindx, exc); /* in [us] */
805 
806 } /* ksgre_scan_sliceloop_nargs() */
#define KS_NOTSET
Definition: KSFoundation.h:103
STATUS ks_error(const char *format,...) __attribute__((format(printf
Common error message function for HOST and TGT
int ksgre_scan_sliceloop(int slperpass, int passindx, int kyindx, int exc)
Plays out slperpass slices corresponding to one TR
Definition: ksgre_tutorial_implementation.e:740
int passindx
Definition: ksgre_tutorial_implementation.e:907

◆ ksgre_scan_acqloop()

float ksgre_scan_acqloop ( int  passindx)

Plays out all phase encodes for all slices belonging to one pass

This function traverses through all phase encodes to be played out and runs the ksgre_scan_sliceloop() for each set of kyindx, and excitation. If ksgre_dda > 0, dummy scans will be played out before the phase encoding begins.

Parameters
[in]passindx0-based pass index in range [0, ks_slice_plan.npasses - 1]
Return values
passlooptimeTime taken in [us] to play out all phase encodes and excitations for slperpass slices. Note that the value is a float instead of int to avoid int overrange at 38 mins of scanning
824  {
825  float time = 0.0;
826  int dda, kyindx, exc;
827 
828  /* dummy scans for steady state */
829  for (dda = 0; dda < ksgre_dda; dda++) {
831  ks_plot_slicetime_endofslicegroup("ksgre dummy TR");
832  }
833  if (ksgre_dda > 0) {
835  }
836 
837  for (kyindx = 0; kyindx < ksgre.phaseenc.numlinestoacq; kyindx++) {
838  for (exc = 0; exc < (int) ceil(opnex); exc++) { /* ceil rounds up opnex < 1 (used for partial Fourier) to 1 */
839 
840  time += (float) ksgre_scan_sliceloop(ks_slice_plan.nslices_per_pass, passindx, kyindx, exc);
841 
842  } /* for exc */
843 
844 
845  ks_plot_slicetime_endofslicegroup("ksgre line");
846 
847  /* save a frame of the main sequence */
849 
850  } /* for kyindx */
851 
853 
854  return time; /* in [us] */
855 
856 } /* ksgre_scan_acqloop() */
#define KS_NOTSET
Definition: KSFoundation.h:103
void ks_plot_slicetime_endofpass(KS_PLOT_PASS_MODE)
Definition: KSFoundation_common.c:3412
int numlinestoacq
Definition: KSFoundation.h:1684
void ks_plot_tgt_addframe(KS_SEQ_CONTROL *ctrl)
Definition: KSFoundation_common.c:3488
void ks_plot_slicetime_endofslicegroup(const char *desc)
Definition: KSFoundation_common.c:3428
int ksgre_scan_sliceloop(int slperpass, int passindx, int kyindx, int exc)
Plays out slperpass slices corresponding to one TR
Definition: ksgre_tutorial_implementation.e:740
int nslices_per_pass
Definition: KSFoundation.h:1353
Definition: KSFoundation.h:339
KSGRE_SEQUENCE ksgre
Definition: ksgre_tutorial_implementation.e:78
int passindx
Definition: ksgre_tutorial_implementation.e:907
int ksgre_dda
Definition: ksgre_tutorial_implementation.e:66
KS_PHASER phaseenc
Definition: ksgre_implementation.e:49
KS_SEQ_CONTROL seqctrl
Definition: ksgre_implementation.e:45
KS_SLICE_PLAN ks_slice_plan
Definition: GERequired.e:217
Definition: KSFoundation.h:341

◆ ksgre_scan_scanloop()

float ksgre_scan_scanloop ( )

Plays out all passes of a single or multi-pass scan

This function traverses through all phase encodes to be played out, and runs the ksgre_scan_sliceloop() for each set of kyindx and excitation. If ksgre_dda > 0, dummy scans will be played out before the phase encoding begins.

Return values
scantimeTotal scan time in [us] (float to avoid int overrange after 38 mins)
871  {
872  float time = 0.0;
873 
874  for (volindx = 0; volindx < opfphases; volindx++) { /* opfphases is # volumes */
875 
877 
878  time += ksgre_scan_acqloop(passindx);
879 
880 #ifdef IPG
881  /* Send instruction to dump Pfile (if autolock = 1) and for GE's recon to start reconstructing the slices for current pass */
882  GEReq_endofpass();
883 #endif
884 
885  } /* end: acqs (pass) loop */
886 
887  } /* end: volume loop */
888 
889  return time;
890 
891 } /* ksgre_scan_scanloop() */
float ksgre_scan_acqloop(int passindx)
Plays out all phase encodes for all slices belonging to one pass
Definition: ksgre_tutorial_implementation.e:824
int npasses
Definition: KSFoundation.h:1352
int volindx
Definition: ksgre_tutorial_implementation.e:907
int passindx
Definition: ksgre_tutorial_implementation.e:907
int GEReq_endofpass()
Sets SSP word in sequence off_GEpass() to trigger data (Pfile) writing and reconstruction
Definition: GERequired.e:2574
KS_SLICE_PLAN ks_slice_plan
Definition: GERequired.e:217

◆ ksgre_scan_seqstate()

STATUS ksgre_scan_seqstate ( SCAN_INFO  slice_info,
int  kyview 
)

Sets the current state of all ksgre sequence objects being part of KSGRE_SEQUENCE

This function sets the current state of all ksgre sequence objects being part of KSGRE_SEQUENCE, incl. gradient amplitude changes, RF freq/phases and receive freq/phase based on current slice position and phase encoding indices.

The idea of having a 'seqstate' function is to be able to come back to a certain sequence state at any time and possibly play it out once more. This could for example be useful when certain lines or slices need to be rescanned due to image artifacts detected during scanning.

Parameters
[in]slice_infoPosition of the slice to be played out (one element in the ks_scan_info[] array)
[in]kyviewPhase encoding index related to ksgre.phaseenc. A value outside of [0, ksgre.phaseenc.res-1] will set the phase encoding gradient amplitude to 0.
Return values
STATUSSUCCESS or FAILURE
637  {
638  float rfphase = 0;
639 
640  /* rotate the slice plane */
641  ks_scan_rotate(slice_info);
642 
643  /* RF frequency & phase */
644  ks_scan_rf_on(&ksgre.selrfexc.rf, INSTRALL);
645  ks_scan_selrf_setfreqphase(&ksgre.selrfexc, 0 /* instance */, slice_info, rfphase);
646 
647  /* FOV offsets (by changing freq/phase of ksgre.read) */
648  ks_scan_offsetfov(&ksgre.read, INSTRALL, slice_info, kyview, opphasefov, rfphase);
649 
650  /* phase enc amp */
651  ks_scan_phaser_toline(&ksgre.phaseenc, 0, kyview);
652 
653  return SUCCESS;
654 
655 } /* ksgre_scan_seqstate() */
void ks_scan_rf_on(KS_RF *rf, int instanceno)
Resets the amplitude of one or all instances of an RF pulse (KS_RF)
Definition: KSFoundation_tgt.c:442
KS_SELRF selrfexc
Definition: ksgre_implementation.e:52
void ks_scan_selrf_setfreqphase(KS_SELRF *selrf, int instanceno, SCAN_INFO sliceinfo, float rfphase)
Updates the frequency and phase of one or all instances of a slice selective RF pulse (KS_SELRF)...
Definition: KSFoundation_tgt.c:581
KS_RF rf
Definition: KSFoundation.h:1485
KSGRE_SEQUENCE ksgre
Definition: ksgre_tutorial_implementation.e:78
void ks_scan_rotate(SCAN_INFO slice_info)
Performs a rotation of the logical system on hardware (WARP)
Definition: KSFoundation_tgt.c:989
KS_READTRAP read
Definition: ksgre_implementation.e:46
void ks_scan_phaser_toline(KS_PHASER *phaser, int instanceno, int view)
Updates the amplitude of a KS_PHASER sequence object to move from the k-space center to a desired k-s...
Definition: KSFoundation_tgt.c:340
KS_PHASER phaseenc
Definition: ksgre_implementation.e:49
void ks_scan_offsetfov(KS_READTRAP *readtrap, int instanceno, SCAN_INFO sliceinfo, float view, float phasefovratio, float rcvphase)
Updates the frequency and phase of one or all instances of a KS_READTRAP to create a FOV shift...
Definition: KSFoundation_tgt.c:968

◆ ksgre_init_imagingoptions()

void ksgre_init_imagingoptions ( void  )

Initial handling of imaging options buttons and top-level CVs at the PSD type-in page

Returns
void
134  {
135  int numopts = sizeof(sequence_iopts) / sizeof(int);
136 
137  psd_init_iopt_activity();
138  activate_iopt_list(numopts, sequence_iopts);
139  enable_iopt_list(numopts, sequence_iopts);
140 
141  /* Imaging option control functions (using PSD_IOPT_ZIP_512 as example):
142  - Make an option unchecked and not selectable: disable_ioption(PSD_IOPT_ZIP_512)
143  - Make an option checked and not selectable: set_required_disabled_option(PSD_IOPT_ZIP_512)
144  - Remove the imaging option: deactivate_ioption(PSD_IOPT_ZIP_512)
145  */
146 
147  /* default slice order is interleaved */
148  cvdef(opirmode, 0); opirmode = 0;
149 
150 } /* ksgre_init_imagingoptions() */
int sequence_iopts[]
Definition: ksgre_tutorial_implementation.e:108

◆ ksgre_init_UI()

STATUS ksgre_init_UI ( void  )

Initial setup of user interface (UI) with default values for menus and fields

Return values
STATUSSUCCESS or FAILURE
160  {
161 
162  /* Menus and button content
163  See epic.h or ksgre.e for more pi*** CVs to use to set up the user menus and buttons */
164 
165  /* Gradient Echo Type of sequence */
166  acq_type = TYPGRAD; /* loadrheader.e rheaderinit: sets eeff = 1 */
167 
168  /* show "Minimum" as 1st option in TR menu */
169  pitrval2 = PSD_MINIMUMTR;
170 
171  /* show "MinimumFull" as 1st option in TE menu */
172  pite1val2 = PSD_MINFULLTE;
173 
174  /* show flip angle menu */
175  pifanub = 2;
176 
177  /* hide second bandwidth option */
178  pircb2nub = 0;
179 
180  /* default low FA */
181  cvdef(opflip, 5);
182  opflip = _opflip.defval;
183 
184  return SUCCESS;
185 
186 } /* ksgre_init_UI() */

◆ ksgre_eval_UI()

STATUS ksgre_eval_UI ( )

Gets the current UI and checks for valid inputs

Return values
STATUSSUCCESS or FAILURE
205  {
206 
207  if (ksgre_init_UI() == FAILURE)
208  return FAILURE;
209 
210  /* add code here that is related to the user interface (i.e. scan parameter) changes */
211 
212  return SUCCESS;
213 
214 } /* ksgre_eval_UI() */
STATUS ksgre_init_UI(void)
Initial setup of user interface (UI) with default values for menus and fields
Definition: ksgre_tutorial_implementation.e:160

◆ ksgre_eval_setupobjects()

STATUS ksgre_eval_setupobjects ( )

Sets up all sequence objects for the main sequence module (KSGRE_SEQUENCE ksgre)

Return values
STATUSSUCCESS or FAILURE
224  {
225  STATUS status;
226 
227  /*******************************************************************************************************
228  * RF Excitation
229  *******************************************************************************************************/
230 
231  /* RF pulse choice (KSFoundation_GERF.h) */
233 
234  ksgre.selrfexc.rf.flip = opflip;
236 
237  /* selective RF excitation */
238  if (ks_eval_selrf(&ksgre.selrfexc, "rfexc") == FAILURE)
239  return FAILURE;
240 
241  /*******************************************************************************************************
242  * Readout
243  *******************************************************************************************************/
244 
245  ksgre.read.fov = opfov;
246  ksgre.read.res = RUP_FACTOR(opxres, 2); /* round up (RUP) to nearest multiple of 2 */
247  ksgre.read.acq.rbw = oprbw;
248  status = ks_eval_readtrap(&ksgre.read, "read");
249  if (status != SUCCESS) return status;
250 
251  /*******************************************************************************************************
252  * Readout dephaser
253  *******************************************************************************************************/
254 
256  status = ks_eval_trap(&ksgre.readdephaser, "readdephaser");
257  if (status != SUCCESS) return status;
258 
259  /*******************************************************************************************************
260  * Phase encoding
261  *******************************************************************************************************/
262 
263  ksgre.phaseenc.fov = opfov * opphasefov;
264  ksgre.phaseenc.res = RUP_FACTOR((int) (opyres * opphasefov), 2); /* round up (RUP) to nearest multiple of 2 */
265 
266  if (ks_eval_phaser(&ksgre.phaseenc, "phaseenc") == FAILURE)
267  return FAILURE;
268 
269  /*******************************************************************************************************
270  * Spoiler
271  *******************************************************************************************************/
272 
274  if (ks_eval_trap(&ksgre.spoiler, "spoiler") == FAILURE)
275  return FAILURE;
276 
277  /*******************************************************************************************************
278  * Init (reset) sequence control and set the SSI time
279  *******************************************************************************************************/
281  strcpy(ksgre.seqctrl.description, "ksgremain");
282  /* Copy SSI CV to seqctrl field used by setssitime() */
284 
285  return SUCCESS;
286 
287 } /* ksgre_eval_setupobjects() */
int res
Definition: KSFoundation.h:1678
int opxres
float ksgre_spoilerarea
Definition: ksgre_tutorial_implementation.e:64
int opyres
STATUS ks_eval_phaser(KS_PHASER *phaser, const char *const desc) WARN_UNUSED_RESULT
Sets up an acquisition window with a trapezoid with preset gradient constraints
Definition: KSFoundation_host.c:2073
STATUS ks_eval_selrf(KS_SELRF *selrf, const char *const desc) WARN_UNUSED_RESULT
Sets up a KS_SELRF object for RF slice selection with preset gradient constraints
Definition: KSFoundation_host.c:3032
float fov
Definition: KSFoundation.h:1576
KS_SELRF selrfexc
Definition: ksgre_implementation.e:52
float rbw
Definition: KSFoundation.h:734
float flip
Definition: KSFoundation.h:940
void ks_init_seqcontrol(KS_SEQ_CONTROL *seqcontrol)
Resets KS_SEQ_CONTROL to its default value (KS_INIT_SEQ_CONTROL)
Definition: KSFoundation_host.c:112
KS_RF rf
Definition: KSFoundation.h:1485
float ksgre_gscalerfexc
Definition: ksgre_tutorial_implementation.e:63
int res
Definition: KSFoundation.h:1577
float opfov
DECL_TYPE KS_RF exc_3dfgre
Definition: KSFoundation_GERF.c:74
STATUS ks_eval_trap(KS_TRAP *trap, const char *const desc) WARN_UNUSED_RESULT
Sets up a trapezoid using a KS_TRAP sequence object with preset gradient constraints
Definition: KSFoundation_host.c:434
KSGRE_SEQUENCE ksgre
Definition: ksgre_tutorial_implementation.e:78
float area
Definition: KSFoundation.h:582
KS_TRAP readdephaser
Definition: ksgre_implementation.e:47
KS_TRAP spoiler
Definition: ksgre_implementation.e:51
KS_READTRAP read
Definition: ksgre_implementation.e:46
int ssi_time
Definition: KSFoundation.h:1134
KS_PHASER phaseenc
Definition: ksgre_implementation.e:49
KS_SEQ_CONTROL seqctrl
Definition: ksgre_implementation.e:45
STATUS ks_eval_readtrap(KS_READTRAP *readtrap, const char *const desc) WARN_UNUSED_RESULT
Sets up an acquisition window with a trapezoid with preset gradient constraints
Definition: KSFoundation_host.c:733
KS_DESCRIPTION description
Definition: KSFoundation.h:1141
KS_READ acq
Definition: KSFoundation.h:1574
float opslthick
float area2center
Definition: KSFoundation.h:1584
float fov
Definition: KSFoundation.h:1677
int ksgre_ssi_time
Definition: ksgre_tutorial_implementation.e:65
float slthick
Definition: KSFoundation.h:1487

◆ ksgre_eval_TErange()

STATUS ksgre_eval_TErange ( )

Sets the min TE based on the durations of the sequence objects in KSGRE_SEQUENCE (ksgre)

Return values
STATUSSUCCESS or FAILURE
298  {
299 
300  /* Minimum TE */
301  avminte = ksgre.selrfexc.rf.iso2end;
302  avminte += IMax(3, \
306  avminte += ksgre.read.time2center - ksgre.read.acqdelay; /* from start of acq win to k-space center */
307  avminte = RUP_FACTOR(avminte + 8us, 8); /* add 8us margin and round up to make time divisible by 8us */
308 
309  if (opautote) {
310  setpopup(opte, PSD_OFF);
311  cvoverride(opte, avminte, PSD_FIX_ON, PSD_EXIST_ON); /* AutoTE: force TE to minimum */
312  } else {
313  setpopup(opte, PSD_ON);
314  if (opte < avminte)
315  opte = avminte;
316  }
317 
318  return SUCCESS;
319 
320 } /* ksgre_eval_TErange() */
KS_TRAP grad
Definition: KSFoundation.h:1491
KS_TRAP grad
Definition: KSFoundation.h:1676
KS_SELRF selrfexc
Definition: ksgre_implementation.e:52
KS_RF rf
Definition: KSFoundation.h:1485
KSGRE_SEQUENCE ksgre
Definition: ksgre_tutorial_implementation.e:78
KS_TRAP readdephaser
Definition: ksgre_implementation.e:47
KS_READTRAP read
Definition: ksgre_implementation.e:46
KS_TRAP postgrad
Definition: KSFoundation.h:1492
int iso2end
Definition: KSFoundation.h:945
KS_PHASER phaseenc
Definition: ksgre_implementation.e:49
int duration
Definition: KSFoundation.h:585
int time2center
Definition: KSFoundation.h:1585
int acqdelay
Definition: KSFoundation.h:1580
int ramptime
Definition: KSFoundation.h:583

◆ ksgre_eval_tr()

STATUS ksgre_eval_tr ( KS_SEQ_COLLECTION seqcollection)

Evaluation of number of slices / TR, set up of slice plan, TR validation and SAR checks

With the current sequence collection (see my_cveval()), and a function pointer to an argument-standardized wrapper function (ksgre_scan_sliceloop_nargs()) to the slice loop function (ksgre_scan_sliceloop(), this function calls GEReq_eval_TR(), where number of slices that can fit within one TR is determined by adding more slices as input argument to the slice loop function. For more details see GEReq_eval_TR().

With the number of slices/TR now known, a standard 2D slice plan is set up using ks_calc_sliceplan() and the duration of the main sequence is increased based on timetoadd_perTR, which was returned by GEReq_eval_TR(). timetoadd_perTR > 0 when optr > avmintr and when heat or SAR restrictions requires avmintr to be larger than the net sum of sequence modules in the slice loop.

At the end of this function, TR validation and heat/SAR checks are done using GEReq_eval_checkTR_SAR().

Parameters
[in]seqcollectionPointer to the KS_SEQ_COLLECTION struct holding all sequence modules
Return values
STATUSSUCCESS or FAILURE
344  {
345  int timetoadd_perTR;
346  STATUS status;
347  int slperpass, min_npasses;
348 
349  /* interleaved slices in slice gap menu, force 2+ acqs */
350  if (opileave)
351  min_npasses = 2;
352  else
353  min_npasses = 1;
354 
355  /* Calculate # slices per TR, # acquisitions and how much spare time we have within the current TR by running the slice loop, honoring heating and SAR limits */
356  status = GEReq_eval_TR(&slperpass, &timetoadd_perTR, min_npasses, seqcollection, ksgre_scan_sliceloop_nargs, 0, NULL);
357  if (status != SUCCESS) return status;
358 
359  /* Calculate the slice plan (ordering) and passes (acqs). ks_slice_plan is passed to GEReq_predownload_store_sliceplan() in predownload() */
360  ks_calc_sliceplan(&ks_slice_plan, exist(opslquant), slperpass);
361 
362  /* We spread the available timetoadd_perTR evenly, by increasing the .duration of each slice by timetoadd_perTR/slperpass */
363  ksgre.seqctrl.duration = RUP_GRD(ksgre.seqctrl.duration + CEIL_DIV(timetoadd_perTR, ks_slice_plan.nslices_per_pass));
364 
365  /* Update SAR values in the UI (error will occur if the sum of sequence durations differs from optr) */
367  if (status != SUCCESS) return status;
368 
369  return SUCCESS;
370 
371 } /* ksgre_eval_tr() */
STATUS GEReq_eval_checkTR_SAR(KS_SEQ_COLLECTION *seqcollection, int nslices, int(*play_loop)(int, int, void **), int nargs, void **args)
Runs the slice loop and validates TR and SAR/hardware limits
Definition: GERequired.e:963
int ksgre_scan_sliceloop_nargs(int slperpass, int nargs, void **args)
Wrapper function to ksgre_scan_sliceloop() with standardized input arguments
Definition: ksgre_tutorial_implementation.e:781
STATUS GEReq_eval_TR(int *slperpass, int *timetoadd_perTR, int requested_minacqs, KS_SEQ_COLLECTION *seqcollection, int(*play_loop)(int, int, void **), int nargs, void **args)
Definition: GERequired.e:719
int duration
Definition: KSFoundation.h:1135
int nslices_per_pass
Definition: KSFoundation.h:1353
KSGRE_SEQUENCE ksgre
Definition: ksgre_tutorial_implementation.e:78
KS_SEQ_CONTROL seqctrl
Definition: ksgre_implementation.e:45
STATUS ks_calc_sliceplan(KS_SLICE_PLAN *slice_plan, int nslices, int slperpass)
Calculates the data acquisition order for a standard interleaved 2D scans using one or more passes...
Definition: KSFoundation_host.c:4866
KS_SEQ_COLLECTION seqcollection
Definition: ksepi.e:80
KS_SLICE_PLAN ks_slice_plan
Definition: GERequired.e:217

◆ ksgre_check()

STATUS ksgre_check ( )

Returns error of various parameter combinations that are not allowed for ksgre

Return values
STATUSSUCCESS or FAILURE
390  {
391 
392 
393  return SUCCESS;
394 
395 } /* ksgre_check() */

◆ ksgre_predownload_plot()

STATUS ksgre_predownload_plot ( KS_SEQ_COLLECTION seqcollection)

Plotting of sequence modules and slice timing to PNG/SVG/PDF files

The ks_plot_*** functions used in here will save plots to disk depending on the value of the CV ks_plot_filefmt (see KS_PLOT_FILEFORMATS). E.g. if ks_plot_filefmt = KS_PLOT_OFF, nothing will be written to disk. On the MR scanner, the output will be located in /usr/g/mrraw/plot/<ks_psdname>. In simulation, it will be placed in the current directory (./plot/).

Please see the documentation on how to install the required python version and links. Specifically, there must be a link /usr/local/bin/apython pointing to the Anaconda 2 python binary (v. 2.7).

In addition, the following text files is printed out

  • <ks_psdname>_objects.txt
426  {
427  char tmpstr[1000];
428 
429 #ifdef PSD_HW
430  sprintf(tmpstr, "/usr/g/mrraw/%s_objects.txt", ks_psdname);
431 #else
432  sprintf(tmpstr, "./%s_objects.txt", ks_psdname);
433 #endif
434  FILE *fp = fopen(tmpstr, "w");
435 
436  /* Note: 'fp' can be replaced with 'stdout' or 'stderr' to get these
437  values printed out in the WTools window in simulation. However,
438  heavy printing may result in that the WTools window closes,
439  why we here write to a file ksgre_objects.txt instead */
445  fclose(fp);
446 
447 
448  /* ks_plot_host():
449  Plot each sequence module as a separate file (PNG/SVG/PDF depending on ks_plot_filefmt (GERequired.e))
450  See KS_PLOT_FILEFORMATS in KSFoundation.h for options.
451  Note that the phase encoding amplitudes corresponds to the first shot, as set by the call to ksgre_scan_seqstate below */
454 
455  /* Sequence timing plot */
459 
460  /* ks_plot_tgt_reset():
461  Creates sub directories and clear old files for later use of ksgre_scan_acqloop()->ks_plot_tgt_addframe().
462  ks_plot_tgt_addframe() will only write in MgdSim (WTools) to avoid timing issues on the MR scanner. Hence,
463  unlike ks_plot_host() and the sequence timing plot, one has to open MgdSim and press RunEntry (and also
464  press PlotPulse several times after pressing RunEntry). */
466 
467 
468  return SUCCESS;
469 
470 } /* ksgre_predownload_plot() */
STATUS ksgre_scan_seqstate(SCAN_INFO slice_info, int kyview)
Sets the current state of all ksgre sequence objects being part of KSGRE_SEQUENCE
Definition: ksgre_tutorial_implementation.e:637
KS_SELRF selrfexc
Definition: ksgre_implementation.e:52
void ks_plot_host(KS_SEQ_COLLECTION *seqcollection, KS_PHASEENCODING_PLAN *plan)
Definition: KSFoundation_host.c:5585
char ks_psdname[256]
Definition: GERequired.e:221
void ks_plot_slicetime_begin()
Definition: KSFoundation_common.c:3396
void ks_plot_slicetime_end()
Definition: KSFoundation_common.c:3437
KSGRE_SEQUENCE ksgre
Definition: ksgre_tutorial_implementation.e:78
KS_TRAP readdephaser
Definition: ksgre_implementation.e:47
float ksgre_scan_scanloop()
Plays out all passes of a single or multi-pass scan
Definition: ksgre_tutorial_implementation.e:871
void ks_print_phaser(KS_PHASER phaser, FILE *fp)
Writes out the contents of a KS_PHASER sequence object for debugging
Definition: KSFoundation_host.c:5198
KS_TRAP spoiler
Definition: ksgre_implementation.e:51
KS_READTRAP read
Definition: ksgre_implementation.e:46
void ks_print_trap(KS_TRAP trap, FILE *fp)
Writes out the contents of a KS_TRAP sequence object for debugging
Definition: KSFoundation_host.c:5168
KS_PHASER phaseenc
Definition: ksgre_implementation.e:49
KS_SEQ_CONTROL seqctrl
Definition: ksgre_implementation.e:45
void ks_plot_tgt_reset(KS_SEQ_CONTROL *ctrl)
Definition: KSFoundation_common.c:3445
KS_SEQ_COLLECTION seqcollection
Definition: ksepi.e:80
void ks_print_selrf(KS_SELRF selrf, FILE *fp)
Writes out the contents of a KS_SELRF sequence object for debugging
Definition: KSFoundation_host.c:5316
endif SCAN_INFO ks_scan_info[SLTAB_MAX]
Definition: GERequired.e:215
void ks_print_readtrap(KS_READTRAP readtrap, FILE *fp)
Writes out the contents of a KS_READTRAP sequence object for debugging
Definition: KSFoundation_host.c:5179

◆ ksgre_predownload_setrecon()

STATUS ksgre_predownload_setrecon ( )

Last-resort function to override certain recon variables not set up correctly already

For most cases, the GEReq_predownload_*** functions in predownload() in ksgre.e set up the necessary rh*** variables for the reconstruction to work properly. However, if this sequence is customized, certain rh*** variables may need to be changed. Doing this here instead of in predownload() directly separates these changes from the standard behavior.

Return values
STATUSSUCCESS or FAILURE
484  {
485 
486  return SUCCESS;
487 
488 } /* ksgre_predownload_setrecon() */

◆ ksgre_pg()

STATUS ksgre_pg ( )

The ksgre (main) pulse sequence

This is the main pulse sequence in ksgre.e using the sequence objects in KSGRE_SEQUENCE with the sequence module name "ksgremain" (= ksgre.seqctrl.description)

Return values
STATUSSUCCESS or FAILURE
516  {
517  KS_SEQLOC tmploc = KS_INIT_SEQLOC;
518  int readstart_pos;
519  int endofseq_pos;
520  STATUS status;
521 
522 
523  /*******************************************************************************************************
524  * RF Excitation
525  *******************************************************************************************************/
526  tmploc.pos = RUP_GRD(KS_RFSSP_PRETIME);
527  tmploc.board = ZGRAD;
528 
529  /* N.B.: ks_pg_selrf()->ks_pg_rf() detects that ksgre.selrfexc is an excitation pulse
530  (ksgre.selrfexc.rf.role = KS_RF_ROLE_EXC) and will also set ksgre.seqctrl.momentstart
531  to the absolute position in [us] of the isocenter of the RF excitation pulse */
532  status = ks_pg_selrf(&ksgre.selrfexc, tmploc, &ksgre.seqctrl);
533  if (status != SUCCESS) return status;
534 
535  /*******************************************************************************************************
536  * Readout timing
537  *******************************************************************************************************/
538 
539  /* With ksgre.seqctrl.momentstart set by ks_pg_selrf(&ksgre.selrfexc, ...), the absolute readout position
540  can be determined (for both full Fourier and partial Fourier readouts using ksgre.read.time2center) */
541  readstart_pos = ksgre.seqctrl.momentstart + opte - ksgre.read.time2center;
542 
543  /*******************************************************************************************************
544  * Phase encoding
545  *******************************************************************************************************/
546 
547  tmploc.pos = readstart_pos + RUP_GRD(ksgre.read.acqdelay) - ksgre.phaseenc.grad.duration;
548  tmploc.board = YGRAD;
549 
550  status = ks_pg_phaser(&ksgre.phaseenc, tmploc, &ksgre.seqctrl);
551  if (status != SUCCESS) return status;
552 
553  /* set phase encode amps to first ky view (for plotting & moment calcs in WTools) */
555 
556  /*******************************************************************************************************
557  * Readout dephaser
558  *******************************************************************************************************/
559 
560  tmploc.pos = readstart_pos - ksgre.readdephaser.duration;
561  tmploc.board = XGRAD;
562 
563  status = ks_pg_trap(&ksgre.readdephaser, tmploc, &ksgre.seqctrl);
564  if (status != SUCCESS) return status;
565 
566  /*******************************************************************************************************
567  * Readout
568  *******************************************************************************************************/
569 
570  tmploc.pos = readstart_pos;
571  tmploc.board = XGRAD;
572 
573  status = ks_pg_readtrap(&ksgre.read, tmploc, &ksgre.seqctrl);
574  if (status != SUCCESS) return status;
575 
576  /*******************************************************************************************************
577  * Spoiler
578  *******************************************************************************************************/
579 
580  tmploc.pos = readstart_pos + ksgre.read.grad.duration;
581  tmploc.board = XGRAD;
582 
583  status = ks_pg_trap(&ksgre.spoiler, tmploc, &ksgre.seqctrl);
584  if (status != SUCCESS) return status;
585 
586  /*******************************************************************************************************
587  * Set the minimal sequence duration (ksgre.seqctrl.min_duration) by calling
588  * ks_eval_seqctrl_setminduration()
589  *******************************************************************************************************/
590 
591  endofseq_pos = RUP_GRD(tmploc.pos + ksgre.spoiler.duration);
592 
593 #ifdef HOST_TGT
594  /* On HOST only: Sequence duration (ksgre.seqctrl.ssi_time must be > 0 and is added to ksgre.seqctrl.min_duration in ks_eval_seqctrl_setminduration() */
595  ks_eval_seqctrl_setminduration(&ksgre.seqctrl, endofseq_pos); /* endofseq_pos now corresponds to the end of last gradient in the sequence */
596 #endif
597 
598  return SUCCESS;
599 
600 } /* ksgre_pg() */
KS_TRAP grad
Definition: KSFoundation.h:1676
int pos
Definition: KSFoundation.h:389
STATUS ks_pg_readtrap(KS_READTRAP *readtrap, KS_SEQLOC loc, KS_SEQ_CONTROL *ctrl) WARN_UNUSED_RESULT
Places a KS_READTRAP sequence object on a board at some position in the pulse sequence
Definition: KSFoundation_common.c:1785
STATUS ks_pg_phaser(KS_PHASER *phaser, KS_SEQLOC loc, KS_SEQ_CONTROL *ctrl) WARN_UNUSED_RESULT
Places a KS_PHASER sequence object on a board at some position in the pulse sequence
Definition: KSFoundation_common.c:1669
KS_SELRF selrfexc
Definition: ksgre_implementation.e:52
STATUS ks_pg_selrf(KS_SELRF *selrf, KS_SEQLOC loc, KS_SEQ_CONTROL *ctrl) WARN_UNUSED_RESULT
Places a KS_SELRF sequence object on a gradient (and RF) board at some position in the pulse sequence...
Definition: KSFoundation_common.c:2204
int momentstart
Definition: KSFoundation.h:1136
int board
Definition: KSFoundation.h:388
KS_TRAP grad
Definition: KSFoundation.h:1586
STATUS ks_pg_trap(KS_TRAP *trap, KS_SEQLOC loc, KS_SEQ_CONTROL *ctrl) WARN_UNUSED_RESULT
Places a KS_TRAP sequence object on a board at some position in the pulse sequence
Definition: KSFoundation_common.c:1475
KSGRE_SEQUENCE ksgre
Definition: ksgre_tutorial_implementation.e:78
KS_TRAP readdephaser
Definition: ksgre_implementation.e:47
KS_TRAP spoiler
Definition: ksgre_implementation.e:51
typedef struct used as argument to ks_pg_*** functions to control where and when to place a sequence ...
Definition: KSFoundation.h:387
KS_READTRAP read
Definition: ksgre_implementation.e:46
void ks_scan_phaser_toline(KS_PHASER *phaser, int instanceno, int view)
Updates the amplitude of a KS_PHASER sequence object to move from the k-space center to a desired k-s...
Definition: KSFoundation_tgt.c:340
KS_PHASER phaseenc
Definition: ksgre_implementation.e:49
STATUS ks_eval_seqctrl_setminduration(KS_SEQ_CONTROL *seqctrl, int mindur)
Sets the minimum duration and duration fields of a KS_SEQ_CONTROL struct based on some minimum time (...
Definition: KSFoundation_host.c:4281
KS_SEQ_CONTROL seqctrl
Definition: ksgre_implementation.e:45
#define KS_INIT_SEQLOC
Definition: KSFoundation.h:208
int duration
Definition: KSFoundation.h:585
int time2center
Definition: KSFoundation.h:1585
int acqdelay
Definition: KSFoundation.h:1580
#define KS_RFSSP_PRETIME
Definition: KSFoundation.h:152

◆ ksgre_scan_coreslice()

int ksgre_scan_coreslice ( const SCAN_INFO *  slice_pos,
int  dabslice,
int  kyindx,
int  exc 
)

Plays out one slice in real time during scanning together with other active sequence modules

On TGT on the MR system (PSD_HW), this function sets up (ksgre_scan_seqstate()) and plays out the core ksgre sequence with optional sequence modules also called in this function. The low-level function call startseq(), which actually starts the realtime sequence playout is called from within ks_scan_playsequence(), which in addition also returns the time to play out that sequence module (see time += ...).

On HOST (in ksgre_eval_tr()) we call ksgre_scan_sliceloop_nargs(), which in turn calls this function that returns the total time in [us] taken to play out this core slice. These times are increasing in each parent function until ultimately ksgre_scan_scantime(), which returns the total time of the entire scan.

After each call to ks_scan_playsequence(), ks_plot_slicetime() is called to add slice-timing information on file for later PDF-generation of the sequence. As scanning is performed in real-time and may fail if interrupted, ks_plot_slicetime() will return quietly if it detects both IPG (TGT) and PSD_HW (on the MR scanner). See predownload() for the PNG/PDF generation.

Parameters
[in]slice_posPosition of the slice to be played out (one element in the global ks_scan_info[] array)
[in]dabslice0-based slice index for data storage
[in]kyindxPhase encoding index related to ksgre.phaseenc. A value outside of [0, ksgre.phaseenc.res-1] will set the phase encoding gradient amplitude to 0.
[in]excExcitation index in range [0, NEX-1], where NEX = number of excitations (opnex)
Return values
coreslicetimeTime taken in [us] to play out one slice with potentially other sequence modules
688  {
689  int echoindx;
690  int dabop, dabview;
691  TYPDAB_PACKETS acqflag;
692  int time = 0;
693  float tloc = 0.0;
694 
695  if (slice_pos != NULL) {
696  /* modify sequence for next playout */
697  ksgre_scan_seqstate(*slice_pos, ksgre.phaseenc.linetoacq[kyindx]);
698  tloc = slice_pos->optloc;
699  } else {
700  /* false slice, shut off RF */
701  ks_scan_rf_off(&ksgre.selrfexc.rf, INSTRALL);
702  }
703 
704  /* data acquisition control */
705  acqflag = (kyindx >= 0 && slice_pos != NULL && dabslice >= 0) ? DABON : DABOFF; /* open or close data receiver */
706  dabop = (exc <= 0) ? DABSTORE : DABADD; /* replace or add to data */
707  dabview = (kyindx >= 0) ? ksgre.phaseenc.linetoacq[kyindx] : KS_NOTSET;
708 
709  for (echoindx = 0; echoindx < ksgre.read.acq.base.ngenerated; echoindx++) {
710  loaddab(&ksgre.read.acq.echo[echoindx], dabslice, echoindx, dabop, dabview + 1, acqflag, PSD_LOAD_DAB_ALL);
711  }
712 
714 
715  KS_PLOT_EXCITATION_MODE plottag = (slice_pos == NULL) ? KS_PLOT_NO_EXCITATION : KS_PLOT_STANDARD;
716  ks_plot_slicetime(&ksgre.seqctrl, 1, &tloc, opslthick, plottag);
717 
718  return time; /* in [us] */
719 
720 } /* ksgre_scan_coreslice() */
WF_PULSE * echo
Definition: KSFoundation.h:738
STATUS ksgre_scan_seqstate(SCAN_INFO slice_info, int kyview)
Sets the current state of all ksgre sequence objects being part of KSGRE_SEQUENCE
Definition: ksgre_tutorial_implementation.e:637
#define KS_NOTSET
Definition: KSFoundation.h:103
KS_PLOT_EXCITATION_MODE
Definition: KSFoundation.h:334
KS_SELRF selrfexc
Definition: ksgre_implementation.e:52
int linetoacq[KS_MAX_PHASEDYN]
Definition: KSFoundation.h:1685
void ks_scan_rf_off(KS_RF *rf, int instanceno)
Sets the amplitude of one or all instances of an RF pulse (KS_RF) to zero
Definition: KSFoundation_tgt.c:469
KS_BASE base
Definition: KSFoundation.h:731
KS_RF rf
Definition: KSFoundation.h:1485
int ks_scan_playsequence(KS_SEQ_CONTROL *ctrl)
Definition: KSFoundation_tgt.c:1368
Definition: KSFoundation.h:336
KSGRE_SEQUENCE ksgre
Definition: ksgre_tutorial_implementation.e:78
Definition: KSFoundation.h:335
KS_READTRAP read
Definition: ksgre_implementation.e:46
KS_PHASER phaseenc
Definition: ksgre_implementation.e:49
void ks_plot_slicetime(KS_SEQ_CONTROL *ctrl, int nslices, float *slicepos_mm, float slthick_mm, KS_PLOT_EXCITATION_MODE exctype)
Definition: KSFoundation_common.c:3404
KS_SEQ_CONTROL seqctrl
Definition: ksgre_implementation.e:45
int ngenerated
Definition: KSFoundation.h:410
KS_READ acq
Definition: KSFoundation.h:1574
float opslthick

◆ ksgre_scan_sliceloop()

int ksgre_scan_sliceloop ( int  slperpass,
int  passindx,
int  kyindx,
int  exc 
)

Plays out slperpass slices corresponding to one TR

This function gets a spatial slice location index based on the pass index and temporal position within current pass. It then calls ksgre_scan_coreslice() to play out one coreslice (i.e. the main ksgre main sequence + optional sequence modules, excluding inversion modules).

Parameters
[in]slperpassNumber of slices to play in the slice loop
[in]passindx0-based pass index in range [0, ks_slice_plan.npasses - 1]
[in]kyindxPhase encoding index related to ksgre.phaseenc. A value outside of [0, ksgre.phaseenc.res-1] will set the phase encoding gradient amplitude to 0.
[in]excExcitation index in range [0, NEX-1], where NEX = number of excitations (opnex)
Return values
slicelooptimeTime taken in [us] to play out slperpass slices
740  {
741  int time = 0;
742  int slloc, sltimeinpass;
743 
744  for (sltimeinpass = 0; sltimeinpass < slperpass; sltimeinpass++) {
745 
746  /* slice location from slice plan (KS_NOTSET (= -1) means dummy slice) */
747  slloc = ks_scan_getsliceloc(&ks_slice_plan, passindx, sltimeinpass);
748 
749  time += ksgre_scan_coreslice((slloc != KS_NOTSET) ? &ks_scan_info[slloc] : NULL, sltimeinpass, kyindx, exc);
750 
751  }
752 
753  return time; /* in [us] */
754 
755 } /* ksgre_scan_sliceloop() */
#define KS_NOTSET
Definition: KSFoundation.h:103
int passindx
Definition: ksgre_tutorial_implementation.e:907
int ksgre_scan_coreslice(const SCAN_INFO *slice_pos, int dabslice, int kyindx, int exc)
Plays out one slice in real time during scanning together with other active sequence modules...
Definition: ksgre_tutorial_implementation.e:688
KS_SLICE_PLAN ks_slice_plan
Definition: GERequired.e:217
int ks_scan_getsliceloc(const KS_SLICE_PLAN *slice_plan, int passindx, int sltimeinpass)
Returns the spatially sorted slice index from a DATA_ACQ_ORDER struct array
Definition: KSFoundation_tgt.c:1023
endif SCAN_INFO ks_scan_info[SLTAB_MAX]
Definition: GERequired.e:215

◆ ksgre_scan_init()

STATUS ksgre_scan_init ( void  )

Common initialization for prescan entry points MPS2 and APS2 as well as the SCAN entry point

Return values
STATUSSUCCESS or FAILURE
926  {
927 
928  GEReq_initRSP();
929 
930  /* Here goes code common for APS2, MPS2 and SCAN */
931 
932  ks_scan_switch_to_sequence(&ksgre.seqctrl); /* switch to main sequence */
933  scopeon(&seqcore); /* Activate scope for core */
934  syncon(&seqcore); /* Activate sync for core */
935  setssitime(ksgre.seqctrl.ssi_time/HW_GRAD_UPDATE_TIME);
936 
937  /* can we make these independent on global rsptrigger and rsprot in orderslice? */
938  settriggerarray( (short) ks_slice_plan.nslices_per_pass, rsptrigger);
939 
940  return SUCCESS;
941 
942 } /* ksgre_scan_init() */
void ks_scan_switch_to_sequence(KS_SEQ_CONTROL *ctrl)
Definition: KSFoundation_tgt.c:1356
STATUS setssitime(long)
int nslices_per_pass
Definition: KSFoundation.h:1353
void GEReq_initRSP(void)
RSP Init. To be inserted in the psdinit() function (or scan()) in the main sequence
Definition: GERequired.e:2683
KSGRE_SEQUENCE ksgre
Definition: ksgre_tutorial_implementation.e:78
int ssi_time
Definition: KSFoundation.h:1134
KS_SEQ_CONTROL seqctrl
Definition: ksgre_implementation.e:45
KS_SLICE_PLAN ks_slice_plan
Definition: GERequired.e:217

◆ ksgre_scan_prescanloop()

STATUS ksgre_scan_prescanloop ( int  nloops,
int  dda 
)

Prescan loop called from both APS2 and MPS2 entry points

Return values
STATUSSUCCESS or FAILURE
951  {
952  int i, echoindx, sltimeinpass, slloc;
953 
954  /* turn off receivers for all echoes */
955  for (echoindx = 0; echoindx < ksgre.read.acq.base.ngenerated; echoindx++) {
956  loaddab(&ksgre.read.acq.echo[echoindx], 0, 0, DABSTORE, 0, DABOFF, PSD_LOAD_DAB_ALL);
957  }
958 
959  /* play first 'dda' dummy scans to get into steady state before start acquiring data */
960  for (i = -dda; i < nloops; i++) {
961 
962  /* loop over slices */
963  for (sltimeinpass = 0; sltimeinpass < ks_slice_plan.nslices_per_pass; sltimeinpass++) {
964 
965  slloc = ks_scan_getsliceloc(&ks_slice_plan, 0, sltimeinpass);
966 
967  /* modify sequence for next playout */
968  ksgre_scan_seqstate(ks_scan_info[slloc], KS_NOTSET); /* KS_NOTSET => no phase encoding */
969 
970  /* data routing control */
971  if (i >= 0) {
972  /* turn on receiver for 1st echo */
973  if (ksgre.read.acq.base.ngenerated > 0)
974  loaddab(&ksgre.read.acq.echo[0], 0, 0, DABSTORE, 0, DABON, PSD_LOAD_DAB_ALL);
975  }
976 
978 
979  } /* for slices */
980 
981  } /* for nloops */
982 
983  return SUCCESS;
984 
985 } /* ksgre_scan_prescanloop() */
WF_PULSE * echo
Definition: KSFoundation.h:738
STATUS ksgre_scan_seqstate(SCAN_INFO slice_info, int kyview)
Sets the current state of all ksgre sequence objects being part of KSGRE_SEQUENCE
Definition: ksgre_tutorial_implementation.e:637
#define KS_NOTSET
Definition: KSFoundation.h:103
int32_t i
Definition: KSFoundation_tgt.c:1389
KS_BASE base
Definition: KSFoundation.h:731
int nslices_per_pass
Definition: KSFoundation.h:1353
int ks_scan_playsequence(KS_SEQ_CONTROL *ctrl)
Definition: KSFoundation_tgt.c:1368
KSGRE_SEQUENCE ksgre
Definition: ksgre_tutorial_implementation.e:78
KS_READTRAP read
Definition: ksgre_implementation.e:46
KS_SEQ_CONTROL seqctrl
Definition: ksgre_implementation.e:45
KS_SLICE_PLAN ks_slice_plan
Definition: GERequired.e:217
int ks_scan_getsliceloc(const KS_SLICE_PLAN *slice_plan, int passindx, int sltimeinpass)
Returns the spatially sorted slice index from a DATA_ACQ_ORDER struct array
Definition: KSFoundation_tgt.c:1023
int ngenerated
Definition: KSFoundation.h:410
KS_READ acq
Definition: KSFoundation.h:1574
endif SCAN_INFO ks_scan_info[SLTAB_MAX]
Definition: GERequired.e:215

Variable Documentation

◆ seqcollection

KS_SEQ_COLLECTION seqcollection

◆ ksgre_gscalerfexc

float ksgre_gscalerfexc = 0.9

◆ ksgre_spoilerarea

float ksgre_spoilerarea = 2000.0 with {0.0, 10000.0, 2000.0, VIS, "ksgre spoiler gradient area",}

◆ ksgre_ssi_time

int ksgre_ssi_time = KSGRE_DEFAULT_SSI_TIME with {32, , KSGRE_DEFAULT_SSI_TIME, VIS, "time from eos to ssi in intern trig",}

◆ ksgre_dda

int ksgre_dda = 2 with {0, 200, 2, VIS, "Number of dummy scans for steady state",}

◆ ksgre

◆ sequence_iopts

int sequence_iopts[]
Initial value:
= {
PSD_IOPT_SEQUENTIAL
}

◆ volindx

int volindx

◆ passindx

int passindx