Index: /trunk/htdocs2/Classes/General/Dir.php
===================================================================
--- /trunk/htdocs2/Classes/General/Dir.php	(revision 331)
+++ /trunk/htdocs2/Classes/General/Dir.php	(revision 332)
@@ -57,4 +57,11 @@
     return $dir;
   }
+  
+  public static function ConvertPathString( $path )
+  {
+    $dir = new Dir();
+    $dir->SetPath( $path );
+    return $dir;
+  }
 
   // PRIVATE
Index: /trunk/htdocs2/Classes/General/TarBuilder.php
===================================================================
--- /trunk/htdocs2/Classes/General/TarBuilder.php	(revision 331)
+++ /trunk/htdocs2/Classes/General/TarBuilder.php	(revision 332)
@@ -22,13 +22,11 @@
     {
       $this->tar_file = new File();
-      $this->filenames = Array();
-      $this->src_dir = '';
+      $this->files = Array();
     }
 
-    public function SetSrcDir( $s_src_dir ) { $this->src_dir = $s_src_dir; }
-    public function AddFile( $new_file ) { $this->filenames[] = $new_file; }
+    public function AddFile( File $new_file ) { $this->files[] = $new_file; }
     public function SetTarFile( File $s_tar_file ) { $this->tar_file = $s_tar_file; }
 
-    public function GetTarFile() { return $this->tar_file; }
+//     public function GetTarFile() { return $this->tar_file; }
 
     //! Call exec to run tar and create our tarfile.
@@ -36,10 +34,11 @@
     {
       $web_dir = getcwd();
-      chdir( $this->src_dir );
+//       chdir( $this->src_dir );
 
       $command = 'tar --dereference -cf ' . $this->tar_file->GetFullPath() . ' ';
 
-      foreach( $this->filenames as $next_filename )
-	$command .= $next_filename . ' ';
+
+      foreach( $this->files as $next_file )
+	$command .= $next_file->GetFullPath() . ' ';
 
       $ret_val = '';
@@ -47,8 +46,10 @@
       $last_line = exec( $command, $output_array, $ret_val );
 
+      if( !$this->tar_file->Exists() )
+        throw new GZ_Exception( 'No tar file created', 'TarBuilder::Execute' );
       // TODO throw an exception if the exec failed in some way
       // TODO throw an exception if no tar file was created.
 
-      chdir( $web_dir );
+//       chdir( $web_dir );
     }
 
@@ -56,5 +57,5 @@
 
     private $tar_file;
-    private $src_dir;
+//     private $src_dir;
     private $filenames;
 };
Index: /trunk/htdocs2/Classes/Model/ObservationSet.php
===================================================================
--- /trunk/htdocs2/Classes/Model/ObservationSet.php	(revision 331)
+++ /trunk/htdocs2/Classes/Model/ObservationSet.php	(revision 332)
@@ -22,4 +22,5 @@
     $this->calibrations = null;
     $this->observation_data = null;
+    $this->data_dir = Dir::ConvertPathString( '/pulsar/scratch01/data_archive/' );
 
     if( $rhs != null )
@@ -44,5 +45,5 @@
   
   //! Get the adjusted filename, this will include scrunching parameters if set
-  public function GetDataFilen()
+  public function GetDataFile()
   {
     if( $this->observation_data != null )
@@ -69,4 +70,5 @@
     $this->observation_data->SetNChan( $this->observation->GetNChan() );
     $this->observation_data->SetNSub( $this->observation->GetNSub() );
+    $this->observation_data->SetDataDir( $this->data_dir );
   }
   
@@ -81,4 +83,30 @@
     return $dl_size;
   }
