AMMRL: How to collect data at intervals on Varian - a solution

From: Margaret Eastman <meastman_at_chem.okstate.edu>
Date: Wed, 23 Apr 2008 17:11:02 -0500

Folks,
     Thanks to everyone who responded to my query. The task was to collect
automatically a series of 2D spectra with time delays between them and to
save the data automatically. There were a few different approaches offered,
but I am just going to describe below the one I chose to follow.
     First, note that if one wants to collect such a series of 1D spectra,
the method most likely chosen and quite convenient would be to array the
parameter ³pad², the pre-acquisition delay, and save all the spectra
together in an arrayed data set. For 2D (or higher dimensional) data, it
may be most convenient to save each spectrum in a separate data file so they
can be processed in the normal way. This is what I have done.
     This scheme is based upon using ³wexp² to call a macro that keeps the
acquisitions and saves going, as suggested by Bayard Fetler, Steve Silber,
and George Gray. The delays in Bayard¹s and Steve¹s macros are made with
the Unix ³sleep² function, which Steve says will lock up the command line
during the delay. So I have instead chosen to use ³pad² for the delay,
thereby allowing the user to interact in some ways with the console during
the delays. George says there is a limit of 8190 seconds on ³pad², but this
can be changed with the ³setlimit² command if longer delays are needed.
     I am including below both Bayard¹s macro (timexp) with some comments at
the beginning that I wrote, and my macro (tacqsv), which is based upon
timexp. My modifications are using ³pad², allowing ³pad² to have a series
of different values rather than just one, having the macro return to the
workspace/expt where it was started, and changing the naming convention for
the files. The overall structure of the macros is two-part: When they are
called without an argument, the introductory questions are asked and the
setup for future acquisitions and saves is done. When they are called with
an argument (by ³wexp²) data is saved, ³pad² is set, and a new acquisition
is started. The latter section also increments a counter to keep track of
the number of spectra required, and tests whether the final spectrum has
been reached. I like this scheme because all the user has to do is set up
acquisition parameters for the desired experiment, then type the macro name
and answer the setup questions. There is no need to edit a file or macro to
make this work for a variety of pulse sequences and situations.
     I hope this submission will be helpful both to people who need this
capability and to people who, like myself, have never tried to write a macro
before. If you had glanced at macros previously and been bewildered by all
those $¹s, please join me in the end of bewilderment, and understand that a
$ at the beginning of a name marks that variable as local, meaning that it
exists only while the macro is running. Such variables need to be announced
with an assignment statement like $s=¹¹ for a string or $s=1 for a real
variable, at least in cases where you cannot tell their usage such as when
they are about to be read in with an ³input² statement. These macros are a
good introduction to the local/global distinction. Since the macro does not
have continuous control, the setup information must be saved in the initial
pass mainly in the workspace-based parameters r1-r7 and n1-n3, which will
retain their values even after the macro is done executing. These
parameters are called ³global², but they are ³current² (attached to the
current workspace) and there is actually another level of ³global²
exemplified by my variable ³aexp² that saves the workspace/experiment
number. Bayard¹s macro provides a good introduction to macro-writing because
it is short and to the point but also includes many valuable features such
as reading input values, writing messages to the user, use of local and
workspace-based variables, and if statement structure. I struggled a bit
with finding a good way to save a vector/array of values for ³pad² to allow
the option of nonuniform delays. It turns out you cannot array r1-r7, and
if you create a new parameter in the workspace/experiment it causes the
acquisition to be arrayed. George came to the rescue here by pointing out
that the line list array ³llfrq², which does not cause arrayed acquisition,
can be appropriated to save the delay values.
     By homing to the experiment where the macro was launched, I am trying
to remove the need to avoid switching experiments. Note that we are saving
data between passes through the macro in the workspace-based parameters.
This means that we have to be back in the correct workspace when these
values are accessed to set ³pad², construct a filename, or check if the
total number of spectra requested (r2) has been acquired yet. What I have
done works pretty well but is not bulletproof. There could be a crash of
you switch workspaces just at the time when the macro is trying to set up
another acquisition. Therefore, I would say, if your delays are sec or just
a few min, stay in the original workspace and don¹t rock the boat. If you
have 1Ž2 - 1 hr delays or so, this gives enough time to switch expts and read
in and transform some data in another workspace. Just keep in mind that
switching can only be done while the spectrometer reports it is ³acquiring²
(during the pad delay and acquisition). {Bayard mentioned that: there is a
bug with some software versions where if you start a series of experiments
in one exp, then join another exp, then join back to the original exp, then
the wexp processing doesn't happen. This would throw a wrench in the works,
so watch out. In testing my macro on our Inova 400 with VNMRJ2.1B, I did
not encounter the bug.} {One thing that I still do not understand with my
macro is that if you switch experiments during the operation, the statements
written to Œline3¹, for example about saving the data, do not show up. You
still see the usual VNMR message about starting the acquisition, with the
exp number. ??}
Margaret
 
The macros (which do work with the caveats):
 
timexp
 
