Index: branches/eam_branches/ipp-20120405/ippTools/src/addtool.c
===================================================================
--- branches/eam_branches/ipp-20120405/ippTools/src/addtool.c	(revision 33724)
+++ branches/eam_branches/ipp-20120405/ippTools/src/addtool.c	(revision 33949)
@@ -1417,5 +1417,5 @@
   psString query = NULL;
   psStringAppend(&query, bare_query, minidvodb_group);
-  psStringAppend(&query, where_string);
+  psStringAppend(&query," %s ", where_string);
 
 
Index: branches/eam_branches/ipp-20120405/ippTools/src/pstamptoolConfig.c
===================================================================
--- branches/eam_branches/ipp-20120405/ippTools/src/pstamptoolConfig.c	(revision 33724)
+++ branches/eam_branches/ipp-20120405/ippTools/src/pstamptoolConfig.c	(revision 33949)
@@ -125,4 +125,6 @@
     psMetadataAddStr(revertreqArgs, PS_LIST_TAIL, "-state", 0,      "state to revert", NULL);
     psMetadataAddStr(revertreqArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by pstampRequest label (LIKE comparision)", NULL);
+    // this argument is supplied by pantasks so we accept it but don't use it
+    psMetadataAddU64(revertreqArgs, PS_LIST_TAIL, "-limit", 0,      "not used", 0);
 
     // -pendingcleanup
Index: branches/eam_branches/ipp-20120405/ippTools/src/pxspace.c
===================================================================
--- branches/eam_branches/ipp-20120405/ippTools/src/pxspace.c	(revision 33724)
+++ branches/eam_branches/ipp-20120405/ippTools/src/pxspace.c	(revision 33949)
@@ -56,2 +56,27 @@
     psMetadataAddF64(md, PS_LIST_TAIL, "-decl", 0,             "DEC value for radius search (degrees)", false);
 }
