Index: trunk/ippdb/src/ippdb.c
===================================================================
--- trunk/ippdb/src/ippdb.c	(revision 11733)
+++ trunk/ippdb/src/ippdb.c	(revision 11780)
@@ -64,10 +64,6 @@
 #define P4RUN_TABLE_NAME "p4Run"
 #define P4INPUTEXP_TABLE_NAME "p4InputExp"
+#define P4SKYCELLMAP_TABLE_NAME "p4SkyCellMap"
 #define P4SCFILE_TABLE_NAME "p4Scfile"
-#define P4INPUTSCFILE_TABLE_NAME "p4InputScfile"
-#define P4DIFFSCFILE_TABLE_NAME "p4DiffScfile"
-#define P4MAGICMASKIMFILE_TABLE_NAME "p4MagicMaskImfile"
-#define SKYCELL_TABLE_NAME "skyCell"
-#define SKYCELLMAP_TABLE_NAME "skyCellMap"
 #define MAX_STRING_LENGTH 1024
 
@@ -13462,5 +13458,5 @@
 static void p4RunRowFree(p4RunRow *object);
 
-p4RunRow *p4RunRowAlloc(psS32 p4a_id, const char *mode, const char *state, const char *workdir, psTime* registered)
+p4RunRow *p4RunRowAlloc(psS32 p4_id, const char *mode, const char *state, const char *workdir, psTime* registered)
 {
     p4RunRow        *_object;
@@ -13469,5 +13465,5 @@
     psMemSetDeallocator(_object, (psFreeFunc)p4RunRowFree);
 
-    _object->p4a_id = p4a_id;
+    _object->p4_id = p4_id;
     _object->mode = psStringCopy(mode);
     _object->state = psStringCopy(state);
@@ -13489,6 +13485,6 @@
 {
     psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, "Primary Key AUTO_INCREMENT", 0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key AUTO_INCREMENT", 0)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
         psFree(md);
         return false;
@@ -13527,9 +13523,9 @@
 }
 
-bool p4RunInsert(psDB * dbh, psS32 p4a_id, const char *mode, const char *state, const char *workdir, psTime* registered)
+bool p4RunInsert(psDB * dbh, psS32 p4_id, const char *mode, const char *state, const char *workdir, psTime* registered)
 {
     psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, NULL, p4a_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
         psFree(md);
         return false;
@@ -13578,5 +13574,5 @@
 bool p4RunInsertObject(psDB *dbh, p4RunRow *object)
 {
-    return p4RunInsert(dbh, object->p4a_id, object->mode, object->state, object->workdir, object->registered);
+    return p4RunInsert(dbh, object->p4_id, object->mode, object->state, object->workdir, object->registered);
 }
 
@@ -13651,6 +13647,6 @@
 {
     psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, NULL, object->p4a_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
         psFree(md);
         return false;
@@ -13685,7 +13681,7 @@
 
 bool status = false;
-    psS32 p4a_id = psMetadataLookupS32(&status, md, "p4a_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4a_id");
+    psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id");
         return false;
     }
@@ -13711,5 +13707,5 @@
     }
 
-    return p4RunRowAlloc(p4a_id, mode, state, workdir, registered);
+    return p4RunRowAlloc(p4_id, mode, state, workdir, registered);
 }
 psArray *p4RunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
@@ -13823,5 +13819,5 @@
 static void p4InputExpRowFree(p4InputExpRow *object);
 
-p4InputExpRow *p4InputExpRowAlloc(psS32 p4a_id, const char *exp_tag, psS32 p3_version, bool magiced)
+p4InputExpRow *p4InputExpRowAlloc(psS32 p4_id, const char *exp_tag, psS32 p3_version, bool magiced)
 {
     p4InputExpRow   *_object;
@@ -13830,5 +13826,5 @@
     psMemSetDeallocator(_object, (psFreeFunc)p4InputExpRowFree);
 
-    _object->p4a_id = p4a_id;
+    _object->p4_id = p4_id;
     _object->exp_tag = psStringCopy(exp_tag);
     _object->p3_version = p3_version;
@@ -13846,6 +13842,6 @@
 {
     psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, "Primary Key", 0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key", 0)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
         psFree(md);
         return false;
@@ -13879,9 +13875,9 @@
 }
 
-bool p4InputExpInsert(psDB * dbh, psS32 p4a_id, const char *exp_tag, psS32 p3_version, bool magiced)
+bool p4InputExpInsert(psDB * dbh, psS32 p4_id, const char *exp_tag, psS32 p3_version, bool magiced)
 {
     psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, NULL, p4a_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
         psFree(md);
         return false;
@@ -13925,5 +13921,5 @@
 bool p4InputExpInsertObject(psDB *dbh, p4InputExpRow *object)
 {
-    return p4InputExpInsert(dbh, object->p4a_id, object->exp_tag, object->p3_version, object->magiced);
+    return p4InputExpInsert(dbh, object->p4_id, object->exp_tag, object->p3_version, object->magiced);
 }
 
@@ -13998,6 +13994,6 @@
 {
     psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, NULL, object->p4a_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
         psFree(md);
         return false;
@@ -14027,7 +14023,7 @@
 
 bool status = false;
-    psS32 p4a_id = psMetadataLookupS32(&status, md, "p4a_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4a_id");
+    psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id");
         return false;
     }
@@ -14048,5 +14044,5 @@
     }
 
-    return p4InputExpRowAlloc(p4a_id, exp_tag, p3_version, magiced);
+    return p4InputExpRowAlloc(p4_id, exp_tag, p3_version, magiced);
 }
 psArray *p4InputExpSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
@@ -14158,7 +14154,389 @@
     return true;
 }
