$input_path = userdir
$sequence_name = 'SOLIDSDEVELOPER3'
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)

archive_file($get_path,$put_path,$0)
archive_file($get_path,$put_path,'archive_ALSOLIDSPACK3')

"Macros That Run Protocols"

archive_file($get_path,$put_path,'Settancpx')

"Apptype Macros"

archive_file($get_path,$put_path,'solidsseq1d')
archive_file($get_path,$put_path,'solids1d')
archive_file($get_path,$put_path,'fixtancpxpars')
archive_file($get_path,$put_path,'par2d')  "needed for vnmrj3.1 and later"

"Macros for Sequence Development" 

archive_file($get_path,$put_path,'archive_file')
archive_file($get_path,$put_path,'narchive_SEQUENCE3')
archive_file($get_path,$put_path,'clearallparams')
archive_file($get_path,$put_path,'clearnewparams')
archive_file($get_path,$put_path,'setnewparams')
archive_file($get_path,$put_path,'shownewparams')
archive_file($get_path,$put_path,'copypseq')
archive_file($get_path,$put_path,'capitalizestring')
archive_file($get_path,$put_path,'paramgroup')
archive_file($get_path,$put_path,'macroupdatepars')
archive_file($get_path,$put_path,'solidsetup')
archive_file($get_path,$put_path,'closesolidsetup')
archive_file($get_path,$put_path,'setupupdatepars')
archive_file($get_path,$put_path,'updatetext')
archive_file($get_path,$put_path,'updateprocpars')
archive_file($get_path,$put_path,'vtos')
archive_file($get_path,$put_path,'stov')
archive_file($get_path,$put_path,'make_README')
archive_file($get_path,$put_path,'make_all_README')
archive_file($get_path,$put_path,'replacetext')
archive_file($get_path,$put_path,'settabs')
archive_file($get_path,$put_path,'set_all_tabs')
archive_file($get_path,$put_path,'probeparamgroup')
archive_file($get_path,$put_path,'updatetemplates')

"Macros for the Tool Bar

archive_file($get_path,$put_path,'copyexp')

"******** Create README ********"

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

"README Files - needed for userlib submission of individual sequences"

archive_file($get_path,$put_path,'solidspackvj3.2.README')
archive_file($get_path,$put_path,'solidsdeveloper3.README')

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

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

"******** Create PSGLIB ********"

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



"******** Create PSG ********"

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

"******** Create PARLIB ********"

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

"parameter files for protocols have the protocol name"

archive_file($get_path,$put_path,'Settancpx.par') "primary RTP file"

"******** Create STUDYLIB ********"

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

archive_file($get_path,$put_path,'STDYdpC13H1adamALL')
archive_file($get_path,$put_path,'StdycpH1C13alphaALL')
archive_file($get_path,$put_path,'StdycpH1C13carbonylALL')
archive_file($get_path,$put_path,'StdycpH1N15amideALL')
archive_file($get_path,$put_path,'StdydcpN15C13alphaALL')
archive_file($get_path,$put_path,'StdydcpN15C13carbonylALL')

"******** Create EXECPARS ********"

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

archive_file($get_path,$put_path,'solids1d')
archive_file($get_path,$put_path,'solidsseq1d')

"******** Create MANUAL *********************"

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

"Manual Pages for Pulse Sequence Development" 

