Index: trunk/ippdb/src/ippdb.h
===================================================================
--- trunk/ippdb/src/ippdb.h	(revision 15533)
+++ trunk/ippdb/src/ippdb.h	(revision 15569)
@@ -10700,4 +10700,409 @@
     bool            mdcf                ///< format as mdconfig or simple
 );
+/** calDBRow data structure
+ *
+ * Structure for representing a single row of calDB table data.
+ */
+
+typedef struct {
+    psS64           cal_id;
+    char            *catdir;
+    char            *state;
+} calDBRow;
+
+/** Creates a new calDBRow object
+ *
+ *  @return A new calDBRow object or NULL on failure.
+ */
+
+calDBRow *calDBRowAlloc(
+    psS64           cal_id,
+    const char      *catdir,
+    const char      *state
+);
+
+/** Creates a new calDB table
+ *
+ * @return true on success
+ */
+
+bool calDBCreateTable(
+    psDB            *dbh                ///< Database handle
+);
+
+/** Deletes a calDB table
+ *
+ * @return true on success
+ */
+
+bool calDBDropTable(
+    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 calDBInsert(
+    psDB            *dbh,               ///< Database handle
+    psS64           cal_id,
+    const char      *catdir,
+    const char      *state
+);
+
+/** 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 calDBDelete(
+    psDB            *dbh,               ///< Database handle
+    const psMetadata *where,            ///< Row match criteria
+    unsigned long long limit            ///< Maximum number of elements to delete 
+);
+
+/** Insert a single calDBRow object into a table
+ *
+ * This function constructs and inserts a single row based on it's parameters.
+ *
+ * @return true on success
+ */
+
+bool calDBInsertObject(
+    psDB            *dbh,               ///< Database handle
+    calDBRow        *object             ///< calDBRow object
+);
+
+/** Insert an array of calDBRow object into a table
+ *
+ * This function constructs and inserts multiple rows based on it's parameters.
+ *
+ * @return true on success
+ */
+
+bool calDBInsertObjects(
+    psDB            *dbh,               ///< Database handle
+    psArray         *objects            ///< array of calDBRow objects
+);
+
+/** Insert data from a binary FITS table calDBRow 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 calDBInsertFits(
+    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 calDBSelectRowsFits(
+    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 calDBRow into an equivalent psMetadata
+ *
+ * @return A psMetadata pointer or NULL on error
+ */
+
+psMetadata *calDBMetadataFromObject(
+    const calDBRow  *object             ///< fooRow to convert into a psMetadata
+);
+
+/** Convert a psMetadata into an equivalent fooRow
+ *
+ * @return A calDBRow pointer or NULL on error
+ */
+
+calDBRow *calDBObjectFromMetadata(
+    psMetadata      *md                 ///< psMetadata to convert into a fooRow
+);
+/** Selects up to limit rows from the database and returns as calDBRow objects in a psArray
+ *
+ *  See psDBSelectRows() for documentation on the format of where.
+ *
+ * @return A psArray pointer or NULL on error
+ */
+
+psArray *calDBSelectRowObjects(
+    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 calDB
+ *
+ *  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 calDBDeleteObject(
+    psDB            *dbh,               ///< Database handle
+    const calDBRow *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 calDBDeleteRowObjects(
+    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 calDBRow 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 calDBPrintObjects(
+    FILE            *stream,            ///< a stream
+    psArray         *objects,           ///< An array of calDBRow objects
+    bool            mdcf                ///< format as mdconfig or simple
+);
+/** Formats and prints an calDBRow 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 calDBPrintObject(
+    FILE            *stream,            ///< a stream
+    calDBRow *object,    ///< an calDBRow object
+    bool            mdcf                ///< format as mdconfig or simple
+);
+/** calRunRow data structure
+ *
+ * Structure for representing a single row of calRun table data.
+ */
+
+typedef struct {
+    psS64           cal_id;
+    char            *region;
+    char            *last_step;
+    char            *state;
+} calRunRow;
+
+/** Creates a new calRunRow object
+ *
+ *  @return A new calRunRow object or NULL on failure.
+ */
+
+calRunRow *calRunRowAlloc(
+    psS64           cal_id,
+    const char      *region,
+    const char      *last_step,
+    const char      *state
+);
+
+/** Creates a new calRun table
+ *
+ * @return true on success
+ */
+
+bool calRunCreateTable(
+    psDB            *dbh                ///< Database handle
+);
+
+/** Deletes a calRun table
+ *
+ * @return true on success
+ */
+
+bool calRunDropTable(
+    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 calRunInsert(
+    psDB            *dbh,               ///< Database handle
+    psS64           cal_id,
+    const char      *region,
+    const char      *last_step,
+    const char      *state
+);
+
+/** 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 calRunDelete(
+    psDB            *dbh,               ///< Database handle
+    const psMetadata *where,            ///< Row match criteria
+    unsigned long long limit            ///< Maximum number of elements to delete 
+);
+
+/** Insert a single calRunRow object into a table
+ *
+ * This function constructs and inserts a single row based on it's parameters.
+ *
+ * @return true on success
+ */
+
+bool calRunInsertObject(
+    psDB            *dbh,               ///< Database handle
+    calRunRow       *object             ///< calRunRow object
+);
+
+/** Insert an array of calRunRow object into a table
+ *
+ * This function constructs and inserts multiple rows based on it's parameters.
+ *
+ * @return true on success
+ */
+
+bool calRunInsertObjects(
+    psDB            *dbh,               ///< Database handle
+    psArray         *objects            ///< array of calRunRow objects
+);
+
+/** Insert data from a binary FITS table calRunRow 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 calRunInsertFits(
+    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 calRunSelectRowsFits(
+    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 calRunRow into an equivalent psMetadata
+ *
+ * @return A psMetadata pointer or NULL on error
+ */
+
+psMetadata *calRunMetadataFromObject(
+    const calRunRow *object             ///< fooRow to convert into a psMetadata
+);
+
+/** Convert a psMetadata into an equivalent fooRow
+ *
+ * @return A calRunRow pointer or NULL on error
+ */
+
+calRunRow *calRunObjectFromMetadata(
+    psMetadata      *md                 ///< psMetadata to convert into a fooRow
+);
+/** Selects up to limit rows from the database and returns as calRunRow objects in a psArray
+ *
+ *  See psDBSelectRows() for documentation on the format of where.
+ *
+ * @return A psArray pointer or NULL on error
+ */
+
+psArray *calRunSelectRowObjects(
+    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 calRun
+ *
+ *  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 calRunDeleteObject(
+    psDB            *dbh,               ///< Database handle
+    const calRunRow *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 calRunDeleteRowObjects(
+    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 calRunRow 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 calRunPrintObjects(
+    FILE            *stream,            ///< a stream
+    psArray         *objects,           ///< An array of calRunRow objects
+    bool            mdcf                ///< format as mdconfig or simple
+);
+/** Formats and prints an calRunRow 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 calRunPrintObject(
+    FILE            *stream,            ///< a stream
+    calRunRow *object,    ///< an calRunRow object
+    bool            mdcf                ///< format as mdconfig or simple
+);
 
 /// @}
@@ -10707,3 +11112,3 @@
 #endif
 
-#endif // MAGICSKYFILEMASK_DB_H
+#endif // CALRUN_DB_H
