"**************************************************************"
"settabs - A macro to read tabname and menu1 for a protocol    "
"          from the local Experiment Selector.xml and set these"
"          items in the protocol.xml file.  Argument 1 is the  "
"          root name of the protocol - the first character is  "
"          case insensitive.                                   "
"                                                              "
"          Fields for tabname=, menu1= and menu2= are placed   "
"          after the field for seqfil= and tabname and menu1   "
"          are given values from ExperimentSelector.xml. The   "
"          macro will abort if the fields are already present  "
"          or if seqfil is not the last field of the line.     " 
"          Use replacetext or updatetext to preapare one or    "
"          more protocol.xml files for settabs.                "
"**************************************************************"         
 
$expsel = userdir + '/templates/vnmrj/interface/ExperimentSelector.xml.orig'
exists($expsel,'file'):$e
if ($e < 0.5) then 
   write('error','ExperimentSelector.xml does not exist')
   return
endif 

format($1,'upper'):$name_upper
substr($name_upper,1,1):$upper_character
length($1):$length
substr($1,2,$length - 1):$last_characters
$name_protocol = $upper_character + $last_characters

$search = $name_protocol
write('alpha','protocol = %s',$search)
lookup('file',$expsel)
lookup('delimiter','"')
lookup('seek',$search)
lookup('skip')
lookup('skip')
$tabstring =''
lookup('read'):$tabstring 
lookup('skip')
$menu1string =''
lookup('read'):$menu1string

$repfile = userdir + '/templates/vnmrj/protocols/' + $search + '.xml'
exists($repfile,'file'):$e
if ($e < 0.5) then 
   write('error','%s.xml does not exist',$repfile)
   return
endif 
lookup('file',$repfile)
$repfile1=''
format($1,'lower'):$repfile1
$search1 = 'seqfil="' + $repfile1 + '">'
$times=0
lookup('count',$search1):$times
if ($times < 0.5) then 
   write('alpha','Replacement can not be made')
   return
endif
$replacestring = '\\1 tabname="' + $tabstring + '" menu1="' + $menu1string + '" menu2=""'
replacetext($repfile,'\\(seqfil=.[a-zA-Z0-9]*.\\)',$replacestring)



