Index: /trunk/ippdb/Makefile.am
===================================================================
--- /trunk/ippdb/Makefile.am	(revision 11779)
+++ /trunk/ippdb/Makefile.am	(revision 11780)
@@ -43,13 +43,9 @@
     $(top_builddir)/docs/man/man3/p4RunRow.3 \
     $(top_builddir)/docs/man/man3/p4InputExpRow.3 \
-    $(top_builddir)/docs/man/man3/p4ScfileRow.3 \
-    $(top_builddir)/docs/man/man3/p4InputScfileRow.3 \
-    $(top_builddir)/docs/man/man3/p4DiffScfileRow.3 \
-    $(top_builddir)/docs/man/man3/p4MagicMaskImfileRow.3 \
-    $(top_builddir)/docs/man/man3/skyCellRow.3 \
-    $(top_builddir)/docs/man/man3/skyCellMapRow.3 
+    $(top_builddir)/docs/man/man3/p4SkyCellMapRow.3 \
+    $(top_builddir)/docs/man/man3/p4ScfileRow.3 
 
 
-docs/man/man3/ippdb.3 docs/man/man3/expTagCounterRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/summitImfileRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/pzDoneExpRow.3 docs/man/man3/pzDoneImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawExpRow.3 docs/man/man3/rawImfileRow.3 docs/man/man3/p1PendingExpRow.3 docs/man/man3/p2PendingExpRow.3 docs/man/man3/p2PendingImfileRow.3 docs/man/man3/p2ProcessedExpRow.3 docs/man/man3/p2MaskRow.3 docs/man/man3/p2ProcessedImfileRow.3 docs/man/man3/p3PendingExpRow.3 docs/man/man3/p3ProcessedExpRow.3 docs/man/man3/p3MaskRow.3 docs/man/man3/detRunRow.3 docs/man/man3/detInputExpRow.3 docs/man/man3/detProcessedImfileRow.3 docs/man/man3/detProcessedExpRow.3 docs/man/man3/detStackedImfileRow.3 docs/man/man3/detNormalizedStatImfileRow.3 docs/man/man3/detNormalizedImfileRow.3 docs/man/man3/detNormalizedExpRow.3 docs/man/man3/detResidImfileRow.3 docs/man/man3/detResidExpRow.3 docs/man/man3/detRunSummaryRow.3 docs/man/man3/p4RunRow.3 docs/man/man3/p4InputExpRow.3 docs/man/man3/p4ScfileRow.3 docs/man/man3/p4InputScfileRow.3 docs/man/man3/p4DiffScfileRow.3 docs/man/man3/p4MagicMaskImfileRow.3 docs/man/man3/skyCellRow.3 docs/man/man3/skyCellMapRow.3:
+docs/man/man3/ippdb.3 docs/man/man3/expTagCounterRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/summitImfileRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/pzDoneExpRow.3 docs/man/man3/pzDoneImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawExpRow.3 docs/man/man3/rawImfileRow.3 docs/man/man3/p1PendingExpRow.3 docs/man/man3/p2PendingExpRow.3 docs/man/man3/p2PendingImfileRow.3 docs/man/man3/p2ProcessedExpRow.3 docs/man/man3/p2MaskRow.3 docs/man/man3/p2ProcessedImfileRow.3 docs/man/man3/p3PendingExpRow.3 docs/man/man3/p3ProcessedExpRow.3 docs/man/man3/p3MaskRow.3 docs/man/man3/detRunRow.3 docs/man/man3/detInputExpRow.3 docs/man/man3/detProcessedImfileRow.3 docs/man/man3/detProcessedExpRow.3 docs/man/man3/detStackedImfileRow.3 docs/man/man3/detNormalizedStatImfileRow.3 docs/man/man3/detNormalizedImfileRow.3 docs/man/man3/detNormalizedExpRow.3 docs/man/man3/detResidImfileRow.3 docs/man/man3/detResidExpRow.3 docs/man/man3/detRunSummaryRow.3 docs/man/man3/p4RunRow.3 docs/man/man3/p4InputExpRow.3 docs/man/man3/p4SkyCellMapRow.3 docs/man/man3/p4ScfileRow.3:
 	$(DOXYGEN)
 
Index: /trunk/ippdb/configure.ac
===================================================================
--- /trunk/ippdb/configure.ac	(revision 11779)
+++ /trunk/ippdb/configure.ac	(revision 11780)
@@ -7,5 +7,5 @@
 AC_PREREQ(2.59)
 
-AC_INIT([ippdb], [1.1.4], [pan-starrs.ifa.hawaii.edu])
+AC_INIT([ippdb], [1.1.5], [pan-starrs.ifa.hawaii.edu])
 AC_CONFIG_SRCDIR([ippdb.pc.in])
 
