Index: branches/simmosaic_branches/ippTools/src/pxcam.c
===================================================================
--- branches/simmosaic_branches/ippTools/src/pxcam.c	(revision 24860)
+++ branches/simmosaic_branches/ippTools/src/pxcam.c	(revision 27839)
@@ -68,6 +68,6 @@
     psMetadataAddF64(md,  PS_LIST_TAIL, "-posang_max",         0, "define max rotator position angle", NAN);
     psMetadataAddStr(md,  PS_LIST_TAIL, "-object",             0, "search by exposure object", NULL);
-    psMetadataAddF32(md,  PS_LIST_TAIL, "-solang_min",         0, "define min solar angle", NAN);
-    psMetadataAddF32(md,  PS_LIST_TAIL, "-solang_max",         0, "define max solar angle", NAN);
+    psMetadataAddF32(md,  PS_LIST_TAIL, "-sun_angle_min",         0, "define min solar angle", NAN);
+    psMetadataAddF32(md,  PS_LIST_TAIL, "-sun_angle_max",         0, "define max solar angle", NAN);
 
     return true;
@@ -76,16 +76,16 @@
 bool pxcamGetSearchArgs (pxConfig *config, psMetadata *where) {
 
-    PXOPT_COPY_S64(config->args,   where, "-chip_id",            "chipRun.chip_id", 	 "==");
-    PXOPT_COPY_S64(config->args,   where, "-exp_id",             "rawExp.exp_id",   	 "==");
-    PXOPT_COPY_STR(config->args,   where, "-exp_name",           "rawExp.exp_name", 	 "==");
-    PXOPT_COPY_STR(config->args,   where, "-inst",               "rawExp.camera",   	 "==");
-    PXOPT_COPY_STR(config->args,   where, "-telescope",          "rawExp.telescope",	 "==");
-    PXOPT_COPY_TIME(config->args,  where, "-dateobs_begin",      "rawExp.dateobs",  	 ">=");
-    PXOPT_COPY_TIME(config->args,  where, "-dateobs_end",        "rawExp.dateobs",  	 "<=");
-    PXOPT_COPY_STR(config->args,   where, "-exp_tag",            "rawExp.exp_tag",  	 "==");
-    PXOPT_COPY_STR(config->args,   where, "-exp_type",           "rawExp.exp_type", 	 "==");
-    PXOPT_COPY_STR(config->args,   where, "-comment",            "rawExp.comment",  	 "LIKE");
-    PXOPT_COPY_STR(config->args,   where, "-filelevel",          "rawExp.filelevel",	 "==");
-    PXOPT_COPY_STR(config->args,   where, "-filter",             "rawExp.filter",         "==");
+    PXOPT_COPY_S64(config->args,   where, "-chip_id",            "chipRun.chip_id",      "==");
+    PXOPT_COPY_S64(config->args,   where, "-exp_id",             "rawExp.exp_id",        "==");
+    PXOPT_COPY_STR(config->args,   where, "-exp_name",           "rawExp.exp_name",      "==");
+    PXOPT_COPY_STR(config->args,   where, "-inst",               "rawExp.camera",        "==");
+    PXOPT_COPY_STR(config->args,   where, "-telescope",          "rawExp.telescope",     "==");
+    PXOPT_COPY_TIME(config->args,  where, "-dateobs_begin",      "rawExp.dateobs",       ">=");
+    PXOPT_COPY_TIME(config->args,  where, "-dateobs_end",        "rawExp.dateobs",       "<=");
+    PXOPT_COPY_STR(config->args,   where, "-exp_tag",            "rawExp.exp_tag",       "==");
+    PXOPT_COPY_STR(config->args,   where, "-exp_type",           "rawExp.exp_type",      "==");
+    PXOPT_COPY_STR(config->args,   where, "-comment",            "rawExp.comment",       "LIKE");
+    PXOPT_COPY_STR(config->args,   where, "-filelevel",          "rawExp.filelevel",     "==");
+    PXOPT_COPY_STR(config->args,   where, "-filter",             "rawExp.filter",         "LIKE");
     PXOPT_COPY_F64(config->args,   where, "-airmass_min",        "rawExp.airmass",        ">=");
     PXOPT_COPY_F64(config->args,   where, "-airmass_max",        "rawExp.airmass",        "<");
@@ -113,6 +113,6 @@
     PXOPT_COPY_F64(config->args,   where, "-posang_max",         "rawExp.posang",         "<");
     PXOPT_COPY_STR(config->args,   where, "-object",             "rawExp.object",         "==");
-    PXOPT_COPY_F32(config->args,   where, "-solang_min",         "rawExp.solang",         ">=");
-    PXOPT_COPY_F32(config->args,   where, "-solang_max",         "rawExp.solang",         "<");
+    PXOPT_COPY_F32(config->args,   where, "-sun_angle_min",         "rawExp.sun_angle",         ">=");
+    PXOPT_COPY_F32(config->args,   where, "-sun_angle_max",         "rawExp.sun_angle",         "<");
 
     return true;
@@ -141,86 +141,17 @@
 }
 