+  
+  public function MakeDownloadables()
+  {
+    $this->observation_data->MakeDownloadableFile();
+    foreach( $this->calibrations as $next_cal )
+    {
+      $src_file = $next_cal->GetFile();
+      $dest_file = File::ConvertFullPath( $this->data_dir->GetPath() . '/' . $src_file->GetFilename() );
+      if( !$dest_file->Exists() )
+        link( $src_file->GetFullPath(), $dest_file->GetFullPath() );
+    }
+  }
+  
+  public function GetDownloadFiles()
+  {
+    $data_files = Array();
+    $data_files[] = $this->observation_data->GetDataFile();
+    foreach( $this->calibrations as $next_cal )
+    {
+      $cal_data_path = $this->data_dir->GetPath();
+      $cal_data_path .= '/' . $next_cal->GetFile()->GetFilename();
+      $data_files[] =  File::ConvertFullPath( $cal_data_path );
+    }
+    
+    return $data_files;
+  }
 
   // PRIVATE
@@ -87,4 +115,5 @@
   private $calibrations;
   private $observation_data;
+  private $data_dir;
 };
 
Index: /trunk/htdocs2/Classes/Pulsar/ArchiveScruncher.php
===================================================================
--- /trunk/htdocs2/Classes/Pulsar/ArchiveScruncher.php	(revision 331)
+++ /trunk/htdocs2/Classes/Pulsar/ArchiveScruncher.php	(revision 332)
@@ -4,5 +4,5 @@
 
 require_once 'Classes/General/File.php';
-require_once 'Utils/strutils.php';
+require_once GREEN_ZONE_DIR . 'Utils/StringUtils.php';
 require_once 'Classes/Pulsar/ScrunchingParameters.php';
 
Index: /trunk/htdocs2/Classes/Pulsar/CPSR2Combiner.php
===================================================================
--- /trunk/htdocs2/Classes/Pulsar/CPSR2Combiner.php	(revision 331)
+++ /trunk/htdocs2/Classes/Pulsar/CPSR2Combiner.php	(revision 332)
@@ -4,4 +4,5 @@
 
 require_once GREEN_ZONE_DIR . 'Utils/GZ_Exception.php';
+require_once 'Classes/Pulsar/Archive.php';
 require_once 'Classes/General/File.php';
 require_once 'Classes/General/Dir.php';
@@ -31,28 +32,25 @@
   public function __construct()
   {
-    $this->src_dir = new Dir();
+    $this->archives = Array();
     $this->dest_file = new File();
   }
 
-  public function SetSrcDir( $s_src_dir ) { $this->src_dir = $s_src_dir; }
+  public function AddArchive( Archive $s_archive ) { $this->archives[] = $s_archive; }
   public function SetDestFile( $s_dest_file ) { $this->dest_file = $s_dest_file; }
 
   public function Execute()
   {
-    // Get a list of all the .cfb files from the src directory
-    $src_files = $src_dir->ListFiles();
     $src_files_str = ' ';
-    foreach( $src_files as $next_filename )
-      $src_files_str .= $src_dir->GetPath() . '/' . $next_filename;
+    foreach( $this->archives as $next_archive )
+          $src_files_str .= $next_archive->GetFullPath() . ' ';
 
-    $psradd_cmd = FIX_LD_LIB . PSRADD_CMD . ' -f ' . $dest_file->GetFullPath() . $src_files_str;
+    $psradd_cmd = FIX_LD_LIB . PSRADD_CMD . ' -f ' . $this->dest_file->GetFullPath() . $src_files_str;
     $retval = '';
     $all_lines = Array();
 
-    echo 'execing command ' . $psradd_cmd . ' <br> ';
     exec( $psradd_cmd, $all_lines, $retval );
 
     // TODO throw an exception if the psradd call failed or if the file wasn't created
-    if( !$dest_file->Exists() )
+    if( !$this->dest_file->Exists() )
         throw new GZ_Exception( 'Failed to psradd files together', 'CPSR2Combiner::Execute' );
   }