Index: /trunk/ippdb/src/ippdb.c
===================================================================
--- /trunk/ippdb/src/ippdb.c	(revision 11779)
+++ /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;
-}
Index: /trunk/ippdb/src/ippdb.h
===================================================================
--- /trunk/ippdb/src/ippdb.h	(revision 11779)
+++ /trunk/ippdb/src/ippdb.h	(revision 11780)
@@ -6836,5 +6836,5 @@
 
 typedef struct {
-    psS32           p4a_id;
+    psS32           p4_id;
     char            *mode;
     char            *state;
@@ -6849,5 +6849,5 @@
 
 p4RunRow *p4RunRowAlloc(
-    psS32           p4a_id,
+    psS32           p4_id,
     const char      *mode,
     const char      *state,
@@ -6883,5 +6883,5 @@
 bool p4RunInsert(
     psDB            *dbh,               ///< Database handle
-    psS32           p4a_id,
+    psS32           p4_id,
     const char      *mode,
     const char      *state,
@@ -7043,5 +7043,5 @@
 
 typedef struct {
-    psS32           p4a_id;
+    psS32           p4_id;
     char            *exp_tag;
     psS32           p3_version;
@@ -7055,5 +7055,5 @@
 
 p4InputExpRow *p4InputExpRowAlloc(
-    psS32           p4a_id,
+    psS32           p4_id,
     const char      *exp_tag,
     psS32           p3_version,
@@ -7088,5 +7088,5 @@
 bool p4InputExpInsert(
     psDB            *dbh,               ///< Database handle
-    psS32           p4a_id,
+    psS32           p4_id,
     const char      *exp_tag,
     psS32           p3_version,
@@ -7241,4 +7241,214 @@
     bool            mdcf                ///< format as mdconfig or simple
 );
+/** p4SkyCellMapRow data structure
+ *
+ * Structure for representing a single row of p4SkyCellMap table data.
+ */
+
+typedef struct {
+    psS32           p4_id;
+    char            *skycell_id;
+    char            *tess_id;
+    char            *exp_tag;
+    psS32           p3_version;
+    char            *class_id;
+} p4SkyCellMapRow;
+
+/** Creates a new p4SkyCellMapRow object
+ *
+ *  @return A new p4SkyCellMapRow object or NULL on failure.
+ */
+
+p4SkyCellMapRow *p4SkyCellMapRowAlloc(
+    psS32           p4_id,
+    const char      *skycell_id,
+    const char      *tess_id,
+    const char      *exp_tag,
+    psS32           p3_version,
+    const char      *class_id
+);
+
+/** Creates a new p4SkyCellMap table
+ *
+ * @return true on success
+ */
+
+bool p4SkyCellMapCreateTable(
+    psDB            *dbh                ///< Database handle
+);
+
+/** Deletes a p4SkyCellMap table
+ *
+ * @return true on success
+ */
+
+bool p4SkyCellMapDropTable(
+    psDB            *dbh                ///< Database handle
+);
+
+/** Insert a single row into a table
+ *
+ * This function constructs and inserts a single row based on it's parameters.
+ *
+ * @return true on success
+ */
+
+bool p4SkyCellMapInsert(
+    psDB            *dbh,               ///< Database handle
+    psS32           p4_id,
+    const char      *skycell_id,
+    const char      *tess_id,
+    const char      *exp_tag,
+    psS32           p3_version,
+    const char      *class_id
+);
+
+/** Deletes up to limit rows from the database and returns the number of rows actually deleted. 
+ *
+ * @return A The number of rows removed or a negative value on error
+ */
+
+long long p4SkyCellMapDelete(
+    psDB            *dbh,               ///< Database handle
+    const psMetadata *where,            ///< Row match criteria
+    unsigned long long limit            ///< Maximum number of elements to delete 
+);
+
+/** Insert a single p4SkyCellMapRow object into a table
+ *
+ * This function constructs and inserts a single row based on it's parameters.
+ *
+ * @return true on success
+ */
+
+bool p4SkyCellMapInsertObject(
+    psDB            *dbh,               ///< Database handle
+    p4SkyCellMapRow *object             ///< p4SkyCellMapRow object
+);
+
+/** Insert an array of p4SkyCellMapRow object into a table
+ *
+ * This function constructs and inserts multiple rows based on it's parameters.
+ *
+ * @return true on success
+ */
+
+bool p4SkyCellMapInsertObjects(
+    psDB            *dbh,               ///< Database handle
+    psArray         *objects            ///< array of p4SkyCellMapRow objects
+);
+
+/** Insert data from a binary FITS table p4SkyCellMapRow into the database
+ *
+ * This function expects a psFits object with a FITS table as the first
+ * extension.  The table must have at least one row of data in it, that is of
+ * the appropriate format (number of columns and their type).  All other
+ * extensions are ignored.
+ *
+ * @return true on success
+ */
+
+bool p4SkyCellMapInsertFits(
+    psDB            *dbh,               ///< Database handle
+    const psFits    *fits               ///< psFits object
+);
+
+/** Selects up to limit from the database and returns them in a binary FITS table
+ *
+ * This function assumes an empty psFits object and will create a FITS table
+ * as the first extension.
+ *
+ *  See psDBSelectRows() for documentation on the format of where.
+ *
+ * @return true on success
+ */
+
+bool p4SkyCellMapSelectRowsFits(
+    psDB            *dbh,               ///< Database handle
+    psFits          *fits,              ///< psFits object
+    const psMetadata *where,            ///< Row match criteria
+    unsigned long long limit            ///< Maximum number of elements to return
+);
+
+/** Convert a p4SkyCellMapRow into an equivalent psMetadata
+ *
+ * @return A psMetadata pointer or NULL on error
+ */
+
+psMetadata *p4SkyCellMapMetadataFromObject(
+    const p4SkyCellMapRow *object             ///< fooRow to convert into a psMetadata
+);
+
+/** Convert a psMetadata into an equivalent fooRow
+ *
+ * @return A p4SkyCellMapRow pointer or NULL on error
+ */
+
+p4SkyCellMapRow *p4SkyCellMapObjectFromMetadata(
+    psMetadata      *md                 ///< psMetadata to convert into a fooRow
+);
+/** Selects up to limit rows from the database and returns as p4SkyCellMapRow objects in a psArray
+ *
+ *  See psDBSelectRows() for documentation on the format of where.
+ *
+ * @return A psArray pointer or NULL on error
+ */
+
+psArray *p4SkyCellMapSelectRowObjects(
+    psDB            *dbh,               ///< Database handle
+    const psMetadata *where,            ///< Row match criteria
+    unsigned long long limit            ///< Maximum number of elements to return
+);
+/** Deletes a row from the database coresponding to an p4SkyCellMap
+ *
+ *  Note that a 'where' search psMetadata is constructed from each object and
+ *  used to find rows to delete.
+ *
+ * @return A The number of rows removed or a negative value on error
+ */
+
+bool p4SkyCellMapDeleteObject(
+    psDB            *dbh,               ///< Database handle
+    const p4SkyCellMapRow *object    ///< Object to delete
+);
+/** Deletes up to limit rows from the database and returns the number of rows actually deleted. 
+ *
+ *  Note that a 'where' search psMetadata is constructed from each object and
+ *  used to find rows to delete.
+ *
+ * @return A The number of rows removed or a negative value on error
+ */
+
+long long p4SkyCellMapDeleteRowObjects(
+    psDB            *dbh,               ///< Database handle
+    const psArray   *objects,           ///< Array of objects to delete
+    unsigned long long limit            ///< Maximum number of elements to delete 
+);
+/** Formats and prints an array of p4SkyCellMapRow objects
+ *
+ * When mdcf is set the formated output is in psMetadataConfig
+ * format, otherwise it is in a simple tabular format.
+ *
+ * @return true on success
+ */
+
+bool p4SkyCellMapPrintObjects(
+    FILE            *stream,            ///< a stream
+    psArray         *objects,           ///< An array of p4SkyCellMapRow objects
+    bool            mdcf                ///< format as mdconfig or simple
+);
+/** Formats and prints an p4SkyCellMapRow object
+ *
+ * When mdcf is set the formated output is in psMetadataConfig
+ * format, otherwise it is in a simple tabular format.
+ *
+ * @return true on success
+ */
+
+bool p4SkyCellMapPrintObject(
+    FILE            *stream,            ///< a stream
+    p4SkyCellMapRow *object,    ///< an p4SkyCellMapRow object
+    bool            mdcf                ///< format as mdconfig or simple
+);
 /** p4ScfileRow data structure
  *
@@ -7247,5 +7457,5 @@
 
 typedef struct {
-    psS32           p4a_id;
+    psS32           p4_id;
     char            *skycell_id;
     char            *tess_id;
@@ -7263,5 +7473,5 @@
 
 p4ScfileRow *p4ScfileRowAlloc(
-    psS32           p4a_id,
+    psS32           p4_id,
     const char      *skycell_id,
     const char      *tess_id,
@@ -7300,5 +7510,5 @@
 bool p4ScfileInsert(
     psDB            *dbh,               ///< Database handle
-    psS32           p4a_id,
+    psS32           p4_id,
     const char      *skycell_id,
     const char      *tess_id,
@@ -7457,1063 +7667,4 @@
     bool            mdcf                ///< format as mdconfig or simple
 );
-/** p4InputScfileRow data structure
- *
- * Structure for representing a single row of p4InputScfile table data.
- */
-
-typedef struct {
-    psS32           p4b_id;
-    char            *skycell_id;
-    char            *tess_id;
-    char            *exp_tag;
-    psS32           p3_version;
-    char            *kind;
-} p4InputScfileRow;
-
-/** Creates a new p4InputScfileRow object
- *
- *  @return A new p4InputScfileRow object or NULL on failure.
- */
-
-p4InputScfileRow *p4InputScfileRowAlloc(
-    psS32           p4b_id,
-    const char      *skycell_id,
-    const char      *tess_id,
-    const char      *exp_tag,
-    psS32           p3_version,
-    const char      *kind
-);
-
-/** Creates a new p4InputScfile table
- *
- * @return true on success
- */
-
-bool p4InputScfileCreateTable(
-    psDB            *dbh                ///< Database handle
-);
-
-/** Deletes a p4InputScfile table
- *
- * @return true on success
- */
-
-bool p4InputScfileDropTable(
-    psDB            *dbh                ///< Database handle
-);
-
-/** Insert a single row into a table
- *
- * This function constructs and inserts a single row based on it's parameters.
- *
- * @return true on success
- */
-
-bool p4InputScfileInsert(
-    psDB            *dbh,               ///< Database handle
-    psS32           p4b_id,
-    const char      *skycell_id,
-    const char      *tess_id,
-    const char      *exp_tag,
-    psS32           p3_version,
-    const char      *kind
-);
-
-/** Deletes up to limit rows from the database and returns the number of rows actually deleted. 
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-long long p4InputScfileDelete(
-    psDB            *dbh,               ///< Database handle
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to delete 
-);
-
-/** Insert a single p4InputScfileRow object into a table
- *
- * This function constructs and inserts a single row based on it's parameters.
- *
- * @return true on success
- */
-
-bool p4InputScfileInsertObject(
-    psDB            *dbh,               ///< Database handle
-    p4InputScfileRow *object             ///< p4InputScfileRow object
-);
-
-/** Insert an array of p4InputScfileRow object into a table
- *
- * This function constructs and inserts multiple rows based on it's parameters.
- *
- * @return true on success
- */
-
-bool p4InputScfileInsertObjects(
-    psDB            *dbh,               ///< Database handle
-    psArray         *objects            ///< array of p4InputScfileRow objects
-);
-
-/** Insert data from a binary FITS table p4InputScfileRow into the database
- *
- * This function expects a psFits object with a FITS table as the first
- * extension.  The table must have at least one row of data in it, that is of
- * the appropriate format (number of columns and their type).  All other
- * extensions are ignored.
- *
- * @return true on success
- */
-
-bool p4InputScfileInsertFits(
-    psDB            *dbh,               ///< Database handle
-    const psFits    *fits               ///< psFits object
-);
-
-/** Selects up to limit from the database and returns them in a binary FITS table
- *
- * This function assumes an empty psFits object and will create a FITS table
- * as the first extension.
- *
- *  See psDBSelectRows() for documentation on the format of where.
- *
- * @return true on success
- */
-
-bool p4InputScfileSelectRowsFits(
-    psDB            *dbh,               ///< Database handle
-    psFits          *fits,              ///< psFits object
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to return
-);
-
-/** Convert a p4InputScfileRow into an equivalent psMetadata
- *
- * @return A psMetadata pointer or NULL on error
- */
-
-psMetadata *p4InputScfileMetadataFromObject(
-    const p4InputScfileRow *object             ///< fooRow to convert into a psMetadata
-);
-
-/** Convert a psMetadata into an equivalent fooRow
- *
- * @return A p4InputScfileRow pointer or NULL on error
- */
-
-p4InputScfileRow *p4InputScfileObjectFromMetadata(
-    psMetadata      *md                 ///< psMetadata to convert into a fooRow
-);
-/** Selects up to limit rows from the database and returns as p4InputScfileRow objects in a psArray
- *
- *  See psDBSelectRows() for documentation on the format of where.
- *
- * @return A psArray pointer or NULL on error
- */
-
-psArray *p4InputScfileSelectRowObjects(
-    psDB            *dbh,               ///< Database handle
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to return
-);
-/** Deletes a row from the database coresponding to an p4InputScfile
- *
- *  Note that a 'where' search psMetadata is constructed from each object and
- *  used to find rows to delete.
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-bool p4InputScfileDeleteObject(
-    psDB            *dbh,               ///< Database handle
-    const p4InputScfileRow *object    ///< Object to delete
-);
-/** Deletes up to limit rows from the database and returns the number of rows actually deleted. 
- *
- *  Note that a 'where' search psMetadata is constructed from each object and
- *  used to find rows to delete.
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-long long p4InputScfileDeleteRowObjects(
-    psDB            *dbh,               ///< Database handle
-    const psArray   *objects,           ///< Array of objects to delete
-    unsigned long long limit            ///< Maximum number of elements to delete 
-);
-/** Formats and prints an array of p4InputScfileRow objects
- *
- * When mdcf is set the formated output is in psMetadataConfig
- * format, otherwise it is in a simple tabular format.
- *
- * @return true on success
- */
-
-bool p4InputScfilePrintObjects(
-    FILE            *stream,            ///< a stream
-    psArray         *objects,           ///< An array of p4InputScfileRow objects
-    bool            mdcf                ///< format as mdconfig or simple
-);
-/** Formats and prints an p4InputScfileRow object
- *
- * When mdcf is set the formated output is in psMetadataConfig
- * format, otherwise it is in a simple tabular format.
- *
- * @return true on success
- */
-
-bool p4InputScfilePrintObject(
-    FILE            *stream,            ///< a stream
-    p4InputScfileRow *object,    ///< an p4InputScfileRow object
-    bool            mdcf                ///< format as mdconfig or simple
-);
-/** p4DiffScfileRow data structure
- *
- * Structure for representing a single row of p4DiffScfile table data.
- */
-
-typedef struct {
-    psS32           p4b_id;
-    char            *skycell_id;
-    char            *tess_id;
-    char            *exp_tag;
-    psS32           p3_version;
-    char            *uri;
-    psF64           bg;
-    psF64           bg_mean_stdev;
-} p4DiffScfileRow;
-
-/** Creates a new p4DiffScfileRow object
- *
- *  @return A new p4DiffScfileRow object or NULL on failure.
- */
-
-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
-);
-
-/** Creates a new p4DiffScfile table
- *
- * @return true on success
- */
-
-bool p4DiffScfileCreateTable(
-    psDB            *dbh                ///< Database handle
-);
-
-/** Deletes a p4DiffScfile table
- *
- * @return true on success
- */
-
-bool p4DiffScfileDropTable(
-    psDB            *dbh                ///< Database handle
-);
-
-/** Insert a single row into a table
- *
- * This function constructs and inserts a single row based on it's parameters.
- *
- * @return true on success
- */
-
-bool p4DiffScfileInsert(
-    psDB            *dbh,               ///< Database handle
-    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
-);
-
-/** Deletes up to limit rows from the database and returns the number of rows actually deleted. 
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-long long p4DiffScfileDelete(
-    psDB            *dbh,               ///< Database handle
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to delete 
-);
-
-/** Insert a single p4DiffScfileRow object into a table
- *
- * This function constructs and inserts a single row based on it's parameters.
- *
- * @return true on success
- */
-
-bool p4DiffScfileInsertObject(
-    psDB            *dbh,               ///< Database handle
-    p4DiffScfileRow *object             ///< p4DiffScfileRow object
-);
-
-/** Insert an array of p4DiffScfileRow object into a table
- *
- * This function constructs and inserts multiple rows based on it's parameters.
- *
- * @return true on success
- */
-
-bool p4DiffScfileInsertObjects(
-    psDB            *dbh,               ///< Database handle
-    psArray         *objects            ///< array of p4DiffScfileRow objects
-);
-
-/** Insert data from a binary FITS table p4DiffScfileRow into the database
- *
- * This function expects a psFits object with a FITS table as the first
- * extension.  The table must have at least one row of data in it, that is of
- * the appropriate format (number of columns and their type).  All other
- * extensions are ignored.
- *
- * @return true on success
- */
-
-bool p4DiffScfileInsertFits(
-    psDB            *dbh,               ///< Database handle
-    const psFits    *fits               ///< psFits object
-);
-
-/** Selects up to limit from the database and returns them in a binary FITS table
- *
- * This function assumes an empty psFits object and will create a FITS table
- * as the first extension.
- *
- *  See psDBSelectRows() for documentation on the format of where.
- *
- * @return true on success
- */
-
-bool p4DiffScfileSelectRowsFits(
-    psDB            *dbh,               ///< Database handle
-    psFits          *fits,              ///< psFits object
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to return
-);
-
-/** Convert a p4DiffScfileRow into an equivalent psMetadata
- *
- * @return A psMetadata pointer or NULL on error
- */
-
-psMetadata *p4DiffScfileMetadataFromObject(
-    const p4DiffScfileRow *object             ///< fooRow to convert into a psMetadata
-);
-
-/** Convert a psMetadata into an equivalent fooRow
- *
- * @return A p4DiffScfileRow pointer or NULL on error
- */
-
-p4DiffScfileRow *p4DiffScfileObjectFromMetadata(
-    psMetadata      *md                 ///< psMetadata to convert into a fooRow
-);
-/** Selects up to limit rows from the database and returns as p4DiffScfileRow objects in a psArray
- *
- *  See psDBSelectRows() for documentation on the format of where.
- *
- * @return A psArray pointer or NULL on error
- */
-
-psArray *p4DiffScfileSelectRowObjects(
-    psDB            *dbh,               ///< Database handle
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to return
-);
-/** Deletes a row from the database coresponding to an p4DiffScfile
- *
- *  Note that a 'where' search psMetadata is constructed from each object and
- *  used to find rows to delete.
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-bool p4DiffScfileDeleteObject(
-    psDB            *dbh,               ///< Database handle
-    const p4DiffScfileRow *object    ///< Object to delete
-);
-/** Deletes up to limit rows from the database and returns the number of rows actually deleted. 
- *
- *  Note that a 'where' search psMetadata is constructed from each object and
- *  used to find rows to delete.
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-long long p4DiffScfileDeleteRowObjects(
-    psDB            *dbh,               ///< Database handle
-    const psArray   *objects,           ///< Array of objects to delete
-    unsigned long long limit            ///< Maximum number of elements to delete 
-);
-/** Formats and prints an array of p4DiffScfileRow objects
- *
- * When mdcf is set the formated output is in psMetadataConfig
- * format, otherwise it is in a simple tabular format.
- *
- * @return true on success
- */
-
-bool p4DiffScfilePrintObjects(
-    FILE            *stream,            ///< a stream
-    psArray         *objects,           ///< An array of p4DiffScfileRow objects
-    bool            mdcf                ///< format as mdconfig or simple
-);
-/** Formats and prints an p4DiffScfileRow object
- *
- * When mdcf is set the formated output is in psMetadataConfig
- * format, otherwise it is in a simple tabular format.
- *
- * @return true on success
- */
-
-bool p4DiffScfilePrintObject(
-    FILE            *stream,            ///< a stream
-    p4DiffScfileRow *object,    ///< an p4DiffScfileRow object
-    bool            mdcf                ///< format as mdconfig or simple
-);
-/** p4MagicMaskImfileRow data structure
- *
- * Structure for representing a single row of p4MagicMaskImfile table data.
- */
-
-typedef struct {
-    psS32           p4c_id;
-    char            *exp_tag;
-    psS32           p3_version;
-    char            *class_id;
-    char            *uri;
-} p4MagicMaskImfileRow;
-
-/** Creates a new p4MagicMaskImfileRow object
- *
- *  @return A new p4MagicMaskImfileRow object or NULL on failure.
- */
-
-p4MagicMaskImfileRow *p4MagicMaskImfileRowAlloc(
-    psS32           p4c_id,
-    const char      *exp_tag,
-    psS32           p3_version,
-    const char      *class_id,
-    const char      *uri
-);
-
-/** Creates a new p4MagicMaskImfile table
- *
- * @return true on success
- */
-
-bool p4MagicMaskImfileCreateTable(
-    psDB            *dbh                ///< Database handle
-);
-
-/** Deletes a p4MagicMaskImfile table
- *
- * @return true on success
- */
-
-bool p4MagicMaskImfileDropTable(
-    psDB            *dbh                ///< Database handle
-);
-
-/** Insert a single row into a table
- *
- * This function constructs and inserts a single row based on it's parameters.
- *
- * @return true on success
- */
-
-bool p4MagicMaskImfileInsert(
-    psDB            *dbh,               ///< Database handle
-    psS32           p4c_id,
-    const char      *exp_tag,
-    psS32           p3_version,
-    const char      *class_id,
-    const char      *uri
-);
-
-/** Deletes up to limit rows from the database and returns the number of rows actually deleted. 
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-long long p4MagicMaskImfileDelete(
-    psDB            *dbh,               ///< Database handle
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to delete 
-);
-
-/** Insert a single p4MagicMaskImfileRow object into a table
- *
- * This function constructs and inserts a single row based on it's parameters.
- *
- * @return true on success
- */
-
-bool p4MagicMaskImfileInsertObject(
-    psDB            *dbh,               ///< Database handle
-    p4MagicMaskImfileRow *object             ///< p4MagicMaskImfileRow object
-);
-
-/** Insert an array of p4MagicMaskImfileRow object into a table
- *
- * This function constructs and inserts multiple rows based on it's parameters.
- *
- * @return true on success
- */
-
-bool p4MagicMaskImfileInsertObjects(
-    psDB            *dbh,               ///< Database handle
-    psArray         *objects            ///< array of p4MagicMaskImfileRow objects
-);
-
-/** Insert data from a binary FITS table p4MagicMaskImfileRow into the database
- *
- * This function expects a psFits object with a FITS table as the first
- * extension.  The table must have at least one row of data in it, that is of
- * the appropriate format (number of columns and their type).  All other
- * extensions are ignored.
- *
- * @return true on success
- */
-
-bool p4MagicMaskImfileInsertFits(
-    psDB            *dbh,               ///< Database handle
-    const psFits    *fits               ///< psFits object
-);
-
-/** Selects up to limit from the database and returns them in a binary FITS table
- *
- * This function assumes an empty psFits object and will create a FITS table
- * as the first extension.
- *
- *  See psDBSelectRows() for documentation on the format of where.
- *
- * @return true on success
- */
-
-bool p4MagicMaskImfileSelectRowsFits(
-    psDB            *dbh,               ///< Database handle
-    psFits          *fits,              ///< psFits object
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to return
-);
-
-/** Convert a p4MagicMaskImfileRow into an equivalent psMetadata
- *
- * @return A psMetadata pointer or NULL on error
- */
-
-psMetadata *p4MagicMaskImfileMetadataFromObject(
-    const p4MagicMaskImfileRow *object             ///< fooRow to convert into a psMetadata
-);
-
-/** Convert a psMetadata into an equivalent fooRow
- *
- * @return A p4MagicMaskImfileRow pointer or NULL on error
- */
-
-p4MagicMaskImfileRow *p4MagicMaskImfileObjectFromMetadata(
-    psMetadata      *md                 ///< psMetadata to convert into a fooRow
-);
-/** Selects up to limit rows from the database and returns as p4MagicMaskImfileRow objects in a psArray
- *
- *  See psDBSelectRows() for documentation on the format of where.
- *
- * @return A psArray pointer or NULL on error
- */
-
-psArray *p4MagicMaskImfileSelectRowObjects(
-    psDB            *dbh,               ///< Database handle
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to return
-);
-/** Deletes a row from the database coresponding to an p4MagicMaskImfile
- *
- *  Note that a 'where' search psMetadata is constructed from each object and
- *  used to find rows to delete.
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-bool p4MagicMaskImfileDeleteObject(
-    psDB            *dbh,               ///< Database handle
-    const p4MagicMaskImfileRow *object    ///< Object to delete
-);
-/** Deletes up to limit rows from the database and returns the number of rows actually deleted. 
- *
- *  Note that a 'where' search psMetadata is constructed from each object and
- *  used to find rows to delete.
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-long long p4MagicMaskImfileDeleteRowObjects(
-    psDB            *dbh,               ///< Database handle
-    const psArray   *objects,           ///< Array of objects to delete
-    unsigned long long limit            ///< Maximum number of elements to delete 
-);
-/** Formats and prints an array of p4MagicMaskImfileRow objects
- *
- * When mdcf is set the formated output is in psMetadataConfig
- * format, otherwise it is in a simple tabular format.
- *
- * @return true on success
- */
-
-bool p4MagicMaskImfilePrintObjects(
-    FILE            *stream,            ///< a stream
-    psArray         *objects,           ///< An array of p4MagicMaskImfileRow objects
-    bool            mdcf                ///< format as mdconfig or simple
-);
-/** Formats and prints an p4MagicMaskImfileRow object
- *
- * When mdcf is set the formated output is in psMetadataConfig
- * format, otherwise it is in a simple tabular format.
- *
- * @return true on success
- */
-
-bool p4MagicMaskImfilePrintObject(
-    FILE            *stream,            ///< a stream
-    p4MagicMaskImfileRow *object,    ///< an p4MagicMaskImfileRow object
-    bool            mdcf                ///< format as mdconfig or simple
-);
-/** skyCellRow data structure
- *
- * Structure for representing a single row of skyCell table data.
- */
-
-typedef struct {
-    char            *skycell_id;
-    char            *tess_id;
-    psF64           ra1;
-    psF64           decl1;
-    psF64           ra2;
-    psF64           decl2;
-    psF64           ra3;
-    psF64           decl3;
-    psF64           ra4;
-    psF64           decl4;
-} skyCellRow;
-
-/** Creates a new skyCellRow object
- *
- *  @return A new skyCellRow object or NULL on failure.
- */
-
-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
-);
-
-/** Creates a new skyCell table
- *
- * @return true on success
- */
-
-bool skyCellCreateTable(
-    psDB            *dbh                ///< Database handle
-);
-
-/** Deletes a skyCell table
- *
- * @return true on success
- */
-
-bool skyCellDropTable(
-    psDB            *dbh                ///< Database handle
-);
-
-/** Insert a single row into a table
- *
- * This function constructs and inserts a single row based on it's parameters.
- *
- * @return true on success
- */
-
-bool skyCellInsert(
-    psDB            *dbh,               ///< Database handle
-    const char      *skycell_id,
-    const char      *tess_id,
-    psF64           ra1,
-    psF64           decl1,
-    psF64           ra2,
-    psF64           decl2,
-    psF64           ra3,
-    psF64           decl3,
-    psF64           ra4,
-    psF64           decl4
-);
-
-/** Deletes up to limit rows from the database and returns the number of rows actually deleted. 
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-long long skyCellDelete(
-    psDB            *dbh,               ///< Database handle
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to delete 
-);
-
-/** Insert a single skyCellRow object into a table
- *
- * This function constructs and inserts a single row based on it's parameters.
- *
- * @return true on success
- */
-
-bool skyCellInsertObject(
-    psDB            *dbh,               ///< Database handle
-    skyCellRow      *object             ///< skyCellRow object
-);
-
-/** Insert an array of skyCellRow object into a table
- *
- * This function constructs and inserts multiple rows based on it's parameters.
- *
- * @return true on success
- */
-
-bool skyCellInsertObjects(
-    psDB            *dbh,               ///< Database handle
-    psArray         *objects            ///< array of skyCellRow objects
-);
-
-/** Insert data from a binary FITS table skyCellRow into the database
- *
- * This function expects a psFits object with a FITS table as the first
- * extension.  The table must have at least one row of data in it, that is of
- * the appropriate format (number of columns and their type).  All other
- * extensions are ignored.
- *
- * @return true on success
- */
-
-bool skyCellInsertFits(
-    psDB            *dbh,               ///< Database handle
-    const psFits    *fits               ///< psFits object
-);
-
-/** Selects up to limit from the database and returns them in a binary FITS table
- *
- * This function assumes an empty psFits object and will create a FITS table
- * as the first extension.
- *
- *  See psDBSelectRows() for documentation on the format of where.
- *
- * @return true on success
- */
-
-bool skyCellSelectRowsFits(
-    psDB            *dbh,               ///< Database handle
-    psFits          *fits,              ///< psFits object
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to return
-);
-
-/** Convert a skyCellRow into an equivalent psMetadata
- *
- * @return A psMetadata pointer or NULL on error
- */
-
-psMetadata *skyCellMetadataFromObject(
-    const skyCellRow *object             ///< fooRow to convert into a psMetadata
-);
-
-/** Convert a psMetadata into an equivalent fooRow
- *
- * @return A skyCellRow pointer or NULL on error
- */
-
-skyCellRow *skyCellObjectFromMetadata(
-    psMetadata      *md                 ///< psMetadata to convert into a fooRow
-);
-/** Selects up to limit rows from the database and returns as skyCellRow objects in a psArray
- *
- *  See psDBSelectRows() for documentation on the format of where.
- *
- * @return A psArray pointer or NULL on error
- */
-
-psArray *skyCellSelectRowObjects(
-    psDB            *dbh,               ///< Database handle
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to return
-);
-/** Deletes a row from the database coresponding to an skyCell
- *
- *  Note that a 'where' search psMetadata is constructed from each object and
- *  used to find rows to delete.
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-bool skyCellDeleteObject(
-    psDB            *dbh,               ///< Database handle
-    const skyCellRow *object    ///< Object to delete
-);
-/** Deletes up to limit rows from the database and returns the number of rows actually deleted. 
- *
- *  Note that a 'where' search psMetadata is constructed from each object and
- *  used to find rows to delete.
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-long long skyCellDeleteRowObjects(
-    psDB            *dbh,               ///< Database handle
-    const psArray   *objects,           ///< Array of objects to delete
-    unsigned long long limit            ///< Maximum number of elements to delete 
-);
-/** Formats and prints an array of skyCellRow objects
- *
- * When mdcf is set the formated output is in psMetadataConfig
- * format, otherwise it is in a simple tabular format.
- *
- * @return true on success
- */
-
-bool skyCellPrintObjects(
-    FILE            *stream,            ///< a stream
-    psArray         *objects,           ///< An array of skyCellRow objects
-    bool            mdcf                ///< format as mdconfig or simple
-);
-/** Formats and prints an skyCellRow object
- *
- * When mdcf is set the formated output is in psMetadataConfig
- * format, otherwise it is in a simple tabular format.
- *
- * @return true on success
- */
-
-bool skyCellPrintObject(
-    FILE            *stream,            ///< a stream
-    skyCellRow *object,    ///< an skyCellRow object
-    bool            mdcf                ///< format as mdconfig or simple
-);
-/** skyCellMapRow data structure
- *
- * Structure for representing a single row of skyCellMap table data.
- */
-
-typedef struct {
-    char            *skycell_id;
-    char            *tess_id;
-    char            *exp_tag;
-    char            *class_id;
-} skyCellMapRow;
-
-/** Creates a new skyCellMapRow object
- *
- *  @return A new skyCellMapRow object or NULL on failure.
- */
-
-skyCellMapRow *skyCellMapRowAlloc(
-    const char      *skycell_id,
-    const char      *tess_id,
-    const char      *exp_tag,
-    const char      *class_id
-);
-
-/** Creates a new skyCellMap table
- *
- * @return true on success
- */
-
-bool skyCellMapCreateTable(
-    psDB            *dbh                ///< Database handle
-);
-
-/** Deletes a skyCellMap table
- *
- * @return true on success
- */
-
-bool skyCellMapDropTable(
-    psDB            *dbh                ///< Database handle
-);
-
-/** Insert a single row into a table
- *
- * This function constructs and inserts a single row based on it's parameters.
- *
- * @return true on success
- */
-
-bool skyCellMapInsert(
-    psDB            *dbh,               ///< Database handle
-    const char      *skycell_id,
-    const char      *tess_id,
-    const char      *exp_tag,
-    const char      *class_id
-);
-
-/** Deletes up to limit rows from the database and returns the number of rows actually deleted. 
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-long long skyCellMapDelete(
-    psDB            *dbh,               ///< Database handle
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to delete 
-);
-
-/** Insert a single skyCellMapRow object into a table
- *
- * This function constructs and inserts a single row based on it's parameters.
- *
- * @return true on success
- */
-
-bool skyCellMapInsertObject(
-    psDB            *dbh,               ///< Database handle
-    skyCellMapRow   *object             ///< skyCellMapRow object
-);
-
-/** Insert an array of skyCellMapRow object into a table
- *
- * This function constructs and inserts multiple rows based on it's parameters.
- *
- * @return true on success
- */
-
-bool skyCellMapInsertObjects(
-    psDB            *dbh,               ///< Database handle
-    psArray         *objects            ///< array of skyCellMapRow objects
-);
-
-/** Insert data from a binary FITS table skyCellMapRow into the database
- *
- * This function expects a psFits object with a FITS table as the first
- * extension.  The table must have at least one row of data in it, that is of
- * the appropriate format (number of columns and their type).  All other
- * extensions are ignored.
- *
- * @return true on success
- */
-
-bool skyCellMapInsertFits(
-    psDB            *dbh,               ///< Database handle
-    const psFits    *fits               ///< psFits object
-);
-
-/** Selects up to limit from the database and returns them in a binary FITS table
- *
- * This function assumes an empty psFits object and will create a FITS table
- * as the first extension.
- *
- *  See psDBSelectRows() for documentation on the format of where.
- *
- * @return true on success
- */
-
-bool skyCellMapSelectRowsFits(
-    psDB            *dbh,               ///< Database handle
-    psFits          *fits,              ///< psFits object
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to return
-);
-
-/** Convert a skyCellMapRow into an equivalent psMetadata
- *
- * @return A psMetadata pointer or NULL on error
- */
-
-psMetadata *skyCellMapMetadataFromObject(
-    const skyCellMapRow *object             ///< fooRow to convert into a psMetadata
-);
-
-/** Convert a psMetadata into an equivalent fooRow
- *
- * @return A skyCellMapRow pointer or NULL on error
- */
-
-skyCellMapRow *skyCellMapObjectFromMetadata(
-    psMetadata      *md                 ///< psMetadata to convert into a fooRow
-);
-/** Selects up to limit rows from the database and returns as skyCellMapRow objects in a psArray
- *
- *  See psDBSelectRows() for documentation on the format of where.
- *
- * @return A psArray pointer or NULL on error
- */
-
-psArray *skyCellMapSelectRowObjects(
-    psDB            *dbh,               ///< Database handle
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to return
-);
-/** Deletes a row from the database coresponding to an skyCellMap
- *
- *  Note that a 'where' search psMetadata is constructed from each object and
- *  used to find rows to delete.
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-bool skyCellMapDeleteObject(
-    psDB            *dbh,               ///< Database handle
-    const skyCellMapRow *object    ///< Object to delete
-);
-/** Deletes up to limit rows from the database and returns the number of rows actually deleted. 
- *
- *  Note that a 'where' search psMetadata is constructed from each object and
- *  used to find rows to delete.
- *
- * @return A The number of rows removed or a negative value on error
- */
-
-long long skyCellMapDeleteRowObjects(
-    psDB            *dbh,               ///< Database handle
-    const psArray   *objects,           ///< Array of objects to delete
-    unsigned long long limit            ///< Maximum number of elements to delete 
-);
-/** Formats and prints an array of skyCellMapRow objects
- *
- * When mdcf is set the formated output is in psMetadataConfig
- * format, otherwise it is in a simple tabular format.
- *
- * @return true on success
- */
-
-bool skyCellMapPrintObjects(
-    FILE            *stream,            ///< a stream
-    psArray         *objects,           ///< An array of skyCellMapRow objects
-    bool            mdcf                ///< format as mdconfig or simple
-);
-/** Formats and prints an skyCellMapRow object
- *
- * When mdcf is set the formated output is in psMetadataConfig
- * format, otherwise it is in a simple tabular format.
- *
- * @return true on success
- */
-
-bool skyCellMapPrintObject(
-    FILE            *stream,            ///< a stream
-    skyCellMapRow *object,    ///< an skyCellMapRow object
-    bool            mdcf                ///< format as mdconfig or simple
-);
 
 /// @}
@@ -8523,3 +7674,3 @@
 #endif
 
-#endif // SKYCELLMAP_DB_H
+#endif // P4SCFILE_DB_H
Index: /trunk/ippdb/tests/alloc.c
===================================================================
--- /trunk/ippdb/tests/alloc.c	(revision 11779)
+++ /trunk/ippdb/tests/alloc.c	(revision 11780)
@@ -1416,5 +1416,5 @@
         }
 
-        if (!object->p4a_id == -32) {
+        if (!object->p4_id == -32) {
             psFree(object);
             exit(EXIT_FAILURE);
@@ -1448,5 +1448,5 @@
         }
 
-        if (!object->p4a_id == -32) {
+        if (!object->p4_id == -32) {
             psFree(object);
             exit(EXIT_FAILURE);
@@ -1469,4 +1469,41 @@
 
     {
+        p4SkyCellMapRow *object;
+
+        object = p4SkyCellMapRowAlloc(-32, "a string", "a string", "a string", -32, "a string"    );
+
+        if (!object) {
+            exit(EXIT_FAILURE);
+        }
+
+        if (!object->p4_id == -32) {
+            psFree(object);
+            exit(EXIT_FAILURE);
+        }
+        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
+            psFree(object);
+            exit(EXIT_FAILURE);
+        }
+        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
+            psFree(object);
+            exit(EXIT_FAILURE);
+        }
+        if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
+            psFree(object);
+            exit(EXIT_FAILURE);
+        }
+        if (!object->p3_version == -32) {
+            psFree(object);
+            exit(EXIT_FAILURE);
+        }
+        if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {
+            psFree(object);
+            exit(EXIT_FAILURE);
+        }
+
+        psFree(object);
+    }
+
+    {
         p4ScfileRow     *object;
 
@@ -1477,5 +1514,5 @@
         }
 
-        if (!object->p4a_id == -32) {
+        if (!object->p4_id == -32) {
             psFree(object);
             exit(EXIT_FAILURE);
@@ -1506,201 +1543,4 @@
         }
         if (!object->bg_mean_stdev == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-    }
-
-    {
-        p4InputScfileRow *object;
-
-        object = p4InputScfileRowAlloc(-32, "a string", "a string", "a string", -32, "a string"    );
-
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!object->p4b_id == -32) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->p3_version == -32) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->kind, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-    }
-
-    {
-        p4DiffScfileRow *object;
-
-        object = p4DiffScfileRowAlloc(-32, "a string", "a string", "a string", -32, "a string", 64.64, 64.64    );
-
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!object->p4b_id == -32) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->p3_version == -32) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->bg == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->bg_mean_stdev == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-    }
-
-    {
-        p4MagicMaskImfileRow *object;
-
-        object = p4MagicMaskImfileRowAlloc(-32, "a string", -32, "a string", "a string"    );
-
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!object->p4c_id == -32) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->p3_version == -32) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-    }
-
-    {
-        skyCellRow      *object;
-
-        object = skyCellRowAlloc("a string", "a string", 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64    );
-
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->ra1 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->decl1 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->ra2 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->decl2 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->ra3 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->decl3 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->ra4 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->decl4 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-    }
-
-    {
-        skyCellMapRow   *object;
-
-        object = skyCellMapRowAlloc("a string", "a string", "a string", "a string"    );
-
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {
             psFree(object);
             exit(EXIT_FAILURE);
Index: /trunk/ippdb/tests/createtable.c
===================================================================
--- /trunk/ippdb/tests/createtable.c	(revision 11779)
+++ /trunk/ippdb/tests/createtable.c	(revision 11780)
@@ -508,80 +508,20 @@
         }
 
+        if(!p4SkyCellMapCreateTable(dbh)) {
+            exit(EXIT_FAILURE);
+        }
+
+        psDBCleanup(dbh);
+    }
+
+    {
+        psDB            *dbh;
+
+        dbh = psDBInit("localhost", "test", NULL, "test");
+        if (!dbh) {
+            exit(EXIT_FAILURE);
+        }
+
         if(!p4ScfileCreateTable(dbh)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if(!p4InputScfileCreateTable(dbh)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if(!p4DiffScfileCreateTable(dbh)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if(!p4MagicMaskImfileCreateTable(dbh)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if(!skyCellCreateTable(dbh)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if(!skyCellMapCreateTable(dbh)) {
             exit(EXIT_FAILURE);
         }
Index: /trunk/ippdb/tests/dbcleanup.c
===================================================================
--- /trunk/ippdb/tests/dbcleanup.c	(revision 11779)
+++ /trunk/ippdb/tests/dbcleanup.c	(revision 11780)
@@ -44,10 +44,6 @@
     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4Run");
     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4InputExp");
+    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4SkyCellMap");
     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4Scfile");
-    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4InputScfile");
-    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4DiffScfile");
-    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4MagicMaskImfile");
-    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS skyCell");
-    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS skyCellMap");
 
     psDBCleanup(dbh);
Index: /trunk/ippdb/tests/dbsetup.c
===================================================================
--- /trunk/ippdb/tests/dbsetup.c	(revision 11779)
+++ /trunk/ippdb/tests/dbsetup.c	(revision 11780)
@@ -112,21 +112,9 @@
     p4InputExpCreateTable(dbh);
 
+    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4SkyCellMap");
+    p4SkyCellMapCreateTable(dbh);
+
     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4Scfile");
     p4ScfileCreateTable(dbh);
-
-    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4InputScfile");
-    p4InputScfileCreateTable(dbh);
-
-    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4DiffScfile");
-    p4DiffScfileCreateTable(dbh);
-
-    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4MagicMaskImfile");
-    p4MagicMaskImfileCreateTable(dbh);
-
-    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS skyCell");
-    skyCellCreateTable(dbh);
-
-    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS skyCellMap");
-    skyCellMapCreateTable(dbh);
 
     psDBCleanup(dbh);
Index: /trunk/ippdb/tests/droptable.c
===================================================================
--- /trunk/ippdb/tests/droptable.c	(revision 11779)
+++ /trunk/ippdb/tests/droptable.c	(revision 11780)
@@ -508,80 +508,20 @@
         }
 
+        if (!p4SkyCellMapDropTable(dbh)) {
+            exit(EXIT_FAILURE);
+        }
+
+        psDBCleanup(dbh);
+    }
+
+    {
+        psDB            *dbh;
+
+        dbh = psDBInit("localhost", "test", NULL, "test");
+        if (!dbh) {
+            exit(EXIT_FAILURE);
+        }
+
         if (!p4ScfileDropTable(dbh)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4InputScfileDropTable(dbh)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4DiffScfileDropTable(dbh)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4MagicMaskImfileDropTable(dbh)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!skyCellDropTable(dbh)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!skyCellMapDropTable(dbh)) {
             exit(EXIT_FAILURE);
         }
Index: /trunk/ippdb/tests/insert.c
===================================================================
--- /trunk/ippdb/tests/insert.c	(revision 11779)
+++ /trunk/ippdb/tests/insert.c	(revision 11780)
@@ -508,80 +508,20 @@
         }
 
+        if (!p4SkyCellMapInsert(dbh, -32, "a string", "a string", "a string", -32, "a string")) {
+            exit(EXIT_FAILURE);
+        }
+
+        psDBCleanup(dbh);
+    }
+
+    {
+        psDB            *dbh;
+
+        dbh = psDBInit("localhost", "test", NULL, "test");
+        if (!dbh) {
+            exit(EXIT_FAILURE);
+        }
+
         if (!p4ScfileInsert(dbh, -32, "a string", "a string", "a string", -32, "a string", 64.64, 64.64)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4InputScfileInsert(dbh, -32, "a string", "a string", "a string", -32, "a string")) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4DiffScfileInsert(dbh, -32, "a string", "a string", "a string", -32, "a string", 64.64, 64.64)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4MagicMaskImfileInsert(dbh, -32, "a string", -32, "a string", "a string")) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!skyCellInsert(dbh, "a string", "a string", 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!skyCellMapInsert(dbh, "a string", "a string", "a string", "a string")) {
             exit(EXIT_FAILURE);
         }
Index: /trunk/ippdb/tests/insertfits.c
===================================================================
--- /trunk/ippdb/tests/insertfits.c	(revision 11779)
+++ /trunk/ippdb/tests/insertfits.c	(revision 11780)
@@ -882,135 +882,31 @@
         }
 
+        if (!p4SkyCellMapInsertFits(dbh, fits)) {
+            exit(EXIT_FAILURE);
+        }
+
+        if (!psFitsClose(fits)) {
+            exit(EXIT_FAILURE);
+        }
+
+        psDBCleanup(dbh);
+    }
+
+    {
+        psDB            *dbh;
+        psFits          *fits;
+
+        dbh = psDBInit("localhost", "test", NULL, "test");
+        if (!dbh) {
+            exit(EXIT_FAILURE);
+        }
+
+        // open a temp
+        fits = psFitsOpen(TMP_FILENAME, "r");
+        if (!fits) {
+            exit(EXIT_FAILURE);
+        }
+
         if (!p4ScfileInsertFits(dbh, fits)) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!psFitsClose(fits)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        psFits          *fits;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        // open a temp
-        fits = psFitsOpen(TMP_FILENAME, "r");
-        if (!fits) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4InputScfileInsertFits(dbh, fits)) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!psFitsClose(fits)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        psFits          *fits;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        // open a temp
-        fits = psFitsOpen(TMP_FILENAME, "r");
-        if (!fits) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4DiffScfileInsertFits(dbh, fits)) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!psFitsClose(fits)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        psFits          *fits;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        // open a temp
-        fits = psFitsOpen(TMP_FILENAME, "r");
-        if (!fits) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4MagicMaskImfileInsertFits(dbh, fits)) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!psFitsClose(fits)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        psFits          *fits;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        // open a temp
-        fits = psFitsOpen(TMP_FILENAME, "r");
-        if (!fits) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!skyCellInsertFits(dbh, fits)) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!psFitsClose(fits)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        psFits          *fits;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        // open a temp
-        fits = psFitsOpen(TMP_FILENAME, "r");
-        if (!fits) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!skyCellMapInsertFits(dbh, fits)) {
             exit(EXIT_FAILURE);
         }
