IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9149


Ignore:
Timestamp:
Oct 3, 2006, 12:09:49 PM (20 years ago)
Author:
jhoblitt
Message:

VERSION 0.0.40

Location:
trunk
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/dbconfig/config.md

    r9107 r9149  
    22    pkg_name        STR     ippdb
    33    pkg_namespace   STR     ippdb
    4     pkg_version     STR     0.0.39
     4    pkg_version     STR     0.0.40
    55END
  • trunk/ippdb/Makefile.am

    r9107 r9149  
    3939    $(top_builddir)/docs/man/man3/detNormalizedStatImfileRow.3 \
    4040    $(top_builddir)/docs/man/man3/detNormalizedImfileRow.3 \
     41    $(top_builddir)/docs/man/man3/detNormalizedExpRow.3 \
    4142    $(top_builddir)/docs/man/man3/detMasterFrameRow.3 \
    4243    $(top_builddir)/docs/man/man3/detMasterImfileRow.3 \
     
    4647
    4748
    48 docs/man/man3/ippdb.3 docs/man/man3/weatherRow.3 docs/man/man3/skyp_transparencyRow.3 docs/man/man3/skyp_absorptionRow.3 docs/man/man3/skyp_emissionRow.3 docs/man/man3/dimmRow.3 docs/man/man3/skyp_irRow.3 docs/man/man3/domeRow.3 docs/man/man3/telescopeRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawDetrendExpRow.3 docs/man/man3/rawScienceExpRow.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/p2ProcessedImfileRow.3 docs/man/man3/p3PendingExpRow.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/detMasterFrameRow.3 docs/man/man3/detMasterImfileRow.3 docs/man/man3/detResidImfileRow.3 docs/man/man3/detResidExpRow.3 docs/man/man3/detRunSummaryRow.3:
     49docs/man/man3/ippdb.3 docs/man/man3/weatherRow.3 docs/man/man3/skyp_transparencyRow.3 docs/man/man3/skyp_absorptionRow.3 docs/man/man3/skyp_emissionRow.3 docs/man/man3/dimmRow.3 docs/man/man3/skyp_irRow.3 docs/man/man3/domeRow.3 docs/man/man3/telescopeRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawDetrendExpRow.3 docs/man/man3/rawScienceExpRow.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/p2ProcessedImfileRow.3 docs/man/man3/p3PendingExpRow.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/detMasterFrameRow.3 docs/man/man3/detMasterImfileRow.3 docs/man/man3/detResidImfileRow.3 docs/man/man3/detResidExpRow.3 docs/man/man3/detRunSummaryRow.3:
    4950        $(DOXYGEN)
    5051
  • trunk/ippdb/configure.ac

    r9107 r9149  
    77AC_PREREQ(2.59)
    88
    9 AC_INIT([ippdb], [0.0.39], [pan-starrs.ifa.hawaii.edu])
     9AC_INIT([ippdb], [0.0.40], [pan-starrs.ifa.hawaii.edu])
    1010AC_CONFIG_SRCDIR([ippdb.pc.in])
    1111
  • trunk/ippdb/src/ippdb.c

    r9107 r9149  
    7171#define DETNORMALIZEDIMFILE_TABLE_NAME "detNormalizedImfile"
    7272#define DETNORMALIZEDIMFILE_INDEX_NAME IPPDB_DEFAULT_INDEX_NAME
     73#define DETNORMALIZEDEXP_TABLE_NAME "detNormalizedExp"
     74#define DETNORMALIZEDEXP_INDEX_NAME IPPDB_DEFAULT_INDEX_NAME
    7375#define DETMASTERFRAME_TABLE_NAME "detMasterFrame"
    7476#define DETMASTERFRAME_INDEX_NAME IPPDB_DEFAULT_INDEX_NAME
     
    1642916431    return true;
    1643016432}
     16433static void detNormalizedExpRowFree(detNormalizedExpRow *object);
     16434
     16435detNormalizedExpRow *detNormalizedExpRowAlloc(psS32 det_id, psS32 iteration, const char *recipe, psF64 bg, psF64 bg_stdev, psF64 bg_mean_stdev, const char *b1_uri, const char *b2_uri)
     16436{
     16437    detNormalizedExpRow *object;
     16438
     16439    object = psAlloc(sizeof(detNormalizedExpRow));
     16440    psMemSetDeallocator(object, (psFreeFunc)detNormalizedExpRowFree);
     16441
     16442    object->det_id = det_id;
     16443    object->iteration = iteration;
     16444    object->recipe = psStringCopy(recipe);
     16445    object->bg = bg;
     16446    object->bg_stdev = bg_stdev;
     16447    object->bg_mean_stdev = bg_mean_stdev;
     16448    object->b1_uri = psStringCopy(b1_uri);
     16449    object->b2_uri = psStringCopy(b2_uri);
     16450
     16451    return object;
     16452}
     16453
     16454static void detNormalizedExpRowFree(detNormalizedExpRow *object)
     16455{
     16456    psFree(object->recipe);
     16457    psFree(object->b1_uri);
     16458    psFree(object->b2_uri);
     16459}
     16460
     16461bool detNormalizedExpCreateTable(psDB *dbh)
     16462{
     16463    psMetadata      *md;
     16464    bool            status;
     16465
     16466    md = psMetadataAlloc();
     16467    if (!psMetadataAdd(md, PS_LIST_TAIL, DETNORMALIZEDEXP_INDEX_NAME, PS_DATA_S32, "AUTO_INCREMENT", 0.0)) {
     16468        psError(PS_ERR_UNKNOWN, false, "failed to add item %s", DETNORMALIZEDEXP_INDEX_NAME);
     16469        psFree(md);
     16470        return false;
     16471    }
     16472    if (!psMetadataAddS32(md, PS_LIST_TAIL, "det_id", 0, "Primary Key", 0)) {
     16473        psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
     16474        psFree(md);
     16475        return false;
     16476    }
     16477    if (!psMetadataAddS32(md, PS_LIST_TAIL, "iteration", 0, "Primary Key", 0)) {
     16478        psError(PS_ERR_UNKNOWN, false, "failed to add item iteration");
     16479        psFree(md);
     16480        return false;
     16481    }
     16482    if (!psMetadataAddStr(md, PS_LIST_TAIL, "recipe", 0, NULL, "64")) {
     16483        psError(PS_ERR_UNKNOWN, false, "failed to add item recipe");
     16484        psFree(md);
     16485        return false;
     16486    }
     16487    if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 0.0)) {
     16488        psError(PS_ERR_UNKNOWN, false, "failed to add item bg");
     16489        psFree(md);
     16490        return false;
     16491    }
     16492    if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, 0.0)) {
     16493        psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev");
     16494        psFree(md);
     16495        return false;
     16496    }
     16497    if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_mean_stdev", 0, NULL, 0.0)) {
     16498        psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev");
     16499        psFree(md);
     16500        return false;
     16501    }
     16502    if (!psMetadataAddStr(md, PS_LIST_TAIL, "b1_uri", 0, NULL, "64")) {
     16503        psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri");
     16504        psFree(md);
     16505        return false;
     16506    }
     16507    if (!psMetadataAddStr(md, PS_LIST_TAIL, "b2_uri", 0, NULL, "64")) {
     16508        psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri");
     16509        psFree(md);
     16510        return false;
     16511    }
     16512
     16513    status = psDBCreateTable(dbh, DETNORMALIZEDEXP_TABLE_NAME, md);
     16514
     16515    psFree(md);
     16516
     16517    return status;
     16518}
     16519
     16520bool detNormalizedExpDropTable(psDB *dbh)
     16521{
     16522    return psDBDropTable(dbh, DETNORMALIZEDEXP_TABLE_NAME);
     16523}
     16524
     16525bool detNormalizedExpInsert(psDB * dbh, psS32 det_id, psS32 iteration, const char *recipe, psF64 bg, psF64 bg_stdev, psF64 bg_mean_stdev, const char *b1_uri, const char *b2_uri)
     16526{
     16527    psMetadata      *md;
     16528    bool            status;
     16529
     16530    md = psMetadataAlloc();
     16531    if (!psMetadataAddS32(md, PS_LIST_TAIL, "det_id", 0, NULL, det_id)) {
     16532        psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
     16533        psFree(md);
     16534        return false;
     16535    }
     16536    if (!psMetadataAddS32(md, PS_LIST_TAIL, "iteration", 0, NULL, iteration)) {
     16537        psError(PS_ERR_UNKNOWN, false, "failed to add item iteration");
     16538        psFree(md);
     16539        return false;
     16540    }
     16541    if (!psMetadataAddStr(md, PS_LIST_TAIL, "recipe", 0, NULL, recipe)) {
     16542        psError(PS_ERR_UNKNOWN, false, "failed to add item recipe");
     16543        psFree(md);
     16544        return false;
     16545    }
     16546    if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, bg)) {
     16547        psError(PS_ERR_UNKNOWN, false, "failed to add item bg");
     16548        psFree(md);
     16549        return false;
     16550    }
     16551    if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, bg_stdev)) {
     16552        psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev");
     16553        psFree(md);
     16554        return false;
     16555    }
     16556    if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_mean_stdev", 0, NULL, bg_mean_stdev)) {
     16557        psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev");
     16558        psFree(md);
     16559        return false;
     16560    }
     16561    if (!psMetadataAddStr(md, PS_LIST_TAIL, "b1_uri", 0, NULL, b1_uri)) {
     16562        psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri");
     16563        psFree(md);
     16564        return false;
     16565    }
     16566    if (!psMetadataAddStr(md, PS_LIST_TAIL, "b2_uri", 0, NULL, b2_uri)) {
     16567        psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri");
     16568        psFree(md);
     16569        return false;
     16570    }
     16571
     16572    status = psDBInsertOneRow(dbh, DETNORMALIZEDEXP_TABLE_NAME, md);
     16573    psFree(md);
     16574
     16575    return status;
     16576}
     16577
     16578long long detNormalizedExpDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
     16579{
     16580    long long       deleted = 0;
     16581
     16582    long long count = psDBDeleteRows(dbh, DETNORMALIZEDEXP_TABLE_NAME, where, limit);
     16583    if (count < 0) {
     16584        psError(PS_ERR_UNKNOWN, true, "failed to delete row from detNormalizedExp");
     16585        return count;
     16586
     16587        deleted += count;
     16588    }
     16589
     16590    return deleted;
     16591}
     16592bool detNormalizedExpPop(psDB *dbh, psS32 *det_id, psS32 *iteration, char **recipe, psF64 *bg, psF64 *bg_stdev, psF64 *bg_mean_stdev, char **b1_uri, char **b2_uri)
     16593{
     16594    psArray         *rowSet;
     16595    psMetadata      *row;
     16596    psMetadata      *popped;
     16597    long            deleted;
     16598    bool            status;
     16599    int             rowID;
     16600
     16601    rowSet = psDBSelectRows(dbh, DETNORMALIZEDEXP_TABLE_NAME, NULL, 1);
     16602    if (!rowSet) {
     16603        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item %s", DETNORMALIZEDEXP_INDEX_NAME);
     16604        psFree(rowSet);
     16605        return NULL;
     16606    }
     16607
     16608    row = psArrayGet(rowSet, 0);
     16609    psMemIncrRefCounter(row);
     16610    if (!row) {
     16611        psError(PS_ERR_UNKNOWN, true, "database error or table is empty");
     16612        return NULL;
     16613    }
     16614    psFree(rowSet);
     16615
     16616    rowID = psMetadataLookupS32(&status, row, DETNORMALIZEDEXP_INDEX_NAME);
     16617    if (!status) {
     16618        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item %s", DETNORMALIZEDEXP_INDEX_NAME);
     16619        psFree(row);
     16620        return NULL;
     16621    }
     16622
     16623    popped = psMetadataAlloc();
     16624    psMetadataAddS32(popped, PS_LIST_TAIL, DETNORMALIZEDEXP_INDEX_NAME, 0, NULL, rowID);
     16625
     16626    deleted = psDBDeleteRows(dbh, DETNORMALIZEDEXP_TABLE_NAME, popped, 0);
     16627    if (deleted != 1) {
     16628        psError(PS_ERR_UNKNOWN, false, "database failed to delete row");
     16629        psFree(popped);
     16630        psFree(row);
     16631        return NULL;
     16632    }
     16633
     16634    psFree(popped);
     16635
     16636    *det_id = psMetadataLookupS32(&status, row, "det_id");
     16637    if (!status) {
     16638        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item det_id");
     16639        psFree(row);
     16640        return false;
     16641    }
     16642    *iteration = psMetadataLookupS32(&status, row, "iteration");
     16643    if (!status) {
     16644        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item iteration");
     16645        psFree(row);
     16646        return false;
     16647    }
     16648    *recipe = psMetadataLookupPtr(&status, row, "recipe");
     16649    if (!status) {
     16650        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item recipe");
     16651        psFree(row);
     16652        return false;
     16653    }
     16654    *bg = psMetadataLookupF64(&status, row, "bg");
     16655    if (!status) {
     16656        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg");
     16657        psFree(row);
     16658        return false;
     16659    }
     16660    *bg_stdev = psMetadataLookupF64(&status, row, "bg_stdev");
     16661    if (!status) {
     16662        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_stdev");
     16663        psFree(row);
     16664        return false;
     16665    }
     16666    *bg_mean_stdev = psMetadataLookupF64(&status, row, "bg_mean_stdev");
     16667    if (!status) {
     16668        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_mean_stdev");
     16669        psFree(row);
     16670        return false;
     16671    }
     16672    *b1_uri = psMetadataLookupPtr(&status, row, "b1_uri");
     16673    if (!status) {
     16674        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b1_uri");
     16675        psFree(row);
     16676        return false;
     16677    }
     16678    *b2_uri = psMetadataLookupPtr(&status, row, "b2_uri");
     16679    if (!status) {
     16680        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b2_uri");
     16681        psFree(row);
     16682        return false;
     16683    }
     16684
     16685    psFree(row);
     16686
     16687    return true;
     16688}
     16689
     16690bool detNormalizedExpInsertObject(psDB *dbh, detNormalizedExpRow *object)
     16691{
     16692    return detNormalizedExpInsert(dbh, object->det_id, object->iteration, object->recipe, object->bg, object->bg_stdev, object->bg_mean_stdev, object->b1_uri, object->b2_uri);
     16693}
     16694
     16695bool detNormalizedExpInsertObjects(psDB *dbh, psArray *objects)
     16696{
     16697    for (long i = 0; i < psArrayLength(objects); i++) {
     16698        if (!detNormalizedExpInsertObject(dbh, objects->data[i])) {
     16699            return false;
     16700        }
     16701    }
     16702
     16703    return true;
     16704}
     16705
     16706detNormalizedExpRow *detNormalizedExpPopObject(psDB *dbh)
     16707{
     16708    psS32           det_id;
     16709    psS32           iteration;
     16710    char            recipe[256];
     16711    psF64           bg;
     16712    psF64           bg_stdev;
     16713    psF64           bg_mean_stdev;
     16714    char            b1_uri[256];
     16715    char            b2_uri[256];
     16716
     16717    if (!detNormalizedExpPop(dbh, &det_id, &iteration, (char **)&recipe, &bg, &bg_stdev, &bg_mean_stdev, (char **)&b1_uri, (char **)&b2_uri)) {
     16718        psError(PS_ERR_UNKNOWN, false, "failed to pop a database row");
     16719        return NULL;
     16720    }
     16721
     16722    return detNormalizedExpRowAlloc(det_id, iteration, recipe, bg, bg_stdev, bg_mean_stdev, b1_uri, b2_uri);
     16723}
     16724
     16725bool detNormalizedExpInsertFits(psDB *dbh, const psFits *fits)
     16726{
     16727    psArray         *rowSet;
     16728
     16729    // move to (the first?) extension named  DETNORMALIZEDEXP_TABLE_NAME
     16730    if (!psFitsMoveExtName(fits, DETNORMALIZEDEXP_TABLE_NAME)) {
     16731        psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", DETNORMALIZEDEXP_TABLE_NAME);
     16732        return false;
     16733    }
     16734
     16735    // check HDU type
     16736    if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
     16737        psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
     16738        return false;
     16739    }
     16740
     16741    // read fits table
     16742    rowSet = psFitsReadTable(fits);
     16743    if (!rowSet) {
     16744        psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
     16745        psFree(rowSet);
     16746        return false;
     16747    }
     16748
     16749    if (!psDBInsertRows(dbh, DETNORMALIZEDEXP_TABLE_NAME, rowSet)) {
     16750        psError(PS_ERR_UNKNOWN, false, "databse insert failed");
     16751        psFree(rowSet);
     16752        return false;
     16753    }
     16754
     16755    psFree(rowSet);
     16756
     16757    return true;
     16758}
     16759
     16760bool detNormalizedExpPopFits(psDB *dbh, psFits *fits, unsigned long long limit)
     16761{
     16762    char            query[MAX_STRING_LENGTH];
     16763
     16764    if (!detNormalizedExpSelectRowsFits(dbh, fits, NULL, limit)) {
     16765        psError(PS_ERR_UNKNOWN, true, "database error or table is empty");
     16766        return false;
     16767    }
     16768
     16769    // remove limit rows from the end of the database
     16770    if (snprintf(query, MAX_STRING_LENGTH,
     16771                "DELETE FROM %s ORDER BY %s DESC LIMIT %lld",
     16772                DETNORMALIZEDEXP_TABLE_NAME, DETNORMALIZEDEXP_INDEX_NAME, limit) < 0) {
     16773        psError(PS_ERR_UNKNOWN, true, "query value attempted to exceed %d bytes", MAX_STRING_LENGTH);
     16774        return false;
     16775    }
     16776           
     16777    if (!p_psDBRunQuery(dbh, query)) {
     16778        psError(PS_ERR_UNKNOWN, false, "database query failed");
     16779        return false;
     16780    }
     16781
     16782    return true;
     16783}
     16784
     16785bool detNormalizedExpSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
     16786{
     16787    psArray         *rowSet;
     16788    psU64           i;
     16789
     16790    rowSet = psDBSelectRows(dbh, DETNORMALIZEDEXP_TABLE_NAME, where, limit);
     16791    if (!rowSet) {
     16792        return false;
     16793    }
     16794
     16795    // strip index column
     16796    for (i = 0; i < rowSet->n; i++) {
     16797        if (!psMetadataRemove((psMetadata *)rowSet->data[i], 0, DETNORMALIZEDEXP_INDEX_NAME)) {
     16798            psError(PS_ERR_UNKNOWN, true, "failed to remove item %s", DETNORMALIZEDEXP_INDEX_NAME);
     16799            psFree(rowSet);
     16800            return false;
     16801        }
     16802    }
     16803
     16804    // output to fits
     16805    if (!psFitsWriteTable(fits, NULL, rowSet, DETNORMALIZEDEXP_TABLE_NAME)) {
     16806        psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
     16807        psFree(rowSet);
     16808        return false;
     16809    }
     16810
     16811    psFree(rowSet);
     16812
     16813    return true;
     16814}
     16815
     16816psMetadata *detNormalizedExpMetadataFromObject(const detNormalizedExpRow *object)
     16817{
     16818    psMetadata      *md;
     16819
     16820    md = psMetadataAlloc();
     16821    if (!psMetadataAddS32(md, PS_LIST_TAIL, "det_id", 0, NULL, object->det_id)) {
     16822        psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
     16823        psFree(md);
     16824        return NULL;
     16825    }
     16826    if (!psMetadataAddS32(md, PS_LIST_TAIL, "iteration", 0, NULL, object->iteration)) {
     16827        psError(PS_ERR_UNKNOWN, false, "failed to add item iteration");
     16828        psFree(md);
     16829        return NULL;
     16830    }
     16831    if (!psMetadataAddStr(md, PS_LIST_TAIL, "recipe", 0, NULL, object->recipe)) {
     16832        psError(PS_ERR_UNKNOWN, false, "failed to add item recipe");
     16833        psFree(md);
     16834        return NULL;
     16835    }
     16836    if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, object->bg)) {
     16837        psError(PS_ERR_UNKNOWN, false, "failed to add item bg");
     16838        psFree(md);
     16839        return NULL;
     16840    }
     16841    if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, object->bg_stdev)) {
     16842        psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev");
     16843        psFree(md);
     16844        return NULL;
     16845    }
     16846    if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_mean_stdev", 0, NULL, object->bg_mean_stdev)) {
     16847        psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev");
     16848        psFree(md);
     16849        return NULL;
     16850    }
     16851    if (!psMetadataAddStr(md, PS_LIST_TAIL, "b1_uri", 0, NULL, object->b1_uri)) {
     16852        psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri");
     16853        psFree(md);
     16854        return NULL;
     16855    }
     16856    if (!psMetadataAddStr(md, PS_LIST_TAIL, "b2_uri", 0, NULL, object->b2_uri)) {
     16857        psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri");
     16858        psFree(md);
     16859        return NULL;
     16860    }
     16861
     16862    return md;
     16863}
     16864
     16865detNormalizedExpRow *detNormalizedExpObjectFromMetadata(psMetadata *md)
     16866{
     16867    bool            status;
     16868    psS32           det_id;
     16869    psS32           iteration;
     16870    char            *recipe;
     16871    psF64           bg;
     16872    psF64           bg_stdev;
     16873    psF64           bg_mean_stdev;
     16874    char            *b1_uri;
     16875    char            *b2_uri;
     16876
     16877    det_id = psMetadataLookupS32(&status, md, "det_id");
     16878    if (!status) {
     16879        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item det_id");
     16880        return false;
     16881    }
     16882    iteration = psMetadataLookupS32(&status, md, "iteration");
     16883    if (!status) {
     16884        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item iteration");
     16885        return false;
     16886    }
     16887    recipe = psMetadataLookupPtr(&status, md, "recipe");
     16888    if (!status) {
     16889        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item recipe");
     16890        return false;
     16891    }
     16892    bg = psMetadataLookupF64(&status, md, "bg");
     16893    if (!status) {
     16894        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg");
     16895        return false;
     16896    }
     16897    bg_stdev = psMetadataLookupF64(&status, md, "bg_stdev");
     16898    if (!status) {
     16899        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_stdev");
     16900        return false;
     16901    }
     16902    bg_mean_stdev = psMetadataLookupF64(&status, md, "bg_mean_stdev");
     16903    if (!status) {
     16904        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_mean_stdev");
     16905        return false;
     16906    }
     16907    b1_uri = psMetadataLookupPtr(&status, md, "b1_uri");
     16908    if (!status) {
     16909        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b1_uri");
     16910        return false;
     16911    }
     16912    b2_uri = psMetadataLookupPtr(&status, md, "b2_uri");
     16913    if (!status) {
     16914        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b2_uri");
     16915        return false;
     16916    }
     16917
     16918    return detNormalizedExpRowAlloc(det_id, iteration, recipe, bg, bg_stdev, bg_mean_stdev, b1_uri, b2_uri);
     16919}
     16920psArray *detNormalizedExpSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
     16921{
     16922    psArray         *rowSet;
     16923    psArray         *returnSet;
     16924    psU64           i;
     16925
     16926    rowSet = psDBSelectRows(dbh, DETNORMALIZEDEXP_TABLE_NAME, where, limit);
     16927    if (!rowSet) {
     16928        return NULL;
     16929    }
     16930
     16931    // strip index column
     16932    for (i = 0; i < rowSet->n; i++) {
     16933        if (!psMetadataRemove((psMetadata *)(rowSet->data[i]), 0, DETNORMALIZEDEXP_INDEX_NAME)) {
     16934            psError(PS_ERR_UNKNOWN, true, "failed to remove item %s", DETNORMALIZEDEXP_INDEX_NAME);
     16935            psFree(rowSet);
     16936            return false;
     16937        }
     16938    }
     16939
     16940    // convert psMetadata rows to row objects
     16941
     16942    returnSet = psArrayAlloc(rowSet->n);
     16943    returnSet->n = 0;
     16944
     16945    for (i = 0; i < rowSet->n; i++) {
     16946        detNormalizedExpRow *object = detNormalizedExpObjectFromMetadata(rowSet->data[i]);
     16947        psArrayAdd(returnSet, 0, object);
     16948        psFree(object);
     16949    }
     16950
     16951    psFree(rowSet);
     16952
     16953    return returnSet;
     16954}
     16955bool detNormalizedExpDeleteObject(psDB *dbh, const detNormalizedExpRow *object)
     16956{
     16957    psMetadata *where = detNormalizedExpMetadataFromObject(object);
     16958    long long count = psDBDeleteRows(dbh, DETNORMALIZEDEXP_TABLE_NAME, where, 0);
     16959    psFree(where)
     16960    if (count < 0) {
     16961        psError(PS_ERR_UNKNOWN, true, "failed to delete row from detNormalizedExp");
     16962        return false;
     16963    }
     16964    if (count > 1) {
     16965        // XXX should this be a psAbort() instead?  It is possible that
     16966        // having an object match multiple rows was by design.
     16967        psError(PS_ERR_UNKNOWN, true, "detNormalizedExpRow object matched more then one row.  Check your database schema");
     16968        return false;
     16969    }
     16970
     16971    return true;
     16972}
     16973long long detNormalizedExpDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
     16974{
     16975    long long       deleted = 0;
     16976
     16977    for (long long i = 0; i < objects->n; i++) {
     16978        detNormalizedExpRow *object = objects->data[i];
     16979        psMetadata *where = detNormalizedExpMetadataFromObject(object);
     16980        long long count = psDBDeleteRows(dbh, DETNORMALIZEDEXP_TABLE_NAME, where, limit);
     16981        psFree(where)
     16982        if (count < 0) {
     16983            psError(PS_ERR_UNKNOWN, true, "failed to delete row from detNormalizedExp");
     16984            return count;
     16985        }
     16986
     16987        deleted += count;
     16988    }
     16989
     16990    return deleted;
     16991}
     16992bool detNormalizedExpPrintObjects(FILE *stream, psArray *objects, bool mdcf)
     16993{
     16994    PS_ASSERT_PTR_NON_NULL(objects, false);
     16995
     16996    psMetadata *output = psMetadataAlloc();
     16997    for (long i = 0; i < psArrayLength(objects); i++) {
     16998        psMetadata *md = detNormalizedExpMetadataFromObject(objects->data[i]);
     16999        if (!psMetadataAddMetadata(
     17000            output,
     17001            PS_LIST_TAIL,
     17002            DETNORMALIZEDEXP_TABLE_NAME,
     17003            PS_META_DUPLICATE_OK,
     17004            NULL,
     17005            md
     17006        )) {
     17007            psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
     17008            psFree(md);
     17009            psFree(output);
     17010            return false;
     17011        }
     17012        psFree(md);
     17013    }
     17014
     17015    if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
     17016        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
     17017        psFree(output);
     17018    }
     17019    psFree(output);
     17020
     17021    return true;
     17022}
    1643117023static void detMasterFrameRowFree(detMasterFrameRow *object);
    1643217024
  • trunk/ippdb/src/ippdb.h

    r9107 r9149  
    70247024    bool            mdcf                ///< format as mdconfig or simple
    70257025);
     7026/** detNormalizedExpRow data structure
     7027 *
     7028 * Structure for representing a single row of detNormalizedExp table data.
     7029 */
     7030
     7031typedef struct {
     7032    psS32           det_id;
     7033    psS32           iteration;
     7034    char            *recipe;
     7035    psF64           bg;
     7036    psF64           bg_stdev;
     7037    psF64           bg_mean_stdev;
     7038    char            *b1_uri;
     7039    char            *b2_uri;
     7040} detNormalizedExpRow;
     7041
     7042/** Creates a new detNormalizedExpRow object
     7043 *
     7044 *  @return A new detNormalizedExpRow object or NULL on failure.
     7045 */
     7046
     7047detNormalizedExpRow *detNormalizedExpRowAlloc(
     7048    psS32           det_id,
     7049    psS32           iteration,
     7050    const char      *recipe,
     7051    psF64           bg,
     7052    psF64           bg_stdev,
     7053    psF64           bg_mean_stdev,
     7054    const char      *b1_uri,
     7055    const char      *b2_uri
     7056);
     7057
     7058/** Creates a new detNormalizedExp table
     7059 *
     7060 * @return true on success
     7061 */
     7062
     7063bool detNormalizedExpCreateTable(
     7064    psDB            *dbh                ///< Database handle
     7065);
     7066
     7067/** Deletes a detNormalizedExp table
     7068 *
     7069 * @return true on success
     7070 */
     7071
     7072bool detNormalizedExpDropTable(
     7073    psDB            *dbh                ///< Database handle
     7074);
     7075
     7076/** Insert a single row into a table
     7077 *
     7078 * This function constructs and inserts a single row based on it's parameters.
     7079 *
     7080 * @return true on success
     7081 */
     7082
     7083bool detNormalizedExpInsert(
     7084    psDB            *dbh,               ///< Database handle
     7085    psS32           det_id,
     7086    psS32           iteration,
     7087    const char      *recipe,
     7088    psF64           bg,
     7089    psF64           bg_stdev,
     7090    psF64           bg_mean_stdev,
     7091    const char      *b1_uri,
     7092    const char      *b2_uri
     7093);
     7094
     7095/** Deletes up to limit rows from the database and returns the number of rows actually deleted.
     7096 *
     7097 * @return A The number of rows removed or a negative value on error
     7098 */
     7099
     7100long long detNormalizedExpDelete(
     7101    psDB            *dbh,               ///< Database handle
     7102    const psMetadata *where,            ///< Row match criteria
     7103    unsigned long long limit            ///< Maximum number of elements to delete
     7104);
     7105
     7106/** Removes the last row from the database and returns it
     7107 *
     7108 * @return true on success
     7109 */
     7110
     7111bool detNormalizedExpPop(
     7112    psDB            *dbh,               ///< Database handle
     7113    psS32           *det_id,
     7114    psS32           *iteration,
     7115    char            **recipe,
     7116    psF64           *bg,
     7117    psF64           *bg_stdev,
     7118    psF64           *bg_mean_stdev,
     7119    char            **b1_uri,
     7120    char            **b2_uri
     7121);
     7122
     7123/** Insert a single detNormalizedExpRow object into a table
     7124 *
     7125 * This function constructs and inserts a single row based on it's parameters.
     7126 *
     7127 * @return true on success
     7128 */
     7129
     7130bool detNormalizedExpInsertObject(
     7131    psDB            *dbh,               ///< Database handle
     7132    detNormalizedExpRow *object             ///< detNormalizedExpRow object
     7133);
     7134
     7135/** Insert an array of detNormalizedExpRow object into a table
     7136 *
     7137 * This function constructs and inserts multiple rows based on it's parameters.
     7138 *
     7139 * @return true on success
     7140 */
     7141
     7142bool detNormalizedExpInsertObjects(
     7143    psDB            *dbh,               ///< Database handle
     7144    psArray         *objects            ///< array of detNormalizedExpRow objects
     7145);
     7146
     7147/** Removes the last row from the database and returns it
     7148 *
     7149 * @return A new detNormalizedExpRow on success or NULL on failure.
     7150 */
     7151
     7152detNormalizedExpRow *detNormalizedExpPopObject(
     7153    psDB            *dbh                ///< Database handle
     7154);
     7155
     7156/** Insert data from a binary FITS table detNormalizedExpRow into the database
     7157 *
     7158 * This function expects a psFits object with a FITS table as the first
     7159 * extension.  The table must have at least one row of data in it, that is of
     7160 * the appropriate format (number of columns and their type).  All other
     7161 * extensions are ignored.
     7162 *
     7163 * @return true on success
     7164 */
     7165
     7166bool detNormalizedExpInsertFits(
     7167    psDB            *dbh,               ///< Database handle
     7168    const psFits    *fits               ///< psFits object
     7169);
     7170
     7171/** Removes the last limit row from the database and returns them in a binary FITS table.
     7172 *
     7173 * This function assumes an empty psFits object and will create a FITS table as
     7174 * the first extension.
     7175 *
     7176 * @return true on success
     7177 */
     7178
     7179bool detNormalizedExpPopFits(
     7180    psDB            *dbh,               ///< Database handle
     7181    psFits          *fits,              ///< psFits object
     7182    unsigned long long limit            ///< Maximum number of elements to return
     7183);
     7184
     7185/** Selects up to limit from the database and returns them in a binary FITS table
     7186 *
     7187 * This function assumes an empty psFits object and will create a FITS table
     7188 * as the first extension.
     7189 *
     7190 *  See psDBSelectRows() for documentation on the format of where.
     7191 *
     7192 * @return true on success
     7193 */
     7194
     7195bool detNormalizedExpSelectRowsFits(
     7196    psDB            *dbh,               ///< Database handle
     7197    psFits          *fits,              ///< psFits object
     7198    const psMetadata *where,            ///< Row match criteria
     7199    unsigned long long limit            ///< Maximum number of elements to return
     7200);
     7201
     7202/** Convert a detNormalizedExpRow into an equivalent psMetadata
     7203 *
     7204 * @return A psMetadata pointer or NULL on error
     7205 */
     7206
     7207psMetadata *detNormalizedExpMetadataFromObject(
     7208    const detNormalizedExpRow *object             ///< fooRow to convert into a psMetadata
     7209);
     7210
     7211/** Convert a psMetadata into an equivalent fooRow
     7212 *
     7213 * @return A detNormalizedExpRow pointer or NULL on error
     7214 */
     7215
     7216detNormalizedExpRow *detNormalizedExpObjectFromMetadata(
     7217    psMetadata      *md                 ///< psMetadata to convert into a fooRow
     7218);
     7219/** Selects up to limit rows from the database and returns as detNormalizedExpRow objects in a psArray
     7220 *
     7221 *  See psDBSelectRows() for documentation on the format of where.
     7222 *
     7223 * @return A psArray pointer or NULL on error
     7224 */
     7225
     7226psArray *detNormalizedExpSelectRowObjects(
     7227    psDB            *dbh,               ///< Database handle
     7228    const psMetadata *where,            ///< Row match criteria
     7229    unsigned long long limit            ///< Maximum number of elements to return
     7230);
     7231/** Deletes a row from the database coresponding to an detNormalizedExp
     7232 *
     7233 *  Note that a 'where' search psMetadata is constructed from each object and
     7234 *  used to find rows to delete.
     7235 *
     7236 * @return A The number of rows removed or a negative value on error
     7237 */
     7238
     7239bool detNormalizedExpDeleteObject(
     7240    psDB            *dbh,               ///< Database handle
     7241    const detNormalizedExpRow *object    ///< Object to delete
     7242);
     7243/** Deletes up to limit rows from the database and returns the number of rows actually deleted.
     7244 *
     7245 *  Note that a 'where' search psMetadata is constructed from each object and
     7246 *  used to find rows to delete.
     7247 *
     7248 * @return A The number of rows removed or a negative value on error
     7249 */
     7250
     7251long long detNormalizedExpDeleteRowObjects(
     7252    psDB            *dbh,               ///< Database handle
     7253    const psArray   *objects,           ///< Array of objects to delete
     7254    unsigned long long limit            ///< Maximum number of elements to delete
     7255);
     7256/** Formats and prints an array of detNormalizedExpRow objects
     7257 *
     7258 * When mdcf is set the formated output is in psMetadataConfig
     7259 * format, otherwise it is in a simple tabular format.
     7260 *
     7261 * @return true on success
     7262 */
     7263
     7264bool detNormalizedExpPrintObjects(
     7265    FILE            *stream,            ///< a stream
     7266    psArray         *objects,           ///< An array of detNormalizedExpRow objects
     7267    bool            mdcf                ///< format as mdconfig or simple
     7268);
    70267269/** detMasterFrameRow data structure
    70277270 *
  • trunk/ippdb/tests/alloc.c

    r9107 r9149  
    22#include <ippdb.h>
    33#include <stdlib.h>
     4#include <string.h>
    45
    56#define MAX_STRING_LENGTH 1024
     
    11851186
    11861187    {
     1188        detNormalizedExpRow *object;
     1189
     1190        object = detNormalizedExpRowAlloc(-32, -32, "a string", 64.64, 64.64, 64.64, "a string", "a string"    );
     1191
     1192        if (!object) {
     1193            exit(EXIT_FAILURE);
     1194        }
     1195
     1196        if (!object->det_id == -32) {
     1197            psFree(object);
     1198            exit(EXIT_FAILURE);
     1199        }
     1200        if (!object->iteration == -32) {
     1201            psFree(object);
     1202            exit(EXIT_FAILURE);
     1203        }
     1204        if (strncmp(object->recipe, "a string", MAX_STRING_LENGTH)) {
     1205            psFree(object);
     1206            exit(EXIT_FAILURE);
     1207        }
     1208        if (!object->bg == 64.64) {
     1209            psFree(object);
     1210            exit(EXIT_FAILURE);
     1211        }
     1212        if (!object->bg_stdev == 64.64) {
     1213            psFree(object);
     1214            exit(EXIT_FAILURE);
     1215        }
     1216        if (!object->bg_mean_stdev == 64.64) {
     1217            psFree(object);
     1218            exit(EXIT_FAILURE);
     1219        }
     1220        if (strncmp(object->b1_uri, "a string", MAX_STRING_LENGTH)) {
     1221            psFree(object);
     1222            exit(EXIT_FAILURE);
     1223        }
     1224        if (strncmp(object->b2_uri, "a string", MAX_STRING_LENGTH)) {
     1225            psFree(object);
     1226            exit(EXIT_FAILURE);
     1227        }
     1228
     1229        psFree(object);
     1230    }
     1231
     1232    {
    11871233        detMasterFrameRow *object;
    11881234
  • trunk/ippdb/tests/createtable.c

    r9107 r9149  
    448448        }
    449449
     450        if(!detNormalizedExpCreateTable(dbh)) {
     451            exit(EXIT_FAILURE);
     452        }
     453
     454        psDBCleanup(dbh);
     455    }
     456
     457    {
     458        psDB            *dbh;
     459
     460        dbh = psDBInit("localhost", "test", NULL, "test");
     461        if (!dbh) {
     462            exit(EXIT_FAILURE);
     463        }
     464
    450465        if(!detMasterFrameCreateTable(dbh)) {
    451466            exit(EXIT_FAILURE);
  • trunk/ippdb/tests/dbcleanup.c

    r9107 r9149  
    4040    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detNormalizedStatImfile");
    4141    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detNormalizedImfile");
     42    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detNormalizedExp");
    4243    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detMasterFrame");
    4344    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detMasterImfile");
  • trunk/ippdb/tests/dbsetup.c

    r9107 r9149  
    100100    detNormalizedImfileCreateTable(dbh);
    101101
     102    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detNormalizedExp");
     103    detNormalizedExpCreateTable(dbh);
     104
    102105    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detMasterFrame");
    103106    detMasterFrameCreateTable(dbh);
  • trunk/ippdb/tests/droptable.c

    r9107 r9149  
    448448        }
    449449
     450        if (!detNormalizedExpDropTable(dbh)) {
     451            exit(EXIT_FAILURE);
     452        }
     453
     454        psDBCleanup(dbh);
     455    }
     456
     457    {
     458        psDB            *dbh;
     459
     460        dbh = psDBInit("localhost", "test", NULL, "test");
     461        if (!dbh) {
     462            exit(EXIT_FAILURE);
     463        }
     464
    450465        if (!detMasterFrameDropTable(dbh)) {
    451466            exit(EXIT_FAILURE);
  • trunk/ippdb/tests/insert.c

    r9107 r9149  
    448448        }
    449449
     450        if (!detNormalizedExpInsert(dbh, -32, -32, "a string", 64.64, 64.64, 64.64, "a string", "a string")) {
     451            exit(EXIT_FAILURE);
     452        }
     453
     454        psDBCleanup(dbh);
     455    }
     456
     457    {
     458        psDB            *dbh;
     459
     460        dbh = psDBInit("localhost", "test", NULL, "test");
     461        if (!dbh) {
     462            exit(EXIT_FAILURE);
     463        }
     464
    450465        if (!detMasterFrameInsert(dbh, -32, -32, "a string")) {
    451466            exit(EXIT_FAILURE);
  • trunk/ippdb/tests/insertfits.c

    r9107 r9149  
    778778        }
    779779
     780        if (!detNormalizedExpInsertFits(dbh, fits)) {
     781            exit(EXIT_FAILURE);
     782        }
     783
     784        if (!psFitsClose(fits)) {
     785            exit(EXIT_FAILURE);
     786        }
     787
     788        psDBCleanup(dbh);
     789    }
     790
     791    {
     792        psDB            *dbh;
     793        psFits          *fits;
     794
     795        dbh = psDBInit("localhost", "test", NULL, "test");
     796        if (!dbh) {
     797            exit(EXIT_FAILURE);
     798        }
     799
     800        // open a temp
     801        fits = psFitsOpen(TMP_FILENAME, "r");
     802        if (!fits) {
     803            exit(EXIT_FAILURE);
     804        }
     805
    780806        if (!detMasterFrameInsertFits(dbh, fits)) {
    781807            exit(EXIT_FAILURE);
  • trunk/ippdb/tests/insertobject.c

    r9107 r9149  
    645645    {
    646646        psDB            *dbh;
     647        detNormalizedExpRow *object;
     648
     649        dbh = psDBInit("localhost", "test", NULL, "test");
     650        if (!dbh) {
     651            exit(EXIT_FAILURE);
     652        }
     653
     654        object = detNormalizedExpRowAlloc(-32, -32, "a string", 64.64, 64.64, 64.64, "a string", "a string");
     655        if (!object) {
     656            exit(EXIT_FAILURE);
     657        }
     658
     659        if (!detNormalizedExpInsertObject(dbh, object)) {
     660            exit(EXIT_FAILURE);
     661        }
     662
     663        psFree(object);
     664        psDBCleanup(dbh);
     665    }
     666
     667    {
     668        psDB            *dbh;
    647669        detMasterFrameRow *object;
    648670
  • trunk/ippdb/tests/metadatafromobject.c

    r9107 r9149  
    14191419    {
    14201420        psMetadata      *md;
     1421        detNormalizedExpRow *object;
     1422        bool            status;
     1423
     1424        object = detNormalizedExpRowAlloc(-32, -32, "a string", 64.64, 64.64, 64.64, "a string", "a string");
     1425        if (!object) {
     1426            exit(EXIT_FAILURE);
     1427        }
     1428
     1429        md = detNormalizedExpMetadataFromObject(object);
     1430        if (!md) {
     1431            exit(EXIT_FAILURE);
     1432        }
     1433
     1434        psFree(object);
     1435
     1436        if (!psMetadataLookupS32(&status, md, "det_id") == -32) {
     1437            psFree(md);
     1438            exit(EXIT_FAILURE);
     1439        }
     1440        if (!psMetadataLookupS32(&status, md, "iteration") == -32) {
     1441            psFree(md);
     1442            exit(EXIT_FAILURE);
     1443        }
     1444        if (strncmp(psMetadataLookupPtr(&status, md, "recipe"), "a string", MAX_STRING_LENGTH)) {
     1445            psFree(md);
     1446            exit(EXIT_FAILURE);
     1447        }
     1448        if (!psMetadataLookupF64(&status, md, "bg") == 64.64) {
     1449            psFree(md);
     1450            exit(EXIT_FAILURE);
     1451        }
     1452        if (!psMetadataLookupF64(&status, md, "bg_stdev") == 64.64) {
     1453            psFree(md);
     1454            exit(EXIT_FAILURE);
     1455        }
     1456        if (!psMetadataLookupF64(&status, md, "bg_mean_stdev") == 64.64) {
     1457            psFree(md);
     1458            exit(EXIT_FAILURE);
     1459        }
     1460        if (strncmp(psMetadataLookupPtr(&status, md, "b1_uri"), "a string", MAX_STRING_LENGTH)) {
     1461            psFree(md);
     1462            exit(EXIT_FAILURE);
     1463        }
     1464        if (strncmp(psMetadataLookupPtr(&status, md, "b2_uri"), "a string", MAX_STRING_LENGTH)) {
     1465            psFree(md);
     1466            exit(EXIT_FAILURE);
     1467        }
     1468
     1469        psFree(md);
     1470    }
     1471
     1472    {
     1473        psMetadata      *md;
    14211474        detMasterFrameRow *object;
    14221475        bool            status;
  • trunk/ippdb/tests/objectfrommetadata.c

    r9107 r9149  
    21322132    {
    21332133        psMetadata      *md;
     2134        detNormalizedExpRow *object;
     2135
     2136        md = psMetadataAlloc();
     2137        if (!psMetadataAddS32(md, PS_LIST_TAIL, "det_id", 0, NULL, -32)) {
     2138            psFree(md);
     2139            exit(EXIT_FAILURE);
     2140        }
     2141        if (!psMetadataAddS32(md, PS_LIST_TAIL, "iteration", 0, NULL, -32)) {
     2142            psFree(md);
     2143            exit(EXIT_FAILURE);
     2144        }
     2145        if (!psMetadataAddStr(md, PS_LIST_TAIL, "recipe", 0, NULL, "a string")) {
     2146            psFree(md);
     2147            exit(EXIT_FAILURE);
     2148        }
     2149        if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 64.64)) {
     2150            psFree(md);
     2151            exit(EXIT_FAILURE);
     2152        }
     2153        if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, 64.64)) {
     2154            psFree(md);
     2155            exit(EXIT_FAILURE);
     2156        }
     2157        if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_mean_stdev", 0, NULL, 64.64)) {
     2158            psFree(md);
     2159            exit(EXIT_FAILURE);
     2160        }
     2161        if (!psMetadataAddStr(md, PS_LIST_TAIL, "b1_uri", 0, NULL, "a string")) {
     2162            psFree(md);
     2163            exit(EXIT_FAILURE);
     2164        }
     2165        if (!psMetadataAddStr(md, PS_LIST_TAIL, "b2_uri", 0, NULL, "a string")) {
     2166            psFree(md);
     2167            exit(EXIT_FAILURE);
     2168        }
     2169
     2170        object = detNormalizedExpObjectFromMetadata(md);
     2171        if (!object) {
     2172            psFree(md);
     2173            exit(EXIT_FAILURE);
     2174        }
     2175
     2176        psFree(md);
     2177
     2178        if (!object->det_id == -32) {
     2179            psFree(object);
     2180            exit(EXIT_FAILURE);
     2181        }
     2182        if (!object->iteration == -32) {
     2183            psFree(object);
     2184            exit(EXIT_FAILURE);
     2185        }
     2186        if (strncmp(object->recipe, "a string", MAX_STRING_LENGTH)) {
     2187            psFree(object);
     2188            exit(EXIT_FAILURE);
     2189        }
     2190        if (!object->bg == 64.64) {
     2191            psFree(object);
     2192            exit(EXIT_FAILURE);
     2193        }
     2194        if (!object->bg_stdev == 64.64) {
     2195            psFree(object);
     2196            exit(EXIT_FAILURE);
     2197        }
     2198        if (!object->bg_mean_stdev == 64.64) {
     2199            psFree(object);
     2200            exit(EXIT_FAILURE);
     2201        }
     2202        if (strncmp(object->b1_uri, "a string", MAX_STRING_LENGTH)) {
     2203            psFree(object);
     2204            exit(EXIT_FAILURE);
     2205        }
     2206        if (strncmp(object->b2_uri, "a string", MAX_STRING_LENGTH)) {
     2207            psFree(object);
     2208            exit(EXIT_FAILURE);
     2209        }
     2210
     2211        psFree(object);
     2212    }
     2213
     2214    {
     2215        psMetadata      *md;
    21342216        detMasterFrameRow *object;
    21352217
  • trunk/ippdb/tests/pop.c

    r9107 r9149  
    644644        psS32           det_id;
    645645        psS32           iteration;
     646        char            recipe[256];
     647        psF64           bg;
     648        psF64           bg_stdev;
     649        psF64           bg_mean_stdev;
     650        char            b1_uri[256];
     651        char            b2_uri[256];
     652
     653        dbh = psDBInit("localhost", "test", NULL, "test");
     654        if (!dbh) {
     655            exit(EXIT_FAILURE);
     656        }
     657
     658        if (!detNormalizedExpPop(dbh, &det_id, &iteration, (char **)&recipe, &bg, &bg_stdev, &bg_mean_stdev, (char **)&b1_uri, (char **)&b2_uri)) {
     659            exit(EXIT_FAILURE);
     660        }
     661
     662        psDBCleanup(dbh);
     663    }
     664
     665    {
     666        psDB            *dbh;
     667        psS32           det_id;
     668        psS32           iteration;
    646669        char            comment[256];
    647670
  • trunk/ippdb/tests/popfits.c

    r9107 r9149  
    778778        }
    779779
     780        if (!detNormalizedExpPopFits(dbh, fits, 1)) {
     781            exit(EXIT_FAILURE);
     782        }
     783
     784        if (!psFitsClose(fits)) {
     785            exit(EXIT_FAILURE);
     786        }
     787
     788        psDBCleanup(dbh);
     789    }
     790
     791    {
     792        psDB            *dbh;
     793        psFits          *fits;
     794
     795        dbh = psDBInit("localhost", "test", NULL, "test");
     796        if (!dbh) {
     797            exit(EXIT_FAILURE);
     798        }
     799
     800        // allocate a temp
     801        fits = psFitsOpen(TMP_FILENAME, "w");
     802        if (!fits) {
     803            exit(EXIT_FAILURE);
     804        }
     805
    780806        if (!detMasterFramePopFits(dbh, fits, 1)) {
    781807            exit(EXIT_FAILURE);
  • trunk/ippdb/tests/popobject.c

    r9107 r9149  
    529529    {
    530530        psDB            *dbh;
     531        detNormalizedExpRow *object;
     532
     533        dbh = psDBInit("localhost", "test", NULL, "test");
     534        if (!dbh) {
     535            exit(EXIT_FAILURE);
     536        }
     537
     538        object = detNormalizedExpPopObject(dbh);
     539        if (!object) {
     540            exit(EXIT_FAILURE);
     541        }
     542
     543        psFree(object);
     544        psDBCleanup(dbh);
     545    }
     546
     547    {
     548        psDB            *dbh;
    531549        detMasterFrameRow *object;
    532550
  • trunk/ippdb/tests/selectrowsfits.c

    r9107 r9149  
    659659        }
    660660
     661        if (!detNormalizedExpSelectRowsFits(dbh, fits, NULL, 1)) {
     662            exit(EXIT_FAILURE);
     663        }
     664
     665        psFree(fits);
     666        psDBCleanup(dbh);
     667    }
     668
     669    {
     670        psDB            *dbh;
     671        psFits          *fits;
     672
     673        dbh = psDBInit("localhost", "test", NULL, "test");
     674        if (!dbh) {
     675            exit(EXIT_FAILURE);
     676        }
     677
     678        fits = psFitsOpen(TMP_FILENAME, "w");
     679        if (!fits) {
     680            exit(EXIT_FAILURE);
     681        }
     682
    661683        if (!detMasterFrameSelectRowsFits(dbh, fits, NULL, 1)) {
    662684            exit(EXIT_FAILURE);
Note: See TracChangeset for help on using the changeset viewer.