Index: /trunk/htdocs2/Classes/Pulsar/ObservationData.php
===================================================================
--- /trunk/htdocs2/Classes/Pulsar/ObservationData.php	(revision 331)
+++ /trunk/htdocs2/Classes/Pulsar/ObservationData.php	(revision 332)
@@ -5,5 +5,6 @@
 require_once 'Classes/Pulsar/ScrunchingParameters.php';
 require_once 'Classes/Pulsar/CPSR2Combiner.php';
-
+require_once 'Classes/Pulsar/Archive.php';
+require_once 'Classes/Pulsar/ArchiveScruncher.php';
 
 
@@ -29,5 +30,4 @@
       $this->Copy( $rhs );
     
-    $this->psrdata_dir = Dir::ConvertFullPath( '/pulsar/scratch01/data_archive/' );
   }
   public function Copy( $rhs )
@@ -61,4 +61,6 @@
   public function SetNBin( $s_nbin ) { $this->nbin = $s_nbin; }
   public function SetNChan( $s_nchan ) { $this->nchan = $s_nchan; }
+  
+  public function SetDataDir( Dir $s_data_path ) { $this->data_dir = $s_data_path; }
   
   //! Make an estimate of the size the downloadable file will be
@@ -131,10 +133,12 @@
   public function MakeDownloadableFile()
   {
-    $pre_scr_file = new File();
+    $pre_scr_file = new File( File::ConvertFullPath($this->data_dir->GetPath() .'/'.$this->path->GetFilename()) );
+    $data_file = null;
     
     if( $this->path->IsDir() )
     {
       $combiner = new CPSR2Combiner();
-      $combiner->SetSrcDir( $this->path );
+      foreach( $this->archives as $next_archive )
+        $combiner->AddArchive( $next_archive );
       $combiner->SetDestFile( $pre_scr_file );
       $combiner->Execute();
@@ -146,8 +150,5 @@
 				'ObservationData::MakeDownloadableFile' );
     
-      $pre_scr_file->SetPath( $this->archives[0]->GetPath() );
-      $pre_scr_file->SetFilename( $this->archives[0]->GetFilename() );
-      
-      // create a link to the file in the current directory
+      link( $this->path->GetFullPath(), $pre_src_file->GetFullPath() );
     }
     
@@ -158,21 +159,24 @@
       $scruncher = new ArchiveScruncher();
       $scruncher->SetParameters( $this->scrunching_parameters );
-      $scruncher->SetSrcFile( $data_file );
-      $dest_file = File::ConvertFullPath( $data_file->GetFullPath()
-      $scruncher->SetDestFile( $dest_file );
-    }
-  }
-  
-  public function GetFinalFilename()
-  {
+      $scruncher->SetSrcFile( $pre_scr_file );
+      $scruncher->SetDestFile( $this->GetDataFile() );
+      $scruncher->Execute();
+    }
+  }
+  
+  public function GetDataFile()
+  {
+    $data_file = new File();
+    $data_file->SetPath( $this->data_dir->GetPath() );
+    $data_file->SetFilename( $this->path->GetFilename() );
+    
     if( $this->scrunching_parameters != null )
     {
-      $filename = AddPreExtension( $filename,
-				   $this->GetScrunchingParameters()->GetTextDescription() );
-    }
-    else
-    {
-      
-    }
+
+      $data_file->SetFilename( AddPreExtension( $data_file->GetFilename(),
+				   $this->GetScrunchingParameters()->GetTextDescription() ) );
+    }
+  
+    return $data_file;
   }
   
@@ -186,5 +190,5 @@
   private $nchan;
   private $npol;
-  private $psrdata_dir;
+  private $data_dir;
   
   private function ExamineObservation()
