"*************************************************************************"
"make_README(sequencename,templatename,date,INOVAVJ,VnmrSVJ) - Create a   "
"                    .README file for the sequence sequencename, using    "
"                    the userlib template, templatename. Optional argument"
"                    3 is the first publication date, optional argument 4 " 
"                    names the allowed software versions for INOVA and    " 
"                    optional argument 5 names the allowed software       " 
"                    versions for VnmrJ. The defaults are:                "
"                    $3 - '2010-11-01'                                    "
"                    $4 - 'VnmrJ2.2C-3.1A'                                "
"                    $5 - 'VnmrJ2.2C-3.1A'                                "
"                    A ~/vnmrsys/manual file must exist for the sequence  "
"                    name.                                                "

"           example: make_README('tancpx','userlibtemplate','2010-11-01', "
"                    'VnmrJ2.2C-3.1A','VnmrJ2.2D')                        "
"*************************************************************************"
$inFile = userdir + '/manual/' + $1
$userlibtemplate = userdir + '/manual/' +  $2
$outFile = userdir + '/README/' + $1 + '.README'
$usertempfile = userdir + '/manual/tempfile'

exists($usertempfile,'file'):$e
if ($e > 0.5) then 
   rm($usertempfile):$dum
endif
$cmd = 'cp ' + $userlibtemplate + ' ' + $usertempfile
shell($cmd)

$name_lower=''
$name_upper=''
format($1,'upper'):$name_upper
format($1,'lower'):$name_lower
replacetext($usertempfile,'xxxxx',$name_lower)

substr($name_upper,1,1):$first_character
length($1):$length
substr($name_lower,2,$length - 1):$last_characters
$name_protocol = $first_character + $last_characters 
replacetext($usertempfile,'Xxxxx',$name_protocol)

if ($# > 2) then 
   replacetext($usertempfile,'YYYY',$3)
else
   replacetext($usertempfile,'YYYY','2010-11-1')
endif

if ($# > 3) then 
   replacetext($usertempfile,'CCCC',$4)
else
   replacetext($usertempfile,'CCCC','VnmrJ2.2D only')
endif

if ($# > 4) then 
   replacetext($usertempfile,'BBBB',$5)
else
   replacetext($usertempfile,'BBBB','VnmrJ2.2C-3.1A')
endif

if ($# > 5) then 
   replacetext($usertempfile,'AAAA',$5)
else
   replacetext($usertempfile,'AAAA','VnmrJ2.2C-3.1A')
endif

exists($outFile,'file'):$e
if ($e > 0.5) then 
   rm($outFile):$dum
endif
$cmd = 'cat ' + $usertempfile + ' ' + $inFile + ' > ' + $outFile
shell($cmd)