+static void p4SkyCellMapRowFree(p4SkyCellMapRow *object);
+
+p4SkyCellMapRow *p4SkyCellMapRowAlloc(psS32 p4_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *class_id)
+{
+    p4SkyCellMapRow *_object;
+
+    _object = psAlloc(sizeof(p4SkyCellMapRow));
+    psMemSetDeallocator(_object, (psFreeFunc)p4SkyCellMapRowFree);
+
+    _object->p4_id = p4_id;
+    _object->skycell_id = psStringCopy(skycell_id);
+    _object->tess_id = psStringCopy(tess_id);
+    _object->exp_tag = psStringCopy(exp_tag);
+    _object->p3_version = p3_version;
+    _object->class_id = psStringCopy(class_id);
+
+    return _object;
+}
+
+static void p4SkyCellMapRowFree(p4SkyCellMapRow *object)
+{
+    psFree(object->skycell_id);
+    psFree(object->tess_id);
+    psFree(object->exp_tag);
+    psFree(object->class_id);
+}
+
+bool p4SkyCellMapCreateTable(psDB *dbh)
+{
+    psMetadata *md = psMetadataAlloc();
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key", 0)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
+        psFree(md);
+        return false;
+    }
+
+    bool status = psDBCreateTable(dbh, P4SKYCELLMAP_TABLE_NAME, md);
+
+    psFree(md);
+
+    return status;
+}
+
+bool p4SkyCellMapDropTable(psDB *dbh)
+{
+    return psDBDropTable(dbh, P4SKYCELLMAP_TABLE_NAME);
+}
+
+bool p4SkyCellMapInsert(psDB * dbh, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *class_id)
+{
+    psMetadata *md = psMetadataAlloc();
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
+        psFree(md);
+        return false;
+    }
+
+    bool status = psDBInsertOneRow(dbh, P4SKYCELLMAP_TABLE_NAME, md);
+    psFree(md);
+
+    return status;
+}
+
+long long p4SkyCellMapDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
+{
+    long long       deleted = 0;
+
+    long long count = psDBDeleteRows(dbh, P4SKYCELLMAP_TABLE_NAME, where, limit);
+    if (count < 0) {
+        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4SkyCellMap");
+        return count;
+
+        deleted += count;
+    }
+
+    return deleted;
+}
+bool p4SkyCellMapInsertObject(psDB *dbh, p4SkyCellMapRow *object)
+{
+    return p4SkyCellMapInsert(dbh, object->p4_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->class_id);
+}
+
+bool p4SkyCellMapInsertObjects(psDB *dbh, psArray *objects)
+{
+    for (long i = 0; i < psArrayLength(objects); i++) {
+        if (!p4SkyCellMapInsertObject(dbh, objects->data[i])) {
+            return false;
+        }
+    }
+
+    return true;
+}
+
+bool p4SkyCellMapInsertFits(psDB *dbh, const psFits *fits)
+{
+    psArray         *rowSet;
+
+    // move to (the first?) extension named  P4SKYCELLMAP_TABLE_NAME
+    if (!psFitsMoveExtName(fits, P4SKYCELLMAP_TABLE_NAME)) {
+        psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4SKYCELLMAP_TABLE_NAME);
+        return false;
+    }
+
+    // check HDU type
+    if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
+        psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
+        return false;
+    }
+
+    // read fits table
+    rowSet = psFitsReadTable(fits);
+    if (!rowSet) {
+        psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
+        psFree(rowSet);
+        return false;
+    }
+
+    if (!psDBInsertRows(dbh, P4SKYCELLMAP_TABLE_NAME, rowSet)) {
+        psError(PS_ERR_UNKNOWN, false, "databse insert failed");
+        psFree(rowSet);
+        return false;
+    }
+
+    psFree(rowSet);
+
+    return true;
+}
+
+bool p4SkyCellMapSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
+{
+    psArray         *rowSet;
+
+    rowSet = psDBSelectRows(dbh, P4SKYCELLMAP_TABLE_NAME, where, limit);
+    if (!rowSet) {
+        return false;
+    }
+
+    // output to fits
+    if (!psFitsWriteTable(fits, NULL, rowSet, P4SKYCELLMAP_TABLE_NAME)) {
+        psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
+        psFree(rowSet);
+        return false;
+    }
+
+    psFree(rowSet);
+
+    return true;
+}
+
+psMetadata *p4SkyCellMapMetadataFromObject(const p4SkyCellMapRow *object)
+{
+    psMetadata *md = psMetadataAlloc();
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
+        psFree(md);
+        return false;
+    }
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
+        psFree(md);
+        return false;
+    }
+
+
+    return md;
+}
+
+p4SkyCellMapRow *p4SkyCellMapObjectFromMetadata(psMetadata *md)
+{
+
+bool status = false;
+    psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id");
+        return false;
+    }
+    char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");
+        return false;
+    }
+    char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");
+        return false;
+    }
+    char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag");
+        return false;
+    }
+    psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version");
+        return false;
+    }
+    char* class_id = psMetadataLookupPtr(&status, md, "class_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id");
+        return false;
+    }
+
+    return p4SkyCellMapRowAlloc(p4_id, skycell_id, tess_id, exp_tag, p3_version, class_id);
+}
+psArray *p4SkyCellMapSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
+{
+    psArray         *rowSet;
+    psArray         *returnSet;
+    psU64           i;
+
+    rowSet = psDBSelectRows(dbh, P4SKYCELLMAP_TABLE_NAME, where, limit);
+    if (!rowSet) {
+        return NULL;
+    }
+
+    // convert psMetadata rows to row objects
+
+    returnSet = psArrayAllocEmpty(rowSet->n);
+
+    for (i = 0; i < rowSet->n; i++) {
+        p4SkyCellMapRow *object = p4SkyCellMapObjectFromMetadata(rowSet->data[i]);
+        psArrayAdd(returnSet, 0, object);
+        psFree(object);
+    }
+
+    psFree(rowSet);
+
+    return returnSet;
+}
+bool p4SkyCellMapDeleteObject(psDB *dbh, const p4SkyCellMapRow *object)
+{
+    psMetadata *where = p4SkyCellMapMetadataFromObject(object);
+    long long count = psDBDeleteRows(dbh, P4SKYCELLMAP_TABLE_NAME, where, 0);
+    psFree(where);
+    if (count < 0) {
+        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4SkyCellMap");
+        return false;
+    }
+    if (count > 1) {
+        // XXX should this be a psAbort() instead?  It is possible that
+        // having an object match multiple rows was by design.
+        psError(PS_ERR_UNKNOWN, true, "p4SkyCellMapRow object matched more then one row.  Check your database schema");
+        return false;
+    }
+
+    return true;
+}
+long long p4SkyCellMapDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
+{
+    long long       deleted = 0;
+
+    for (long long i = 0; i < objects->n; i++) {
+        p4SkyCellMapRow *object = objects->data[i];
+        psMetadata *where = p4SkyCellMapMetadataFromObject(object);
+        long long count = psDBDeleteRows(dbh, P4SKYCELLMAP_TABLE_NAME, where, limit);
+        psFree(where);
+        if (count < 0) {
+            psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4SkyCellMap");
+            return count;
+        }
+
+        deleted += count;
+    }
+
+    return deleted;
+}
+bool p4SkyCellMapPrintObjects(FILE *stream, psArray *objects, bool mdcf)
+{
+    PS_ASSERT_PTR_NON_NULL(objects, false);
+
+    psMetadata *output = psMetadataAlloc();
+    for (long i = 0; i < psArrayLength(objects); i++) {
+        psMetadata *md = p4SkyCellMapMetadataFromObject(objects->data[i]);
+        if (!psMetadataAddMetadata(
+            output,
+            PS_LIST_TAIL,
+            P4SKYCELLMAP_TABLE_NAME,
+            PS_META_DUPLICATE_OK,
+            NULL,
+            md
+        )) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
+            psFree(md);
+            psFree(output);
+            return false;
+        }
+        psFree(md);
+    }
+
+    if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
+        psFree(output);
+    }
+    psFree(output);
+
+    return true;
+}
+bool p4SkyCellMapPrintObject(FILE *stream, p4SkyCellMapRow *object, bool mdcf)
+{
+    PS_ASSERT_PTR_NON_NULL(object, false);
+
+    psMetadata *md = p4SkyCellMapMetadataFromObject(object);
+
+    if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
+        psFree(md);
+    }
+
+    psFree(md);
+
+    return true;
+}
 static void p4ScfileRowFree(p4ScfileRow *object);
 