" macro 'timexp' by Bayard Fetler "
" Allows a series of experiments to be run with "
" time delays between them "
" Spectral data is automatically saved in the "
" user's vnmrsys/data directory with the names "
" <pulse_sequence_label>_01, _02, etc "
" DO NOT change experiments while operation "
" is in progress "
" Start the experiments by typing the macro name "
" without any argument (timexp) "
if($#=0) then
   r1=0
  input('number of exps to loop:'):r2
  input('time to wait between exps[sec]:'):r3
  if(r3<1) then return endif
  wexp='timexp(`start`)'
   au
else
   r1=r1+1
   $data = userdir+'/data/$pslabel$_'
  Svfname($data):$fidname
  write('line3','iteration %g of %g, saving data %s',r1,r2,$fidname)
  svf($fidname)
  if(r1<r2) then
      $s=''
      format(r3,1,0):$s
      write('line3','sleeping %g sec',r3)
      shell('sleep'+$s):$dum
      au
   else
      write('line3','timed experiments done')
   endif
endif
 
 
tacqsv
 
" macro 'tacqsv' by Margaret Eastman 04-23-08 "
" Allows a series of experiments to be run with time delays between them "
" Spectral data is automatically saved in the user's vnmrsys/data "
" directory with the names <pulse_sequence_label>_<date>_<time>_01 "
" or <user_entered_name>_<date>_<time>_01, if a name is entered "
" The time (and date if appropriate) increment with each spectrum and "
" reflect the ending time of data collection as recorded in the log file "
" Allows changing workspace while acquisition is in progress, "
" using non-uniform delays between experiments, and uses the 'pad' delay "
" 'llfrq' is used to hold the array of delay values if they are not "
" all the same "
" For uniform delays, the delay is 0 for the first spectrum; for "
" non-uniform delays, the user can enter any delay for the first spectrum "
" Start the expts by typing the macro name without any argument (tacqsv)"
" "
" initialize, ask for info, and run the first expt "
" when the macro is called without an argument ($# is 0)"
" "
if($#=0) then
" "
" set the exp counter to 0 "
" "
   r1=0
" "
" determine which workspace we are in, $exp_number"
" "
  $exp_number = 1
  $exp_name=''
  jexp:$exp_number,$exp_name
" "
" ask for input "
" "
  input('number of exps:'):r2
  write('line3','default file name is %s',pslabel)
  input('enter short name for data (or <ret> for default):'):n2
   if(n2 = '') then
       n2 = '$pslabel$'
   endif
  input('uniform time delay? [y or n]:'):n1
" "
" if a single uniform delay will be used, save it as r3"
" "
  if(n1='y' or n1='yes') then
      input('time to wait between exps [sec]:'):r3
" "
" for a uniform delay, set pad to 0 and acquire the first "
" spectrum immediately "
" "
      pad=0
" "
" do not allow the delay between exps to be less than 1 sec"
" "
      if(r3<1) then
        write('line3','delay of less than 1 sec not allowed')
         return
      endif
" "
" if nonuniform time delays will be entered, use the 'llfrq' "
" parameter to save these delays "
" "
   else
" "
" loop to read in the delays one by one "
" "
      $rc=1
      repeat
        input('enter a delay [sec]:'):llfrq[$rc]
        write('line3','%g-th delay entered: %g',$rc,llfrq[$rc])
        $rc=$rc+1
      until($rc>r2)
" "
" for nonuniform delays, the first pad is the first value entered, "
" allowing the first exp to be delayed if desired "
" "
      pad=llfrq[1]
   endif
" "
" create the global parameter aexp to save the workspace number "
" "
  $exists=0
  exists('aexp','parameter','global'):$exists
  if($exists<>1) then
       create('aexp','real','global') endif
  aexp=$exp_number
  write('line3','will return to exp %g',aexp)
  write('line3','will collect %g timed spectra',r2)
" "
" set wexp to return to this macro after acquisition "
" with an argument that is the workspace number "
" "
  wexp='tacqsv(aexp)'
" "
" acquire the first spectrum "
" "
   au
" "
" if($#=0) then "
" if the macro is invoked with an argument, this is an iteration "
" "
else
" "
" join the correct workspace, which is the argument of tacqsv "
" "
   jexp($1)
" "
" increment the experiment counter. note: this and further actions "
" must be done in the correct workspace, entered above "
" "
   r1=r1+1
" "
" create the file name for saving the data from the last iteration "
" "
   $data = userdir+'/data/'+n2+'_%DATE%_%TIME%_'
  Svfname($data):$fidname
  write('line3','iteration %g of %g, saving data %s',r1,r2,$fidname)
" "
" Save the data "
" "
  svf($fidname)
" "
" if experiments still need to be performed, set the delay "
" "
   jexp($1)
  if(r1<r2) then
      if(n1='y' or n1='yes') then
         pad=r3
      else
         $rc=r1+1
         pad=llfrq[$rc]
      endif
" "
" and acquire "
" "
      au
" "
" if the final requested exp is done, delete the aexp parameter "
" and exit "
" "
   else
      $exists=0
     exists('aexp','parameter','global'):$exists
      if($exists=1) then
          destroy('aexp','global') endif
      write('line3','timed experiments complete')
   endif
endif
 
Received on Wed Apr 23 2008 - 15:05:54 MST

This archive was generated by hypermail 2.4.0 : Wed Jun 14 2023 - 14:41:15 MST