IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11780


Ignore:
Timestamp:
Feb 13, 2007, 12:33:39 PM (19 years ago)
Author:
jhoblitt
Message:

VERSION 1.1.5

Location:
trunk/ippdb
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippdb/Makefile.am

    r11720 r11780  
    4343    $(top_builddir)/docs/man/man3/p4RunRow.3 \
    4444    $(top_builddir)/docs/man/man3/p4InputExpRow.3 \
    45     $(top_builddir)/docs/man/man3/p4ScfileRow.3 \
    46     $(top_builddir)/docs/man/man3/p4InputScfileRow.3 \
    47     $(top_builddir)/docs/man/man3/p4DiffScfileRow.3 \
    48     $(top_builddir)/docs/man/man3/p4MagicMaskImfileRow.3 \
    49     $(top_builddir)/docs/man/man3/skyCellRow.3 \
    50     $(top_builddir)/docs/man/man3/skyCellMapRow.3
     45    $(top_builddir)/docs/man/man3/p4SkyCellMapRow.3 \
     46    $(top_builddir)/docs/man/man3/p4ScfileRow.3
    5147
    5248
    53 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:
     49docs/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:
    5450        $(DOXYGEN)
    5551
  • trunk/ippdb/configure.ac

    r11733 r11780  
    77AC_PREREQ(2.59)
    88
    9 AC_INIT([ippdb], [1.1.4], [pan-starrs.ifa.hawaii.edu])
     9AC_INIT([ippdb], [1.1.5], [pan-starrs.ifa.hawaii.edu])
    1010AC_CONFIG_SRCDIR([ippdb.pc.in])
    1111
  • trunk/ippdb/src/ippdb.c

    r11733 r11780  
    6464#define P4RUN_TABLE_NAME "p4Run"
    6565#define P4INPUTEXP_TABLE_NAME "p4InputExp"
     66#define P4SKYCELLMAP_TABLE_NAME "p4SkyCellMap"
    6667#define P4SCFILE_TABLE_NAME "p4Scfile"
    67 #define P4INPUTSCFILE_TABLE_NAME "p4InputScfile"
    68 #define P4DIFFSCFILE_TABLE_NAME "p4DiffScfile"
    69 #define P4MAGICMASKIMFILE_TABLE_NAME "p4MagicMaskImfile"
    70 #define SKYCELL_TABLE_NAME "skyCell"
    71 #define SKYCELLMAP_TABLE_NAME "skyCellMap"
    7268#define MAX_STRING_LENGTH 1024
    7369
     
    1346213458static void p4RunRowFree(p4RunRow *object);
    1346313459
    13464 p4RunRow *p4RunRowAlloc(psS32 p4a_id, const char *mode, const char *state, const char *workdir, psTime* registered)
     13460p4RunRow *p4RunRowAlloc(psS32 p4_id, const char *mode, const char *state, const char *workdir, psTime* registered)
    1346513461{
    1346613462    p4RunRow        *_object;
     
    1346913465    psMemSetDeallocator(_object, (psFreeFunc)p4RunRowFree);
    1347013466
    13471     _object->p4a_id = p4a_id;
     13467    _object->p4_id = p4_id;
    1347213468    _object->mode = psStringCopy(mode);
    1347313469    _object->state = psStringCopy(state);
     
    1348913485{
    1349013486    psMetadata *md = psMetadataAlloc();
    13491     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, "Primary Key AUTO_INCREMENT", 0)) {
    13492         psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
     13487    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key AUTO_INCREMENT", 0)) {
     13488        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
    1349313489        psFree(md);
    1349413490        return false;
     
    1352713523}
    1352813524
    13529 bool p4RunInsert(psDB * dbh, psS32 p4a_id, const char *mode, const char *state, const char *workdir, psTime* registered)
     13525bool p4RunInsert(psDB * dbh, psS32 p4_id, const char *mode, const char *state, const char *workdir, psTime* registered)
    1353013526{
    1353113527    psMetadata *md = psMetadataAlloc();
    13532     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, NULL, p4a_id)) {
    13533         psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
     13528    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) {
     13529        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
    1353413530        psFree(md);
    1353513531        return false;
     
    1357813574bool p4RunInsertObject(psDB *dbh, p4RunRow *object)
    1357913575{
    13580     return p4RunInsert(dbh, object->p4a_id, object->mode, object->state, object->workdir, object->registered);
     13576    return p4RunInsert(dbh, object->p4_id, object->mode, object->state, object->workdir, object->registered);
    1358113577}
    1358213578
     
    1365113647{
    1365213648    psMetadata *md = psMetadataAlloc();
    13653     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, NULL, object->p4a_id)) {
    13654         psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
     13649    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) {
     13650        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
    1365513651        psFree(md);
    1365613652        return false;
     
    1368513681
    1368613682bool status = false;
    13687     psS32 p4a_id = psMetadataLookupS32(&status, md, "p4a_id");
    13688     if (!status) {
    13689         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4a_id");
     13683    psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id");
     13684    if (!status) {
     13685        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id");
    1369013686        return false;
    1369113687    }
     
    1371113707    }
    1371213708
    13713     return p4RunRowAlloc(p4a_id, mode, state, workdir, registered);
     13709    return p4RunRowAlloc(p4_id, mode, state, workdir, registered);
    1371413710}
    1371513711psArray *p4RunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
     
    1382313819static void p4InputExpRowFree(p4InputExpRow *object);
    1382413820
    13825 p4InputExpRow *p4InputExpRowAlloc(psS32 p4a_id, const char *exp_tag, psS32 p3_version, bool magiced)
     13821p4InputExpRow *p4InputExpRowAlloc(psS32 p4_id, const char *exp_tag, psS32 p3_version, bool magiced)
    1382613822{
    1382713823    p4InputExpRow   *_object;
     
    1383013826    psMemSetDeallocator(_object, (psFreeFunc)p4InputExpRowFree);
    1383113827
    13832     _object->p4a_id = p4a_id;
     13828    _object->p4_id = p4_id;
    1383313829    _object->exp_tag = psStringCopy(exp_tag);
    1383413830    _object->p3_version = p3_version;
     
    1384613842{
    1384713843    psMetadata *md = psMetadataAlloc();
    13848     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, "Primary Key", 0)) {
    13849         psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
     13844    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key", 0)) {
     13845        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
    1385013846        psFree(md);
    1385113847        return false;
     
    1387913875}
    1388013876
    13881 bool p4InputExpInsert(psDB * dbh, psS32 p4a_id, const char *exp_tag, psS32 p3_version, bool magiced)
     13877bool p4InputExpInsert(psDB * dbh, psS32 p4_id, const char *exp_tag, psS32 p3_version, bool magiced)
    1388213878{
    1388313879    psMetadata *md = psMetadataAlloc();
    13884     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, NULL, p4a_id)) {
    13885         psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
     13880    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) {
     13881        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
    1388613882        psFree(md);
    1388713883        return false;
     
    1392513921bool p4InputExpInsertObject(psDB *dbh, p4InputExpRow *object)
    1392613922{
    13927     return p4InputExpInsert(dbh, object->p4a_id, object->exp_tag, object->p3_version, object->magiced);
     13923    return p4InputExpInsert(dbh, object->p4_id, object->exp_tag, object->p3_version, object->magiced);
    1392813924}
    1392913925
     
    1399813994{
    1399913995    psMetadata *md = psMetadataAlloc();
    14000     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, NULL, object->p4a_id)) {
    14001         psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
     13996    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) {
     13997        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
    1400213998        psFree(md);
    1400313999        return false;
     
    1402714023
    1402814024bool status = false;
    14029     psS32 p4a_id = psMetadataLookupS32(&status, md, "p4a_id");
    14030     if (!status) {
    14031         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4a_id");
     14025    psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id");
     14026    if (!status) {
     14027        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id");
    1403214028        return false;
    1403314029    }
     
    1404814044    }
    1404914045
    14050     return p4InputExpRowAlloc(p4a_id, exp_tag, p3_version, magiced);
     14046    return p4InputExpRowAlloc(p4_id, exp_tag, p3_version, magiced);
    1405114047}
    1405214048psArray *p4InputExpSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
     
    1415814154    return true;
    1415914155}
     14156static void p4SkyCellMapRowFree(p4SkyCellMapRow *object);
     14157
     14158p4SkyCellMapRow *p4SkyCellMapRowAlloc(psS32 p4_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *class_id)
     14159{
     14160    p4SkyCellMapRow *_object;
     14161
     14162    _object = psAlloc(sizeof(p4SkyCellMapRow));
     14163    psMemSetDeallocator(_object, (psFreeFunc)p4SkyCellMapRowFree);
     14164
     14165    _object->p4_id = p4_id;
     14166    _object->skycell_id = psStringCopy(skycell_id);
     14167    _object->tess_id = psStringCopy(tess_id);
     14168    _object->exp_tag = psStringCopy(exp_tag);
     14169    _object->p3_version = p3_version;
     14170    _object->class_id = psStringCopy(class_id);
     14171
     14172    return _object;
     14173}
     14174
     14175static void p4SkyCellMapRowFree(p4SkyCellMapRow *object)
     14176{
     14177    psFree(object->skycell_id);
     14178    psFree(object->tess_id);
     14179    psFree(object->exp_tag);
     14180    psFree(object->class_id);
     14181}
     14182
     14183bool p4SkyCellMapCreateTable(psDB *dbh)
     14184{
     14185    psMetadata *md = psMetadataAlloc();
     14186    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key", 0)) {
     14187        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
     14188        psFree(md);
     14189        return false;
     14190    }
     14191    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {
     14192        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
     14193        psFree(md);
     14194        return false;
     14195    }
     14196    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {
     14197        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
     14198        psFree(md);
     14199        return false;
     14200    }
     14201    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) {
     14202        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
     14203        psFree(md);
     14204        return false;
     14205    }
     14206    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) {
     14207        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
     14208        psFree(md);
     14209        return false;
     14210    }
     14211    if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) {
     14212        psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
     14213        psFree(md);
     14214        return false;
     14215    }
     14216
     14217    bool status = psDBCreateTable(dbh, P4SKYCELLMAP_TABLE_NAME, md);
     14218
     14219    psFree(md);
     14220
     14221    return status;
     14222}
     14223
     14224bool p4SkyCellMapDropTable(psDB *dbh)
     14225{
     14226    return psDBDropTable(dbh, P4SKYCELLMAP_TABLE_NAME);
     14227}
     14228
     14229bool 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)
     14230{
     14231    psMetadata *md = psMetadataAlloc();
     14232    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) {
     14233        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
     14234        psFree(md);
     14235        return false;
     14236    }
     14237    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {
     14238        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
     14239        psFree(md);
     14240        return false;
     14241    }
     14242    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {
     14243        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
     14244        psFree(md);
     14245        return false;
     14246    }
     14247    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) {
     14248        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
     14249        psFree(md);
     14250        return false;
     14251    }
     14252    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) {
     14253        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
     14254        psFree(md);
     14255        return false;
     14256    }
     14257    if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) {
     14258        psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
     14259        psFree(md);
     14260        return false;
     14261    }
     14262
     14263    bool status = psDBInsertOneRow(dbh, P4SKYCELLMAP_TABLE_NAME, md);
     14264    psFree(md);
     14265
     14266    return status;
     14267}
     14268
     14269long long p4SkyCellMapDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
     14270{
     14271    long long       deleted = 0;
     14272
     14273    long long count = psDBDeleteRows(dbh, P4SKYCELLMAP_TABLE_NAME, where, limit);
     14274    if (count < 0) {
     14275        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4SkyCellMap");
     14276        return count;
     14277
     14278        deleted += count;
     14279    }
     14280
     14281    return deleted;
     14282}
     14283bool p4SkyCellMapInsertObject(psDB *dbh, p4SkyCellMapRow *object)
     14284{
     14285    return p4SkyCellMapInsert(dbh, object->p4_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->class_id);
     14286}
     14287
     14288bool p4SkyCellMapInsertObjects(psDB *dbh, psArray *objects)
     14289{
     14290    for (long i = 0; i < psArrayLength(objects); i++) {
     14291        if (!p4SkyCellMapInsertObject(dbh, objects->data[i])) {
     14292            return false;
     14293        }
     14294    }
     14295
     14296    return true;
     14297}
     14298
     14299bool p4SkyCellMapInsertFits(psDB *dbh, const psFits *fits)
     14300{
     14301    psArray         *rowSet;
     14302
     14303    // move to (the first?) extension named  P4SKYCELLMAP_TABLE_NAME
     14304    if (!psFitsMoveExtName(fits, P4SKYCELLMAP_TABLE_NAME)) {
     14305        psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4SKYCELLMAP_TABLE_NAME);
     14306        return false;
     14307    }
     14308
     14309    // check HDU type
     14310    if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
     14311        psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
     14312        return false;
     14313    }
     14314
     14315    // read fits table
     14316    rowSet = psFitsReadTable(fits);
     14317    if (!rowSet) {
     14318        psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
     14319        psFree(rowSet);
     14320        return false;
     14321    }
     14322
     14323    if (!psDBInsertRows(dbh, P4SKYCELLMAP_TABLE_NAME, rowSet)) {
     14324        psError(PS_ERR_UNKNOWN, false, "databse insert failed");
     14325        psFree(rowSet);
     14326        return false;
     14327    }
     14328
     14329    psFree(rowSet);
     14330
     14331    return true;
     14332}
     14333
     14334bool p4SkyCellMapSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
     14335{
     14336    psArray         *rowSet;
     14337
     14338    rowSet = psDBSelectRows(dbh, P4SKYCELLMAP_TABLE_NAME, where, limit);
     14339    if (!rowSet) {
     14340        return false;
     14341    }
     14342
     14343    // output to fits
     14344    if (!psFitsWriteTable(fits, NULL, rowSet, P4SKYCELLMAP_TABLE_NAME)) {
     14345        psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
     14346        psFree(rowSet);
     14347        return false;
     14348    }
     14349
     14350    psFree(rowSet);
     14351
     14352    return true;
     14353}
     14354
     14355psMetadata *p4SkyCellMapMetadataFromObject(const p4SkyCellMapRow *object)
     14356{
     14357    psMetadata *md = psMetadataAlloc();
     14358    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) {
     14359        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
     14360        psFree(md);
     14361        return false;
     14362    }
     14363    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {
     14364        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
     14365        psFree(md);
     14366        return false;
     14367    }
     14368    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {
     14369        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
     14370        psFree(md);
     14371        return false;
     14372    }
     14373    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) {
     14374        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
     14375        psFree(md);
     14376        return false;
     14377    }
     14378    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) {
     14379        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
     14380        psFree(md);
     14381        return false;
     14382    }
     14383    if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) {
     14384        psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
     14385        psFree(md);
     14386        return false;
     14387    }
     14388
     14389
     14390    return md;
     14391}
     14392
     14393p4SkyCellMapRow *p4SkyCellMapObjectFromMetadata(psMetadata *md)
     14394{
     14395
     14396bool status = false;
     14397    psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id");
     14398    if (!status) {
     14399        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id");
     14400        return false;
     14401    }
     14402    char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");
     14403    if (!status) {
     14404        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");
     14405        return false;
     14406    }
     14407    char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");
     14408    if (!status) {
     14409        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");
     14410        return false;
     14411    }
     14412    char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag");
     14413    if (!status) {
     14414        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag");
     14415        return false;
     14416    }
     14417    psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version");
     14418    if (!status) {
     14419        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version");
     14420        return false;
     14421    }
     14422    char* class_id = psMetadataLookupPtr(&status, md, "class_id");
     14423    if (!status) {
     14424        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id");
     14425        return false;
     14426    }
     14427
     14428    return p4SkyCellMapRowAlloc(p4_id, skycell_id, tess_id, exp_tag, p3_version, class_id);
     14429}
     14430psArray *p4SkyCellMapSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
     14431{
     14432    psArray         *rowSet;
     14433    psArray         *returnSet;
     14434    psU64           i;
     14435
     14436    rowSet = psDBSelectRows(dbh, P4SKYCELLMAP_TABLE_NAME, where, limit);
     14437    if (!rowSet) {
     14438        return NULL;
     14439    }
     14440
     14441    // convert psMetadata rows to row objects
     14442
     14443    returnSet = psArrayAllocEmpty(rowSet->n);
     14444
     14445    for (i = 0; i < rowSet->n; i++) {
     14446        p4SkyCellMapRow *object = p4SkyCellMapObjectFromMetadata(rowSet->data[i]);
     14447        psArrayAdd(returnSet, 0, object);
     14448        psFree(object);
     14449    }
     14450
     14451    psFree(rowSet);
     14452
     14453    return returnSet;
     14454}
     14455bool p4SkyCellMapDeleteObject(psDB *dbh, const p4SkyCellMapRow *object)
     14456{
     14457    psMetadata *where = p4SkyCellMapMetadataFromObject(object);
     14458    long long count = psDBDeleteRows(dbh, P4SKYCELLMAP_TABLE_NAME, where, 0);
     14459    psFree(where);
     14460    if (count < 0) {
     14461        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4SkyCellMap");
     14462        return false;
     14463    }
     14464    if (count > 1) {
     14465        // XXX should this be a psAbort() instead?  It is possible that
     14466        // having an object match multiple rows was by design.
     14467        psError(PS_ERR_UNKNOWN, true, "p4SkyCellMapRow object matched more then one row.  Check your database schema");
     14468        return false;
     14469    }
     14470
     14471    return true;
     14472}
     14473long long p4SkyCellMapDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
     14474{
     14475    long long       deleted = 0;
     14476
     14477    for (long long i = 0; i < objects->n; i++) {
     14478        p4SkyCellMapRow *object = objects->data[i];
     14479        psMetadata *where = p4SkyCellMapMetadataFromObject(object);
     14480        long long count = psDBDeleteRows(dbh, P4SKYCELLMAP_TABLE_NAME, where, limit);
     14481        psFree(where);
     14482        if (count < 0) {
     14483            psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4SkyCellMap");
     14484            return count;
     14485        }
     14486
     14487        deleted += count;
     14488    }
     14489
     14490    return deleted;
     14491}
     14492bool p4SkyCellMapPrintObjects(FILE *stream, psArray *objects, bool mdcf)
     14493{
     14494    PS_ASSERT_PTR_NON_NULL(objects, false);
     14495
     14496    psMetadata *output = psMetadataAlloc();
     14497    for (long i = 0; i < psArrayLength(objects); i++) {
     14498        psMetadata *md = p4SkyCellMapMetadataFromObject(objects->data[i]);
     14499        if (!psMetadataAddMetadata(
     14500            output,
     14501            PS_LIST_TAIL,
     14502            P4SKYCELLMAP_TABLE_NAME,
     14503            PS_META_DUPLICATE_OK,
     14504            NULL,
     14505            md
     14506        )) {
     14507            psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
     14508            psFree(md);
     14509            psFree(output);
     14510            return false;
     14511        }
     14512        psFree(md);
     14513    }
     14514
     14515    if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
     14516        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
     14517        psFree(output);
     14518    }
     14519    psFree(output);
     14520
     14521    return true;
     14522}
     14523bool p4SkyCellMapPrintObject(FILE *stream, p4SkyCellMapRow *object, bool mdcf)
     14524{
     14525    PS_ASSERT_PTR_NON_NULL(object, false);
     14526
     14527    psMetadata *md = p4SkyCellMapMetadataFromObject(object);
     14528
     14529    if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
     14530        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
     14531        psFree(md);
     14532    }
     14533
     14534    psFree(md);
     14535
     14536    return true;
     14537}
    1416014538static void p4ScfileRowFree(p4ScfileRow *object);
    1416114539
    14162 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)
     14540p4ScfileRow *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)
    1416314541{
    1416414542    p4ScfileRow     *_object;
     
    1416714545    psMemSetDeallocator(_object, (psFreeFunc)p4ScfileRowFree);
    1416814546
    14169     _object->p4a_id = p4a_id;
     14547    _object->p4_id = p4_id;
    1417014548    _object->skycell_id = psStringCopy(skycell_id);
    1417114549    _object->tess_id = psStringCopy(tess_id);
     
    1419014568{
    1419114569    psMetadata *md = psMetadataAlloc();
    14192     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, "Primary Key", 0)) {
    14193         psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
     14570    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key", 0)) {
     14571        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
    1419414572        psFree(md);
    1419514573        return false;
     
    1424314621}
    1424414622
    14245 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)
     14623bool 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)
    1424614624{
    1424714625    psMetadata *md = psMetadataAlloc();
    14248     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, NULL, p4a_id)) {
    14249         psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
     14626    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) {
     14627        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
    1425014628        psFree(md);
    1425114629        return false;
     
    1430914687bool p4ScfileInsertObject(psDB *dbh, p4ScfileRow *object)
    1431014688{
    14311     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);
     14689    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);
    1431214690}
    1431314691
     
    1438214760{
    1438314761    psMetadata *md = psMetadataAlloc();
    14384     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4a_id", PS_DATA_S32, NULL, object->p4a_id)) {
    14385         psError(PS_ERR_UNKNOWN, false, "failed to add item p4a_id");
     14762    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) {
     14763        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
    1438614764        psFree(md);
    1438714765        return false;
     
    1443114809
    1443214810bool status = false;
    14433     psS32 p4a_id = psMetadataLookupS32(&status, md, "p4a_id");
    14434     if (!status) {
    14435         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4a_id");
     14811    psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id");
     14812    if (!status) {
     14813        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id");
    1443614814        return false;
    1443714815    }
     
    1447214850    }
    1447314851
    14474     return p4ScfileRowAlloc(p4a_id, skycell_id, tess_id, exp_tag, p3_version, uri, bg, bg_mean_stdev);
     14852    return p4ScfileRowAlloc(p4_id, skycell_id, tess_id, exp_tag, p3_version, uri, bg, bg_mean_stdev);
    1447514853}
    1447614854psArray *p4ScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
     
    1458214960    return true;
    1458314961}
    14584 static void p4InputScfileRowFree(p4InputScfileRow *object);
    14585 
    14586 p4InputScfileRow *p4InputScfileRowAlloc(psS32 p4b_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *kind)
    14587 {
    14588     p4InputScfileRow *_object;
    14589 
    14590     _object = psAlloc(sizeof(p4InputScfileRow));
    14591     psMemSetDeallocator(_object, (psFreeFunc)p4InputScfileRowFree);
    14592 
    14593     _object->p4b_id = p4b_id;
    14594     _object->skycell_id = psStringCopy(skycell_id);
    14595     _object->tess_id = psStringCopy(tess_id);
    14596     _object->exp_tag = psStringCopy(exp_tag);
    14597     _object->p3_version = p3_version;
    14598     _object->kind = psStringCopy(kind);
    14599 
    14600     return _object;
    14601 }
    14602 
    14603 static void p4InputScfileRowFree(p4InputScfileRow *object)
    14604 {
    14605     psFree(object->skycell_id);
    14606     psFree(object->tess_id);
    14607     psFree(object->exp_tag);
    14608     psFree(object->kind);
    14609 }
    14610 
    14611 bool p4InputScfileCreateTable(psDB *dbh)
    14612 {
    14613     psMetadata *md = psMetadataAlloc();
    14614     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, "Primary Key", 0)) {
    14615         psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id");
    14616         psFree(md);
    14617         return false;
    14618     }
    14619     if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {
    14620         psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
    14621         psFree(md);
    14622         return false;
    14623     }
    14624     if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {
    14625         psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
    14626         psFree(md);
    14627         return false;
    14628     }
    14629     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) {
    14630         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    14631         psFree(md);
    14632         return false;
    14633     }
    14634     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) {
    14635         psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    14636         psFree(md);
    14637         return false;
    14638     }
    14639     if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, "Key", "64")) {
    14640         psError(PS_ERR_UNKNOWN, false, "failed to add item kind");
    14641         psFree(md);
    14642         return false;
    14643     }
    14644 
    14645     bool status = psDBCreateTable(dbh, P4INPUTSCFILE_TABLE_NAME, md);
    14646 
    14647     psFree(md);
    14648 
    14649     return status;
    14650 }
    14651 
    14652 bool p4InputScfileDropTable(psDB *dbh)
    14653 {
    14654     return psDBDropTable(dbh, P4INPUTSCFILE_TABLE_NAME);
    14655 }
    14656 
    14657 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)
    14658 {
    14659     psMetadata *md = psMetadataAlloc();
    14660     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, NULL, p4b_id)) {
    14661         psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id");
    14662         psFree(md);
    14663         return false;
    14664     }
    14665     if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {
    14666         psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
    14667         psFree(md);
    14668         return false;
    14669     }
    14670     if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {
    14671         psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
    14672         psFree(md);
    14673         return false;
    14674     }
    14675     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) {
    14676         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    14677         psFree(md);
    14678         return false;
    14679     }
    14680     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) {
    14681         psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    14682         psFree(md);
    14683         return false;
    14684     }
    14685     if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, kind)) {
    14686         psError(PS_ERR_UNKNOWN, false, "failed to add item kind");
    14687         psFree(md);
    14688         return false;
    14689     }
    14690 
    14691     bool status = psDBInsertOneRow(dbh, P4INPUTSCFILE_TABLE_NAME, md);
    14692     psFree(md);
    14693 
    14694     return status;
    14695 }
    14696 
    14697 long long p4InputScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
    14698 {
    14699     long long       deleted = 0;
    14700 
    14701     long long count = psDBDeleteRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, limit);
    14702     if (count < 0) {
    14703         psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputScfile");
    14704         return count;
    14705 
    14706         deleted += count;
    14707     }
    14708 
    14709     return deleted;
    14710 }
    14711 bool p4InputScfileInsertObject(psDB *dbh, p4InputScfileRow *object)
    14712 {
    14713     return p4InputScfileInsert(dbh, object->p4b_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->kind);
    14714 }
    14715 
    14716 bool p4InputScfileInsertObjects(psDB *dbh, psArray *objects)
    14717 {
    14718     for (long i = 0; i < psArrayLength(objects); i++) {
    14719         if (!p4InputScfileInsertObject(dbh, objects->data[i])) {
    14720             return false;
    14721         }
    14722     }
    14723 
    14724     return true;
    14725 }
    14726 
    14727 bool p4InputScfileInsertFits(psDB *dbh, const psFits *fits)
    14728 {
    14729     psArray         *rowSet;
    14730 
    14731     // move to (the first?) extension named  P4INPUTSCFILE_TABLE_NAME
    14732     if (!psFitsMoveExtName(fits, P4INPUTSCFILE_TABLE_NAME)) {
    14733         psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4INPUTSCFILE_TABLE_NAME);
    14734         return false;
    14735     }
    14736 
    14737     // check HDU type
    14738     if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
    14739         psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
    14740         return false;
    14741     }
    14742 
    14743     // read fits table
    14744     rowSet = psFitsReadTable(fits);
    14745     if (!rowSet) {
    14746         psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
    14747         psFree(rowSet);
    14748         return false;
    14749     }
    14750 
    14751     if (!psDBInsertRows(dbh, P4INPUTSCFILE_TABLE_NAME, rowSet)) {
    14752         psError(PS_ERR_UNKNOWN, false, "databse insert failed");
    14753         psFree(rowSet);
    14754         return false;
    14755     }
    14756 
    14757     psFree(rowSet);
    14758 
    14759     return true;
    14760 }
    14761 
    14762 bool p4InputScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
    14763 {
    14764     psArray         *rowSet;
    14765 
    14766     rowSet = psDBSelectRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, limit);
    14767     if (!rowSet) {
    14768         return false;
    14769     }
    14770 
    14771     // output to fits
    14772     if (!psFitsWriteTable(fits, NULL, rowSet, P4INPUTSCFILE_TABLE_NAME)) {
    14773         psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
    14774         psFree(rowSet);
    14775         return false;
    14776     }
    14777 
    14778     psFree(rowSet);
    14779 
    14780     return true;
    14781 }
    14782 
    14783 psMetadata *p4InputScfileMetadataFromObject(const p4InputScfileRow *object)
    14784 {
    14785     psMetadata *md = psMetadataAlloc();
    14786     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, NULL, object->p4b_id)) {
    14787         psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id");
    14788         psFree(md);
    14789         return false;
    14790     }
    14791     if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {
    14792         psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
    14793         psFree(md);
    14794         return false;
    14795     }
    14796     if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {
    14797         psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
    14798         psFree(md);
    14799         return false;
    14800     }
    14801     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) {
    14802         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    14803         psFree(md);
    14804         return false;
    14805     }
    14806     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) {
    14807         psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    14808         psFree(md);
    14809         return false;
    14810     }
    14811     if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, object->kind)) {
    14812         psError(PS_ERR_UNKNOWN, false, "failed to add item kind");
    14813         psFree(md);
    14814         return false;
    14815     }
    14816 
    14817 
    14818     return md;
    14819 }
    14820 
    14821 p4InputScfileRow *p4InputScfileObjectFromMetadata(psMetadata *md)
    14822 {
    14823 
    14824 bool status = false;
    14825     psS32 p4b_id = psMetadataLookupS32(&status, md, "p4b_id");
    14826     if (!status) {
    14827         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4b_id");
    14828         return false;
    14829     }
    14830     char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");
    14831     if (!status) {
    14832         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");
    14833         return false;
    14834     }
    14835     char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");
    14836     if (!status) {
    14837         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");
    14838         return false;
    14839     }
    14840     char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag");
    14841     if (!status) {
    14842         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag");
    14843         return false;
    14844     }
    14845     psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version");
    14846     if (!status) {
    14847         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version");
    14848         return false;
    14849     }
    14850     char* kind = psMetadataLookupPtr(&status, md, "kind");
    14851     if (!status) {
    14852         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item kind");
    14853         return false;
    14854     }
    14855 
    14856     return p4InputScfileRowAlloc(p4b_id, skycell_id, tess_id, exp_tag, p3_version, kind);
    14857 }
    14858 psArray *p4InputScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
    14859 {
    14860     psArray         *rowSet;
    14861     psArray         *returnSet;
    14862     psU64           i;
    14863 
    14864     rowSet = psDBSelectRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, limit);
    14865     if (!rowSet) {
    14866         return NULL;
    14867     }
    14868 
    14869     // convert psMetadata rows to row objects
    14870 
    14871     returnSet = psArrayAllocEmpty(rowSet->n);
    14872 
    14873     for (i = 0; i < rowSet->n; i++) {
    14874         p4InputScfileRow *object = p4InputScfileObjectFromMetadata(rowSet->data[i]);
    14875         psArrayAdd(returnSet, 0, object);
    14876         psFree(object);
    14877     }
    14878 
    14879     psFree(rowSet);
    14880 
    14881     return returnSet;
    14882 }
    14883 bool p4InputScfileDeleteObject(psDB *dbh, const p4InputScfileRow *object)
    14884 {
    14885     psMetadata *where = p4InputScfileMetadataFromObject(object);
    14886     long long count = psDBDeleteRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, 0);
    14887     psFree(where);
    14888     if (count < 0) {
    14889         psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputScfile");
    14890         return false;
    14891     }
    14892     if (count > 1) {
    14893         // XXX should this be a psAbort() instead?  It is possible that
    14894         // having an object match multiple rows was by design.
    14895         psError(PS_ERR_UNKNOWN, true, "p4InputScfileRow object matched more then one row.  Check your database schema");
    14896         return false;
    14897     }
    14898 
    14899     return true;
    14900 }
    14901 long long p4InputScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
    14902 {
    14903     long long       deleted = 0;
    14904 
    14905     for (long long i = 0; i < objects->n; i++) {
    14906         p4InputScfileRow *object = objects->data[i];
    14907         psMetadata *where = p4InputScfileMetadataFromObject(object);
    14908         long long count = psDBDeleteRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, limit);
    14909         psFree(where);
    14910         if (count < 0) {
    14911             psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputScfile");
    14912             return count;
    14913         }
    14914 
    14915         deleted += count;
    14916     }
    14917 
    14918     return deleted;
    14919 }
    14920 bool p4InputScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)
    14921 {
    14922     PS_ASSERT_PTR_NON_NULL(objects, false);
    14923 
    14924     psMetadata *output = psMetadataAlloc();
    14925     for (long i = 0; i < psArrayLength(objects); i++) {
    14926         psMetadata *md = p4InputScfileMetadataFromObject(objects->data[i]);
    14927         if (!psMetadataAddMetadata(
    14928             output,
    14929             PS_LIST_TAIL,
    14930             P4INPUTSCFILE_TABLE_NAME,
    14931             PS_META_DUPLICATE_OK,
    14932             NULL,
    14933             md
    14934         )) {
    14935             psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
    14936             psFree(md);
    14937             psFree(output);
    14938             return false;
    14939         }
    14940         psFree(md);
    14941     }
    14942 
    14943     if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
    14944         psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
    14945         psFree(output);
    14946     }
    14947     psFree(output);
    14948 
    14949     return true;
    14950 }
    14951 bool p4InputScfilePrintObject(FILE *stream, p4InputScfileRow *object, bool mdcf)
    14952 {
    14953     PS_ASSERT_PTR_NON_NULL(object, false);
    14954 
    14955     psMetadata *md = p4InputScfileMetadataFromObject(object);
    14956 
    14957     if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
    14958         psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
    14959         psFree(md);
    14960     }
    14961 
    14962     psFree(md);
    14963 
    14964     return true;
    14965 }
    14966 static void p4DiffScfileRowFree(p4DiffScfileRow *object);
    14967 
    14968 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)
    14969 {
    14970     p4DiffScfileRow *_object;
    14971 
    14972     _object = psAlloc(sizeof(p4DiffScfileRow));
    14973     psMemSetDeallocator(_object, (psFreeFunc)p4DiffScfileRowFree);
    14974 
    14975     _object->p4b_id = p4b_id;
    14976     _object->skycell_id = psStringCopy(skycell_id);
    14977     _object->tess_id = psStringCopy(tess_id);
    14978     _object->exp_tag = psStringCopy(exp_tag);
    14979     _object->p3_version = p3_version;
    14980     _object->uri = psStringCopy(uri);
    14981     _object->bg = bg;
    14982     _object->bg_mean_stdev = bg_mean_stdev;
    14983 
    14984     return _object;
    14985 }
    14986 
    14987 static void p4DiffScfileRowFree(p4DiffScfileRow *object)
    14988 {
    14989     psFree(object->skycell_id);
    14990     psFree(object->tess_id);
    14991     psFree(object->exp_tag);
    14992     psFree(object->uri);
    14993 }
    14994 
    14995 bool p4DiffScfileCreateTable(psDB *dbh)
    14996 {
    14997     psMetadata *md = psMetadataAlloc();
    14998     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, "Primary Key", 0)) {
    14999         psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id");
    15000         psFree(md);
    15001         return false;
    15002     }
    15003     if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {
    15004         psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
    15005         psFree(md);
    15006         return false;
    15007     }
    15008     if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {
    15009         psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
    15010         psFree(md);
    15011         return false;
    15012     }
    15013     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) {
    15014         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    15015         psFree(md);
    15016         return false;
    15017     }
    15018     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) {
    15019         psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    15020         psFree(md);
    15021         return false;
    15022     }
    15023     if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) {
    15024         psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
    15025         psFree(md);
    15026         return false;
    15027     }
    15028     if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, 0.0)) {
    15029         psError(PS_ERR_UNKNOWN, false, "failed to add item bg");
    15030         psFree(md);
    15031         return false;
    15032     }
    15033     if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, 0.0)) {
    15034         psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev");
    15035         psFree(md);
    15036         return false;
    15037     }
    15038 
    15039     bool status = psDBCreateTable(dbh, P4DIFFSCFILE_TABLE_NAME, md);
    15040 
    15041     psFree(md);
    15042 
    15043     return status;
    15044 }
    15045 
    15046 bool p4DiffScfileDropTable(psDB *dbh)
    15047 {
    15048     return psDBDropTable(dbh, P4DIFFSCFILE_TABLE_NAME);
    15049 }
    15050 
    15051 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)
    15052 {
    15053     psMetadata *md = psMetadataAlloc();
    15054     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, NULL, p4b_id)) {
    15055         psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id");
    15056         psFree(md);
    15057         return false;
    15058     }
    15059     if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {
    15060         psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
    15061         psFree(md);
    15062         return false;
    15063     }
    15064     if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {
    15065         psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
    15066         psFree(md);
    15067         return false;
    15068     }
    15069     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) {
    15070         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    15071         psFree(md);
    15072         return false;
    15073     }
    15074     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) {
    15075         psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    15076         psFree(md);
    15077         return false;
    15078     }
    15079     if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) {
    15080         psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
    15081         psFree(md);
    15082         return false;
    15083     }
    15084     if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, bg)) {
    15085         psError(PS_ERR_UNKNOWN, false, "failed to add item bg");
    15086         psFree(md);
    15087         return false;
    15088     }
    15089     if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, bg_mean_stdev)) {
    15090         psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev");
    15091         psFree(md);
    15092         return false;
    15093     }
    15094 
    15095     bool status = psDBInsertOneRow(dbh, P4DIFFSCFILE_TABLE_NAME, md);
    15096     psFree(md);
    15097 
    15098     return status;
    15099 }
    15100 
    15101 long long p4DiffScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
    15102 {
    15103     long long       deleted = 0;
    15104 
    15105     long long count = psDBDeleteRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, limit);
    15106     if (count < 0) {
    15107         psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4DiffScfile");
    15108         return count;
    15109 
    15110         deleted += count;
    15111     }
    15112 
    15113     return deleted;
    15114 }
    15115 bool p4DiffScfileInsertObject(psDB *dbh, p4DiffScfileRow *object)
    15116 {
    15117     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);
    15118 }
    15119 
    15120 bool p4DiffScfileInsertObjects(psDB *dbh, psArray *objects)
    15121 {
    15122     for (long i = 0; i < psArrayLength(objects); i++) {
    15123         if (!p4DiffScfileInsertObject(dbh, objects->data[i])) {
    15124             return false;
    15125         }
    15126     }
    15127 
    15128     return true;
    15129 }
    15130 
    15131 bool p4DiffScfileInsertFits(psDB *dbh, const psFits *fits)
    15132 {
    15133     psArray         *rowSet;
    15134 
    15135     // move to (the first?) extension named  P4DIFFSCFILE_TABLE_NAME
    15136     if (!psFitsMoveExtName(fits, P4DIFFSCFILE_TABLE_NAME)) {
    15137         psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4DIFFSCFILE_TABLE_NAME);
    15138         return false;
    15139     }
    15140 
    15141     // check HDU type
    15142     if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
    15143         psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
    15144         return false;
    15145     }
    15146 
    15147     // read fits table
    15148     rowSet = psFitsReadTable(fits);
    15149     if (!rowSet) {
    15150         psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
    15151         psFree(rowSet);
    15152         return false;
    15153     }
    15154 
    15155     if (!psDBInsertRows(dbh, P4DIFFSCFILE_TABLE_NAME, rowSet)) {
    15156         psError(PS_ERR_UNKNOWN, false, "databse insert failed");
    15157         psFree(rowSet);
    15158         return false;
    15159     }
    15160 
    15161     psFree(rowSet);
    15162 
    15163     return true;
    15164 }
    15165 
    15166 bool p4DiffScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
    15167 {
    15168     psArray         *rowSet;
    15169 
    15170     rowSet = psDBSelectRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, limit);
    15171     if (!rowSet) {
    15172         return false;
    15173     }
    15174 
    15175     // output to fits
    15176     if (!psFitsWriteTable(fits, NULL, rowSet, P4DIFFSCFILE_TABLE_NAME)) {
    15177         psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
    15178         psFree(rowSet);
    15179         return false;
    15180     }
    15181 
    15182     psFree(rowSet);
    15183 
    15184     return true;
    15185 }
    15186 
    15187 psMetadata *p4DiffScfileMetadataFromObject(const p4DiffScfileRow *object)
    15188 {
    15189     psMetadata *md = psMetadataAlloc();
    15190     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, NULL, object->p4b_id)) {
    15191         psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id");
    15192         psFree(md);
    15193         return false;
    15194     }
    15195     if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {
    15196         psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
    15197         psFree(md);
    15198         return false;
    15199     }
    15200     if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {
    15201         psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
    15202         psFree(md);
    15203         return false;
    15204     }
    15205     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) {
    15206         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    15207         psFree(md);
    15208         return false;
    15209     }
    15210     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) {
    15211         psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    15212         psFree(md);
    15213         return false;
    15214     }
    15215     if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) {
    15216         psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
    15217         psFree(md);
    15218         return false;
    15219     }
    15220     if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, object->bg)) {
    15221         psError(PS_ERR_UNKNOWN, false, "failed to add item bg");
    15222         psFree(md);
    15223         return false;
    15224     }
    15225     if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, object->bg_mean_stdev)) {
    15226         psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev");
    15227         psFree(md);
    15228         return false;
    15229     }
    15230 
    15231 
    15232     return md;
    15233 }
    15234 
    15235 p4DiffScfileRow *p4DiffScfileObjectFromMetadata(psMetadata *md)
    15236 {
    15237 
    15238 bool status = false;
    15239     psS32 p4b_id = psMetadataLookupS32(&status, md, "p4b_id");
    15240     if (!status) {
    15241         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4b_id");
    15242         return false;
    15243     }
    15244     char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");
    15245     if (!status) {
    15246         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");
    15247         return false;
    15248     }
    15249     char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");
    15250     if (!status) {
    15251         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");
    15252         return false;
    15253     }
    15254     char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag");
    15255     if (!status) {
    15256         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag");
    15257         return false;
    15258     }
    15259     psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version");
    15260     if (!status) {
    15261         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version");
    15262         return false;
    15263     }
    15264     char* uri = psMetadataLookupPtr(&status, md, "uri");
    15265     if (!status) {
    15266         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri");
    15267         return false;
    15268     }
    15269     psF64 bg = psMetadataLookupF64(&status, md, "bg");
    15270     if (!status) {
    15271         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg");
    15272         return false;
    15273     }
    15274     psF64 bg_mean_stdev = psMetadataLookupF64(&status, md, "bg_mean_stdev");
    15275     if (!status) {
    15276         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_mean_stdev");
    15277         return false;
    15278     }
    15279 
    15280     return p4DiffScfileRowAlloc(p4b_id, skycell_id, tess_id, exp_tag, p3_version, uri, bg, bg_mean_stdev);
    15281 }
    15282 psArray *p4DiffScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
    15283 {
    15284     psArray         *rowSet;
    15285     psArray         *returnSet;
    15286     psU64           i;
    15287 
    15288     rowSet = psDBSelectRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, limit);
    15289     if (!rowSet) {
    15290         return NULL;
    15291     }
    15292 
    15293     // convert psMetadata rows to row objects
    15294 
    15295     returnSet = psArrayAllocEmpty(rowSet->n);
    15296 
    15297     for (i = 0; i < rowSet->n; i++) {
    15298         p4DiffScfileRow *object = p4DiffScfileObjectFromMetadata(rowSet->data[i]);
    15299         psArrayAdd(returnSet, 0, object);
    15300         psFree(object);
    15301     }
    15302 
    15303     psFree(rowSet);
    15304 
    15305     return returnSet;
    15306 }
    15307 bool p4DiffScfileDeleteObject(psDB *dbh, const p4DiffScfileRow *object)
    15308 {
    15309     psMetadata *where = p4DiffScfileMetadataFromObject(object);
    15310     long long count = psDBDeleteRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, 0);
    15311     psFree(where);
    15312     if (count < 0) {
    15313         psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4DiffScfile");
    15314         return false;
    15315     }
    15316     if (count > 1) {
    15317         // XXX should this be a psAbort() instead?  It is possible that
    15318         // having an object match multiple rows was by design.
    15319         psError(PS_ERR_UNKNOWN, true, "p4DiffScfileRow object matched more then one row.  Check your database schema");
    15320         return false;
    15321     }
    15322 
    15323     return true;
    15324 }
    15325 long long p4DiffScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
    15326 {
    15327     long long       deleted = 0;
    15328 
    15329     for (long long i = 0; i < objects->n; i++) {
    15330         p4DiffScfileRow *object = objects->data[i];
    15331         psMetadata *where = p4DiffScfileMetadataFromObject(object);
    15332         long long count = psDBDeleteRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, limit);
    15333         psFree(where);
    15334         if (count < 0) {
    15335             psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4DiffScfile");
    15336             return count;
    15337         }
    15338 
    15339         deleted += count;
    15340     }
    15341 
    15342     return deleted;
    15343 }
    15344 bool p4DiffScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)
    15345 {
    15346     PS_ASSERT_PTR_NON_NULL(objects, false);
    15347 
    15348     psMetadata *output = psMetadataAlloc();
    15349     for (long i = 0; i < psArrayLength(objects); i++) {
    15350         psMetadata *md = p4DiffScfileMetadataFromObject(objects->data[i]);
    15351         if (!psMetadataAddMetadata(
    15352             output,
    15353             PS_LIST_TAIL,
    15354             P4DIFFSCFILE_TABLE_NAME,
    15355             PS_META_DUPLICATE_OK,
    15356             NULL,
    15357             md
    15358         )) {
    15359             psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
    15360             psFree(md);
    15361             psFree(output);
    15362             return false;
    15363         }
    15364         psFree(md);
    15365     }
    15366 
    15367     if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
    15368         psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
    15369         psFree(output);
    15370     }
    15371     psFree(output);
    15372 
    15373     return true;
    15374 }
    15375 bool p4DiffScfilePrintObject(FILE *stream, p4DiffScfileRow *object, bool mdcf)
    15376 {
    15377     PS_ASSERT_PTR_NON_NULL(object, false);
    15378 
    15379     psMetadata *md = p4DiffScfileMetadataFromObject(object);
    15380 
    15381     if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
    15382         psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
    15383         psFree(md);
    15384     }
    15385 
    15386     psFree(md);
    15387 
    15388     return true;
    15389 }
    15390 static void p4MagicMaskImfileRowFree(p4MagicMaskImfileRow *object);
    15391 
    15392 p4MagicMaskImfileRow *p4MagicMaskImfileRowAlloc(psS32 p4c_id, const char *exp_tag, psS32 p3_version, const char *class_id, const char *uri)
    15393 {
    15394     p4MagicMaskImfileRow *_object;
    15395 
    15396     _object = psAlloc(sizeof(p4MagicMaskImfileRow));
    15397     psMemSetDeallocator(_object, (psFreeFunc)p4MagicMaskImfileRowFree);
    15398 
    15399     _object->p4c_id = p4c_id;
    15400     _object->exp_tag = psStringCopy(exp_tag);
    15401     _object->p3_version = p3_version;
    15402     _object->class_id = psStringCopy(class_id);
    15403     _object->uri = psStringCopy(uri);
    15404 
    15405     return _object;
    15406 }
    15407 
    15408 static void p4MagicMaskImfileRowFree(p4MagicMaskImfileRow *object)
    15409 {
    15410     psFree(object->exp_tag);
    15411     psFree(object->class_id);
    15412     psFree(object->uri);
    15413 }
    15414 
    15415 bool p4MagicMaskImfileCreateTable(psDB *dbh)
    15416 {
    15417     psMetadata *md = psMetadataAlloc();
    15418     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4c_id", PS_DATA_S32, "Primary Key", 0)) {
    15419         psError(PS_ERR_UNKNOWN, false, "failed to add item p4c_id");
    15420         psFree(md);
    15421         return false;
    15422     }
    15423     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) {
    15424         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    15425         psFree(md);
    15426         return false;
    15427     }
    15428     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) {
    15429         psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    15430         psFree(md);
    15431         return false;
    15432     }
    15433     if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) {
    15434         psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
    15435         psFree(md);
    15436         return false;
    15437     }
    15438     if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) {
    15439         psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
    15440         psFree(md);
    15441         return false;
    15442     }
    15443 
    15444     bool status = psDBCreateTable(dbh, P4MAGICMASKIMFILE_TABLE_NAME, md);
    15445 
    15446     psFree(md);
    15447 
    15448     return status;
    15449 }
    15450 
    15451 bool p4MagicMaskImfileDropTable(psDB *dbh)
    15452 {
    15453     return psDBDropTable(dbh, P4MAGICMASKIMFILE_TABLE_NAME);
    15454 }
    15455 
    15456 bool p4MagicMaskImfileInsert(psDB * dbh, psS32 p4c_id, const char *exp_tag, psS32 p3_version, const char *class_id, const char *uri)
    15457 {
    15458     psMetadata *md = psMetadataAlloc();
    15459     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4c_id", PS_DATA_S32, NULL, p4c_id)) {
    15460         psError(PS_ERR_UNKNOWN, false, "failed to add item p4c_id");
    15461         psFree(md);
    15462         return false;
    15463     }
    15464     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) {
    15465         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    15466         psFree(md);
    15467         return false;
    15468     }
    15469     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) {
    15470         psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    15471         psFree(md);
    15472         return false;
    15473     }
    15474     if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) {
    15475         psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
    15476         psFree(md);
    15477         return false;
    15478     }
    15479     if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) {
    15480         psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
    15481         psFree(md);
    15482         return false;
    15483     }
    15484 
    15485     bool status = psDBInsertOneRow(dbh, P4MAGICMASKIMFILE_TABLE_NAME, md);
    15486     psFree(md);
    15487 
    15488     return status;
    15489 }
    15490 
    15491 long long p4MagicMaskImfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
    15492 {
    15493     long long       deleted = 0;
    15494 
    15495     long long count = psDBDeleteRows(dbh, P4MAGICMASKIMFILE_TABLE_NAME, where, limit);
    15496     if (count < 0) {
    15497         psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4MagicMaskImfile");
    15498         return count;
    15499 
    15500         deleted += count;
    15501     }
    15502 
    15503     return deleted;
    15504 }
    15505 bool p4MagicMaskImfileInsertObject(psDB *dbh, p4MagicMaskImfileRow *object)
    15506 {
    15507     return p4MagicMaskImfileInsert(dbh, object->p4c_id, object->exp_tag, object->p3_version, object->class_id, object->uri);
    15508 }
    15509 
    15510 bool p4MagicMaskImfileInsertObjects(psDB *dbh, psArray *objects)
    15511 {
    15512     for (long i = 0; i < psArrayLength(objects); i++) {
    15513         if (!p4MagicMaskImfileInsertObject(dbh, objects->data[i])) {
    15514             return false;
    15515         }
    15516     }
    15517 
    15518     return true;
    15519 }
    15520 
    15521 bool p4MagicMaskImfileInsertFits(psDB *dbh, const psFits *fits)
    15522 {
    15523     psArray         *rowSet;
    15524 
    15525     // move to (the first?) extension named  P4MAGICMASKIMFILE_TABLE_NAME
    15526     if (!psFitsMoveExtName(fits, P4MAGICMASKIMFILE_TABLE_NAME)) {
    15527         psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4MAGICMASKIMFILE_TABLE_NAME);
    15528         return false;
    15529     }
    15530 
    15531     // check HDU type
    15532     if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
    15533         psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
    15534         return false;
    15535     }
    15536 
    15537     // read fits table
    15538     rowSet = psFitsReadTable(fits);
    15539     if (!rowSet) {
    15540         psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
    15541         psFree(rowSet);
    15542         return false;
    15543     }
    15544 
    15545     if (!psDBInsertRows(dbh, P4MAGICMASKIMFILE_TABLE_NAME, rowSet)) {
    15546         psError(PS_ERR_UNKNOWN, false, "databse insert failed");
    15547         psFree(rowSet);
    15548         return false;
    15549     }
    15550 
    15551     psFree(rowSet);
    15552 
    15553     return true;
    15554 }
    15555 
    15556 bool p4MagicMaskImfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
    15557 {
    15558     psArray         *rowSet;
    15559 
    15560     rowSet = psDBSelectRows(dbh, P4MAGICMASKIMFILE_TABLE_NAME, where, limit);
    15561     if (!rowSet) {
    15562         return false;
    15563     }
    15564 
    15565     // output to fits
    15566     if (!psFitsWriteTable(fits, NULL, rowSet, P4MAGICMASKIMFILE_TABLE_NAME)) {
    15567         psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
    15568         psFree(rowSet);
    15569         return false;
    15570     }
    15571 
    15572     psFree(rowSet);
    15573 
    15574     return true;
    15575 }
    15576 
    15577 psMetadata *p4MagicMaskImfileMetadataFromObject(const p4MagicMaskImfileRow *object)
    15578 {
    15579     psMetadata *md = psMetadataAlloc();
    15580     if (!psMetadataAdd(md, PS_LIST_TAIL, "p4c_id", PS_DATA_S32, NULL, object->p4c_id)) {
    15581         psError(PS_ERR_UNKNOWN, false, "failed to add item p4c_id");
    15582         psFree(md);
    15583         return false;
    15584     }
    15585     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) {
    15586         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    15587         psFree(md);
    15588         return false;
    15589     }
    15590     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) {
    15591         psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    15592         psFree(md);
    15593         return false;
    15594     }
    15595     if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) {
    15596         psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
    15597         psFree(md);
    15598         return false;
    15599     }
    15600     if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) {
    15601         psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
    15602         psFree(md);
    15603         return false;
    15604     }
    15605 
    15606 
    15607     return md;
    15608 }
    15609 
    15610 p4MagicMaskImfileRow *p4MagicMaskImfileObjectFromMetadata(psMetadata *md)
    15611 {
    15612 
    15613 bool status = false;
    15614     psS32 p4c_id = psMetadataLookupS32(&status, md, "p4c_id");
    15615     if (!status) {
    15616         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4c_id");
    15617         return false;
    15618     }
    15619     char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag");
    15620     if (!status) {
    15621         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag");
    15622         return false;
    15623     }
    15624     psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version");
    15625     if (!status) {
    15626         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version");
    15627         return false;
    15628     }
    15629     char* class_id = psMetadataLookupPtr(&status, md, "class_id");
    15630     if (!status) {
    15631         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id");
    15632         return false;
    15633     }
    15634     char* uri = psMetadataLookupPtr(&status, md, "uri");
    15635     if (!status) {
    15636         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri");
    15637         return false;
    15638     }
    15639 
    15640     return p4MagicMaskImfileRowAlloc(p4c_id, exp_tag, p3_version, class_id, uri);
    15641 }
    15642 psArray *p4MagicMaskImfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
    15643 {
    15644     psArray         *rowSet;
    15645     psArray         *returnSet;
    15646     psU64           i;
    15647 
    15648     rowSet = psDBSelectRows(dbh, P4MAGICMASKIMFILE_TABLE_NAME, where, limit);
    15649     if (!rowSet) {
    15650         return NULL;
    15651     }
    15652 
    15653     // convert psMetadata rows to row objects
    15654 
    15655     returnSet = psArrayAllocEmpty(rowSet->n);
    15656 
    15657     for (i = 0; i < rowSet->n; i++) {
    15658         p4MagicMaskImfileRow *object = p4MagicMaskImfileObjectFromMetadata(rowSet->data[i]);
    15659         psArrayAdd(returnSet, 0, object);
    15660         psFree(object);
    15661     }
    15662 
    15663     psFree(rowSet);
    15664 
    15665     return returnSet;
    15666 }
    15667 bool p4MagicMaskImfileDeleteObject(psDB *dbh, const p4MagicMaskImfileRow *object)
    15668 {
    15669     psMetadata *where = p4MagicMaskImfileMetadataFromObject(object);
    15670     long long count = psDBDeleteRows(dbh, P4MAGICMASKIMFILE_TABLE_NAME, where, 0);
    15671     psFree(where);
    15672     if (count < 0) {
    15673         psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4MagicMaskImfile");
    15674         return false;
    15675     }
    15676     if (count > 1) {
    15677         // XXX should this be a psAbort() instead?  It is possible that
    15678         // having an object match multiple rows was by design.
    15679         psError(PS_ERR_UNKNOWN, true, "p4MagicMaskImfileRow object matched more then one row.  Check your database schema");
    15680         return false;
    15681     }
    15682 
    15683     return true;
    15684 }
    15685 long long p4MagicMaskImfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
    15686 {
    15687     long long       deleted = 0;
    15688 
    15689     for (long long i = 0; i < objects->n; i++) {
    15690         p4MagicMaskImfileRow *object = objects->data[i];
    15691         psMetadata *where = p4MagicMaskImfileMetadataFromObject(object);
    15692         long long count = psDBDeleteRows(dbh, P4MAGICMASKIMFILE_TABLE_NAME, where, limit);
    15693         psFree(where);
    15694         if (count < 0) {
    15695             psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4MagicMaskImfile");
    15696             return count;
    15697         }
    15698 
    15699         deleted += count;
    15700     }
    15701 
    15702     return deleted;
    15703 }
    15704 bool p4MagicMaskImfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)
    15705 {
    15706     PS_ASSERT_PTR_NON_NULL(objects, false);
    15707 
    15708     psMetadata *output = psMetadataAlloc();
    15709     for (long i = 0; i < psArrayLength(objects); i++) {
    15710         psMetadata *md = p4MagicMaskImfileMetadataFromObject(objects->data[i]);
    15711         if (!psMetadataAddMetadata(
    15712             output,
    15713             PS_LIST_TAIL,
    15714             P4MAGICMASKIMFILE_TABLE_NAME,
    15715             PS_META_DUPLICATE_OK,
    15716             NULL,
    15717             md
    15718         )) {
    15719             psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
    15720             psFree(md);
    15721             psFree(output);
    15722             return false;
    15723         }
    15724         psFree(md);
    15725     }
    15726 
    15727     if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
    15728         psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
    15729         psFree(output);
    15730     }
    15731     psFree(output);
    15732 
    15733     return true;
    15734 }
    15735 bool p4MagicMaskImfilePrintObject(FILE *stream, p4MagicMaskImfileRow *object, bool mdcf)
    15736 {
    15737     PS_ASSERT_PTR_NON_NULL(object, false);
    15738 
    15739     psMetadata *md = p4MagicMaskImfileMetadataFromObject(object);
    15740 
    15741     if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
    15742         psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
    15743         psFree(md);
    15744     }
    15745 
    15746     psFree(md);
    15747 
    15748     return true;
    15749 }
    15750 static void skyCellRowFree(skyCellRow *object);
    15751 
    15752 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)
    15753 {
    15754     skyCellRow      *_object;
    15755 
    15756     _object = psAlloc(sizeof(skyCellRow));
    15757     psMemSetDeallocator(_object, (psFreeFunc)skyCellRowFree);
    15758 
    15759     _object->skycell_id = psStringCopy(skycell_id);
    15760     _object->tess_id = psStringCopy(tess_id);
    15761     _object->ra1 = ra1;
    15762     _object->decl1 = decl1;
    15763     _object->ra2 = ra2;
    15764     _object->decl2 = decl2;
    15765     _object->ra3 = ra3;
    15766     _object->decl3 = decl3;
    15767     _object->ra4 = ra4;
    15768     _object->decl4 = decl4;
    15769 
    15770     return _object;
    15771 }
    15772 
    15773 static void skyCellRowFree(skyCellRow *object)
    15774 {
    15775     psFree(object->skycell_id);
    15776     psFree(object->tess_id);
    15777 }
    15778 
    15779 bool skyCellCreateTable(psDB *dbh)
    15780 {
    15781     psMetadata *md = psMetadataAlloc();
    15782     if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {
    15783         psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
    15784         psFree(md);
    15785         return false;
    15786     }
    15787     if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {
    15788         psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
    15789         psFree(md);
    15790         return false;
    15791     }
    15792     if (!psMetadataAdd(md, PS_LIST_TAIL, "ra1", PS_DATA_F64, NULL, 0.0)) {
    15793         psError(PS_ERR_UNKNOWN, false, "failed to add item ra1");
    15794         psFree(md);
    15795         return false;
    15796     }
    15797     if (!psMetadataAdd(md, PS_LIST_TAIL, "decl1", PS_DATA_F64, NULL, 0.0)) {
    15798         psError(PS_ERR_UNKNOWN, false, "failed to add item decl1");
    15799         psFree(md);
    15800         return false;
    15801     }
    15802     if (!psMetadataAdd(md, PS_LIST_TAIL, "ra2", PS_DATA_F64, NULL, 0.0)) {
    15803         psError(PS_ERR_UNKNOWN, false, "failed to add item ra2");
    15804         psFree(md);
    15805         return false;
    15806     }
    15807     if (!psMetadataAdd(md, PS_LIST_TAIL, "decl2", PS_DATA_F64, NULL, 0.0)) {
    15808         psError(PS_ERR_UNKNOWN, false, "failed to add item decl2");
    15809         psFree(md);
    15810         return false;
    15811     }
    15812     if (!psMetadataAdd(md, PS_LIST_TAIL, "ra3", PS_DATA_F64, NULL, 0.0)) {
    15813         psError(PS_ERR_UNKNOWN, false, "failed to add item ra3");
    15814         psFree(md);
    15815         return false;
    15816     }
    15817     if (!psMetadataAdd(md, PS_LIST_TAIL, "decl3", PS_DATA_F64, NULL, 0.0)) {
    15818         psError(PS_ERR_UNKNOWN, false, "failed to add item decl3");
    15819         psFree(md);
    15820         return false;
    15821     }
    15822     if (!psMetadataAdd(md, PS_LIST_TAIL, "ra4", PS_DATA_F64, NULL, 0.0)) {
    15823         psError(PS_ERR_UNKNOWN, false, "failed to add item ra4");
    15824         psFree(md);
    15825         return false;
    15826     }
    15827     if (!psMetadataAdd(md, PS_LIST_TAIL, "decl4", PS_DATA_F64, NULL, 0.0)) {
    15828         psError(PS_ERR_UNKNOWN, false, "failed to add item decl4");
    15829         psFree(md);
    15830         return false;
    15831     }
    15832 
    15833     bool status = psDBCreateTable(dbh, SKYCELL_TABLE_NAME, md);
    15834 
    15835     psFree(md);
    15836 
    15837     return status;
    15838 }
    15839 
    15840 bool skyCellDropTable(psDB *dbh)
    15841 {
    15842     return psDBDropTable(dbh, SKYCELL_TABLE_NAME);
    15843 }
    15844 
    15845 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)
    15846 {
    15847     psMetadata *md = psMetadataAlloc();
    15848     if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {
    15849         psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
    15850         psFree(md);
    15851         return false;
    15852     }
    15853     if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {
    15854         psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
    15855         psFree(md);
    15856         return false;
    15857     }
    15858     if (!psMetadataAdd(md, PS_LIST_TAIL, "ra1", PS_DATA_F64, NULL, ra1)) {
    15859         psError(PS_ERR_UNKNOWN, false, "failed to add item ra1");
    15860         psFree(md);
    15861         return false;
    15862     }
    15863     if (!psMetadataAdd(md, PS_LIST_TAIL, "decl1", PS_DATA_F64, NULL, decl1)) {
    15864         psError(PS_ERR_UNKNOWN, false, "failed to add item decl1");
    15865         psFree(md);
    15866         return false;
    15867     }
    15868     if (!psMetadataAdd(md, PS_LIST_TAIL, "ra2", PS_DATA_F64, NULL, ra2)) {
    15869         psError(PS_ERR_UNKNOWN, false, "failed to add item ra2");
    15870         psFree(md);
    15871         return false;
    15872     }
    15873     if (!psMetadataAdd(md, PS_LIST_TAIL, "decl2", PS_DATA_F64, NULL, decl2)) {
    15874         psError(PS_ERR_UNKNOWN, false, "failed to add item decl2");
    15875         psFree(md);
    15876         return false;
    15877     }
    15878     if (!psMetadataAdd(md, PS_LIST_TAIL, "ra3", PS_DATA_F64, NULL, ra3)) {
    15879         psError(PS_ERR_UNKNOWN, false, "failed to add item ra3");
    15880         psFree(md);
    15881         return false;
    15882     }
    15883     if (!psMetadataAdd(md, PS_LIST_TAIL, "decl3", PS_DATA_F64, NULL, decl3)) {
    15884         psError(PS_ERR_UNKNOWN, false, "failed to add item decl3");
    15885         psFree(md);
    15886         return false;
    15887     }
    15888     if (!psMetadataAdd(md, PS_LIST_TAIL, "ra4", PS_DATA_F64, NULL, ra4)) {
    15889         psError(PS_ERR_UNKNOWN, false, "failed to add item ra4");
    15890         psFree(md);
    15891         return false;
    15892     }
    15893     if (!psMetadataAdd(md, PS_LIST_TAIL, "decl4", PS_DATA_F64, NULL, decl4)) {
    15894         psError(PS_ERR_UNKNOWN, false, "failed to add item decl4");
    15895         psFree(md);
    15896         return false;
    15897     }
    15898 
    15899     bool status = psDBInsertOneRow(dbh, SKYCELL_TABLE_NAME, md);
    15900     psFree(md);
    15901 
    15902     return status;
    15903 }
    15904 
    15905 long long skyCellDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
    15906 {
    15907     long long       deleted = 0;
    15908 
    15909     long long count = psDBDeleteRows(dbh, SKYCELL_TABLE_NAME, where, limit);
    15910     if (count < 0) {
    15911         psError(PS_ERR_UNKNOWN, true, "failed to delete row from skyCell");
    15912         return count;
    15913 
    15914         deleted += count;
    15915     }
    15916 
    15917     return deleted;
    15918 }
    15919 bool skyCellInsertObject(psDB *dbh, skyCellRow *object)
    15920 {
    15921     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);
    15922 }
    15923 
    15924 bool skyCellInsertObjects(psDB *dbh, psArray *objects)
    15925 {
    15926     for (long i = 0; i < psArrayLength(objects); i++) {
    15927         if (!skyCellInsertObject(dbh, objects->data[i])) {
    15928             return false;
    15929         }
    15930     }
    15931 
    15932     return true;
    15933 }
    15934 
    15935 bool skyCellInsertFits(psDB *dbh, const psFits *fits)
    15936 {
    15937     psArray         *rowSet;
    15938 
    15939     // move to (the first?) extension named  SKYCELL_TABLE_NAME
    15940     if (!psFitsMoveExtName(fits, SKYCELL_TABLE_NAME)) {
    15941         psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", SKYCELL_TABLE_NAME);
    15942         return false;
    15943     }
    15944 
    15945     // check HDU type
    15946     if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
    15947         psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
    15948         return false;
    15949     }
    15950 
    15951     // read fits table
    15952     rowSet = psFitsReadTable(fits);
    15953     if (!rowSet) {
    15954         psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
    15955         psFree(rowSet);
    15956         return false;
    15957     }
    15958 
    15959     if (!psDBInsertRows(dbh, SKYCELL_TABLE_NAME, rowSet)) {
    15960         psError(PS_ERR_UNKNOWN, false, "databse insert failed");
    15961         psFree(rowSet);
    15962         return false;
    15963     }
    15964 
    15965     psFree(rowSet);
    15966 
    15967     return true;
    15968 }
    15969 
    15970 bool skyCellSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
    15971 {
    15972     psArray         *rowSet;
    15973 
    15974     rowSet = psDBSelectRows(dbh, SKYCELL_TABLE_NAME, where, limit);
    15975     if (!rowSet) {
    15976         return false;
    15977     }
    15978 
    15979     // output to fits
    15980     if (!psFitsWriteTable(fits, NULL, rowSet, SKYCELL_TABLE_NAME)) {
    15981         psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
    15982         psFree(rowSet);
    15983         return false;
    15984     }
    15985 
    15986     psFree(rowSet);
    15987 
    15988     return true;
    15989 }
    15990 
    15991 psMetadata *skyCellMetadataFromObject(const skyCellRow *object)
    15992 {
    15993     psMetadata *md = psMetadataAlloc();
    15994     if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {
    15995         psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
    15996         psFree(md);
    15997         return false;
    15998     }
    15999     if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {
    16000         psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
    16001         psFree(md);
    16002         return false;
    16003     }
    16004     if (!psMetadataAdd(md, PS_LIST_TAIL, "ra1", PS_DATA_F64, NULL, object->ra1)) {
    16005         psError(PS_ERR_UNKNOWN, false, "failed to add item ra1");
    16006         psFree(md);
    16007         return false;
    16008     }
    16009     if (!psMetadataAdd(md, PS_LIST_TAIL, "decl1", PS_DATA_F64, NULL, object->decl1)) {
    16010         psError(PS_ERR_UNKNOWN, false, "failed to add item decl1");
    16011         psFree(md);
    16012         return false;
    16013     }
    16014     if (!psMetadataAdd(md, PS_LIST_TAIL, "ra2", PS_DATA_F64, NULL, object->ra2)) {
    16015         psError(PS_ERR_UNKNOWN, false, "failed to add item ra2");
    16016         psFree(md);
    16017         return false;
    16018     }
    16019     if (!psMetadataAdd(md, PS_LIST_TAIL, "decl2", PS_DATA_F64, NULL, object->decl2)) {
    16020         psError(PS_ERR_UNKNOWN, false, "failed to add item decl2");
    16021         psFree(md);
    16022         return false;
    16023     }
    16024     if (!psMetadataAdd(md, PS_LIST_TAIL, "ra3", PS_DATA_F64, NULL, object->ra3)) {
    16025         psError(PS_ERR_UNKNOWN, false, "failed to add item ra3");
    16026         psFree(md);
    16027         return false;
    16028     }
    16029     if (!psMetadataAdd(md, PS_LIST_TAIL, "decl3", PS_DATA_F64, NULL, object->decl3)) {
    16030         psError(PS_ERR_UNKNOWN, false, "failed to add item decl3");
    16031         psFree(md);
    16032         return false;
    16033     }
    16034     if (!psMetadataAdd(md, PS_LIST_TAIL, "ra4", PS_DATA_F64, NULL, object->ra4)) {
    16035         psError(PS_ERR_UNKNOWN, false, "failed to add item ra4");
    16036         psFree(md);
    16037         return false;
    16038     }
    16039     if (!psMetadataAdd(md, PS_LIST_TAIL, "decl4", PS_DATA_F64, NULL, object->decl4)) {
    16040         psError(PS_ERR_UNKNOWN, false, "failed to add item decl4");
    16041         psFree(md);
    16042         return false;
    16043     }
    16044 
    16045 
    16046     return md;
    16047 }
    16048 
    16049 skyCellRow *skyCellObjectFromMetadata(psMetadata *md)
    16050 {
    16051 
    16052 bool status = false;
    16053     char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");
    16054     if (!status) {
    16055         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");
    16056         return false;
    16057     }
    16058     char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");
    16059     if (!status) {
    16060         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");
    16061         return false;
    16062     }
    16063     psF64 ra1 = psMetadataLookupF64(&status, md, "ra1");
    16064     if (!status) {
    16065         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item ra1");
    16066         return false;
    16067     }
    16068     psF64 decl1 = psMetadataLookupF64(&status, md, "decl1");
    16069     if (!status) {
    16070         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item decl1");
    16071         return false;
    16072     }
    16073     psF64 ra2 = psMetadataLookupF64(&status, md, "ra2");
    16074     if (!status) {
    16075         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item ra2");
    16076         return false;
    16077     }
    16078     psF64 decl2 = psMetadataLookupF64(&status, md, "decl2");
    16079     if (!status) {
    16080         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item decl2");
    16081         return false;
    16082     }
    16083     psF64 ra3 = psMetadataLookupF64(&status, md, "ra3");
    16084     if (!status) {
    16085         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item ra3");
    16086         return false;
    16087     }
    16088     psF64 decl3 = psMetadataLookupF64(&status, md, "decl3");
    16089     if (!status) {
    16090         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item decl3");
    16091         return false;
    16092     }
    16093     psF64 ra4 = psMetadataLookupF64(&status, md, "ra4");
    16094     if (!status) {
    16095         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item ra4");
    16096         return false;
    16097     }
    16098     psF64 decl4 = psMetadataLookupF64(&status, md, "decl4");
    16099     if (!status) {
    16100         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item decl4");
    16101         return false;
    16102     }
    16103 
    16104     return skyCellRowAlloc(skycell_id, tess_id, ra1, decl1, ra2, decl2, ra3, decl3, ra4, decl4);
    16105 }
    16106 psArray *skyCellSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
    16107 {
    16108     psArray         *rowSet;
    16109     psArray         *returnSet;
    16110     psU64           i;
    16111 
    16112     rowSet = psDBSelectRows(dbh, SKYCELL_TABLE_NAME, where, limit);
    16113     if (!rowSet) {
    16114         return NULL;
    16115     }
    16116 
    16117     // convert psMetadata rows to row objects
    16118 
    16119     returnSet = psArrayAllocEmpty(rowSet->n);
    16120 
    16121     for (i = 0; i < rowSet->n; i++) {
    16122         skyCellRow *object = skyCellObjectFromMetadata(rowSet->data[i]);
    16123         psArrayAdd(returnSet, 0, object);
    16124         psFree(object);
    16125     }
    16126 
    16127     psFree(rowSet);
    16128 
    16129     return returnSet;
    16130 }
    16131 bool skyCellDeleteObject(psDB *dbh, const skyCellRow *object)
    16132 {
    16133     psMetadata *where = skyCellMetadataFromObject(object);
    16134     long long count = psDBDeleteRows(dbh, SKYCELL_TABLE_NAME, where, 0);
    16135     psFree(where);
    16136     if (count < 0) {
    16137         psError(PS_ERR_UNKNOWN, true, "failed to delete row from skyCell");
    16138         return false;
    16139     }
    16140     if (count > 1) {
    16141         // XXX should this be a psAbort() instead?  It is possible that
    16142         // having an object match multiple rows was by design.
    16143         psError(PS_ERR_UNKNOWN, true, "skyCellRow object matched more then one row.  Check your database schema");
    16144         return false;
    16145     }
    16146 
    16147     return true;
    16148 }
    16149 long long skyCellDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
    16150 {
    16151     long long       deleted = 0;
    16152 
    16153     for (long long i = 0; i < objects->n; i++) {
    16154         skyCellRow *object = objects->data[i];
    16155         psMetadata *where = skyCellMetadataFromObject(object);
    16156         long long count = psDBDeleteRows(dbh, SKYCELL_TABLE_NAME, where, limit);
    16157         psFree(where);
    16158         if (count < 0) {
    16159             psError(PS_ERR_UNKNOWN, true, "failed to delete row from skyCell");
    16160             return count;
    16161         }
    16162 
    16163         deleted += count;
    16164     }
    16165 
    16166     return deleted;
    16167 }
    16168 bool skyCellPrintObjects(FILE *stream, psArray *objects, bool mdcf)
    16169 {
    16170     PS_ASSERT_PTR_NON_NULL(objects, false);
    16171 
    16172     psMetadata *output = psMetadataAlloc();
    16173     for (long i = 0; i < psArrayLength(objects); i++) {
    16174         psMetadata *md = skyCellMetadataFromObject(objects->data[i]);
    16175         if (!psMetadataAddMetadata(
    16176             output,
    16177             PS_LIST_TAIL,
    16178             SKYCELL_TABLE_NAME,
    16179             PS_META_DUPLICATE_OK,
    16180             NULL,
    16181             md
    16182         )) {
    16183             psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
    16184             psFree(md);
    16185             psFree(output);
    16186             return false;
    16187         }
    16188         psFree(md);
    16189     }
    16190 
    16191     if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
    16192         psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
    16193         psFree(output);
    16194     }
    16195     psFree(output);
    16196 
    16197     return true;
    16198 }
    16199 bool skyCellPrintObject(FILE *stream, skyCellRow *object, bool mdcf)
    16200 {
    16201     PS_ASSERT_PTR_NON_NULL(object, false);
    16202 
    16203     psMetadata *md = skyCellMetadataFromObject(object);
    16204 
    16205     if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
    16206         psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
    16207         psFree(md);
    16208     }
    16209 
    16210     psFree(md);
    16211 
    16212     return true;
    16213 }
    16214 static void skyCellMapRowFree(skyCellMapRow *object);
    16215 
    16216 skyCellMapRow *skyCellMapRowAlloc(const char *skycell_id, const char *tess_id, const char *exp_tag, const char *class_id)
    16217 {
    16218     skyCellMapRow   *_object;
    16219 
    16220     _object = psAlloc(sizeof(skyCellMapRow));
    16221     psMemSetDeallocator(_object, (psFreeFunc)skyCellMapRowFree);
    16222 
    16223     _object->skycell_id = psStringCopy(skycell_id);
    16224     _object->tess_id = psStringCopy(tess_id);
    16225     _object->exp_tag = psStringCopy(exp_tag);
    16226     _object->class_id = psStringCopy(class_id);
    16227 
    16228     return _object;
    16229 }
    16230 
    16231 static void skyCellMapRowFree(skyCellMapRow *object)
    16232 {
    16233     psFree(object->skycell_id);
    16234     psFree(object->tess_id);
    16235     psFree(object->exp_tag);
    16236     psFree(object->class_id);
    16237 }
    16238 
    16239 bool skyCellMapCreateTable(psDB *dbh)
    16240 {
    16241     psMetadata *md = psMetadataAlloc();
    16242     if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {
    16243         psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
    16244         psFree(md);
    16245         return false;
    16246     }
    16247     if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {
    16248         psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
    16249         psFree(md);
    16250         return false;
    16251     }
    16252     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) {
    16253         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    16254         psFree(md);
    16255         return false;
    16256     }
    16257     if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) {
    16258         psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
    16259         psFree(md);
    16260         return false;
    16261     }
    16262 
    16263     bool status = psDBCreateTable(dbh, SKYCELLMAP_TABLE_NAME, md);
    16264 
    16265     psFree(md);
    16266 
    16267     return status;
    16268 }
    16269 
    16270 bool skyCellMapDropTable(psDB *dbh)
    16271 {
    16272     return psDBDropTable(dbh, SKYCELLMAP_TABLE_NAME);
    16273 }
    16274 
    16275 bool skyCellMapInsert(psDB * dbh, const char *skycell_id, const char *tess_id, const char *exp_tag, const char *class_id)
    16276 {
    16277     psMetadata *md = psMetadataAlloc();
    16278     if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {
    16279         psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
    16280         psFree(md);
    16281         return false;
    16282     }
    16283     if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {
    16284         psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
    16285         psFree(md);
    16286         return false;
    16287     }
    16288     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) {
    16289         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    16290         psFree(md);
    16291         return false;
    16292     }
    16293     if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) {
    16294         psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
    16295         psFree(md);
    16296         return false;
    16297     }
    16298 
    16299     bool status = psDBInsertOneRow(dbh, SKYCELLMAP_TABLE_NAME, md);
    16300     psFree(md);
    16301 
    16302     return status;
    16303 }
    16304 
    16305 long long skyCellMapDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
    16306 {
    16307     long long       deleted = 0;
    16308 
    16309     long long count = psDBDeleteRows(dbh, SKYCELLMAP_TABLE_NAME, where, limit);
    16310     if (count < 0) {
    16311         psError(PS_ERR_UNKNOWN, true, "failed to delete row from skyCellMap");
    16312         return count;
    16313 
    16314         deleted += count;
    16315     }
    16316 
    16317     return deleted;
    16318 }
    16319 bool skyCellMapInsertObject(psDB *dbh, skyCellMapRow *object)
    16320 {
    16321     return skyCellMapInsert(dbh, object->skycell_id, object->tess_id, object->exp_tag, object->class_id);
    16322 }
    16323 
    16324 bool skyCellMapInsertObjects(psDB *dbh, psArray *objects)
    16325 {
    16326     for (long i = 0; i < psArrayLength(objects); i++) {
    16327         if (!skyCellMapInsertObject(dbh, objects->data[i])) {
    16328             return false;
    16329         }
    16330     }
    16331 
    16332     return true;
    16333 }
    16334 
    16335 bool skyCellMapInsertFits(psDB *dbh, const psFits *fits)
    16336 {
    16337     psArray         *rowSet;
    16338 
    16339     // move to (the first?) extension named  SKYCELLMAP_TABLE_NAME
    16340     if (!psFitsMoveExtName(fits, SKYCELLMAP_TABLE_NAME)) {
    16341         psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", SKYCELLMAP_TABLE_NAME);
    16342         return false;
    16343     }
    16344 
    16345     // check HDU type
    16346     if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
    16347         psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
    16348         return false;
    16349     }
    16350 
    16351     // read fits table
    16352     rowSet = psFitsReadTable(fits);
    16353     if (!rowSet) {
    16354         psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
    16355         psFree(rowSet);
    16356         return false;
    16357     }
    16358 
    16359     if (!psDBInsertRows(dbh, SKYCELLMAP_TABLE_NAME, rowSet)) {
    16360         psError(PS_ERR_UNKNOWN, false, "databse insert failed");
    16361         psFree(rowSet);
    16362         return false;
    16363     }
    16364 
    16365     psFree(rowSet);
    16366 
    16367     return true;
    16368 }
    16369 
    16370 bool skyCellMapSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
    16371 {
    16372     psArray         *rowSet;
    16373 
    16374     rowSet = psDBSelectRows(dbh, SKYCELLMAP_TABLE_NAME, where, limit);
    16375     if (!rowSet) {
    16376         return false;
    16377     }
    16378 
    16379     // output to fits
    16380     if (!psFitsWriteTable(fits, NULL, rowSet, SKYCELLMAP_TABLE_NAME)) {
    16381         psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
    16382         psFree(rowSet);
    16383         return false;
    16384     }
    16385 
    16386     psFree(rowSet);
    16387 
    16388     return true;
    16389 }
    16390 
    16391 psMetadata *skyCellMapMetadataFromObject(const skyCellMapRow *object)
    16392 {
    16393     psMetadata *md = psMetadataAlloc();
    16394     if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {
    16395         psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
    16396         psFree(md);
    16397         return false;
    16398     }
    16399     if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {
    16400         psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
    16401         psFree(md);
    16402         return false;
    16403     }
    16404     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) {
    16405         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    16406         psFree(md);
    16407         return false;
    16408     }
    16409     if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) {
    16410         psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
    16411         psFree(md);
    16412         return false;
    16413     }
    16414 
    16415 
    16416     return md;
    16417 }
    16418 
    16419 skyCellMapRow *skyCellMapObjectFromMetadata(psMetadata *md)
    16420 {
    16421 
    16422 bool status = false;
    16423     char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");
    16424     if (!status) {
    16425         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");
    16426         return false;
    16427     }
    16428     char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");
    16429     if (!status) {
    16430         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");
    16431         return false;
    16432     }
    16433     char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag");
    16434     if (!status) {
    16435         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag");
    16436         return false;
    16437     }
    16438     char* class_id = psMetadataLookupPtr(&status, md, "class_id");
    16439     if (!status) {
    16440         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id");
    16441         return false;
    16442     }
    16443 
    16444     return skyCellMapRowAlloc(skycell_id, tess_id, exp_tag, class_id);
    16445 }
    16446 psArray *skyCellMapSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
    16447 {
    16448     psArray         *rowSet;
    16449     psArray         *returnSet;
    16450     psU64           i;
    16451 
    16452     rowSet = psDBSelectRows(dbh, SKYCELLMAP_TABLE_NAME, where, limit);
    16453     if (!rowSet) {
    16454         return NULL;
    16455     }
    16456 
    16457     // convert psMetadata rows to row objects
    16458 
    16459     returnSet = psArrayAllocEmpty(rowSet->n);
    16460 
    16461     for (i = 0; i < rowSet->n; i++) {
    16462         skyCellMapRow *object = skyCellMapObjectFromMetadata(rowSet->data[i]);
    16463         psArrayAdd(returnSet, 0, object);
    16464         psFree(object);
    16465     }
    16466 
    16467     psFree(rowSet);
    16468 
    16469     return returnSet;
    16470 }
    16471 bool skyCellMapDeleteObject(psDB *dbh, const skyCellMapRow *object)
    16472 {
    16473     psMetadata *where = skyCellMapMetadataFromObject(object);
    16474     long long count = psDBDeleteRows(dbh, SKYCELLMAP_TABLE_NAME, where, 0);
    16475     psFree(where);
    16476     if (count < 0) {
    16477         psError(PS_ERR_UNKNOWN, true, "failed to delete row from skyCellMap");
    16478         return false;
    16479     }
    16480     if (count > 1) {
    16481         // XXX should this be a psAbort() instead?  It is possible that
    16482         // having an object match multiple rows was by design.
    16483         psError(PS_ERR_UNKNOWN, true, "skyCellMapRow object matched more then one row.  Check your database schema");
    16484         return false;
    16485     }
    16486 
    16487     return true;
    16488 }
    16489 long long skyCellMapDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
    16490 {
    16491     long long       deleted = 0;
    16492 
    16493     for (long long i = 0; i < objects->n; i++) {
    16494         skyCellMapRow *object = objects->data[i];
    16495         psMetadata *where = skyCellMapMetadataFromObject(object);
    16496         long long count = psDBDeleteRows(dbh, SKYCELLMAP_TABLE_NAME, where, limit);
    16497         psFree(where);
    16498         if (count < 0) {
    16499             psError(PS_ERR_UNKNOWN, true, "failed to delete row from skyCellMap");
    16500             return count;
    16501         }
    16502 
    16503         deleted += count;
    16504     }
    16505 
    16506     return deleted;
    16507 }
    16508 bool skyCellMapPrintObjects(FILE *stream, psArray *objects, bool mdcf)
    16509 {
    16510     PS_ASSERT_PTR_NON_NULL(objects, false);
    16511 
    16512     psMetadata *output = psMetadataAlloc();
    16513     for (long i = 0; i < psArrayLength(objects); i++) {
    16514         psMetadata *md = skyCellMapMetadataFromObject(objects->data[i]);
    16515         if (!psMetadataAddMetadata(
    16516             output,
    16517             PS_LIST_TAIL,
    16518             SKYCELLMAP_TABLE_NAME,
    16519             PS_META_DUPLICATE_OK,
    16520             NULL,
    16521             md
    16522         )) {
    16523             psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
    16524             psFree(md);
    16525             psFree(output);
    16526             return false;
    16527         }
    16528         psFree(md);
    16529     }
    16530 
    16531     if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
    16532         psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
    16533         psFree(output);
    16534     }
    16535     psFree(output);
    16536 
    16537     return true;
    16538 }
    16539 bool skyCellMapPrintObject(FILE *stream, skyCellMapRow *object, bool mdcf)
    16540 {
    16541     PS_ASSERT_PTR_NON_NULL(object, false);
    16542 
    16543     psMetadata *md = skyCellMapMetadataFromObject(object);
    16544 
    16545     if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
    16546         psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
    16547         psFree(md);
    16548     }
    16549 
    16550     psFree(md);
    16551 
    16552     return true;
    16553 }
  • trunk/ippdb/src/ippdb.h

    r11733 r11780  
    68366836
    68376837typedef struct {
    6838     psS32           p4a_id;
     6838    psS32           p4_id;
    68396839    char            *mode;
    68406840    char            *state;
     
    68496849
    68506850p4RunRow *p4RunRowAlloc(
    6851     psS32           p4a_id,
     6851    psS32           p4_id,
    68526852    const char      *mode,
    68536853    const char      *state,
     
    68836883bool p4RunInsert(
    68846884    psDB            *dbh,               ///< Database handle
    6885     psS32           p4a_id,
     6885    psS32           p4_id,
    68866886    const char      *mode,
    68876887    const char      *state,
     
    70437043
    70447044typedef struct {
    7045     psS32           p4a_id;
     7045    psS32           p4_id;
    70467046    char            *exp_tag;
    70477047    psS32           p3_version;
     
    70557055
    70567056p4InputExpRow *p4InputExpRowAlloc(
    7057     psS32           p4a_id,
     7057    psS32           p4_id,
    70587058    const char      *exp_tag,
    70597059    psS32           p3_version,
     
    70887088bool p4InputExpInsert(
    70897089    psDB            *dbh,               ///< Database handle
    7090     psS32           p4a_id,
     7090    psS32           p4_id,
    70917091    const char      *exp_tag,
    70927092    psS32           p3_version,
     
    72417241    bool            mdcf                ///< format as mdconfig or simple
    72427242);
     7243/** p4SkyCellMapRow data structure
     7244 *
     7245 * Structure for representing a single row of p4SkyCellMap table data.
     7246 */
     7247
     7248typedef struct {
     7249    psS32           p4_id;
     7250    char            *skycell_id;
     7251    char            *tess_id;
     7252    char            *exp_tag;
     7253    psS32           p3_version;
     7254    char            *class_id;
     7255} p4SkyCellMapRow;
     7256
     7257/** Creates a new p4SkyCellMapRow object
     7258 *
     7259 *  @return A new p4SkyCellMapRow object or NULL on failure.
     7260 */
     7261
     7262p4SkyCellMapRow *p4SkyCellMapRowAlloc(
     7263    psS32           p4_id,
     7264    const char      *skycell_id,
     7265    const char      *tess_id,
     7266    const char      *exp_tag,
     7267    psS32           p3_version,
     7268    const char      *class_id
     7269);
     7270
     7271/** Creates a new p4SkyCellMap table
     7272 *
     7273 * @return true on success
     7274 */
     7275
     7276bool p4SkyCellMapCreateTable(
     7277    psDB            *dbh                ///< Database handle
     7278);
     7279
     7280/** Deletes a p4SkyCellMap table
     7281 *
     7282 * @return true on success
     7283 */
     7284
     7285bool p4SkyCellMapDropTable(
     7286    psDB            *dbh                ///< Database handle
     7287);
     7288
     7289/** Insert a single row into a table
     7290 *
     7291 * This function constructs and inserts a single row based on it's parameters.
     7292 *
     7293 * @return true on success
     7294 */
     7295
     7296bool p4SkyCellMapInsert(
     7297    psDB            *dbh,               ///< Database handle
     7298    psS32           p4_id,
     7299    const char      *skycell_id,
     7300    const char      *tess_id,
     7301    const char      *exp_tag,
     7302    psS32           p3_version,
     7303    const char      *class_id
     7304);
     7305
     7306/** Deletes up to limit rows from the database and returns the number of rows actually deleted.
     7307 *
     7308 * @return A The number of rows removed or a negative value on error
     7309 */
     7310
     7311long long p4SkyCellMapDelete(
     7312    psDB            *dbh,               ///< Database handle
     7313    const psMetadata *where,            ///< Row match criteria
     7314    unsigned long long limit            ///< Maximum number of elements to delete
     7315);
     7316
     7317/** Insert a single p4SkyCellMapRow object into a table
     7318 *
     7319 * This function constructs and inserts a single row based on it's parameters.
     7320 *
     7321 * @return true on success
     7322 */
     7323
     7324bool p4SkyCellMapInsertObject(
     7325    psDB            *dbh,               ///< Database handle
     7326    p4SkyCellMapRow *object             ///< p4SkyCellMapRow object
     7327);
     7328
     7329/** Insert an array of p4SkyCellMapRow object into a table
     7330 *
     7331 * This function constructs and inserts multiple rows based on it's parameters.
     7332 *
     7333 * @return true on success
     7334 */
     7335
     7336bool p4SkyCellMapInsertObjects(
     7337    psDB            *dbh,               ///< Database handle
     7338    psArray         *objects            ///< array of p4SkyCellMapRow objects
     7339);
     7340
     7341/** Insert data from a binary FITS table p4SkyCellMapRow into the database
     7342 *
     7343 * This function expects a psFits object with a FITS table as the first
     7344 * extension.  The table must have at least one row of data in it, that is of
     7345 * the appropriate format (number of columns and their type).  All other
     7346 * extensions are ignored.
     7347 *
     7348 * @return true on success
     7349 */
     7350
     7351bool p4SkyCellMapInsertFits(
     7352    psDB            *dbh,               ///< Database handle
     7353    const psFits    *fits               ///< psFits object
     7354);
     7355
     7356/** Selects up to limit from the database and returns them in a binary FITS table
     7357 *
     7358 * This function assumes an empty psFits object and will create a FITS table
     7359 * as the first extension.
     7360 *
     7361 *  See psDBSelectRows() for documentation on the format of where.
     7362 *
     7363 * @return true on success
     7364 */
     7365
     7366bool p4SkyCellMapSelectRowsFits(
     7367    psDB            *dbh,               ///< Database handle
     7368    psFits          *fits,              ///< psFits object
     7369    const psMetadata *where,            ///< Row match criteria
     7370    unsigned long long limit            ///< Maximum number of elements to return
     7371);
     7372
     7373/** Convert a p4SkyCellMapRow into an equivalent psMetadata
     7374 *
     7375 * @return A psMetadata pointer or NULL on error
     7376 */
     7377
     7378psMetadata *p4SkyCellMapMetadataFromObject(
     7379    const p4SkyCellMapRow *object             ///< fooRow to convert into a psMetadata
     7380);
     7381
     7382/** Convert a psMetadata into an equivalent fooRow
     7383 *
     7384 * @return A p4SkyCellMapRow pointer or NULL on error
     7385 */
     7386
     7387p4SkyCellMapRow *p4SkyCellMapObjectFromMetadata(
     7388    psMetadata      *md                 ///< psMetadata to convert into a fooRow
     7389);
     7390/** Selects up to limit rows from the database and returns as p4SkyCellMapRow objects in a psArray
     7391 *
     7392 *  See psDBSelectRows() for documentation on the format of where.
     7393 *
     7394 * @return A psArray pointer or NULL on error
     7395 */
     7396
     7397psArray *p4SkyCellMapSelectRowObjects(
     7398    psDB            *dbh,               ///< Database handle
     7399    const psMetadata *where,            ///< Row match criteria
     7400    unsigned long long limit            ///< Maximum number of elements to return
     7401);
     7402/** Deletes a row from the database coresponding to an p4SkyCellMap
     7403 *
     7404 *  Note that a 'where' search psMetadata is constructed from each object and
     7405 *  used to find rows to delete.
     7406 *
     7407 * @return A The number of rows removed or a negative value on error
     7408 */
     7409
     7410bool p4SkyCellMapDeleteObject(
     7411    psDB            *dbh,               ///< Database handle
     7412    const p4SkyCellMapRow *object    ///< Object to delete
     7413);
     7414/** Deletes up to limit rows from the database and returns the number of rows actually deleted.
     7415 *
     7416 *  Note that a 'where' search psMetadata is constructed from each object and
     7417 *  used to find rows to delete.
     7418 *
     7419 * @return A The number of rows removed or a negative value on error
     7420 */
     7421
     7422long long p4SkyCellMapDeleteRowObjects(
     7423    psDB            *dbh,               ///< Database handle
     7424    const psArray   *objects,           ///< Array of objects to delete
     7425    unsigned long long limit            ///< Maximum number of elements to delete
     7426);
     7427/** Formats and prints an array of p4SkyCellMapRow objects
     7428 *
     7429 * When mdcf is set the formated output is in psMetadataConfig
     7430 * format, otherwise it is in a simple tabular format.
     7431 *
     7432 * @return true on success
     7433 */
     7434
     7435bool p4SkyCellMapPrintObjects(
     7436    FILE            *stream,            ///< a stream
     7437    psArray         *objects,           ///< An array of p4SkyCellMapRow objects
     7438    bool            mdcf                ///< format as mdconfig or simple
     7439);
     7440/** Formats and prints an p4SkyCellMapRow object
     7441 *
     7442 * When mdcf is set the formated output is in psMetadataConfig
     7443 * format, otherwise it is in a simple tabular format.
     7444 *
     7445 * @return true on success
     7446 */
     7447
     7448bool p4SkyCellMapPrintObject(
     7449    FILE            *stream,            ///< a stream
     7450    p4SkyCellMapRow *object,    ///< an p4SkyCellMapRow object
     7451    bool            mdcf                ///< format as mdconfig or simple
     7452);
    72437453/** p4ScfileRow data structure
    72447454 *
     
    72477457
    72487458typedef struct {
    7249     psS32           p4a_id;
     7459    psS32           p4_id;
    72507460    char            *skycell_id;
    72517461    char            *tess_id;
     
    72637473
    72647474p4ScfileRow *p4ScfileRowAlloc(
    7265     psS32           p4a_id,
     7475    psS32           p4_id,
    72667476    const char      *skycell_id,
    72677477    const char      *tess_id,
     
    73007510bool p4ScfileInsert(
    73017511    psDB            *dbh,               ///< Database handle
    7302     psS32           p4a_id,
     7512    psS32           p4_id,
    73037513    const char      *skycell_id,
    73047514    const char      *tess_id,
     
    74577667    bool            mdcf                ///< format as mdconfig or simple
    74587668);
    7459 /** p4InputScfileRow data structure
    7460  *
    7461  * Structure for representing a single row of p4InputScfile table data.
    7462  */
    7463 
    7464 typedef struct {
    7465     psS32           p4b_id;
    7466     char            *skycell_id;
    7467     char            *tess_id;
    7468     char            *exp_tag;
    7469     psS32           p3_version;
    7470     char            *kind;
    7471 } p4InputScfileRow;
    7472 
    7473 /** Creates a new p4InputScfileRow object
    7474  *
    7475  *  @return A new p4InputScfileRow object or NULL on failure.
    7476  */
    7477 
    7478 p4InputScfileRow *p4InputScfileRowAlloc(
    7479     psS32           p4b_id,
    7480     const char      *skycell_id,
    7481     const char      *tess_id,
    7482     const char      *exp_tag,
    7483     psS32           p3_version,
    7484     const char      *kind
    7485 );
    7486 
    7487 /** Creates a new p4InputScfile table
    7488  *
    7489  * @return true on success
    7490  */
    7491 
    7492 bool p4InputScfileCreateTable(
    7493     psDB            *dbh                ///< Database handle
    7494 );
    7495 
    7496 /** Deletes a p4InputScfile table
    7497  *
    7498  * @return true on success
    7499  */
    7500 
    7501 bool p4InputScfileDropTable(
    7502     psDB            *dbh                ///< Database handle
    7503 );
    7504 
    7505 /** Insert a single row into a table
    7506  *
    7507  * This function constructs and inserts a single row based on it's parameters.
    7508  *
    7509  * @return true on success
    7510  */
    7511 
    7512 bool p4InputScfileInsert(
    7513     psDB            *dbh,               ///< Database handle
    7514     psS32           p4b_id,
    7515     const char      *skycell_id,
    7516     const char      *tess_id,
    7517     const char      *exp_tag,
    7518     psS32           p3_version,
    7519     const char      *kind
    7520 );
    7521 
    7522 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.
    7523  *
    7524  * @return A The number of rows removed or a negative value on error
    7525  */
    7526 
    7527 long long p4InputScfileDelete(
    7528     psDB            *dbh,               ///< Database handle
    7529     const psMetadata *where,            ///< Row match criteria
    7530     unsigned long long limit            ///< Maximum number of elements to delete
    7531 );
    7532 
    7533 /** Insert a single p4InputScfileRow object into a table
    7534  *
    7535  * This function constructs and inserts a single row based on it's parameters.
    7536  *
    7537  * @return true on success
    7538  */
    7539 
    7540 bool p4InputScfileInsertObject(
    7541     psDB            *dbh,               ///< Database handle
    7542     p4InputScfileRow *object             ///< p4InputScfileRow object
    7543 );
    7544 
    7545 /** Insert an array of p4InputScfileRow object into a table
    7546  *
    7547  * This function constructs and inserts multiple rows based on it's parameters.
    7548  *
    7549  * @return true on success
    7550  */
    7551 
    7552 bool p4InputScfileInsertObjects(
    7553     psDB            *dbh,               ///< Database handle
    7554     psArray         *objects            ///< array of p4InputScfileRow objects
    7555 );
    7556 
    7557 /** Insert data from a binary FITS table p4InputScfileRow into the database
    7558  *
    7559  * This function expects a psFits object with a FITS table as the first
    7560  * extension.  The table must have at least one row of data in it, that is of
    7561  * the appropriate format (number of columns and their type).  All other
    7562  * extensions are ignored.
    7563  *
    7564  * @return true on success
    7565  */
    7566 
    7567 bool p4InputScfileInsertFits(
    7568     psDB            *dbh,               ///< Database handle
    7569     const psFits    *fits               ///< psFits object
    7570 );
    7571 
    7572 /** Selects up to limit from the database and returns them in a binary FITS table
    7573  *
    7574  * This function assumes an empty psFits object and will create a FITS table
    7575  * as the first extension.
    7576  *
    7577  *  See psDBSelectRows() for documentation on the format of where.
    7578  *
    7579  * @return true on success
    7580  */
    7581 
    7582 bool p4InputScfileSelectRowsFits(
    7583     psDB            *dbh,               ///< Database handle
    7584     psFits          *fits,              ///< psFits object
    7585     const psMetadata *where,            ///< Row match criteria
    7586     unsigned long long limit            ///< Maximum number of elements to return
    7587 );
    7588 
    7589 /** Convert a p4InputScfileRow into an equivalent psMetadata
    7590  *
    7591  * @return A psMetadata pointer or NULL on error
    7592  */
    7593 
    7594 psMetadata *p4InputScfileMetadataFromObject(
    7595     const p4InputScfileRow *object             ///< fooRow to convert into a psMetadata
    7596 );
    7597 
    7598 /** Convert a psMetadata into an equivalent fooRow
    7599  *
    7600  * @return A p4InputScfileRow pointer or NULL on error
    7601  */
    7602 
    7603 p4InputScfileRow *p4InputScfileObjectFromMetadata(
    7604     psMetadata      *md                 ///< psMetadata to convert into a fooRow
    7605 );
    7606 /** Selects up to limit rows from the database and returns as p4InputScfileRow objects in a psArray
    7607  *
    7608  *  See psDBSelectRows() for documentation on the format of where.
    7609  *
    7610  * @return A psArray pointer or NULL on error
    7611  */
    7612 
    7613 psArray *p4InputScfileSelectRowObjects(
    7614     psDB            *dbh,               ///< Database handle
    7615     const psMetadata *where,            ///< Row match criteria
    7616     unsigned long long limit            ///< Maximum number of elements to return
    7617 );
    7618 /** Deletes a row from the database coresponding to an p4InputScfile
    7619  *
    7620  *  Note that a 'where' search psMetadata is constructed from each object and
    7621  *  used to find rows to delete.
    7622  *
    7623  * @return A The number of rows removed or a negative value on error
    7624  */
    7625 
    7626 bool p4InputScfileDeleteObject(
    7627     psDB            *dbh,               ///< Database handle
    7628     const p4InputScfileRow *object    ///< Object to delete
    7629 );
    7630 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.
    7631  *
    7632  *  Note that a 'where' search psMetadata is constructed from each object and
    7633  *  used to find rows to delete.
    7634  *
    7635  * @return A The number of rows removed or a negative value on error
    7636  */
    7637 
    7638 long long p4InputScfileDeleteRowObjects(
    7639     psDB            *dbh,               ///< Database handle
    7640     const psArray   *objects,           ///< Array of objects to delete
    7641     unsigned long long limit            ///< Maximum number of elements to delete
    7642 );
    7643 /** Formats and prints an array of p4InputScfileRow objects
    7644  *
    7645  * When mdcf is set the formated output is in psMetadataConfig
    7646  * format, otherwise it is in a simple tabular format.
    7647  *
    7648  * @return true on success
    7649  */
    7650 
    7651 bool p4InputScfilePrintObjects(
    7652     FILE            *stream,            ///< a stream
    7653     psArray         *objects,           ///< An array of p4InputScfileRow objects
    7654     bool            mdcf                ///< format as mdconfig or simple
    7655 );
    7656 /** Formats and prints an p4InputScfileRow object
    7657  *
    7658  * When mdcf is set the formated output is in psMetadataConfig
    7659  * format, otherwise it is in a simple tabular format.
    7660  *
    7661  * @return true on success
    7662  */
    7663 
    7664 bool p4InputScfilePrintObject(
    7665     FILE            *stream,            ///< a stream
    7666     p4InputScfileRow *object,    ///< an p4InputScfileRow object
    7667     bool            mdcf                ///< format as mdconfig or simple
    7668 );
    7669 /** p4DiffScfileRow data structure
    7670  *
    7671  * Structure for representing a single row of p4DiffScfile table data.
    7672  */
    7673 
    7674 typedef struct {
    7675     psS32           p4b_id;
    7676     char            *skycell_id;
    7677     char            *tess_id;
    7678     char            *exp_tag;
    7679     psS32           p3_version;
    7680     char            *uri;
    7681     psF64           bg;
    7682     psF64           bg_mean_stdev;
    7683 } p4DiffScfileRow;
    7684 
    7685 /** Creates a new p4DiffScfileRow object
    7686  *
    7687  *  @return A new p4DiffScfileRow object or NULL on failure.
    7688  */
    7689 
    7690 p4DiffScfileRow *p4DiffScfileRowAlloc(
    7691     psS32           p4b_id,
    7692     const char      *skycell_id,
    7693     const char      *tess_id,
    7694     const char      *exp_tag,
    7695     psS32           p3_version,
    7696     const char      *uri,
    7697     psF64           bg,
    7698     psF64           bg_mean_stdev
    7699 );
    7700 
    7701 /** Creates a new p4DiffScfile table
    7702  *
    7703  * @return true on success
    7704  */
    7705 
    7706 bool p4DiffScfileCreateTable(
    7707     psDB            *dbh                ///< Database handle
    7708 );
    7709 
    7710 /** Deletes a p4DiffScfile table
    7711  *
    7712  * @return true on success
    7713  */
    7714 
    7715 bool p4DiffScfileDropTable(
    7716     psDB            *dbh                ///< Database handle
    7717 );
    7718 
    7719 /** Insert a single row into a table
    7720  *
    7721  * This function constructs and inserts a single row based on it's parameters.
    7722  *
    7723  * @return true on success
    7724  */
    7725 
    7726 bool p4DiffScfileInsert(
    7727     psDB            *dbh,               ///< Database handle
    7728     psS32           p4b_id,
    7729     const char      *skycell_id,
    7730     const char      *tess_id,
    7731     const char      *exp_tag,
    7732     psS32           p3_version,
    7733     const char      *uri,
    7734     psF64           bg,
    7735     psF64           bg_mean_stdev
    7736 );
    7737 
    7738 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.
    7739  *
    7740  * @return A The number of rows removed or a negative value on error
    7741  */
    7742 
    7743 long long p4DiffScfileDelete(
    7744     psDB            *dbh,               ///< Database handle
    7745     const psMetadata *where,            ///< Row match criteria
    7746     unsigned long long limit            ///< Maximum number of elements to delete
    7747 );
    7748 
    7749 /** Insert a single p4DiffScfileRow object into a table
    7750  *
    7751  * This function constructs and inserts a single row based on it's parameters.
    7752  *
    7753  * @return true on success
    7754  */
    7755 
    7756 bool p4DiffScfileInsertObject(
    7757     psDB            *dbh,               ///< Database handle
    7758     p4DiffScfileRow *object             ///< p4DiffScfileRow object
    7759 );
    7760 
    7761 /** Insert an array of p4DiffScfileRow object into a table
    7762  *
    7763  * This function constructs and inserts multiple rows based on it's parameters.
    7764  *
    7765  * @return true on success
    7766  */
    7767 
    7768 bool p4DiffScfileInsertObjects(
    7769     psDB            *dbh,               ///< Database handle
    7770     psArray         *objects            ///< array of p4DiffScfileRow objects
    7771 );
    7772 
    7773 /** Insert data from a binary FITS table p4DiffScfileRow into the database
    7774  *
    7775  * This function expects a psFits object with a FITS table as the first
    7776  * extension.  The table must have at least one row of data in it, that is of
    7777  * the appropriate format (number of columns and their type).  All other
    7778  * extensions are ignored.
    7779  *
    7780  * @return true on success
    7781  */
    7782 
    7783 bool p4DiffScfileInsertFits(
    7784     psDB            *dbh,               ///< Database handle
    7785     const psFits    *fits               ///< psFits object
    7786 );
    7787 
    7788 /** Selects up to limit from the database and returns them in a binary FITS table
    7789  *
    7790  * This function assumes an empty psFits object and will create a FITS table
    7791  * as the first extension.
    7792  *
    7793  *  See psDBSelectRows() for documentation on the format of where.
    7794  *
    7795  * @return true on success
    7796  */
    7797 
    7798 bool p4DiffScfileSelectRowsFits(
    7799     psDB            *dbh,               ///< Database handle
    7800     psFits          *fits,              ///< psFits object
    7801     const psMetadata *where,            ///< Row match criteria
    7802     unsigned long long limit            ///< Maximum number of elements to return
    7803 );
    7804 
    7805 /** Convert a p4DiffScfileRow into an equivalent psMetadata
    7806  *
    7807  * @return A psMetadata pointer or NULL on error
    7808  */
    7809 
    7810 psMetadata *p4DiffScfileMetadataFromObject(
    7811     const p4DiffScfileRow *object             ///< fooRow to convert into a psMetadata
    7812 );
    7813 
    7814 /** Convert a psMetadata into an equivalent fooRow
    7815  *
    7816  * @return A p4DiffScfileRow pointer or NULL on error
    7817  */
    7818 
    7819 p4DiffScfileRow *p4DiffScfileObjectFromMetadata(
    7820     psMetadata      *md                 ///< psMetadata to convert into a fooRow
    7821 );
    7822 /** Selects up to limit rows from the database and returns as p4DiffScfileRow objects in a psArray
    7823  *
    7824  *  See psDBSelectRows() for documentation on the format of where.
    7825  *
    7826  * @return A psArray pointer or NULL on error
    7827  */
    7828 
    7829 psArray *p4DiffScfileSelectRowObjects(
    7830     psDB            *dbh,               ///< Database handle
    7831     const psMetadata *where,            ///< Row match criteria
    7832     unsigned long long limit            ///< Maximum number of elements to return
    7833 );
    7834 /** Deletes a row from the database coresponding to an p4DiffScfile
    7835  *
    7836  *  Note that a 'where' search psMetadata is constructed from each object and
    7837  *  used to find rows to delete.
    7838  *
    7839  * @return A The number of rows removed or a negative value on error
    7840  */
    7841 
    7842 bool p4DiffScfileDeleteObject(
    7843     psDB            *dbh,               ///< Database handle
    7844     const p4DiffScfileRow *object    ///< Object to delete
    7845 );
    7846 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.
    7847  *
    7848  *  Note that a 'where' search psMetadata is constructed from each object and
    7849  *  used to find rows to delete.
    7850  *
    7851  * @return A The number of rows removed or a negative value on error
    7852  */
    7853 
    7854 long long p4DiffScfileDeleteRowObjects(
    7855     psDB            *dbh,               ///< Database handle
    7856     const psArray   *objects,           ///< Array of objects to delete
    7857     unsigned long long limit            ///< Maximum number of elements to delete
    7858 );
    7859 /** Formats and prints an array of p4DiffScfileRow objects
    7860  *
    7861  * When mdcf is set the formated output is in psMetadataConfig
    7862  * format, otherwise it is in a simple tabular format.
    7863  *
    7864  * @return true on success
    7865  */
    7866 
    7867 bool p4DiffScfilePrintObjects(
    7868     FILE            *stream,            ///< a stream
    7869     psArray         *objects,           ///< An array of p4DiffScfileRow objects
    7870     bool            mdcf                ///< format as mdconfig or simple
    7871 );
    7872 /** Formats and prints an p4DiffScfileRow object
    7873  *
    7874  * When mdcf is set the formated output is in psMetadataConfig
    7875  * format, otherwise it is in a simple tabular format.
    7876  *
    7877  * @return true on success
    7878  */
    7879 
    7880 bool p4DiffScfilePrintObject(
    7881     FILE            *stream,            ///< a stream
    7882     p4DiffScfileRow *object,    ///< an p4DiffScfileRow object
    7883     bool            mdcf                ///< format as mdconfig or simple
    7884 );
    7885 /** p4MagicMaskImfileRow data structure
    7886  *
    7887  * Structure for representing a single row of p4MagicMaskImfile table data.
    7888  */
    7889 
    7890 typedef struct {
    7891     psS32           p4c_id;
    7892     char            *exp_tag;
    7893     psS32           p3_version;
    7894     char            *class_id;
    7895     char            *uri;
    7896 } p4MagicMaskImfileRow;
    7897 
    7898 /** Creates a new p4MagicMaskImfileRow object
    7899  *
    7900  *  @return A new p4MagicMaskImfileRow object or NULL on failure.
    7901  */
    7902 
    7903 p4MagicMaskImfileRow *p4MagicMaskImfileRowAlloc(
    7904     psS32           p4c_id,
    7905     const char      *exp_tag,
    7906     psS32           p3_version,
    7907     const char      *class_id,
    7908     const char      *uri
    7909 );
    7910 
    7911 /** Creates a new p4MagicMaskImfile table
    7912  *
    7913  * @return true on success
    7914  */
    7915 
    7916 bool p4MagicMaskImfileCreateTable(
    7917     psDB            *dbh                ///< Database handle
    7918 );
    7919 
    7920 /** Deletes a p4MagicMaskImfile table
    7921  *
    7922  * @return true on success
    7923  */
    7924 
    7925 bool p4MagicMaskImfileDropTable(
    7926     psDB            *dbh                ///< Database handle
    7927 );
    7928 
    7929 /** Insert a single row into a table
    7930  *
    7931  * This function constructs and inserts a single row based on it's parameters.
    7932  *
    7933  * @return true on success
    7934  */
    7935 
    7936 bool p4MagicMaskImfileInsert(
    7937     psDB            *dbh,               ///< Database handle
    7938     psS32           p4c_id,
    7939     const char      *exp_tag,
    7940     psS32           p3_version,
    7941     const char      *class_id,
    7942     const char      *uri
    7943 );
    7944 
    7945 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.
    7946  *
    7947  * @return A The number of rows removed or a negative value on error
    7948  */
    7949 
    7950 long long p4MagicMaskImfileDelete(
    7951     psDB            *dbh,               ///< Database handle
    7952     const psMetadata *where,            ///< Row match criteria
    7953     unsigned long long limit            ///< Maximum number of elements to delete
    7954 );
    7955 
    7956 /** Insert a single p4MagicMaskImfileRow object into a table
    7957  *
    7958  * This function constructs and inserts a single row based on it's parameters.
    7959  *
    7960  * @return true on success
    7961  */
    7962 
    7963 bool p4MagicMaskImfileInsertObject(
    7964     psDB            *dbh,               ///< Database handle
    7965     p4MagicMaskImfileRow *object             ///< p4MagicMaskImfileRow object
    7966 );
    7967 
    7968 /** Insert an array of p4MagicMaskImfileRow object into a table
    7969  *
    7970  * This function constructs and inserts multiple rows based on it's parameters.
    7971  *
    7972  * @return true on success
    7973  */
    7974 
    7975 bool p4MagicMaskImfileInsertObjects(
    7976     psDB            *dbh,               ///< Database handle
    7977     psArray         *objects            ///< array of p4MagicMaskImfileRow objects
    7978 );
    7979 
    7980 /** Insert data from a binary FITS table p4MagicMaskImfileRow into the database
    7981  *
    7982  * This function expects a psFits object with a FITS table as the first
    7983  * extension.  The table must have at least one row of data in it, that is of
    7984  * the appropriate format (number of columns and their type).  All other
    7985  * extensions are ignored.
    7986  *
    7987  * @return true on success
    7988  */
    7989 
    7990 bool p4MagicMaskImfileInsertFits(
    7991     psDB            *dbh,               ///< Database handle
    7992     const psFits    *fits               ///< psFits object
    7993 );
    7994 
    7995 /** Selects up to limit from the database and returns them in a binary FITS table
    7996  *
    7997  * This function assumes an empty psFits object and will create a FITS table
    7998  * as the first extension.
    7999  *
    8000  *  See psDBSelectRows() for documentation on the format of where.
    8001  *
    8002  * @return true on success
    8003  */
    8004 
    8005 bool p4MagicMaskImfileSelectRowsFits(
    8006     psDB            *dbh,               ///< Database handle
    8007     psFits          *fits,              ///< psFits object
    8008     const psMetadata *where,            ///< Row match criteria
    8009     unsigned long long limit            ///< Maximum number of elements to return
    8010 );
    8011 
    8012 /** Convert a p4MagicMaskImfileRow into an equivalent psMetadata
    8013  *
    8014  * @return A psMetadata pointer or NULL on error
    8015  */
    8016 
    8017 psMetadata *p4MagicMaskImfileMetadataFromObject(
    8018     const p4MagicMaskImfileRow *object             ///< fooRow to convert into a psMetadata
    8019 );
    8020 
    8021 /** Convert a psMetadata into an equivalent fooRow
    8022  *
    8023  * @return A p4MagicMaskImfileRow pointer or NULL on error
    8024  */
    8025 
    8026 p4MagicMaskImfileRow *p4MagicMaskImfileObjectFromMetadata(
    8027     psMetadata      *md                 ///< psMetadata to convert into a fooRow
    8028 );
    8029 /** Selects up to limit rows from the database and returns as p4MagicMaskImfileRow objects in a psArray
    8030  *
    8031  *  See psDBSelectRows() for documentation on the format of where.
    8032  *
    8033  * @return A psArray pointer or NULL on error
    8034  */
    8035 
    8036 psArray *p4MagicMaskImfileSelectRowObjects(
    8037     psDB            *dbh,               ///< Database handle
    8038     const psMetadata *where,            ///< Row match criteria
    8039     unsigned long long limit            ///< Maximum number of elements to return
    8040 );
    8041 /** Deletes a row from the database coresponding to an p4MagicMaskImfile
    8042  *
    8043  *  Note that a 'where' search psMetadata is constructed from each object and
    8044  *  used to find rows to delete.
    8045  *
    8046  * @return A The number of rows removed or a negative value on error
    8047  */
    8048 
    8049 bool p4MagicMaskImfileDeleteObject(
    8050     psDB            *dbh,               ///< Database handle
    8051     const p4MagicMaskImfileRow *object    ///< Object to delete
    8052 );
    8053 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.
    8054  *
    8055  *  Note that a 'where' search psMetadata is constructed from each object and
    8056  *  used to find rows to delete.
    8057  *
    8058  * @return A The number of rows removed or a negative value on error
    8059  */
    8060 
    8061 long long p4MagicMaskImfileDeleteRowObjects(
    8062     psDB            *dbh,               ///< Database handle
    8063     const psArray   *objects,           ///< Array of objects to delete
    8064     unsigned long long limit            ///< Maximum number of elements to delete
    8065 );
    8066 /** Formats and prints an array of p4MagicMaskImfileRow objects
    8067  *
    8068  * When mdcf is set the formated output is in psMetadataConfig
    8069  * format, otherwise it is in a simple tabular format.
    8070  *
    8071  * @return true on success
    8072  */
    8073 
    8074 bool p4MagicMaskImfilePrintObjects(
    8075     FILE            *stream,            ///< a stream
    8076     psArray         *objects,           ///< An array of p4MagicMaskImfileRow objects
    8077     bool            mdcf                ///< format as mdconfig or simple
    8078 );
    8079 /** Formats and prints an p4MagicMaskImfileRow object
    8080  *
    8081  * When mdcf is set the formated output is in psMetadataConfig
    8082  * format, otherwise it is in a simple tabular format.
    8083  *
    8084  * @return true on success
    8085  */
    8086 
    8087 bool p4MagicMaskImfilePrintObject(
    8088     FILE            *stream,            ///< a stream
    8089     p4MagicMaskImfileRow *object,    ///< an p4MagicMaskImfileRow object
    8090     bool            mdcf                ///< format as mdconfig or simple
    8091 );
    8092 /** skyCellRow data structure
    8093  *
    8094  * Structure for representing a single row of skyCell table data.
    8095  */
    8096 
    8097 typedef struct {
    8098     char            *skycell_id;
    8099     char            *tess_id;
    8100     psF64           ra1;
    8101     psF64           decl1;
    8102     psF64           ra2;
    8103     psF64           decl2;
    8104     psF64           ra3;
    8105     psF64           decl3;
    8106     psF64           ra4;
    8107     psF64           decl4;
    8108 } skyCellRow;
    8109 
    8110 /** Creates a new skyCellRow object
    8111  *
    8112  *  @return A new skyCellRow object or NULL on failure.
    8113  */
    8114 
    8115 skyCellRow *skyCellRowAlloc(
    8116     const char      *skycell_id,
    8117     const char      *tess_id,
    8118     psF64           ra1,
    8119     psF64           decl1,
    8120     psF64           ra2,
    8121     psF64           decl2,
    8122     psF64           ra3,
    8123     psF64           decl3,
    8124     psF64           ra4,
    8125     psF64           decl4
    8126 );
    8127 
    8128 /** Creates a new skyCell table
    8129  *
    8130  * @return true on success
    8131  */
    8132 
    8133 bool skyCellCreateTable(
    8134     psDB            *dbh                ///< Database handle
    8135 );
    8136 
    8137 /** Deletes a skyCell table
    8138  *
    8139  * @return true on success
    8140  */
    8141 
    8142 bool skyCellDropTable(
    8143     psDB            *dbh                ///< Database handle
    8144 );
    8145 
    8146 /** Insert a single row into a table
    8147  *
    8148  * This function constructs and inserts a single row based on it's parameters.
    8149  *
    8150  * @return true on success
    8151  */
    8152 
    8153 bool skyCellInsert(
    8154     psDB            *dbh,               ///< Database handle
    8155     const char      *skycell_id,
    8156     const char      *tess_id,
    8157     psF64           ra1,
    8158     psF64           decl1,
    8159     psF64           ra2,
    8160     psF64           decl2,
    8161     psF64           ra3,
    8162     psF64           decl3,
    8163     psF64           ra4,
    8164     psF64           decl4
    8165 );
    8166 
    8167 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.
    8168  *
    8169  * @return A The number of rows removed or a negative value on error
    8170  */
    8171 
    8172 long long skyCellDelete(
    8173     psDB            *dbh,               ///< Database handle
    8174     const psMetadata *where,            ///< Row match criteria
    8175     unsigned long long limit            ///< Maximum number of elements to delete
    8176 );
    8177 
    8178 /** Insert a single skyCellRow object into a table
    8179  *
    8180  * This function constructs and inserts a single row based on it's parameters.
    8181  *
    8182  * @return true on success
    8183  */
    8184 
    8185 bool skyCellInsertObject(
    8186     psDB            *dbh,               ///< Database handle
    8187     skyCellRow      *object             ///< skyCellRow object
    8188 );
    8189 
    8190 /** Insert an array of skyCellRow object into a table
    8191  *
    8192  * This function constructs and inserts multiple rows based on it's parameters.
    8193  *
    8194  * @return true on success
    8195  */
    8196 
    8197 bool skyCellInsertObjects(
    8198     psDB            *dbh,               ///< Database handle
    8199     psArray         *objects            ///< array of skyCellRow objects
    8200 );
    8201 
    8202 /** Insert data from a binary FITS table skyCellRow into the database
    8203  *
    8204  * This function expects a psFits object with a FITS table as the first
    8205  * extension.  The table must have at least one row of data in it, that is of
    8206  * the appropriate format (number of columns and their type).  All other
    8207  * extensions are ignored.
    8208  *
    8209  * @return true on success
    8210  */
    8211 
    8212 bool skyCellInsertFits(
    8213     psDB            *dbh,               ///< Database handle
    8214     const psFits    *fits               ///< psFits object
    8215 );
    8216 
    8217 /** Selects up to limit from the database and returns them in a binary FITS table
    8218  *
    8219  * This function assumes an empty psFits object and will create a FITS table
    8220  * as the first extension.
    8221  *
    8222  *  See psDBSelectRows() for documentation on the format of where.
    8223  *
    8224  * @return true on success
    8225  */
    8226 
    8227 bool skyCellSelectRowsFits(
    8228     psDB            *dbh,               ///< Database handle
    8229     psFits          *fits,              ///< psFits object
    8230     const psMetadata *where,            ///< Row match criteria
    8231     unsigned long long limit            ///< Maximum number of elements to return
    8232 );
    8233 
    8234 /** Convert a skyCellRow into an equivalent psMetadata
    8235  *
    8236  * @return A psMetadata pointer or NULL on error
    8237  */
    8238 
    8239 psMetadata *skyCellMetadataFromObject(
    8240     const skyCellRow *object             ///< fooRow to convert into a psMetadata
    8241 );
    8242 
    8243 /** Convert a psMetadata into an equivalent fooRow
    8244  *
    8245  * @return A skyCellRow pointer or NULL on error
    8246  */
    8247 
    8248 skyCellRow *skyCellObjectFromMetadata(
    8249     psMetadata      *md                 ///< psMetadata to convert into a fooRow
    8250 );
    8251 /** Selects up to limit rows from the database and returns as skyCellRow objects in a psArray
    8252  *
    8253  *  See psDBSelectRows() for documentation on the format of where.
    8254  *
    8255  * @return A psArray pointer or NULL on error
    8256  */
    8257 
    8258 psArray *skyCellSelectRowObjects(
    8259     psDB            *dbh,               ///< Database handle
    8260     const psMetadata *where,            ///< Row match criteria
    8261     unsigned long long limit            ///< Maximum number of elements to return
    8262 );
    8263 /** Deletes a row from the database coresponding to an skyCell
    8264  *
    8265  *  Note that a 'where' search psMetadata is constructed from each object and
    8266  *  used to find rows to delete.
    8267  *
    8268  * @return A The number of rows removed or a negative value on error
    8269  */
    8270 
    8271 bool skyCellDeleteObject(
    8272     psDB            *dbh,               ///< Database handle
    8273     const skyCellRow *object    ///< Object to delete
    8274 );
    8275 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.
    8276  *
    8277  *  Note that a 'where' search psMetadata is constructed from each object and
    8278  *  used to find rows to delete.
    8279  *
    8280  * @return A The number of rows removed or a negative value on error
    8281  */
    8282 
    8283 long long skyCellDeleteRowObjects(
    8284     psDB            *dbh,               ///< Database handle
    8285     const psArray   *objects,           ///< Array of objects to delete
    8286     unsigned long long limit            ///< Maximum number of elements to delete
    8287 );
    8288 /** Formats and prints an array of skyCellRow objects
    8289  *
    8290  * When mdcf is set the formated output is in psMetadataConfig
    8291  * format, otherwise it is in a simple tabular format.
    8292  *
    8293  * @return true on success
    8294  */
    8295 
    8296 bool skyCellPrintObjects(
    8297     FILE            *stream,            ///< a stream
    8298     psArray         *objects,           ///< An array of skyCellRow objects
    8299     bool            mdcf                ///< format as mdconfig or simple
    8300 );
    8301 /** Formats and prints an skyCellRow object
    8302  *
    8303  * When mdcf is set the formated output is in psMetadataConfig
    8304  * format, otherwise it is in a simple tabular format.
    8305  *
    8306  * @return true on success
    8307  */
    8308 
    8309 bool skyCellPrintObject(
    8310     FILE            *stream,            ///< a stream
    8311     skyCellRow *object,    ///< an skyCellRow object
    8312     bool            mdcf                ///< format as mdconfig or simple
    8313 );
    8314 /** skyCellMapRow data structure
    8315  *
    8316  * Structure for representing a single row of skyCellMap table data.
    8317  */
    8318 
    8319 typedef struct {
    8320     char            *skycell_id;
    8321     char            *tess_id;
    8322     char            *exp_tag;
    8323     char            *class_id;
    8324 } skyCellMapRow;
    8325 
    8326 /** Creates a new skyCellMapRow object
    8327  *
    8328  *  @return A new skyCellMapRow object or NULL on failure.
    8329  */
    8330 
    8331 skyCellMapRow *skyCellMapRowAlloc(
    8332     const char      *skycell_id,
    8333     const char      *tess_id,
    8334     const char      *exp_tag,
    8335     const char      *class_id
    8336 );
    8337 
    8338 /** Creates a new skyCellMap table
    8339  *
    8340  * @return true on success
    8341  */
    8342 
    8343 bool skyCellMapCreateTable(
    8344     psDB            *dbh                ///< Database handle
    8345 );
    8346 
    8347 /** Deletes a skyCellMap table
    8348  *
    8349  * @return true on success
    8350  */
    8351 
    8352 bool skyCellMapDropTable(
    8353     psDB            *dbh                ///< Database handle
    8354 );
    8355 
    8356 /** Insert a single row into a table
    8357  *
    8358  * This function constructs and inserts a single row based on it's parameters.
    8359  *
    8360  * @return true on success
    8361  */
    8362 
    8363 bool skyCellMapInsert(
    8364     psDB            *dbh,               ///< Database handle
    8365     const char      *skycell_id,
    8366     const char      *tess_id,
    8367     const char      *exp_tag,
    8368     const char      *class_id
    8369 );
    8370 
    8371 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.
    8372  *
    8373  * @return A The number of rows removed or a negative value on error
    8374  */
    8375 
    8376 long long skyCellMapDelete(
    8377     psDB            *dbh,               ///< Database handle
    8378     const psMetadata *where,            ///< Row match criteria
    8379     unsigned long long limit            ///< Maximum number of elements to delete
    8380 );
    8381 
    8382 /** Insert a single skyCellMapRow object into a table
    8383  *
    8384  * This function constructs and inserts a single row based on it's parameters.
    8385  *
    8386  * @return true on success
    8387  */
    8388 
    8389 bool skyCellMapInsertObject(
    8390     psDB            *dbh,               ///< Database handle
    8391     skyCellMapRow   *object             ///< skyCellMapRow object
    8392 );
    8393 
    8394 /** Insert an array of skyCellMapRow object into a table
    8395  *
    8396  * This function constructs and inserts multiple rows based on it's parameters.
    8397  *
    8398  * @return true on success
    8399  */
    8400 
    8401 bool skyCellMapInsertObjects(
    8402     psDB            *dbh,               ///< Database handle
    8403     psArray         *objects            ///< array of skyCellMapRow objects
    8404 );
    8405 
    8406 /** Insert data from a binary FITS table skyCellMapRow into the database
    8407  *
    8408  * This function expects a psFits object with a FITS table as the first
    8409  * extension.  The table must have at least one row of data in it, that is of
    8410  * the appropriate format (number of columns and their type).  All other
    8411  * extensions are ignored.
    8412  *
    8413  * @return true on success
    8414  */
    8415 
    8416 bool skyCellMapInsertFits(
    8417     psDB            *dbh,               ///< Database handle
    8418     const psFits    *fits               ///< psFits object
    8419 );
    8420 
    8421 /** Selects up to limit from the database and returns them in a binary FITS table
    8422  *
    8423  * This function assumes an empty psFits object and will create a FITS table
    8424  * as the first extension.
    8425  *
    8426  *  See psDBSelectRows() for documentation on the format of where.
    8427  *
    8428  * @return true on success
    8429  */
    8430 
    8431 bool skyCellMapSelectRowsFits(
    8432     psDB            *dbh,               ///< Database handle
    8433     psFits          *fits,              ///< psFits object
    8434     const psMetadata *where,            ///< Row match criteria
    8435     unsigned long long limit            ///< Maximum number of elements to return
    8436 );
    8437 
    8438 /** Convert a skyCellMapRow into an equivalent psMetadata
    8439  *
    8440  * @return A psMetadata pointer or NULL on error
    8441  */
    8442 
    8443 psMetadata *skyCellMapMetadataFromObject(
    8444     const skyCellMapRow *object             ///< fooRow to convert into a psMetadata
    8445 );
    8446 
    8447 /** Convert a psMetadata into an equivalent fooRow
    8448  *
    8449  * @return A skyCellMapRow pointer or NULL on error
    8450  */
    8451 
    8452 skyCellMapRow *skyCellMapObjectFromMetadata(
    8453     psMetadata      *md                 ///< psMetadata to convert into a fooRow
    8454 );
    8455 /** Selects up to limit rows from the database and returns as skyCellMapRow objects in a psArray
    8456  *
    8457  *  See psDBSelectRows() for documentation on the format of where.
    8458  *
    8459  * @return A psArray pointer or NULL on error
    8460  */
    8461 
    8462 psArray *skyCellMapSelectRowObjects(
    8463     psDB            *dbh,               ///< Database handle
    8464     const psMetadata *where,            ///< Row match criteria
    8465     unsigned long long limit            ///< Maximum number of elements to return
    8466 );
    8467 /** Deletes a row from the database coresponding to an skyCellMap
    8468  *
    8469  *  Note that a 'where' search psMetadata is constructed from each object and
    8470  *  used to find rows to delete.
    8471  *
    8472  * @return A The number of rows removed or a negative value on error
    8473  */
    8474 
    8475 bool skyCellMapDeleteObject(
    8476     psDB            *dbh,               ///< Database handle
    8477     const skyCellMapRow *object    ///< Object to delete
    8478 );
    8479 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.
    8480  *
    8481  *  Note that a 'where' search psMetadata is constructed from each object and
    8482  *  used to find rows to delete.
    8483  *
    8484  * @return A The number of rows removed or a negative value on error
    8485  */
    8486 
    8487 long long skyCellMapDeleteRowObjects(
    8488     psDB            *dbh,               ///< Database handle
    8489     const psArray   *objects,           ///< Array of objects to delete
    8490     unsigned long long limit            ///< Maximum number of elements to delete
    8491 );
    8492 /** Formats and prints an array of skyCellMapRow objects
    8493  *
    8494  * When mdcf is set the formated output is in psMetadataConfig
    8495  * format, otherwise it is in a simple tabular format.
    8496  *
    8497  * @return true on success
    8498  */
    8499 
    8500 bool skyCellMapPrintObjects(
    8501     FILE            *stream,            ///< a stream
    8502     psArray         *objects,           ///< An array of skyCellMapRow objects
    8503     bool            mdcf                ///< format as mdconfig or simple
    8504 );
    8505 /** Formats and prints an skyCellMapRow object
    8506  *
    8507  * When mdcf is set the formated output is in psMetadataConfig
    8508  * format, otherwise it is in a simple tabular format.
    8509  *
    8510  * @return true on success
    8511  */
    8512 
    8513 bool skyCellMapPrintObject(
    8514     FILE            *stream,            ///< a stream
    8515     skyCellMapRow *object,    ///< an skyCellMapRow object
    8516     bool            mdcf                ///< format as mdconfig or simple
    8517 );
    85187669
    85197670/// @}
     
    85237674#endif
    85247675
    8525 #endif // SKYCELLMAP_DB_H
     7676#endif // P4SCFILE_DB_H
  • trunk/ippdb/tests/alloc.c

    r11733 r11780  
    14161416        }
    14171417
    1418         if (!object->p4a_id == -32) {
     1418        if (!object->p4_id == -32) {
    14191419            psFree(object);
    14201420            exit(EXIT_FAILURE);
     
    14481448        }
    14491449
    1450         if (!object->p4a_id == -32) {
     1450        if (!object->p4_id == -32) {
    14511451            psFree(object);
    14521452            exit(EXIT_FAILURE);
     
    14691469
    14701470    {
     1471        p4SkyCellMapRow *object;
     1472
     1473        object = p4SkyCellMapRowAlloc(-32, "a string", "a string", "a string", -32, "a string"    );
     1474
     1475        if (!object) {
     1476            exit(EXIT_FAILURE);
     1477        }
     1478
     1479        if (!object->p4_id == -32) {
     1480            psFree(object);
     1481            exit(EXIT_FAILURE);
     1482        }
     1483        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
     1484            psFree(object);
     1485            exit(EXIT_FAILURE);
     1486        }
     1487        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
     1488            psFree(object);
     1489            exit(EXIT_FAILURE);
     1490        }
     1491        if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
     1492            psFree(object);
     1493            exit(EXIT_FAILURE);
     1494        }
     1495        if (!object->p3_version == -32) {
     1496            psFree(object);
     1497            exit(EXIT_FAILURE);
     1498        }
     1499        if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {
     1500            psFree(object);
     1501            exit(EXIT_FAILURE);
     1502        }
     1503
     1504        psFree(object);
     1505    }
     1506
     1507    {
    14711508        p4ScfileRow     *object;
    14721509
     
    14771514        }
    14781515
    1479         if (!object->p4a_id == -32) {
     1516        if (!object->p4_id == -32) {
    14801517            psFree(object);
    14811518            exit(EXIT_FAILURE);
     
    15061543        }
    15071544        if (!object->bg_mean_stdev == 64.64) {
    1508             psFree(object);
    1509             exit(EXIT_FAILURE);
    1510         }
    1511 
    1512         psFree(object);
    1513     }
    1514 
    1515     {
    1516         p4InputScfileRow *object;
    1517 
    1518         object = p4InputScfileRowAlloc(-32, "a string", "a string", "a string", -32, "a string"    );
    1519 
    1520         if (!object) {
    1521             exit(EXIT_FAILURE);
    1522         }
    1523 
    1524         if (!object->p4b_id == -32) {
    1525             psFree(object);
    1526             exit(EXIT_FAILURE);
    1527         }
    1528         if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
    1529             psFree(object);
    1530             exit(EXIT_FAILURE);
    1531         }
    1532         if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
    1533             psFree(object);
    1534             exit(EXIT_FAILURE);
    1535         }
    1536         if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
    1537             psFree(object);
    1538             exit(EXIT_FAILURE);
    1539         }
    1540         if (!object->p3_version == -32) {
    1541             psFree(object);
    1542             exit(EXIT_FAILURE);
    1543         }
    1544         if (strncmp(object->kind, "a string", MAX_STRING_LENGTH)) {
    1545             psFree(object);
    1546             exit(EXIT_FAILURE);
    1547         }
    1548 
    1549         psFree(object);
    1550     }
    1551 
    1552     {
    1553         p4DiffScfileRow *object;
    1554 
    1555         object = p4DiffScfileRowAlloc(-32, "a string", "a string", "a string", -32, "a string", 64.64, 64.64    );
    1556 
    1557         if (!object) {
    1558             exit(EXIT_FAILURE);
    1559         }
    1560 
    1561         if (!object->p4b_id == -32) {
    1562             psFree(object);
    1563             exit(EXIT_FAILURE);
    1564         }
    1565         if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
    1566             psFree(object);
    1567             exit(EXIT_FAILURE);
    1568         }
    1569         if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
    1570             psFree(object);
    1571             exit(EXIT_FAILURE);
    1572         }
    1573         if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
    1574             psFree(object);
    1575             exit(EXIT_FAILURE);
    1576         }
    1577         if (!object->p3_version == -32) {
    1578             psFree(object);
    1579             exit(EXIT_FAILURE);
    1580         }
    1581         if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {
    1582             psFree(object);
    1583             exit(EXIT_FAILURE);
    1584         }
    1585         if (!object->bg == 64.64) {
    1586             psFree(object);
    1587             exit(EXIT_FAILURE);
    1588         }
    1589         if (!object->bg_mean_stdev == 64.64) {
    1590             psFree(object);
    1591             exit(EXIT_FAILURE);
    1592         }
    1593 
    1594         psFree(object);
    1595     }
    1596 
    1597     {
    1598         p4MagicMaskImfileRow *object;
    1599 
    1600         object = p4MagicMaskImfileRowAlloc(-32, "a string", -32, "a string", "a string"    );
    1601 
    1602         if (!object) {
    1603             exit(EXIT_FAILURE);
    1604         }
    1605 
    1606         if (!object->p4c_id == -32) {
    1607             psFree(object);
    1608             exit(EXIT_FAILURE);
    1609         }
    1610         if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
    1611             psFree(object);
    1612             exit(EXIT_FAILURE);
    1613         }
    1614         if (!object->p3_version == -32) {
    1615             psFree(object);
    1616             exit(EXIT_FAILURE);
    1617         }
    1618         if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {
    1619             psFree(object);
    1620             exit(EXIT_FAILURE);
    1621         }
    1622         if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {
    1623             psFree(object);
    1624             exit(EXIT_FAILURE);
    1625         }
    1626 
    1627         psFree(object);
    1628     }
    1629 
    1630     {
    1631         skyCellRow      *object;
    1632 
    1633         object = skyCellRowAlloc("a string", "a string", 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64    );
    1634 
    1635         if (!object) {
    1636             exit(EXIT_FAILURE);
    1637         }
    1638 
    1639         if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
    1640             psFree(object);
    1641             exit(EXIT_FAILURE);
    1642         }
    1643         if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
    1644             psFree(object);
    1645             exit(EXIT_FAILURE);
    1646         }
    1647         if (!object->ra1 == 64.64) {
    1648             psFree(object);
    1649             exit(EXIT_FAILURE);
    1650         }
    1651         if (!object->decl1 == 64.64) {
    1652             psFree(object);
    1653             exit(EXIT_FAILURE);
    1654         }
    1655         if (!object->ra2 == 64.64) {
    1656             psFree(object);
    1657             exit(EXIT_FAILURE);
    1658         }
    1659         if (!object->decl2 == 64.64) {
    1660             psFree(object);
    1661             exit(EXIT_FAILURE);
    1662         }
    1663         if (!object->ra3 == 64.64) {
    1664             psFree(object);
    1665             exit(EXIT_FAILURE);
    1666         }
    1667         if (!object->decl3 == 64.64) {
    1668             psFree(object);
    1669             exit(EXIT_FAILURE);
    1670         }
    1671         if (!object->ra4 == 64.64) {
    1672             psFree(object);
    1673             exit(EXIT_FAILURE);
    1674         }
    1675         if (!object->decl4 == 64.64) {
    1676             psFree(object);
    1677             exit(EXIT_FAILURE);
    1678         }
    1679 
    1680         psFree(object);
    1681     }
    1682 
    1683     {
    1684         skyCellMapRow   *object;
    1685 
    1686         object = skyCellMapRowAlloc("a string", "a string", "a string", "a string"    );
    1687 
    1688         if (!object) {
    1689             exit(EXIT_FAILURE);
    1690         }
    1691 
    1692         if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
    1693             psFree(object);
    1694             exit(EXIT_FAILURE);
    1695         }
    1696         if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
    1697             psFree(object);
    1698             exit(EXIT_FAILURE);
    1699         }
    1700         if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
    1701             psFree(object);
    1702             exit(EXIT_FAILURE);
    1703         }
    1704         if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {
    17051545            psFree(object);
    17061546            exit(EXIT_FAILURE);
  • trunk/ippdb/tests/createtable.c

    r11720 r11780  
    508508        }
    509509
     510        if(!p4SkyCellMapCreateTable(dbh)) {
     511            exit(EXIT_FAILURE);
     512        }
     513
     514        psDBCleanup(dbh);
     515    }
     516
     517    {
     518        psDB            *dbh;
     519
     520        dbh = psDBInit("localhost", "test", NULL, "test");
     521        if (!dbh) {
     522            exit(EXIT_FAILURE);
     523        }
     524
    510525        if(!p4ScfileCreateTable(dbh)) {
    511             exit(EXIT_FAILURE);
    512         }
    513 
    514         psDBCleanup(dbh);
    515     }
    516 
    517     {
    518         psDB            *dbh;
    519 
    520         dbh = psDBInit("localhost", "test", NULL, "test");
    521         if (!dbh) {
    522             exit(EXIT_FAILURE);
    523         }
    524 
    525         if(!p4InputScfileCreateTable(dbh)) {
    526             exit(EXIT_FAILURE);
    527         }
    528 
    529         psDBCleanup(dbh);
    530     }
    531 
    532     {
    533         psDB            *dbh;
    534 
    535         dbh = psDBInit("localhost", "test", NULL, "test");
    536         if (!dbh) {
    537             exit(EXIT_FAILURE);
    538         }
    539 
    540         if(!p4DiffScfileCreateTable(dbh)) {
    541             exit(EXIT_FAILURE);
    542         }
    543 
    544         psDBCleanup(dbh);
    545     }
    546 
    547     {
    548         psDB            *dbh;
    549 
    550         dbh = psDBInit("localhost", "test", NULL, "test");
    551         if (!dbh) {
    552             exit(EXIT_FAILURE);
    553         }
    554 
    555         if(!p4MagicMaskImfileCreateTable(dbh)) {
    556             exit(EXIT_FAILURE);
    557         }
    558 
    559         psDBCleanup(dbh);
    560     }
    561 
    562     {
    563         psDB            *dbh;
    564 
    565         dbh = psDBInit("localhost", "test", NULL, "test");
    566         if (!dbh) {
    567             exit(EXIT_FAILURE);
    568         }
    569 
    570         if(!skyCellCreateTable(dbh)) {
    571             exit(EXIT_FAILURE);
    572         }
    573 
    574         psDBCleanup(dbh);
    575     }
    576 
    577     {
    578         psDB            *dbh;
    579 
    580         dbh = psDBInit("localhost", "test", NULL, "test");
    581         if (!dbh) {
    582             exit(EXIT_FAILURE);
    583         }
    584 
    585         if(!skyCellMapCreateTable(dbh)) {
    586526            exit(EXIT_FAILURE);
    587527        }
  • trunk/ippdb/tests/dbcleanup.c

    r11720 r11780  
    4444    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4Run");
    4545    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4InputExp");
     46    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4SkyCellMap");
    4647    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4Scfile");
    47     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4InputScfile");
    48     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4DiffScfile");
    49     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4MagicMaskImfile");
    50     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS skyCell");
    51     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS skyCellMap");
    5248
    5349    psDBCleanup(dbh);
  • trunk/ippdb/tests/dbsetup.c

    r11720 r11780  
    112112    p4InputExpCreateTable(dbh);
    113113
     114    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4SkyCellMap");
     115    p4SkyCellMapCreateTable(dbh);
     116
    114117    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4Scfile");
    115118    p4ScfileCreateTable(dbh);
    116 
    117     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4InputScfile");
    118     p4InputScfileCreateTable(dbh);
    119 
    120     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4DiffScfile");
    121     p4DiffScfileCreateTable(dbh);
    122 
    123     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4MagicMaskImfile");
    124     p4MagicMaskImfileCreateTable(dbh);
    125 
    126     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS skyCell");
    127     skyCellCreateTable(dbh);
    128 
    129     p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS skyCellMap");
    130     skyCellMapCreateTable(dbh);
    131119
    132120    psDBCleanup(dbh);
  • trunk/ippdb/tests/droptable.c

    r11720 r11780  
    508508        }
    509509
     510        if (!p4SkyCellMapDropTable(dbh)) {
     511            exit(EXIT_FAILURE);
     512        }
     513
     514        psDBCleanup(dbh);
     515    }
     516
     517    {
     518        psDB            *dbh;
     519
     520        dbh = psDBInit("localhost", "test", NULL, "test");
     521        if (!dbh) {
     522            exit(EXIT_FAILURE);
     523        }
     524
    510525        if (!p4ScfileDropTable(dbh)) {
    511             exit(EXIT_FAILURE);
    512         }
    513 
    514         psDBCleanup(dbh);
    515     }
    516 
    517     {
    518         psDB            *dbh;
    519 
    520         dbh = psDBInit("localhost", "test", NULL, "test");
    521         if (!dbh) {
    522             exit(EXIT_FAILURE);
    523         }
    524 
    525         if (!p4InputScfileDropTable(dbh)) {
    526             exit(EXIT_FAILURE);
    527         }
    528 
    529         psDBCleanup(dbh);
    530     }
    531 
    532     {
    533         psDB            *dbh;
    534 
    535         dbh = psDBInit("localhost", "test", NULL, "test");
    536         if (!dbh) {
    537             exit(EXIT_FAILURE);
    538         }
    539 
    540         if (!p4DiffScfileDropTable(dbh)) {
    541             exit(EXIT_FAILURE);
    542         }
    543 
    544         psDBCleanup(dbh);
    545     }
    546 
    547     {
    548         psDB            *dbh;
    549 
    550         dbh = psDBInit("localhost", "test", NULL, "test");
    551         if (!dbh) {
    552             exit(EXIT_FAILURE);
    553         }
    554 
    555         if (!p4MagicMaskImfileDropTable(dbh)) {
    556             exit(EXIT_FAILURE);
    557         }
    558 
    559         psDBCleanup(dbh);
    560     }
    561 
    562     {
    563         psDB            *dbh;
    564 
    565         dbh = psDBInit("localhost", "test", NULL, "test");
    566         if (!dbh) {
    567             exit(EXIT_FAILURE);
    568         }
    569 
    570         if (!skyCellDropTable(dbh)) {
    571             exit(EXIT_FAILURE);
    572         }
    573 
    574         psDBCleanup(dbh);
    575     }
    576 
    577     {
    578         psDB            *dbh;
    579 
    580         dbh = psDBInit("localhost", "test", NULL, "test");
    581         if (!dbh) {
    582             exit(EXIT_FAILURE);
    583         }
    584 
    585         if (!skyCellMapDropTable(dbh)) {
    586526            exit(EXIT_FAILURE);
    587527        }
  • trunk/ippdb/tests/insert.c

    r11733 r11780  
    508508        }
    509509
     510        if (!p4SkyCellMapInsert(dbh, -32, "a string", "a string", "a string", -32, "a string")) {
     511            exit(EXIT_FAILURE);
     512        }
     513
     514        psDBCleanup(dbh);
     515    }
     516
     517    {
     518        psDB            *dbh;
     519
     520        dbh = psDBInit("localhost", "test", NULL, "test");
     521        if (!dbh) {
     522            exit(EXIT_FAILURE);
     523        }
     524
    510525        if (!p4ScfileInsert(dbh, -32, "a string", "a string", "a string", -32, "a string", 64.64, 64.64)) {
    511             exit(EXIT_FAILURE);
    512         }
    513 
    514         psDBCleanup(dbh);
    515     }
    516 
    517     {
    518         psDB            *dbh;
    519 
    520         dbh = psDBInit("localhost", "test", NULL, "test");
    521         if (!dbh) {
    522             exit(EXIT_FAILURE);
    523         }
    524 
    525         if (!p4InputScfileInsert(dbh, -32, "a string", "a string", "a string", -32, "a string")) {
    526             exit(EXIT_FAILURE);
    527         }
    528 
    529         psDBCleanup(dbh);
    530     }
    531 
    532     {
    533         psDB            *dbh;
    534 
    535         dbh = psDBInit("localhost", "test", NULL, "test");
    536         if (!dbh) {
    537             exit(EXIT_FAILURE);
    538         }
    539 
    540         if (!p4DiffScfileInsert(dbh, -32, "a string", "a string", "a string", -32, "a string", 64.64, 64.64)) {
    541             exit(EXIT_FAILURE);
    542         }
    543 
    544         psDBCleanup(dbh);
    545     }
    546 
    547     {
    548         psDB            *dbh;
    549 
    550         dbh = psDBInit("localhost", "test", NULL, "test");
    551         if (!dbh) {
    552             exit(EXIT_FAILURE);
    553         }
    554 
    555         if (!p4MagicMaskImfileInsert(dbh, -32, "a string", -32, "a string", "a string")) {
    556             exit(EXIT_FAILURE);
    557         }
    558 
    559         psDBCleanup(dbh);
    560     }
    561 
    562     {
    563         psDB            *dbh;
    564 
    565         dbh = psDBInit("localhost", "test", NULL, "test");
    566         if (!dbh) {
    567             exit(EXIT_FAILURE);
    568         }
    569 
    570         if (!skyCellInsert(dbh, "a string", "a string", 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64)) {
    571             exit(EXIT_FAILURE);
    572         }
    573 
    574         psDBCleanup(dbh);
    575     }
    576 
    577     {
    578         psDB            *dbh;
    579 
    580         dbh = psDBInit("localhost", "test", NULL, "test");
    581         if (!dbh) {
    582             exit(EXIT_FAILURE);
    583         }
    584 
    585         if (!skyCellMapInsert(dbh, "a string", "a string", "a string", "a string")) {
    586526            exit(EXIT_FAILURE);
    587527        }
  • trunk/ippdb/tests/insertfits.c

    r11720 r11780  
    882882        }
    883883
     884        if (!p4SkyCellMapInsertFits(dbh, fits)) {
     885            exit(EXIT_FAILURE);
     886        }
     887
     888        if (!psFitsClose(fits)) {
     889            exit(EXIT_FAILURE);
     890        }
     891
     892        psDBCleanup(dbh);
     893    }
     894
     895    {
     896        psDB            *dbh;
     897        psFits          *fits;
     898
     899        dbh = psDBInit("localhost", "test", NULL, "test");
     900        if (!dbh) {
     901            exit(EXIT_FAILURE);
     902        }
     903
     904        // open a temp
     905        fits = psFitsOpen(TMP_FILENAME, "r");
     906        if (!fits) {
     907            exit(EXIT_FAILURE);
     908        }
     909
    884910        if (!p4ScfileInsertFits(dbh, fits)) {
    885             exit(EXIT_FAILURE);
    886         }
    887 
    888         if (!psFitsClose(fits)) {
    889             exit(EXIT_FAILURE);
    890         }
    891 
    892         psDBCleanup(dbh);
    893     }
    894 
    895     {
    896         psDB            *dbh;
    897         psFits          *fits;
    898 
    899         dbh = psDBInit("localhost", "test", NULL, "test");
    900         if (!dbh) {
    901             exit(EXIT_FAILURE);
    902         }
    903 
    904         // open a temp
    905         fits = psFitsOpen(TMP_FILENAME, "r");
    906         if (!fits) {
    907             exit(EXIT_FAILURE);
    908         }
    909 
    910         if (!p4InputScfileInsertFits(dbh, fits)) {
    911             exit(EXIT_FAILURE);
    912         }
    913 
    914         if (!psFitsClose(fits)) {
    915             exit(EXIT_FAILURE);
    916         }
    917 
    918         psDBCleanup(dbh);
    919     }
    920 
    921     {
    922         psDB            *dbh;
    923         psFits          *fits;
    924 
    925         dbh = psDBInit("localhost", "test", NULL, "test");
    926         if (!dbh) {
    927             exit(EXIT_FAILURE);
    928         }
    929 
    930         // open a temp
    931         fits = psFitsOpen(TMP_FILENAME, "r");
    932         if (!fits) {
    933             exit(EXIT_FAILURE);
    934         }
    935 
    936         if (!p4DiffScfileInsertFits(dbh, fits)) {
    937             exit(EXIT_FAILURE);
    938         }
    939 
    940         if (!psFitsClose(fits)) {
    941             exit(EXIT_FAILURE);
    942         }
    943 
    944         psDBCleanup(dbh);
    945     }
    946 
    947     {
    948         psDB            *dbh;
    949         psFits          *fits;
    950 
    951         dbh = psDBInit("localhost", "test", NULL, "test");
    952         if (!dbh) {
    953             exit(EXIT_FAILURE);
    954         }
    955 
    956         // open a temp
    957         fits = psFitsOpen(TMP_FILENAME, "r");
    958         if (!fits) {
    959             exit(EXIT_FAILURE);
    960         }
    961 
    962         if (!p4MagicMaskImfileInsertFits(dbh, fits)) {
    963             exit(EXIT_FAILURE);
    964         }
    965 
    966         if (!psFitsClose(fits)) {
    967             exit(EXIT_FAILURE);
    968         }
    969 
    970         psDBCleanup(dbh);
    971     }
    972 
    973     {
    974         psDB            *dbh;
    975         psFits          *fits;
    976 
    977         dbh = psDBInit("localhost", "test", NULL, "test");
    978         if (!dbh) {
    979             exit(EXIT_FAILURE);
    980         }
    981 
    982         // open a temp
    983         fits = psFitsOpen(TMP_FILENAME, "r");
    984         if (!fits) {
    985             exit(EXIT_FAILURE);
    986         }
    987 
    988         if (!skyCellInsertFits(dbh, fits)) {
    989             exit(EXIT_FAILURE);
    990         }
    991 
    992         if (!psFitsClose(fits)) {
    993             exit(EXIT_FAILURE);
    994         }
    995 
    996         psDBCleanup(dbh);
    997     }
    998 
    999     {
    1000         psDB            *dbh;
    1001         psFits          *fits;
    1002 
    1003         dbh = psDBInit("localhost", "test", NULL, "test");
    1004         if (!dbh) {
    1005             exit(EXIT_FAILURE);
    1006         }
    1007 
    1008         // open a temp
    1009         fits = psFitsOpen(TMP_FILENAME, "r");
    1010         if (!fits) {
    1011             exit(EXIT_FAILURE);
    1012         }
    1013 
    1014         if (!skyCellMapInsertFits(dbh, fits)) {
    1015911            exit(EXIT_FAILURE);
    1016912        }
  • trunk/ippdb/tests/insertobject.c

    r11733 r11780  
    733733    {
    734734        psDB            *dbh;
     735        p4SkyCellMapRow *object;
     736
     737        dbh = psDBInit("localhost", "test", NULL, "test");
     738        if (!dbh) {
     739            exit(EXIT_FAILURE);
     740        }
     741
     742        object = p4SkyCellMapRowAlloc(-32, "a string", "a string", "a string", -32, "a string");
     743        if (!object) {
     744            exit(EXIT_FAILURE);
     745        }
     746
     747        if (!p4SkyCellMapInsertObject(dbh, object)) {
     748            exit(EXIT_FAILURE);
     749        }
     750
     751        psFree(object);
     752        psDBCleanup(dbh);
     753    }
     754
     755    {
     756        psDB            *dbh;
    735757        p4ScfileRow     *object;
    736758
     
    746768
    747769        if (!p4ScfileInsertObject(dbh, object)) {
    748             exit(EXIT_FAILURE);
    749         }
    750 
    751         psFree(object);
    752         psDBCleanup(dbh);
    753     }
    754 
    755     {
    756         psDB            *dbh;
    757         p4InputScfileRow *object;
    758 
    759         dbh = psDBInit("localhost", "test", NULL, "test");
    760         if (!dbh) {
    761             exit(EXIT_FAILURE);
    762         }
    763 
    764         object = p4InputScfileRowAlloc(-32, "a string", "a string", "a string", -32, "a string");
    765         if (!object) {
    766             exit(EXIT_FAILURE);
    767         }
    768 
    769         if (!p4InputScfileInsertObject(dbh, object)) {
    770             exit(EXIT_FAILURE);
    771         }
    772 
    773         psFree(object);
    774         psDBCleanup(dbh);
    775     }
    776 
    777     {
    778         psDB            *dbh;
    779         p4DiffScfileRow *object;
    780 
    781         dbh = psDBInit("localhost", "test", NULL, "test");
    782         if (!dbh) {
    783             exit(EXIT_FAILURE);
    784         }
    785 
    786         object = p4DiffScfileRowAlloc(-32, "a string", "a string", "a string", -32, "a string", 64.64, 64.64);
    787         if (!object) {
    788             exit(EXIT_FAILURE);
    789         }
    790 
    791         if (!p4DiffScfileInsertObject(dbh, object)) {
    792             exit(EXIT_FAILURE);
    793         }
    794 
    795         psFree(object);
    796         psDBCleanup(dbh);
    797     }
    798 
    799     {
    800         psDB            *dbh;
    801         p4MagicMaskImfileRow *object;
    802 
    803         dbh = psDBInit("localhost", "test", NULL, "test");
    804         if (!dbh) {
    805             exit(EXIT_FAILURE);
    806         }
    807 
    808         object = p4MagicMaskImfileRowAlloc(-32, "a string", -32, "a string", "a string");
    809         if (!object) {
    810             exit(EXIT_FAILURE);
    811         }
    812 
    813         if (!p4MagicMaskImfileInsertObject(dbh, object)) {
    814             exit(EXIT_FAILURE);
    815         }
    816 
    817         psFree(object);
    818         psDBCleanup(dbh);
    819     }
    820 
    821     {
    822         psDB            *dbh;
    823         skyCellRow      *object;
    824 
    825         dbh = psDBInit("localhost", "test", NULL, "test");
    826         if (!dbh) {
    827             exit(EXIT_FAILURE);
    828         }
    829 
    830         object = skyCellRowAlloc("a string", "a string", 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64);
    831         if (!object) {
    832             exit(EXIT_FAILURE);
    833         }
    834 
    835         if (!skyCellInsertObject(dbh, object)) {
    836             exit(EXIT_FAILURE);
    837         }
    838 
    839         psFree(object);
    840         psDBCleanup(dbh);
    841     }
    842 
    843     {
    844         psDB            *dbh;
    845         skyCellMapRow   *object;
    846 
    847         dbh = psDBInit("localhost", "test", NULL, "test");
    848         if (!dbh) {
    849             exit(EXIT_FAILURE);
    850         }
    851 
    852         object = skyCellMapRowAlloc("a string", "a string", "a string", "a string");
    853         if (!object) {
    854             exit(EXIT_FAILURE);
    855         }
    856 
    857         if (!skyCellMapInsertObject(dbh, object)) {
    858770            exit(EXIT_FAILURE);
    859771        }
  • trunk/ippdb/tests/metadatafromobject.c

    r11733 r11780  
    16581658        psFree(object);
    16591659
    1660         if (!psMetadataLookupS32(&status, md, "p4a_id") == -32) {
     1660        if (!psMetadataLookupS32(&status, md, "p4_id") == -32) {
    16611661            psFree(md);
    16621662            exit(EXIT_FAILURE);
     
    16981698        psFree(object);
    16991699
    1700         if (!psMetadataLookupS32(&status, md, "p4a_id") == -32) {
     1700        if (!psMetadataLookupS32(&status, md, "p4_id") == -32) {
    17011701            psFree(md);
    17021702            exit(EXIT_FAILURE);
     
    17201720    {
    17211721        psMetadata      *md;
     1722        p4SkyCellMapRow *object;
     1723        bool            status;
     1724
     1725        object = p4SkyCellMapRowAlloc(-32, "a string", "a string", "a string", -32, "a string");
     1726        if (!object) {
     1727            exit(EXIT_FAILURE);
     1728        }
     1729
     1730        md = p4SkyCellMapMetadataFromObject(object);
     1731        if (!md) {
     1732            exit(EXIT_FAILURE);
     1733        }
     1734
     1735        psFree(object);
     1736
     1737        if (!psMetadataLookupS32(&status, md, "p4_id") == -32) {
     1738            psFree(md);
     1739            exit(EXIT_FAILURE);
     1740        }
     1741        if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {
     1742            psFree(md);
     1743            exit(EXIT_FAILURE);
     1744        }
     1745        if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {
     1746            psFree(md);
     1747            exit(EXIT_FAILURE);
     1748        }
     1749        if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) {
     1750            psFree(md);
     1751            exit(EXIT_FAILURE);
     1752        }
     1753        if (!psMetadataLookupS32(&status, md, "p3_version") == -32) {
     1754            psFree(md);
     1755            exit(EXIT_FAILURE);
     1756        }
     1757        if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) {
     1758            psFree(md);
     1759            exit(EXIT_FAILURE);
     1760        }
     1761
     1762        psFree(md);
     1763    }
     1764
     1765    {
     1766        psMetadata      *md;
    17221767        p4ScfileRow     *object;
    17231768        bool            status;
     
    17351780        psFree(object);
    17361781
    1737         if (!psMetadataLookupS32(&status, md, "p4a_id") == -32) {
     1782        if (!psMetadataLookupS32(&status, md, "p4_id") == -32) {
    17381783            psFree(md);
    17391784            exit(EXIT_FAILURE);
     
    17641809        }
    17651810        if (!psMetadataLookupF64(&status, md, "bg_mean_stdev") == 64.64) {
    1766             psFree(md);
    1767             exit(EXIT_FAILURE);
    1768         }
    1769 
    1770         psFree(md);
    1771     }
    1772 
    1773     {
    1774         psMetadata      *md;
    1775         p4InputScfileRow *object;
    1776         bool            status;
    1777 
    1778         object = p4InputScfileRowAlloc(-32, "a string", "a string", "a string", -32, "a string");
    1779         if (!object) {
    1780             exit(EXIT_FAILURE);
    1781         }
    1782 
    1783         md = p4InputScfileMetadataFromObject(object);
    1784         if (!md) {
    1785             exit(EXIT_FAILURE);
    1786         }
    1787 
    1788         psFree(object);
    1789 
    1790         if (!psMetadataLookupS32(&status, md, "p4b_id") == -32) {
    1791             psFree(md);
    1792             exit(EXIT_FAILURE);
    1793         }
    1794         if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {
    1795             psFree(md);
    1796             exit(EXIT_FAILURE);
    1797         }
    1798         if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {
    1799             psFree(md);
    1800             exit(EXIT_FAILURE);
    1801         }
    1802         if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) {
    1803             psFree(md);
    1804             exit(EXIT_FAILURE);
    1805         }
    1806         if (!psMetadataLookupS32(&status, md, "p3_version") == -32) {
    1807             psFree(md);
    1808             exit(EXIT_FAILURE);
    1809         }
    1810         if (strncmp(psMetadataLookupPtr(&status, md, "kind"), "a string", MAX_STRING_LENGTH)) {
    1811             psFree(md);
    1812             exit(EXIT_FAILURE);
    1813         }
    1814 
    1815         psFree(md);
    1816     }
    1817 
    1818     {
    1819         psMetadata      *md;
    1820         p4DiffScfileRow *object;
    1821         bool            status;
    1822 
    1823         object = p4DiffScfileRowAlloc(-32, "a string", "a string", "a string", -32, "a string", 64.64, 64.64);
    1824         if (!object) {
    1825             exit(EXIT_FAILURE);
    1826         }
    1827 
    1828         md = p4DiffScfileMetadataFromObject(object);
    1829         if (!md) {
    1830             exit(EXIT_FAILURE);
    1831         }
    1832 
    1833         psFree(object);
    1834 
    1835         if (!psMetadataLookupS32(&status, md, "p4b_id") == -32) {
    1836             psFree(md);
    1837             exit(EXIT_FAILURE);
    1838         }
    1839         if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {
    1840             psFree(md);
    1841             exit(EXIT_FAILURE);
    1842         }
    1843         if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {
    1844             psFree(md);
    1845             exit(EXIT_FAILURE);
    1846         }
    1847         if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) {
    1848             psFree(md);
    1849             exit(EXIT_FAILURE);
    1850         }
    1851         if (!psMetadataLookupS32(&status, md, "p3_version") == -32) {
    1852             psFree(md);
    1853             exit(EXIT_FAILURE);
    1854         }
    1855         if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) {
    1856             psFree(md);
    1857             exit(EXIT_FAILURE);
    1858         }
    1859         if (!psMetadataLookupF64(&status, md, "bg") == 64.64) {
    1860             psFree(md);
    1861             exit(EXIT_FAILURE);
    1862         }
    1863         if (!psMetadataLookupF64(&status, md, "bg_mean_stdev") == 64.64) {
    1864             psFree(md);
    1865             exit(EXIT_FAILURE);
    1866         }
    1867 
    1868         psFree(md);
    1869     }
    1870 
    1871     {
    1872         psMetadata      *md;
    1873         p4MagicMaskImfileRow *object;
    1874         bool            status;
    1875 
    1876         object = p4MagicMaskImfileRowAlloc(-32, "a string", -32, "a string", "a string");
    1877         if (!object) {
    1878             exit(EXIT_FAILURE);
    1879         }
    1880 
    1881         md = p4MagicMaskImfileMetadataFromObject(object);
    1882         if (!md) {
    1883             exit(EXIT_FAILURE);
    1884         }
    1885 
    1886         psFree(object);
    1887 
    1888         if (!psMetadataLookupS32(&status, md, "p4c_id") == -32) {
    1889             psFree(md);
    1890             exit(EXIT_FAILURE);
    1891         }
    1892         if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) {
    1893             psFree(md);
    1894             exit(EXIT_FAILURE);
    1895         }
    1896         if (!psMetadataLookupS32(&status, md, "p3_version") == -32) {
    1897             psFree(md);
    1898             exit(EXIT_FAILURE);
    1899         }
    1900         if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) {
    1901             psFree(md);
    1902             exit(EXIT_FAILURE);
    1903         }
    1904         if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) {
    1905             psFree(md);
    1906             exit(EXIT_FAILURE);
    1907         }
    1908 
    1909         psFree(md);
    1910     }
    1911 
    1912     {
    1913         psMetadata      *md;
    1914         skyCellRow      *object;
    1915         bool            status;
    1916 
    1917         object = skyCellRowAlloc("a string", "a string", 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64, 64.64);
    1918         if (!object) {
    1919             exit(EXIT_FAILURE);
    1920         }
    1921 
    1922         md = skyCellMetadataFromObject(object);
    1923         if (!md) {
    1924             exit(EXIT_FAILURE);
    1925         }
    1926 
    1927         psFree(object);
    1928 
    1929         if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {
    1930             psFree(md);
    1931             exit(EXIT_FAILURE);
    1932         }
    1933         if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {
    1934             psFree(md);
    1935             exit(EXIT_FAILURE);
    1936         }
    1937         if (!psMetadataLookupF64(&status, md, "ra1") == 64.64) {
    1938             psFree(md);
    1939             exit(EXIT_FAILURE);
    1940         }
    1941         if (!psMetadataLookupF64(&status, md, "decl1") == 64.64) {
    1942             psFree(md);
    1943             exit(EXIT_FAILURE);
    1944         }
    1945         if (!psMetadataLookupF64(&status, md, "ra2") == 64.64) {
    1946             psFree(md);
    1947             exit(EXIT_FAILURE);
    1948         }
    1949         if (!psMetadataLookupF64(&status, md, "decl2") == 64.64) {
    1950             psFree(md);
    1951             exit(EXIT_FAILURE);
    1952         }
    1953         if (!psMetadataLookupF64(&status, md, "ra3") == 64.64) {
    1954             psFree(md);
    1955             exit(EXIT_FAILURE);
    1956         }
    1957         if (!psMetadataLookupF64(&status, md, "decl3") == 64.64) {
    1958             psFree(md);
    1959             exit(EXIT_FAILURE);
    1960         }
    1961         if (!psMetadataLookupF64(&status, md, "ra4") == 64.64) {
    1962             psFree(md);
    1963             exit(EXIT_FAILURE);
    1964         }
    1965         if (!psMetadataLookupF64(&status, md, "decl4") == 64.64) {
    1966             psFree(md);
    1967             exit(EXIT_FAILURE);
    1968         }
    1969 
    1970         psFree(md);
    1971     }
    1972 
    1973     {
    1974         psMetadata      *md;
    1975         skyCellMapRow   *object;
    1976         bool            status;
    1977 
    1978         object = skyCellMapRowAlloc("a string", "a string", "a string", "a string");
    1979         if (!object) {
    1980             exit(EXIT_FAILURE);
    1981         }
    1982 
    1983         md = skyCellMapMetadataFromObject(object);
    1984         if (!md) {
    1985             exit(EXIT_FAILURE);
    1986         }
    1987 
    1988         psFree(object);
    1989 
    1990         if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {
    1991             psFree(md);
    1992             exit(EXIT_FAILURE);
    1993         }
    1994         if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {
    1995             psFree(md);
    1996             exit(EXIT_FAILURE);
    1997         }
    1998         if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) {
    1999             psFree(md);
    2000             exit(EXIT_FAILURE);
    2001         }
    2002         if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) {
    20031811            psFree(md);
    20041812            exit(EXIT_FAILURE);
  • trunk/ippdb/tests/objectfrommetadata.c

    r11733 r11780  
    25352535
    25362536        md = psMetadataAlloc();
    2537         if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4a_id", 0, NULL, -32)) {
     2537        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) {
    25382538            psFree(md);
    25392539            exit(EXIT_FAILURE);
     
    25632563        psFree(md);
    25642564
    2565         if (!object->p4a_id == -32) {
     2565        if (!object->p4_id == -32) {
    25662566            psFree(object);
    25672567            exit(EXIT_FAILURE);
     
    25912591
    25922592        md = psMetadataAlloc();
    2593         if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4a_id", 0, NULL, -32)) {
     2593        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) {
    25942594            psFree(md);
    25952595            exit(EXIT_FAILURE);
     
    26162616        psFree(md);
    26172617
    2618         if (!object->p4a_id == -32) {
     2618        if (!object->p4_id == -32) {
    26192619            psFree(object);
    26202620            exit(EXIT_FAILURE);
     
    26382638    {
    26392639        psMetadata      *md;
     2640        p4SkyCellMapRow *object;
     2641
     2642        md = psMetadataAlloc();
     2643        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) {
     2644            psFree(md);
     2645            exit(EXIT_FAILURE);
     2646        }
     2647        if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {
     2648            psFree(md);
     2649            exit(EXIT_FAILURE);
     2650        }
     2651        if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {
     2652            psFree(md);
     2653            exit(EXIT_FAILURE);
     2654        }
     2655        if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) {
     2656            psFree(md);
     2657            exit(EXIT_FAILURE);
     2658        }
     2659        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) {
     2660            psFree(md);
     2661            exit(EXIT_FAILURE);
     2662        }
     2663        if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) {
     2664            psFree(md);
     2665            exit(EXIT_FAILURE);
     2666        }
     2667
     2668        object = p4SkyCellMapObjectFromMetadata(md);
     2669        if (!object) {
     2670            psFree(md);
     2671            exit(EXIT_FAILURE);
     2672        }
     2673
     2674        psFree(md);
     2675
     2676        if (!object->p4_id == -32) {
     2677            psFree(object);
     2678            exit(EXIT_FAILURE);
     2679        }
     2680        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
     2681            psFree(object);
     2682            exit(EXIT_FAILURE);
     2683        }
     2684        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
     2685            psFree(object);
     2686            exit(EXIT_FAILURE);
     2687        }
     2688        if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
     2689            psFree(object);
     2690            exit(EXIT_FAILURE);
     2691        }
     2692        if (!object->p3_version == -32) {
     2693            psFree(object);
     2694            exit(EXIT_FAILURE);
     2695        }
     2696        if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {
     2697            psFree(object);
     2698            exit(EXIT_FAILURE);
     2699        }
     2700
     2701        psFree(object);
     2702    }
     2703
     2704    {
     2705        psMetadata      *md;
    26402706        p4ScfileRow     *object;
    26412707
    26422708        md = psMetadataAlloc();
    2643         if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4a_id", 0, NULL, -32)) {
     2709        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) {
    26442710            psFree(md);
    26452711            exit(EXIT_FAILURE);
     
    26822748        psFree(md);
    26832749
    2684         if (!object->p4a_id == -32) {
     2750        if (!object->p4_id == -32) {
    26852751            psFree(object);
    26862752            exit(EXIT_FAILURE);
     
    27112777        }
    27122778        if (!object->bg_mean_stdev == 64.64) {
    2713             psFree(object);
    2714             exit(EXIT_FAILURE);
    2715         }
    2716 
    2717         psFree(object);
    2718     }
    2719 
    2720     {
    2721         psMetadata      *md;
    2722         p4InputScfileRow *object;
    2723 
    2724         md = psMetadataAlloc();
    2725         if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4b_id", 0, NULL, -32)) {
    2726             psFree(md);
    2727             exit(EXIT_FAILURE);
    2728         }
    2729         if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {
    2730             psFree(md);
    2731             exit(EXIT_FAILURE);
    2732         }
    2733         if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {
    2734             psFree(md);
    2735             exit(EXIT_FAILURE);
    2736         }
    2737         if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) {
    2738             psFree(md);
    2739             exit(EXIT_FAILURE);
    2740         }
    2741         if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) {
    2742             psFree(md);
    2743             exit(EXIT_FAILURE);
    2744         }
    2745         if (!psMetadataAddStr(md, PS_LIST_TAIL, "kind", 0, NULL, "a string")) {
    2746             psFree(md);
    2747             exit(EXIT_FAILURE);
    2748         }
    2749 
    2750         object = p4InputScfileObjectFromMetadata(md);
    2751         if (!object) {
    2752             psFree(md);
    2753             exit(EXIT_FAILURE);
    2754         }
    2755 
    2756         psFree(md);
    2757 
    2758         if (!object->p4b_id == -32) {
    2759             psFree(object);
    2760             exit(EXIT_FAILURE);
    2761         }
    2762         if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
    2763             psFree(object);
    2764             exit(EXIT_FAILURE);
    2765         }
    2766         if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
    2767             psFree(object);
    2768             exit(EXIT_FAILURE);
    2769         }
    2770         if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
    2771             psFree(object);
    2772             exit(EXIT_FAILURE);
    2773         }
    2774         if (!object->p3_version == -32) {
    2775             psFree(object);
    2776             exit(EXIT_FAILURE);
    2777         }
    2778         if (strncmp(object->kind, "a string", MAX_STRING_LENGTH)) {
    2779             psFree(object);
    2780             exit(EXIT_FAILURE);
    2781         }
    2782 
    2783         psFree(object);
    2784     }
    2785 
    2786     {
    2787         psMetadata      *md;
    2788         p4DiffScfileRow *object;
    2789 
    2790         md = psMetadataAlloc();
    2791         if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4b_id", 0, NULL, -32)) {
    2792             psFree(md);
    2793             exit(EXIT_FAILURE);
    2794         }
    2795         if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {
    2796             psFree(md);
    2797             exit(EXIT_FAILURE);
    2798         }
    2799         if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {
    2800             psFree(md);
    2801             exit(EXIT_FAILURE);
    2802         }
    2803         if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) {
    2804             psFree(md);
    2805             exit(EXIT_FAILURE);
    2806         }
    2807         if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) {
    2808             psFree(md);
    2809             exit(EXIT_FAILURE);
    2810         }
    2811         if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) {
    2812             psFree(md);
    2813             exit(EXIT_FAILURE);
    2814         }
    2815         if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 64.64)) {
    2816             psFree(md);
    2817             exit(EXIT_FAILURE);
    2818         }
    2819         if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_mean_stdev", 0, NULL, 64.64)) {
    2820             psFree(md);
    2821             exit(EXIT_FAILURE);
    2822         }
    2823 
    2824         object = p4DiffScfileObjectFromMetadata(md);
    2825         if (!object) {
    2826             psFree(md);
    2827             exit(EXIT_FAILURE);
    2828         }
    2829 
    2830         psFree(md);
    2831 
    2832         if (!object->p4b_id == -32) {
    2833             psFree(object);
    2834             exit(EXIT_FAILURE);
    2835         }
    2836         if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
    2837             psFree(object);
    2838             exit(EXIT_FAILURE);
    2839         }
    2840         if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
    2841             psFree(object);
    2842             exit(EXIT_FAILURE);
    2843         }
    2844         if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
    2845             psFree(object);
    2846             exit(EXIT_FAILURE);
    2847         }
    2848         if (!object->p3_version == -32) {
    2849             psFree(object);
    2850             exit(EXIT_FAILURE);
    2851         }
    2852         if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {
    2853             psFree(object);
    2854             exit(EXIT_FAILURE);
    2855         }
    2856         if (!object->bg == 64.64) {
    2857             psFree(object);
    2858             exit(EXIT_FAILURE);
    2859         }
    2860         if (!object->bg_mean_stdev == 64.64) {
    2861             psFree(object);
    2862             exit(EXIT_FAILURE);
    2863         }
    2864 
    2865         psFree(object);
    2866     }
    2867 
    2868     {
    2869         psMetadata      *md;
    2870         p4MagicMaskImfileRow *object;
    2871 
    2872         md = psMetadataAlloc();
    2873         if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4c_id", 0, NULL, -32)) {
    2874             psFree(md);
    2875             exit(EXIT_FAILURE);
    2876         }
    2877         if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) {
    2878             psFree(md);
    2879             exit(EXIT_FAILURE);
    2880         }
    2881         if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) {
    2882             psFree(md);
    2883             exit(EXIT_FAILURE);
    2884         }
    2885         if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) {
    2886             psFree(md);
    2887             exit(EXIT_FAILURE);
    2888         }
    2889         if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) {
    2890             psFree(md);
    2891             exit(EXIT_FAILURE);
    2892         }
    2893 
    2894         object = p4MagicMaskImfileObjectFromMetadata(md);
    2895         if (!object) {
    2896             psFree(md);
    2897             exit(EXIT_FAILURE);
    2898         }
    2899 
    2900         psFree(md);
    2901 
    2902         if (!object->p4c_id == -32) {
    2903             psFree(object);
    2904             exit(EXIT_FAILURE);
    2905         }
    2906         if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
    2907             psFree(object);
    2908             exit(EXIT_FAILURE);
    2909         }
    2910         if (!object->p3_version == -32) {
    2911             psFree(object);
    2912             exit(EXIT_FAILURE);
    2913         }
    2914         if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {
    2915             psFree(object);
    2916             exit(EXIT_FAILURE);
    2917         }
    2918         if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {
    2919             psFree(object);
    2920             exit(EXIT_FAILURE);
    2921         }
    2922 
    2923         psFree(object);
    2924     }
    2925 
    2926     {
    2927         psMetadata      *md;
    2928         skyCellRow      *object;
    2929 
    2930         md = psMetadataAlloc();
    2931         if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {
    2932             psFree(md);
    2933             exit(EXIT_FAILURE);
    2934         }
    2935         if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {
    2936             psFree(md);
    2937             exit(EXIT_FAILURE);
    2938         }
    2939         if (!psMetadataAddF64(md, PS_LIST_TAIL, "ra1", 0, NULL, 64.64)) {
    2940             psFree(md);
    2941             exit(EXIT_FAILURE);
    2942         }
    2943         if (!psMetadataAddF64(md, PS_LIST_TAIL, "decl1", 0, NULL, 64.64)) {
    2944             psFree(md);
    2945             exit(EXIT_FAILURE);
    2946         }
    2947         if (!psMetadataAddF64(md, PS_LIST_TAIL, "ra2", 0, NULL, 64.64)) {
    2948             psFree(md);
    2949             exit(EXIT_FAILURE);
    2950         }
    2951         if (!psMetadataAddF64(md, PS_LIST_TAIL, "decl2", 0, NULL, 64.64)) {
    2952             psFree(md);
    2953             exit(EXIT_FAILURE);
    2954         }
    2955         if (!psMetadataAddF64(md, PS_LIST_TAIL, "ra3", 0, NULL, 64.64)) {
    2956             psFree(md);
    2957             exit(EXIT_FAILURE);
    2958         }
    2959         if (!psMetadataAddF64(md, PS_LIST_TAIL, "decl3", 0, NULL, 64.64)) {
    2960             psFree(md);
    2961             exit(EXIT_FAILURE);
    2962         }
    2963         if (!psMetadataAddF64(md, PS_LIST_TAIL, "ra4", 0, NULL, 64.64)) {
    2964             psFree(md);
    2965             exit(EXIT_FAILURE);
    2966         }
    2967         if (!psMetadataAddF64(md, PS_LIST_TAIL, "decl4", 0, NULL, 64.64)) {
    2968             psFree(md);
    2969             exit(EXIT_FAILURE);
    2970         }
    2971 
    2972         object = skyCellObjectFromMetadata(md);
    2973         if (!object) {
    2974             psFree(md);
    2975             exit(EXIT_FAILURE);
    2976         }
    2977 
    2978         psFree(md);
    2979 
    2980         if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
    2981             psFree(object);
    2982             exit(EXIT_FAILURE);
    2983         }
    2984         if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
    2985             psFree(object);
    2986             exit(EXIT_FAILURE);
    2987         }
    2988         if (!object->ra1 == 64.64) {
    2989             psFree(object);
    2990             exit(EXIT_FAILURE);
    2991         }
    2992         if (!object->decl1 == 64.64) {
    2993             psFree(object);
    2994             exit(EXIT_FAILURE);
    2995         }
    2996         if (!object->ra2 == 64.64) {
    2997             psFree(object);
    2998             exit(EXIT_FAILURE);
    2999         }
    3000         if (!object->decl2 == 64.64) {
    3001             psFree(object);
    3002             exit(EXIT_FAILURE);
    3003         }
    3004         if (!object->ra3 == 64.64) {
    3005             psFree(object);
    3006             exit(EXIT_FAILURE);
    3007         }
    3008         if (!object->decl3 == 64.64) {
    3009             psFree(object);
    3010             exit(EXIT_FAILURE);
    3011         }
    3012         if (!object->ra4 == 64.64) {
    3013             psFree(object);
    3014             exit(EXIT_FAILURE);
    3015         }
    3016         if (!object->decl4 == 64.64) {
    3017             psFree(object);
    3018             exit(EXIT_FAILURE);
    3019         }
    3020 
    3021         psFree(object);
    3022     }
    3023 
    3024     {
    3025         psMetadata      *md;
    3026         skyCellMapRow   *object;
    3027 
    3028         md = psMetadataAlloc();
    3029         if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {
    3030             psFree(md);
    3031             exit(EXIT_FAILURE);
    3032         }
    3033         if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {
    3034             psFree(md);
    3035             exit(EXIT_FAILURE);
    3036         }
    3037         if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) {
    3038             psFree(md);
    3039             exit(EXIT_FAILURE);
    3040         }
    3041         if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) {
    3042             psFree(md);
    3043             exit(EXIT_FAILURE);
    3044         }
    3045 
    3046         object = skyCellMapObjectFromMetadata(md);
    3047         if (!object) {
    3048             psFree(md);
    3049             exit(EXIT_FAILURE);
    3050         }
    3051 
    3052         psFree(md);
    3053 
    3054         if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
    3055             psFree(object);
    3056             exit(EXIT_FAILURE);
    3057         }
    3058         if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
    3059             psFree(object);
    3060             exit(EXIT_FAILURE);
    3061         }
    3062         if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) {
    3063             psFree(object);
    3064             exit(EXIT_FAILURE);
    3065         }
    3066         if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {
    30672779            psFree(object);
    30682780            exit(EXIT_FAILURE);
  • trunk/ippdb/tests/selectrowsfits.c

    r11720 r11780  
    747747        }
    748748
     749        if (!p4SkyCellMapSelectRowsFits(dbh, fits, NULL, 1)) {
     750            exit(EXIT_FAILURE);
     751        }
     752
     753        psFree(fits);
     754        psDBCleanup(dbh);
     755    }
     756
     757    {
     758        psDB            *dbh;
     759        psFits          *fits;
     760
     761        dbh = psDBInit("localhost", "test", NULL, "test");
     762        if (!dbh) {
     763            exit(EXIT_FAILURE);
     764        }
     765
     766        fits = psFitsOpen(TMP_FILENAME, "w");
     767        if (!fits) {
     768            exit(EXIT_FAILURE);
     769        }
     770
    749771        if (!p4ScfileSelectRowsFits(dbh, fits, NULL, 1)) {
    750             exit(EXIT_FAILURE);
    751         }
    752 
    753         psFree(fits);
    754         psDBCleanup(dbh);
    755     }
    756 
    757     {
    758         psDB            *dbh;
    759         psFits          *fits;
    760 
    761         dbh = psDBInit("localhost", "test", NULL, "test");
    762         if (!dbh) {
    763             exit(EXIT_FAILURE);
    764         }
    765 
    766         fits = psFitsOpen(TMP_FILENAME, "w");
    767         if (!fits) {
    768             exit(EXIT_FAILURE);
    769         }
    770 
    771         if (!p4InputScfileSelectRowsFits(dbh, fits, NULL, 1)) {
    772             exit(EXIT_FAILURE);
    773         }
    774 
    775         psFree(fits);
    776         psDBCleanup(dbh);
    777     }
    778 
    779     {
    780         psDB            *dbh;
    781         psFits          *fits;
    782 
    783         dbh = psDBInit("localhost", "test", NULL, "test");
    784         if (!dbh) {
    785             exit(EXIT_FAILURE);
    786         }
    787 
    788         fits = psFitsOpen(TMP_FILENAME, "w");
    789         if (!fits) {
    790             exit(EXIT_FAILURE);
    791         }
    792 
    793         if (!p4DiffScfileSelectRowsFits(dbh, fits, NULL, 1)) {
    794             exit(EXIT_FAILURE);
    795         }
    796 
    797         psFree(fits);
    798         psDBCleanup(dbh);
    799     }
    800 
    801     {
    802         psDB            *dbh;
    803         psFits          *fits;
    804 
    805         dbh = psDBInit("localhost", "test", NULL, "test");
    806         if (!dbh) {
    807             exit(EXIT_FAILURE);
    808         }
    809 
    810         fits = psFitsOpen(TMP_FILENAME, "w");
    811         if (!fits) {
    812             exit(EXIT_FAILURE);
    813         }
    814 
    815         if (!p4MagicMaskImfileSelectRowsFits(dbh, fits, NULL, 1)) {
    816             exit(EXIT_FAILURE);
    817         }
    818 
    819         psFree(fits);
    820         psDBCleanup(dbh);
    821     }
    822 
    823     {
    824         psDB            *dbh;
    825         psFits          *fits;
    826 
    827         dbh = psDBInit("localhost", "test", NULL, "test");
    828         if (!dbh) {
    829             exit(EXIT_FAILURE);
    830         }
    831 
    832         fits = psFitsOpen(TMP_FILENAME, "w");
    833         if (!fits) {
    834             exit(EXIT_FAILURE);
    835         }
    836 
    837         if (!skyCellSelectRowsFits(dbh, fits, NULL, 1)) {
    838             exit(EXIT_FAILURE);
    839         }
    840 
    841         psFree(fits);
    842         psDBCleanup(dbh);
    843     }
    844 
    845     {
    846         psDB            *dbh;
    847         psFits          *fits;
    848 
    849         dbh = psDBInit("localhost", "test", NULL, "test");
    850         if (!dbh) {
    851             exit(EXIT_FAILURE);
    852         }
    853 
    854         fits = psFitsOpen(TMP_FILENAME, "w");
    855         if (!fits) {
    856             exit(EXIT_FAILURE);
    857         }
    858 
    859         if (!skyCellMapSelectRowsFits(dbh, fits, NULL, 1)) {
    860772            exit(EXIT_FAILURE);
    861773        }
Note: See TracChangeset for help on using the changeset viewer.