-p4ScfileRow *p4ScfileRowAlloc(psS32 p4a_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev)
+p4ScfileRow *p4ScfileRowAlloc(psS32 p4_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev)
 {
     p4ScfileRow     *_object;
@@ -14167,5 +14545,5 @@
     psMemSetDeallocator(_object, (psFreeFunc)p4ScfileRowFree);
 
-    _object->p4a_id = p4a_id;
+    _object->p4_id = p4_id;
     _object->skycell_id = psStringCopy(skycell_id);
     _object->tess_id = psStringCopy(tess_id);
@@ -14190,6 +14568,6 @@
 {
     psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, "Primary Key", 0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key", 0)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
         psFree(md);
         return false;
@@ -14243,9 +14621,9 @@
 }
 
-bool p4ScfileInsert(psDB * dbh, psS32 p4a_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev)
+bool p4ScfileInsert(psDB * dbh, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev)
 {
     psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, NULL, p4a_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
         psFree(md);
         return false;
@@ -14309,5 +14687,5 @@
 bool p4ScfileInsertObject(psDB *dbh, p4ScfileRow *object)
 {
-    return p4ScfileInsert(dbh, object->p4a_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->uri, object->bg, object->bg_mean_stdev);
+    return p4ScfileInsert(dbh, object->p4_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->uri, object->bg, object->bg_mean_stdev);
 }
 
@@ -14382,6 +14760,6 @@
 {
     psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, NULL, object->p4a_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
+    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
         psFree(md);
         return false;
@@ -14431,7 +14809,7 @@
 
 bool status = false;
-    psS32 p4a_id = psMetadataLookupS32(&status, md, "p4a_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4a_id");
+    psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id");
         return false;
     }
@@ -14472,5 +14850,5 @@
     }
 
-    return p4ScfileRowAlloc(p4a_id, skycell_id, tess_id, exp_tag, p3_version, uri, bg, bg_mean_stdev);
+    return p4ScfileRowAlloc(p4_id, skycell_id, tess_id, exp_tag, p3_version, uri, bg, bg_mean_stdev);
 }
 psArray *p4ScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
@@ -14582,1972 +14960,2 @@
     return true;
 }
