$input_path = userdir
$sequence_name = 'SIMPLEXER'
format($sequence_name,'upper'):$name_upper
format($sequence_name,'lower'):$name_lower

$archive_path =  userdir + '/ARCHIVE'
$output_path = $archive_path + '/' + $name_upper
$backup_path = 'none'

exists($archive_path,'directory'):$e
if ($e < 0.5) then 
   shell('mkdir ' + $archive_path)
endif
   
exists($output_path,'directory'):$e1
if ($e1 > 0.5) then 
   $i = 0
   $j = 0
   while (($i< 20) and ($j<20)) do 
      $j = $j + 1
      $i = $i + 1
      $istring=''
      format($i,1,0):$istring
      $backup_path = $output_path + '_' + $istring
      exists( $backup_path,'directory'):$e2
      if ($e2 > 0.5) then 
         if ($i = 20) then
            write('error','Too Many Backups: Abort')
            abort 
         endif
      else 
         shell('mv ' + $output_path + ' ' + $backup_path)
         write('error','Backup %s created',$istring)
         $i = 20
      endif
   endwhile
endif

shell('mkdir ' + $output_path)

"******** Create MACLIB ********"

$get_path = $input_path + '/maclib'
$put_path = $output_path +'/maclib'
shell('mkdir ' + $put_path)

"Items for Simplexer and Shimdriver"

archive_file($get_path,$put_path,'archive_SIMPLEXER')
archive_file($get_path,$put_path,'simplexer')
archive_file($get_path,$put_path,'SIMPLEXER')
archive_file($get_path,$put_path,'shimDriver')
archive_file($get_path,$put_path,'Simplexer')
archive_file($get_path,$put_path,'shimdriver')
archive_file($get_path,$put_path,'initSimplex.tcl')
archive_file($get_path,$put_path,'killFile')
archive_file($get_path,$put_path,'pokeFOM')
archive_file($get_path,$put_path,'setMacroState')
archive_file($get_path,$put_path,'simplexOptions.tcl')
archive_file($get_path,$put_path,'asSetUp')
archive_file($get_path,$put_path,'buildQueue.tcl')
archive_file($get_path,$put_path,'buildQueue')
archive_file($get_path,$put_path,'buildqueue')
archive_file($get_path,$put_path,'initQueue.tcl')
archive_file($get_path,$put_path,'testQueue.tcl')
archive_file($get_path,$put_path,'genTempCommun')

"******** Create SIMPLEXER ********"

$get_path = $input_path + '/Simplexer'
$put_path = $output_path +'/Simplexer'
shell('mkdir ' + $put_path)

archive_file($get_path,$put_path,'onepul.s')
archive_file($get_path,$put_path,'tancpx.s')
archive_file($get_path,$put_path,'dcptan.s')
archive_file($get_path,$put_path,'wdumbogen1d.s')

"*********Add Current .DATE file ********"

$get_path = $backup_path
$put_path = $output_path 
$date_name = $name_lower + '.DATE'
$date_file = $backup_path + '/' + $date_name

exists($date_file,'file'):$e4
if ($e4 > 0.5) then
   archive_file($backup_path, $output_path, $date_name)
else
   $date_file = $output_path + '/' + $date_name
   write('file',$date_file,'%s:',$name_upper)
   endif
$date_file = $output_path + '/' + $date_name
$date='' shell('date +%Y%m%d%H%M%S'):$date
write('file',$date_file,'LAST ARCHIVE DATE: %s  %s',$date, userdir)

"******** Create SolidsPack.dir *********"

$get_path = $input_path + '/SolidsPack.dir'
$put_path = $output_path +'/SolidsPack.dir'
shell('mkdir ' + $put_path)

archive_file($get_path,$put_path,'SolidsPack.README')
archive_file($get_path,$put_path,'SP_doc')
archive_file($get_path,$put_path,'SP_rev')

"******** Add a TAR file of the directories ********"

$tar_file = $output_path + '/' + $name_lower + '.tar'
$directories = ''
$directories = $directories + ' -C ' + $output_path + ' maclib'
$directories = $directories + ' -C ' + $output_path + ' maclib_lowercase'
$directories = $directories + ' -C ' + $output_path + ' maclib_uppercase'
$directories = $directories + ' -C ' + $output_path + ' psglib'
$directories = $directories + ' -C ' + $output_path + ' parlib'
$directories = $directories + ' -C ' + $output_path + ' execpars'
$directories = $directories + ' -C ' + $output_path + ' templates'
$directories = $directories + ' -C ' + $output_path + ' psg' 
$directories = $directories + ' -C ' + $output_path + ' shapelib' 
$directories = $directories + ' -C ' + $output_path + ' manual'
$directories = $directories + ' -C ' + $output_path + ' adm'
$directories = $directories + ' -C ' + $output_path + ' wtlib'
$directories = $directories + ' -C ' + $output_path + ' Simplexer'
$directories = $directories + ' -C ' + $output_path + ' bin'
$directories = $directories + ' -C ' + $output_path + ' SolidsPack.dir'
$directories = $directories + ' -C ' + $output_path + ' README'
$directories = $directories + ' -C ' + $output_path + ' shims'

shell('tar cfz ' + $tar_file + '.Z ' + $directories)

$expoutput_path = $archive_path + '/EXP_OUTPUT'
exists($expoutput_path,'directory'):$e
if ($e < 0.5) then 
   shell('mkdir ' + $expoutput_path)
endif
$readme_file = $output_path + '/README/' + $name_lower + '.README'
shell('cp ' + $tar_file + '.Z  ' + $expoutput_path + '/' + $name_lower + '.tar.Z') 
shell('cp ' + $readme_file + ' ' + $expoutput_path + '/' + $name_lower + '.README')
 
write('alpha','ARCHIVE COMPLETE')
write('line3','ARCHIVE COMPLETE')





