Index: trunk/ippScripts/scripts/dist_advancerun.pl
===================================================================
--- trunk/ippScripts/scripts/dist_advancerun.pl	(revision 23776)
+++ trunk/ippScripts/scripts/dist_advancerun.pl	(revision 23777)
@@ -28,5 +28,5 @@
 
 # Parse the command-line arguments
-my ($dist_id, $stage, $stage_id, $outroot);
+my ($dist_id, $stage, $stage_id, $outdir);
 my ($dbname, $save_temps, $verbose, $no_update, $no_op, $logfile);
 
@@ -35,5 +35,5 @@
            'stage=s'        => \$stage,      # raw, chip, warp, or diff
            'stage_id=s'     => \$stage_id,   # exp_id, chip_id, warp_id, or diff_id
-           'outroot=s'      => \$outroot,    # "directory" for outputs
+           'outdir=s'       => \$outdir,    # "directory" for outputs
            'save-temps'     => \$save_temps, # Save temporary files?
            'dbname=s'       => \$dbname,     # Database name
@@ -45,10 +45,10 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --dist_id --stage --stage_id --outroot",
+pod2usage( -msg => "Required options: --dist_id --stage --stage_id --outdir",
            -exitval => 3) unless
     defined $dist_id and
     defined $stage and
     defined $stage_id and
-    defined $outroot;
+    defined $outdir;
 
 $ipprc->redirect_output($logfile) if $logfile;
@@ -90,5 +90,5 @@
 
 # XXX we should create a file rule for this