archive_file($get_path,$put_path,'archive_file')
archive_file($get_path,$put_path,'narchive_SEQUENCE3')
archive_file($get_path,$put_path,'AllParGroups')
archive_file($get_path,$put_path,'AllSeqTitles')
archive_file($get_path,$put_path,'SolidsPack')
archive_file($get_path,$put_path,'SolidsPackChanges')
archive_file($get_path,$put_path,'clearallparams')
archive_file($get_path,$put_path,'clearnewparams')
archive_file($get_path,$put_path,'setnewparams')
archive_file($get_path,$put_path,'shownewparams')
archive_file($get_path,$put_path,'copypseq')
archive_file($get_path,$put_path,'capitalizestring')
archive_file($get_path,$put_path,'paramgroup')
archive_file($get_path,$put_path,'macroupdatepars')
archive_file($get_path,$put_path,'solidsetup')
archive_file($get_path,$put_path,'closesolidsetup')
archive_file($get_path,$put_path,'setupupdatepars')
archive_file($get_path,$put_path,'updateprocpars')
archive_file($get_path,$put_path,'updatetext')
archive_file($get_path,$put_path,'userlibtemplate')
archive_file($get_path,$put_path,'replacetext')
archive_file($get_path,$put_path,'make_README')
archive_file($get_path,$put_path,'make_all_README')
archive_file($get_path,$put_path,'settabs')
archive_file($get_path,$put_path,'set_all_tabs')
archive_file($get_path,$put_path,'reset_cp')
archive_file($get_path,$put_path,'updatetemplates')

"******** Create TEMPLATES/LAYOUT ***********"

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

archive_file($get_path,$put_path,'solidsdefault')

"******** Create TEMPLATES/VNMRJ/PROTOCOLS ***********"

$get_path = $input_path + '/templates/vnmrj/protocols'
$put_path = $output_path +'/templates/vnmrj'
shell('mkdir ' + $put_path)
$put_path = $put_path +'/protocols'
shell('mkdir ' + $put_path)

archive_file($get_path,$put_path,'Settancpx.xml')

"******** Create TEMPLATES/VNMRJ/PANELITEMS ***********"

$get_path = $input_path + '/templates/vnmrj/panelitems'
$put_path = $output_path +'/templates/vnmrj'
shell('mkdir ' + $put_path)
$put_path = $put_path +'/panelitems'
shell('mkdir ' + $put_path)

archive_file($get_path,$put_path,'cpHX.xml')
archive_file($get_path,$put_path,'Htppm.xml')
archive_file($get_path,$put_path,'Hspinal.xml')
archive_file($get_path,$put_path,'180X.xml')
archive_file($get_path,$put_path,'spinlockX.xml')
archive_file($get_path,$put_path,'c7X.xml')
archive_file($get_path,$put_path,'fslgX.xml')
archive_file($get_path,$put_path,'fslgH.xml')
archive_file($get_path,$put_path,'prepX.xml')
archive_file($get_path,$put_path,'br24X.xml')
archive_file($get_path,$put_path,'mrev8X.xml')
archive_file($get_path,$put_path,'swwhh4X.xml')
archive_file($get_path,$put_path,'idrefX.xml')
archive_file($get_path,$put_path,'tossX.xml')
archive_file($get_path,$put_path,'tune.xml')
archive_file($get_path,$put_path,'echoX.xml')
archive_file($get_path,$put_path,'180H.xml')
archive_file($get_path,$put_path,'mqmasX.xml')
archive_file($get_path,$put_path,'zfselX.xml')
archive_file($get_path,$put_path,'3QshearX.xml')
archive_file($get_path,$put_path,'5QshearX.xml')
archive_file($get_path,$put_path,'xy8XY.xml')
archive_file($get_path,$put_path,'Hmixtppm.xml')
archive_file($get_path,$put_path,'Hmixspinal.xml')
archive_file($get_path,$put_path,'xy8Y.xml')
archive_file($get_path,$put_path,'xxX.xml')
archive_file($get_path,$put_path,'xmxX.xml')
archive_file($get_path,$put_path,'prep1X.xml')
archive_file($get_path,$put_path,'mixX.xml')
archive_file($get_path,$put_path,'mixH.xml')
archive_file($get_path,$put_path,'pmlgX.xml')
archive_file($get_path,$put_path,'wpmlgX.xml')
archive_file($get_path,$put_path,'wpmlg1X.xml')
archive_file($get_path,$put_path,'scaleX.xml')
archive_file($get_path,$put_path,'scalef1X.xml')
archive_file($get_path,$put_path,'scaleH.xml')
archive_file($get_path,$put_path,'scalef1H.xml')
archive_file($get_path,$put_path,'stmasX.xml')
archive_file($get_path,$put_path,'echselX.xml')

