Index: unk/dettools/doc/det.define.sh
===================================================================
--- /trunk/dettools/doc/det.define.sh	(revision 9354)
+++ 	(revision )
@@ -1,53 +1,0 @@
-
-## PanTasks scripts for mkdetrend
-
-# det.cleanup.resid : search for images to be processed
-task	       det.types
-  command      dettools -dettypes
-  host         local
-
-  # this needs to be an absolute event
-  periods      -exec     sunset + 20min?
-
-  # success
-  task.exit    0
-    local i Nstdout
-    queuesize stdout -var Nstdout
-    for i 0 $Nstdout
-      queuepop stdout -var line
-      queuepush detTypePending line
-    end
-  end
-end
-
-
-# det.process.norm : submit an image for processing by ppImage
-task	       det.define
-  periods      -exec 1
-  periods      -timeout 10
-
-  task.exec
-    local Npending
-    queuesize  detTypePending -var Npending
-    if ($Npending == 0) break
-
-    queuepop detTypePending -var line
-    if ("$line" == "NULL") break
-
-    host local
-    command dettools -define $line
-  end
-
-  # success
-  task.exit    0
-    queueinit stdout
-  end
-
-end
-
-# det.assess
-task	       det.assess
-  command      dettools -assess
-  host         local
-
-end
Index: unk/dettools/doc/det.norm.sh
===================================================================
--- /trunk/dettools/doc/det.norm.sh	(revision 9354)
+++ 	(revision )
@@ -1,75 +1,0 @@
-
-## PanTasks scripts for mkdetrend
-
-# tasks: 
-#   det.pending.norm  - select norm input imfiles for processing
-#   det.process.norm  - send norm images to pcontol to be processed
-#   det.update.raw   - update completed exposures
-#   det.cleanup.raw  - retire old input image
-#
-# queues: 
-#   detNormPending: (url) (expID) (cameraID) (chipID) (state)
-#
-# globals: 
-
-# det.pending.norm : search for images to be processed
-task	       det.pending.norm
-  command      dettools -pending norm
-  host         local
-
-  # timeout shorter than exec so jobs do not build up
-  periods      -exec     5
-  periods      -poll     1
-  periods      -timeout  4
-
-  # success
-  task.exit    0
-    local i Nstdout
-    # keep only new, unique entries (URL is key)
-    queuesize stdout -var Nstdout
-    for i 0 $Nstdout
-      queuepop stdout -var line
-      queuepush detNormPending -uniq -key 0 "$line new"
-    end
-  end
-end
-
-# det.process.norm : submit an image for processing by ppImage
-task	       det.process.norm
-  periods      -exec 0.1
-  periods      -timeout 120
-
-  task.exec
-    local Npending
-    queuesize  detNormPending -var Npending
-    if ($Npending == 0) break
-
-    # add in system status interruptions later
-    # if ($network == 0) break
-    
-    queuepop detNormPending -var line -key 4 new
-    if ("$line" == "NULL") break
-
-    list tmp -split $line
-    $url    = $tmp:0
-    $expID  = $tmp:1
-    $camera = $tmp:2
-    $chip   = $tmp:3
-    queuepush detNormPending "$url $expID $camera $chip run"
-
-    # need to decide real name for this function
-    $host = `chip.host $camera $chip`
-    host $host
-    command normalize $url $chip -recipe detrendNorm
-    # the detrend image(s) used by this analysis are determined by 
-    # the recipe : normally, the best available
-  end
-
-  # success
-  task.exit    0
-    # if ppImage updates the DB:
-    queueinit stdout
-    queuepush detPendingNorm $taskargs:0 $taskargs:1 $taskargs:2 $taskargs:3 done
-  end
-
-end
Index: unk/dettools/doc/det.process.sh
===================================================================
--- /trunk/dettools/doc/det.process.sh	(revision 9354)
+++ 	(revision )
@@ -1,99 +1,0 @@
-
-## PanTasks scripts for mkdetrend
-
-# tasks: 
-#   det.pending.raw  - select raw input imfiles for processing
-#   det.process.raw  - send raw images to pcontol to be processed
-#   det.update.raw   - update completed exposures
-#   det.cleanup.raw  - retire old input image
-#
-# queues: 
-#   detRawPending: (url) (expID) (cameraID) (chipID) (state)
-#
-# globals: 
-
-# det.pending.raw : search for images to be processed
-task	       det.pending.raw
-  command      dettools -pending raw
-  host         local
-
-  # timeout shorter than exec so jobs do not build up
-  periods      -exec     5
-  periods      -poll     1
-  periods      -timeout  4
-
-  # success
-  task.exit    0
-    local i Nstdout
-    # keep only new, unique entries (URL is key)
-    queuesize stdout -var Nstdout
-    for i 0 $Nstdout
-      queuepop stdout -var line
-      queuepush detRawPending -uniq -key 0 "$line new"
-    end
-  end
-end
-
-# det.process.raw : submit an image for processing by ppImage
-task	       det.process.raw
-  periods      -exec 0.1
-  periods      -timeout 120
-
-  task.exec
-    local Npending
-    queuesize  detRawPending -var Npending
-    if ($Npending == 0) break
-
-    # add in system status interruptions later
-    # if ($network == 0) break
-    
-    queuepop detRawPending -var line -key 4 new
-    if ("$line" == "NULL") break
-
-    list tmp -split $line
-    $url    = $tmp:0
-    $expID  = $tmp:1
-    $camera = $tmp:2
-    $chip   = $tmp:3
-    queuepush detRawPending "$url $expID $camera $chip run"
-
-    # need to decide real name for this function
-    $host = `chip.host $camera $chip`
-    host $host
-    command ppImage $url $chip -recipe detrendRaw
-    # the detrend image(s) used by this analysis are determined by 
-    # the recipe : normally, the best available
-  end
-
-  # success
-  task.exit    0
-    # if ppImage updates the DB:
-    queueinit stdout
-    queuepush detPendingRaw $taskargs:0 $taskargs:1 $taskargs:2 $taskargs:3 done
-  end
-
-end
-
-# det.update.raw : search for images to be processed
-task	       det.update.raw
-  command      dettools -update raw
-  host         local
-
-  # timeout shorter than exec so jobs do not build up
-  periods      -exec     5
-  periods      -poll     1
-  periods      -timeout  4
-end
-
-# det.cleanup.raw : search for images to be processed
-task	       det.cleanup.raw
-  command      dettools -cleanup raw
-  host         local
-
-  # timeout shorter than exec so jobs do not build up
-  # this would be better as an absolute event
-  periods      -exec     {86400*3}
-  periods      -poll     10
-  periods      -timeout  120
-end
-
Index: unk/dettools/doc/det.resid.sh
===================================================================
--- /trunk/dettools/doc/det.resid.sh	(revision 9354)
+++ 	(revision )
@@ -1,101 +1,0 @@
-
-## PanTasks scripts for mkdetrend
-
-# tasks: 
-#   det.pending.resid  - select resid input imfiles for processing
-#   det.process.resid  - send resid images to pcontol to be processed
-#   det.update.resid   - update completed exposures
-#   det.cleanup.resid  - retire old input image
-#
-# queues: 
-#   detResidPending: (url) (detID) (expID) (cameraID) (chipID) (mode) (state)
-#
-# globals: 
-
-# det.pending.resid : search for images to be processed
-task	       det.pending.resid
-  command      dettools -pending resid
-  host         local
-
-  # timeout shorter than exec so jobs do not build up
-  periods      -exec     5
-  periods      -poll     1
-  periods      -timeout  4
-
-  # success
-  task.exit    0
-    local i Nstdout
-    # keep only new, unique entries (URL is key)
-    queuesize stdout -var Nstdout
-    for i 0 $Nstdout
-      queuepop stdout -var line
-      queuepush detResidPending -uniq -key 0 "$line new"
-    end
-  end
-end
-
-# det.process.resid : submit an image for processing by ppImage
-task	       det.process.resid
-  periods      -exec 0.1
-  periods      -timeout 120
-
-  task.exec
-    local Npending
-    queuesize  detResidPending -var Npending
-    if ($Npending == 0) break
-
-    # add in system status interruptions later
-    # if ($network == 0) break
-    
-    queuepop detResidPending -var line -key 4 new
-    if ("$line" == "NULL") break
-
-    list tmp -split $line
-    $url    = $tmp:0
-    $detID  = $tmp:1
-    $expID  = $tmp:2
-    $camera = $tmp:3
-    $chip   = $tmp:4
-    queuepush detResidPending "$url $detID $expID $camera $chip run"
-
-    # need to decide real name for this function
-    $host = `chip.host $camera $chip`
-    host $host
-    command ppImage $url $chip -recipe detrendResid
-    end
-    # the detrend image(s) used by this analysis are determined by 
-    # the recipe : detrendResid uses the detID to choose the current or previous
-  end
-
-  # success
-  task.exit    0
-    # if ppImage updates the DB:
-    queueinit stdout
-    queuepush detPendingResid $taskargs:0 $taskargs:1 $taskargs:2 $taskargs:3 done
-  end
-
-end
-
-# det.update.resid : search for images to be processed
-task	       det.update.resid
-  command      dettools -update resid
-  host         local
-
-  # timeout shorter than exec so jobs do not build up
-  periods      -exec     5
-  periods      -poll     1
-  periods      -timeout  4
-end
-
-# det.cleanup.resid : search for images to be processed
-task	       det.cleanup.resid
-  command      dettools -cleanup resid
-  host         local
-
-  # timeout shorter than exec so jobs do not build up
-  # this would be better as an absolute event
-  periods      -exec     {86400*3}
-  periods      -poll     10
-  periods      -timeout  120
-end
-
Index: unk/dettools/doc/det.stack.sh
===================================================================
--- /trunk/dettools/doc/det.stack.sh	(revision 9354)
+++ 	(revision )
@@ -1,75 +1,0 @@
-
-## PanTasks scripts for mkdetrend
-
-# tasks: 
-#   det.pending.stack  - select stack input imfiles for processing
-#   det.process.stack  - send stack images to pcontol to be processed
-#   det.update.raw   - update completed exposures
-#   det.cleanup.raw  - retire old input image
-#
-# queues: 
-#   detStackPending: (url) (expID) (cameraID) (chipID) (state)
-#
-# globals: 
-
-# det.pending.stack : search for images to be processed
-task	       det.pending.stack
-  command      dettools -pending stack
-  host         local
-
-  # timeout shorter than exec so jobs do not build up
-  periods      -exec     5
-  periods      -poll     1
-  periods      -timeout  4
-
-  # success
-  task.exit    0
-    local i Nstdout
-    # keep only new, unique entries (URL is key)
-    queuesize stdout -var Nstdout
-    for i 0 $Nstdout
-      queuepop stdout -var line
-      queuepush detStackPending -uniq -key 0 "$line new"
-    end
-  end
-end
-
-# det.process.stack : submit an image for processing by ppImage
-task	       det.process.stack
-  periods      -exec 0.1
-  periods      -timeout 120
-
-  task.exec
-    local Npending
-    queuesize  detStackPending -var Npending
-    if ($Npending == 0) break
-
-    # add in system status interruptions later
-    # if ($network == 0) break
-    
-    queuepop detStackPending -var line -key 4 new
-    if ("$line" == "NULL") break
-
-    list tmp -split $line
-    $url    = $tmp:0
-    $expID  = $tmp:1
-    $camera = $tmp:2
-    $chip   = $tmp:3
-    queuepush detStackPending "$url $expID $camera $chip run"
-
-    # need to decide real name for this function
-    $host = `chip.host $camera $chip`
-    host $host
-    command ppMerge $url $chip -recipe detrendStack
-    # the detrend image(s) used by this analysis are determined by 
-    # the recipe : normally, the best available
-  end
-
-  # success
-  task.exit    0
-    # if ppImage updates the DB:
-    queueinit stdout
-    queuepush detPendingStack $taskargs:0 $taskargs:1 $taskargs:2 $taskargs:3 done
-  end
-
-end
Index: unk/dettools/doc/dettools.txt
===================================================================
--- /trunk/dettools/doc/dettools.txt	(revision 9354)
+++ 	(revision )
@@ -1,106 +1,0 @@
-mkdetrend tools
-
-dettools -define [options]
- * define a new detRun, specifying the constraints, and adding it to
- the run table.  if the detRun ID already exists, creates a new
- version.  the initial state is set to START.  the iteration is set to
- 0. also creates a new master detrend frame entry
- (detID.version.iteration define this frame uniquely).
- * select the input matching a given detRun.  selects the input
- exposures and the input files.
-
-options : 
-  -ID ID : a free-form string; if not specified, a unique string is constructed
-  -type type : bias dark (mask?) flat fringe (other?)
-  -camera camera 
-  -filter filter
-  -time start stop
-  -exptime min max
-  -airmass min max
-  -expgroup groupID
-
-  (-type and -camera are mandatory)
-  (-filter is mandatory for 'light' types)
-  (-exptime is mandatory for dark)
-
-dettools -pending raw [-state state] [-outmode mode]
- * select the unprocessed input infiles
- - output of this program is used by pantasks to schedule the ppImage
- run on each image
-
-dettools -pending resid [-state state] [-outmode mode]
- * select the residual images to be processed
- - output of this program is used by pantasks to schedule the ppImage
- run on each image
-
-dettools -pending stack [-state state] [-outmode mode]
- * select the files to be stacked for a given detRun, if exposures are ready
- - output of this program is used by ppMerge to build a master stack
-
-dettools -pending norm
- * select the master detrend frames & imfiles to be normalized
-
-dettools -update raw
- * select the raw input exposures, count processed imfiles, update if done
-
-dettools -update resid
- * select the resid exposures, count processed resid imfiles, update if done
- - for a given resid exposure, compile the results from the stacks for
- each chip and renormalize the output files as needed.
-
-dettools -assess
- * for a given master detrend frame, compile the results from the
- residual exposures and assess the validity of the input exposures and of
- the complete stack.  if too many input images are rejected, the
- affect the master detrend frame state.  if input images are rejected
- and a new set of master stacks should be made, create a new master
- detrend image, incrementing the iteration by one.
-
-** NOTE the sequence is: 
-
-   process, stack, merge, residual, assess
-              ^--------------------------<
-
-   IF we have no relevant detrend image for comparison.  otherwise,
-   the sequence should skip from process to residual on the first
-   pass, with a lower rejection threshold for the first assess pass.
-   the tools above allow either option; it is the choice of state
-   after process that determines which happens next.
-
-
-
-States:
- input detrend exposures:
-  RAW
-  PROCESSED
-
- input detrend imfiles:
-  RAW
-  PROCESSED
-  
- master detrend frames
-  RAW
-  NORMALIZED
-  MKRESID
-  SUCCESS
-  FAILURE
-  RETRY
-  (also has NEW/PRIOR flag)
-
- master detrend imfiles
-  NEW (not yet created)
-  RAW (created, but not normalized)
-  NORMALIZED
-
- resid exposure
-  RAW
-  PROCESSED
-  ASSESSED
-
- resid imfiles:
-  RAW
-  PROCESSED
-
- master detrend run:
-  NEW
-  DONE
Index: unk/dettools/src/detSelectInputImfiles.c
===================================================================
--- /trunk/dettools/src/detSelectInputImfiles.c	(revision 9354)
+++ 	(revision )
@@ -1,159 +1,0 @@
-# include "dettools.h"
-
-// select raw frames (exposure+images) which match the given config options
-psArray *detSelectInputImfiles (detConfig *config, int state) {
-
-    // build 'where' structure
-    psMetadata *where = psMetadataAlloc ();
-
-    psMetadataAddStr (where, PS_LIST_TAIL, "STATE", 0, "==", state);
-
-    // XXX EAM : do we really want/need to allow these restrictions?
-    if (config->type != DET_TYPE_UNDEF) {
-	psMetadataAddU8  (where, PS_LIST_TAIL, "TYPE",  0, "==", config->type);
-    }
-    if (config->camera != NULL) {
-	psMetadataAddStr (where, PS_LIST_TAIL, "CAMERA", 0, "==", config->camera);
-    }
-    if (config->filter != NULL) {
-	psMetadataAddStr (where, PS_LIST_TAIL, "FILTER", 0, "==", config->filter);
-    }
-    if (config->timeSelect) {
-	psMetadataAddTime (where, PS_LIST_TAIL, "TIME_START", 0, "<", config->timeStop);
-	psMetadataAddTime (where, PS_LIST_TAIL, "TIME_STOP", 0, ">", config->timeStart);
-    }
-    if (config->exptimeSelect) {
-	psMetadataAddTime (where, PS_LIST_TAIL, "EXPTIME", 0, "<", config->exptimeMin);
-	psMetadataAddTime (where, PS_LIST_TAIL, "EXPTIME", 0, ">", config->exptimeMax);
-    }
-    if (config->airmassSelect) {
-	psMetadataAddTime (where, PS_LIST_TAIL, "AIRMASS", 0, "<", config->airmassMin);
-	psMetadataAddTime (where, PS_LIST_TAIL, "AIRMASS", 0, ">", config->airmassMax);
-    }
-
-    psArray *imfiles = detInputImfileSelectRows (config->database, where, MAX_ROWS);
-    psFree (where);
-
-    return imfiles;
-} 
-
-// select raw frames (exposure+images) which match the given config options
-psArray *detSelectRawUpdateExposures (detConfig *config) {
-
-    // build 'where' structure
-    psMetadata *where = psMetadataAlloc ();
-
-    psMetadataAddStr (where, PS_LIST_TAIL, "STATE", 0, "==", DET_STATE_RAW);
-
-    // XXX EAM : do we really want/need to allow these restrictions?
-    if (config->type != DET_TYPE_UNDEF) {
-	psMetadataAddU8  (where, PS_LIST_TAIL, "TYPE",  0, "==", config->type);
-    }
-    if (config->camera != NULL) {
-	psMetadataAddStr (where, PS_LIST_TAIL, "CAMERA", 0, "==", config->camera);
-    }
-    if (config->filter != NULL) {
-	psMetadataAddStr (where, PS_LIST_TAIL, "FILTER", 0, "==", config->filter);
-    }
-    if (config->timeSelect) {
-	psMetadataAddTime (where, PS_LIST_TAIL, "TIME_START", 0, "<", config->timeStop);
-	psMetadataAddTime (where, PS_LIST_TAIL, "TIME_STOP", 0, ">", config->timeStart);
-    }
-    if (config->exptimeSelect) {
-	psMetadataAddTime (where, PS_LIST_TAIL, "EXPTIME", 0, "<", config->exptimeMin);
-	psMetadataAddTime (where, PS_LIST_TAIL, "EXPTIME", 0, ">", config->exptimeMax);
-    }
-    if (config->airmassSelect) {
-	psMetadataAddTime (where, PS_LIST_TAIL, "AIRMASS", 0, "<", config->airmassMin);
-	psMetadataAddTime (where, PS_LIST_TAIL, "AIRMASS", 0, ">", config->airmassMax);
-    }
-
-    psArray *exposures = detInputExposureSelectRows (config->database, where, MAX_ROWS);
-    psFree (where);
-
-    // output array of detMasterExposures
-    psArray *ready = psArrayAlloc (exposures->n);
-    ready->n = 0;
-
-    // 'where' to select each exposure
-    psMetadata *where = psMetadataAlloc ();
-    for (int i = 0; i < exposures->n; i++) {
-	detInputExposure *exposure = exposures->data[i];
-
-	// are all chips finished processing?
-	psMetadataAddStr (where, PS_LIST_TAIL, "STATE", PS_META_REPLACE, "==", DET_STATE_PROCESSED);
-	psMetadataAddStr (where, PS_LIST_TAIL, "DET_ID", PS_META_REPLACE, "==", exposure->detID);
-	psMetadataAddStr (where, PS_LIST_TAIL, "VERSION", PS_META_REPLACE, "==", exposure->version);
-
-	psArray *imfiles = detInputImfileSelectRows (config->database, where, MAX_ROWS);
-	if (imfiles->n != exposure->Nclass) {
-	    psFree (imfiles);
-	    continue;
-	}
-
-	psFree (imfiles);
-	psArrayAdd (ready, 100, exposure);
-    }
-    return ready;
-} 
-
-// select raw frames (exposure+images) which match the given config options
-psArray *detSelectResidUpdateExposures (detConfig *config) {
-
-    // build 'where' structure
-    psMetadata *where = psMetadataAlloc ();
-
-    psMetadataAddStr (where, PS_LIST_TAIL, "STATE", 0, "==", DET_STATE_RAW);
-
-    // XXX EAM : do we really want/need to allow these restrictions?
-    if (config->type != DET_TYPE_UNDEF) {
-	psMetadataAddU8  (where, PS_LIST_TAIL, "TYPE",  0, "==", config->type);
-    }
-    if (config->camera != NULL) {
-	psMetadataAddStr (where, PS_LIST_TAIL, "CAMERA", 0, "==", config->camera);
-    }
-    if (config->filter != NULL) {
-	psMetadataAddStr (where, PS_LIST_TAIL, "FILTER", 0, "==", config->filter);
-    }
-    if (config->timeSelect) {
-	psMetadataAddTime (where, PS_LIST_TAIL, "TIME_START", 0, "<", config->timeStop);
-	psMetadataAddTime (where, PS_LIST_TAIL, "TIME_STOP", 0, ">", config->timeStart);
-    }
-    if (config->exptimeSelect) {
-	psMetadataAddTime (where, PS_LIST_TAIL, "EXPTIME", 0, "<", config->exptimeMin);
-	psMetadataAddTime (where, PS_LIST_TAIL, "EXPTIME", 0, ">", config->exptimeMax);
-    }
-    if (config->airmassSelect) {
-	psMetadataAddTime (where, PS_LIST_TAIL, "AIRMASS", 0, "<", config->airmassMin);
-	psMetadataAddTime (where, PS_LIST_TAIL, "AIRMASS", 0, ">", config->airmassMax);
-    }
-
-    psArray *exposures = detResidExposureSelectRows (config->database, where, MAX_ROWS);
-    psFree (where);
-
-    // output array of detMasterExposures
-    psArray *ready = psArrayAlloc (exposures->n);
-    ready->n = 0;
-
-    // 'where' to select each exposure
-    psMetadata *where = psMetadataAlloc ();
-    for (int i = 0; i < exposures->n; i++) {
-	detResidExposure *exposure = exposures->data[i];
-
-	// are all chips finished processing?
-	psMetadataAddStr (where, PS_LIST_TAIL, "STATE", PS_META_REPLACE, "==", DET_STATE_PROCESSED);
-	psMetadataAddStr (where, PS_LIST_TAIL, "DET_ID", PS_META_REPLACE, "==", exposure->detID);
-	psMetadataAddStr (where, PS_LIST_TAIL, "VERSION", PS_META_REPLACE, "==", exposure->version);
-	psMetadataAddStr (where, PS_LIST_TAIL, "ITERATION", PS_META_REPLACE, "==", exposure->iteration);
-
-	psArray *imfiles = detResidImfileSelectRows (config->database, where, MAX_ROWS);
-	if (imfiles->n != exposure->Nclass) {
-	    psFree (imfiles);
-	    continue;
-	}
-
-	psFree (imfiles);
-	psArrayAdd (ready, 100, exposure);
-    }
-    return ready;
-} 
Index: unk/dettools/src/detSelectMasterExposures.c
===================================================================
--- /trunk/dettools/src/detSelectMasterExposures.c	(revision 9354)
+++ 	(revision )
@@ -1,138 +1,0 @@
-# include "dettools.h"
-
-// select raw frames (exposure+images) which match the given config options
-psArray *detSelectMasterExposuresForStack (detConfig *config) {
-
-    // build 'where' structure
-    psMetadata *where = psMetadataAlloc ();
-
-    psMetadataAddStr (where, PS_LIST_TAIL, "STATE", 0, "==", DET_STATE_RAW);
-
-    // XXX EAM : do we really want/need to allow these restrictions?
-    if (config->type != DET_TYPE_UNDEF) {
-	psMetadataAddU8  (where, PS_LIST_TAIL, "TYPE",  0, "==", config->type);
-    }
-    if (config->camera != NULL) {
-	psMetadataAddStr (where, PS_LIST_TAIL, "CAMERA", 0, "==", config->camera);
-    }
-    if (config->filter != NULL) {
-	psMetadataAddStr (where, PS_LIST_TAIL, "FILTER", 0, "==", config->filter);
-    }
-
-    psArray *exposures = detMasterExposureSelectRows (config->database, where, MAX_ROWS);
-    psFree (where);
-
-    // output array of detMasterExposures
-    psArray *ready = psArrayAlloc (exposures->n);
-    ready->n = 0;
-
-    // 'where' to select each exposure
-    psMetadata *where = psMetadataAlloc ();
-    for (int i = 0; i < exposures->n; i++) {
-	detMasterExposure *exposure = exposures->data[i];
-	
-	// is the input data for this master exposure ready for stacking?
-	psMetadataAddStr (where, PS_LIST_TAIL, "STATE", PS_META_REPLACE, "==", DET_STATE_PROCESSED);
-	psMetadataAddStr (where, PS_LIST_TAIL, "DET_ID", PS_META_REPLACE, "==", exposure->detID);
-	psMetadataAddStr (where, PS_LIST_TAIL, "VERSION", PS_META_REPLACE, "==", exposure->version);
-
-	psArray *inputs = detInputExposureSelectRows (config->database, where, MAX_ROWS);
-	if (inputs->n != exposure->nInput) {
-	    psFree (inputs);
-	    continue;
-	}
-
-	psFree (inputs);
-	psArrayAdd (ready, 100, exposure);
-    }
-    return ready;
-} 
-
-// select stack frames (detMasterImfile + detInputImfiles) which match the given master detrend exposures
-// XXX an alternative to this would construct the imfiles here based on the camera metadata
-psArray *detSelectMasterImfilesForStack (detConfig *config, psArray *exposures) {
-
-    psArray *frames = psArrayAlloc (100);
-
-    // 'where' to select each exposure
-    psMetadata *where = psMetadataAlloc ();
-    for (int i = 0; i < exposures->n; i++) {
-	detMasterExposure *exposure = exposures->data[i];
-	
-	// select the detrend master imfiles for this master exposure
-	psMetadataAddStr (where, PS_LIST_TAIL, "DET_ID", PS_META_REPLACE, "==", exposure->detID);
-	psMetadataAddStr (where, PS_LIST_TAIL, "VERSION", PS_META_REPLACE, "==", exposure->version);
-	psMetadataAddStr (where, PS_LIST_TAIL, "ITERATION", PS_META_REPLACE, "==", exposure->iteration);
-
-	psArray *detImfiles = detMasterImfileSelectRows (config->database, where, MAX_ROWS);
-
-	for (int j = 0; j < detImfiles->n; j++) {
-	    
-	    detMasterImfile *detImfile = detImfiles->data[j];
-
-	    // XXX : confirm that this detImfile has state DET_STATE_NEW ??
-
-	    // select the input imfiles for this master imfile
-	    psMetadataAddStr (where, PS_LIST_TAIL, "CLASS_ID", PS_META_REPLACE, "==", detImfile->classID);
-
-	    psArray *inputImfiles = detInputImfileSelectRows (config->database, where, MAX_ROWS);
-
-	    detStackFrame *stackFrame = detStackFrameAlloc (detImfile, inputImfiles);
-
-	    psArrayAdd (frames, 100, stackFrame);
-	}
-    }
-    return frames;
-} 
-
-
-// ************ normalization (put in new file) *******
-
-// select raw frames (exposure+images) which match the given config options
-psArray *detSelectMasterExposuresForNormalization (detConfig *config) {
-
-    // build 'where' structure
-    psMetadata *where = psMetadataAlloc ();
-
-    psMetadataAddStr (where, PS_LIST_TAIL, "STATE", 0, "==", DET_STATE_RAW);
-
-    // XXX EAM : do we really want/need to allow these restrictions?
-    if (config->type != DET_TYPE_UNDEF) {
-	psMetadataAddU8  (where, PS_LIST_TAIL, "TYPE",  0, "==", config->type);
-    }
-    if (config->camera != NULL) {
-	psMetadataAddStr (where, PS_LIST_TAIL, "CAMERA", 0, "==", config->camera);
-    }
-    if (config->filter != NULL) {
-	psMetadataAddStr (where, PS_LIST_TAIL, "FILTER", 0, "==", config->filter);
-    }
-
-    psArray *exposures = detMasterExposureSelectRows (config->database, where, MAX_ROWS);
-    psFree (where);
-
-    // output array of detMasterExposures
-    psArray *frames = psArrayAlloc (exposures->n);
-    frames->n = 0;
-
-    // 'where' to select each exposure
-    psMetadata *where = psMetadataAlloc ();
-    for (int i = 0; i < exposures->n; i++) {
-	detMasterExposure *exposure = exposures->data[i];
-	
-	// is the input data for this master exposure ready for stacking?
-	psMetadataAddStr (where, PS_LIST_TAIL, "STATE", PS_META_REPLACE, "==", DET_STATE_RAW);
-	psMetadataAddStr (where, PS_LIST_TAIL, "DET_ID", PS_META_REPLACE, "==", exposure->detID);
-	psMetadataAddStr (where, PS_LIST_TAIL, "VERSION", PS_META_REPLACE, "==", exposure->version);
-	psMetadataAddStr (where, PS_LIST_TAIL, "ITERATION", PS_META_REPLACE, "==", exposure->iteration);
-
-	psArray *imfiles = detMasterImfileSelectRows (config->database, where, MAX_ROWS);
-	if (imfiles->n != exposure->nImfiles) {
-	    psFree (imfiles);
-	    continue;
-	}
-
-	detNormFrame *frame = detNormFrameAlloc (exposure, imfiles);
-	psArrayAdd (frames, 100, frame);
-    }
-    return frames;
-} 
Index: unk/dettools/src/dettools.c
===================================================================
--- /trunk/dettools/src/dettools.c	(revision 9354)
+++ 	(revision )
@@ -1,78 +1,0 @@
-# include "dettools.h"
-
-int main (int argc, char **argv) {
-
-    psArray *imfiles;
-    psArray *frames;
-    psArray *pendingFrames;
-
-    dettoolsConfig (&config, argc, argv);
-
-    // -select options
-    if (config->mode == DET_MODE_SELECT_RAW) {
-	imfiles = detSelectInputImfiles (config, DET_STATE_RAW);
-	detWriteInputImfiles (config, imfiles);
-    }	
-
-    if (config->mode == DET_MODE_SELECT_RESID) {
-	imfiles = detSelectResidImfiles (config, DET_STATE_RAW);
-	detWriteResidImfiles (config, imfiles);
-    }	
-
-    if (config->mode == DET_MODE_SELECT_STACK) {
-	exposures = detSelectMasterExposuresForStack (config);
-	frames = detSelectMasterImfilesForStack (config, exposures);
-	detWriteStackFrames (config, frames);
-    }	
-
-    if (config->mode == DET_MODE_SELECT_NORM) {
-	frames  = detSelectMasterExposuresForNorm (config);
-	detWriteNormFrames (config, frames);
-    }	
-
-    // -update options
-    if (config->mode == DET_MODE_UPDATE_RAW) {
-	exposures = detSelectRawUpdateExposures (config);
-	detUpdateRawExposures (config, exposures);
-    }
-
-    if (config->mode == DET_MODE_UPDATE_RESID) {
-	exposures = detSelectResidUpdateExposures (config);
-	detUpdateResidExposures (config, exposures);
-    }
-
-    if (config->mode == DET_MODE_UPDATE_RUN) {
-	// select master detrend exposures where (state == MKRESID)
-	// foreach master exposure:
-	//   select matching resid exposures where (state == PROCESSED)
-	//   if (residExposures->n != nInput) continue;
-	//   calculate summary stats
-	//   set state of masterExposure
-	//   create new masterExposure iteration (if needed)
-	//   set state of masterRun (if done)
-    }
-
-    // -define options
-    if (config->mode == DET_MODE_DEFINE_RUN) {
-	// select matching group, if desired
-	// select matching raw exposures, imfiles
-	// create masterRun based on options
-	// create new inputExposures
-	// create new inputImfiles
-	// create new detrendImfiles
-    }
-
-    if (config->mode == DET_MODE_DEFINE_RESID) {
-	// select master detrend exposures where (state == NORMALIZED)
-	// foreach master exposure:
-	//   select matching input exposures where (state == PROCESSED)
-	//   foreach input exposure
-	//     create matching resid exposure
-	//     select matching input imfiles
-	//     foreach input imfile
-	//       create matching resid imfile
-	//   set master exposure state to MKRESID
-    }
-
-    exit (0);
-}
Index: unk/dettools/src/dettools.h
===================================================================
--- /trunk/dettools/src/dettools.h	(revision 9354)
+++ 	(revision )
@@ -1,76 +1,0 @@
-# include <stdio.h>
-# include <strings.h>
-# include <unistd.h>
-# include <pslib.h>
-# include "metadata.h"
-
-typedef enum {
-    DET_MODE_NONE,		      	// 
-    DET_MODE_QUICK,		      	// 
-    DET_MODE_SELECT_RAW,		// 
-    DET_MODE_SELECT_RESID,		// 
-    DET_MODE_SELECT_STACK,		// 
-    DET_MODE_SELECT_NORM,		// 
-
-    DET_MODE_UPDATE_RAW,		// 
-    DET_MODE_UPDATE_RESID,		// 
-    DET_MODE_UPDATE_RUN,		// 
-
-    DET_MODE_DEFINE_RUN,		// 
-    DET_MODE_DEFINE_RESID,		// 
-} detMode;
-
-typedef unsigned char detType;
-typedef unsigned char detState;
-
-typedef struct {
-    p2mode mode;
-
-    detType type;
-    char *camera;
-    char *filter;
-
-    bool groupSelect;
-    char *groupID;
-
-    bool timeSelect;
-    psTime start;
-    psTime stop;
-
-    bool exptimeSelect;
-    float exptimeMin;
-    float exptimeMax;
-
-    bool airmassSelect;
-    float airmassMin;
-    float airmassMax;
-
-    psDB *database;
-} detConfig;
-
-// these structures are defined in metadata.h using glueforge
-// typedef struct DetrendInputExposure;
-// typedef struct DetrendInputImfile;
-// typedef struct DetrendMasterRun;
-// typedef struct DetrendMasterExposure;
-// typedef struct DetrendMasterImfile;
-
-typedef struct {
-    ppRawExposure *exposure;
-    psArray *images;
-} ppRawFrame;
-
-typedef struct {
-    detMasterImfile *imfile;
-    psArray *inputImfiles;
-} detStackFrame;
-
-typedef struct {
-    detMasterExposure *exposure;
-    psArray *imfiles;
-} detNormFrame;
-
-typedef struct {
-    ppDoneExposure *exposure;
-    psArray *images;
-} p2DoneFrame;
Index: unk/dettools/src/dettoolsConfig.c
===================================================================
--- /trunk/dettools/src/dettoolsConfig.c	(revision 9354)
+++ 	(revision )
@@ -1,68 +1,0 @@
-# include "p2search.h"
-
-bool dettoolsConfig (psConfig *config, int argc, char **argv) {
-
-    // Parse the configurations (re-org a la ppImage)
-    config->site = NULL;            // Site configuration
-    config->camera = NULL;          // Camera configuration
-    config->recipe = NULL;          // Recipe configuration
-    if (! pmConfigRead(&config->site, &config->camera, &config->recipe, &argc, argv, RECIPE)) {
-        psErrorStackPrint(stderr, "Can't find site configuration!\n");
-        exit(EXIT_FAILURE);
-    }
-
-    // Parse other command-line arguments
-    config->arguments = psMetadataAlloc(); // The arguments, with default values
-
-    config->mode = P2_MODE_NONE;
-    if ((N = psArgumentGet (*argc, argv, "-quick"))) {
-	psArgumentRemove (N, argc, argv);
-	if (config->mode) psAbort ("p2search", "only one mode selection is allowed");
-	config->mode = P2_MODE_QUICK;
-    }
-    if ((N = psArgumentGet (*argc, argv, "-define"))) {
-	psArgumentRemove (N, argc, argv);
-	if (config->mode) psAbort ("p2search", "only one mode selection is allowed");
-	config->mode = P2_MODE_DEFINE;
-    }
-    if ((N = psArgumentGet (*argc, argv, "-pending"))) {
-	psArgumentRemove (N, argc, argv);
-	if (config->mode) psAbort ("p2search", "only one mode selection is allowed");
-	config->mode = P2_MODE_PENDING;
-    }
-    if ((N = psArgumentGet (*argc, argv, "-update"))) {
-	psArgumentRemove (N, argc, argv);
-	if (config->mode) psAbort ("p2search", "only one mode selection is allowed");
-	config->mode = P2_MODE_UPDATE;
-    }
-    if ((N = psArgumentGet (*argc, argv, "-done"))) {
-	psArgumentRemove (N, argc, argv);
-	if (config->mode) psAbort ("p2search", "only one mode selection is allowed");
-	config->mode = P2_MODE_UPDATE;
-    }
-
-    // paul's argument parsing convention requires: -key value 
-    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-quick",   0, "examine raw image table, write ppImage output", "");
-    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-define",  0, "examine raw image table, add to pending image table", "");
-    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-pending", 0, "examine pending image table, write ppImage output", "");
-    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-update",  0, "update pending image table", "");
-    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-time",    0, "define time range of interest", "");
-    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-camera",  0, "define camera of interest", "");
-    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-filter",  0, "define filter of interest", "");
-
-    if (! psArgumentParse(config->arguments, &argc, argv) || argc != 2) {
-        printf("\nPan-STARRS Phase 2 Search Tool\n\n");
-        printf("Usage: %s [mode] [options]\n\n", argv[0]);
-        printf(" [mode] : -quick | -define | -pending | -update\n\n");
-        psArgumentHelp(config->arguments);
-        psFree(config->arguments);
-        exit(EXIT_FAILURE);
-    }
-
-    // add the input and output images to the arguments list
-    psMetadataAddStr (config->arguments, PS_LIST_TAIL, "-output", 0, "Name of the output image", argv[1]);
-
-    // define Database handle, if used
-    config->database = pmConfigDB(config->site);
-    return true;
-} 