+
+void pxskycellAddArguments(psMetadata *md)
+{
+    psMetadataAddF32(md,  PS_LIST_TAIL, "-ra_min",            0, "search by right ascension (degrees)", NAN);
+    psMetadataAddF32(md,  PS_LIST_TAIL, "-dec_min",           0, "search by declination (degrees)", NAN);
+    psMetadataAddF32(md,  PS_LIST_TAIL, "-ra_max",            0, "search by right ascension (degrees)", NAN);
+    psMetadataAddF32(md,  PS_LIST_TAIL, "-dec_max",           0, "search by declination (degrees)", NAN);
+    psMetadataAddF32(md,  PS_LIST_TAIL, "-glong_min",         0, "search by galactic longitude (degrees)", NAN);
+    psMetadataAddF32(md,  PS_LIST_TAIL, "-glat_min",          0, "search by galactic latitude (degrees)", NAN);
+    psMetadataAddF32(md,  PS_LIST_TAIL, "-glong_max",         0, "search by galactic longitude (degrees)", NAN);
+    psMetadataAddF32(md,  PS_LIST_TAIL, "-glat_max",          0, "search by galactic latitude (degrees)", NAN);
+}
+
+bool pxskycellAddWhere(pxConfig *config, psMetadata *where)
+{
+    PXOPT_COPY_F32(config->args, where, "-ra_min", "skycell.radeg", ">=");
+    PXOPT_COPY_F32(config->args, where, "-dec_min", "skycell.decdeg", ">=");
+    PXOPT_COPY_F32(config->args, where, "-ra_max", "skycell.radeg", "<");
+    PXOPT_COPY_F32(config->args, where, "-dec_max", "skycell.decdeg", "<");
+    PXOPT_COPY_F32(config->args, where, "-glong_min", "skycell.glong", ">=");
+    PXOPT_COPY_F32(config->args, where, "-glat_min", "skycell.glat", ">=");
+    PXOPT_COPY_F32(config->args, where, "-glong_max", "skycell.glong", "<");
+    PXOPT_COPY_F32(config->args, where, "-glat_max", "skycell.glat", "<");
+    return true;
+}
Index: branches/eam_branches/ipp-20120405/ippTools/src/pxspace.h
===================================================================
--- branches/eam_branches/ipp-20120405/ippTools/src/pxspace.h	(revision 33724)
+++ branches/eam_branches/ipp-20120405/ippTools/src/pxspace.h	(revision 33949)
@@ -1,4 +1,4 @@
 /*
- * pxmagic.h
+ * pxspace.h
  *
  * Copyright (C) 2009  IfA
@@ -24,3 +24,6 @@
 extern void pxspaceAddArguments(psMetadata *md);
 
+extern bool pxskycellAddWhere(pxConfig *config, psMetadata *where);
+extern void pxskycellAddArguments(psMetadata *md);
+
 #endif // PXSPACE_H
Index: branches/eam_branches/ipp-20120405/ippTools/src/sctool.c
===================================================================
--- branches/eam_branches/ipp-20120405/ippTools/src/sctool.c	(revision 33724)
+++ branches/eam_branches/ipp-20120405/ippTools/src/sctool.c	(revision 33949)
@@ -31,8 +31,10 @@
 #include "pxdata.h"
 #include "pxchip.h"
+#include "pxspace.h"
 
 #include "sctool.h"
 
 static bool defineskycellsMode(pxConfig *config);
+static bool listMode(pxConfig *config);
 
 # define MODECASE(caseName, func) \
@@ -53,5 +55,6 @@
 
     switch (config->mode) {
-        MODECASE(SCTOOL_MODE_DEFINESKYCELLS,         defineskycellsMode);
+        MODECASE(SCTOOL_MODE_DEFINESKYCELLS,    defineskycellsMode);
+        MODECASE(SCTOOL_MODE_LIST,              listMode);
         default:
             psAbort("invalid option (this should not happen)");
@@ -131,2 +134,65 @@
     return true;
 }
+static bool listMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+    psMetadata *where = psMetadataAlloc();
+
+    PXOPT_COPY_STR(config->args, where, "-skycell_id", "skycell.skycell_id", "LIKE");
+    PXOPT_COPY_STR(config->args, where, "-tess_id", "skycell.tess_id", "LIKE");
+    pxskycellAddWhere(config, where);
+
+    psString query = pxDataGet("sctool_list.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
+        return false;
+    }
+
+    if (!psListLength(where->list)) {
+        psError(PXTOOLS_ERR_CONFIG, false, "search paramters are required\n");
+        psFree(where);
+        return false;
+    }
+    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
+    psStringAppend(&query, " WHERE %s", whereClause);
+    psFree(whereClause);
+
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
+    }
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
+
+    psArray *output = p_psDBFetchResult(config->dbh);
+    if (!output) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    if (!psArrayLength(output)) {
+        psTrace("sctool", PS_LOG_INFO, "no rows found");
+        psFree(output);
+        return true;
+    }
+
+    if (!ippdbPrintMetadatas(stdout, output, "skycell", !simple)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
+    }
+
+    psFree(output);
+
+
+    return true;
+}
Index: branches/eam_branches/ipp-20120405/ippTools/src/sctool.h
===================================================================
--- branches/eam_branches/ipp-20120405/ippTools/src/sctool.h	(revision 33724)
+++ branches/eam_branches/ipp-20120405/ippTools/src/sctool.h	(revision 33949)
@@ -26,4 +26,5 @@
     SCTOOL_MODE_NONE      = 0x0,
     SCTOOL_MODE_DEFINESKYCELLS,
+    SCTOOL_MODE_LIST,
 } sctoolMode;
 
Index: branches/eam_branches/ipp-20120405/ippTools/src/sctoolConfig.c
===================================================================
--- branches/eam_branches/ipp-20120405/ippTools/src/sctoolConfig.c	(revision 33949)
+++ branches/eam_branches/ipp-20120405/ippTools/src/sctoolConfig.c	(revision 33949)
@@ -0,0 +1,86 @@
+/*
+ * sctoolConfig.c
+ *
+ * Copyright (C) 2012 IfA University of Hawaii
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * program; see the file COPYING. If not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdint.h>
+
+#include <psmodules.h>
+
+#include "pxtools.h"
+#include "pxspace.h"
+#include "sctool.h"
+
+pxConfig *sctoolConfig(pxConfig *config, int argc, char **argv)
+{
+    if (!config) {
+        config = pxConfigAlloc();
+    }
+
+    pmConfigReadParamsSet(false);
+
+    config->modules = pmConfigRead(&argc, argv, NULL);
+    if (! config->modules) {
+        psError(psErrorCodeLast(), false, "Can't find site configuration");
+        psFree(config);
+        return NULL;
+    }
+
+    // -defineskycells
+    psMetadata *defineskycellsArgs = psMetadataAlloc();
+    psMetadataAddStr(defineskycellsArgs, PS_LIST_TAIL, "-input", 0, "file containing skycell data (required)", NULL);
+
+    // -list
+    psMetadata *listArgs = psMetadataAlloc();
+    psMetadataAddStr(listArgs,  PS_LIST_TAIL, "-skycell_id",        0, "search by skycell_id (LIKE comparision)", NULL);
+    psMetadataAddStr(listArgs,  PS_LIST_TAIL, "-tess_id",           0, "search by tess_id (LIKE comparision)", NULL);
+    // add skycell coordinate search arguments
+    pxskycellAddArguments(listArgs);
+    psMetadataAddU64(listArgs,  PS_LIST_TAIL, "-limit",             0, "limit result set to N items", 0);
+    psMetadataAddBool(listArgs, PS_LIST_TAIL, "-simple",            0, "use the simple output format", false);
+
+    psMetadata *argSets = psMetadataAlloc();
+    psMetadata *modes = psMetadataAlloc();
+
+    PXOPT_ADD_MODE("-defineskycells",        "insert skycells from mdc file",  SCTOOL_MODE_DEFINESKYCELLS,        defineskycellsArgs);
+    PXOPT_ADD_MODE("-list",                   "list skycell parameters",       SCTOOL_MODE_LIST,        listArgs);
+
+    if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
+        psError(PS_ERR_UNKNOWN, false, "option parsing failed");
+        psFree(argSets);
+        psFree(modes);
+        psFree(config);
+        return NULL;
+    }
+
+    psFree(argSets);
+    psFree(modes);
+
+    // define Database handle, if used
+    config->dbh = psMemIncrRefCounter(pmConfigDB(config->modules));
+    if (!config->dbh) {
+        psError(PS_ERR_UNKNOWN, false, "Can't configure database");
+        psFree(config);
+        return NULL;
+    }
+
+    return config;
+}
Index: branches/eam_branches/ipp-20120405/ippTools/src/stacktool.c
===================================================================
--- branches/eam_branches/ipp-20120405/ippTools/src/stacktool.c	(revision 33724)
+++ branches/eam_branches/ipp-20120405/ippTools/src/stacktool.c	(revision 33949)
@@ -232,4 +232,6 @@
     PXOPT_COPY_F32(config->args,  where, "-select_fwhm_minor_min",     "camProcessedExp.fwhm_minor", ">=");
     PXOPT_COPY_F32(config->args,  where, "-select_fwhm_minor_max",     "camProcessedExp.fwhm_minor", "<=");
+    PXOPT_COPY_F32(config->args,  where, "-select_elong_max",          "(camProcessedExp.fwhm_major / camProcessedExp.fwhm_minor)", "<=");
+    PXOPT_COPY_F32(config->args,  where, "-select_iq_elong_max",       "(camProcessedExp.iq_fwhm_major / camProcessedExp.iq_fwhm_minor)", "<=");
     PXOPT_COPY_F32(config->args,  where, "-select_iq_m2_max",          "camProcessedExp.iq_m2", "<=");
     PXOPT_COPY_F32(config->args,  where, "-select_iq_m2_min",          "camProcessedExp.iq_m2", ">=");
@@ -239,4 +241,6 @@
     PXOPT_COPY_F32(config->args,  where, "-select_zpt_obs_min",        "camProcessedExp.zpt_obs", ">=");
     PXOPT_COPY_F32(config->args,  where, "-select_zpt_obs_max",        "camProcessedExp.zpt_obs", "<=");
+    PXOPT_COPY_F32(config->args,  where, "-select_bg_max",             "camProcessedExp.bg", "<=");
+    PXOPT_COPY_F32(config->args,  where, "-select_bg_stdev_max",       "camProcessedExp.bg_stdev", "<=");
     PXOPT_COPY_F32(config->args,  where, "-select_astrom",             "sqrt(POWER(camProcessedExp.sigma_ra, 2) + POWER(camProcessedExp.sigma_dec, 2))", "<=");
 
Index: branches/eam_branches/ipp-20120405/ippTools/src/stacktoolConfig.c
===================================================================
--- branches/eam_branches/ipp-20120405/ippTools/src/stacktoolConfig.c	(revision 33724)
+++ branches/eam_branches/ipp-20120405/ippTools/src/stacktoolConfig.c	(revision 33949)
@@ -82,4 +82,6 @@
     psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_fwhm_minor_min", 0, "define min fwhm (minor axis)", NAN);
     psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_fwhm_minor_max", 0, "define max fwhm (minor axis)", NAN);
+    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_elong_max", 0, "define max elongation from fwhm ", NAN);
+    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_iq_elong_max", 0, "define max elongation from iq_fwhm ", NAN);
     psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_iq_m2_min", 0, "define min iq_m2", NAN);
     psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_iq_m2_max", 0, "define max iq_m2", NAN);
@@ -90,4 +92,6 @@
     psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_zpt_obs_min", 0, "define min zero point", NAN);
     psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_zpt_obs_max", 0, "define max zero point", NAN);
+    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_bg_max", 0, "define max background", NAN);
+    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_bg_stdev_max", 0, "define max background stdev", NAN);    
     psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_astrom", 0, "define max astrometry rms", NAN);
     psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-warp_id", PS_META_DUPLICATE_OK, "include this warp ID (multiple OK)", 0);
Index: branches/eam_branches/ipp-20120405/ippTools/src/staticskytool.c
===================================================================
--- branches/eam_branches/ipp-20120405/ippTools/src/staticskytool.c	(revision 33724)
+++ branches/eam_branches/ipp-20120405/ippTools/src/staticskytool.c	(revision 33949)
@@ -29,4 +29,5 @@
 
 #include "pxtools.h"
+#include "pxspace.h"
 #include "staticskytool.h"
 
@@ -131,4 +132,6 @@
     pxAddLabelSearchArgs(config, whereMD, "-select_data_group",    "stackRun.data_group",       "LIKE");
     pxAddLabelSearchArgs(config, whereMD, "-select_filter",        "stackRun.filter",           "LIKE");
+    PXOPT_COPY_F32(config->args, whereMD, "-select_glat_min",      "skycell.glat",              ">=");
+    PXOPT_COPY_F32(config->args, whereMD, "-select_glat_max",      "skycell.glat",              "<=");
 
     // find the number of requested filters:
@@ -390,7 +393,13 @@
 
     psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_S64(config->args, where, "-sky_id",  "sky_id",   "==");
-    PXOPT_COPY_STR(config->args, where, "-label",   "label",    "==");
-    PXOPT_COPY_STR(config->args, where, "-state",   "state",    "==");
+    PXOPT_COPY_S64(config->args, where, "-sky_id",      "sky_id",   "==");
+    PXOPT_COPY_STR(config->args, where, "-label",       "staticskyRun.label",    "==");
+    PXOPT_COPY_STR(config->args, where, "-state",       "staticskyRun.state",    "==");
+    PXOPT_COPY_STR(config->args, where, "-tess_id",     "stackRun.tess_id",    "==");
+    PXOPT_COPY_STR(config->args, where, "-skycell_id",  "stackRun.skycell_id",    "==");
+    if (!pxskycellAddWhere(config, where)) {
+        psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments");
+        return false;
+    }
     if (!psListLength(where->list)) {
         psFree(where);
@@ -399,5 +408,5 @@
     }
 
-    psString query = psStringCopy("UPDATE staticskyRun");
+    psString query = psStringCopy("UPDATE staticskyRun JOIN staticskyInput USING(sky_id) JOIN stackRun using(stack_id) JOIN skycell USING(tess_id, skycell_id)");
 
     // pxUpdateRun gets parameters from config->args and updates
@@ -638,4 +647,5 @@
     PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "LIKE");
     PXOPT_COPY_S16(config->args, where, "-fault",      "staticskyResult.fault", "==");
+    pxskycellAddWhere(config, where);
     PXOPT_LOOKUP_S32(num_filters, config->args, "-num_filters", false, false);
 
Index: branches/eam_branches/ipp-20120405/ippTools/src/staticskytoolConfig.c
===================================================================
--- branches/eam_branches/ipp-20120405/ippTools/src/staticskytoolConfig.c	(revision 33724)
+++ branches/eam_branches/ipp-20120405/ippTools/src/staticskytoolConfig.c	(revision 33949)
@@ -55,4 +55,6 @@
     psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-select_data_group", PS_META_DUPLICATE_OK, "search by stackRun data_group (LIKE comparison, multiple OK)", NULL);
     psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-select_filter", PS_META_DUPLICATE_OK, "search by filter (LIKE comparison, multiple OK)", NULL);
+    psMetadataAddF32(definebyqueryArgs,  PS_LIST_TAIL, "-select_glat_min", 0, "define min galactic latitude", NAN);
+    psMetadataAddF32(definebyqueryArgs,  PS_LIST_TAIL, "-select_glat_max", 0, "define max galactic latitude", NAN);
     psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-set_workdir", 0, "define workdir (required)", NULL);
     psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-set_label", 0, "define label (required)", NULL);
@@ -73,4 +75,7 @@
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0, "search by state", NULL);
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label", 0, "search by label", 0);
+    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-tess_id", 0, "search by tess_id", NULL);
+    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-skycell_id", 0, "search by skycell_id", NULL);
+    pxskycellAddArguments(updaterunArgs);
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label", 0, "define new value for label", NULL);
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state", 0, "define new state", NULL);
@@ -113,4 +118,5 @@
     psMetadataAddStr(resultArgs, PS_LIST_TAIL, "-data_group", 0, "search by data_group (LIKE comparison)", NULL);
     psMetadataAddS16(resultArgs, PS_LIST_TAIL, "-num_filters", 0, "search by number of filters in the inputs (>=)", 0);
+    pxskycellAddArguments(resultArgs);
     psMetadataAddS16(resultArgs, PS_LIST_TAIL, "-fault", 0, "search by fault code", 0);
     psMetadataAddU64(resultArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0);