archive_file($get_path,$put_path,'7QshearX.xml')
archive_file($get_path,$put_path,'9QshearX.xml')
archive_file($get_path,$put_path,'aptfHX.xml')
archive_file($get_path,$put_path,'babaX.xml')
archive_file($get_path,$put_path,'blewH.xml')
archive_file($get_path,$put_path,'cpHY.xml')
archive_file($get_path,$put_path,'cpYX.xml')
archive_file($get_path,$put_path,'dfsX.xml')
archive_file($get_path,$put_path,'dfsX.xml')
archive_file($get_path,$put_path,'dumboH.xml')
archive_file($get_path,$put_path,'hmqcHX.xml')
archive_file($get_path,$put_path,'hsqcHX.xml')
archive_file($get_path,$put_path,'inadX.xml')
archive_file($get_path,$put_path,'ineptYX.xml')
archive_file($get_path,$put_path,'pmlgH.xml')
archive_file($get_path,$put_path,'pto1HX.xml')
archive_file($get_path,$put_path,'pto2HX.xml')
archive_file($get_path,$put_path,'pto3HX.xml')
archive_file($get_path,$put_path,'r14X.xml')
archive_file($get_path,$put_path,'r18H.xml')
archive_file($get_path,$put_path,'r2invX.xml')
archive_file($get_path,$put_path,'REDORHtppm.xml')
archive_file($get_path,$put_path,'selREDOR.xml')
archive_file($get_path,$put_path,'spc5X.xml')
archive_file($get_path,$put_path,'wdumbotX.xml')
archive_file($get_path,$put_path,'wdumboX.xml')
archive_file($get_path,$put_path,'Yspinal.xml')
archive_file($get_path,$put_path,'Ytppm.xml')
archive_file($get_path,$put_path,'r12H.xml')
archive_file($get_path,$put_path,'fam1X.xml')
archive_file($get_path,$put_path,'fam2X.xml')
archive_file($get_path,$put_path,'cpmgX.xml')
archive_file($get_path,$put_path,'dumboX.xml')