-
-bool pxcamRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *state)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-    PS_ASSERT_PTR_NON_NULL(state, false);
-
-    // check that state is a valid string value
-    if (!pxIsValidState(state)) {
-        psError(PS_ERR_UNKNOWN, false,
-                "invalid chipRun state: %s", state);
-        return false;
-    }
-
-    psString query = psStringCopy("UPDATE camRun JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET camRun.state = '%s'");
-
-    if (where) {
-        psString whereClause = psDBGenerateWhereSQL(where, NULL);
-        psStringAppend(&query, " %s", whereClause);
-        psFree(whereClause);
-    }
-
-    if (!p_psDBRunQueryF(config->dbh, query, state)) {
-        psFree(query);
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-
-    psFree(query);
-
-    return true;
-}
-
-
-bool pxcamRunSetLabel(pxConfig *config, psS64 cam_id, const char *label)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-    // note label == NULL should be explicitly allowed
-
-    char *query = "UPDATE camRun SET camRun.label = '%s' WHERE cam_id = %" PRId64;
-    if (!p_psDBRunQueryF(config->dbh, query, label, cam_id)) {
-        psError(PS_ERR_UNKNOWN, false,
-                "failed to change state for cam_id %" PRId64, cam_id);
-        return false;
-    }
-
-    return true;
-}
-
-bool pxcamRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-    // note label == NULL should be explicitly allowed
-
-    psString query = psStringCopy("UPDATE camRun JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET camRun.label = '%s'");
-
-    if (where) {
-        psString whereClause = psDBGenerateWhereSQL(where, NULL);
-        psStringAppend(&query, " %s", whereClause);
-        psFree(whereClause);
-    }
-
-    if (!p_psDBRunQueryF(config->dbh, query, label)) {
-        psFree(query);
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-
-    psFree(query);
-
-    return true;
-}
-
-
 bool pxcamQueueByChipID(pxConfig *config,
                     psS64 chip_id,
                     char *workdir,
                     char *label,
+                    char *data_group,
+                    char *dist_group,
                     char *recipe,
                     char *expgroup,
                     char *dvodb,
                     char *tess_id,
-                    char *end_stage)
+                    char *end_stage,
+                    psS64 magicked,
+                    char *note)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -232,5 +163,5 @@
         psMemSetPersistent(query, true);
         if (!query) {
-            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
             return false;
         }
@@ -238,5 +169,5 @@
 
     // queue the exp
-    // XXX chip_id is being cast here work around psS64 have a different type
+    // XXX chip_id and magicked are being cast here work around psS64 have a different type
     // different on 32/64
     if (!p_psDBRunQueryF(config->dbh, query,
@@ -245,4 +176,6 @@
                 "dirty", //workdir_state
                 label    ? label    : "NULL",
+                data_group ? data_group : "NULL",
+                dist_group ? dist_group : "NULL",
                 recipe   ? recipe   : "NULL",
                 expgroup ? expgroup : "NULL",
@@ -250,4 +183,6 @@
                 tess_id  ? tess_id  : "NULL",
                 end_stage ? end_stage : "NULL",
+                (long long) magicked,
+                note     ? note     : "NULL",
                 (long long)chip_id
     )) {