@@ -204,5 +208,5 @@
 	if( $extension == 'cfb' || $extension == 'fb' )
 	{
-	  $new_archive = new File();
+	  $new_archive = new Archive();
 	  $new_archive->SetPath( $dir->GetPath() );
 	  $new_archive->SetFilename( $next_filename);
@@ -213,5 +217,5 @@
     else
     {
-      $new_archive = new File();
+      $new_archive = new Archive();
 	$new_archive->SetPath( $this->path->GetPath() );
 	$new_archive->SetFilename( $this->path->GetFilename() );
Index: /trunk/htdocs2/Forms/CartForm.php
===================================================================
--- /trunk/htdocs2/Forms/CartForm.php	(revision 331)
+++ /trunk/htdocs2/Forms/CartForm.php	(revision 332)
@@ -7,5 +7,5 @@
 require_once 'Forms/ObservationSetTable.php';
 require_once 'Classes/Interfaces/ObsInterface.php';
-
+require_once 'Classes/General/TarBuilder.php';
 
 
@@ -22,4 +22,6 @@
     
     $this->SetupPaginator();
+    
+    $this->download_created = false;
   }
   
@@ -32,4 +34,7 @@
     $this->gz->smarty_assign( $smarty, 'cart_size', count( $this->cart_contents ) );
     $smarty->display( 'CartFormHeader.tpl' );
+    
+    if( $this->download_created )
+      echo 'Click <a href=downloads/random.tar> here </a> to download <br>';
     
     if( count( $this->cart_contents ) > 0 )
@@ -79,4 +84,5 @@
   private $obs_table;
   private $paginator;
+  private $download_created;
   
   private function SetupPaginator()
@@ -103,6 +109,34 @@
   private function DownloadObservations()
   {
-    echo 'downloading observations <br> ';
-    echo 'there are ' . count( $this->obs_table->GetSelectedIDs() ) . ' items selected <br> ';
+    $files_to_tar = Array();
+    
+    $selected_ids = $this->obs_table->GetSelectedIDs();
+    
+    foreach( $this->cart_contents as $next_item )
+    {
+      if( in_array( $next_item->GetObservation()->GetFileID(), $selected_ids ) )
+      {
+        $next_item->MakeDownloadables();
+        $download_files = $next_item->GetDownloadFiles();
+        foreach( $download_files as $next_file )
+          $files_to_tar[] = $next_file;
+      }
+    }
+    
+    $tar_file = File::ConvertFullPath( '/pulsar/scratch01/data_archive/random.tar' );
+    
+    $tar_builder = new TarBuilder();
+    $tar_builder->SetTarFile( $tar_file );
+    foreach( $files_to_tar as $next_file )
+      $tar_builder->AddFile( $next_file );
+    $tar_builder->Execute();
+    
+    $web_link = File::ConvertFullPath( '/usr/local/work/pulsararchive/htdocs2/downloads/'. $tar_file->GetFilename() );
+    
+    echo 'will link ' . $tar_file->GetFullPath .' to ' . $web_link->GetFullPath() .'<br>';
+    if( !$web_link->Exists() )
+      link( $tar_file->GetFullPath(), $web_link->GetFullPath() );
+    
+    $this->download_created = true;
   }
   
Index: /trunk/htdocs2/config.php
===================================================================
--- /trunk/htdocs2/config.php	(revision 331)
+++ /trunk/htdocs2/config.php	(revision 332)
@@ -36,6 +36,10 @@
 define( 'PSRCAT_CMD', PSRHOME, '/bin/psrcat' );
 define( 'VAP_CMD', PSRHOME . '/bin/vap' );
-define( 'PSRADD_CMD', '/bin/psradd' );
-define( 'PSRSH_CMD', '/bin/psrsh' );
+define( 'PSRADD_CMD', PSRHOME . '/bin/psradd' );
+define( 'PSRSH_CMD', PSRHOME . '/bin/psrsh' );
+
+define( 'DATA_DIR', '/pulsar/scratch01/data_archive/' );
+define( 'WEB_ROOT', '/var/www/vhosts/pulsararchive.atnf.csiro.au/' );
+define( 'DOWNLOAD_DIR', WEB_ROOT . 'downloads' );
 
 