-static void p4InputScfileRowFree(p4InputScfileRow *object);
-
-p4InputScfileRow *p4InputScfileRowAlloc(psS32 p4b_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *kind)
-{
-    p4InputScfileRow *_object;
-
-    _object = psAlloc(sizeof(p4InputScfileRow));
-    psMemSetDeallocator(_object, (psFreeFunc)p4InputScfileRowFree);
-
-    _object->p4b_id = p4b_id;
-    _object->skycell_id = psStringCopy(skycell_id);
-    _object->tess_id = psStringCopy(tess_id);
-    _object->exp_tag = psStringCopy(exp_tag);
-    _object->p3_version = p3_version;
-    _object->kind = psStringCopy(kind);
-
-    return _object;
-}
-
-static void p4InputScfileRowFree(p4InputScfileRow *object)
-{
-    psFree(object->skycell_id);
-    psFree(object->tess_id);
-    psFree(object->exp_tag);
-    psFree(object->kind);
-}
-
-bool p4InputScfileCreateTable(psDB *dbh)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, "Primary Key", 0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, "Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item kind");
-        psFree(md);
-        return false;
-    }
-
-    bool status = psDBCreateTable(dbh, P4INPUTSCFILE_TABLE_NAME, md);
-
-    psFree(md);
-
-    return status;
-}
-
-bool p4InputScfileDropTable(psDB *dbh)
-{
-    return psDBDropTable(dbh, P4INPUTSCFILE_TABLE_NAME);
-}
-
-bool p4InputScfileInsert(psDB * dbh, psS32 p4b_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *kind)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, NULL, p4b_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, kind)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item kind");
-        psFree(md);
-        return false;
-    }
-
-    bool status = psDBInsertOneRow(dbh, P4INPUTSCFILE_TABLE_NAME, md);
-    psFree(md);
-
-    return status;
-}
-
-long long p4InputScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
-{
-    long long       deleted = 0;
-
-    long long count = psDBDeleteRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, limit);
-    if (count < 0) {
-        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputScfile");
-        return count;
-
-        deleted += count;
-    }
-
-    return deleted;
-}
-bool p4InputScfileInsertObject(psDB *dbh, p4InputScfileRow *object)
-{
-    return p4InputScfileInsert(dbh, object->p4b_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->kind);
-}
-
-bool p4InputScfileInsertObjects(psDB *dbh, psArray *objects)
-{
-    for (long i = 0; i < psArrayLength(objects); i++) {
-        if (!p4InputScfileInsertObject(dbh, objects->data[i])) {
-            return false;
-        }
-    }
-
-    return true;
-}
-
-bool p4InputScfileInsertFits(psDB *dbh, const psFits *fits)
-{
-    psArray         *rowSet;
-
-    // move to (the first?) extension named  P4INPUTSCFILE_TABLE_NAME
-    if (!psFitsMoveExtName(fits, P4INPUTSCFILE_TABLE_NAME)) {
-        psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4INPUTSCFILE_TABLE_NAME);
-        return false;
-    }
-
-    // check HDU type
-    if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
-        psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
-        return false;
-    }
-
-    // read fits table
-    rowSet = psFitsReadTable(fits);
-    if (!rowSet) {
-        psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
-        psFree(rowSet);
-        return false;
-    }
-
-    if (!psDBInsertRows(dbh, P4INPUTSCFILE_TABLE_NAME, rowSet)) {
-        psError(PS_ERR_UNKNOWN, false, "databse insert failed");
-        psFree(rowSet);
-        return false;
-    }
-
-    psFree(rowSet);
-
-    return true;
-}
-
-bool p4InputScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
-{
-    psArray         *rowSet;
-
-    rowSet = psDBSelectRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, limit);
-    if (!rowSet) {
-        return false;
-    }
-
-    // output to fits
-    if (!psFitsWriteTable(fits, NULL, rowSet, P4INPUTSCFILE_TABLE_NAME)) {
-        psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
-        psFree(rowSet);
-        return false;
-    }
-
-    psFree(rowSet);
-
-    return true;
-}
-
-psMetadata *p4InputScfileMetadataFromObject(const p4InputScfileRow *object)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, NULL, object->p4b_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, object->kind)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item kind");
-        psFree(md);
-        return false;
-    }
-
-
-    return md;
-}
-
-p4InputScfileRow *p4InputScfileObjectFromMetadata(psMetadata *md)
-{
-
-bool status = false;
-    psS32 p4b_id = psMetadataLookupS32(&status, md, "p4b_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4b_id");
-        return false;
-    }
-    char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");
-        return false;
-    }
-    char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");
-        return false;
-    }
-    char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag");
-        return false;
-    }
-    psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version");
-        return false;
-    }
-    char* kind = psMetadataLookupPtr(&status, md, "kind");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item kind");
-        return false;
-    }
-
-    return p4InputScfileRowAlloc(p4b_id, skycell_id, tess_id, exp_tag, p3_version, kind);
-}
-psArray *p4InputScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
-{
-    psArray         *rowSet;
-    psArray         *returnSet;
-    psU64           i;
-
-    rowSet = psDBSelectRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, limit);
-    if (!rowSet) {
-        return NULL;
-    }
-
-    // convert psMetadata rows to row objects
-
-    returnSet = psArrayAllocEmpty(rowSet->n);
-
-    for (i = 0; i < rowSet->n; i++) {
-        p4InputScfileRow *object = p4InputScfileObjectFromMetadata(rowSet->data[i]);
-        psArrayAdd(returnSet, 0, object);
-        psFree(object);
-    }
-
-    psFree(rowSet);
-
-    return returnSet;
-}
-bool p4InputScfileDeleteObject(psDB *dbh, const p4InputScfileRow *object)
-{
-    psMetadata *where = p4InputScfileMetadataFromObject(object);
-    long long count = psDBDeleteRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, 0);
-    psFree(where);
-    if (count < 0) {
-        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputScfile");
-        return false;
-    }
-    if (count > 1) {
-        // XXX should this be a psAbort() instead?  It is possible that
-        // having an object match multiple rows was by design.
-        psError(PS_ERR_UNKNOWN, true, "p4InputScfileRow object matched more then one row.  Check your database schema");
-        return false;
-    }
-
-    return true;
-}
-long long p4InputScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
-{
-    long long       deleted = 0;
-
-    for (long long i = 0; i < objects->n; i++) {
-        p4InputScfileRow *object = objects->data[i];
-        psMetadata *where = p4InputScfileMetadataFromObject(object);
-        long long count = psDBDeleteRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, limit);
-        psFree(where);
-        if (count < 0) {
-            psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputScfile");
-            return count;
-        }
-
-        deleted += count;
-    }
-
-    return deleted;
-}
-bool p4InputScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)
-{
-    PS_ASSERT_PTR_NON_NULL(objects, false);
-
-    psMetadata *output = psMetadataAlloc();
-    for (long i = 0; i < psArrayLength(objects); i++) {
-        psMetadata *md = p4InputScfileMetadataFromObject(objects->data[i]);
-        if (!psMetadataAddMetadata(
-            output,
-            PS_LIST_TAIL,
-            P4INPUTSCFILE_TABLE_NAME,
-            PS_META_DUPLICATE_OK,
-            NULL,
-            md
-        )) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
-            psFree(md);
-            psFree(output);
-            return false;
-        }
-        psFree(md);
-    }
-
-    if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
-        psFree(output);
-    }
-    psFree(output);
-
-    return true;
-}
-bool p4InputScfilePrintObject(FILE *stream, p4InputScfileRow *object, bool mdcf)
-{
-    PS_ASSERT_PTR_NON_NULL(object, false);
-
-    psMetadata *md = p4InputScfileMetadataFromObject(object);
-
-    if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
-        psFree(md);
-    }
-
-    psFree(md);
-
-    return true;
-}
-static void p4DiffScfileRowFree(p4DiffScfileRow *object);
-
-p4DiffScfileRow *p4DiffScfileRowAlloc(psS32 p4b_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev)
-{
-    p4DiffScfileRow *_object;
-
-    _object = psAlloc(sizeof(p4DiffScfileRow));
-    psMemSetDeallocator(_object, (psFreeFunc)p4DiffScfileRowFree);
-
-    _object->p4b_id = p4b_id;
-    _object->skycell_id = psStringCopy(skycell_id);
-    _object->tess_id = psStringCopy(tess_id);
-    _object->exp_tag = psStringCopy(exp_tag);
-    _object->p3_version = p3_version;
-    _object->uri = psStringCopy(uri);
-    _object->bg = bg;
-    _object->bg_mean_stdev = bg_mean_stdev;
-
-    return _object;
-}
-
-static void p4DiffScfileRowFree(p4DiffScfileRow *object)
-{
-    psFree(object->skycell_id);
-    psFree(object->tess_id);
-    psFree(object->exp_tag);
-    psFree(object->uri);
-}
-
-bool p4DiffScfileCreateTable(psDB *dbh)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, "Primary Key", 0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, 0.0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item bg");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, 0.0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev");
-        psFree(md);
-        return false;
-    }
-
-    bool status = psDBCreateTable(dbh, P4DIFFSCFILE_TABLE_NAME, md);
-
-    psFree(md);
-
-    return status;
-}
-
-bool p4DiffScfileDropTable(psDB *dbh)
-{
-    return psDBDropTable(dbh, P4DIFFSCFILE_TABLE_NAME);
-}
-
-bool p4DiffScfileInsert(psDB * dbh, psS32 p4b_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, NULL, p4b_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, bg)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item bg");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, bg_mean_stdev)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev");
-        psFree(md);
-        return false;
-    }
-
-    bool status = psDBInsertOneRow(dbh, P4DIFFSCFILE_TABLE_NAME, md);
-    psFree(md);
-
-    return status;
-}
-
-long long p4DiffScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
-{
-    long long       deleted = 0;
-
-    long long count = psDBDeleteRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, limit);
-    if (count < 0) {
-        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4DiffScfile");
-        return count;
-
-        deleted += count;
-    }
-
-    return deleted;
-}
-bool p4DiffScfileInsertObject(psDB *dbh, p4DiffScfileRow *object)
-{
-    return p4DiffScfileInsert(dbh, object->p4b_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->uri, object->bg, object->bg_mean_stdev);
-}
-
-bool p4DiffScfileInsertObjects(psDB *dbh, psArray *objects)
-{
-    for (long i = 0; i < psArrayLength(objects); i++) {
-        if (!p4DiffScfileInsertObject(dbh, objects->data[i])) {
-            return false;
-        }
-    }
-
-    return true;
-}
-
-bool p4DiffScfileInsertFits(psDB *dbh, const psFits *fits)
-{
-    psArray         *rowSet;
-
-    // move to (the first?) extension named  P4DIFFSCFILE_TABLE_NAME
-    if (!psFitsMoveExtName(fits, P4DIFFSCFILE_TABLE_NAME)) {
-        psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4DIFFSCFILE_TABLE_NAME);
-        return false;
-    }
-
-    // check HDU type
-    if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
-        psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
-        return false;
-    }
-
-    // read fits table
-    rowSet = psFitsReadTable(fits);
-    if (!rowSet) {
-        psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
-        psFree(rowSet);
-        return false;
-    }
-
-    if (!psDBInsertRows(dbh, P4DIFFSCFILE_TABLE_NAME, rowSet)) {
-        psError(PS_ERR_UNKNOWN, false, "databse insert failed");
-        psFree(rowSet);
-        return false;
-    }
-
-    psFree(rowSet);
-
-    return true;
-}
-
-bool p4DiffScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
-{
-    psArray         *rowSet;
-
-    rowSet = psDBSelectRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, limit);
-    if (!rowSet) {
-        return false;
-    }
-
-    // output to fits
-    if (!psFitsWriteTable(fits, NULL, rowSet, P4DIFFSCFILE_TABLE_NAME)) {
-        psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
-        psFree(rowSet);
-        return false;
-    }
-
-    psFree(rowSet);
-
-    return true;
-}
-
-psMetadata *p4DiffScfileMetadataFromObject(const p4DiffScfileRow *object)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, NULL, object->p4b_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, object->bg)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item bg");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, object->bg_mean_stdev)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev");
-        psFree(md);
-        return false;
-    }
-
-
-    return md;
-}
-
-p4DiffScfileRow *p4DiffScfileObjectFromMetadata(psMetadata *md)
-{
-
-bool status = false;
-    psS32 p4b_id = psMetadataLookupS32(&status, md, "p4b_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4b_id");
-        return false;
-    }
-    char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");
-        return false;
-    }
-    char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");
-        return false;
-    }
-    char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag");
-        return false;
-    }
-    psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version");
-        return false;
-    }
-    char* uri = psMetadataLookupPtr(&status, md, "uri");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri");
-        return false;
-    }
-    psF64 bg = psMetadataLookupF64(&status, md, "bg");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg");
-        return false;
-    }
-    psF64 bg_mean_stdev = psMetadataLookupF64(&status, md, "bg_mean_stdev");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_mean_stdev");
-        return false;
-    }
-
-    return p4DiffScfileRowAlloc(p4b_id, skycell_id, tess_id, exp_tag, p3_version, uri, bg, bg_mean_stdev);
-}
-psArray *p4DiffScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
-{
-    psArray         *rowSet;
-    psArray         *returnSet;
-    psU64           i;
-
-    rowSet = psDBSelectRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, limit);
-    if (!rowSet) {
-        return NULL;
-    }
-
-    // convert psMetadata rows to row objects
-
-    returnSet = psArrayAllocEmpty(rowSet->n);
-
-    for (i = 0; i < rowSet->n; i++) {
-        p4DiffScfileRow *object = p4DiffScfileObjectFromMetadata(rowSet->data[i]);
-        psArrayAdd(returnSet, 0, object);
-        psFree(object);
-    }
-
-    psFree(rowSet);
-
-    return returnSet;
-}
-bool p4DiffScfileDeleteObject(psDB *dbh, const p4DiffScfileRow *object)
-{
-    psMetadata *where = p4DiffScfileMetadataFromObject(object);
-    long long count = psDBDeleteRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, 0);
-    psFree(where);
-    if (count < 0) {
-        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4DiffScfile");
-        return false;
-    }
-    if (count > 1) {
-        // XXX should this be a psAbort() instead?  It is possible that
-        // having an object match multiple rows was by design.
-        psError(PS_ERR_UNKNOWN, true, "p4DiffScfileRow object matched more then one row.  Check your database schema");
-        return false;
-    }
-
-    return true;
-}
-long long p4DiffScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
-{
-    long long       deleted = 0;
-
-    for (long long i = 0; i < objects->n; i++) {
-        p4DiffScfileRow *object = objects->data[i];
-        psMetadata *where = p4DiffScfileMetadataFromObject(object);
-        long long count = psDBDeleteRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, limit);
-        psFree(where);
-        if (count < 0) {
-            psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4DiffScfile");
-            return count;
-        }
-
-        deleted += count;
-    }
-
-    return deleted;
-}
-bool p4DiffScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)
-{
-    PS_ASSERT_PTR_NON_NULL(objects, false);
-
-    psMetadata *output = psMetadataAlloc();
-    for (long i = 0; i < psArrayLength(objects); i++) {
-        psMetadata *md = p4DiffScfileMetadataFromObject(objects->data[i]);
-        if (!psMetadataAddMetadata(
-            output,
-            PS_LIST_TAIL,
-            P4DIFFSCFILE_TABLE_NAME,
-            PS_META_DUPLICATE_OK,
-            NULL,
-            md
-        )) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
-            psFree(md);
-            psFree(output);
-            return false;
-        }
-        psFree(md);
-    }
-
-    if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
-        psFree(output);
-    }
-    psFree(output);
-
-    return true;
-}
-bool p4DiffScfilePrintObject(FILE *stream, p4DiffScfileRow *object, bool mdcf)
-{
-    PS_ASSERT_PTR_NON_NULL(object, false);
-
-    psMetadata *md = p4DiffScfileMetadataFromObject(object);
-
-    if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
-        psFree(md);
-    }
-
-    psFree(md);
-
-    return true;
-}
-static void p4MagicMaskImfileRowFree(p4MagicMaskImfileRow *object);
-
-p4MagicMaskImfileRow *p4MagicMaskImfileRowAlloc(psS32 p4c_id, const char *exp_tag, psS32 p3_version, const char *class_id, const char *uri)
-{
-    p4MagicMaskImfileRow *_object;
-
-    _object = psAlloc(sizeof(p4MagicMaskImfileRow));
-    psMemSetDeallocator(_object, (psFreeFunc)p4MagicMaskImfileRowFree);
-
-    _object->p4c_id = p4c_id;
-    _object->exp_tag = psStringCopy(exp_tag);
-    _object->p3_version = p3_version;
-    _object->class_id = psStringCopy(class_id);
-    _object->uri = psStringCopy(uri);
-
-    return _object;
-}
-
-static void p4MagicMaskImfileRowFree(p4MagicMaskImfileRow *object)
-{
-    psFree(object->exp_tag);
-    psFree(object->class_id);
-    psFree(object->uri);
-}
-
-bool p4MagicMaskImfileCreateTable(psDB *dbh)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4c_id", PS_DATA_S32, "Primary Key", 0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4c_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
-        psFree(md);
-        return false;
-    }
-
-    bool status = psDBCreateTable(dbh, P4MAGICMASKIMFILE_TABLE_NAME, md);
-
-    psFree(md);
-
-    return status;
-}
-
-bool p4MagicMaskImfileDropTable(psDB *dbh)
-{
-    return psDBDropTable(dbh, P4MAGICMASKIMFILE_TABLE_NAME);
-}
-
-bool p4MagicMaskImfileInsert(psDB * dbh, psS32 p4c_id, const char *exp_tag, psS32 p3_version, const char *class_id, const char *uri)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4c_id", PS_DATA_S32, NULL, p4c_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4c_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
-        psFree(md);
-        return false;
-    }
-
-    bool status = psDBInsertOneRow(dbh, P4MAGICMASKIMFILE_TABLE_NAME, md);
-    psFree(md);
-
-    return status;
-}
-
-long long p4MagicMaskImfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
-{
-    long long       deleted = 0;
-
-    long long count = psDBDeleteRows(dbh, P4MAGICMASKIMFILE_TABLE_NAME, where, limit);
-    if (count < 0) {
-        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4MagicMaskImfile");
-        return count;
-
-        deleted += count;
-    }
-
-    return deleted;
-}
-bool p4MagicMaskImfileInsertObject(psDB *dbh, p4MagicMaskImfileRow *object)
-{
-    return p4MagicMaskImfileInsert(dbh, object->p4c_id, object->exp_tag, object->p3_version, object->class_id, object->uri);
-}
-
-bool p4MagicMaskImfileInsertObjects(psDB *dbh, psArray *objects)
-{
-    for (long i = 0; i < psArrayLength(objects); i++) {
-        if (!p4MagicMaskImfileInsertObject(dbh, objects->data[i])) {
-            return false;
-        }
-    }
-
-    return true;
-}
-
-bool p4MagicMaskImfileInsertFits(psDB *dbh, const psFits *fits)
-{
-    psArray         *rowSet;
-
-    // move to (the first?) extension named  P4MAGICMASKIMFILE_TABLE_NAME
-    if (!psFitsMoveExtName(fits, P4MAGICMASKIMFILE_TABLE_NAME)) {
-        psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4MAGICMASKIMFILE_TABLE_NAME);
-        return false;
-    }
-
-    // check HDU type
-    if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
-        psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
-        return false;
-    }
-
-    // read fits table
-    rowSet = psFitsReadTable(fits);
-    if (!rowSet) {
-        psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
-        psFree(rowSet);
-        return false;
-    }
-
-    if (!psDBInsertRows(dbh, P4MAGICMASKIMFILE_TABLE_NAME, rowSet)) {
-        psError(PS_ERR_UNKNOWN, false, "databse insert failed");
-        psFree(rowSet);
-        return false;
-    }
-
-    psFree(rowSet);
-
-    return true;
-}
-
-bool p4MagicMaskImfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
-{
-    psArray         *rowSet;
-
-    rowSet = psDBSelectRows(dbh, P4MAGICMASKIMFILE_TABLE_NAME, where, limit);
-    if (!rowSet) {
-        return false;
-    }
-
-    // output to fits
-    if (!psFitsWriteTable(fits, NULL, rowSet, P4MAGICMASKIMFILE_TABLE_NAME)) {
-        psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
-        psFree(rowSet);
-        return false;
-    }
-
-    psFree(rowSet);
-
-    return true;
-}
-
-psMetadata *p4MagicMaskImfileMetadataFromObject(const p4MagicMaskImfileRow *object)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4c_id", PS_DATA_S32, NULL, object->p4c_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p4c_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
-        psFree(md);
-        return false;
-    }
-
-
-    return md;
-}
-
-p4MagicMaskImfileRow *p4MagicMaskImfileObjectFromMetadata(psMetadata *md)
-{
-
-bool status = false;
-    psS32 p4c_id = psMetadataLookupS32(&status, md, "p4c_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4c_id");
-        return false;
-    }
-    char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag");
-        return false;
-    }
-    psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version");
-        return false;
-    }
-    char* class_id = psMetadataLookupPtr(&status, md, "class_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id");
-        return false;
-    }
-    char* uri = psMetadataLookupPtr(&status, md, "uri");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri");
-        return false;
-    }
-
-    return p4MagicMaskImfileRowAlloc(p4c_id, exp_tag, p3_version, class_id, uri);
-}
-psArray *p4MagicMaskImfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
-{
-    psArray         *rowSet;
-    psArray         *returnSet;
-    psU64           i;
-
-    rowSet = psDBSelectRows(dbh, P4MAGICMASKIMFILE_TABLE_NAME, where, limit);
-    if (!rowSet) {
-        return NULL;
-    }
-
-    // convert psMetadata rows to row objects
-
-    returnSet = psArrayAllocEmpty(rowSet->n);
-
-    for (i = 0; i < rowSet->n; i++) {
-        p4MagicMaskImfileRow *object = p4MagicMaskImfileObjectFromMetadata(rowSet->data[i]);
-        psArrayAdd(returnSet, 0, object);
-        psFree(object);
-    }
-
-    psFree(rowSet);
-
-    return returnSet;
-}
-bool p4MagicMaskImfileDeleteObject(psDB *dbh, const p4MagicMaskImfileRow *object)
-{
-    psMetadata *where = p4MagicMaskImfileMetadataFromObject(object);
-    long long count = psDBDeleteRows(dbh, P4MAGICMASKIMFILE_TABLE_NAME, where, 0);
-    psFree(where);
-    if (count < 0) {
-        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4MagicMaskImfile");
-        return false;
-    }
-    if (count > 1) {
-        // XXX should this be a psAbort() instead?  It is possible that
-        // having an object match multiple rows was by design.
-        psError(PS_ERR_UNKNOWN, true, "p4MagicMaskImfileRow object matched more then one row.  Check your database schema");
-        return false;
-    }
-
-    return true;
-}
-long long p4MagicMaskImfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
-{
-    long long       deleted = 0;
-
-    for (long long i = 0; i < objects->n; i++) {
-        p4MagicMaskImfileRow *object = objects->data[i];
-        psMetadata *where = p4MagicMaskImfileMetadataFromObject(object);
-        long long count = psDBDeleteRows(dbh, P4MAGICMASKIMFILE_TABLE_NAME, where, limit);
-        psFree(where);
-        if (count < 0) {
-            psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4MagicMaskImfile");
-            return count;
-        }
-
-        deleted += count;
-    }
-
-    return deleted;
-}
-bool p4MagicMaskImfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)
-{
-    PS_ASSERT_PTR_NON_NULL(objects, false);
-
-    psMetadata *output = psMetadataAlloc();
-    for (long i = 0; i < psArrayLength(objects); i++) {
-        psMetadata *md = p4MagicMaskImfileMetadataFromObject(objects->data[i]);
-        if (!psMetadataAddMetadata(
-            output,
-            PS_LIST_TAIL,
-            P4MAGICMASKIMFILE_TABLE_NAME,
-            PS_META_DUPLICATE_OK,
-            NULL,
-            md
-        )) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
-            psFree(md);
-            psFree(output);
-            return false;
-        }
-        psFree(md);
-    }
-
-    if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
-        psFree(output);
-    }
-    psFree(output);
-
-    return true;
-}
-bool p4MagicMaskImfilePrintObject(FILE *stream, p4MagicMaskImfileRow *object, bool mdcf)
-{
-    PS_ASSERT_PTR_NON_NULL(object, false);
-
-    psMetadata *md = p4MagicMaskImfileMetadataFromObject(object);
-
-    if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
-        psFree(md);
-    }
-
-    psFree(md);
-
-    return true;
-}
-static void skyCellRowFree(skyCellRow *object);
-
-skyCellRow *skyCellRowAlloc(const char *skycell_id, const char *tess_id, psF64 ra1, psF64 decl1, psF64 ra2, psF64 decl2, psF64 ra3, psF64 decl3, psF64 ra4, psF64 decl4)
-{
-    skyCellRow      *_object;
-
-    _object = psAlloc(sizeof(skyCellRow));
-    psMemSetDeallocator(_object, (psFreeFunc)skyCellRowFree);
-
-    _object->skycell_id = psStringCopy(skycell_id);
-    _object->tess_id = psStringCopy(tess_id);
-    _object->ra1 = ra1;
-    _object->decl1 = decl1;
-    _object->ra2 = ra2;
-    _object->decl2 = decl2;
-    _object->ra3 = ra3;
-    _object->decl3 = decl3;
-    _object->ra4 = ra4;
-    _object->decl4 = decl4;
-
-    return _object;
-}
-
-static void skyCellRowFree(skyCellRow *object)
-{
-    psFree(object->skycell_id);
-    psFree(object->tess_id);
-}
-
-bool skyCellCreateTable(psDB *dbh)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "ra1", PS_DATA_F64, NULL, 0.0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item ra1");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "decl1", PS_DATA_F64, NULL, 0.0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item decl1");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "ra2", PS_DATA_F64, NULL, 0.0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item ra2");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "decl2", PS_DATA_F64, NULL, 0.0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item decl2");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "ra3", PS_DATA_F64, NULL, 0.0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item ra3");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "decl3", PS_DATA_F64, NULL, 0.0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item decl3");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "ra4", PS_DATA_F64, NULL, 0.0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item ra4");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "decl4", PS_DATA_F64, NULL, 0.0)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item decl4");
-        psFree(md);
-        return false;
-    }
-
-    bool status = psDBCreateTable(dbh, SKYCELL_TABLE_NAME, md);
-
-    psFree(md);
-
-    return status;
-}
-
-bool skyCellDropTable(psDB *dbh)
-{
-    return psDBDropTable(dbh, SKYCELL_TABLE_NAME);
-}
-
-bool skyCellInsert(psDB * dbh, const char *skycell_id, const char *tess_id, psF64 ra1, psF64 decl1, psF64 ra2, psF64 decl2, psF64 ra3, psF64 decl3, psF64 ra4, psF64 decl4)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "ra1", PS_DATA_F64, NULL, ra1)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item ra1");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "decl1", PS_DATA_F64, NULL, decl1)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item decl1");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "ra2", PS_DATA_F64, NULL, ra2)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item ra2");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "decl2", PS_DATA_F64, NULL, decl2)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item decl2");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "ra3", PS_DATA_F64, NULL, ra3)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item ra3");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "decl3", PS_DATA_F64, NULL, decl3)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item decl3");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "ra4", PS_DATA_F64, NULL, ra4)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item ra4");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "decl4", PS_DATA_F64, NULL, decl4)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item decl4");
-        psFree(md);
-        return false;
-    }
-
-    bool status = psDBInsertOneRow(dbh, SKYCELL_TABLE_NAME, md);
-    psFree(md);
-
-    return status;
-}
-
-long long skyCellDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
-{
-    long long       deleted = 0;
-
-    long long count = psDBDeleteRows(dbh, SKYCELL_TABLE_NAME, where, limit);
-    if (count < 0) {
-        psError(PS_ERR_UNKNOWN, true, "failed to delete row from skyCell");
-        return count;
-
-        deleted += count;
-    }
-
-    return deleted;
-}
-bool skyCellInsertObject(psDB *dbh, skyCellRow *object)
-{
-    return skyCellInsert(dbh, object->skycell_id, object->tess_id, object->ra1, object->decl1, object->ra2, object->decl2, object->ra3, object->decl3, object->ra4, object->decl4);
-}
-
-bool skyCellInsertObjects(psDB *dbh, psArray *objects)
-{
-    for (long i = 0; i < psArrayLength(objects); i++) {
-        if (!skyCellInsertObject(dbh, objects->data[i])) {
-            return false;
-        }
-    }
-
-    return true;
-}
-
-bool skyCellInsertFits(psDB *dbh, const psFits *fits)
-{
-    psArray         *rowSet;
-
-    // move to (the first?) extension named  SKYCELL_TABLE_NAME
-    if (!psFitsMoveExtName(fits, SKYCELL_TABLE_NAME)) {
-        psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", SKYCELL_TABLE_NAME);
-        return false;
-    }
-
-    // check HDU type
-    if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
-        psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
-        return false;
-    }
-
-    // read fits table
-    rowSet = psFitsReadTable(fits);
-    if (!rowSet) {
-        psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
-        psFree(rowSet);
-        return false;
-    }
-
-    if (!psDBInsertRows(dbh, SKYCELL_TABLE_NAME, rowSet)) {
-        psError(PS_ERR_UNKNOWN, false, "databse insert failed");
-        psFree(rowSet);
-        return false;
-    }
-
-    psFree(rowSet);
-
-    return true;
-}
-
-bool skyCellSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
-{
-    psArray         *rowSet;
-
-    rowSet = psDBSelectRows(dbh, SKYCELL_TABLE_NAME, where, limit);
-    if (!rowSet) {
-        return false;
-    }
-
-    // output to fits
-    if (!psFitsWriteTable(fits, NULL, rowSet, SKYCELL_TABLE_NAME)) {
-        psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
-        psFree(rowSet);
-        return false;
-    }
-
-    psFree(rowSet);
-
-    return true;
-}
-
-psMetadata *skyCellMetadataFromObject(const skyCellRow *object)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "ra1", PS_DATA_F64, NULL, object->ra1)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item ra1");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "decl1", PS_DATA_F64, NULL, object->decl1)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item decl1");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "ra2", PS_DATA_F64, NULL, object->ra2)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item ra2");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "decl2", PS_DATA_F64, NULL, object->decl2)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item decl2");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "ra3", PS_DATA_F64, NULL, object->ra3)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item ra3");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "decl3", PS_DATA_F64, NULL, object->decl3)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item decl3");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "ra4", PS_DATA_F64, NULL, object->ra4)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item ra4");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "decl4", PS_DATA_F64, NULL, object->decl4)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item decl4");
-        psFree(md);
-        return false;
-    }
-
-
-    return md;
-}
-
-skyCellRow *skyCellObjectFromMetadata(psMetadata *md)
-{
-
-bool status = false;
-    char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");
-        return false;
-    }
-    char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");
-        return false;
-    }
-    psF64 ra1 = psMetadataLookupF64(&status, md, "ra1");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item ra1");
-        return false;
-    }
-    psF64 decl1 = psMetadataLookupF64(&status, md, "decl1");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item decl1");
-        return false;
-    }
-    psF64 ra2 = psMetadataLookupF64(&status, md, "ra2");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item ra2");
-        return false;
-    }
-    psF64 decl2 = psMetadataLookupF64(&status, md, "decl2");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item decl2");
-        return false;
-    }
-    psF64 ra3 = psMetadataLookupF64(&status, md, "ra3");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item ra3");
-        return false;
-    }
-    psF64 decl3 = psMetadataLookupF64(&status, md, "decl3");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item decl3");
-        return false;
-    }
-    psF64 ra4 = psMetadataLookupF64(&status, md, "ra4");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item ra4");
-        return false;
-    }
-    psF64 decl4 = psMetadataLookupF64(&status, md, "decl4");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item decl4");
-        return false;
-    }
-
-    return skyCellRowAlloc(skycell_id, tess_id, ra1, decl1, ra2, decl2, ra3, decl3, ra4, decl4);
-}
-psArray *skyCellSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
-{
-    psArray         *rowSet;
-    psArray         *returnSet;
-    psU64           i;
-
-    rowSet = psDBSelectRows(dbh, SKYCELL_TABLE_NAME, where, limit);
-    if (!rowSet) {
-        return NULL;
-    }
-
-    // convert psMetadata rows to row objects
-
-    returnSet = psArrayAllocEmpty(rowSet->n);
-
-    for (i = 0; i < rowSet->n; i++) {
-        skyCellRow *object = skyCellObjectFromMetadata(rowSet->data[i]);
-        psArrayAdd(returnSet, 0, object);
-        psFree(object);
-    }
-
-    psFree(rowSet);
-
-    return returnSet;
-}
-bool skyCellDeleteObject(psDB *dbh, const skyCellRow *object)
-{
-    psMetadata *where = skyCellMetadataFromObject(object);
-    long long count = psDBDeleteRows(dbh, SKYCELL_TABLE_NAME, where, 0);
-    psFree(where);
-    if (count < 0) {
-        psError(PS_ERR_UNKNOWN, true, "failed to delete row from skyCell");
-        return false;
-    }
-    if (count > 1) {
-        // XXX should this be a psAbort() instead?  It is possible that
-        // having an object match multiple rows was by design.
-        psError(PS_ERR_UNKNOWN, true, "skyCellRow object matched more then one row.  Check your database schema");
-        return false;
-    }
-
-    return true;
-}
-long long skyCellDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
-{
-    long long       deleted = 0;
-
-    for (long long i = 0; i < objects->n; i++) {
-        skyCellRow *object = objects->data[i];
-        psMetadata *where = skyCellMetadataFromObject(object);
-        long long count = psDBDeleteRows(dbh, SKYCELL_TABLE_NAME, where, limit);
-        psFree(where);
-        if (count < 0) {
-            psError(PS_ERR_UNKNOWN, true, "failed to delete row from skyCell");
-            return count;
-        }
-
-        deleted += count;
-    }
-
-    return deleted;
-}
-bool skyCellPrintObjects(FILE *stream, psArray *objects, bool mdcf)
-{
-    PS_ASSERT_PTR_NON_NULL(objects, false);
-
-    psMetadata *output = psMetadataAlloc();
-    for (long i = 0; i < psArrayLength(objects); i++) {
-        psMetadata *md = skyCellMetadataFromObject(objects->data[i]);
-        if (!psMetadataAddMetadata(
-            output,
-            PS_LIST_TAIL,
-            SKYCELL_TABLE_NAME,
-            PS_META_DUPLICATE_OK,
-            NULL,
-            md
-        )) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
-            psFree(md);
-            psFree(output);
-            return false;
-        }
-        psFree(md);
-    }
-
-    if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
-        psFree(output);
-    }
-    psFree(output);
-
-    return true;
-}
-bool skyCellPrintObject(FILE *stream, skyCellRow *object, bool mdcf)
-{
-    PS_ASSERT_PTR_NON_NULL(object, false);
-
-    psMetadata *md = skyCellMetadataFromObject(object);
-
-    if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
-        psFree(md);
-    }
-
-    psFree(md);
-
-    return true;
-}
-static void skyCellMapRowFree(skyCellMapRow *object);
-
-skyCellMapRow *skyCellMapRowAlloc(const char *skycell_id, const char *tess_id, const char *exp_tag, const char *class_id)
-{
-    skyCellMapRow   *_object;
-
-    _object = psAlloc(sizeof(skyCellMapRow));
-    psMemSetDeallocator(_object, (psFreeFunc)skyCellMapRowFree);
-
-    _object->skycell_id = psStringCopy(skycell_id);
-    _object->tess_id = psStringCopy(tess_id);
-    _object->exp_tag = psStringCopy(exp_tag);
-    _object->class_id = psStringCopy(class_id);
-
-    return _object;
-}
-
-static void skyCellMapRowFree(skyCellMapRow *object)
-{
-    psFree(object->skycell_id);
-    psFree(object->tess_id);
-    psFree(object->exp_tag);
-    psFree(object->class_id);
-}
-
-bool skyCellMapCreateTable(psDB *dbh)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
-        psFree(md);
-        return false;
-    }
-
-    bool status = psDBCreateTable(dbh, SKYCELLMAP_TABLE_NAME, md);
-
-    psFree(md);
-
-    return status;
-}
-
-bool skyCellMapDropTable(psDB *dbh)
-{
-    return psDBDropTable(dbh, SKYCELLMAP_TABLE_NAME);
-}
-
-bool skyCellMapInsert(psDB * dbh, const char *skycell_id, const char *tess_id, const char *exp_tag, const char *class_id)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
-        psFree(md);
-        return false;
-    }
-
-    bool status = psDBInsertOneRow(dbh, SKYCELLMAP_TABLE_NAME, md);
-    psFree(md);
-
-    return status;
-}
-
-long long skyCellMapDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
-{
-    long long       deleted = 0;
-
-    long long count = psDBDeleteRows(dbh, SKYCELLMAP_TABLE_NAME, where, limit);
-    if (count < 0) {
-        psError(PS_ERR_UNKNOWN, true, "failed to delete row from skyCellMap");
-        return count;
-
-        deleted += count;
-    }
-
-    return deleted;
-}
-bool skyCellMapInsertObject(psDB *dbh, skyCellMapRow *object)
-{
-    return skyCellMapInsert(dbh, object->skycell_id, object->tess_id, object->exp_tag, object->class_id);
-}
-
-bool skyCellMapInsertObjects(psDB *dbh, psArray *objects)
-{
-    for (long i = 0; i < psArrayLength(objects); i++) {
-        if (!skyCellMapInsertObject(dbh, objects->data[i])) {
-            return false;
-        }
-    }
-
-    return true;
-}
-
-bool skyCellMapInsertFits(psDB *dbh, const psFits *fits)
-{
-    psArray         *rowSet;
-
-    // move to (the first?) extension named  SKYCELLMAP_TABLE_NAME
-    if (!psFitsMoveExtName(fits, SKYCELLMAP_TABLE_NAME)) {
-        psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", SKYCELLMAP_TABLE_NAME);
-        return false;
-    }
-
-    // check HDU type
-    if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
-        psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
-        return false;
-    }
-
-    // read fits table
-    rowSet = psFitsReadTable(fits);
-    if (!rowSet) {
-        psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
-        psFree(rowSet);
-        return false;
-    }
-
-    if (!psDBInsertRows(dbh, SKYCELLMAP_TABLE_NAME, rowSet)) {
-        psError(PS_ERR_UNKNOWN, false, "databse insert failed");
-        psFree(rowSet);
-        return false;
-    }
-
-    psFree(rowSet);
-
-    return true;
-}
-
-bool skyCellMapSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
-{
-    psArray         *rowSet;
-
-    rowSet = psDBSelectRows(dbh, SKYCELLMAP_TABLE_NAME, where, limit);
-    if (!rowSet) {
-        return false;
-    }
-
-    // output to fits
-    if (!psFitsWriteTable(fits, NULL, rowSet, SKYCELLMAP_TABLE_NAME)) {
-        psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
-        psFree(rowSet);
-        return false;
-    }
-
-    psFree(rowSet);
-
-    return true;
-}
-
-psMetadata *skyCellMapMetadataFromObject(const skyCellMapRow *object)
-{
-    psMetadata *md = psMetadataAlloc();
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-        psFree(md);
-        return false;
-    }
-    if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
-        psFree(md);
-        return false;
-    }
-
-
-    return md;
-}
-
-skyCellMapRow *skyCellMapObjectFromMetadata(psMetadata *md)
-{
-
-bool status = false;
-    char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");
-        return false;
-    }
-    char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");
-        return false;
-    }
-    char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag");
-        return false;
-    }
-    char* class_id = psMetadataLookupPtr(&status, md, "class_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id");
-        return false;
-    }
-
-    return skyCellMapRowAlloc(skycell_id, tess_id, exp_tag, class_id);
-}
-psArray *skyCellMapSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
-{
-    psArray         *rowSet;
-    psArray         *returnSet;
-    psU64           i;
-
-    rowSet = psDBSelectRows(dbh, SKYCELLMAP_TABLE_NAME, where, limit);
-    if (!rowSet) {
-        return NULL;
-    }
-
-    // convert psMetadata rows to row objects
-
-    returnSet = psArrayAllocEmpty(rowSet->n);
-
-    for (i = 0; i < rowSet->n; i++) {
-        skyCellMapRow *object = skyCellMapObjectFromMetadata(rowSet->data[i]);
-        psArrayAdd(returnSet, 0, object);
-        psFree(object);
-    }
-
-    psFree(rowSet);
-
-    return returnSet;
-}
-bool skyCellMapDeleteObject(psDB *dbh, const skyCellMapRow *object)
-{
-    psMetadata *where = skyCellMapMetadataFromObject(object);
-    long long count = psDBDeleteRows(dbh, SKYCELLMAP_TABLE_NAME, where, 0);
-    psFree(where);
-    if (count < 0) {
-        psError(PS_ERR_UNKNOWN, true, "failed to delete row from skyCellMap");
-        return false;
-    }
-    if (count > 1) {
-        // XXX should this be a psAbort() instead?  It is possible that
-        // having an object match multiple rows was by design.
-        psError(PS_ERR_UNKNOWN, true, "skyCellMapRow object matched more then one row.  Check your database schema");
-        return false;
-    }
-
-    return true;
-}
-long long skyCellMapDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
-{
-    long long       deleted = 0;
-
-    for (long long i = 0; i < objects->n; i++) {
-        skyCellMapRow *object = objects->data[i];
-        psMetadata *where = skyCellMapMetadataFromObject(object);
-        long long count = psDBDeleteRows(dbh, SKYCELLMAP_TABLE_NAME, where, limit);
-        psFree(where);
-        if (count < 0) {
-            psError(PS_ERR_UNKNOWN, true, "failed to delete row from skyCellMap");
-            return count;
-        }
-
-        deleted += count;
-    }
-
-    return deleted;
-}
-bool skyCellMapPrintObjects(FILE *stream, psArray *objects, bool mdcf)
-{
-    PS_ASSERT_PTR_NON_NULL(objects, false);
-
-    psMetadata *output = psMetadataAlloc();
-    for (long i = 0; i < psArrayLength(objects); i++) {
-        psMetadata *md = skyCellMapMetadataFromObject(objects->data[i]);
-        if (!psMetadataAddMetadata(
-            output,
-            PS_LIST_TAIL,
-            SKYCELLMAP_TABLE_NAME,
-            PS_META_DUPLICATE_OK,
-            NULL,
-            md
-        )) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
-            psFree(md);
-            psFree(output);
-            return false;
-        }
-        psFree(md);
-    }
-
-    if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
-        psFree(output);
-    }
-    psFree(output);
-
-    return true;
-}
-bool skyCellMapPrintObject(FILE *stream, skyCellMapRow *object, bool mdcf)
-{
-    PS_ASSERT_PTR_NON_NULL(object, false);
-
-    psMetadata *md = skyCellMapMetadataFromObject(object);
-
-    if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
-        psFree(md);
-    }
-
-    psFree(md);
-
-    return true;
-}