archive_file($get_path,$put_path,'dreamX.xml')
archive_file($get_path,$put_path,'cp1HX.xml')
archive_file($get_path,$put_path,'drawsX.xml')
archive_file($get_path,$put_path,'raptX.xml')
archive_file($get_path,$put_path,'graptX.xml')
archive_file($get_path,$put_path,'hmqcYX.xml')
archive_file($get_path,$put_path,'rampY.xml')
archive_file($get_path,$put_path,'pipsH.xml')
archive_file($get_path,$put_path,'rampH.xml')
archive_file($get_path,$put_path,'rampX.xml')
archive_file($get_path,$put_path,'sfsH.xml')
archive_file($get_path,$put_path,'sfsX.xml')
archive_file($get_path,$put_path,'r12H.xml')
archive_file($get_path,$put_path,'dfspX.xml')
archive_file($get_path,$put_path,'mdfsX.xml')
archive_file($get_path,$put_path,'sft1A.xml')
archive_file($get_path,$put_path,'sft2A.xml')
archive_file($get_path,$put_path,'sft2A.xml')
archive_file($get_path,$put_path,'smyoX.xml')
archive_file($get_path,$put_path,'smydH.xml')
archive_file($get_path,$put_path,'STshearX.xml')
archive_file($get_path,$put_path,'lgH.xml')
archive_file($get_path,$put_path,'rfdrX.xml')
archive_file($get_path,$put_path,'r18X.xml')
archive_file($get_path,$put_path,'lgX.xml')
archive_file($get_path,$put_path,'tiltH.xml')
archive_file($get_path,$put_path,'trapHY.xml')
archive_file($get_path,$put_path,'trapXH.xml')
archive_file($get_path,$put_path,'sc14X.xml')
archive_file($get_path,$put_path,'seac7X.xml')
archive_file($get_path,$put_path,'gaussX.xml')
archive_file($get_path,$put_path,'fprfdrX.xml')
archive_file($get_path,$put_path,'ptrfdrX.xml')
archive_file($get_path,$put_path,'tm5H.xml')
archive_file($get_path,$put_path,'spnlH.xml')
archive_file($get_path,$put_path,'spnlmH.xml')
archive_file($get_path,$put_path,'Decoupling:.xml')
archive_file($get_path,$put_path,'Decouplingm:.xml')
archive_file($get_path,$put_path,'shp1X.xml')
archive_file($get_path,$put_path,'shp2X.xml')
archive_file($get_path,$put_path,'shp3X.xml')
archive_file($get_path,$put_path,'cpXY.xml')
archive_file($get_path,$put_path,'shp3X.xml')
archive_file($get_path,$put_path,'presatX.xml')
archive_file($get_path,$put_path,'presatY.xml')
archive_file($get_path,$put_path,'180Y.xml')
archive_file($get_path,$put_path,'pipsY.xml')
archive_file($get_path,$put_path,'pxyH.xml')
archive_file($get_path,$put_path,'hssmallX.xml')
archive_file($get_path,$put_path,'tilt3H.xml')
archive_file($get_path,$put_path,'tilt2H.xml')
archive_file($get_path,$put_path,'tilt1H.xml')
archive_file($get_path,$put_path,'sfmX.xml')
archive_file($get_path,$put_path,'samH.xml')
archive_file($get_path,$put_path,'wsamX.xml')
archive_file($get_path,$put_path,'dcfX.xml')
archive_file($get_path,$put_path,'dcf1X.xml')
archive_file($get_path,$put_path,'superX.xml')
archive_file($get_path,$put_path,'sr4H.xml')
archive_file($get_path,$put_path,'lockH.xml')
archive_file($get_path,$put_path,'compH.xml')
archive_file($get_path,$put_path,'decofH.xml')
archive_file($get_path,$put_path,'satX.xml')
archive_file($get_path,$put_path,'Hwaltz.xml')
archive_file($get_path,$put_path,'Ywaltz.xml')
archive_file($get_path,$put_path,'Xseq.xml')
archive_file($get_path,$put_path,'Xwaltz.xml')
archive_file($get_path,$put_path,'Xspinal.xml')
archive_file($get_path,$put_path,'Xtppm.xml')
archive_file($get_path,$put_path,'echoH.xml')
archive_file($get_path,$put_path,'zG.xml')
archive_file($get_path,$put_path,'cdxX.xml')
archive_file($get_path,$put_path,'shcaX.xml')
archive_file($get_path,$put_path,'shcoX.xml')
archive_file($get_path,$put_path,'shY.xml')
archive_file($get_path,$put_path,'gradZ.xml')
archive_file($get_path,$put_path,'Hspinal2.xml')
archive_file($get_path,$put_path,'Xspinal2.xml')
archive_file($get_path,$put_path,'cpmH.xml')

"******** Create TEMPLATES/VNMRJ/INTERFACE **********"

$get_path = $input_path + '/templates/vnmrj/interface'
$put_path = $output_path +'/templates/vnmrj'
$put_path2 = $put_path +'/interface'
shell('mkdir ' + $put_path2)

"******** Create ADM/USERS **********"

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

"******** Create ADM/USERS/USERPROFILES **********"
"          carries over from adm/users            "

$get_path = $input_path + '/adm/users/userProfiles'
$put_path = $put_path +'/userProfiles'
shell('mkdir ' + $put_path)

"******** Create WTLIB ********"

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

"******** Create SHIMS ********"

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

"******** Create BIN Directory in User (less vnmrsys) Directory********"

length(userdir):$userdirlength
substr(userdir,1,$userdirlength - 8):$user_path

$get_path = $user_path + '/bin'
$put_path = $output_path +'/bin'
shell('mkdir ' + $put_path)

"******** 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)

"******** 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 + ' 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'
$directories = $directories + ' -C ' + $output_path + ' studylib'

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')





