Index: trunk/ippdb/src/ippdb.h
===================================================================
--- trunk/ippdb/src/ippdb.h	(revision 11780)
+++ trunk/ippdb/src/ippdb.h	(revision 11809)
@@ -7667,4 +7667,634 @@
     bool            mdcf                ///< format as mdconfig or simple
 );
+/** p5RunRow data structure
+ *
+ * Structure for representing a single row of p5Run table data.
+ */
+
+typedef struct {
+    psS32           p5_id;
+    char            *state;
+    char            *workdir;
+    psTime*         registered;
+} p5RunRow;
+
+/** Creates a new p5RunRow object
+ *
+ *  @return A new p5RunRow object or NULL on failure.
+ */
+
+p5RunRow *p5RunRowAlloc(
+    psS32           p5_id,
+    const char      *state,
+    const char      *workdir,
+    psTime*         registered
+);
+
+/** Creates a new p5Run table
+ *
+ * @return true on success
+ */
+
+bool p5RunCreateTable(
+    psDB            *dbh                ///< Database handle
+);
+
+/** Deletes a p5Run table
+ *
+ * @return true on success
+ */
+
+bool p5RunDropTable(
+    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 p5RunInsert(
+    psDB            *dbh,               ///< Database handle
+    psS32           p5_id,
+    const char      *state,
+    const char      *workdir,
+    psTime*         registered
+);
+
+/** 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 p5RunDelete(
+    psDB            *dbh,               ///< Database handle
+    const psMetadata *where,            ///< Row match criteria
+    unsigned long long limit            ///< Maximum number of elements to delete 
+);
+
+/** Insert a single p5RunRow object into a table
+ *
+ * This function constructs and inserts a single row based on it's parameters.
+ *
+ * @return true on success
+ */
+
+bool p5RunInsertObject(
+    psDB            *dbh,               ///< Database handle
+    p5RunRow        *object             ///< p5RunRow object
+);
+
+/** Insert an array of p5RunRow object into a table
+ *
+ * This function constructs and inserts multiple rows based on it's parameters.
+ *
+ * @return true on success
+ */
+
+bool p5RunInsertObjects(
+    psDB            *dbh,               ///< Database handle
+    psArray         *objects            ///< array of p5RunRow objects
+);
+
+/** Insert data from a binary FITS table p5RunRow 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 p5RunInsertFits(
+    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 p5RunSelectRowsFits(
+    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 p5RunRow into an equivalent psMetadata
+ *
+ * @return A psMetadata pointer or NULL on error
+ */
+
+psMetadata *p5RunMetadataFromObject(
+    const p5RunRow  *object             ///< fooRow to convert into a psMetadata
+);
+
+/** Convert a psMetadata into an equivalent fooRow
+ *
+ * @return A p5RunRow pointer or NULL on error
+ */
+
+p5RunRow *p5RunObjectFromMetadata(
+    psMetadata      *md                 ///< psMetadata to convert into a fooRow
+);
+/** Selects up to limit rows from the database and returns as p5RunRow objects in a psArray
+ *
+ *  See psDBSelectRows() for documentation on the format of where.
+ *
+ * @return A psArray pointer or NULL on error
+ */
+
+psArray *p5RunSelectRowObjects(
+    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 p5Run
+ *
+ *  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 p5RunDeleteObject(
+    psDB            *dbh,               ///< Database handle
+    const p5RunRow *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 p5RunDeleteRowObjects(
+    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 p5RunRow 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 p5RunPrintObjects(
+    FILE            *stream,            ///< a stream
+    psArray         *objects,           ///< An array of p5RunRow objects
+    bool            mdcf                ///< format as mdconfig or simple
+);
+/** Formats and prints an p5RunRow 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 p5RunPrintObject(
+    FILE            *stream,            ///< a stream
+    p5RunRow *object,    ///< an p5RunRow object
+    bool            mdcf                ///< format as mdconfig or simple
+);
+/** p5InputScfileRow data structure
+ *
+ * Structure for representing a single row of p5InputScfile table data.
+ */
+
+typedef struct {
+    psS32           p5_id;
+    psS32           p4_id;
+    char            *skycell_id;
+    char            *tess_id;
+    char            *exp_tag;
+    psS32           p3_version;
+    char            *kind;
+    bool            template;
+} p5InputScfileRow;
+
+/** Creates a new p5InputScfileRow object
+ *
+ *  @return A new p5InputScfileRow object or NULL on failure.
+ */
+
+p5InputScfileRow *p5InputScfileRowAlloc(
+    psS32           p5_id,
+    psS32           p4_id,
+    const char      *skycell_id,
+    const char      *tess_id,
+    const char      *exp_tag,
+    psS32           p3_version,
+    const char      *kind,
+    bool            template
+);
+
+/** Creates a new p5InputScfile table
+ *
+ * @return true on success
+ */
+
+bool p5InputScfileCreateTable(
+    psDB            *dbh                ///< Database handle
+);
+
+/** Deletes a p5InputScfile table
+ *
+ * @return true on success
+ */
+
+bool p5InputScfileDropTable(
+    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 p5InputScfileInsert(
+    psDB            *dbh,               ///< Database handle
+    psS32           p5_id,
+    psS32           p4_id,
+    const char      *skycell_id,
+    const char      *tess_id,
+    const char      *exp_tag,
+    psS32           p3_version,
+    const char      *kind,
+    bool            template
+);
+
+/** 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 p5InputScfileDelete(
+    psDB            *dbh,               ///< Database handle
+    const psMetadata *where,            ///< Row match criteria
+    unsigned long long limit            ///< Maximum number of elements to delete 
+);
+
+/** Insert a single p5InputScfileRow object into a table
+ *
+ * This function constructs and inserts a single row based on it's parameters.
+ *
+ * @return true on success
+ */
+
+bool p5InputScfileInsertObject(
+    psDB            *dbh,               ///< Database handle
+    p5InputScfileRow *object             ///< p5InputScfileRow object
+);
+
+/** Insert an array of p5InputScfileRow object into a table
+ *
+ * This function constructs and inserts multiple rows based on it's parameters.
+ *
+ * @return true on success
+ */
+
+bool p5InputScfileInsertObjects(
+    psDB            *dbh,               ///< Database handle
+    psArray         *objects            ///< array of p5InputScfileRow objects
+);
+
+/** Insert data from a binary FITS table p5InputScfileRow 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 p5InputScfileInsertFits(
+    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 p5InputScfileSelectRowsFits(
+    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 p5InputScfileRow into an equivalent psMetadata
+ *
+ * @return A psMetadata pointer or NULL on error
+ */
+
+psMetadata *p5InputScfileMetadataFromObject(
+    const p5InputScfileRow *object             ///< fooRow to convert into a psMetadata
+);
+
+/** Convert a psMetadata into an equivalent fooRow
+ *
+ * @return A p5InputScfileRow pointer or NULL on error
+ */
+
+p5InputScfileRow *p5InputScfileObjectFromMetadata(
+    psMetadata      *md                 ///< psMetadata to convert into a fooRow
+);
+/** Selects up to limit rows from the database and returns as p5InputScfileRow objects in a psArray
+ *
+ *  See psDBSelectRows() for documentation on the format of where.
+ *
+ * @return A psArray pointer or NULL on error
+ */
+
+psArray *p5InputScfileSelectRowObjects(
+    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 p5InputScfile
+ *
+ *  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 p5InputScfileDeleteObject(
+    psDB            *dbh,               ///< Database handle
+    const p5InputScfileRow *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 p5InputScfileDeleteRowObjects(
+    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 p5InputScfileRow 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 p5InputScfilePrintObjects(
+    FILE            *stream,            ///< a stream
+    psArray         *objects,           ///< An array of p5InputScfileRow objects
+    bool            mdcf                ///< format as mdconfig or simple
+);
+/** Formats and prints an p5InputScfileRow 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 p5InputScfilePrintObject(
+    FILE            *stream,            ///< a stream
+    p5InputScfileRow *object,    ///< an p5InputScfileRow object
+    bool            mdcf                ///< format as mdconfig or simple
+);
+/** p5DiffScfileRow data structure
+ *
+ * Structure for representing a single row of p5DiffScfile table data.
+ */
+
+typedef struct {
+    psS32           p5_id;
+    char            *skycell_id;
+    char            *tess_id;
+    char            *uri;
+    psF64           bg;
+    psF64           bg_mean_stdev;
+} p5DiffScfileRow;
+
+/** Creates a new p5DiffScfileRow object
+ *
+ *  @return A new p5DiffScfileRow object or NULL on failure.
+ */
+
+p5DiffScfileRow *p5DiffScfileRowAlloc(
+    psS32           p5_id,
+    const char      *skycell_id,
+    const char      *tess_id,
+    const char      *uri,
+    psF64           bg,
+    psF64           bg_mean_stdev
+);
+
+/** Creates a new p5DiffScfile table
+ *
+ * @return true on success
+ */
+
+bool p5DiffScfileCreateTable(
+    psDB            *dbh                ///< Database handle
+);
+
+/** Deletes a p5DiffScfile table
+ *
+ * @return true on success
+ */
+
+bool p5DiffScfileDropTable(
+    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 p5DiffScfileInsert(
+    psDB            *dbh,               ///< Database handle
+    psS32           p5_id,
+    const char      *skycell_id,
+    const char      *tess_id,
+    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 p5DiffScfileDelete(
+    psDB            *dbh,               ///< Database handle
+    const psMetadata *where,            ///< Row match criteria
+    unsigned long long limit            ///< Maximum number of elements to delete 
+);
+
+/** Insert a single p5DiffScfileRow object into a table
+ *
+ * This function constructs and inserts a single row based on it's parameters.
+ *
+ * @return true on success
+ */
+
+bool p5DiffScfileInsertObject(
+    psDB            *dbh,               ///< Database handle
+    p5DiffScfileRow *object             ///< p5DiffScfileRow object
+);
+
+/** Insert an array of p5DiffScfileRow object into a table
+ *
+ * This function constructs and inserts multiple rows based on it's parameters.
+ *
+ * @return true on success
+ */
+
+bool p5DiffScfileInsertObjects(
+    psDB            *dbh,               ///< Database handle
+    psArray         *objects            ///< array of p5DiffScfileRow objects
+);
+
+/** Insert data from a binary FITS table p5DiffScfileRow 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 p5DiffScfileInsertFits(
+    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 p5DiffScfileSelectRowsFits(
+    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 p5DiffScfileRow into an equivalent psMetadata
+ *
+ * @return A psMetadata pointer or NULL on error
+ */
+
+psMetadata *p5DiffScfileMetadataFromObject(
+    const p5DiffScfileRow *object             ///< fooRow to convert into a psMetadata
+);
+
+/** Convert a psMetadata into an equivalent fooRow
+ *
+ * @return A p5DiffScfileRow pointer or NULL on error
+ */
+
+p5DiffScfileRow *p5DiffScfileObjectFromMetadata(
+    psMetadata      *md                 ///< psMetadata to convert into a fooRow
+);
+/** Selects up to limit rows from the database and returns as p5DiffScfileRow objects in a psArray
+ *
+ *  See psDBSelectRows() for documentation on the format of where.
+ *
+ * @return A psArray pointer or NULL on error
+ */
+
+psArray *p5DiffScfileSelectRowObjects(
+    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 p5DiffScfile
+ *
+ *  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 p5DiffScfileDeleteObject(
+    psDB            *dbh,               ///< Database handle
+    const p5DiffScfileRow *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 p5DiffScfileDeleteRowObjects(
+    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 p5DiffScfileRow 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 p5DiffScfilePrintObjects(
+    FILE            *stream,            ///< a stream
+    psArray         *objects,           ///< An array of p5DiffScfileRow objects
+    bool            mdcf                ///< format as mdconfig or simple
+);
+/** Formats and prints an p5DiffScfileRow 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 p5DiffScfilePrintObject(
+    FILE            *stream,            ///< a stream
+    p5DiffScfileRow *object,    ///< an p5DiffScfileRow object
+    bool            mdcf                ///< format as mdconfig or simple
+);
 
 /// @}
@@ -7674,3 +8304,3 @@
 #endif
 
-#endif // P4SCFILE_DB_H
+#endif // P5DIFFSCFILE_DB_H