Index: /trunk/ippdb/tests/insertobject.c
===================================================================
--- /trunk/ippdb/tests/insertobject.c	(revision 11779)
+++ /trunk/ippdb/tests/insertobject.c	(revision 11780)
@@ -733,4 +733,26 @@
     {
         psDB            *dbh;
+        p4SkyCellMapRow *object;
+
+        dbh = psDBInit("localhost", "test", NULL, "test");
+        if (!dbh) {
+            exit(EXIT_FAILURE);
+        }
+
+        object = p4SkyCellMapRowAlloc(-32, "a string", "a string", "a string", -32, "a string");
+        if (!object) {
+            exit(EXIT_FAILURE);
+        }
+
+        if (!p4SkyCellMapInsertObject(dbh, object)) {
+            exit(EXIT_FAILURE);
+        }
+
+        psFree(object);
+        psDBCleanup(dbh);
+    }
+
+    {
+        psDB            *dbh;
         p4ScfileRow     *object;
 
@@ -746,114 +768,4 @@
 
         if (!p4ScfileInsertObject(dbh, object)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        p4InputScfileRow *object;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        object = p4InputScfileRowAlloc(-32, "a string", "a string", "a string", -32, "a string");
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4InputScfileInsertObject(dbh, object)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        p4DiffScfileRow *object;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        object = p4DiffScfileRowAlloc(-32, "a string", "a string", "a string", -32, "a string", 64.64, 64.64);
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4DiffScfileInsertObject(dbh, object)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        p4MagicMaskImfileRow *object;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        object = p4MagicMaskImfileRowAlloc(-32, "a string", -32, "a string", "a string");
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4MagicMaskImfileInsertObject(dbh, object)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        skyCellRow      *object;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        object = skyCellRowAlloc("a string", "a string", 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64);
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!skyCellInsertObject(dbh, object)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        skyCellMapRow   *object;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        object = skyCellMapRowAlloc("a string", "a string", "a string", "a string");
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!skyCellMapInsertObject(dbh, object)) {
             exit(EXIT_FAILURE);
         }
Index: /trunk/ippdb/tests/metadatafromobject.c
===================================================================
--- /trunk/ippdb/tests/metadatafromobject.c	(revision 11779)
+++ /trunk/ippdb/tests/metadatafromobject.c	(revision 11780)
@@ -1658,5 +1658,5 @@
         psFree(object);
 
-        if (!psMetadataLookupS32(&status, md, "p4a_id") == -32) {
+        if (!psMetadataLookupS32(&status, md, "p4_id") == -32) {
             psFree(md);
             exit(EXIT_FAILURE);
@@ -1698,5 +1698,5 @@
         psFree(object);
 
-        if (!psMetadataLookupS32(&status, md, "p4a_id") == -32) {
+        if (!psMetadataLookupS32(&status, md, "p4_id") == -32) {
             psFree(md);
             exit(EXIT_FAILURE);
@@ -1720,4 +1720,49 @@
     {
         psMetadata      *md;
+        p4SkyCellMapRow *object;
+        bool            status;
+
+        object = p4SkyCellMapRowAlloc(-32, "a string", "a string", "a string", -32, "a string");
+        if (!object) {
+            exit(EXIT_FAILURE);
+        }
+
+        md = p4SkyCellMapMetadataFromObject(object);
+        if (!md) {
+            exit(EXIT_FAILURE);
+        }
+
+        psFree(object);
+
+        if (!psMetadataLookupS32(&status, md, "p4_id") == -32) {
+            psFree(md);
+            exit(EXIT_FAILURE);
+        }
+        if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {
+            psFree(md);
+            exit(EXIT_FAILURE);
+        }
+        if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {
+            psFree(md);
+            exit(EXIT_FAILURE);
+        }
+        if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) {
+            psFree(md);
+            exit(EXIT_FAILURE);
+        }
+        if (!psMetadataLookupS32(&status, md, "p3_version") == -32) {
+            psFree(md);
+            exit(EXIT_FAILURE);
+        }
+        if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) {
+            psFree(md);
+            exit(EXIT_FAILURE);
+        }
+
+        psFree(md);
+    }
+
+    {
+        psMetadata      *md;
         p4ScfileRow     *object;
         bool            status;
@@ -1735,5 +1780,5 @@
         psFree(object);
 
-        if (!psMetadataLookupS32(&status, md, "p4a_id") == -32) {
+        if (!psMetadataLookupS32(&status, md, "p4_id") == -32) {
             psFree(md);
             exit(EXIT_FAILURE);
@@ -1764,241 +1809,4 @@
         }
         if (!psMetadataLookupF64(&status, md, "bg_mean_stdev") == 64.64) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(md);
-    }
-
-    {
-        psMetadata      *md;
-        p4InputScfileRow *object;
-        bool            status;
-
-        object = p4InputScfileRowAlloc(-32, "a string", "a string", "a string", -32, "a string");
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        md = p4InputScfileMetadataFromObject(object);
-        if (!md) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-
-        if (!psMetadataLookupS32(&status, md, "p4b_id") == -32) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataLookupS32(&status, md, "p3_version") == -32) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "kind"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(md);
-    }
-
-    {
-        psMetadata      *md;
-        p4DiffScfileRow *object;
-        bool            status;
-
-        object = p4DiffScfileRowAlloc(-32, "a string", "a string", "a string", -32, "a string", 64.64, 64.64);
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        md = p4DiffScfileMetadataFromObject(object);
-        if (!md) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-
-        if (!psMetadataLookupS32(&status, md, "p4b_id") == -32) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataLookupS32(&status, md, "p3_version") == -32) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataLookupF64(&status, md, "bg") == 64.64) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataLookupF64(&status, md, "bg_mean_stdev") == 64.64) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(md);
-    }
-
-    {
-        psMetadata      *md;
-        p4MagicMaskImfileRow *object;
-        bool            status;
-
-        object = p4MagicMaskImfileRowAlloc(-32, "a string", -32, "a string", "a string");
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        md = p4MagicMaskImfileMetadataFromObject(object);
-        if (!md) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-
-        if (!psMetadataLookupS32(&status, md, "p4c_id") == -32) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataLookupS32(&status, md, "p3_version") == -32) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(md);
-    }
-
-    {
-        psMetadata      *md;
-        skyCellRow      *object;
-        bool            status;
-
-        object = skyCellRowAlloc("a string", "a string", 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64);
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        md = skyCellMetadataFromObject(object);
-        if (!md) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-
-        if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataLookupF64(&status, md, "ra1") == 64.64) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataLookupF64(&status, md, "decl1") == 64.64) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataLookupF64(&status, md, "ra2") == 64.64) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataLookupF64(&status, md, "decl2") == 64.64) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataLookupF64(&status, md, "ra3") == 64.64) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataLookupF64(&status, md, "decl3") == 64.64) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataLookupF64(&status, md, "ra4") == 64.64) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataLookupF64(&status, md, "decl4") == 64.64) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(md);
-    }
-
-    {
-        psMetadata      *md;
-        skyCellMapRow   *object;
-        bool            status;
-
-        object = skyCellMapRowAlloc("a string", "a string", "a string", "a string");
-        if (!object) {
-            exit(EXIT_FAILURE);
-        }
-
-        md = skyCellMapMetadataFromObject(object);
-        if (!md) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-
-        if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) {
             psFree(md);
             exit(EXIT_FAILURE);
Index: /trunk/ippdb/tests/objectfrommetadata.c
===================================================================
--- /trunk/ippdb/tests/objectfrommetadata.c	(revision 11779)
+++ /trunk/ippdb/tests/objectfrommetadata.c	(revision 11780)
@@ -2535,5 +2535,5 @@
 
         md = psMetadataAlloc();
-        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4a_id", 0, NULL, -32)) {
+        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) {
             psFree(md);
             exit(EXIT_FAILURE);
@@ -2563,5 +2563,5 @@
         psFree(md);
 
-        if (!object->p4a_id == -32) {
+        if (!object->p4_id == -32) {
             psFree(object);
             exit(EXIT_FAILURE);
@@ -2591,5 +2591,5 @@
 
         md = psMetadataAlloc();
-        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4a_id", 0, NULL, -32)) {
+        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) {
             psFree(md);
             exit(EXIT_FAILURE);
@@ -2616,5 +2616,5 @@
         psFree(md);
 
-        if (!object->p4a_id == -32) {
+        if (!object->p4_id == -32) {
             psFree(object);
             exit(EXIT_FAILURE);
@@ -2638,8 +2638,74 @@
     {
         psMetadata      *md;
+        p4SkyCellMapRow *object;
+
+        md = psMetadataAlloc();
+        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) {
+            psFree(md);
+            exit(EXIT_FAILURE);
+        }
+        if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {
+            psFree(md);
+            exit(EXIT_FAILURE);
+        }
+        if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {
+            psFree(md);
+            exit(EXIT_FAILURE);
+        }
+        if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) {
+            psFree(md);
+            exit(EXIT_FAILURE);
+        }
+        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) {
+            psFree(md);
+            exit(EXIT_FAILURE);
+        }
+        if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) {
+            psFree(md);
+            exit(EXIT_FAILURE);
+        }
+
+        object = p4SkyCellMapObjectFromMetadata(md);
+        if (!object) {
+            psFree(md);
+            exit(EXIT_FAILURE);
+        }
+
+        psFree(md);
+
+        if (!object->p4_id == -32) {
+            psFree(object);
+            exit(EXIT_FAILURE);
+        }
+        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
+            psFree(object);
+            exit(EXIT_FAILURE);
+        }
+        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
+            psFree(object);
+            exit(EXIT_FAILURE);
+        }
+        if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
+            psFree(object);
+            exit(EXIT_FAILURE);
+        }
+        if (!object->p3_version == -32) {
+            psFree(object);
+            exit(EXIT_FAILURE);
+        }
+        if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {
+            psFree(object);
+            exit(EXIT_FAILURE);
+        }
+
+        psFree(object);
+    }
+
+    {
+        psMetadata      *md;
         p4ScfileRow     *object;
 
         md = psMetadataAlloc();
-        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4a_id", 0, NULL, -32)) {
+        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) {
             psFree(md);
             exit(EXIT_FAILURE);
@@ -2682,5 +2748,5 @@
         psFree(md);
 
-        if (!object->p4a_id == -32) {
+        if (!object->p4_id == -32) {
             psFree(object);
             exit(EXIT_FAILURE);
@@ -2711,358 +2777,4 @@
         }
         if (!object->bg_mean_stdev == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-    }
-
-    {
-        psMetadata      *md;
-        p4InputScfileRow *object;
-
-        md = psMetadataAlloc();
-        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4b_id", 0, NULL, -32)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "kind", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        object = p4InputScfileObjectFromMetadata(md);
-        if (!object) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(md);
-
-        if (!object->p4b_id == -32) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->p3_version == -32) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->kind, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-    }
-
-    {
-        psMetadata      *md;
-        p4DiffScfileRow *object;
-
-        md = psMetadataAlloc();
-        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4b_id", 0, NULL, -32)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 64.64)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_mean_stdev", 0, NULL, 64.64)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        object = p4DiffScfileObjectFromMetadata(md);
-        if (!object) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(md);
-
-        if (!object->p4b_id == -32) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->p3_version == -32) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->bg == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->bg_mean_stdev == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-    }
-
-    {
-        psMetadata      *md;
-        p4MagicMaskImfileRow *object;
-
-        md = psMetadataAlloc();
-        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4c_id", 0, NULL, -32)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        object = p4MagicMaskImfileObjectFromMetadata(md);
-        if (!object) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(md);
-
-        if (!object->p4c_id == -32) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->p3_version == -32) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-    }
-
-    {
-        psMetadata      *md;
-        skyCellRow      *object;
-
-        md = psMetadataAlloc();
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddF64(md, PS_LIST_TAIL, "ra1", 0, NULL, 64.64)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddF64(md, PS_LIST_TAIL, "decl1", 0, NULL, 64.64)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddF64(md, PS_LIST_TAIL, "ra2", 0, NULL, 64.64)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddF64(md, PS_LIST_TAIL, "decl2", 0, NULL, 64.64)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddF64(md, PS_LIST_TAIL, "ra3", 0, NULL, 64.64)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddF64(md, PS_LIST_TAIL, "decl3", 0, NULL, 64.64)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddF64(md, PS_LIST_TAIL, "ra4", 0, NULL, 64.64)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddF64(md, PS_LIST_TAIL, "decl4", 0, NULL, 64.64)) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        object = skyCellObjectFromMetadata(md);
-        if (!object) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(md);
-
-        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->ra1 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->decl1 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->ra2 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->decl2 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->ra3 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->decl3 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->ra4 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (!object->decl4 == 64.64) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(object);
-    }
-
-    {
-        psMetadata      *md;
-        skyCellMapRow   *object;
-
-        md = psMetadataAlloc();
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-        if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        object = skyCellMapObjectFromMetadata(md);
-        if (!object) {
-            psFree(md);
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(md);
-
-        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
-            psFree(object);
-            exit(EXIT_FAILURE);
-        }
-        if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {
             psFree(object);
             exit(EXIT_FAILURE);
Index: /trunk/ippdb/tests/selectrowsfits.c
===================================================================
--- /trunk/ippdb/tests/selectrowsfits.c	(revision 11779)
+++ /trunk/ippdb/tests/selectrowsfits.c	(revision 11780)
@@ -747,115 +747,27 @@
         }
 
+        if (!p4SkyCellMapSelectRowsFits(dbh, fits, NULL, 1)) {
+            exit(EXIT_FAILURE);
+        }
+
+        psFree(fits);
+        psDBCleanup(dbh);
+    }
+
+    {
+        psDB            *dbh;
+        psFits          *fits;
+
+        dbh = psDBInit("localhost", "test", NULL, "test");
+        if (!dbh) {
+            exit(EXIT_FAILURE);
+        }
+
+        fits = psFitsOpen(TMP_FILENAME, "w");
+        if (!fits) {
+            exit(EXIT_FAILURE);
+        }
+
         if (!p4ScfileSelectRowsFits(dbh, fits, NULL, 1)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(fits);
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        psFits          *fits;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        fits = psFitsOpen(TMP_FILENAME, "w");
-        if (!fits) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4InputScfileSelectRowsFits(dbh, fits, NULL, 1)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(fits);
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        psFits          *fits;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        fits = psFitsOpen(TMP_FILENAME, "w");
-        if (!fits) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4DiffScfileSelectRowsFits(dbh, fits, NULL, 1)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(fits);
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        psFits          *fits;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        fits = psFitsOpen(TMP_FILENAME, "w");
-        if (!fits) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!p4MagicMaskImfileSelectRowsFits(dbh, fits, NULL, 1)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(fits);
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        psFits          *fits;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        fits = psFitsOpen(TMP_FILENAME, "w");
-        if (!fits) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!skyCellSelectRowsFits(dbh, fits, NULL, 1)) {
-            exit(EXIT_FAILURE);
-        }
-
-        psFree(fits);
-        psDBCleanup(dbh);
-    }
-
-    {
-        psDB            *dbh;
-        psFits          *fits;
-
-        dbh = psDBInit("localhost", "test", NULL, "test");
-        if (!dbh) {
-            exit(EXIT_FAILURE);
-        }
-
-        fits = psFitsOpen(TMP_FILENAME, "w");
-        if (!fits) {
-            exit(EXIT_FAILURE);
-        }
-
-        if (!skyCellMapSelectRowsFits(dbh, fits, NULL, 1)) {
             exit(EXIT_FAILURE);
         }