-my $outfile = "$outroot/dbinfo.$stage.$stage_id.mdc";
+my $outfile = "$outdir/dbinfo.$stage.$stage_id.mdc";
 
 {
Index: trunk/ippScripts/scripts/dist_component.pl
===================================================================
--- trunk/ippScripts/scripts/dist_component.pl	(revision 23776)
+++ trunk/ippScripts/scripts/dist_component.pl	(revision 23777)
@@ -58,5 +58,5 @@
 # Parse the command-line arguments
 my ($dist_id, $camera, $stage, $stage_id, $component, $path_base, $chip_path_base, $clean);
-my ($outroot, $run_state, $data_state, $magicked, $no_magic, $poor_quality);
+my ($outdir, $run_state, $data_state, $magicked, $no_magic, $poor_quality);
 my ($dbname, $save_temps, $verbose, $no_update, $logfile);
 
@@ -71,8 +71,8 @@
            'state=s'        => \$run_state,  # state of the run
            'data_state=s'   => \$data_state, # data_state for this component
-           'poor_quality'      => \$poor_quality,  # the processing for this component did not produced images
+           'poor_quality'   => \$poor_quality,  # the processing for this component did not produced images
            'no_magic'       => \$no_magic,   # magic is not required for this distribution run
            'magicked'       => \$magicked,   # magicked state for this component
-           'outroot=s'      => \$outroot,    # "directory" for outputs
+           'outdir=s'       => \$outdir,     # "directory" for outputs
            'clean'          => \$clean,      # create clean distribution
            'save-temps'     => \$save_temps, # Save temporary files?
@@ -84,5 +84,5 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --dist_id --camera --stage --stage_id --component --path_base --outroot",
+pod2usage( -msg => "Required options: --dist_id --camera --stage --stage_id --component --path_base --outdir",
            -exitval => 3) unless
     defined $dist_id and
@@ -92,9 +92,9 @@
     defined $component and
     defined $path_base and
-    defined $outroot;
+    defined $outdir;
 
 $ipprc->redirect_output($logfile) if $logfile;
 
-if (($stage eq 'raw') and !defined $chip_path_base) {
+if (($stage eq 'raw') and !$clean and !defined $chip_path_base) {
     pod2usage( -msg => "Required options: --chip_path_base for raw stage", -exitval => 3);
 }
@@ -105,14 +105,10 @@
 
 # making a clean bundle of raw images doesn't make sense
-if (($stage eq "raw") and $clean) {
-    # well I suppose we could ship the registration log file. naw.
-    &my_die("cannot create clean run at raw stage", $dist_id, $component, $PS_EXIT_CONFIG_ERROR);
-}
 
 # create the output directories if it is not a nebulous path and it doesn't exist
-if (index($outroot, "neb://") != 0) {
-    if (! -e $outroot ) {
-        my $code = system "mkdir -p $outroot";
-        &my_die("cannot create output directory $outroot", $dist_id, $component,
+if (index($outdir, "neb://") != 0) {
+    if (! -e $outdir ) {
+        my $code = system "mkdir -p $outdir";
+        &my_die("cannot create output directory $outdir", $dist_id, $component,
                 $code >> 8) if $code;
     }
@@ -122,7 +118,7 @@
 # note: We my_die in get_file_list if something goes wrong. 
 
-my $file_list = get_file_list($stage, $component, $path_base);
-
-if ($stage ne 'fake') {
+my $file_list = get_file_list($stage, $component, $path_base, $clean);
+
+if (($stage ne 'raw') and ($stage ne 'fake')) {
     # If the file list is empty it is an error because we should at least get a config dump file
     # except for fake stage which doesn't do anything yet
@@ -132,5 +128,5 @@
 # set up directory for temporary files
 
-my $tmpdir  = "$outroot/tmpdir.$dist_id.$component";
+my $tmpdir  = "$outdir/tmpdir.$dist_id.$component";
 if (-e $tmpdir) {
     if (-d $tmpdir) {
@@ -155,4 +151,5 @@
 
 # foreach my $file_rule (keys %$file_list) {
+my $num_files = 0;
 foreach my $file (@$file_list) {
     # check whether this file rule refers to an image, mask, or variance fits image
@@ -188,4 +185,5 @@
     # we need to pre-process the image before adding to the bundle. Save the path names.
     # the images will be created below
+    $num_files++;
     if ($image_type && $nan_masked_pixels) {
         # save the 
@@ -251,5 +249,6 @@
 my $bytes;
 my $md5sum;
-if ($stage eq 'fake') {
+if (0) {
+if (($stage eq 'fake')  or (($stage eq 'raw') and $clean)) {
     open DUMMY, ">$tmpdir/fake.$component" or &my_die("Unable to create placeholder for fake component",
         $dist_id, $component, $PS_EXIT_CONFIG_ERROR);
@@ -257,11 +256,12 @@
     close DUMMY;
 }
-# create the tarfile
-{
+}
+if ($num_files) {
+    # create the tarfile
     # XXX TODO: create a file rule for the tar file name
     my $tbase = basename($path_base);
     $tbase .= ".$component" if $component;
     $file_name = "$tbase.tgz";
-    my $tarfile = "$outroot/$file_name";
+    my $tarfile = "$outdir/$file_name";
 
     my $command = "tar -C $tmpdir --owner=ipp --group=users -czhf $tarfile .";
@@ -279,9 +279,12 @@
     &my_die("unable to compute md5sum for $tarfile", $dist_id, $component, $PS_EXIT_UNKNOWN_ERROR) if !$md5sum;
 
-    my @finfo = stat($tarfile);
-    &my_die("unable to stat $tarfile", $dist_id, $component, $PS_EXIT_UNKNOWN_ERROR) if !@finfo;
-    $bytes = $finfo[7];
+    $bytes = -s $tarfile;
 
     delete_tmpdir($tmpdir);
+} else {
+    # no files for this component
+    $file_name = "none";
+    $bytes = 0;
+    $md5sum = "0";
 }
 {
@@ -360,4 +363,5 @@
     my $component = shift;
     my $path_base = shift;
+    my $clean = shift;
 
     my @file_list;
@@ -366,8 +370,10 @@
         # eventually rawImfile will have a path_base that we'll need to add '.fits'
         # XXX do we want to distribute the registration log files?
-        my %file;
-        $file{file_rule} = "RAW.IMAGE";
-        $file{name} = $path_base;
-        push @file_list, \%file;
+        if (!$clean) {
+            my %file;
+            $file{file_rule} = "RAW.IMAGE";
+            $file{name} = $path_base;
+            push @file_list, \%file;
+        }
         return \@file_list;
     }
Index: trunk/ippTasks/dist.pro
===================================================================
--- trunk/ippTasks/dist.pro	(revision 23776)
+++ trunk/ippTasks/dist.pro	(revision 23777)
@@ -131,20 +131,24 @@
     book getword distToProcess $pageName state -var STATE
     book getword distToProcess $pageName data_state -var DATA_STATE
+    book getword distToProcess $pageName quality -var QUALITY
     book getword distToProcess $pageName no_magic -var NO_MAGIC
     book getword distToProcess $pageName magicked -var MAGICKED
-    book getword distToProcess $pageName outroot -var OUTROOT
+    book getword distToProcess $pageName outdir -var OUTDIR
     book getword distToProcess $pageName dbname -var DBNAME
 
-    $EXTRA_FLAGS = ""
+    $EXTRA_ARGS = ""
     if ("$CLEAN" == "T")
-        $EXTRA_FLAGS = --clean
+        $EXTRA_ARGS = --clean
     end
     # magicked is output as integer due to the union in the sql
     if ($MAGICKED)
-        $EXTRA_FLAGS = $EXTRA_FLAGS --magicked
+        $EXTRA_ARGS = $EXTRA_ARGS --magicked
     end
     # no_magic is output as integer due to the union in the sql
     if ($NO_MAGIC)
-        $EXTRA_FLAGS = $EXTRA_FLAGS --no_magic
+        $EXTRA_ARGS = $EXTRA_ARGS --no_magic
+    end
+    if ($QUALITY)
+        $EXTRA_ARGS = $EXTRA_ARGS --poor_quality
     end
 
@@ -153,9 +157,9 @@
     host anyhost
 
-    sprintf logfile "%s/dist.%s.%s.log" $OUTROOT $DIST_ID $COMPONENT
+    sprintf logfile "%s.%s/dist.%s.%s.log" $OUTDIR $DIST_ID $COMPONENT
     stdout $logfile
     stderr $logfile
 
-    $run = dist_component.pl --dist_id $DIST_ID --camera $CAMERA --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --path_base $PATH_BASE --chip_path_base $CHIP_PATH_BASE --state $STATE --data_state $DATA_STATE $EXTRA_FLAGS --outroot $OUTROOT --logfile $logfile
+    $run = dist_component.pl --dist_id $DIST_ID --camera $CAMERA --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --path_base $PATH_BASE --chip_path_base $CHIP_PATH_BASE --state $STATE --data_state $DATA_STATE $EXTRA_ARGS --outdir $OUTDIR --logfile $logfile
 
     add_standard_args run
@@ -251,13 +255,13 @@
     book getword distToAdvance $pageName stage   -var STAGE
     book getword distToAdvance $pageName stage_id -var STAGE_ID
-    book getword distToAdvance $pageName outroot -var OUTROOT
+    book getword distToAdvance $pageName outdir -var OUTDIR
 
     host anyhost
 
-    sprintf logfile "%s/dist.advance.%s.log" $OUTROOT $DIST_ID
+    sprintf logfile "%s/dist.advance.%s.log" $OUTDIR $DIST_ID
     stdout $logfile
     stderr $logfile
 
-    $run = dist_advancerun.pl --dist_id $DIST_ID --stage $STAGE --stage_id $STAGE_ID --outroot $OUTROOT --logfile $logfile
+    $run = dist_advancerun.pl --dist_id $DIST_ID --stage $STAGE --stage_id $STAGE_ID --outdir $OUTDIR --logfile $logfile
     add_standard_args run
 
Index: trunk/ippTools/share/disttool_pendingcomponent.sql
===================================================================
--- trunk/ippTools/share/disttool_pendingcomponent.sql	(revision 23776)
+++ trunk/ippTools/share/disttool_pendingcomponent.sql	(revision 23777)
@@ -1,3 +1,4 @@
 SELECT * FROM (
+    -- raw stage
 SELECT
     distRun.dist_id,
@@ -8,5 +9,5 @@
     clean,
     rawExp.camera,
-    outroot,
+    CONCAT_WS('.', outroot, CONVERT(distRun.dist_id, CHAR)) as outdir,
     rawImfile.uri as path_base,         -- change this once rawImfile has path_base
     chipProcessedImfile.path_base as chip_path_base,
@@ -41,8 +42,37 @@
 WHERE
     distRun.state = 'new'
+    AND distRun.clean = 0
     AND distRun.stage = 'raw'
     AND distComponent.dist_id IS NULL
     AND (rawExp.magicked OR distRun.no_magic)
     -- where hook 1 %s
+UNION
+    -- raw stage clean (dbinfo only)
+SELECT
+    distRun.dist_id,
+    distRun.label,
+    stage,
+    stage_id,
+    'exposure' AS component,
+    clean,
+    rawExp.camera,
+    CONCAT_WS('.', outroot, CONVERT(distRun.dist_id, CHAR)) as outdir,
+    NULL,
+    NULL,
+    NULL as state,
+    NULL as data_state,
+    0 as quality,
+    distRun.no_magic,
+    rawExp.magicked
+FROM distRun
+JOIN rawExp ON exp_id = stage_id
+LEFT JOIN distComponent 
+    ON distRun.dist_id = distComponent.dist_id 
+WHERE
+    distRun.state = 'new'
+    AND distRun.stage = 'raw'
+    AND distRun.clean
+    AND distComponent.dist_id IS NULL
+    -- where hook 2 %s
 
 -- chip stage
@@ -56,5 +86,5 @@
     clean,
     rawExp.camera,
-    outroot,
+    CONCAT_WS('.', outroot, CONVERT(distRun.dist_id, CHAR)) as outdir,
     chipProcessedImfile.path_base,
     chipProcessedImfile.path_base as chip_path_base,
@@ -77,5 +107,5 @@
     AND (distRun.clean OR chipRun.magicked OR distRun.no_magic)
     AND (chipRun.state = 'full' OR (distRun.clean AND chipRun.state = 'cleaned'))
-    -- where hook 2 %s
+    -- where hook 3 %s
 UNION
 SELECT
@@ -88,5 +118,5 @@
     clean,
     rawExp.camera,
-    outroot,
+    CONCAT_WS('.', outroot, CONVERT(distRun.dist_id, CHAR)) as outdir,
     camProcessedExp.path_base,
     NULL as chip_path_base,
@@ -111,5 +141,5 @@
     AND (distRun.clean OR chipRun.magicked OR distRun.no_magic)
     AND (camRun.state = 'full' OR (distRun.clean AND camRun.state = 'cleaned'))
-    -- where hook 3 %s
+    -- where hook 4 %s
 UNION
 SELECT
@@ -121,5 +151,5 @@
     clean,
     rawExp.camera,
-    outroot,
+    CONCAT_WS('.', outroot, CONVERT(distRun.dist_id, CHAR)) as outdir,
     fakeProcessedImfile.path_base,
     NULL,
@@ -142,5 +172,5 @@
     AND distRun.stage = 'fake'
     AND distComponent.dist_id IS NULL
-    -- where hook 4 %s
+    -- where hook 5 %s
 UNION
 SELECT
@@ -152,5 +182,5 @@
     clean,
     rawExp.camera,
-    outroot,
+    CONCAT_WS('.', outroot, CONVERT(distRun.dist_id, CHAR)) as outdir,
     warpSkyfile.path_base,
     NULL as chip_path_base,
@@ -176,5 +206,5 @@
     AND (distRun.clean OR warpRun.magicked OR distRun.no_magic)
     AND (warpRun.state = 'full' OR (distRun.clean AND warpRun.state = 'cleaned'))
-    -- where hook 5 %s
+    -- where hook 6 %s
 UNION
 SELECT
@@ -186,5 +216,5 @@
     clean,
     rawExp.camera,
-    outroot,
+    CONCAT_WS('.', outroot, CONVERT(distRun.dist_id, CHAR)) as outdir,
     diffSkyfile.path_base,
     NULL as chip_path_base,
@@ -209,5 +239,5 @@
     AND (distRun.clean OR diffRun.magicked OR distRun.no_magic)
     AND (diffRun.state = 'full' OR (distRun.clean AND diffRun.state = 'cleaned'))
-    -- where hook 6 %s
+    -- where hook 7 %s
 UNION
 SELECT DISTINCT
@@ -219,5 +249,5 @@
     clean,
     rawExp.camera,
-    outroot,
+    CONCAT_WS('.', outroot, CONVERT(distRun.dist_id, CHAR)) as outdir,
     stackSumSkyfile.path_base,
     NULL as chip_path_base,
@@ -258,4 +288,4 @@
     AND distComponent.dist_id IS NULL
     AND (stackRun.state = 'full' OR (distRun.clean AND stackRun.state = 'cleaned'))
-    -- where hook 7 %s
+    -- where hook 8 %s
 ) as Foo
Index: trunk/ippTools/share/disttool_toadvance.sql
===================================================================
--- trunk/ippTools/share/disttool_toadvance.sql	(revision 23776)
+++ trunk/ippTools/share/disttool_toadvance.sql	(revision 23777)
@@ -3,10 +3,10 @@
     stage,
     stage_id,
-    outroot,
+    CONCAT_WS('.', outroot, CONVERT(dist_id, CHAR)) as outdir,
     label,
     clean
 FROM
     (
--- raw stage
+-- raw stage not clean
 SELECT
     distRun.dist_id,
@@ -23,4 +23,5 @@
     WHERE
         distRun.state = 'new'
+        AND distRun.clean = 0
         AND distRun.fault = 0
         AND distRun.stage = 'raw'
@@ -31,4 +32,23 @@
         COUNT(rawImfile.class_id) = COUNT(distComponent.component)
         AND SUM(distComponent.fault) = 0
+UNION
+-- clean distribution of raw files (dbinfo only) only 1 component
+SELECT
+    distRun.dist_id,
+    stage,
+    stage_id,
+    outroot,
+    label,
+    clean
+    FROM distRun
+    LEFT JOIN distComponent
+        ON distRun.dist_id = distComponent.dist_id
+    WHERE
+        distRun.state = 'new'
+        AND distRun.clean
+        AND distRun.fault = 0
+        AND distRun.stage = 'raw'
+        AND distComponent.component IS NOT NULL
+        AND distComponent.fault = 0
 UNION
 -- chip stage
Index: trunk/ippTools/src/disttool.c
===================================================================
--- trunk/ippTools/src/disttool.c	(revision 23776)
+++ trunk/ippTools/src/disttool.c	(revision 23777)
@@ -564,4 +564,5 @@
     // will get blocked by pending earlier stages
     psString    raw_where = "";
+    psString    raw_clean_where = "";
     psString    chip_where = "";
     psString    camera_where = "";
@@ -574,4 +575,5 @@
             query,
             raw_where,
+            raw_clean_where,
             chip_where,
             camera_where,
