Changeset 12535
- Timestamp:
- Mar 21, 2007, 5:14:51 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 16 edited
-
ippTools/configure.ac (modified) (2 diffs)
-
ippdb/Makefile.am (modified) (2 diffs)
-
ippdb/configure.ac (modified) (2 diffs)
-
ippdb/src/ippdb.c (modified) (7 diffs)
-
ippdb/src/ippdb.h (modified) (4 diffs)
-
ippdb/tests/alloc.c (modified) (2 diffs)
-
ippdb/tests/createtable.c (modified) (2 diffs)
-
ippdb/tests/dbcleanup.c (modified) (2 diffs)
-
ippdb/tests/dbsetup.c (modified) (2 diffs)
-
ippdb/tests/droptable.c (modified) (2 diffs)
-
ippdb/tests/insert.c (modified) (2 diffs)
-
ippdb/tests/insertfits.c (modified) (2 diffs)
-
ippdb/tests/insertobject.c (modified) (2 diffs)
-
ippdb/tests/metadatafromobject.c (modified) (2 diffs)
-
ippdb/tests/objectfrommetadata.c (modified) (2 diffs)
-
ippdb/tests/selectrowsfits.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/configure.ac
r12422 r12535 1 1 AC_PREREQ(2.59) 2 2 3 AC_INIT([ipptools], [1.1.1 8], [ipp-support@ifa.hawaii.edu])3 AC_INIT([ipptools], [1.1.19], [ipp-support@ifa.hawaii.edu]) 4 4 AC_CONFIG_SRCDIR([autogen.sh]) 5 5 … … 18 18 PKG_CHECK_MODULES([PSLIB], [pslib >= 1.1.0]) 19 19 PKG_CHECK_MODULES([PSMODULES], [psmodules >= 1.1.0]) 20 PKG_CHECK_MODULES([IPPDB], [ippdb >= 1.1.1 8])20 PKG_CHECK_MODULES([IPPDB], [ippdb >= 1.1.19]) 21 21 22 22 PXTOOLS_CFLAGS="${PSLIB_CFLAGS=} ${PSMODULES_CFLAGS=} ${IPPDB_CFLAGS=}" -
trunk/ippdb/Makefile.am
r12026 r12535 30 30 $(top_builddir)/docs/man/man3/camProcessedExpRow.3 \ 31 31 $(top_builddir)/docs/man/man3/camMaskRow.3 \ 32 $(top_builddir)/docs/man/man3/warpRunRow.3 \ 33 $(top_builddir)/docs/man/man3/warpInputExpRow.3 \ 34 $(top_builddir)/docs/man/man3/warpSkyCellMapRow.3 \ 35 $(top_builddir)/docs/man/man3/warpSkyfileRow.3 \ 36 $(top_builddir)/docs/man/man3/diffRunRow.3 \ 37 $(top_builddir)/docs/man/man3/diffInputSkyfileRow.3 \ 38 $(top_builddir)/docs/man/man3/diffSkyfileRow.3 \ 39 $(top_builddir)/docs/man/man3/stackRunRow.3 \ 40 $(top_builddir)/docs/man/man3/stackInputSkyfileRow.3 \ 41 $(top_builddir)/docs/man/man3/stackSumSkyfileRow.3 \ 32 42 $(top_builddir)/docs/man/man3/detRunRow.3 \ 33 43 $(top_builddir)/docs/man/man3/detInputExpRow.3 \ … … 40 50 $(top_builddir)/docs/man/man3/detResidImfileRow.3 \ 41 51 $(top_builddir)/docs/man/man3/detResidExpRow.3 \ 42 $(top_builddir)/docs/man/man3/detRunSummaryRow.3 \ 43 $(top_builddir)/docs/man/man3/warpRunRow.3 \ 44 $(top_builddir)/docs/man/man3/warpInputExpRow.3 \ 45 $(top_builddir)/docs/man/man3/warpSkyCellMapRow.3 \ 46 $(top_builddir)/docs/man/man3/warpSkyfileRow.3 \ 47 $(top_builddir)/docs/man/man3/diffRunRow.3 \ 48 $(top_builddir)/docs/man/man3/diffInputSkyfileRow.3 \ 49 $(top_builddir)/docs/man/man3/diffSkyfileRow.3 \ 50 $(top_builddir)/docs/man/man3/stackRunRow.3 \ 51 $(top_builddir)/docs/man/man3/stackInputSkyfileRow.3 \ 52 $(top_builddir)/docs/man/man3/stackSumSkyfileRow.3 52 $(top_builddir)/docs/man/man3/detRunSummaryRow.3 53 53 54 54 55 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/guidePendingExpRow.3 docs/man/man3/chipPendingExpRow.3 docs/man/man3/chipPendingImfileRow.3 docs/man/man3/chipProcessedExpRow.3 docs/man/man3/chipMaskRow.3 docs/man/man3/chipProcessedImfileRow.3 docs/man/man3/camPendingExpRow.3 docs/man/man3/camProcessedExpRow.3 docs/man/man3/camMaskRow.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/warpRunRow.3 docs/man/man3/warpInputExpRow.3 docs/man/man3/warpSkyCellMapRow.3 docs/man/man3/warpSkyfileRow.3 docs/man/man3/diffRunRow.3 docs/man/man3/diffInputSkyfileRow.3 docs/man/man3/diffSkyfileRow.3 docs/man/man3/stackRunRow.3 docs/man/man3/stackInputSkyfileRow.3 docs/man/man3/stackSumSkyfileRow.3:55 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/guidePendingExpRow.3 docs/man/man3/chipPendingExpRow.3 docs/man/man3/chipPendingImfileRow.3 docs/man/man3/chipProcessedExpRow.3 docs/man/man3/chipMaskRow.3 docs/man/man3/chipProcessedImfileRow.3 docs/man/man3/camPendingExpRow.3 docs/man/man3/camProcessedExpRow.3 docs/man/man3/camMaskRow.3 docs/man/man3/warpRunRow.3 docs/man/man3/warpInputExpRow.3 docs/man/man3/warpSkyCellMapRow.3 docs/man/man3/warpSkyfileRow.3 docs/man/man3/diffRunRow.3 docs/man/man3/diffInputSkyfileRow.3 docs/man/man3/diffSkyfileRow.3 docs/man/man3/stackRunRow.3 docs/man/man3/stackInputSkyfileRow.3 docs/man/man3/stackSumSkyfileRow.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: 56 56 $(DOXYGEN) 57 57 -
trunk/ippdb/configure.ac
r12426 r12535 1 1 dnl 2 dnl This file was generated by glueforge 1.0 02 dnl This file was generated by glueforge 1.01 3 3 dnl 4 4 dnl Do NOT directly edit this file. … … 7 7 AC_PREREQ(2.59) 8 8 9 AC_INIT([ippdb], [1.1.1 8], [pan-starrs.ifa.hawaii.edu])9 AC_INIT([ippdb], [1.1.19], [pan-starrs.ifa.hawaii.edu]) 10 10 AC_CONFIG_SRCDIR([ippdb.pc.in]) 11 11 -
trunk/ippdb/src/ippdb.c
r12426 r12535 20 20 /* 21 21 * 22 * This file was generated by glueforge 1.0 022 * This file was generated by glueforge 1.01 23 23 * 24 24 * Do NOT directly edit this file. … … 51 51 #define CAMPROCESSEDEXP_TABLE_NAME "camProcessedExp" 52 52 #define CAMMASK_TABLE_NAME "camMask" 53 #define WARPRUN_TABLE_NAME "warpRun" 54 #define WARPINPUTEXP_TABLE_NAME "warpInputExp" 55 #define WARPSKYCELLMAP_TABLE_NAME "warpSkyCellMap" 56 #define WARPSKYFILE_TABLE_NAME "warpSkyfile" 57 #define DIFFRUN_TABLE_NAME "diffRun" 58 #define DIFFINPUTSKYFILE_TABLE_NAME "diffInputSkyfile" 59 #define DIFFSKYFILE_TABLE_NAME "diffSkyfile" 60 #define STACKRUN_TABLE_NAME "stackRun" 61 #define STACKINPUTSKYFILE_TABLE_NAME "stackInputSkyfile" 62 #define STACKSUMSKYFILE_TABLE_NAME "stackSumSkyfile" 53 63 #define DETRUN_TABLE_NAME "detRun" 54 64 #define DETINPUTEXP_TABLE_NAME "detInputExp" … … 62 72 #define DETRESIDEXP_TABLE_NAME "detResidExp" 63 73 #define DETRUNSUMMARY_TABLE_NAME "detRunSummary" 64 #define WARPRUN_TABLE_NAME "warpRun"65 #define WARPINPUTEXP_TABLE_NAME "warpInputExp"66 #define WARPSKYCELLMAP_TABLE_NAME "warpSkyCellMap"67 #define WARPSKYFILE_TABLE_NAME "warpSkyfile"68 #define DIFFRUN_TABLE_NAME "diffRun"69 #define DIFFINPUTSKYFILE_TABLE_NAME "diffInputSkyfile"70 #define DIFFSKYFILE_TABLE_NAME "diffSkyfile"71 #define STACKRUN_TABLE_NAME "stackRun"72 #define STACKINPUTSKYFILE_TABLE_NAME "stackInputSkyfile"73 #define STACKSUMSKYFILE_TABLE_NAME "stackSumSkyfile"74 74 #define MAX_STRING_LENGTH 1024 75 75 … … 7190 7190 return false; 7191 7191 } 7192 if (!psMetadataAdd(md, PS_LIST_TAIL, "chip_id", PS_DATA_S64, "Primary Key ", 0)) {7192 if (!psMetadataAdd(md, PS_LIST_TAIL, "chip_id", PS_DATA_S64, "Primary Key fkey(chip_id) ref chipProcessedExp.chip_id)", 0)) { 7193 7193 psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id"); 7194 7194 psFree(md); … … 7607 7607 return false; 7608 7608 } 7609 if (!psMetadataAdd(md, PS_LIST_TAIL, "chip_id", PS_DATA_S64, "Primary Key ", 0)) {7609 if (!psMetadataAdd(md, PS_LIST_TAIL, "chip_id", PS_DATA_S64, "Primary Key fkey(chip_id) ref chipProcessedExp.chip_id)", 0)) { 7610 7610 psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id"); 7611 7611 psFree(md); … … 8458 8458 8459 8459 psMetadata *md = camMaskMetadataFromObject(object); 8460 8461 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 8462 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 8463 psFree(md); 8464 } 8465 8466 psFree(md); 8467 8468 return true; 8469 } 8470 static void warpRunRowFree(warpRunRow *object); 8471 8472 warpRunRow *warpRunRowAlloc(psS64 warp_id, const char *mode, const char *state, const char *workdir, const char *dvodb, psTime* registered) 8473 { 8474 warpRunRow *_object; 8475 8476 _object = psAlloc(sizeof(warpRunRow)); 8477 psMemSetDeallocator(_object, (psFreeFunc)warpRunRowFree); 8478 8479 _object->warp_id = warp_id; 8480 _object->mode = psStringCopy(mode); 8481 _object->state = psStringCopy(state); 8482 _object->workdir = psStringCopy(workdir); 8483 _object->dvodb = psStringCopy(dvodb); 8484 _object->registered = psTimeCopy(registered); 8485 8486 return _object; 8487 } 8488 8489 static void warpRunRowFree(warpRunRow *object) 8490 { 8491 psFree(object->mode); 8492 psFree(object->state); 8493 psFree(object->workdir); 8494 psFree(object->dvodb); 8495 psFree(object->registered); 8496 } 8497 8498 bool warpRunCreateTable(psDB *dbh) 8499 { 8500 psMetadata *md = psMetadataAlloc(); 8501 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key AUTO_INCREMENT", 0)) { 8502 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 8503 psFree(md); 8504 return false; 8505 } 8506 if (!psMetadataAdd(md, PS_LIST_TAIL, "mode", PS_DATA_STRING, "Key", "64")) { 8507 psError(PS_ERR_UNKNOWN, false, "failed to add item mode"); 8508 psFree(md); 8509 return false; 8510 } 8511 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "Key", "64")) { 8512 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 8513 psFree(md); 8514 return false; 8515 } 8516 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, "255")) { 8517 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 8518 psFree(md); 8519 return false; 8520 } 8521 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, "255")) { 8522 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 8523 psFree(md); 8524 return false; 8525 } 8526 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, NULL)) { 8527 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 8528 psFree(md); 8529 return false; 8530 } 8531 8532 bool status = psDBCreateTable(dbh, WARPRUN_TABLE_NAME, md); 8533 8534 psFree(md); 8535 8536 return status; 8537 } 8538 8539 bool warpRunDropTable(psDB *dbh) 8540 { 8541 return psDBDropTable(dbh, WARPRUN_TABLE_NAME); 8542 } 8543 8544 bool warpRunInsert(psDB * dbh, psS64 warp_id, const char *mode, const char *state, const char *workdir, const char *dvodb, psTime* registered) 8545 { 8546 psMetadata *md = psMetadataAlloc(); 8547 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, warp_id)) { 8548 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 8549 psFree(md); 8550 return false; 8551 } 8552 if (!psMetadataAdd(md, PS_LIST_TAIL, "mode", PS_DATA_STRING, NULL, mode)) { 8553 psError(PS_ERR_UNKNOWN, false, "failed to add item mode"); 8554 psFree(md); 8555 return false; 8556 } 8557 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) { 8558 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 8559 psFree(md); 8560 return false; 8561 } 8562 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, workdir)) { 8563 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 8564 psFree(md); 8565 return false; 8566 } 8567 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, dvodb)) { 8568 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 8569 psFree(md); 8570 return false; 8571 } 8572 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, registered)) { 8573 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 8574 psFree(md); 8575 return false; 8576 } 8577 8578 bool status = psDBInsertOneRow(dbh, WARPRUN_TABLE_NAME, md); 8579 psFree(md); 8580 8581 return status; 8582 } 8583 8584 long long warpRunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 8585 { 8586 long long deleted = 0; 8587 8588 long long count = psDBDeleteRows(dbh, WARPRUN_TABLE_NAME, where, limit); 8589 if (count < 0) { 8590 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpRun"); 8591 return count; 8592 8593 deleted += count; 8594 } 8595 8596 return deleted; 8597 } 8598 bool warpRunInsertObject(psDB *dbh, warpRunRow *object) 8599 { 8600 return warpRunInsert(dbh, object->warp_id, object->mode, object->state, object->workdir, object->dvodb, object->registered); 8601 } 8602 8603 bool warpRunInsertObjects(psDB *dbh, psArray *objects) 8604 { 8605 for (long i = 0; i < psArrayLength(objects); i++) { 8606 if (!warpRunInsertObject(dbh, objects->data[i])) { 8607 return false; 8608 } 8609 } 8610 8611 return true; 8612 } 8613 8614 bool warpRunInsertFits(psDB *dbh, const psFits *fits) 8615 { 8616 psArray *rowSet; 8617 8618 // move to (the first?) extension named WARPRUN_TABLE_NAME 8619 if (!psFitsMoveExtName(fits, WARPRUN_TABLE_NAME)) { 8620 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", WARPRUN_TABLE_NAME); 8621 return false; 8622 } 8623 8624 // check HDU type 8625 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 8626 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 8627 return false; 8628 } 8629 8630 // read fits table 8631 rowSet = psFitsReadTable(fits); 8632 if (!rowSet) { 8633 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 8634 psFree(rowSet); 8635 return false; 8636 } 8637 8638 if (!psDBInsertRows(dbh, WARPRUN_TABLE_NAME, rowSet)) { 8639 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 8640 psFree(rowSet); 8641 return false; 8642 } 8643 8644 psFree(rowSet); 8645 8646 return true; 8647 } 8648 8649 bool warpRunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 8650 { 8651 psArray *rowSet; 8652 8653 rowSet = psDBSelectRows(dbh, WARPRUN_TABLE_NAME, where, limit); 8654 if (!rowSet) { 8655 return false; 8656 } 8657 8658 // output to fits 8659 if (!psFitsWriteTable(fits, NULL, rowSet, WARPRUN_TABLE_NAME)) { 8660 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 8661 psFree(rowSet); 8662 return false; 8663 } 8664 8665 psFree(rowSet); 8666 8667 return true; 8668 } 8669 8670 psMetadata *warpRunMetadataFromObject(const warpRunRow *object) 8671 { 8672 psMetadata *md = psMetadataAlloc(); 8673 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, object->warp_id)) { 8674 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 8675 psFree(md); 8676 return false; 8677 } 8678 if (!psMetadataAdd(md, PS_LIST_TAIL, "mode", PS_DATA_STRING, NULL, object->mode)) { 8679 psError(PS_ERR_UNKNOWN, false, "failed to add item mode"); 8680 psFree(md); 8681 return false; 8682 } 8683 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) { 8684 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 8685 psFree(md); 8686 return false; 8687 } 8688 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, object->workdir)) { 8689 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 8690 psFree(md); 8691 return false; 8692 } 8693 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, object->dvodb)) { 8694 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 8695 psFree(md); 8696 return false; 8697 } 8698 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, object->registered)) { 8699 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 8700 psFree(md); 8701 return false; 8702 } 8703 8704 8705 return md; 8706 } 8707 8708 warpRunRow *warpRunObjectFromMetadata(psMetadata *md) 8709 { 8710 8711 bool status = false; 8712 psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id"); 8713 if (!status) { 8714 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item warp_id"); 8715 return false; 8716 } 8717 char* mode = psMetadataLookupPtr(&status, md, "mode"); 8718 if (!status) { 8719 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item mode"); 8720 return false; 8721 } 8722 char* state = psMetadataLookupPtr(&status, md, "state"); 8723 if (!status) { 8724 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state"); 8725 return false; 8726 } 8727 char* workdir = psMetadataLookupPtr(&status, md, "workdir"); 8728 if (!status) { 8729 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item workdir"); 8730 return false; 8731 } 8732 char* dvodb = psMetadataLookupPtr(&status, md, "dvodb"); 8733 if (!status) { 8734 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item dvodb"); 8735 return false; 8736 } 8737 psTime* registered = psMetadataLookupPtr(&status, md, "registered"); 8738 if (!status) { 8739 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item registered"); 8740 return false; 8741 } 8742 8743 return warpRunRowAlloc(warp_id, mode, state, workdir, dvodb, registered); 8744 } 8745 psArray *warpRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 8746 { 8747 psArray *rowSet; 8748 psArray *returnSet; 8749 psU64 i; 8750 8751 rowSet = psDBSelectRows(dbh, WARPRUN_TABLE_NAME, where, limit); 8752 if (!rowSet) { 8753 return NULL; 8754 } 8755 8756 // convert psMetadata rows to row objects 8757 8758 returnSet = psArrayAllocEmpty(rowSet->n); 8759 8760 for (i = 0; i < rowSet->n; i++) { 8761 warpRunRow *object = warpRunObjectFromMetadata(rowSet->data[i]); 8762 psArrayAdd(returnSet, 0, object); 8763 psFree(object); 8764 } 8765 8766 psFree(rowSet); 8767 8768 return returnSet; 8769 } 8770 bool warpRunDeleteObject(psDB *dbh, const warpRunRow *object) 8771 { 8772 psMetadata *where = warpRunMetadataFromObject(object); 8773 long long count = psDBDeleteRows(dbh, WARPRUN_TABLE_NAME, where, 0); 8774 psFree(where); 8775 if (count < 0) { 8776 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpRun"); 8777 return false; 8778 } 8779 if (count > 1) { 8780 // XXX should this be a psAbort() instead? It is possible that 8781 // having an object match multiple rows was by design. 8782 psError(PS_ERR_UNKNOWN, true, "warpRunRow object matched more then one row. Check your database schema"); 8783 return false; 8784 } 8785 8786 return true; 8787 } 8788 long long warpRunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 8789 { 8790 long long deleted = 0; 8791 8792 for (long long i = 0; i < objects->n; i++) { 8793 warpRunRow *object = objects->data[i]; 8794 psMetadata *where = warpRunMetadataFromObject(object); 8795 long long count = psDBDeleteRows(dbh, WARPRUN_TABLE_NAME, where, limit); 8796 psFree(where); 8797 if (count < 0) { 8798 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpRun"); 8799 return count; 8800 } 8801 8802 deleted += count; 8803 } 8804 8805 return deleted; 8806 } 8807 bool warpRunPrintObjects(FILE *stream, psArray *objects, bool mdcf) 8808 { 8809 PS_ASSERT_PTR_NON_NULL(objects, false); 8810 8811 psMetadata *output = psMetadataAlloc(); 8812 for (long i = 0; i < psArrayLength(objects); i++) { 8813 psMetadata *md = warpRunMetadataFromObject(objects->data[i]); 8814 if (!psMetadataAddMetadata( 8815 output, 8816 PS_LIST_TAIL, 8817 WARPRUN_TABLE_NAME, 8818 PS_META_DUPLICATE_OK, 8819 NULL, 8820 md 8821 )) { 8822 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 8823 psFree(md); 8824 psFree(output); 8825 return false; 8826 } 8827 psFree(md); 8828 } 8829 8830 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 8831 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 8832 psFree(output); 8833 } 8834 psFree(output); 8835 8836 return true; 8837 } 8838 bool warpRunPrintObject(FILE *stream, warpRunRow *object, bool mdcf) 8839 { 8840 PS_ASSERT_PTR_NON_NULL(object, false); 8841 8842 psMetadata *md = warpRunMetadataFromObject(object); 8843 8844 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 8845 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 8846 psFree(md); 8847 } 8848 8849 psFree(md); 8850 8851 return true; 8852 } 8853 static void warpInputExpRowFree(warpInputExpRow *object); 8854 8855 warpInputExpRow *warpInputExpRowAlloc(psS64 warp_id, psS64 cam_id, bool magiced) 8856 { 8857 warpInputExpRow *_object; 8858 8859 _object = psAlloc(sizeof(warpInputExpRow)); 8860 psMemSetDeallocator(_object, (psFreeFunc)warpInputExpRowFree); 8861 8862 _object->warp_id = warp_id; 8863 _object->cam_id = cam_id; 8864 _object->magiced = magiced; 8865 8866 return _object; 8867 } 8868 8869 static void warpInputExpRowFree(warpInputExpRow *object) 8870 { 8871 } 8872 8873 bool warpInputExpCreateTable(psDB *dbh) 8874 { 8875 psMetadata *md = psMetadataAlloc(); 8876 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key fkey(warp_id) ref warpRun(warp_id)", 0)) { 8877 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 8878 psFree(md); 8879 return false; 8880 } 8881 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, "Primary Key fkey(cam_id) ref camProcessedExp(cam_id)", 0)) { 8882 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id"); 8883 psFree(md); 8884 return false; 8885 } 8886 if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, "Key", 0)) { 8887 psError(PS_ERR_UNKNOWN, false, "failed to add item magiced"); 8888 psFree(md); 8889 return false; 8890 } 8891 8892 bool status = psDBCreateTable(dbh, WARPINPUTEXP_TABLE_NAME, md); 8893 8894 psFree(md); 8895 8896 return status; 8897 } 8898 8899 bool warpInputExpDropTable(psDB *dbh) 8900 { 8901 return psDBDropTable(dbh, WARPINPUTEXP_TABLE_NAME); 8902 } 8903 8904 bool warpInputExpInsert(psDB * dbh, psS64 warp_id, psS64 cam_id, bool magiced) 8905 { 8906 psMetadata *md = psMetadataAlloc(); 8907 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, warp_id)) { 8908 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 8909 psFree(md); 8910 return false; 8911 } 8912 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, NULL, cam_id)) { 8913 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id"); 8914 psFree(md); 8915 return false; 8916 } 8917 if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, NULL, magiced)) { 8918 psError(PS_ERR_UNKNOWN, false, "failed to add item magiced"); 8919 psFree(md); 8920 return false; 8921 } 8922 8923 bool status = psDBInsertOneRow(dbh, WARPINPUTEXP_TABLE_NAME, md); 8924 psFree(md); 8925 8926 return status; 8927 } 8928 8929 long long warpInputExpDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 8930 { 8931 long long deleted = 0; 8932 8933 long long count = psDBDeleteRows(dbh, WARPINPUTEXP_TABLE_NAME, where, limit); 8934 if (count < 0) { 8935 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpInputExp"); 8936 return count; 8937 8938 deleted += count; 8939 } 8940 8941 return deleted; 8942 } 8943 bool warpInputExpInsertObject(psDB *dbh, warpInputExpRow *object) 8944 { 8945 return warpInputExpInsert(dbh, object->warp_id, object->cam_id, object->magiced); 8946 } 8947 8948 bool warpInputExpInsertObjects(psDB *dbh, psArray *objects) 8949 { 8950 for (long i = 0; i < psArrayLength(objects); i++) { 8951 if (!warpInputExpInsertObject(dbh, objects->data[i])) { 8952 return false; 8953 } 8954 } 8955 8956 return true; 8957 } 8958 8959 bool warpInputExpInsertFits(psDB *dbh, const psFits *fits) 8960 { 8961 psArray *rowSet; 8962 8963 // move to (the first?) extension named WARPINPUTEXP_TABLE_NAME 8964 if (!psFitsMoveExtName(fits, WARPINPUTEXP_TABLE_NAME)) { 8965 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", WARPINPUTEXP_TABLE_NAME); 8966 return false; 8967 } 8968 8969 // check HDU type 8970 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 8971 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 8972 return false; 8973 } 8974 8975 // read fits table 8976 rowSet = psFitsReadTable(fits); 8977 if (!rowSet) { 8978 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 8979 psFree(rowSet); 8980 return false; 8981 } 8982 8983 if (!psDBInsertRows(dbh, WARPINPUTEXP_TABLE_NAME, rowSet)) { 8984 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 8985 psFree(rowSet); 8986 return false; 8987 } 8988 8989 psFree(rowSet); 8990 8991 return true; 8992 } 8993 8994 bool warpInputExpSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 8995 { 8996 psArray *rowSet; 8997 8998 rowSet = psDBSelectRows(dbh, WARPINPUTEXP_TABLE_NAME, where, limit); 8999 if (!rowSet) { 9000 return false; 9001 } 9002 9003 // output to fits 9004 if (!psFitsWriteTable(fits, NULL, rowSet, WARPINPUTEXP_TABLE_NAME)) { 9005 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 9006 psFree(rowSet); 9007 return false; 9008 } 9009 9010 psFree(rowSet); 9011 9012 return true; 9013 } 9014 9015 psMetadata *warpInputExpMetadataFromObject(const warpInputExpRow *object) 9016 { 9017 psMetadata *md = psMetadataAlloc(); 9018 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, object->warp_id)) { 9019 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 9020 psFree(md); 9021 return false; 9022 } 9023 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, NULL, object->cam_id)) { 9024 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id"); 9025 psFree(md); 9026 return false; 9027 } 9028 if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, NULL, object->magiced)) { 9029 psError(PS_ERR_UNKNOWN, false, "failed to add item magiced"); 9030 psFree(md); 9031 return false; 9032 } 9033 9034 9035 return md; 9036 } 9037 9038 warpInputExpRow *warpInputExpObjectFromMetadata(psMetadata *md) 9039 { 9040 9041 bool status = false; 9042 psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id"); 9043 if (!status) { 9044 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item warp_id"); 9045 return false; 9046 } 9047 psS64 cam_id = psMetadataLookupS64(&status, md, "cam_id"); 9048 if (!status) { 9049 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item cam_id"); 9050 return false; 9051 } 9052 bool magiced = psMetadataLookupBool(&status, md, "magiced"); 9053 if (!status) { 9054 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item magiced"); 9055 return false; 9056 } 9057 9058 return warpInputExpRowAlloc(warp_id, cam_id, magiced); 9059 } 9060 psArray *warpInputExpSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 9061 { 9062 psArray *rowSet; 9063 psArray *returnSet; 9064 psU64 i; 9065 9066 rowSet = psDBSelectRows(dbh, WARPINPUTEXP_TABLE_NAME, where, limit); 9067 if (!rowSet) { 9068 return NULL; 9069 } 9070 9071 // convert psMetadata rows to row objects 9072 9073 returnSet = psArrayAllocEmpty(rowSet->n); 9074 9075 for (i = 0; i < rowSet->n; i++) { 9076 warpInputExpRow *object = warpInputExpObjectFromMetadata(rowSet->data[i]); 9077 psArrayAdd(returnSet, 0, object); 9078 psFree(object); 9079 } 9080 9081 psFree(rowSet); 9082 9083 return returnSet; 9084 } 9085 bool warpInputExpDeleteObject(psDB *dbh, const warpInputExpRow *object) 9086 { 9087 psMetadata *where = warpInputExpMetadataFromObject(object); 9088 long long count = psDBDeleteRows(dbh, WARPINPUTEXP_TABLE_NAME, where, 0); 9089 psFree(where); 9090 if (count < 0) { 9091 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpInputExp"); 9092 return false; 9093 } 9094 if (count > 1) { 9095 // XXX should this be a psAbort() instead? It is possible that 9096 // having an object match multiple rows was by design. 9097 psError(PS_ERR_UNKNOWN, true, "warpInputExpRow object matched more then one row. Check your database schema"); 9098 return false; 9099 } 9100 9101 return true; 9102 } 9103 long long warpInputExpDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 9104 { 9105 long long deleted = 0; 9106 9107 for (long long i = 0; i < objects->n; i++) { 9108 warpInputExpRow *object = objects->data[i]; 9109 psMetadata *where = warpInputExpMetadataFromObject(object); 9110 long long count = psDBDeleteRows(dbh, WARPINPUTEXP_TABLE_NAME, where, limit); 9111 psFree(where); 9112 if (count < 0) { 9113 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpInputExp"); 9114 return count; 9115 } 9116 9117 deleted += count; 9118 } 9119 9120 return deleted; 9121 } 9122 bool warpInputExpPrintObjects(FILE *stream, psArray *objects, bool mdcf) 9123 { 9124 PS_ASSERT_PTR_NON_NULL(objects, false); 9125 9126 psMetadata *output = psMetadataAlloc(); 9127 for (long i = 0; i < psArrayLength(objects); i++) { 9128 psMetadata *md = warpInputExpMetadataFromObject(objects->data[i]); 9129 if (!psMetadataAddMetadata( 9130 output, 9131 PS_LIST_TAIL, 9132 WARPINPUTEXP_TABLE_NAME, 9133 PS_META_DUPLICATE_OK, 9134 NULL, 9135 md 9136 )) { 9137 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 9138 psFree(md); 9139 psFree(output); 9140 return false; 9141 } 9142 psFree(md); 9143 } 9144 9145 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 9146 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 9147 psFree(output); 9148 } 9149 psFree(output); 9150 9151 return true; 9152 } 9153 bool warpInputExpPrintObject(FILE *stream, warpInputExpRow *object, bool mdcf) 9154 { 9155 PS_ASSERT_PTR_NON_NULL(object, false); 9156 9157 psMetadata *md = warpInputExpMetadataFromObject(object); 9158 9159 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 9160 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 9161 psFree(md); 9162 } 9163 9164 psFree(md); 9165 9166 return true; 9167 } 9168 static void warpSkyCellMapRowFree(warpSkyCellMapRow *object); 9169 9170 warpSkyCellMapRow *warpSkyCellMapRowAlloc(psS64 warp_id, const char *skycell_id, const char *tess_id, psS64 cam_id, const char *class_id, psS16 fault) 9171 { 9172 warpSkyCellMapRow *_object; 9173 9174 _object = psAlloc(sizeof(warpSkyCellMapRow)); 9175 psMemSetDeallocator(_object, (psFreeFunc)warpSkyCellMapRowFree); 9176 9177 _object->warp_id = warp_id; 9178 _object->skycell_id = psStringCopy(skycell_id); 9179 _object->tess_id = psStringCopy(tess_id); 9180 _object->cam_id = cam_id; 9181 _object->class_id = psStringCopy(class_id); 9182 _object->fault = fault; 9183 9184 return _object; 9185 } 9186 9187 static void warpSkyCellMapRowFree(warpSkyCellMapRow *object) 9188 { 9189 psFree(object->skycell_id); 9190 psFree(object->tess_id); 9191 psFree(object->class_id); 9192 } 9193 9194 bool warpSkyCellMapCreateTable(psDB *dbh) 9195 { 9196 psMetadata *md = psMetadataAlloc(); 9197 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key fkey(warp_id, cam_id) ref warpInputExp(warp_id, cam_id)", 0)) { 9198 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 9199 psFree(md); 9200 return false; 9201 } 9202 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) { 9203 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 9204 psFree(md); 9205 return false; 9206 } 9207 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) { 9208 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 9209 psFree(md); 9210 return false; 9211 } 9212 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, "Primary Key", 0)) { 9213 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id"); 9214 psFree(md); 9215 return false; 9216 } 9217 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) { 9218 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 9219 psFree(md); 9220 return false; 9221 } 9222 if (!psMetadataAdd(md, PS_LIST_TAIL, "fault", PS_DATA_S16, "Key", 0)) { 9223 psError(PS_ERR_UNKNOWN, false, "failed to add item fault"); 9224 psFree(md); 9225 return false; 9226 } 9227 9228 bool status = psDBCreateTable(dbh, WARPSKYCELLMAP_TABLE_NAME, md); 9229 9230 psFree(md); 9231 9232 return status; 9233 } 9234 9235 bool warpSkyCellMapDropTable(psDB *dbh) 9236 { 9237 return psDBDropTable(dbh, WARPSKYCELLMAP_TABLE_NAME); 9238 } 9239 9240 bool warpSkyCellMapInsert(psDB * dbh, psS64 warp_id, const char *skycell_id, const char *tess_id, psS64 cam_id, const char *class_id, psS16 fault) 9241 { 9242 psMetadata *md = psMetadataAlloc(); 9243 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, warp_id)) { 9244 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 9245 psFree(md); 9246 return false; 9247 } 9248 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) { 9249 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 9250 psFree(md); 9251 return false; 9252 } 9253 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 9254 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 9255 psFree(md); 9256 return false; 9257 } 9258 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, NULL, cam_id)) { 9259 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id"); 9260 psFree(md); 9261 return false; 9262 } 9263 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) { 9264 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 9265 psFree(md); 9266 return false; 9267 } 9268 if (!psMetadataAdd(md, PS_LIST_TAIL, "fault", PS_DATA_S16, NULL, fault)) { 9269 psError(PS_ERR_UNKNOWN, false, "failed to add item fault"); 9270 psFree(md); 9271 return false; 9272 } 9273 9274 bool status = psDBInsertOneRow(dbh, WARPSKYCELLMAP_TABLE_NAME, md); 9275 psFree(md); 9276 9277 return status; 9278 } 9279 9280 long long warpSkyCellMapDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 9281 { 9282 long long deleted = 0; 9283 9284 long long count = psDBDeleteRows(dbh, WARPSKYCELLMAP_TABLE_NAME, where, limit); 9285 if (count < 0) { 9286 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpSkyCellMap"); 9287 return count; 9288 9289 deleted += count; 9290 } 9291 9292 return deleted; 9293 } 9294 bool warpSkyCellMapInsertObject(psDB *dbh, warpSkyCellMapRow *object) 9295 { 9296 return warpSkyCellMapInsert(dbh, object->warp_id, object->skycell_id, object->tess_id, object->cam_id, object->class_id, object->fault); 9297 } 9298 9299 bool warpSkyCellMapInsertObjects(psDB *dbh, psArray *objects) 9300 { 9301 for (long i = 0; i < psArrayLength(objects); i++) { 9302 if (!warpSkyCellMapInsertObject(dbh, objects->data[i])) { 9303 return false; 9304 } 9305 } 9306 9307 return true; 9308 } 9309 9310 bool warpSkyCellMapInsertFits(psDB *dbh, const psFits *fits) 9311 { 9312 psArray *rowSet; 9313 9314 // move to (the first?) extension named WARPSKYCELLMAP_TABLE_NAME 9315 if (!psFitsMoveExtName(fits, WARPSKYCELLMAP_TABLE_NAME)) { 9316 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", WARPSKYCELLMAP_TABLE_NAME); 9317 return false; 9318 } 9319 9320 // check HDU type 9321 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 9322 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 9323 return false; 9324 } 9325 9326 // read fits table 9327 rowSet = psFitsReadTable(fits); 9328 if (!rowSet) { 9329 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 9330 psFree(rowSet); 9331 return false; 9332 } 9333 9334 if (!psDBInsertRows(dbh, WARPSKYCELLMAP_TABLE_NAME, rowSet)) { 9335 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 9336 psFree(rowSet); 9337 return false; 9338 } 9339 9340 psFree(rowSet); 9341 9342 return true; 9343 } 9344 9345 bool warpSkyCellMapSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 9346 { 9347 psArray *rowSet; 9348 9349 rowSet = psDBSelectRows(dbh, WARPSKYCELLMAP_TABLE_NAME, where, limit); 9350 if (!rowSet) { 9351 return false; 9352 } 9353 9354 // output to fits 9355 if (!psFitsWriteTable(fits, NULL, rowSet, WARPSKYCELLMAP_TABLE_NAME)) { 9356 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 9357 psFree(rowSet); 9358 return false; 9359 } 9360 9361 psFree(rowSet); 9362 9363 return true; 9364 } 9365 9366 psMetadata *warpSkyCellMapMetadataFromObject(const warpSkyCellMapRow *object) 9367 { 9368 psMetadata *md = psMetadataAlloc(); 9369 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, object->warp_id)) { 9370 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 9371 psFree(md); 9372 return false; 9373 } 9374 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) { 9375 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 9376 psFree(md); 9377 return false; 9378 } 9379 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) { 9380 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 9381 psFree(md); 9382 return false; 9383 } 9384 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, NULL, object->cam_id)) { 9385 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id"); 9386 psFree(md); 9387 return false; 9388 } 9389 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) { 9390 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 9391 psFree(md); 9392 return false; 9393 } 9394 if (!psMetadataAdd(md, PS_LIST_TAIL, "fault", PS_DATA_S16, NULL, object->fault)) { 9395 psError(PS_ERR_UNKNOWN, false, "failed to add item fault"); 9396 psFree(md); 9397 return false; 9398 } 9399 9400 9401 return md; 9402 } 9403 9404 warpSkyCellMapRow *warpSkyCellMapObjectFromMetadata(psMetadata *md) 9405 { 9406 9407 bool status = false; 9408 psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id"); 9409 if (!status) { 9410 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item warp_id"); 9411 return false; 9412 } 9413 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id"); 9414 if (!status) { 9415 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id"); 9416 return false; 9417 } 9418 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 9419 if (!status) { 9420 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 9421 return false; 9422 } 9423 psS64 cam_id = psMetadataLookupS64(&status, md, "cam_id"); 9424 if (!status) { 9425 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item cam_id"); 9426 return false; 9427 } 9428 char* class_id = psMetadataLookupPtr(&status, md, "class_id"); 9429 if (!status) { 9430 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id"); 9431 return false; 9432 } 9433 psS16 fault = psMetadataLookupS16(&status, md, "fault"); 9434 if (!status) { 9435 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item fault"); 9436 return false; 9437 } 9438 9439 return warpSkyCellMapRowAlloc(warp_id, skycell_id, tess_id, cam_id, class_id, fault); 9440 } 9441 psArray *warpSkyCellMapSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 9442 { 9443 psArray *rowSet; 9444 psArray *returnSet; 9445 psU64 i; 9446 9447 rowSet = psDBSelectRows(dbh, WARPSKYCELLMAP_TABLE_NAME, where, limit); 9448 if (!rowSet) { 9449 return NULL; 9450 } 9451 9452 // convert psMetadata rows to row objects 9453 9454 returnSet = psArrayAllocEmpty(rowSet->n); 9455 9456 for (i = 0; i < rowSet->n; i++) { 9457 warpSkyCellMapRow *object = warpSkyCellMapObjectFromMetadata(rowSet->data[i]); 9458 psArrayAdd(returnSet, 0, object); 9459 psFree(object); 9460 } 9461 9462 psFree(rowSet); 9463 9464 return returnSet; 9465 } 9466 bool warpSkyCellMapDeleteObject(psDB *dbh, const warpSkyCellMapRow *object) 9467 { 9468 psMetadata *where = warpSkyCellMapMetadataFromObject(object); 9469 long long count = psDBDeleteRows(dbh, WARPSKYCELLMAP_TABLE_NAME, where, 0); 9470 psFree(where); 9471 if (count < 0) { 9472 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpSkyCellMap"); 9473 return false; 9474 } 9475 if (count > 1) { 9476 // XXX should this be a psAbort() instead? It is possible that 9477 // having an object match multiple rows was by design. 9478 psError(PS_ERR_UNKNOWN, true, "warpSkyCellMapRow object matched more then one row. Check your database schema"); 9479 return false; 9480 } 9481 9482 return true; 9483 } 9484 long long warpSkyCellMapDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 9485 { 9486 long long deleted = 0; 9487 9488 for (long long i = 0; i < objects->n; i++) { 9489 warpSkyCellMapRow *object = objects->data[i]; 9490 psMetadata *where = warpSkyCellMapMetadataFromObject(object); 9491 long long count = psDBDeleteRows(dbh, WARPSKYCELLMAP_TABLE_NAME, where, limit); 9492 psFree(where); 9493 if (count < 0) { 9494 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpSkyCellMap"); 9495 return count; 9496 } 9497 9498 deleted += count; 9499 } 9500 9501 return deleted; 9502 } 9503 bool warpSkyCellMapPrintObjects(FILE *stream, psArray *objects, bool mdcf) 9504 { 9505 PS_ASSERT_PTR_NON_NULL(objects, false); 9506 9507 psMetadata *output = psMetadataAlloc(); 9508 for (long i = 0; i < psArrayLength(objects); i++) { 9509 psMetadata *md = warpSkyCellMapMetadataFromObject(objects->data[i]); 9510 if (!psMetadataAddMetadata( 9511 output, 9512 PS_LIST_TAIL, 9513 WARPSKYCELLMAP_TABLE_NAME, 9514 PS_META_DUPLICATE_OK, 9515 NULL, 9516 md 9517 )) { 9518 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 9519 psFree(md); 9520 psFree(output); 9521 return false; 9522 } 9523 psFree(md); 9524 } 9525 9526 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 9527 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 9528 psFree(output); 9529 } 9530 psFree(output); 9531 9532 return true; 9533 } 9534 bool warpSkyCellMapPrintObject(FILE *stream, warpSkyCellMapRow *object, bool mdcf) 9535 { 9536 PS_ASSERT_PTR_NON_NULL(object, false); 9537 9538 psMetadata *md = warpSkyCellMapMetadataFromObject(object); 9539 9540 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 9541 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 9542 psFree(md); 9543 } 9544 9545 psFree(md); 9546 9547 return true; 9548 } 9549 static void warpSkyfileRowFree(warpSkyfileRow *object); 9550 9551 warpSkyfileRow *warpSkyfileRowAlloc(psS64 warp_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_stdev) 9552 { 9553 warpSkyfileRow *_object; 9554 9555 _object = psAlloc(sizeof(warpSkyfileRow)); 9556 psMemSetDeallocator(_object, (psFreeFunc)warpSkyfileRowFree); 9557 9558 _object->warp_id = warp_id; 9559 _object->skycell_id = psStringCopy(skycell_id); 9560 _object->tess_id = psStringCopy(tess_id); 9561 _object->uri = psStringCopy(uri); 9562 _object->bg = bg; 9563 _object->bg_stdev = bg_stdev; 9564 9565 return _object; 9566 } 9567 9568 static void warpSkyfileRowFree(warpSkyfileRow *object) 9569 { 9570 psFree(object->skycell_id); 9571 psFree(object->tess_id); 9572 psFree(object->uri); 9573 } 9574 9575 bool warpSkyfileCreateTable(psDB *dbh) 9576 { 9577 psMetadata *md = psMetadataAlloc(); 9578 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key fkey(warp_id, skycell_id, tess_id) ref warpSkyCellMap(warp_id, skycell_id, tess_id)", 0)) { 9579 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 9580 psFree(md); 9581 return false; 9582 } 9583 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) { 9584 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 9585 psFree(md); 9586 return false; 9587 } 9588 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) { 9589 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 9590 psFree(md); 9591 return false; 9592 } 9593 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 9594 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 9595 psFree(md); 9596 return false; 9597 } 9598 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, 0.0)) { 9599 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 9600 psFree(md); 9601 return false; 9602 } 9603 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, 0.0)) { 9604 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev"); 9605 psFree(md); 9606 return false; 9607 } 9608 9609 bool status = psDBCreateTable(dbh, WARPSKYFILE_TABLE_NAME, md); 9610 9611 psFree(md); 9612 9613 return status; 9614 } 9615 9616 bool warpSkyfileDropTable(psDB *dbh) 9617 { 9618 return psDBDropTable(dbh, WARPSKYFILE_TABLE_NAME); 9619 } 9620 9621 bool warpSkyfileInsert(psDB * dbh, psS64 warp_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_stdev) 9622 { 9623 psMetadata *md = psMetadataAlloc(); 9624 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, warp_id)) { 9625 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 9626 psFree(md); 9627 return false; 9628 } 9629 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) { 9630 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 9631 psFree(md); 9632 return false; 9633 } 9634 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 9635 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 9636 psFree(md); 9637 return false; 9638 } 9639 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 9640 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 9641 psFree(md); 9642 return false; 9643 } 9644 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, bg)) { 9645 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 9646 psFree(md); 9647 return false; 9648 } 9649 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, bg_stdev)) { 9650 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev"); 9651 psFree(md); 9652 return false; 9653 } 9654 9655 bool status = psDBInsertOneRow(dbh, WARPSKYFILE_TABLE_NAME, md); 9656 psFree(md); 9657 9658 return status; 9659 } 9660 9661 long long warpSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 9662 { 9663 long long deleted = 0; 9664 9665 long long count = psDBDeleteRows(dbh, WARPSKYFILE_TABLE_NAME, where, limit); 9666 if (count < 0) { 9667 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpSkyfile"); 9668 return count; 9669 9670 deleted += count; 9671 } 9672 9673 return deleted; 9674 } 9675 bool warpSkyfileInsertObject(psDB *dbh, warpSkyfileRow *object) 9676 { 9677 return warpSkyfileInsert(dbh, object->warp_id, object->skycell_id, object->tess_id, object->uri, object->bg, object->bg_stdev); 9678 } 9679 9680 bool warpSkyfileInsertObjects(psDB *dbh, psArray *objects) 9681 { 9682 for (long i = 0; i < psArrayLength(objects); i++) { 9683 if (!warpSkyfileInsertObject(dbh, objects->data[i])) { 9684 return false; 9685 } 9686 } 9687 9688 return true; 9689 } 9690 9691 bool warpSkyfileInsertFits(psDB *dbh, const psFits *fits) 9692 { 9693 psArray *rowSet; 9694 9695 // move to (the first?) extension named WARPSKYFILE_TABLE_NAME 9696 if (!psFitsMoveExtName(fits, WARPSKYFILE_TABLE_NAME)) { 9697 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", WARPSKYFILE_TABLE_NAME); 9698 return false; 9699 } 9700 9701 // check HDU type 9702 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 9703 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 9704 return false; 9705 } 9706 9707 // read fits table 9708 rowSet = psFitsReadTable(fits); 9709 if (!rowSet) { 9710 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 9711 psFree(rowSet); 9712 return false; 9713 } 9714 9715 if (!psDBInsertRows(dbh, WARPSKYFILE_TABLE_NAME, rowSet)) { 9716 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 9717 psFree(rowSet); 9718 return false; 9719 } 9720 9721 psFree(rowSet); 9722 9723 return true; 9724 } 9725 9726 bool warpSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 9727 { 9728 psArray *rowSet; 9729 9730 rowSet = psDBSelectRows(dbh, WARPSKYFILE_TABLE_NAME, where, limit); 9731 if (!rowSet) { 9732 return false; 9733 } 9734 9735 // output to fits 9736 if (!psFitsWriteTable(fits, NULL, rowSet, WARPSKYFILE_TABLE_NAME)) { 9737 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 9738 psFree(rowSet); 9739 return false; 9740 } 9741 9742 psFree(rowSet); 9743 9744 return true; 9745 } 9746 9747 psMetadata *warpSkyfileMetadataFromObject(const warpSkyfileRow *object) 9748 { 9749 psMetadata *md = psMetadataAlloc(); 9750 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, object->warp_id)) { 9751 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 9752 psFree(md); 9753 return false; 9754 } 9755 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) { 9756 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 9757 psFree(md); 9758 return false; 9759 } 9760 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) { 9761 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 9762 psFree(md); 9763 return false; 9764 } 9765 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 9766 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 9767 psFree(md); 9768 return false; 9769 } 9770 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, object->bg)) { 9771 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 9772 psFree(md); 9773 return false; 9774 } 9775 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, object->bg_stdev)) { 9776 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev"); 9777 psFree(md); 9778 return false; 9779 } 9780 9781 9782 return md; 9783 } 9784 9785 warpSkyfileRow *warpSkyfileObjectFromMetadata(psMetadata *md) 9786 { 9787 9788 bool status = false; 9789 psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id"); 9790 if (!status) { 9791 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item warp_id"); 9792 return false; 9793 } 9794 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id"); 9795 if (!status) { 9796 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id"); 9797 return false; 9798 } 9799 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 9800 if (!status) { 9801 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 9802 return false; 9803 } 9804 char* uri = psMetadataLookupPtr(&status, md, "uri"); 9805 if (!status) { 9806 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri"); 9807 return false; 9808 } 9809 psF64 bg = psMetadataLookupF64(&status, md, "bg"); 9810 if (!status) { 9811 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg"); 9812 return false; 9813 } 9814 psF64 bg_stdev = psMetadataLookupF64(&status, md, "bg_stdev"); 9815 if (!status) { 9816 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_stdev"); 9817 return false; 9818 } 9819 9820 return warpSkyfileRowAlloc(warp_id, skycell_id, tess_id, uri, bg, bg_stdev); 9821 } 9822 psArray *warpSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 9823 { 9824 psArray *rowSet; 9825 psArray *returnSet; 9826 psU64 i; 9827 9828 rowSet = psDBSelectRows(dbh, WARPSKYFILE_TABLE_NAME, where, limit); 9829 if (!rowSet) { 9830 return NULL; 9831 } 9832 9833 // convert psMetadata rows to row objects 9834 9835 returnSet = psArrayAllocEmpty(rowSet->n); 9836 9837 for (i = 0; i < rowSet->n; i++) { 9838 warpSkyfileRow *object = warpSkyfileObjectFromMetadata(rowSet->data[i]); 9839 psArrayAdd(returnSet, 0, object); 9840 psFree(object); 9841 } 9842 9843 psFree(rowSet); 9844 9845 return returnSet; 9846 } 9847 bool warpSkyfileDeleteObject(psDB *dbh, const warpSkyfileRow *object) 9848 { 9849 psMetadata *where = warpSkyfileMetadataFromObject(object); 9850 long long count = psDBDeleteRows(dbh, WARPSKYFILE_TABLE_NAME, where, 0); 9851 psFree(where); 9852 if (count < 0) { 9853 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpSkyfile"); 9854 return false; 9855 } 9856 if (count > 1) { 9857 // XXX should this be a psAbort() instead? It is possible that 9858 // having an object match multiple rows was by design. 9859 psError(PS_ERR_UNKNOWN, true, "warpSkyfileRow object matched more then one row. Check your database schema"); 9860 return false; 9861 } 9862 9863 return true; 9864 } 9865 long long warpSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 9866 { 9867 long long deleted = 0; 9868 9869 for (long long i = 0; i < objects->n; i++) { 9870 warpSkyfileRow *object = objects->data[i]; 9871 psMetadata *where = warpSkyfileMetadataFromObject(object); 9872 long long count = psDBDeleteRows(dbh, WARPSKYFILE_TABLE_NAME, where, limit); 9873 psFree(where); 9874 if (count < 0) { 9875 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpSkyfile"); 9876 return count; 9877 } 9878 9879 deleted += count; 9880 } 9881 9882 return deleted; 9883 } 9884 bool warpSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 9885 { 9886 PS_ASSERT_PTR_NON_NULL(objects, false); 9887 9888 psMetadata *output = psMetadataAlloc(); 9889 for (long i = 0; i < psArrayLength(objects); i++) { 9890 psMetadata *md = warpSkyfileMetadataFromObject(objects->data[i]); 9891 if (!psMetadataAddMetadata( 9892 output, 9893 PS_LIST_TAIL, 9894 WARPSKYFILE_TABLE_NAME, 9895 PS_META_DUPLICATE_OK, 9896 NULL, 9897 md 9898 )) { 9899 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 9900 psFree(md); 9901 psFree(output); 9902 return false; 9903 } 9904 psFree(md); 9905 } 9906 9907 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 9908 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 9909 psFree(output); 9910 } 9911 psFree(output); 9912 9913 return true; 9914 } 9915 bool warpSkyfilePrintObject(FILE *stream, warpSkyfileRow *object, bool mdcf) 9916 { 9917 PS_ASSERT_PTR_NON_NULL(object, false); 9918 9919 psMetadata *md = warpSkyfileMetadataFromObject(object); 9920 9921 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 9922 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 9923 psFree(md); 9924 } 9925 9926 psFree(md); 9927 9928 return true; 9929 } 9930 static void diffRunRowFree(diffRunRow *object); 9931 9932 diffRunRow *diffRunRowAlloc(psS64 diff_id, const char *state, const char *workdir, const char *dvodb, psTime* registered, const char *skycell_id, const char *tess_id) 9933 { 9934 diffRunRow *_object; 9935 9936 _object = psAlloc(sizeof(diffRunRow)); 9937 psMemSetDeallocator(_object, (psFreeFunc)diffRunRowFree); 9938 9939 _object->diff_id = diff_id; 9940 _object->state = psStringCopy(state); 9941 _object->workdir = psStringCopy(workdir); 9942 _object->dvodb = psStringCopy(dvodb); 9943 _object->registered = psTimeCopy(registered); 9944 _object->skycell_id = psStringCopy(skycell_id); 9945 _object->tess_id = psStringCopy(tess_id); 9946 9947 return _object; 9948 } 9949 9950 static void diffRunRowFree(diffRunRow *object) 9951 { 9952 psFree(object->state); 9953 psFree(object->workdir); 9954 psFree(object->dvodb); 9955 psFree(object->registered); 9956 psFree(object->skycell_id); 9957 psFree(object->tess_id); 9958 } 9959 9960 bool diffRunCreateTable(psDB *dbh) 9961 { 9962 psMetadata *md = psMetadataAlloc(); 9963 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, "Primary Key AUTO_INCREMENT", 0)) { 9964 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id"); 9965 psFree(md); 9966 return false; 9967 } 9968 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "Key", "64")) { 9969 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 9970 psFree(md); 9971 return false; 9972 } 9973 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, "255")) { 9974 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 9975 psFree(md); 9976 return false; 9977 } 9978 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, "255")) { 9979 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 9980 psFree(md); 9981 return false; 9982 } 9983 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, NULL)) { 9984 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 9985 psFree(md); 9986 return false; 9987 } 9988 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Key", "64")) { 9989 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 9990 psFree(md); 9991 return false; 9992 } 9993 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Key", "64")) { 9994 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 9995 psFree(md); 9996 return false; 9997 } 9998 9999 bool status = psDBCreateTable(dbh, DIFFRUN_TABLE_NAME, md); 10000 10001 psFree(md); 10002 10003 return status; 10004 } 10005 10006 bool diffRunDropTable(psDB *dbh) 10007 { 10008 return psDBDropTable(dbh, DIFFRUN_TABLE_NAME); 10009 } 10010 10011 bool diffRunInsert(psDB * dbh, psS64 diff_id, const char *state, const char *workdir, const char *dvodb, psTime* registered, const char *skycell_id, const char *tess_id) 10012 { 10013 psMetadata *md = psMetadataAlloc(); 10014 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, NULL, diff_id)) { 10015 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id"); 10016 psFree(md); 10017 return false; 10018 } 10019 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) { 10020 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 10021 psFree(md); 10022 return false; 10023 } 10024 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, workdir)) { 10025 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 10026 psFree(md); 10027 return false; 10028 } 10029 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, dvodb)) { 10030 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 10031 psFree(md); 10032 return false; 10033 } 10034 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, registered)) { 10035 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 10036 psFree(md); 10037 return false; 10038 } 10039 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) { 10040 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 10041 psFree(md); 10042 return false; 10043 } 10044 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 10045 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 10046 psFree(md); 10047 return false; 10048 } 10049 10050 bool status = psDBInsertOneRow(dbh, DIFFRUN_TABLE_NAME, md); 10051 psFree(md); 10052 10053 return status; 10054 } 10055 10056 long long diffRunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 10057 { 10058 long long deleted = 0; 10059 10060 long long count = psDBDeleteRows(dbh, DIFFRUN_TABLE_NAME, where, limit); 10061 if (count < 0) { 10062 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffRun"); 10063 return count; 10064 10065 deleted += count; 10066 } 10067 10068 return deleted; 10069 } 10070 bool diffRunInsertObject(psDB *dbh, diffRunRow *object) 10071 { 10072 return diffRunInsert(dbh, object->diff_id, object->state, object->workdir, object->dvodb, object->registered, object->skycell_id, object->tess_id); 10073 } 10074 10075 bool diffRunInsertObjects(psDB *dbh, psArray *objects) 10076 { 10077 for (long i = 0; i < psArrayLength(objects); i++) { 10078 if (!diffRunInsertObject(dbh, objects->data[i])) { 10079 return false; 10080 } 10081 } 10082 10083 return true; 10084 } 10085 10086 bool diffRunInsertFits(psDB *dbh, const psFits *fits) 10087 { 10088 psArray *rowSet; 10089 10090 // move to (the first?) extension named DIFFRUN_TABLE_NAME 10091 if (!psFitsMoveExtName(fits, DIFFRUN_TABLE_NAME)) { 10092 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", DIFFRUN_TABLE_NAME); 10093 return false; 10094 } 10095 10096 // check HDU type 10097 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 10098 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 10099 return false; 10100 } 10101 10102 // read fits table 10103 rowSet = psFitsReadTable(fits); 10104 if (!rowSet) { 10105 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 10106 psFree(rowSet); 10107 return false; 10108 } 10109 10110 if (!psDBInsertRows(dbh, DIFFRUN_TABLE_NAME, rowSet)) { 10111 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 10112 psFree(rowSet); 10113 return false; 10114 } 10115 10116 psFree(rowSet); 10117 10118 return true; 10119 } 10120 10121 bool diffRunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 10122 { 10123 psArray *rowSet; 10124 10125 rowSet = psDBSelectRows(dbh, DIFFRUN_TABLE_NAME, where, limit); 10126 if (!rowSet) { 10127 return false; 10128 } 10129 10130 // output to fits 10131 if (!psFitsWriteTable(fits, NULL, rowSet, DIFFRUN_TABLE_NAME)) { 10132 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 10133 psFree(rowSet); 10134 return false; 10135 } 10136 10137 psFree(rowSet); 10138 10139 return true; 10140 } 10141 10142 psMetadata *diffRunMetadataFromObject(const diffRunRow *object) 10143 { 10144 psMetadata *md = psMetadataAlloc(); 10145 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, NULL, object->diff_id)) { 10146 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id"); 10147 psFree(md); 10148 return false; 10149 } 10150 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) { 10151 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 10152 psFree(md); 10153 return false; 10154 } 10155 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, object->workdir)) { 10156 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 10157 psFree(md); 10158 return false; 10159 } 10160 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, object->dvodb)) { 10161 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 10162 psFree(md); 10163 return false; 10164 } 10165 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, object->registered)) { 10166 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 10167 psFree(md); 10168 return false; 10169 } 10170 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) { 10171 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 10172 psFree(md); 10173 return false; 10174 } 10175 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) { 10176 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 10177 psFree(md); 10178 return false; 10179 } 10180 10181 10182 return md; 10183 } 10184 10185 diffRunRow *diffRunObjectFromMetadata(psMetadata *md) 10186 { 10187 10188 bool status = false; 10189 psS64 diff_id = psMetadataLookupS64(&status, md, "diff_id"); 10190 if (!status) { 10191 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item diff_id"); 10192 return false; 10193 } 10194 char* state = psMetadataLookupPtr(&status, md, "state"); 10195 if (!status) { 10196 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state"); 10197 return false; 10198 } 10199 char* workdir = psMetadataLookupPtr(&status, md, "workdir"); 10200 if (!status) { 10201 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item workdir"); 10202 return false; 10203 } 10204 char* dvodb = psMetadataLookupPtr(&status, md, "dvodb"); 10205 if (!status) { 10206 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item dvodb"); 10207 return false; 10208 } 10209 psTime* registered = psMetadataLookupPtr(&status, md, "registered"); 10210 if (!status) { 10211 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item registered"); 10212 return false; 10213 } 10214 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id"); 10215 if (!status) { 10216 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id"); 10217 return false; 10218 } 10219 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 10220 if (!status) { 10221 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 10222 return false; 10223 } 10224 10225 return diffRunRowAlloc(diff_id, state, workdir, dvodb, registered, skycell_id, tess_id); 10226 } 10227 psArray *diffRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 10228 { 10229 psArray *rowSet; 10230 psArray *returnSet; 10231 psU64 i; 10232 10233 rowSet = psDBSelectRows(dbh, DIFFRUN_TABLE_NAME, where, limit); 10234 if (!rowSet) { 10235 return NULL; 10236 } 10237 10238 // convert psMetadata rows to row objects 10239 10240 returnSet = psArrayAllocEmpty(rowSet->n); 10241 10242 for (i = 0; i < rowSet->n; i++) { 10243 diffRunRow *object = diffRunObjectFromMetadata(rowSet->data[i]); 10244 psArrayAdd(returnSet, 0, object); 10245 psFree(object); 10246 } 10247 10248 psFree(rowSet); 10249 10250 return returnSet; 10251 } 10252 bool diffRunDeleteObject(psDB *dbh, const diffRunRow *object) 10253 { 10254 psMetadata *where = diffRunMetadataFromObject(object); 10255 long long count = psDBDeleteRows(dbh, DIFFRUN_TABLE_NAME, where, 0); 10256 psFree(where); 10257 if (count < 0) { 10258 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffRun"); 10259 return false; 10260 } 10261 if (count > 1) { 10262 // XXX should this be a psAbort() instead? It is possible that 10263 // having an object match multiple rows was by design. 10264 psError(PS_ERR_UNKNOWN, true, "diffRunRow object matched more then one row. Check your database schema"); 10265 return false; 10266 } 10267 10268 return true; 10269 } 10270 long long diffRunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 10271 { 10272 long long deleted = 0; 10273 10274 for (long long i = 0; i < objects->n; i++) { 10275 diffRunRow *object = objects->data[i]; 10276 psMetadata *where = diffRunMetadataFromObject(object); 10277 long long count = psDBDeleteRows(dbh, DIFFRUN_TABLE_NAME, where, limit); 10278 psFree(where); 10279 if (count < 0) { 10280 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffRun"); 10281 return count; 10282 } 10283 10284 deleted += count; 10285 } 10286 10287 return deleted; 10288 } 10289 bool diffRunPrintObjects(FILE *stream, psArray *objects, bool mdcf) 10290 { 10291 PS_ASSERT_PTR_NON_NULL(objects, false); 10292 10293 psMetadata *output = psMetadataAlloc(); 10294 for (long i = 0; i < psArrayLength(objects); i++) { 10295 psMetadata *md = diffRunMetadataFromObject(objects->data[i]); 10296 if (!psMetadataAddMetadata( 10297 output, 10298 PS_LIST_TAIL, 10299 DIFFRUN_TABLE_NAME, 10300 PS_META_DUPLICATE_OK, 10301 NULL, 10302 md 10303 )) { 10304 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 10305 psFree(md); 10306 psFree(output); 10307 return false; 10308 } 10309 psFree(md); 10310 } 10311 10312 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 10313 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 10314 psFree(output); 10315 } 10316 psFree(output); 10317 10318 return true; 10319 } 10320 bool diffRunPrintObject(FILE *stream, diffRunRow *object, bool mdcf) 10321 { 10322 PS_ASSERT_PTR_NON_NULL(object, false); 10323 10324 psMetadata *md = diffRunMetadataFromObject(object); 10325 10326 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 10327 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 10328 psFree(md); 10329 } 10330 10331 psFree(md); 10332 10333 return true; 10334 } 10335 static void diffInputSkyfileRowFree(diffInputSkyfileRow *object); 10336 10337 diffInputSkyfileRow *diffInputSkyfileRowAlloc(psS64 diff_id, psS64 warp_id, const char *skycell_id, const char *tess_id, const char *kind, bool template) 10338 { 10339 diffInputSkyfileRow *_object; 10340 10341 _object = psAlloc(sizeof(diffInputSkyfileRow)); 10342 psMemSetDeallocator(_object, (psFreeFunc)diffInputSkyfileRowFree); 10343 10344 _object->diff_id = diff_id; 10345 _object->warp_id = warp_id; 10346 _object->skycell_id = psStringCopy(skycell_id); 10347 _object->tess_id = psStringCopy(tess_id); 10348 _object->kind = psStringCopy(kind); 10349 _object->template = template; 10350 10351 return _object; 10352 } 10353 10354 static void diffInputSkyfileRowFree(diffInputSkyfileRow *object) 10355 { 10356 psFree(object->skycell_id); 10357 psFree(object->tess_id); 10358 psFree(object->kind); 10359 } 10360 10361 bool diffInputSkyfileCreateTable(psDB *dbh) 10362 { 10363 psMetadata *md = psMetadataAlloc(); 10364 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, "Primary Key fkey(diff_id) ref diffRun(diff_id)", 0)) { 10365 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id"); 10366 psFree(md); 10367 return false; 10368 } 10369 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key fkey(warp_id, skycell_id, tess_id) ref warpSkyfile(warp_id, skycell_id, tess_id)", 0)) { 10370 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 10371 psFree(md); 10372 return false; 10373 } 10374 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) { 10375 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 10376 psFree(md); 10377 return false; 10378 } 10379 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) { 10380 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 10381 psFree(md); 10382 return false; 10383 } 10384 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, "Key", "64")) { 10385 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); 10386 psFree(md); 10387 return false; 10388 } 10389 if (!psMetadataAdd(md, PS_LIST_TAIL, "template", PS_DATA_BOOL, NULL, 0)) { 10390 psError(PS_ERR_UNKNOWN, false, "failed to add item template"); 10391 psFree(md); 10392 return false; 10393 } 10394 10395 bool status = psDBCreateTable(dbh, DIFFINPUTSKYFILE_TABLE_NAME, md); 10396 10397 psFree(md); 10398 10399 return status; 10400 } 10401 10402 bool diffInputSkyfileDropTable(psDB *dbh) 10403 { 10404 return psDBDropTable(dbh, DIFFINPUTSKYFILE_TABLE_NAME); 10405 } 10406 10407 bool diffInputSkyfileInsert(psDB * dbh, psS64 diff_id, psS64 warp_id, const char *skycell_id, const char *tess_id, const char *kind, bool template) 10408 { 10409 psMetadata *md = psMetadataAlloc(); 10410 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, NULL, diff_id)) { 10411 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id"); 10412 psFree(md); 10413 return false; 10414 } 10415 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, warp_id)) { 10416 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 10417 psFree(md); 10418 return false; 10419 } 10420 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) { 10421 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 10422 psFree(md); 10423 return false; 10424 } 10425 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 10426 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 10427 psFree(md); 10428 return false; 10429 } 10430 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, kind)) { 10431 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); 10432 psFree(md); 10433 return false; 10434 } 10435 if (!psMetadataAdd(md, PS_LIST_TAIL, "template", PS_DATA_BOOL, NULL, template)) { 10436 psError(PS_ERR_UNKNOWN, false, "failed to add item template"); 10437 psFree(md); 10438 return false; 10439 } 10440 10441 bool status = psDBInsertOneRow(dbh, DIFFINPUTSKYFILE_TABLE_NAME, md); 10442 psFree(md); 10443 10444 return status; 10445 } 10446 10447 long long diffInputSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 10448 { 10449 long long deleted = 0; 10450 10451 long long count = psDBDeleteRows(dbh, DIFFINPUTSKYFILE_TABLE_NAME, where, limit); 10452 if (count < 0) { 10453 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffInputSkyfile"); 10454 return count; 10455 10456 deleted += count; 10457 } 10458 10459 return deleted; 10460 } 10461 bool diffInputSkyfileInsertObject(psDB *dbh, diffInputSkyfileRow *object) 10462 { 10463 return diffInputSkyfileInsert(dbh, object->diff_id, object->warp_id, object->skycell_id, object->tess_id, object->kind, object->template); 10464 } 10465 10466 bool diffInputSkyfileInsertObjects(psDB *dbh, psArray *objects) 10467 { 10468 for (long i = 0; i < psArrayLength(objects); i++) { 10469 if (!diffInputSkyfileInsertObject(dbh, objects->data[i])) { 10470 return false; 10471 } 10472 } 10473 10474 return true; 10475 } 10476 10477 bool diffInputSkyfileInsertFits(psDB *dbh, const psFits *fits) 10478 { 10479 psArray *rowSet; 10480 10481 // move to (the first?) extension named DIFFINPUTSKYFILE_TABLE_NAME 10482 if (!psFitsMoveExtName(fits, DIFFINPUTSKYFILE_TABLE_NAME)) { 10483 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", DIFFINPUTSKYFILE_TABLE_NAME); 10484 return false; 10485 } 10486 10487 // check HDU type 10488 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 10489 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 10490 return false; 10491 } 10492 10493 // read fits table 10494 rowSet = psFitsReadTable(fits); 10495 if (!rowSet) { 10496 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 10497 psFree(rowSet); 10498 return false; 10499 } 10500 10501 if (!psDBInsertRows(dbh, DIFFINPUTSKYFILE_TABLE_NAME, rowSet)) { 10502 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 10503 psFree(rowSet); 10504 return false; 10505 } 10506 10507 psFree(rowSet); 10508 10509 return true; 10510 } 10511 10512 bool diffInputSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 10513 { 10514 psArray *rowSet; 10515 10516 rowSet = psDBSelectRows(dbh, DIFFINPUTSKYFILE_TABLE_NAME, where, limit); 10517 if (!rowSet) { 10518 return false; 10519 } 10520 10521 // output to fits 10522 if (!psFitsWriteTable(fits, NULL, rowSet, DIFFINPUTSKYFILE_TABLE_NAME)) { 10523 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 10524 psFree(rowSet); 10525 return false; 10526 } 10527 10528 psFree(rowSet); 10529 10530 return true; 10531 } 10532 10533 psMetadata *diffInputSkyfileMetadataFromObject(const diffInputSkyfileRow *object) 10534 { 10535 psMetadata *md = psMetadataAlloc(); 10536 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, NULL, object->diff_id)) { 10537 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id"); 10538 psFree(md); 10539 return false; 10540 } 10541 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, object->warp_id)) { 10542 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 10543 psFree(md); 10544 return false; 10545 } 10546 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) { 10547 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 10548 psFree(md); 10549 return false; 10550 } 10551 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) { 10552 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 10553 psFree(md); 10554 return false; 10555 } 10556 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, object->kind)) { 10557 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); 10558 psFree(md); 10559 return false; 10560 } 10561 if (!psMetadataAdd(md, PS_LIST_TAIL, "template", PS_DATA_BOOL, NULL, object->template)) { 10562 psError(PS_ERR_UNKNOWN, false, "failed to add item template"); 10563 psFree(md); 10564 return false; 10565 } 10566 10567 10568 return md; 10569 } 10570 10571 diffInputSkyfileRow *diffInputSkyfileObjectFromMetadata(psMetadata *md) 10572 { 10573 10574 bool status = false; 10575 psS64 diff_id = psMetadataLookupS64(&status, md, "diff_id"); 10576 if (!status) { 10577 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item diff_id"); 10578 return false; 10579 } 10580 psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id"); 10581 if (!status) { 10582 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item warp_id"); 10583 return false; 10584 } 10585 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id"); 10586 if (!status) { 10587 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id"); 10588 return false; 10589 } 10590 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 10591 if (!status) { 10592 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 10593 return false; 10594 } 10595 char* kind = psMetadataLookupPtr(&status, md, "kind"); 10596 if (!status) { 10597 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item kind"); 10598 return false; 10599 } 10600 bool template = psMetadataLookupBool(&status, md, "template"); 10601 if (!status) { 10602 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item template"); 10603 return false; 10604 } 10605 10606 return diffInputSkyfileRowAlloc(diff_id, warp_id, skycell_id, tess_id, kind, template); 10607 } 10608 psArray *diffInputSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 10609 { 10610 psArray *rowSet; 10611 psArray *returnSet; 10612 psU64 i; 10613 10614 rowSet = psDBSelectRows(dbh, DIFFINPUTSKYFILE_TABLE_NAME, where, limit); 10615 if (!rowSet) { 10616 return NULL; 10617 } 10618 10619 // convert psMetadata rows to row objects 10620 10621 returnSet = psArrayAllocEmpty(rowSet->n); 10622 10623 for (i = 0; i < rowSet->n; i++) { 10624 diffInputSkyfileRow *object = diffInputSkyfileObjectFromMetadata(rowSet->data[i]); 10625 psArrayAdd(returnSet, 0, object); 10626 psFree(object); 10627 } 10628 10629 psFree(rowSet); 10630 10631 return returnSet; 10632 } 10633 bool diffInputSkyfileDeleteObject(psDB *dbh, const diffInputSkyfileRow *object) 10634 { 10635 psMetadata *where = diffInputSkyfileMetadataFromObject(object); 10636 long long count = psDBDeleteRows(dbh, DIFFINPUTSKYFILE_TABLE_NAME, where, 0); 10637 psFree(where); 10638 if (count < 0) { 10639 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffInputSkyfile"); 10640 return false; 10641 } 10642 if (count > 1) { 10643 // XXX should this be a psAbort() instead? It is possible that 10644 // having an object match multiple rows was by design. 10645 psError(PS_ERR_UNKNOWN, true, "diffInputSkyfileRow object matched more then one row. Check your database schema"); 10646 return false; 10647 } 10648 10649 return true; 10650 } 10651 long long diffInputSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 10652 { 10653 long long deleted = 0; 10654 10655 for (long long i = 0; i < objects->n; i++) { 10656 diffInputSkyfileRow *object = objects->data[i]; 10657 psMetadata *where = diffInputSkyfileMetadataFromObject(object); 10658 long long count = psDBDeleteRows(dbh, DIFFINPUTSKYFILE_TABLE_NAME, where, limit); 10659 psFree(where); 10660 if (count < 0) { 10661 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffInputSkyfile"); 10662 return count; 10663 } 10664 10665 deleted += count; 10666 } 10667 10668 return deleted; 10669 } 10670 bool diffInputSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 10671 { 10672 PS_ASSERT_PTR_NON_NULL(objects, false); 10673 10674 psMetadata *output = psMetadataAlloc(); 10675 for (long i = 0; i < psArrayLength(objects); i++) { 10676 psMetadata *md = diffInputSkyfileMetadataFromObject(objects->data[i]); 10677 if (!psMetadataAddMetadata( 10678 output, 10679 PS_LIST_TAIL, 10680 DIFFINPUTSKYFILE_TABLE_NAME, 10681 PS_META_DUPLICATE_OK, 10682 NULL, 10683 md 10684 )) { 10685 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 10686 psFree(md); 10687 psFree(output); 10688 return false; 10689 } 10690 psFree(md); 10691 } 10692 10693 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 10694 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 10695 psFree(output); 10696 } 10697 psFree(output); 10698 10699 return true; 10700 } 10701 bool diffInputSkyfilePrintObject(FILE *stream, diffInputSkyfileRow *object, bool mdcf) 10702 { 10703 PS_ASSERT_PTR_NON_NULL(object, false); 10704 10705 psMetadata *md = diffInputSkyfileMetadataFromObject(object); 10706 10707 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 10708 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 10709 psFree(md); 10710 } 10711 10712 psFree(md); 10713 10714 return true; 10715 } 10716 static void diffSkyfileRowFree(diffSkyfileRow *object); 10717 10718 diffSkyfileRow *diffSkyfileRowAlloc(psS64 diff_id, const char *uri, psF64 bg, psF64 bg_stdev) 10719 { 10720 diffSkyfileRow *_object; 10721 10722 _object = psAlloc(sizeof(diffSkyfileRow)); 10723 psMemSetDeallocator(_object, (psFreeFunc)diffSkyfileRowFree); 10724 10725 _object->diff_id = diff_id; 10726 _object->uri = psStringCopy(uri); 10727 _object->bg = bg; 10728 _object->bg_stdev = bg_stdev; 10729 10730 return _object; 10731 } 10732 10733 static void diffSkyfileRowFree(diffSkyfileRow *object) 10734 { 10735 psFree(object->uri); 10736 } 10737 10738 bool diffSkyfileCreateTable(psDB *dbh) 10739 { 10740 psMetadata *md = psMetadataAlloc(); 10741 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, "Primary Key fkey(diff_id) ref diffRun(diff_id)", 0)) { 10742 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id"); 10743 psFree(md); 10744 return false; 10745 } 10746 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 10747 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 10748 psFree(md); 10749 return false; 10750 } 10751 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, 0.0)) { 10752 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 10753 psFree(md); 10754 return false; 10755 } 10756 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, 0.0)) { 10757 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev"); 10758 psFree(md); 10759 return false; 10760 } 10761 10762 bool status = psDBCreateTable(dbh, DIFFSKYFILE_TABLE_NAME, md); 10763 10764 psFree(md); 10765 10766 return status; 10767 } 10768 10769 bool diffSkyfileDropTable(psDB *dbh) 10770 { 10771 return psDBDropTable(dbh, DIFFSKYFILE_TABLE_NAME); 10772 } 10773 10774 bool diffSkyfileInsert(psDB * dbh, psS64 diff_id, const char *uri, psF64 bg, psF64 bg_stdev) 10775 { 10776 psMetadata *md = psMetadataAlloc(); 10777 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, NULL, diff_id)) { 10778 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id"); 10779 psFree(md); 10780 return false; 10781 } 10782 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 10783 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 10784 psFree(md); 10785 return false; 10786 } 10787 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, bg)) { 10788 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 10789 psFree(md); 10790 return false; 10791 } 10792 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, bg_stdev)) { 10793 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev"); 10794 psFree(md); 10795 return false; 10796 } 10797 10798 bool status = psDBInsertOneRow(dbh, DIFFSKYFILE_TABLE_NAME, md); 10799 psFree(md); 10800 10801 return status; 10802 } 10803 10804 long long diffSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 10805 { 10806 long long deleted = 0; 10807 10808 long long count = psDBDeleteRows(dbh, DIFFSKYFILE_TABLE_NAME, where, limit); 10809 if (count < 0) { 10810 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffSkyfile"); 10811 return count; 10812 10813 deleted += count; 10814 } 10815 10816 return deleted; 10817 } 10818 bool diffSkyfileInsertObject(psDB *dbh, diffSkyfileRow *object) 10819 { 10820 return diffSkyfileInsert(dbh, object->diff_id, object->uri, object->bg, object->bg_stdev); 10821 } 10822 10823 bool diffSkyfileInsertObjects(psDB *dbh, psArray *objects) 10824 { 10825 for (long i = 0; i < psArrayLength(objects); i++) { 10826 if (!diffSkyfileInsertObject(dbh, objects->data[i])) { 10827 return false; 10828 } 10829 } 10830 10831 return true; 10832 } 10833 10834 bool diffSkyfileInsertFits(psDB *dbh, const psFits *fits) 10835 { 10836 psArray *rowSet; 10837 10838 // move to (the first?) extension named DIFFSKYFILE_TABLE_NAME 10839 if (!psFitsMoveExtName(fits, DIFFSKYFILE_TABLE_NAME)) { 10840 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", DIFFSKYFILE_TABLE_NAME); 10841 return false; 10842 } 10843 10844 // check HDU type 10845 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 10846 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 10847 return false; 10848 } 10849 10850 // read fits table 10851 rowSet = psFitsReadTable(fits); 10852 if (!rowSet) { 10853 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 10854 psFree(rowSet); 10855 return false; 10856 } 10857 10858 if (!psDBInsertRows(dbh, DIFFSKYFILE_TABLE_NAME, rowSet)) { 10859 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 10860 psFree(rowSet); 10861 return false; 10862 } 10863 10864 psFree(rowSet); 10865 10866 return true; 10867 } 10868 10869 bool diffSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 10870 { 10871 psArray *rowSet; 10872 10873 rowSet = psDBSelectRows(dbh, DIFFSKYFILE_TABLE_NAME, where, limit); 10874 if (!rowSet) { 10875 return false; 10876 } 10877 10878 // output to fits 10879 if (!psFitsWriteTable(fits, NULL, rowSet, DIFFSKYFILE_TABLE_NAME)) { 10880 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 10881 psFree(rowSet); 10882 return false; 10883 } 10884 10885 psFree(rowSet); 10886 10887 return true; 10888 } 10889 10890 psMetadata *diffSkyfileMetadataFromObject(const diffSkyfileRow *object) 10891 { 10892 psMetadata *md = psMetadataAlloc(); 10893 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, NULL, object->diff_id)) { 10894 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id"); 10895 psFree(md); 10896 return false; 10897 } 10898 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 10899 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 10900 psFree(md); 10901 return false; 10902 } 10903 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, object->bg)) { 10904 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 10905 psFree(md); 10906 return false; 10907 } 10908 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, object->bg_stdev)) { 10909 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev"); 10910 psFree(md); 10911 return false; 10912 } 10913 10914 10915 return md; 10916 } 10917 10918 diffSkyfileRow *diffSkyfileObjectFromMetadata(psMetadata *md) 10919 { 10920 10921 bool status = false; 10922 psS64 diff_id = psMetadataLookupS64(&status, md, "diff_id"); 10923 if (!status) { 10924 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item diff_id"); 10925 return false; 10926 } 10927 char* uri = psMetadataLookupPtr(&status, md, "uri"); 10928 if (!status) { 10929 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri"); 10930 return false; 10931 } 10932 psF64 bg = psMetadataLookupF64(&status, md, "bg"); 10933 if (!status) { 10934 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg"); 10935 return false; 10936 } 10937 psF64 bg_stdev = psMetadataLookupF64(&status, md, "bg_stdev"); 10938 if (!status) { 10939 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_stdev"); 10940 return false; 10941 } 10942 10943 return diffSkyfileRowAlloc(diff_id, uri, bg, bg_stdev); 10944 } 10945 psArray *diffSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 10946 { 10947 psArray *rowSet; 10948 psArray *returnSet; 10949 psU64 i; 10950 10951 rowSet = psDBSelectRows(dbh, DIFFSKYFILE_TABLE_NAME, where, limit); 10952 if (!rowSet) { 10953 return NULL; 10954 } 10955 10956 // convert psMetadata rows to row objects 10957 10958 returnSet = psArrayAllocEmpty(rowSet->n); 10959 10960 for (i = 0; i < rowSet->n; i++) { 10961 diffSkyfileRow *object = diffSkyfileObjectFromMetadata(rowSet->data[i]); 10962 psArrayAdd(returnSet, 0, object); 10963 psFree(object); 10964 } 10965 10966 psFree(rowSet); 10967 10968 return returnSet; 10969 } 10970 bool diffSkyfileDeleteObject(psDB *dbh, const diffSkyfileRow *object) 10971 { 10972 psMetadata *where = diffSkyfileMetadataFromObject(object); 10973 long long count = psDBDeleteRows(dbh, DIFFSKYFILE_TABLE_NAME, where, 0); 10974 psFree(where); 10975 if (count < 0) { 10976 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffSkyfile"); 10977 return false; 10978 } 10979 if (count > 1) { 10980 // XXX should this be a psAbort() instead? It is possible that 10981 // having an object match multiple rows was by design. 10982 psError(PS_ERR_UNKNOWN, true, "diffSkyfileRow object matched more then one row. Check your database schema"); 10983 return false; 10984 } 10985 10986 return true; 10987 } 10988 long long diffSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 10989 { 10990 long long deleted = 0; 10991 10992 for (long long i = 0; i < objects->n; i++) { 10993 diffSkyfileRow *object = objects->data[i]; 10994 psMetadata *where = diffSkyfileMetadataFromObject(object); 10995 long long count = psDBDeleteRows(dbh, DIFFSKYFILE_TABLE_NAME, where, limit); 10996 psFree(where); 10997 if (count < 0) { 10998 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffSkyfile"); 10999 return count; 11000 } 11001 11002 deleted += count; 11003 } 11004 11005 return deleted; 11006 } 11007 bool diffSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 11008 { 11009 PS_ASSERT_PTR_NON_NULL(objects, false); 11010 11011 psMetadata *output = psMetadataAlloc(); 11012 for (long i = 0; i < psArrayLength(objects); i++) { 11013 psMetadata *md = diffSkyfileMetadataFromObject(objects->data[i]); 11014 if (!psMetadataAddMetadata( 11015 output, 11016 PS_LIST_TAIL, 11017 DIFFSKYFILE_TABLE_NAME, 11018 PS_META_DUPLICATE_OK, 11019 NULL, 11020 md 11021 )) { 11022 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 11023 psFree(md); 11024 psFree(output); 11025 return false; 11026 } 11027 psFree(md); 11028 } 11029 11030 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 11031 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 11032 psFree(output); 11033 } 11034 psFree(output); 11035 11036 return true; 11037 } 11038 bool diffSkyfilePrintObject(FILE *stream, diffSkyfileRow *object, bool mdcf) 11039 { 11040 PS_ASSERT_PTR_NON_NULL(object, false); 11041 11042 psMetadata *md = diffSkyfileMetadataFromObject(object); 11043 11044 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 11045 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 11046 psFree(md); 11047 } 11048 11049 psFree(md); 11050 11051 return true; 11052 } 11053 static void stackRunRowFree(stackRunRow *object); 11054 11055 stackRunRow *stackRunRowAlloc(psS64 stack_id, const char *state, const char *workdir, const char *dvodb, psTime* registered, const char *skycell_id, const char *tess_id) 11056 { 11057 stackRunRow *_object; 11058 11059 _object = psAlloc(sizeof(stackRunRow)); 11060 psMemSetDeallocator(_object, (psFreeFunc)stackRunRowFree); 11061 11062 _object->stack_id = stack_id; 11063 _object->state = psStringCopy(state); 11064 _object->workdir = psStringCopy(workdir); 11065 _object->dvodb = psStringCopy(dvodb); 11066 _object->registered = psTimeCopy(registered); 11067 _object->skycell_id = psStringCopy(skycell_id); 11068 _object->tess_id = psStringCopy(tess_id); 11069 11070 return _object; 11071 } 11072 11073 static void stackRunRowFree(stackRunRow *object) 11074 { 11075 psFree(object->state); 11076 psFree(object->workdir); 11077 psFree(object->dvodb); 11078 psFree(object->registered); 11079 psFree(object->skycell_id); 11080 psFree(object->tess_id); 11081 } 11082 11083 bool stackRunCreateTable(psDB *dbh) 11084 { 11085 psMetadata *md = psMetadataAlloc(); 11086 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, "Primary Key AUTO_INCREMENT", 0)) { 11087 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id"); 11088 psFree(md); 11089 return false; 11090 } 11091 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "Key", "64")) { 11092 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 11093 psFree(md); 11094 return false; 11095 } 11096 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, "255")) { 11097 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 11098 psFree(md); 11099 return false; 11100 } 11101 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, "255")) { 11102 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 11103 psFree(md); 11104 return false; 11105 } 11106 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, NULL)) { 11107 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 11108 psFree(md); 11109 return false; 11110 } 11111 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Key", "64")) { 11112 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 11113 psFree(md); 11114 return false; 11115 } 11116 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Key", "64")) { 11117 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 11118 psFree(md); 11119 return false; 11120 } 11121 11122 bool status = psDBCreateTable(dbh, STACKRUN_TABLE_NAME, md); 11123 11124 psFree(md); 11125 11126 return status; 11127 } 11128 11129 bool stackRunDropTable(psDB *dbh) 11130 { 11131 return psDBDropTable(dbh, STACKRUN_TABLE_NAME); 11132 } 11133 11134 bool stackRunInsert(psDB * dbh, psS64 stack_id, const char *state, const char *workdir, const char *dvodb, psTime* registered, const char *skycell_id, const char *tess_id) 11135 { 11136 psMetadata *md = psMetadataAlloc(); 11137 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, NULL, stack_id)) { 11138 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id"); 11139 psFree(md); 11140 return false; 11141 } 11142 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) { 11143 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 11144 psFree(md); 11145 return false; 11146 } 11147 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, workdir)) { 11148 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 11149 psFree(md); 11150 return false; 11151 } 11152 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, dvodb)) { 11153 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 11154 psFree(md); 11155 return false; 11156 } 11157 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, registered)) { 11158 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 11159 psFree(md); 11160 return false; 11161 } 11162 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) { 11163 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 11164 psFree(md); 11165 return false; 11166 } 11167 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 11168 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 11169 psFree(md); 11170 return false; 11171 } 11172 11173 bool status = psDBInsertOneRow(dbh, STACKRUN_TABLE_NAME, md); 11174 psFree(md); 11175 11176 return status; 11177 } 11178 11179 long long stackRunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 11180 { 11181 long long deleted = 0; 11182 11183 long long count = psDBDeleteRows(dbh, STACKRUN_TABLE_NAME, where, limit); 11184 if (count < 0) { 11185 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackRun"); 11186 return count; 11187 11188 deleted += count; 11189 } 11190 11191 return deleted; 11192 } 11193 bool stackRunInsertObject(psDB *dbh, stackRunRow *object) 11194 { 11195 return stackRunInsert(dbh, object->stack_id, object->state, object->workdir, object->dvodb, object->registered, object->skycell_id, object->tess_id); 11196 } 11197 11198 bool stackRunInsertObjects(psDB *dbh, psArray *objects) 11199 { 11200 for (long i = 0; i < psArrayLength(objects); i++) { 11201 if (!stackRunInsertObject(dbh, objects->data[i])) { 11202 return false; 11203 } 11204 } 11205 11206 return true; 11207 } 11208 11209 bool stackRunInsertFits(psDB *dbh, const psFits *fits) 11210 { 11211 psArray *rowSet; 11212 11213 // move to (the first?) extension named STACKRUN_TABLE_NAME 11214 if (!psFitsMoveExtName(fits, STACKRUN_TABLE_NAME)) { 11215 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", STACKRUN_TABLE_NAME); 11216 return false; 11217 } 11218 11219 // check HDU type 11220 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 11221 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 11222 return false; 11223 } 11224 11225 // read fits table 11226 rowSet = psFitsReadTable(fits); 11227 if (!rowSet) { 11228 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 11229 psFree(rowSet); 11230 return false; 11231 } 11232 11233 if (!psDBInsertRows(dbh, STACKRUN_TABLE_NAME, rowSet)) { 11234 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 11235 psFree(rowSet); 11236 return false; 11237 } 11238 11239 psFree(rowSet); 11240 11241 return true; 11242 } 11243 11244 bool stackRunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 11245 { 11246 psArray *rowSet; 11247 11248 rowSet = psDBSelectRows(dbh, STACKRUN_TABLE_NAME, where, limit); 11249 if (!rowSet) { 11250 return false; 11251 } 11252 11253 // output to fits 11254 if (!psFitsWriteTable(fits, NULL, rowSet, STACKRUN_TABLE_NAME)) { 11255 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 11256 psFree(rowSet); 11257 return false; 11258 } 11259 11260 psFree(rowSet); 11261 11262 return true; 11263 } 11264 11265 psMetadata *stackRunMetadataFromObject(const stackRunRow *object) 11266 { 11267 psMetadata *md = psMetadataAlloc(); 11268 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, NULL, object->stack_id)) { 11269 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id"); 11270 psFree(md); 11271 return false; 11272 } 11273 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) { 11274 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 11275 psFree(md); 11276 return false; 11277 } 11278 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, object->workdir)) { 11279 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 11280 psFree(md); 11281 return false; 11282 } 11283 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, object->dvodb)) { 11284 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 11285 psFree(md); 11286 return false; 11287 } 11288 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, object->registered)) { 11289 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 11290 psFree(md); 11291 return false; 11292 } 11293 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) { 11294 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 11295 psFree(md); 11296 return false; 11297 } 11298 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) { 11299 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 11300 psFree(md); 11301 return false; 11302 } 11303 11304 11305 return md; 11306 } 11307 11308 stackRunRow *stackRunObjectFromMetadata(psMetadata *md) 11309 { 11310 11311 bool status = false; 11312 psS64 stack_id = psMetadataLookupS64(&status, md, "stack_id"); 11313 if (!status) { 11314 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item stack_id"); 11315 return false; 11316 } 11317 char* state = psMetadataLookupPtr(&status, md, "state"); 11318 if (!status) { 11319 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state"); 11320 return false; 11321 } 11322 char* workdir = psMetadataLookupPtr(&status, md, "workdir"); 11323 if (!status) { 11324 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item workdir"); 11325 return false; 11326 } 11327 char* dvodb = psMetadataLookupPtr(&status, md, "dvodb"); 11328 if (!status) { 11329 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item dvodb"); 11330 return false; 11331 } 11332 psTime* registered = psMetadataLookupPtr(&status, md, "registered"); 11333 if (!status) { 11334 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item registered"); 11335 return false; 11336 } 11337 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id"); 11338 if (!status) { 11339 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id"); 11340 return false; 11341 } 11342 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 11343 if (!status) { 11344 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 11345 return false; 11346 } 11347 11348 return stackRunRowAlloc(stack_id, state, workdir, dvodb, registered, skycell_id, tess_id); 11349 } 11350 psArray *stackRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 11351 { 11352 psArray *rowSet; 11353 psArray *returnSet; 11354 psU64 i; 11355 11356 rowSet = psDBSelectRows(dbh, STACKRUN_TABLE_NAME, where, limit); 11357 if (!rowSet) { 11358 return NULL; 11359 } 11360 11361 // convert psMetadata rows to row objects 11362 11363 returnSet = psArrayAllocEmpty(rowSet->n); 11364 11365 for (i = 0; i < rowSet->n; i++) { 11366 stackRunRow *object = stackRunObjectFromMetadata(rowSet->data[i]); 11367 psArrayAdd(returnSet, 0, object); 11368 psFree(object); 11369 } 11370 11371 psFree(rowSet); 11372 11373 return returnSet; 11374 } 11375 bool stackRunDeleteObject(psDB *dbh, const stackRunRow *object) 11376 { 11377 psMetadata *where = stackRunMetadataFromObject(object); 11378 long long count = psDBDeleteRows(dbh, STACKRUN_TABLE_NAME, where, 0); 11379 psFree(where); 11380 if (count < 0) { 11381 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackRun"); 11382 return false; 11383 } 11384 if (count > 1) { 11385 // XXX should this be a psAbort() instead? It is possible that 11386 // having an object match multiple rows was by design. 11387 psError(PS_ERR_UNKNOWN, true, "stackRunRow object matched more then one row. Check your database schema"); 11388 return false; 11389 } 11390 11391 return true; 11392 } 11393 long long stackRunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 11394 { 11395 long long deleted = 0; 11396 11397 for (long long i = 0; i < objects->n; i++) { 11398 stackRunRow *object = objects->data[i]; 11399 psMetadata *where = stackRunMetadataFromObject(object); 11400 long long count = psDBDeleteRows(dbh, STACKRUN_TABLE_NAME, where, limit); 11401 psFree(where); 11402 if (count < 0) { 11403 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackRun"); 11404 return count; 11405 } 11406 11407 deleted += count; 11408 } 11409 11410 return deleted; 11411 } 11412 bool stackRunPrintObjects(FILE *stream, psArray *objects, bool mdcf) 11413 { 11414 PS_ASSERT_PTR_NON_NULL(objects, false); 11415 11416 psMetadata *output = psMetadataAlloc(); 11417 for (long i = 0; i < psArrayLength(objects); i++) { 11418 psMetadata *md = stackRunMetadataFromObject(objects->data[i]); 11419 if (!psMetadataAddMetadata( 11420 output, 11421 PS_LIST_TAIL, 11422 STACKRUN_TABLE_NAME, 11423 PS_META_DUPLICATE_OK, 11424 NULL, 11425 md 11426 )) { 11427 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 11428 psFree(md); 11429 psFree(output); 11430 return false; 11431 } 11432 psFree(md); 11433 } 11434 11435 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 11436 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 11437 psFree(output); 11438 } 11439 psFree(output); 11440 11441 return true; 11442 } 11443 bool stackRunPrintObject(FILE *stream, stackRunRow *object, bool mdcf) 11444 { 11445 PS_ASSERT_PTR_NON_NULL(object, false); 11446 11447 psMetadata *md = stackRunMetadataFromObject(object); 11448 11449 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 11450 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 11451 psFree(md); 11452 } 11453 11454 psFree(md); 11455 11456 return true; 11457 } 11458 static void stackInputSkyfileRowFree(stackInputSkyfileRow *object); 11459 11460 stackInputSkyfileRow *stackInputSkyfileRowAlloc(psS64 stack_id, psS64 warp_id) 11461 { 11462 stackInputSkyfileRow *_object; 11463 11464 _object = psAlloc(sizeof(stackInputSkyfileRow)); 11465 psMemSetDeallocator(_object, (psFreeFunc)stackInputSkyfileRowFree); 11466 11467 _object->stack_id = stack_id; 11468 _object->warp_id = warp_id; 11469 11470 return _object; 11471 } 11472 11473 static void stackInputSkyfileRowFree(stackInputSkyfileRow *object) 11474 { 11475 } 11476 11477 bool stackInputSkyfileCreateTable(psDB *dbh) 11478 { 11479 psMetadata *md = psMetadataAlloc(); 11480 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, "Primary Key fkey(stack_id) ref stackRun(stack_id)", 0)) { 11481 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id"); 11482 psFree(md); 11483 return false; 11484 } 11485 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key fkey(warp_id) ref warpSkyfile(warp_id)", 0)) { 11486 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 11487 psFree(md); 11488 return false; 11489 } 11490 11491 bool status = psDBCreateTable(dbh, STACKINPUTSKYFILE_TABLE_NAME, md); 11492 11493 psFree(md); 11494 11495 return status; 11496 } 11497 11498 bool stackInputSkyfileDropTable(psDB *dbh) 11499 { 11500 return psDBDropTable(dbh, STACKINPUTSKYFILE_TABLE_NAME); 11501 } 11502 11503 bool stackInputSkyfileInsert(psDB * dbh, psS64 stack_id, psS64 warp_id) 11504 { 11505 psMetadata *md = psMetadataAlloc(); 11506 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, NULL, stack_id)) { 11507 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id"); 11508 psFree(md); 11509 return false; 11510 } 11511 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, warp_id)) { 11512 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 11513 psFree(md); 11514 return false; 11515 } 11516 11517 bool status = psDBInsertOneRow(dbh, STACKINPUTSKYFILE_TABLE_NAME, md); 11518 psFree(md); 11519 11520 return status; 11521 } 11522 11523 long long stackInputSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 11524 { 11525 long long deleted = 0; 11526 11527 long long count = psDBDeleteRows(dbh, STACKINPUTSKYFILE_TABLE_NAME, where, limit); 11528 if (count < 0) { 11529 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackInputSkyfile"); 11530 return count; 11531 11532 deleted += count; 11533 } 11534 11535 return deleted; 11536 } 11537 bool stackInputSkyfileInsertObject(psDB *dbh, stackInputSkyfileRow *object) 11538 { 11539 return stackInputSkyfileInsert(dbh, object->stack_id, object->warp_id); 11540 } 11541 11542 bool stackInputSkyfileInsertObjects(psDB *dbh, psArray *objects) 11543 { 11544 for (long i = 0; i < psArrayLength(objects); i++) { 11545 if (!stackInputSkyfileInsertObject(dbh, objects->data[i])) { 11546 return false; 11547 } 11548 } 11549 11550 return true; 11551 } 11552 11553 bool stackInputSkyfileInsertFits(psDB *dbh, const psFits *fits) 11554 { 11555 psArray *rowSet; 11556 11557 // move to (the first?) extension named STACKINPUTSKYFILE_TABLE_NAME 11558 if (!psFitsMoveExtName(fits, STACKINPUTSKYFILE_TABLE_NAME)) { 11559 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", STACKINPUTSKYFILE_TABLE_NAME); 11560 return false; 11561 } 11562 11563 // check HDU type 11564 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 11565 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 11566 return false; 11567 } 11568 11569 // read fits table 11570 rowSet = psFitsReadTable(fits); 11571 if (!rowSet) { 11572 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 11573 psFree(rowSet); 11574 return false; 11575 } 11576 11577 if (!psDBInsertRows(dbh, STACKINPUTSKYFILE_TABLE_NAME, rowSet)) { 11578 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 11579 psFree(rowSet); 11580 return false; 11581 } 11582 11583 psFree(rowSet); 11584 11585 return true; 11586 } 11587 11588 bool stackInputSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 11589 { 11590 psArray *rowSet; 11591 11592 rowSet = psDBSelectRows(dbh, STACKINPUTSKYFILE_TABLE_NAME, where, limit); 11593 if (!rowSet) { 11594 return false; 11595 } 11596 11597 // output to fits 11598 if (!psFitsWriteTable(fits, NULL, rowSet, STACKINPUTSKYFILE_TABLE_NAME)) { 11599 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 11600 psFree(rowSet); 11601 return false; 11602 } 11603 11604 psFree(rowSet); 11605 11606 return true; 11607 } 11608 11609 psMetadata *stackInputSkyfileMetadataFromObject(const stackInputSkyfileRow *object) 11610 { 11611 psMetadata *md = psMetadataAlloc(); 11612 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, NULL, object->stack_id)) { 11613 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id"); 11614 psFree(md); 11615 return false; 11616 } 11617 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, object->warp_id)) { 11618 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 11619 psFree(md); 11620 return false; 11621 } 11622 11623 11624 return md; 11625 } 11626 11627 stackInputSkyfileRow *stackInputSkyfileObjectFromMetadata(psMetadata *md) 11628 { 11629 11630 bool status = false; 11631 psS64 stack_id = psMetadataLookupS64(&status, md, "stack_id"); 11632 if (!status) { 11633 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item stack_id"); 11634 return false; 11635 } 11636 psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id"); 11637 if (!status) { 11638 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item warp_id"); 11639 return false; 11640 } 11641 11642 return stackInputSkyfileRowAlloc(stack_id, warp_id); 11643 } 11644 psArray *stackInputSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 11645 { 11646 psArray *rowSet; 11647 psArray *returnSet; 11648 psU64 i; 11649 11650 rowSet = psDBSelectRows(dbh, STACKINPUTSKYFILE_TABLE_NAME, where, limit); 11651 if (!rowSet) { 11652 return NULL; 11653 } 11654 11655 // convert psMetadata rows to row objects 11656 11657 returnSet = psArrayAllocEmpty(rowSet->n); 11658 11659 for (i = 0; i < rowSet->n; i++) { 11660 stackInputSkyfileRow *object = stackInputSkyfileObjectFromMetadata(rowSet->data[i]); 11661 psArrayAdd(returnSet, 0, object); 11662 psFree(object); 11663 } 11664 11665 psFree(rowSet); 11666 11667 return returnSet; 11668 } 11669 bool stackInputSkyfileDeleteObject(psDB *dbh, const stackInputSkyfileRow *object) 11670 { 11671 psMetadata *where = stackInputSkyfileMetadataFromObject(object); 11672 long long count = psDBDeleteRows(dbh, STACKINPUTSKYFILE_TABLE_NAME, where, 0); 11673 psFree(where); 11674 if (count < 0) { 11675 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackInputSkyfile"); 11676 return false; 11677 } 11678 if (count > 1) { 11679 // XXX should this be a psAbort() instead? It is possible that 11680 // having an object match multiple rows was by design. 11681 psError(PS_ERR_UNKNOWN, true, "stackInputSkyfileRow object matched more then one row. Check your database schema"); 11682 return false; 11683 } 11684 11685 return true; 11686 } 11687 long long stackInputSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 11688 { 11689 long long deleted = 0; 11690 11691 for (long long i = 0; i < objects->n; i++) { 11692 stackInputSkyfileRow *object = objects->data[i]; 11693 psMetadata *where = stackInputSkyfileMetadataFromObject(object); 11694 long long count = psDBDeleteRows(dbh, STACKINPUTSKYFILE_TABLE_NAME, where, limit); 11695 psFree(where); 11696 if (count < 0) { 11697 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackInputSkyfile"); 11698 return count; 11699 } 11700 11701 deleted += count; 11702 } 11703 11704 return deleted; 11705 } 11706 bool stackInputSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 11707 { 11708 PS_ASSERT_PTR_NON_NULL(objects, false); 11709 11710 psMetadata *output = psMetadataAlloc(); 11711 for (long i = 0; i < psArrayLength(objects); i++) { 11712 psMetadata *md = stackInputSkyfileMetadataFromObject(objects->data[i]); 11713 if (!psMetadataAddMetadata( 11714 output, 11715 PS_LIST_TAIL, 11716 STACKINPUTSKYFILE_TABLE_NAME, 11717 PS_META_DUPLICATE_OK, 11718 NULL, 11719 md 11720 )) { 11721 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 11722 psFree(md); 11723 psFree(output); 11724 return false; 11725 } 11726 psFree(md); 11727 } 11728 11729 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 11730 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 11731 psFree(output); 11732 } 11733 psFree(output); 11734 11735 return true; 11736 } 11737 bool stackInputSkyfilePrintObject(FILE *stream, stackInputSkyfileRow *object, bool mdcf) 11738 { 11739 PS_ASSERT_PTR_NON_NULL(object, false); 11740 11741 psMetadata *md = stackInputSkyfileMetadataFromObject(object); 11742 11743 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 11744 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 11745 psFree(md); 11746 } 11747 11748 psFree(md); 11749 11750 return true; 11751 } 11752 static void stackSumSkyfileRowFree(stackSumSkyfileRow *object); 11753 11754 stackSumSkyfileRow *stackSumSkyfileRowAlloc(psS64 stack_id, const char *uri, psF64 bg, psF64 bg_stdev) 11755 { 11756 stackSumSkyfileRow *_object; 11757 11758 _object = psAlloc(sizeof(stackSumSkyfileRow)); 11759 psMemSetDeallocator(_object, (psFreeFunc)stackSumSkyfileRowFree); 11760 11761 _object->stack_id = stack_id; 11762 _object->uri = psStringCopy(uri); 11763 _object->bg = bg; 11764 _object->bg_stdev = bg_stdev; 11765 11766 return _object; 11767 } 11768 11769 static void stackSumSkyfileRowFree(stackSumSkyfileRow *object) 11770 { 11771 psFree(object->uri); 11772 } 11773 11774 bool stackSumSkyfileCreateTable(psDB *dbh) 11775 { 11776 psMetadata *md = psMetadataAlloc(); 11777 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, "Primary Key fkey(stack_id) ref stackRun(stack_id)", 0)) { 11778 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id"); 11779 psFree(md); 11780 return false; 11781 } 11782 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 11783 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 11784 psFree(md); 11785 return false; 11786 } 11787 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, 0.0)) { 11788 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 11789 psFree(md); 11790 return false; 11791 } 11792 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, 0.0)) { 11793 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev"); 11794 psFree(md); 11795 return false; 11796 } 11797 11798 bool status = psDBCreateTable(dbh, STACKSUMSKYFILE_TABLE_NAME, md); 11799 11800 psFree(md); 11801 11802 return status; 11803 } 11804 11805 bool stackSumSkyfileDropTable(psDB *dbh) 11806 { 11807 return psDBDropTable(dbh, STACKSUMSKYFILE_TABLE_NAME); 11808 } 11809 11810 bool stackSumSkyfileInsert(psDB * dbh, psS64 stack_id, const char *uri, psF64 bg, psF64 bg_stdev) 11811 { 11812 psMetadata *md = psMetadataAlloc(); 11813 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, NULL, stack_id)) { 11814 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id"); 11815 psFree(md); 11816 return false; 11817 } 11818 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 11819 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 11820 psFree(md); 11821 return false; 11822 } 11823 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, bg)) { 11824 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 11825 psFree(md); 11826 return false; 11827 } 11828 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, bg_stdev)) { 11829 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev"); 11830 psFree(md); 11831 return false; 11832 } 11833 11834 bool status = psDBInsertOneRow(dbh, STACKSUMSKYFILE_TABLE_NAME, md); 11835 psFree(md); 11836 11837 return status; 11838 } 11839 11840 long long stackSumSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 11841 { 11842 long long deleted = 0; 11843 11844 long long count = psDBDeleteRows(dbh, STACKSUMSKYFILE_TABLE_NAME, where, limit); 11845 if (count < 0) { 11846 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackSumSkyfile"); 11847 return count; 11848 11849 deleted += count; 11850 } 11851 11852 return deleted; 11853 } 11854 bool stackSumSkyfileInsertObject(psDB *dbh, stackSumSkyfileRow *object) 11855 { 11856 return stackSumSkyfileInsert(dbh, object->stack_id, object->uri, object->bg, object->bg_stdev); 11857 } 11858 11859 bool stackSumSkyfileInsertObjects(psDB *dbh, psArray *objects) 11860 { 11861 for (long i = 0; i < psArrayLength(objects); i++) { 11862 if (!stackSumSkyfileInsertObject(dbh, objects->data[i])) { 11863 return false; 11864 } 11865 } 11866 11867 return true; 11868 } 11869 11870 bool stackSumSkyfileInsertFits(psDB *dbh, const psFits *fits) 11871 { 11872 psArray *rowSet; 11873 11874 // move to (the first?) extension named STACKSUMSKYFILE_TABLE_NAME 11875 if (!psFitsMoveExtName(fits, STACKSUMSKYFILE_TABLE_NAME)) { 11876 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", STACKSUMSKYFILE_TABLE_NAME); 11877 return false; 11878 } 11879 11880 // check HDU type 11881 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 11882 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 11883 return false; 11884 } 11885 11886 // read fits table 11887 rowSet = psFitsReadTable(fits); 11888 if (!rowSet) { 11889 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 11890 psFree(rowSet); 11891 return false; 11892 } 11893 11894 if (!psDBInsertRows(dbh, STACKSUMSKYFILE_TABLE_NAME, rowSet)) { 11895 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 11896 psFree(rowSet); 11897 return false; 11898 } 11899 11900 psFree(rowSet); 11901 11902 return true; 11903 } 11904 11905 bool stackSumSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 11906 { 11907 psArray *rowSet; 11908 11909 rowSet = psDBSelectRows(dbh, STACKSUMSKYFILE_TABLE_NAME, where, limit); 11910 if (!rowSet) { 11911 return false; 11912 } 11913 11914 // output to fits 11915 if (!psFitsWriteTable(fits, NULL, rowSet, STACKSUMSKYFILE_TABLE_NAME)) { 11916 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 11917 psFree(rowSet); 11918 return false; 11919 } 11920 11921 psFree(rowSet); 11922 11923 return true; 11924 } 11925 11926 psMetadata *stackSumSkyfileMetadataFromObject(const stackSumSkyfileRow *object) 11927 { 11928 psMetadata *md = psMetadataAlloc(); 11929 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, NULL, object->stack_id)) { 11930 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id"); 11931 psFree(md); 11932 return false; 11933 } 11934 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 11935 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 11936 psFree(md); 11937 return false; 11938 } 11939 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, object->bg)) { 11940 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 11941 psFree(md); 11942 return false; 11943 } 11944 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, object->bg_stdev)) { 11945 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev"); 11946 psFree(md); 11947 return false; 11948 } 11949 11950 11951 return md; 11952 } 11953 11954 stackSumSkyfileRow *stackSumSkyfileObjectFromMetadata(psMetadata *md) 11955 { 11956 11957 bool status = false; 11958 psS64 stack_id = psMetadataLookupS64(&status, md, "stack_id"); 11959 if (!status) { 11960 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item stack_id"); 11961 return false; 11962 } 11963 char* uri = psMetadataLookupPtr(&status, md, "uri"); 11964 if (!status) { 11965 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri"); 11966 return false; 11967 } 11968 psF64 bg = psMetadataLookupF64(&status, md, "bg"); 11969 if (!status) { 11970 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg"); 11971 return false; 11972 } 11973 psF64 bg_stdev = psMetadataLookupF64(&status, md, "bg_stdev"); 11974 if (!status) { 11975 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_stdev"); 11976 return false; 11977 } 11978 11979 return stackSumSkyfileRowAlloc(stack_id, uri, bg, bg_stdev); 11980 } 11981 psArray *stackSumSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 11982 { 11983 psArray *rowSet; 11984 psArray *returnSet; 11985 psU64 i; 11986 11987 rowSet = psDBSelectRows(dbh, STACKSUMSKYFILE_TABLE_NAME, where, limit); 11988 if (!rowSet) { 11989 return NULL; 11990 } 11991 11992 // convert psMetadata rows to row objects 11993 11994 returnSet = psArrayAllocEmpty(rowSet->n); 11995 11996 for (i = 0; i < rowSet->n; i++) { 11997 stackSumSkyfileRow *object = stackSumSkyfileObjectFromMetadata(rowSet->data[i]); 11998 psArrayAdd(returnSet, 0, object); 11999 psFree(object); 12000 } 12001 12002 psFree(rowSet); 12003 12004 return returnSet; 12005 } 12006 bool stackSumSkyfileDeleteObject(psDB *dbh, const stackSumSkyfileRow *object) 12007 { 12008 psMetadata *where = stackSumSkyfileMetadataFromObject(object); 12009 long long count = psDBDeleteRows(dbh, STACKSUMSKYFILE_TABLE_NAME, where, 0); 12010 psFree(where); 12011 if (count < 0) { 12012 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackSumSkyfile"); 12013 return false; 12014 } 12015 if (count > 1) { 12016 // XXX should this be a psAbort() instead? It is possible that 12017 // having an object match multiple rows was by design. 12018 psError(PS_ERR_UNKNOWN, true, "stackSumSkyfileRow object matched more then one row. Check your database schema"); 12019 return false; 12020 } 12021 12022 return true; 12023 } 12024 long long stackSumSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 12025 { 12026 long long deleted = 0; 12027 12028 for (long long i = 0; i < objects->n; i++) { 12029 stackSumSkyfileRow *object = objects->data[i]; 12030 psMetadata *where = stackSumSkyfileMetadataFromObject(object); 12031 long long count = psDBDeleteRows(dbh, STACKSUMSKYFILE_TABLE_NAME, where, limit); 12032 psFree(where); 12033 if (count < 0) { 12034 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackSumSkyfile"); 12035 return count; 12036 } 12037 12038 deleted += count; 12039 } 12040 12041 return deleted; 12042 } 12043 bool stackSumSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 12044 { 12045 PS_ASSERT_PTR_NON_NULL(objects, false); 12046 12047 psMetadata *output = psMetadataAlloc(); 12048 for (long i = 0; i < psArrayLength(objects); i++) { 12049 psMetadata *md = stackSumSkyfileMetadataFromObject(objects->data[i]); 12050 if (!psMetadataAddMetadata( 12051 output, 12052 PS_LIST_TAIL, 12053 STACKSUMSKYFILE_TABLE_NAME, 12054 PS_META_DUPLICATE_OK, 12055 NULL, 12056 md 12057 )) { 12058 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 12059 psFree(md); 12060 psFree(output); 12061 return false; 12062 } 12063 psFree(md); 12064 } 12065 12066 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 12067 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 12068 psFree(output); 12069 } 12070 psFree(output); 12071 12072 return true; 12073 } 12074 bool stackSumSkyfilePrintObject(FILE *stream, stackSumSkyfileRow *object, bool mdcf) 12075 { 12076 PS_ASSERT_PTR_NON_NULL(object, false); 12077 12078 psMetadata *md = stackSumSkyfileMetadataFromObject(object); 8460 12079 8461 12080 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { … … 13570 17189 return true; 13571 17190 } 13572 static void warpRunRowFree(warpRunRow *object);13573 13574 warpRunRow *warpRunRowAlloc(psS64 warp_id, const char *mode, const char *state, const char *workdir, const char *dvodb, psTime* registered)13575 {13576 warpRunRow *_object;13577 13578 _object = psAlloc(sizeof(warpRunRow));13579 psMemSetDeallocator(_object, (psFreeFunc)warpRunRowFree);13580 13581 _object->warp_id = warp_id;13582 _object->mode = psStringCopy(mode);13583 _object->state = psStringCopy(state);13584 _object->workdir = psStringCopy(workdir);13585 _object->dvodb = psStringCopy(dvodb);13586 _object->registered = psTimeCopy(registered);13587 13588 return _object;13589 }13590 13591 static void warpRunRowFree(warpRunRow *object)13592 {13593 psFree(object->mode);13594 psFree(object->state);13595 psFree(object->workdir);13596 psFree(object->dvodb);13597 psFree(object->registered);13598 }13599 13600 bool warpRunCreateTable(psDB *dbh)13601 {13602 psMetadata *md = psMetadataAlloc();13603 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key AUTO_INCREMENT", 0)) {13604 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");13605 psFree(md);13606 return false;13607 }13608 if (!psMetadataAdd(md, PS_LIST_TAIL, "mode", PS_DATA_STRING, "Key", "64")) {13609 psError(PS_ERR_UNKNOWN, false, "failed to add item mode");13610 psFree(md);13611 return false;13612 }13613 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "Key", "64")) {13614 psError(PS_ERR_UNKNOWN, false, "failed to add item state");13615 psFree(md);13616 return false;13617 }13618 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, "255")) {13619 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir");13620 psFree(md);13621 return false;13622 }13623 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, "255")) {13624 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb");13625 psFree(md);13626 return false;13627 }13628 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, NULL)) {13629 psError(PS_ERR_UNKNOWN, false, "failed to add item registered");13630 psFree(md);13631 return false;13632 }13633 13634 bool status = psDBCreateTable(dbh, WARPRUN_TABLE_NAME, md);13635 13636 psFree(md);13637 13638 return status;13639 }13640 13641 bool warpRunDropTable(psDB *dbh)13642 {13643 return psDBDropTable(dbh, WARPRUN_TABLE_NAME);13644 }13645 13646 bool warpRunInsert(psDB * dbh, psS64 warp_id, const char *mode, const char *state, const char *workdir, const char *dvodb, psTime* registered)13647 {13648 psMetadata *md = psMetadataAlloc();13649 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, warp_id)) {13650 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");13651 psFree(md);13652 return false;13653 }13654 if (!psMetadataAdd(md, PS_LIST_TAIL, "mode", PS_DATA_STRING, NULL, mode)) {13655 psError(PS_ERR_UNKNOWN, false, "failed to add item mode");13656 psFree(md);13657 return false;13658 }13659 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) {13660 psError(PS_ERR_UNKNOWN, false, "failed to add item state");13661 psFree(md);13662 return false;13663 }13664 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, workdir)) {13665 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir");13666 psFree(md);13667 return false;13668 }13669 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, dvodb)) {13670 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb");13671 psFree(md);13672 return false;13673 }13674 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, registered)) {13675 psError(PS_ERR_UNKNOWN, false, "failed to add item registered");13676 psFree(md);13677 return false;13678 }13679 13680 bool status = psDBInsertOneRow(dbh, WARPRUN_TABLE_NAME, md);13681 psFree(md);13682 13683 return status;13684 }13685 13686 long long warpRunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)13687 {13688 long long deleted = 0;13689 13690 long long count = psDBDeleteRows(dbh, WARPRUN_TABLE_NAME, where, limit);13691 if (count < 0) {13692 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpRun");13693 return count;13694 13695 deleted += count;13696 }13697 13698 return deleted;13699 }13700 bool warpRunInsertObject(psDB *dbh, warpRunRow *object)13701 {13702 return warpRunInsert(dbh, object->warp_id, object->mode, object->state, object->workdir, object->dvodb, object->registered);13703 }13704 13705 bool warpRunInsertObjects(psDB *dbh, psArray *objects)13706 {13707 for (long i = 0; i < psArrayLength(objects); i++) {13708 if (!warpRunInsertObject(dbh, objects->data[i])) {13709 return false;13710 }13711 }13712 13713 return true;13714 }13715 13716 bool warpRunInsertFits(psDB *dbh, const psFits *fits)13717 {13718 psArray *rowSet;13719 13720 // move to (the first?) extension named WARPRUN_TABLE_NAME13721 if (!psFitsMoveExtName(fits, WARPRUN_TABLE_NAME)) {13722 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", WARPRUN_TABLE_NAME);13723 return false;13724 }13725 13726 // check HDU type13727 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) {13728 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");13729 return false;13730 }13731 13732 // read fits table13733 rowSet = psFitsReadTable(fits);13734 if (!rowSet) {13735 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");13736 psFree(rowSet);13737 return false;13738 }13739 13740 if (!psDBInsertRows(dbh, WARPRUN_TABLE_NAME, rowSet)) {13741 psError(PS_ERR_UNKNOWN, false, "databse insert failed");13742 psFree(rowSet);13743 return false;13744 }13745 13746 psFree(rowSet);13747 13748 return true;13749 }13750 13751 bool warpRunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)13752 {13753 psArray *rowSet;13754 13755 rowSet = psDBSelectRows(dbh, WARPRUN_TABLE_NAME, where, limit);13756 if (!rowSet) {13757 return false;13758 }13759 13760 // output to fits13761 if (!psFitsWriteTable(fits, NULL, rowSet, WARPRUN_TABLE_NAME)) {13762 psError(PS_ERR_UNKNOWN, false, "FITS table write failed");13763 psFree(rowSet);13764 return false;13765 }13766 13767 psFree(rowSet);13768 13769 return true;13770 }13771 13772 psMetadata *warpRunMetadataFromObject(const warpRunRow *object)13773 {13774 psMetadata *md = psMetadataAlloc();13775 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, object->warp_id)) {13776 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");13777 psFree(md);13778 return false;13779 }13780 if (!psMetadataAdd(md, PS_LIST_TAIL, "mode", PS_DATA_STRING, NULL, object->mode)) {13781 psError(PS_ERR_UNKNOWN, false, "failed to add item mode");13782 psFree(md);13783 return false;13784 }13785 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) {13786 psError(PS_ERR_UNKNOWN, false, "failed to add item state");13787 psFree(md);13788 return false;13789 }13790 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, object->workdir)) {13791 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir");13792 psFree(md);13793 return false;13794 }13795 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, object->dvodb)) {13796 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb");13797 psFree(md);13798 return false;13799 }13800 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, object->registered)) {13801 psError(PS_ERR_UNKNOWN, false, "failed to add item registered");13802 psFree(md);13803 return false;13804 }13805 13806 13807 return md;13808 }13809 13810 warpRunRow *warpRunObjectFromMetadata(psMetadata *md)13811 {13812 13813 bool status = false;13814 psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id");13815 if (!status) {13816 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item warp_id");13817 return false;13818 }13819 char* mode = psMetadataLookupPtr(&status, md, "mode");13820 if (!status) {13821 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item mode");13822 return false;13823 }13824 char* state = psMetadataLookupPtr(&status, md, "state");13825 if (!status) {13826 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state");13827 return false;13828 }13829 char* workdir = psMetadataLookupPtr(&status, md, "workdir");13830 if (!status) {13831 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item workdir");13832 return false;13833 }13834 char* dvodb = psMetadataLookupPtr(&status, md, "dvodb");13835 if (!status) {13836 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item dvodb");13837 return false;13838 }13839 psTime* registered = psMetadataLookupPtr(&status, md, "registered");13840 if (!status) {13841 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item registered");13842 return false;13843 }13844 13845 return warpRunRowAlloc(warp_id, mode, state, workdir, dvodb, registered);13846 }13847 psArray *warpRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)13848 {13849 psArray *rowSet;13850 psArray *returnSet;13851 psU64 i;13852 13853 rowSet = psDBSelectRows(dbh, WARPRUN_TABLE_NAME, where, limit);13854 if (!rowSet) {13855 return NULL;13856 }13857 13858 // convert psMetadata rows to row objects13859 13860 returnSet = psArrayAllocEmpty(rowSet->n);13861 13862 for (i = 0; i < rowSet->n; i++) {13863 warpRunRow *object = warpRunObjectFromMetadata(rowSet->data[i]);13864 psArrayAdd(returnSet, 0, object);13865 psFree(object);13866 }13867 13868 psFree(rowSet);13869 13870 return returnSet;13871 }13872 bool warpRunDeleteObject(psDB *dbh, const warpRunRow *object)13873 {13874 psMetadata *where = warpRunMetadataFromObject(object);13875 long long count = psDBDeleteRows(dbh, WARPRUN_TABLE_NAME, where, 0);13876 psFree(where);13877 if (count < 0) {13878 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpRun");13879 return false;13880 }13881 if (count > 1) {13882 // XXX should this be a psAbort() instead? It is possible that13883 // having an object match multiple rows was by design.13884 psError(PS_ERR_UNKNOWN, true, "warpRunRow object matched more then one row. Check your database schema");13885 return false;13886 }13887 13888 return true;13889 }13890 long long warpRunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)13891 {13892 long long deleted = 0;13893 13894 for (long long i = 0; i < objects->n; i++) {13895 warpRunRow *object = objects->data[i];13896 psMetadata *where = warpRunMetadataFromObject(object);13897 long long count = psDBDeleteRows(dbh, WARPRUN_TABLE_NAME, where, limit);13898 psFree(where);13899 if (count < 0) {13900 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpRun");13901 return count;13902 }13903 13904 deleted += count;13905 }13906 13907 return deleted;13908 }13909 bool warpRunPrintObjects(FILE *stream, psArray *objects, bool mdcf)13910 {13911 PS_ASSERT_PTR_NON_NULL(objects, false);13912 13913 psMetadata *output = psMetadataAlloc();13914 for (long i = 0; i < psArrayLength(objects); i++) {13915 psMetadata *md = warpRunMetadataFromObject(objects->data[i]);13916 if (!psMetadataAddMetadata(13917 output,13918 PS_LIST_TAIL,13919 WARPRUN_TABLE_NAME,13920 PS_META_DUPLICATE_OK,13921 NULL,13922 md13923 )) {13924 psError(PS_ERR_UNKNOWN, false, "failed to add metadata");13925 psFree(md);13926 psFree(output);13927 return false;13928 }13929 psFree(md);13930 }13931 13932 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {13933 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");13934 psFree(output);13935 }13936 psFree(output);13937 13938 return true;13939 }13940 bool warpRunPrintObject(FILE *stream, warpRunRow *object, bool mdcf)13941 {13942 PS_ASSERT_PTR_NON_NULL(object, false);13943 13944 psMetadata *md = warpRunMetadataFromObject(object);13945 13946 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {13947 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");13948 psFree(md);13949 }13950 13951 psFree(md);13952 13953 return true;13954 }13955 static void warpInputExpRowFree(warpInputExpRow *object);13956 13957 warpInputExpRow *warpInputExpRowAlloc(psS64 warp_id, psS64 cam_id, bool magiced)13958 {13959 warpInputExpRow *_object;13960 13961 _object = psAlloc(sizeof(warpInputExpRow));13962 psMemSetDeallocator(_object, (psFreeFunc)warpInputExpRowFree);13963 13964 _object->warp_id = warp_id;13965 _object->cam_id = cam_id;13966 _object->magiced = magiced;13967 13968 return _object;13969 }13970 13971 static void warpInputExpRowFree(warpInputExpRow *object)13972 {13973 }13974 13975 bool warpInputExpCreateTable(psDB *dbh)13976 {13977 psMetadata *md = psMetadataAlloc();13978 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key", 0)) {13979 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");13980 psFree(md);13981 return false;13982 }13983 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, "Primary Key", 0)) {13984 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");13985 psFree(md);13986 return false;13987 }13988 if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, "Key", 0)) {13989 psError(PS_ERR_UNKNOWN, false, "failed to add item magiced");13990 psFree(md);13991 return false;13992 }13993 13994 bool status = psDBCreateTable(dbh, WARPINPUTEXP_TABLE_NAME, md);13995 13996 psFree(md);13997 13998 return status;13999 }14000 14001 bool warpInputExpDropTable(psDB *dbh)14002 {14003 return psDBDropTable(dbh, WARPINPUTEXP_TABLE_NAME);14004 }14005 14006 bool warpInputExpInsert(psDB * dbh, psS64 warp_id, psS64 cam_id, bool magiced)14007 {14008 psMetadata *md = psMetadataAlloc();14009 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, warp_id)) {14010 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");14011 psFree(md);14012 return false;14013 }14014 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, NULL, cam_id)) {14015 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");14016 psFree(md);14017 return false;14018 }14019 if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, NULL, magiced)) {14020 psError(PS_ERR_UNKNOWN, false, "failed to add item magiced");14021 psFree(md);14022 return false;14023 }14024 14025 bool status = psDBInsertOneRow(dbh, WARPINPUTEXP_TABLE_NAME, md);14026 psFree(md);14027 14028 return status;14029 }14030 14031 long long warpInputExpDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)14032 {14033 long long deleted = 0;14034 14035 long long count = psDBDeleteRows(dbh, WARPINPUTEXP_TABLE_NAME, where, limit);14036 if (count < 0) {14037 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpInputExp");14038 return count;14039 14040 deleted += count;14041 }14042 14043 return deleted;14044 }14045 bool warpInputExpInsertObject(psDB *dbh, warpInputExpRow *object)14046 {14047 return warpInputExpInsert(dbh, object->warp_id, object->cam_id, object->magiced);14048 }14049 14050 bool warpInputExpInsertObjects(psDB *dbh, psArray *objects)14051 {14052 for (long i = 0; i < psArrayLength(objects); i++) {14053 if (!warpInputExpInsertObject(dbh, objects->data[i])) {14054 return false;14055 }14056 }14057 14058 return true;14059 }14060 14061 bool warpInputExpInsertFits(psDB *dbh, const psFits *fits)14062 {14063 psArray *rowSet;14064 14065 // move to (the first?) extension named WARPINPUTEXP_TABLE_NAME14066 if (!psFitsMoveExtName(fits, WARPINPUTEXP_TABLE_NAME)) {14067 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", WARPINPUTEXP_TABLE_NAME);14068 return false;14069 }14070 14071 // check HDU type14072 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) {14073 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");14074 return false;14075 }14076 14077 // read fits table14078 rowSet = psFitsReadTable(fits);14079 if (!rowSet) {14080 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");14081 psFree(rowSet);14082 return false;14083 }14084 14085 if (!psDBInsertRows(dbh, WARPINPUTEXP_TABLE_NAME, rowSet)) {14086 psError(PS_ERR_UNKNOWN, false, "databse insert failed");14087 psFree(rowSet);14088 return false;14089 }14090 14091 psFree(rowSet);14092 14093 return true;14094 }14095 14096 bool warpInputExpSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)14097 {14098 psArray *rowSet;14099 14100 rowSet = psDBSelectRows(dbh, WARPINPUTEXP_TABLE_NAME, where, limit);14101 if (!rowSet) {14102 return false;14103 }14104 14105 // output to fits14106 if (!psFitsWriteTable(fits, NULL, rowSet, WARPINPUTEXP_TABLE_NAME)) {14107 psError(PS_ERR_UNKNOWN, false, "FITS table write failed");14108 psFree(rowSet);14109 return false;14110 }14111 14112 psFree(rowSet);14113 14114 return true;14115 }14116 14117 psMetadata *warpInputExpMetadataFromObject(const warpInputExpRow *object)14118 {14119 psMetadata *md = psMetadataAlloc();14120 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, object->warp_id)) {14121 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");14122 psFree(md);14123 return false;14124 }14125 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, NULL, object->cam_id)) {14126 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");14127 psFree(md);14128 return false;14129 }14130 if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, NULL, object->magiced)) {14131 psError(PS_ERR_UNKNOWN, false, "failed to add item magiced");14132 psFree(md);14133 return false;14134 }14135 14136 14137 return md;14138 }14139 14140 warpInputExpRow *warpInputExpObjectFromMetadata(psMetadata *md)14141 {14142 14143 bool status = false;14144 psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id");14145 if (!status) {14146 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item warp_id");14147 return false;14148 }14149 psS64 cam_id = psMetadataLookupS64(&status, md, "cam_id");14150 if (!status) {14151 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item cam_id");14152 return false;14153 }14154 bool magiced = psMetadataLookupBool(&status, md, "magiced");14155 if (!status) {14156 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item magiced");14157 return false;14158 }14159 14160 return warpInputExpRowAlloc(warp_id, cam_id, magiced);14161 }14162 psArray *warpInputExpSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)14163 {14164 psArray *rowSet;14165 psArray *returnSet;14166 psU64 i;14167 14168 rowSet = psDBSelectRows(dbh, WARPINPUTEXP_TABLE_NAME, where, limit);14169 if (!rowSet) {14170 return NULL;14171 }14172 14173 // convert psMetadata rows to row objects14174 14175 returnSet = psArrayAllocEmpty(rowSet->n);14176 14177 for (i = 0; i < rowSet->n; i++) {14178 warpInputExpRow *object = warpInputExpObjectFromMetadata(rowSet->data[i]);14179 psArrayAdd(returnSet, 0, object);14180 psFree(object);14181 }14182 14183 psFree(rowSet);14184 14185 return returnSet;14186 }14187 bool warpInputExpDeleteObject(psDB *dbh, const warpInputExpRow *object)14188 {14189 psMetadata *where = warpInputExpMetadataFromObject(object);14190 long long count = psDBDeleteRows(dbh, WARPINPUTEXP_TABLE_NAME, where, 0);14191 psFree(where);14192 if (count < 0) {14193 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpInputExp");14194 return false;14195 }14196 if (count > 1) {14197 // XXX should this be a psAbort() instead? It is possible that14198 // having an object match multiple rows was by design.14199 psError(PS_ERR_UNKNOWN, true, "warpInputExpRow object matched more then one row. Check your database schema");14200 return false;14201 }14202 14203 return true;14204 }14205 long long warpInputExpDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)14206 {14207 long long deleted = 0;14208 14209 for (long long i = 0; i < objects->n; i++) {14210 warpInputExpRow *object = objects->data[i];14211 psMetadata *where = warpInputExpMetadataFromObject(object);14212 long long count = psDBDeleteRows(dbh, WARPINPUTEXP_TABLE_NAME, where, limit);14213 psFree(where);14214 if (count < 0) {14215 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpInputExp");14216 return count;14217 }14218 14219 deleted += count;14220 }14221 14222 return deleted;14223 }14224 bool warpInputExpPrintObjects(FILE *stream, psArray *objects, bool mdcf)14225 {14226 PS_ASSERT_PTR_NON_NULL(objects, false);14227 14228 psMetadata *output = psMetadataAlloc();14229 for (long i = 0; i < psArrayLength(objects); i++) {14230 psMetadata *md = warpInputExpMetadataFromObject(objects->data[i]);14231 if (!psMetadataAddMetadata(14232 output,14233 PS_LIST_TAIL,14234 WARPINPUTEXP_TABLE_NAME,14235 PS_META_DUPLICATE_OK,14236 NULL,14237 md14238 )) {14239 psError(PS_ERR_UNKNOWN, false, "failed to add metadata");14240 psFree(md);14241 psFree(output);14242 return false;14243 }14244 psFree(md);14245 }14246 14247 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {14248 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");14249 psFree(output);14250 }14251 psFree(output);14252 14253 return true;14254 }14255 bool warpInputExpPrintObject(FILE *stream, warpInputExpRow *object, bool mdcf)14256 {14257 PS_ASSERT_PTR_NON_NULL(object, false);14258 14259 psMetadata *md = warpInputExpMetadataFromObject(object);14260 14261 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {14262 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");14263 psFree(md);14264 }14265 14266 psFree(md);14267 14268 return true;14269 }14270 static void warpSkyCellMapRowFree(warpSkyCellMapRow *object);14271 14272 warpSkyCellMapRow *warpSkyCellMapRowAlloc(psS64 warp_id, const char *skycell_id, const char *tess_id, psS64 cam_id, const char *class_id, psS16 fault)14273 {14274 warpSkyCellMapRow *_object;14275 14276 _object = psAlloc(sizeof(warpSkyCellMapRow));14277 psMemSetDeallocator(_object, (psFreeFunc)warpSkyCellMapRowFree);14278 14279 _object->warp_id = warp_id;14280 _object->skycell_id = psStringCopy(skycell_id);14281 _object->tess_id = psStringCopy(tess_id);14282 _object->cam_id = cam_id;14283 _object->class_id = psStringCopy(class_id);14284 _object->fault = fault;14285 14286 return _object;14287 }14288 14289 static void warpSkyCellMapRowFree(warpSkyCellMapRow *object)14290 {14291 psFree(object->skycell_id);14292 psFree(object->tess_id);14293 psFree(object->class_id);14294 }14295 14296 bool warpSkyCellMapCreateTable(psDB *dbh)14297 {14298 psMetadata *md = psMetadataAlloc();14299 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key", 0)) {14300 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");14301 psFree(md);14302 return false;14303 }14304 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {14305 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");14306 psFree(md);14307 return false;14308 }14309 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {14310 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");14311 psFree(md);14312 return false;14313 }14314 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, "Primary Key", 0)) {14315 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");14316 psFree(md);14317 return false;14318 }14319 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) {14320 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");14321 psFree(md);14322 return false;14323 }14324 if (!psMetadataAdd(md, PS_LIST_TAIL, "fault", PS_DATA_S16, "Key", 0)) {14325 psError(PS_ERR_UNKNOWN, false, "failed to add item fault");14326 psFree(md);14327 return false;14328 }14329 14330 bool status = psDBCreateTable(dbh, WARPSKYCELLMAP_TABLE_NAME, md);14331 14332 psFree(md);14333 14334 return status;14335 }14336 14337 bool warpSkyCellMapDropTable(psDB *dbh)14338 {14339 return psDBDropTable(dbh, WARPSKYCELLMAP_TABLE_NAME);14340 }14341 14342 bool warpSkyCellMapInsert(psDB * dbh, psS64 warp_id, const char *skycell_id, const char *tess_id, psS64 cam_id, const char *class_id, psS16 fault)14343 {14344 psMetadata *md = psMetadataAlloc();14345 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, warp_id)) {14346 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");14347 psFree(md);14348 return false;14349 }14350 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {14351 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");14352 psFree(md);14353 return false;14354 }14355 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {14356 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");14357 psFree(md);14358 return false;14359 }14360 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, NULL, cam_id)) {14361 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");14362 psFree(md);14363 return false;14364 }14365 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) {14366 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");14367 psFree(md);14368 return false;14369 }14370 if (!psMetadataAdd(md, PS_LIST_TAIL, "fault", PS_DATA_S16, NULL, fault)) {14371 psError(PS_ERR_UNKNOWN, false, "failed to add item fault");14372 psFree(md);14373 return false;14374 }14375 14376 bool status = psDBInsertOneRow(dbh, WARPSKYCELLMAP_TABLE_NAME, md);14377 psFree(md);14378 14379 return status;14380 }14381 14382 long long warpSkyCellMapDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)14383 {14384 long long deleted = 0;14385 14386 long long count = psDBDeleteRows(dbh, WARPSKYCELLMAP_TABLE_NAME, where, limit);14387 if (count < 0) {14388 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpSkyCellMap");14389 return count;14390 14391 deleted += count;14392 }14393 14394 return deleted;14395 }14396 bool warpSkyCellMapInsertObject(psDB *dbh, warpSkyCellMapRow *object)14397 {14398 return warpSkyCellMapInsert(dbh, object->warp_id, object->skycell_id, object->tess_id, object->cam_id, object->class_id, object->fault);14399 }14400 14401 bool warpSkyCellMapInsertObjects(psDB *dbh, psArray *objects)14402 {14403 for (long i = 0; i < psArrayLength(objects); i++) {14404 if (!warpSkyCellMapInsertObject(dbh, objects->data[i])) {14405 return false;14406 }14407 }14408 14409 return true;14410 }14411 14412 bool warpSkyCellMapInsertFits(psDB *dbh, const psFits *fits)14413 {14414 psArray *rowSet;14415 14416 // move to (the first?) extension named WARPSKYCELLMAP_TABLE_NAME14417 if (!psFitsMoveExtName(fits, WARPSKYCELLMAP_TABLE_NAME)) {14418 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", WARPSKYCELLMAP_TABLE_NAME);14419 return false;14420 }14421 14422 // check HDU type14423 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) {14424 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");14425 return false;14426 }14427 14428 // read fits table14429 rowSet = psFitsReadTable(fits);14430 if (!rowSet) {14431 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");14432 psFree(rowSet);14433 return false;14434 }14435 14436 if (!psDBInsertRows(dbh, WARPSKYCELLMAP_TABLE_NAME, rowSet)) {14437 psError(PS_ERR_UNKNOWN, false, "databse insert failed");14438 psFree(rowSet);14439 return false;14440 }14441 14442 psFree(rowSet);14443 14444 return true;14445 }14446 14447 bool warpSkyCellMapSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)14448 {14449 psArray *rowSet;14450 14451 rowSet = psDBSelectRows(dbh, WARPSKYCELLMAP_TABLE_NAME, where, limit);14452 if (!rowSet) {14453 return false;14454 }14455 14456 // output to fits14457 if (!psFitsWriteTable(fits, NULL, rowSet, WARPSKYCELLMAP_TABLE_NAME)) {14458 psError(PS_ERR_UNKNOWN, false, "FITS table write failed");14459 psFree(rowSet);14460 return false;14461 }14462 14463 psFree(rowSet);14464 14465 return true;14466 }14467 14468 psMetadata *warpSkyCellMapMetadataFromObject(const warpSkyCellMapRow *object)14469 {14470 psMetadata *md = psMetadataAlloc();14471 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, object->warp_id)) {14472 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");14473 psFree(md);14474 return false;14475 }14476 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {14477 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");14478 psFree(md);14479 return false;14480 }14481 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {14482 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");14483 psFree(md);14484 return false;14485 }14486 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, NULL, object->cam_id)) {14487 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");14488 psFree(md);14489 return false;14490 }14491 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) {14492 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");14493 psFree(md);14494 return false;14495 }14496 if (!psMetadataAdd(md, PS_LIST_TAIL, "fault", PS_DATA_S16, NULL, object->fault)) {14497 psError(PS_ERR_UNKNOWN, false, "failed to add item fault");14498 psFree(md);14499 return false;14500 }14501 14502 14503 return md;14504 }14505 14506 warpSkyCellMapRow *warpSkyCellMapObjectFromMetadata(psMetadata *md)14507 {14508 14509 bool status = false;14510 psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id");14511 if (!status) {14512 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item warp_id");14513 return false;14514 }14515 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");14516 if (!status) {14517 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");14518 return false;14519 }14520 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");14521 if (!status) {14522 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");14523 return false;14524 }14525 psS64 cam_id = psMetadataLookupS64(&status, md, "cam_id");14526 if (!status) {14527 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item cam_id");14528 return false;14529 }14530 char* class_id = psMetadataLookupPtr(&status, md, "class_id");14531 if (!status) {14532 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id");14533 return false;14534 }14535 psS16 fault = psMetadataLookupS16(&status, md, "fault");14536 if (!status) {14537 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item fault");14538 return false;14539 }14540 14541 return warpSkyCellMapRowAlloc(warp_id, skycell_id, tess_id, cam_id, class_id, fault);14542 }14543 psArray *warpSkyCellMapSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)14544 {14545 psArray *rowSet;14546 psArray *returnSet;14547 psU64 i;14548 14549 rowSet = psDBSelectRows(dbh, WARPSKYCELLMAP_TABLE_NAME, where, limit);14550 if (!rowSet) {14551 return NULL;14552 }14553 14554 // convert psMetadata rows to row objects14555 14556 returnSet = psArrayAllocEmpty(rowSet->n);14557 14558 for (i = 0; i < rowSet->n; i++) {14559 warpSkyCellMapRow *object = warpSkyCellMapObjectFromMetadata(rowSet->data[i]);14560 psArrayAdd(returnSet, 0, object);14561 psFree(object);14562 }14563 14564 psFree(rowSet);14565 14566 return returnSet;14567 }14568 bool warpSkyCellMapDeleteObject(psDB *dbh, const warpSkyCellMapRow *object)14569 {14570 psMetadata *where = warpSkyCellMapMetadataFromObject(object);14571 long long count = psDBDeleteRows(dbh, WARPSKYCELLMAP_TABLE_NAME, where, 0);14572 psFree(where);14573 if (count < 0) {14574 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpSkyCellMap");14575 return false;14576 }14577 if (count > 1) {14578 // XXX should this be a psAbort() instead? It is possible that14579 // having an object match multiple rows was by design.14580 psError(PS_ERR_UNKNOWN, true, "warpSkyCellMapRow object matched more then one row. Check your database schema");14581 return false;14582 }14583 14584 return true;14585 }14586 long long warpSkyCellMapDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)14587 {14588 long long deleted = 0;14589 14590 for (long long i = 0; i < objects->n; i++) {14591 warpSkyCellMapRow *object = objects->data[i];14592 psMetadata *where = warpSkyCellMapMetadataFromObject(object);14593 long long count = psDBDeleteRows(dbh, WARPSKYCELLMAP_TABLE_NAME, where, limit);14594 psFree(where);14595 if (count < 0) {14596 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpSkyCellMap");14597 return count;14598 }14599 14600 deleted += count;14601 }14602 14603 return deleted;14604 }14605 bool warpSkyCellMapPrintObjects(FILE *stream, psArray *objects, bool mdcf)14606 {14607 PS_ASSERT_PTR_NON_NULL(objects, false);14608 14609 psMetadata *output = psMetadataAlloc();14610 for (long i = 0; i < psArrayLength(objects); i++) {14611 psMetadata *md = warpSkyCellMapMetadataFromObject(objects->data[i]);14612 if (!psMetadataAddMetadata(14613 output,14614 PS_LIST_TAIL,14615 WARPSKYCELLMAP_TABLE_NAME,14616 PS_META_DUPLICATE_OK,14617 NULL,14618 md14619 )) {14620 psError(PS_ERR_UNKNOWN, false, "failed to add metadata");14621 psFree(md);14622 psFree(output);14623 return false;14624 }14625 psFree(md);14626 }14627 14628 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {14629 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");14630 psFree(output);14631 }14632 psFree(output);14633 14634 return true;14635 }14636 bool warpSkyCellMapPrintObject(FILE *stream, warpSkyCellMapRow *object, bool mdcf)14637 {14638 PS_ASSERT_PTR_NON_NULL(object, false);14639 14640 psMetadata *md = warpSkyCellMapMetadataFromObject(object);14641 14642 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {14643 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");14644 psFree(md);14645 }14646 14647 psFree(md);14648 14649 return true;14650 }14651 static void warpSkyfileRowFree(warpSkyfileRow *object);14652 14653 warpSkyfileRow *warpSkyfileRowAlloc(psS64 warp_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_stdev)14654 {14655 warpSkyfileRow *_object;14656 14657 _object = psAlloc(sizeof(warpSkyfileRow));14658 psMemSetDeallocator(_object, (psFreeFunc)warpSkyfileRowFree);14659 14660 _object->warp_id = warp_id;14661 _object->skycell_id = psStringCopy(skycell_id);14662 _object->tess_id = psStringCopy(tess_id);14663 _object->uri = psStringCopy(uri);14664 _object->bg = bg;14665 _object->bg_stdev = bg_stdev;14666 14667 return _object;14668 }14669 14670 static void warpSkyfileRowFree(warpSkyfileRow *object)14671 {14672 psFree(object->skycell_id);14673 psFree(object->tess_id);14674 psFree(object->uri);14675 }14676 14677 bool warpSkyfileCreateTable(psDB *dbh)14678 {14679 psMetadata *md = psMetadataAlloc();14680 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key", 0)) {14681 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");14682 psFree(md);14683 return false;14684 }14685 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {14686 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");14687 psFree(md);14688 return false;14689 }14690 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {14691 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");14692 psFree(md);14693 return false;14694 }14695 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) {14696 psError(PS_ERR_UNKNOWN, false, "failed to add item uri");14697 psFree(md);14698 return false;14699 }14700 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, 0.0)) {14701 psError(PS_ERR_UNKNOWN, false, "failed to add item bg");14702 psFree(md);14703 return false;14704 }14705 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, 0.0)) {14706 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev");14707 psFree(md);14708 return false;14709 }14710 14711 bool status = psDBCreateTable(dbh, WARPSKYFILE_TABLE_NAME, md);14712 14713 psFree(md);14714 14715 return status;14716 }14717 14718 bool warpSkyfileDropTable(psDB *dbh)14719 {14720 return psDBDropTable(dbh, WARPSKYFILE_TABLE_NAME);14721 }14722 14723 bool warpSkyfileInsert(psDB * dbh, psS64 warp_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_stdev)14724 {14725 psMetadata *md = psMetadataAlloc();14726 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, warp_id)) {14727 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");14728 psFree(md);14729 return false;14730 }14731 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {14732 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");14733 psFree(md);14734 return false;14735 }14736 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {14737 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");14738 psFree(md);14739 return false;14740 }14741 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) {14742 psError(PS_ERR_UNKNOWN, false, "failed to add item uri");14743 psFree(md);14744 return false;14745 }14746 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, bg)) {14747 psError(PS_ERR_UNKNOWN, false, "failed to add item bg");14748 psFree(md);14749 return false;14750 }14751 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, bg_stdev)) {14752 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev");14753 psFree(md);14754 return false;14755 }14756 14757 bool status = psDBInsertOneRow(dbh, WARPSKYFILE_TABLE_NAME, md);14758 psFree(md);14759 14760 return status;14761 }14762 14763 long long warpSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)14764 {14765 long long deleted = 0;14766 14767 long long count = psDBDeleteRows(dbh, WARPSKYFILE_TABLE_NAME, where, limit);14768 if (count < 0) {14769 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpSkyfile");14770 return count;14771 14772 deleted += count;14773 }14774 14775 return deleted;14776 }14777 bool warpSkyfileInsertObject(psDB *dbh, warpSkyfileRow *object)14778 {14779 return warpSkyfileInsert(dbh, object->warp_id, object->skycell_id, object->tess_id, object->uri, object->bg, object->bg_stdev);14780 }14781 14782 bool warpSkyfileInsertObjects(psDB *dbh, psArray *objects)14783 {14784 for (long i = 0; i < psArrayLength(objects); i++) {14785 if (!warpSkyfileInsertObject(dbh, objects->data[i])) {14786 return false;14787 }14788 }14789 14790 return true;14791 }14792 14793 bool warpSkyfileInsertFits(psDB *dbh, const psFits *fits)14794 {14795 psArray *rowSet;14796 14797 // move to (the first?) extension named WARPSKYFILE_TABLE_NAME14798 if (!psFitsMoveExtName(fits, WARPSKYFILE_TABLE_NAME)) {14799 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", WARPSKYFILE_TABLE_NAME);14800 return false;14801 }14802 14803 // check HDU type14804 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) {14805 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");14806 return false;14807 }14808 14809 // read fits table14810 rowSet = psFitsReadTable(fits);14811 if (!rowSet) {14812 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");14813 psFree(rowSet);14814 return false;14815 }14816 14817 if (!psDBInsertRows(dbh, WARPSKYFILE_TABLE_NAME, rowSet)) {14818 psError(PS_ERR_UNKNOWN, false, "databse insert failed");14819 psFree(rowSet);14820 return false;14821 }14822 14823 psFree(rowSet);14824 14825 return true;14826 }14827 14828 bool warpSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)14829 {14830 psArray *rowSet;14831 14832 rowSet = psDBSelectRows(dbh, WARPSKYFILE_TABLE_NAME, where, limit);14833 if (!rowSet) {14834 return false;14835 }14836 14837 // output to fits14838 if (!psFitsWriteTable(fits, NULL, rowSet, WARPSKYFILE_TABLE_NAME)) {14839 psError(PS_ERR_UNKNOWN, false, "FITS table write failed");14840 psFree(rowSet);14841 return false;14842 }14843 14844 psFree(rowSet);14845 14846 return true;14847 }14848 14849 psMetadata *warpSkyfileMetadataFromObject(const warpSkyfileRow *object)14850 {14851 psMetadata *md = psMetadataAlloc();14852 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, object->warp_id)) {14853 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");14854 psFree(md);14855 return false;14856 }14857 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {14858 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");14859 psFree(md);14860 return false;14861 }14862 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {14863 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");14864 psFree(md);14865 return false;14866 }14867 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) {14868 psError(PS_ERR_UNKNOWN, false, "failed to add item uri");14869 psFree(md);14870 return false;14871 }14872 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, object->bg)) {14873 psError(PS_ERR_UNKNOWN, false, "failed to add item bg");14874 psFree(md);14875 return false;14876 }14877 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, object->bg_stdev)) {14878 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev");14879 psFree(md);14880 return false;14881 }14882 14883 14884 return md;14885 }14886 14887 warpSkyfileRow *warpSkyfileObjectFromMetadata(psMetadata *md)14888 {14889 14890 bool status = false;14891 psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id");14892 if (!status) {14893 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item warp_id");14894 return false;14895 }14896 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");14897 if (!status) {14898 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");14899 return false;14900 }14901 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");14902 if (!status) {14903 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");14904 return false;14905 }14906 char* uri = psMetadataLookupPtr(&status, md, "uri");14907 if (!status) {14908 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri");14909 return false;14910 }14911 psF64 bg = psMetadataLookupF64(&status, md, "bg");14912 if (!status) {14913 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg");14914 return false;14915 }14916 psF64 bg_stdev = psMetadataLookupF64(&status, md, "bg_stdev");14917 if (!status) {14918 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_stdev");14919 return false;14920 }14921 14922 return warpSkyfileRowAlloc(warp_id, skycell_id, tess_id, uri, bg, bg_stdev);14923 }14924 psArray *warpSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)14925 {14926 psArray *rowSet;14927 psArray *returnSet;14928 psU64 i;14929 14930 rowSet = psDBSelectRows(dbh, WARPSKYFILE_TABLE_NAME, where, limit);14931 if (!rowSet) {14932 return NULL;14933 }14934 14935 // convert psMetadata rows to row objects14936 14937 returnSet = psArrayAllocEmpty(rowSet->n);14938 14939 for (i = 0; i < rowSet->n; i++) {14940 warpSkyfileRow *object = warpSkyfileObjectFromMetadata(rowSet->data[i]);14941 psArrayAdd(returnSet, 0, object);14942 psFree(object);14943 }14944 14945 psFree(rowSet);14946 14947 return returnSet;14948 }14949 bool warpSkyfileDeleteObject(psDB *dbh, const warpSkyfileRow *object)14950 {14951 psMetadata *where = warpSkyfileMetadataFromObject(object);14952 long long count = psDBDeleteRows(dbh, WARPSKYFILE_TABLE_NAME, where, 0);14953 psFree(where);14954 if (count < 0) {14955 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpSkyfile");14956 return false;14957 }14958 if (count > 1) {14959 // XXX should this be a psAbort() instead? It is possible that14960 // having an object match multiple rows was by design.14961 psError(PS_ERR_UNKNOWN, true, "warpSkyfileRow object matched more then one row. Check your database schema");14962 return false;14963 }14964 14965 return true;14966 }14967 long long warpSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)14968 {14969 long long deleted = 0;14970 14971 for (long long i = 0; i < objects->n; i++) {14972 warpSkyfileRow *object = objects->data[i];14973 psMetadata *where = warpSkyfileMetadataFromObject(object);14974 long long count = psDBDeleteRows(dbh, WARPSKYFILE_TABLE_NAME, where, limit);14975 psFree(where);14976 if (count < 0) {14977 psError(PS_ERR_UNKNOWN, true, "failed to delete row from warpSkyfile");14978 return count;14979 }14980 14981 deleted += count;14982 }14983 14984 return deleted;14985 }14986 bool warpSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)14987 {14988 PS_ASSERT_PTR_NON_NULL(objects, false);14989 14990 psMetadata *output = psMetadataAlloc();14991 for (long i = 0; i < psArrayLength(objects); i++) {14992 psMetadata *md = warpSkyfileMetadataFromObject(objects->data[i]);14993 if (!psMetadataAddMetadata(14994 output,14995 PS_LIST_TAIL,14996 WARPSKYFILE_TABLE_NAME,14997 PS_META_DUPLICATE_OK,14998 NULL,14999 md15000 )) {15001 psError(PS_ERR_UNKNOWN, false, "failed to add metadata");15002 psFree(md);15003 psFree(output);15004 return false;15005 }15006 psFree(md);15007 }15008 15009 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {15010 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");15011 psFree(output);15012 }15013 psFree(output);15014 15015 return true;15016 }15017 bool warpSkyfilePrintObject(FILE *stream, warpSkyfileRow *object, bool mdcf)15018 {15019 PS_ASSERT_PTR_NON_NULL(object, false);15020 15021 psMetadata *md = warpSkyfileMetadataFromObject(object);15022 15023 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {15024 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");15025 psFree(md);15026 }15027 15028 psFree(md);15029 15030 return true;15031 }15032 static void diffRunRowFree(diffRunRow *object);15033 15034 diffRunRow *diffRunRowAlloc(psS64 diff_id, const char *state, const char *workdir, const char *dvodb, psTime* registered, const char *skycell_id, const char *tess_id)15035 {15036 diffRunRow *_object;15037 15038 _object = psAlloc(sizeof(diffRunRow));15039 psMemSetDeallocator(_object, (psFreeFunc)diffRunRowFree);15040 15041 _object->diff_id = diff_id;15042 _object->state = psStringCopy(state);15043 _object->workdir = psStringCopy(workdir);15044 _object->dvodb = psStringCopy(dvodb);15045 _object->registered = psTimeCopy(registered);15046 _object->skycell_id = psStringCopy(skycell_id);15047 _object->tess_id = psStringCopy(tess_id);15048 15049 return _object;15050 }15051 15052 static void diffRunRowFree(diffRunRow *object)15053 {15054 psFree(object->state);15055 psFree(object->workdir);15056 psFree(object->dvodb);15057 psFree(object->registered);15058 psFree(object->skycell_id);15059 psFree(object->tess_id);15060 }15061 15062 bool diffRunCreateTable(psDB *dbh)15063 {15064 psMetadata *md = psMetadataAlloc();15065 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, "Primary Key AUTO_INCREMENT", 0)) {15066 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id");15067 psFree(md);15068 return false;15069 }15070 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "Key", "64")) {15071 psError(PS_ERR_UNKNOWN, false, "failed to add item state");15072 psFree(md);15073 return false;15074 }15075 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, "255")) {15076 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir");15077 psFree(md);15078 return false;15079 }15080 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, "255")) {15081 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb");15082 psFree(md);15083 return false;15084 }15085 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, NULL)) {15086 psError(PS_ERR_UNKNOWN, false, "failed to add item registered");15087 psFree(md);15088 return false;15089 }15090 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Key", "64")) {15091 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");15092 psFree(md);15093 return false;15094 }15095 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Key", "64")) {15096 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");15097 psFree(md);15098 return false;15099 }15100 15101 bool status = psDBCreateTable(dbh, DIFFRUN_TABLE_NAME, md);15102 15103 psFree(md);15104 15105 return status;15106 }15107 15108 bool diffRunDropTable(psDB *dbh)15109 {15110 return psDBDropTable(dbh, DIFFRUN_TABLE_NAME);15111 }15112 15113 bool diffRunInsert(psDB * dbh, psS64 diff_id, const char *state, const char *workdir, const char *dvodb, psTime* registered, const char *skycell_id, const char *tess_id)15114 {15115 psMetadata *md = psMetadataAlloc();15116 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, NULL, diff_id)) {15117 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id");15118 psFree(md);15119 return false;15120 }15121 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) {15122 psError(PS_ERR_UNKNOWN, false, "failed to add item state");15123 psFree(md);15124 return false;15125 }15126 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, workdir)) {15127 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir");15128 psFree(md);15129 return false;15130 }15131 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, dvodb)) {15132 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb");15133 psFree(md);15134 return false;15135 }15136 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, registered)) {15137 psError(PS_ERR_UNKNOWN, false, "failed to add item registered");15138 psFree(md);15139 return false;15140 }15141 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {15142 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");15143 psFree(md);15144 return false;15145 }15146 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {15147 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");15148 psFree(md);15149 return false;15150 }15151 15152 bool status = psDBInsertOneRow(dbh, DIFFRUN_TABLE_NAME, md);15153 psFree(md);15154 15155 return status;15156 }15157 15158 long long diffRunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)15159 {15160 long long deleted = 0;15161 15162 long long count = psDBDeleteRows(dbh, DIFFRUN_TABLE_NAME, where, limit);15163 if (count < 0) {15164 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffRun");15165 return count;15166 15167 deleted += count;15168 }15169 15170 return deleted;15171 }15172 bool diffRunInsertObject(psDB *dbh, diffRunRow *object)15173 {15174 return diffRunInsert(dbh, object->diff_id, object->state, object->workdir, object->dvodb, object->registered, object->skycell_id, object->tess_id);15175 }15176 15177 bool diffRunInsertObjects(psDB *dbh, psArray *objects)15178 {15179 for (long i = 0; i < psArrayLength(objects); i++) {15180 if (!diffRunInsertObject(dbh, objects->data[i])) {15181 return false;15182 }15183 }15184 15185 return true;15186 }15187 15188 bool diffRunInsertFits(psDB *dbh, const psFits *fits)15189 {15190 psArray *rowSet;15191 15192 // move to (the first?) extension named DIFFRUN_TABLE_NAME15193 if (!psFitsMoveExtName(fits, DIFFRUN_TABLE_NAME)) {15194 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", DIFFRUN_TABLE_NAME);15195 return false;15196 }15197 15198 // check HDU type15199 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) {15200 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");15201 return false;15202 }15203 15204 // read fits table15205 rowSet = psFitsReadTable(fits);15206 if (!rowSet) {15207 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");15208 psFree(rowSet);15209 return false;15210 }15211 15212 if (!psDBInsertRows(dbh, DIFFRUN_TABLE_NAME, rowSet)) {15213 psError(PS_ERR_UNKNOWN, false, "databse insert failed");15214 psFree(rowSet);15215 return false;15216 }15217 15218 psFree(rowSet);15219 15220 return true;15221 }15222 15223 bool diffRunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)15224 {15225 psArray *rowSet;15226 15227 rowSet = psDBSelectRows(dbh, DIFFRUN_TABLE_NAME, where, limit);15228 if (!rowSet) {15229 return false;15230 }15231 15232 // output to fits15233 if (!psFitsWriteTable(fits, NULL, rowSet, DIFFRUN_TABLE_NAME)) {15234 psError(PS_ERR_UNKNOWN, false, "FITS table write failed");15235 psFree(rowSet);15236 return false;15237 }15238 15239 psFree(rowSet);15240 15241 return true;15242 }15243 15244 psMetadata *diffRunMetadataFromObject(const diffRunRow *object)15245 {15246 psMetadata *md = psMetadataAlloc();15247 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, NULL, object->diff_id)) {15248 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id");15249 psFree(md);15250 return false;15251 }15252 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) {15253 psError(PS_ERR_UNKNOWN, false, "failed to add item state");15254 psFree(md);15255 return false;15256 }15257 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, object->workdir)) {15258 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir");15259 psFree(md);15260 return false;15261 }15262 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, object->dvodb)) {15263 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb");15264 psFree(md);15265 return false;15266 }15267 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, object->registered)) {15268 psError(PS_ERR_UNKNOWN, false, "failed to add item registered");15269 psFree(md);15270 return false;15271 }15272 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {15273 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");15274 psFree(md);15275 return false;15276 }15277 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {15278 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");15279 psFree(md);15280 return false;15281 }15282 15283 15284 return md;15285 }15286 15287 diffRunRow *diffRunObjectFromMetadata(psMetadata *md)15288 {15289 15290 bool status = false;15291 psS64 diff_id = psMetadataLookupS64(&status, md, "diff_id");15292 if (!status) {15293 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item diff_id");15294 return false;15295 }15296 char* state = psMetadataLookupPtr(&status, md, "state");15297 if (!status) {15298 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state");15299 return false;15300 }15301 char* workdir = psMetadataLookupPtr(&status, md, "workdir");15302 if (!status) {15303 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item workdir");15304 return false;15305 }15306 char* dvodb = psMetadataLookupPtr(&status, md, "dvodb");15307 if (!status) {15308 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item dvodb");15309 return false;15310 }15311 psTime* registered = psMetadataLookupPtr(&status, md, "registered");15312 if (!status) {15313 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item registered");15314 return false;15315 }15316 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");15317 if (!status) {15318 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");15319 return false;15320 }15321 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");15322 if (!status) {15323 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");15324 return false;15325 }15326 15327 return diffRunRowAlloc(diff_id, state, workdir, dvodb, registered, skycell_id, tess_id);15328 }15329 psArray *diffRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)15330 {15331 psArray *rowSet;15332 psArray *returnSet;15333 psU64 i;15334 15335 rowSet = psDBSelectRows(dbh, DIFFRUN_TABLE_NAME, where, limit);15336 if (!rowSet) {15337 return NULL;15338 }15339 15340 // convert psMetadata rows to row objects15341 15342 returnSet = psArrayAllocEmpty(rowSet->n);15343 15344 for (i = 0; i < rowSet->n; i++) {15345 diffRunRow *object = diffRunObjectFromMetadata(rowSet->data[i]);15346 psArrayAdd(returnSet, 0, object);15347 psFree(object);15348 }15349 15350 psFree(rowSet);15351 15352 return returnSet;15353 }15354 bool diffRunDeleteObject(psDB *dbh, const diffRunRow *object)15355 {15356 psMetadata *where = diffRunMetadataFromObject(object);15357 long long count = psDBDeleteRows(dbh, DIFFRUN_TABLE_NAME, where, 0);15358 psFree(where);15359 if (count < 0) {15360 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffRun");15361 return false;15362 }15363 if (count > 1) {15364 // XXX should this be a psAbort() instead? It is possible that15365 // having an object match multiple rows was by design.15366 psError(PS_ERR_UNKNOWN, true, "diffRunRow object matched more then one row. Check your database schema");15367 return false;15368 }15369 15370 return true;15371 }15372 long long diffRunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)15373 {15374 long long deleted = 0;15375 15376 for (long long i = 0; i < objects->n; i++) {15377 diffRunRow *object = objects->data[i];15378 psMetadata *where = diffRunMetadataFromObject(object);15379 long long count = psDBDeleteRows(dbh, DIFFRUN_TABLE_NAME, where, limit);15380 psFree(where);15381 if (count < 0) {15382 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffRun");15383 return count;15384 }15385 15386 deleted += count;15387 }15388 15389 return deleted;15390 }15391 bool diffRunPrintObjects(FILE *stream, psArray *objects, bool mdcf)15392 {15393 PS_ASSERT_PTR_NON_NULL(objects, false);15394 15395 psMetadata *output = psMetadataAlloc();15396 for (long i = 0; i < psArrayLength(objects); i++) {15397 psMetadata *md = diffRunMetadataFromObject(objects->data[i]);15398 if (!psMetadataAddMetadata(15399 output,15400 PS_LIST_TAIL,15401 DIFFRUN_TABLE_NAME,15402 PS_META_DUPLICATE_OK,15403 NULL,15404 md15405 )) {15406 psError(PS_ERR_UNKNOWN, false, "failed to add metadata");15407 psFree(md);15408 psFree(output);15409 return false;15410 }15411 psFree(md);15412 }15413 15414 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {15415 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");15416 psFree(output);15417 }15418 psFree(output);15419 15420 return true;15421 }15422 bool diffRunPrintObject(FILE *stream, diffRunRow *object, bool mdcf)15423 {15424 PS_ASSERT_PTR_NON_NULL(object, false);15425 15426 psMetadata *md = diffRunMetadataFromObject(object);15427 15428 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {15429 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");15430 psFree(md);15431 }15432 15433 psFree(md);15434 15435 return true;15436 }15437 static void diffInputSkyfileRowFree(diffInputSkyfileRow *object);15438 15439 diffInputSkyfileRow *diffInputSkyfileRowAlloc(psS64 diff_id, psS64 warp_id, const char *skycell_id, const char *tess_id, const char *kind, bool template)15440 {15441 diffInputSkyfileRow *_object;15442 15443 _object = psAlloc(sizeof(diffInputSkyfileRow));15444 psMemSetDeallocator(_object, (psFreeFunc)diffInputSkyfileRowFree);15445 15446 _object->diff_id = diff_id;15447 _object->warp_id = warp_id;15448 _object->skycell_id = psStringCopy(skycell_id);15449 _object->tess_id = psStringCopy(tess_id);15450 _object->kind = psStringCopy(kind);15451 _object->template = template;15452 15453 return _object;15454 }15455 15456 static void diffInputSkyfileRowFree(diffInputSkyfileRow *object)15457 {15458 psFree(object->skycell_id);15459 psFree(object->tess_id);15460 psFree(object->kind);15461 }15462 15463 bool diffInputSkyfileCreateTable(psDB *dbh)15464 {15465 psMetadata *md = psMetadataAlloc();15466 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, "Primary Key", 0)) {15467 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id");15468 psFree(md);15469 return false;15470 }15471 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key", 0)) {15472 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");15473 psFree(md);15474 return false;15475 }15476 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {15477 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");15478 psFree(md);15479 return false;15480 }15481 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {15482 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");15483 psFree(md);15484 return false;15485 }15486 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, "Key", "64")) {15487 psError(PS_ERR_UNKNOWN, false, "failed to add item kind");15488 psFree(md);15489 return false;15490 }15491 if (!psMetadataAdd(md, PS_LIST_TAIL, "template", PS_DATA_BOOL, NULL, 0)) {15492 psError(PS_ERR_UNKNOWN, false, "failed to add item template");15493 psFree(md);15494 return false;15495 }15496 15497 bool status = psDBCreateTable(dbh, DIFFINPUTSKYFILE_TABLE_NAME, md);15498 15499 psFree(md);15500 15501 return status;15502 }15503 15504 bool diffInputSkyfileDropTable(psDB *dbh)15505 {15506 return psDBDropTable(dbh, DIFFINPUTSKYFILE_TABLE_NAME);15507 }15508 15509 bool diffInputSkyfileInsert(psDB * dbh, psS64 diff_id, psS64 warp_id, const char *skycell_id, const char *tess_id, const char *kind, bool template)15510 {15511 psMetadata *md = psMetadataAlloc();15512 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, NULL, diff_id)) {15513 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id");15514 psFree(md);15515 return false;15516 }15517 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, warp_id)) {15518 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");15519 psFree(md);15520 return false;15521 }15522 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {15523 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");15524 psFree(md);15525 return false;15526 }15527 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {15528 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");15529 psFree(md);15530 return false;15531 }15532 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, kind)) {15533 psError(PS_ERR_UNKNOWN, false, "failed to add item kind");15534 psFree(md);15535 return false;15536 }15537 if (!psMetadataAdd(md, PS_LIST_TAIL, "template", PS_DATA_BOOL, NULL, template)) {15538 psError(PS_ERR_UNKNOWN, false, "failed to add item template");15539 psFree(md);15540 return false;15541 }15542 15543 bool status = psDBInsertOneRow(dbh, DIFFINPUTSKYFILE_TABLE_NAME, md);15544 psFree(md);15545 15546 return status;15547 }15548 15549 long long diffInputSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)15550 {15551 long long deleted = 0;15552 15553 long long count = psDBDeleteRows(dbh, DIFFINPUTSKYFILE_TABLE_NAME, where, limit);15554 if (count < 0) {15555 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffInputSkyfile");15556 return count;15557 15558 deleted += count;15559 }15560 15561 return deleted;15562 }15563 bool diffInputSkyfileInsertObject(psDB *dbh, diffInputSkyfileRow *object)15564 {15565 return diffInputSkyfileInsert(dbh, object->diff_id, object->warp_id, object->skycell_id, object->tess_id, object->kind, object->template);15566 }15567 15568 bool diffInputSkyfileInsertObjects(psDB *dbh, psArray *objects)15569 {15570 for (long i = 0; i < psArrayLength(objects); i++) {15571 if (!diffInputSkyfileInsertObject(dbh, objects->data[i])) {15572 return false;15573 }15574 }15575 15576 return true;15577 }15578 15579 bool diffInputSkyfileInsertFits(psDB *dbh, const psFits *fits)15580 {15581 psArray *rowSet;15582 15583 // move to (the first?) extension named DIFFINPUTSKYFILE_TABLE_NAME15584 if (!psFitsMoveExtName(fits, DIFFINPUTSKYFILE_TABLE_NAME)) {15585 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", DIFFINPUTSKYFILE_TABLE_NAME);15586 return false;15587 }15588 15589 // check HDU type15590 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) {15591 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");15592 return false;15593 }15594 15595 // read fits table15596 rowSet = psFitsReadTable(fits);15597 if (!rowSet) {15598 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");15599 psFree(rowSet);15600 return false;15601 }15602 15603 if (!psDBInsertRows(dbh, DIFFINPUTSKYFILE_TABLE_NAME, rowSet)) {15604 psError(PS_ERR_UNKNOWN, false, "databse insert failed");15605 psFree(rowSet);15606 return false;15607 }15608 15609 psFree(rowSet);15610 15611 return true;15612 }15613 15614 bool diffInputSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)15615 {15616 psArray *rowSet;15617 15618 rowSet = psDBSelectRows(dbh, DIFFINPUTSKYFILE_TABLE_NAME, where, limit);15619 if (!rowSet) {15620 return false;15621 }15622 15623 // output to fits15624 if (!psFitsWriteTable(fits, NULL, rowSet, DIFFINPUTSKYFILE_TABLE_NAME)) {15625 psError(PS_ERR_UNKNOWN, false, "FITS table write failed");15626 psFree(rowSet);15627 return false;15628 }15629 15630 psFree(rowSet);15631 15632 return true;15633 }15634 15635 psMetadata *diffInputSkyfileMetadataFromObject(const diffInputSkyfileRow *object)15636 {15637 psMetadata *md = psMetadataAlloc();15638 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, NULL, object->diff_id)) {15639 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id");15640 psFree(md);15641 return false;15642 }15643 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, object->warp_id)) {15644 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");15645 psFree(md);15646 return false;15647 }15648 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {15649 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");15650 psFree(md);15651 return false;15652 }15653 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {15654 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");15655 psFree(md);15656 return false;15657 }15658 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, object->kind)) {15659 psError(PS_ERR_UNKNOWN, false, "failed to add item kind");15660 psFree(md);15661 return false;15662 }15663 if (!psMetadataAdd(md, PS_LIST_TAIL, "template", PS_DATA_BOOL, NULL, object->template)) {15664 psError(PS_ERR_UNKNOWN, false, "failed to add item template");15665 psFree(md);15666 return false;15667 }15668 15669 15670 return md;15671 }15672 15673 diffInputSkyfileRow *diffInputSkyfileObjectFromMetadata(psMetadata *md)15674 {15675 15676 bool status = false;15677 psS64 diff_id = psMetadataLookupS64(&status, md, "diff_id");15678 if (!status) {15679 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item diff_id");15680 return false;15681 }15682 psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id");15683 if (!status) {15684 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item warp_id");15685 return false;15686 }15687 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");15688 if (!status) {15689 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");15690 return false;15691 }15692 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");15693 if (!status) {15694 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");15695 return false;15696 }15697 char* kind = psMetadataLookupPtr(&status, md, "kind");15698 if (!status) {15699 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item kind");15700 return false;15701 }15702 bool template = psMetadataLookupBool(&status, md, "template");15703 if (!status) {15704 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item template");15705 return false;15706 }15707 15708 return diffInputSkyfileRowAlloc(diff_id, warp_id, skycell_id, tess_id, kind, template);15709 }15710 psArray *diffInputSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)15711 {15712 psArray *rowSet;15713 psArray *returnSet;15714 psU64 i;15715 15716 rowSet = psDBSelectRows(dbh, DIFFINPUTSKYFILE_TABLE_NAME, where, limit);15717 if (!rowSet) {15718 return NULL;15719 }15720 15721 // convert psMetadata rows to row objects15722 15723 returnSet = psArrayAllocEmpty(rowSet->n);15724 15725 for (i = 0; i < rowSet->n; i++) {15726 diffInputSkyfileRow *object = diffInputSkyfileObjectFromMetadata(rowSet->data[i]);15727 psArrayAdd(returnSet, 0, object);15728 psFree(object);15729 }15730 15731 psFree(rowSet);15732 15733 return returnSet;15734 }15735 bool diffInputSkyfileDeleteObject(psDB *dbh, const diffInputSkyfileRow *object)15736 {15737 psMetadata *where = diffInputSkyfileMetadataFromObject(object);15738 long long count = psDBDeleteRows(dbh, DIFFINPUTSKYFILE_TABLE_NAME, where, 0);15739 psFree(where);15740 if (count < 0) {15741 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffInputSkyfile");15742 return false;15743 }15744 if (count > 1) {15745 // XXX should this be a psAbort() instead? It is possible that15746 // having an object match multiple rows was by design.15747 psError(PS_ERR_UNKNOWN, true, "diffInputSkyfileRow object matched more then one row. Check your database schema");15748 return false;15749 }15750 15751 return true;15752 }15753 long long diffInputSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)15754 {15755 long long deleted = 0;15756 15757 for (long long i = 0; i < objects->n; i++) {15758 diffInputSkyfileRow *object = objects->data[i];15759 psMetadata *where = diffInputSkyfileMetadataFromObject(object);15760 long long count = psDBDeleteRows(dbh, DIFFINPUTSKYFILE_TABLE_NAME, where, limit);15761 psFree(where);15762 if (count < 0) {15763 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffInputSkyfile");15764 return count;15765 }15766 15767 deleted += count;15768 }15769 15770 return deleted;15771 }15772 bool diffInputSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)15773 {15774 PS_ASSERT_PTR_NON_NULL(objects, false);15775 15776 psMetadata *output = psMetadataAlloc();15777 for (long i = 0; i < psArrayLength(objects); i++) {15778 psMetadata *md = diffInputSkyfileMetadataFromObject(objects->data[i]);15779 if (!psMetadataAddMetadata(15780 output,15781 PS_LIST_TAIL,15782 DIFFINPUTSKYFILE_TABLE_NAME,15783 PS_META_DUPLICATE_OK,15784 NULL,15785 md15786 )) {15787 psError(PS_ERR_UNKNOWN, false, "failed to add metadata");15788 psFree(md);15789 psFree(output);15790 return false;15791 }15792 psFree(md);15793 }15794 15795 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {15796 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");15797 psFree(output);15798 }15799 psFree(output);15800 15801 return true;15802 }15803 bool diffInputSkyfilePrintObject(FILE *stream, diffInputSkyfileRow *object, bool mdcf)15804 {15805 PS_ASSERT_PTR_NON_NULL(object, false);15806 15807 psMetadata *md = diffInputSkyfileMetadataFromObject(object);15808 15809 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {15810 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");15811 psFree(md);15812 }15813 15814 psFree(md);15815 15816 return true;15817 }15818 static void diffSkyfileRowFree(diffSkyfileRow *object);15819 15820 diffSkyfileRow *diffSkyfileRowAlloc(psS64 diff_id, const char *uri, psF64 bg, psF64 bg_stdev)15821 {15822 diffSkyfileRow *_object;15823 15824 _object = psAlloc(sizeof(diffSkyfileRow));15825 psMemSetDeallocator(_object, (psFreeFunc)diffSkyfileRowFree);15826 15827 _object->diff_id = diff_id;15828 _object->uri = psStringCopy(uri);15829 _object->bg = bg;15830 _object->bg_stdev = bg_stdev;15831 15832 return _object;15833 }15834 15835 static void diffSkyfileRowFree(diffSkyfileRow *object)15836 {15837 psFree(object->uri);15838 }15839 15840 bool diffSkyfileCreateTable(psDB *dbh)15841 {15842 psMetadata *md = psMetadataAlloc();15843 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, "Primary Key", 0)) {15844 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id");15845 psFree(md);15846 return false;15847 }15848 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) {15849 psError(PS_ERR_UNKNOWN, false, "failed to add item uri");15850 psFree(md);15851 return false;15852 }15853 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, 0.0)) {15854 psError(PS_ERR_UNKNOWN, false, "failed to add item bg");15855 psFree(md);15856 return false;15857 }15858 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, 0.0)) {15859 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev");15860 psFree(md);15861 return false;15862 }15863 15864 bool status = psDBCreateTable(dbh, DIFFSKYFILE_TABLE_NAME, md);15865 15866 psFree(md);15867 15868 return status;15869 }15870 15871 bool diffSkyfileDropTable(psDB *dbh)15872 {15873 return psDBDropTable(dbh, DIFFSKYFILE_TABLE_NAME);15874 }15875 15876 bool diffSkyfileInsert(psDB * dbh, psS64 diff_id, const char *uri, psF64 bg, psF64 bg_stdev)15877 {15878 psMetadata *md = psMetadataAlloc();15879 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, NULL, diff_id)) {15880 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id");15881 psFree(md);15882 return false;15883 }15884 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) {15885 psError(PS_ERR_UNKNOWN, false, "failed to add item uri");15886 psFree(md);15887 return false;15888 }15889 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, bg)) {15890 psError(PS_ERR_UNKNOWN, false, "failed to add item bg");15891 psFree(md);15892 return false;15893 }15894 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, bg_stdev)) {15895 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev");15896 psFree(md);15897 return false;15898 }15899 15900 bool status = psDBInsertOneRow(dbh, DIFFSKYFILE_TABLE_NAME, md);15901 psFree(md);15902 15903 return status;15904 }15905 15906 long long diffSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)15907 {15908 long long deleted = 0;15909 15910 long long count = psDBDeleteRows(dbh, DIFFSKYFILE_TABLE_NAME, where, limit);15911 if (count < 0) {15912 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffSkyfile");15913 return count;15914 15915 deleted += count;15916 }15917 15918 return deleted;15919 }15920 bool diffSkyfileInsertObject(psDB *dbh, diffSkyfileRow *object)15921 {15922 return diffSkyfileInsert(dbh, object->diff_id, object->uri, object->bg, object->bg_stdev);15923 }15924 15925 bool diffSkyfileInsertObjects(psDB *dbh, psArray *objects)15926 {15927 for (long i = 0; i < psArrayLength(objects); i++) {15928 if (!diffSkyfileInsertObject(dbh, objects->data[i])) {15929 return false;15930 }15931 }15932 15933 return true;15934 }15935 15936 bool diffSkyfileInsertFits(psDB *dbh, const psFits *fits)15937 {15938 psArray *rowSet;15939 15940 // move to (the first?) extension named DIFFSKYFILE_TABLE_NAME15941 if (!psFitsMoveExtName(fits, DIFFSKYFILE_TABLE_NAME)) {15942 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", DIFFSKYFILE_TABLE_NAME);15943 return false;15944 }15945 15946 // check HDU type15947 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) {15948 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");15949 return false;15950 }15951 15952 // read fits table15953 rowSet = psFitsReadTable(fits);15954 if (!rowSet) {15955 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");15956 psFree(rowSet);15957 return false;15958 }15959 15960 if (!psDBInsertRows(dbh, DIFFSKYFILE_TABLE_NAME, rowSet)) {15961 psError(PS_ERR_UNKNOWN, false, "databse insert failed");15962 psFree(rowSet);15963 return false;15964 }15965 15966 psFree(rowSet);15967 15968 return true;15969 }15970 15971 bool diffSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)15972 {15973 psArray *rowSet;15974 15975 rowSet = psDBSelectRows(dbh, DIFFSKYFILE_TABLE_NAME, where, limit);15976 if (!rowSet) {15977 return false;15978 }15979 15980 // output to fits15981 if (!psFitsWriteTable(fits, NULL, rowSet, DIFFSKYFILE_TABLE_NAME)) {15982 psError(PS_ERR_UNKNOWN, false, "FITS table write failed");15983 psFree(rowSet);15984 return false;15985 }15986 15987 psFree(rowSet);15988 15989 return true;15990 }15991 15992 psMetadata *diffSkyfileMetadataFromObject(const diffSkyfileRow *object)15993 {15994 psMetadata *md = psMetadataAlloc();15995 if (!psMetadataAdd(md, PS_LIST_TAIL, "diff_id", PS_DATA_S64, NULL, object->diff_id)) {15996 psError(PS_ERR_UNKNOWN, false, "failed to add item diff_id");15997 psFree(md);15998 return false;15999 }16000 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) {16001 psError(PS_ERR_UNKNOWN, false, "failed to add item uri");16002 psFree(md);16003 return false;16004 }16005 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, object->bg)) {16006 psError(PS_ERR_UNKNOWN, false, "failed to add item bg");16007 psFree(md);16008 return false;16009 }16010 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, object->bg_stdev)) {16011 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev");16012 psFree(md);16013 return false;16014 }16015 16016 16017 return md;16018 }16019 16020 diffSkyfileRow *diffSkyfileObjectFromMetadata(psMetadata *md)16021 {16022 16023 bool status = false;16024 psS64 diff_id = psMetadataLookupS64(&status, md, "diff_id");16025 if (!status) {16026 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item diff_id");16027 return false;16028 }16029 char* uri = psMetadataLookupPtr(&status, md, "uri");16030 if (!status) {16031 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri");16032 return false;16033 }16034 psF64 bg = psMetadataLookupF64(&status, md, "bg");16035 if (!status) {16036 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg");16037 return false;16038 }16039 psF64 bg_stdev = psMetadataLookupF64(&status, md, "bg_stdev");16040 if (!status) {16041 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_stdev");16042 return false;16043 }16044 16045 return diffSkyfileRowAlloc(diff_id, uri, bg, bg_stdev);16046 }16047 psArray *diffSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)16048 {16049 psArray *rowSet;16050 psArray *returnSet;16051 psU64 i;16052 16053 rowSet = psDBSelectRows(dbh, DIFFSKYFILE_TABLE_NAME, where, limit);16054 if (!rowSet) {16055 return NULL;16056 }16057 16058 // convert psMetadata rows to row objects16059 16060 returnSet = psArrayAllocEmpty(rowSet->n);16061 16062 for (i = 0; i < rowSet->n; i++) {16063 diffSkyfileRow *object = diffSkyfileObjectFromMetadata(rowSet->data[i]);16064 psArrayAdd(returnSet, 0, object);16065 psFree(object);16066 }16067 16068 psFree(rowSet);16069 16070 return returnSet;16071 }16072 bool diffSkyfileDeleteObject(psDB *dbh, const diffSkyfileRow *object)16073 {16074 psMetadata *where = diffSkyfileMetadataFromObject(object);16075 long long count = psDBDeleteRows(dbh, DIFFSKYFILE_TABLE_NAME, where, 0);16076 psFree(where);16077 if (count < 0) {16078 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffSkyfile");16079 return false;16080 }16081 if (count > 1) {16082 // XXX should this be a psAbort() instead? It is possible that16083 // having an object match multiple rows was by design.16084 psError(PS_ERR_UNKNOWN, true, "diffSkyfileRow object matched more then one row. Check your database schema");16085 return false;16086 }16087 16088 return true;16089 }16090 long long diffSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)16091 {16092 long long deleted = 0;16093 16094 for (long long i = 0; i < objects->n; i++) {16095 diffSkyfileRow *object = objects->data[i];16096 psMetadata *where = diffSkyfileMetadataFromObject(object);16097 long long count = psDBDeleteRows(dbh, DIFFSKYFILE_TABLE_NAME, where, limit);16098 psFree(where);16099 if (count < 0) {16100 psError(PS_ERR_UNKNOWN, true, "failed to delete row from diffSkyfile");16101 return count;16102 }16103 16104 deleted += count;16105 }16106 16107 return deleted;16108 }16109 bool diffSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)16110 {16111 PS_ASSERT_PTR_NON_NULL(objects, false);16112 16113 psMetadata *output = psMetadataAlloc();16114 for (long i = 0; i < psArrayLength(objects); i++) {16115 psMetadata *md = diffSkyfileMetadataFromObject(objects->data[i]);16116 if (!psMetadataAddMetadata(16117 output,16118 PS_LIST_TAIL,16119 DIFFSKYFILE_TABLE_NAME,16120 PS_META_DUPLICATE_OK,16121 NULL,16122 md16123 )) {16124 psError(PS_ERR_UNKNOWN, false, "failed to add metadata");16125 psFree(md);16126 psFree(output);16127 return false;16128 }16129 psFree(md);16130 }16131 16132 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {16133 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");16134 psFree(output);16135 }16136 psFree(output);16137 16138 return true;16139 }16140 bool diffSkyfilePrintObject(FILE *stream, diffSkyfileRow *object, bool mdcf)16141 {16142 PS_ASSERT_PTR_NON_NULL(object, false);16143 16144 psMetadata *md = diffSkyfileMetadataFromObject(object);16145 16146 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {16147 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");16148 psFree(md);16149 }16150 16151 psFree(md);16152 16153 return true;16154 }16155 static void stackRunRowFree(stackRunRow *object);16156 16157 stackRunRow *stackRunRowAlloc(psS64 stack_id, const char *state, const char *workdir, const char *dvodb, psTime* registered, const char *skycell_id, const char *tess_id)16158 {16159 stackRunRow *_object;16160 16161 _object = psAlloc(sizeof(stackRunRow));16162 psMemSetDeallocator(_object, (psFreeFunc)stackRunRowFree);16163 16164 _object->stack_id = stack_id;16165 _object->state = psStringCopy(state);16166 _object->workdir = psStringCopy(workdir);16167 _object->dvodb = psStringCopy(dvodb);16168 _object->registered = psTimeCopy(registered);16169 _object->skycell_id = psStringCopy(skycell_id);16170 _object->tess_id = psStringCopy(tess_id);16171 16172 return _object;16173 }16174 16175 static void stackRunRowFree(stackRunRow *object)16176 {16177 psFree(object->state);16178 psFree(object->workdir);16179 psFree(object->dvodb);16180 psFree(object->registered);16181 psFree(object->skycell_id);16182 psFree(object->tess_id);16183 }16184 16185 bool stackRunCreateTable(psDB *dbh)16186 {16187 psMetadata *md = psMetadataAlloc();16188 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, "Primary Key AUTO_INCREMENT", 0)) {16189 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id");16190 psFree(md);16191 return false;16192 }16193 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "Key", "64")) {16194 psError(PS_ERR_UNKNOWN, false, "failed to add item state");16195 psFree(md);16196 return false;16197 }16198 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, "255")) {16199 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir");16200 psFree(md);16201 return false;16202 }16203 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, "255")) {16204 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb");16205 psFree(md);16206 return false;16207 }16208 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, NULL)) {16209 psError(PS_ERR_UNKNOWN, false, "failed to add item registered");16210 psFree(md);16211 return false;16212 }16213 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Key", "64")) {16214 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");16215 psFree(md);16216 return false;16217 }16218 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Key", "64")) {16219 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");16220 psFree(md);16221 return false;16222 }16223 16224 bool status = psDBCreateTable(dbh, STACKRUN_TABLE_NAME, md);16225 16226 psFree(md);16227 16228 return status;16229 }16230 16231 bool stackRunDropTable(psDB *dbh)16232 {16233 return psDBDropTable(dbh, STACKRUN_TABLE_NAME);16234 }16235 16236 bool stackRunInsert(psDB * dbh, psS64 stack_id, const char *state, const char *workdir, const char *dvodb, psTime* registered, const char *skycell_id, const char *tess_id)16237 {16238 psMetadata *md = psMetadataAlloc();16239 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, NULL, stack_id)) {16240 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id");16241 psFree(md);16242 return false;16243 }16244 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) {16245 psError(PS_ERR_UNKNOWN, false, "failed to add item state");16246 psFree(md);16247 return false;16248 }16249 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, workdir)) {16250 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir");16251 psFree(md);16252 return false;16253 }16254 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, dvodb)) {16255 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb");16256 psFree(md);16257 return false;16258 }16259 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, registered)) {16260 psError(PS_ERR_UNKNOWN, false, "failed to add item registered");16261 psFree(md);16262 return false;16263 }16264 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {16265 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");16266 psFree(md);16267 return false;16268 }16269 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {16270 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");16271 psFree(md);16272 return false;16273 }16274 16275 bool status = psDBInsertOneRow(dbh, STACKRUN_TABLE_NAME, md);16276 psFree(md);16277 16278 return status;16279 }16280 16281 long long stackRunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)16282 {16283 long long deleted = 0;16284 16285 long long count = psDBDeleteRows(dbh, STACKRUN_TABLE_NAME, where, limit);16286 if (count < 0) {16287 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackRun");16288 return count;16289 16290 deleted += count;16291 }16292 16293 return deleted;16294 }16295 bool stackRunInsertObject(psDB *dbh, stackRunRow *object)16296 {16297 return stackRunInsert(dbh, object->stack_id, object->state, object->workdir, object->dvodb, object->registered, object->skycell_id, object->tess_id);16298 }16299 16300 bool stackRunInsertObjects(psDB *dbh, psArray *objects)16301 {16302 for (long i = 0; i < psArrayLength(objects); i++) {16303 if (!stackRunInsertObject(dbh, objects->data[i])) {16304 return false;16305 }16306 }16307 16308 return true;16309 }16310 16311 bool stackRunInsertFits(psDB *dbh, const psFits *fits)16312 {16313 psArray *rowSet;16314 16315 // move to (the first?) extension named STACKRUN_TABLE_NAME16316 if (!psFitsMoveExtName(fits, STACKRUN_TABLE_NAME)) {16317 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", STACKRUN_TABLE_NAME);16318 return false;16319 }16320 16321 // check HDU type16322 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) {16323 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");16324 return false;16325 }16326 16327 // read fits table16328 rowSet = psFitsReadTable(fits);16329 if (!rowSet) {16330 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");16331 psFree(rowSet);16332 return false;16333 }16334 16335 if (!psDBInsertRows(dbh, STACKRUN_TABLE_NAME, rowSet)) {16336 psError(PS_ERR_UNKNOWN, false, "databse insert failed");16337 psFree(rowSet);16338 return false;16339 }16340 16341 psFree(rowSet);16342 16343 return true;16344 }16345 16346 bool stackRunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)16347 {16348 psArray *rowSet;16349 16350 rowSet = psDBSelectRows(dbh, STACKRUN_TABLE_NAME, where, limit);16351 if (!rowSet) {16352 return false;16353 }16354 16355 // output to fits16356 if (!psFitsWriteTable(fits, NULL, rowSet, STACKRUN_TABLE_NAME)) {16357 psError(PS_ERR_UNKNOWN, false, "FITS table write failed");16358 psFree(rowSet);16359 return false;16360 }16361 16362 psFree(rowSet);16363 16364 return true;16365 }16366 16367 psMetadata *stackRunMetadataFromObject(const stackRunRow *object)16368 {16369 psMetadata *md = psMetadataAlloc();16370 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, NULL, object->stack_id)) {16371 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id");16372 psFree(md);16373 return false;16374 }16375 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) {16376 psError(PS_ERR_UNKNOWN, false, "failed to add item state");16377 psFree(md);16378 return false;16379 }16380 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, object->workdir)) {16381 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir");16382 psFree(md);16383 return false;16384 }16385 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, object->dvodb)) {16386 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb");16387 psFree(md);16388 return false;16389 }16390 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, object->registered)) {16391 psError(PS_ERR_UNKNOWN, false, "failed to add item registered");16392 psFree(md);16393 return false;16394 }16395 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {16396 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");16397 psFree(md);16398 return false;16399 }16400 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {16401 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");16402 psFree(md);16403 return false;16404 }16405 16406 16407 return md;16408 }16409 16410 stackRunRow *stackRunObjectFromMetadata(psMetadata *md)16411 {16412 16413 bool status = false;16414 psS64 stack_id = psMetadataLookupS64(&status, md, "stack_id");16415 if (!status) {16416 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item stack_id");16417 return false;16418 }16419 char* state = psMetadataLookupPtr(&status, md, "state");16420 if (!status) {16421 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state");16422 return false;16423 }16424 char* workdir = psMetadataLookupPtr(&status, md, "workdir");16425 if (!status) {16426 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item workdir");16427 return false;16428 }16429 char* dvodb = psMetadataLookupPtr(&status, md, "dvodb");16430 if (!status) {16431 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item dvodb");16432 return false;16433 }16434 psTime* registered = psMetadataLookupPtr(&status, md, "registered");16435 if (!status) {16436 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item registered");16437 return false;16438 }16439 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");16440 if (!status) {16441 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");16442 return false;16443 }16444 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");16445 if (!status) {16446 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");16447 return false;16448 }16449 16450 return stackRunRowAlloc(stack_id, state, workdir, dvodb, registered, skycell_id, tess_id);16451 }16452 psArray *stackRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)16453 {16454 psArray *rowSet;16455 psArray *returnSet;16456 psU64 i;16457 16458 rowSet = psDBSelectRows(dbh, STACKRUN_TABLE_NAME, where, limit);16459 if (!rowSet) {16460 return NULL;16461 }16462 16463 // convert psMetadata rows to row objects16464 16465 returnSet = psArrayAllocEmpty(rowSet->n);16466 16467 for (i = 0; i < rowSet->n; i++) {16468 stackRunRow *object = stackRunObjectFromMetadata(rowSet->data[i]);16469 psArrayAdd(returnSet, 0, object);16470 psFree(object);16471 }16472 16473 psFree(rowSet);16474 16475 return returnSet;16476 }16477 bool stackRunDeleteObject(psDB *dbh, const stackRunRow *object)16478 {16479 psMetadata *where = stackRunMetadataFromObject(object);16480 long long count = psDBDeleteRows(dbh, STACKRUN_TABLE_NAME, where, 0);16481 psFree(where);16482 if (count < 0) {16483 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackRun");16484 return false;16485 }16486 if (count > 1) {16487 // XXX should this be a psAbort() instead? It is possible that16488 // having an object match multiple rows was by design.16489 psError(PS_ERR_UNKNOWN, true, "stackRunRow object matched more then one row. Check your database schema");16490 return false;16491 }16492 16493 return true;16494 }16495 long long stackRunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)16496 {16497 long long deleted = 0;16498 16499 for (long long i = 0; i < objects->n; i++) {16500 stackRunRow *object = objects->data[i];16501 psMetadata *where = stackRunMetadataFromObject(object);16502 long long count = psDBDeleteRows(dbh, STACKRUN_TABLE_NAME, where, limit);16503 psFree(where);16504 if (count < 0) {16505 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackRun");16506 return count;16507 }16508 16509 deleted += count;16510 }16511 16512 return deleted;16513 }16514 bool stackRunPrintObjects(FILE *stream, psArray *objects, bool mdcf)16515 {16516 PS_ASSERT_PTR_NON_NULL(objects, false);16517 16518 psMetadata *output = psMetadataAlloc();16519 for (long i = 0; i < psArrayLength(objects); i++) {16520 psMetadata *md = stackRunMetadataFromObject(objects->data[i]);16521 if (!psMetadataAddMetadata(16522 output,16523 PS_LIST_TAIL,16524 STACKRUN_TABLE_NAME,16525 PS_META_DUPLICATE_OK,16526 NULL,16527 md16528 )) {16529 psError(PS_ERR_UNKNOWN, false, "failed to add metadata");16530 psFree(md);16531 psFree(output);16532 return false;16533 }16534 psFree(md);16535 }16536 16537 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {16538 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");16539 psFree(output);16540 }16541 psFree(output);16542 16543 return true;16544 }16545 bool stackRunPrintObject(FILE *stream, stackRunRow *object, bool mdcf)16546 {16547 PS_ASSERT_PTR_NON_NULL(object, false);16548 16549 psMetadata *md = stackRunMetadataFromObject(object);16550 16551 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {16552 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");16553 psFree(md);16554 }16555 16556 psFree(md);16557 16558 return true;16559 }16560 static void stackInputSkyfileRowFree(stackInputSkyfileRow *object);16561 16562 stackInputSkyfileRow *stackInputSkyfileRowAlloc(psS64 stack_id, psS64 warp_id)16563 {16564 stackInputSkyfileRow *_object;16565 16566 _object = psAlloc(sizeof(stackInputSkyfileRow));16567 psMemSetDeallocator(_object, (psFreeFunc)stackInputSkyfileRowFree);16568 16569 _object->stack_id = stack_id;16570 _object->warp_id = warp_id;16571 16572 return _object;16573 }16574 16575 static void stackInputSkyfileRowFree(stackInputSkyfileRow *object)16576 {16577 }16578 16579 bool stackInputSkyfileCreateTable(psDB *dbh)16580 {16581 psMetadata *md = psMetadataAlloc();16582 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, "Primary Key", 0)) {16583 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id");16584 psFree(md);16585 return false;16586 }16587 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key", 0)) {16588 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");16589 psFree(md);16590 return false;16591 }16592 16593 bool status = psDBCreateTable(dbh, STACKINPUTSKYFILE_TABLE_NAME, md);16594 16595 psFree(md);16596 16597 return status;16598 }16599 16600 bool stackInputSkyfileDropTable(psDB *dbh)16601 {16602 return psDBDropTable(dbh, STACKINPUTSKYFILE_TABLE_NAME);16603 }16604 16605 bool stackInputSkyfileInsert(psDB * dbh, psS64 stack_id, psS64 warp_id)16606 {16607 psMetadata *md = psMetadataAlloc();16608 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, NULL, stack_id)) {16609 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id");16610 psFree(md);16611 return false;16612 }16613 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, warp_id)) {16614 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");16615 psFree(md);16616 return false;16617 }16618 16619 bool status = psDBInsertOneRow(dbh, STACKINPUTSKYFILE_TABLE_NAME, md);16620 psFree(md);16621 16622 return status;16623 }16624 16625 long long stackInputSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)16626 {16627 long long deleted = 0;16628 16629 long long count = psDBDeleteRows(dbh, STACKINPUTSKYFILE_TABLE_NAME, where, limit);16630 if (count < 0) {16631 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackInputSkyfile");16632 return count;16633 16634 deleted += count;16635 }16636 16637 return deleted;16638 }16639 bool stackInputSkyfileInsertObject(psDB *dbh, stackInputSkyfileRow *object)16640 {16641 return stackInputSkyfileInsert(dbh, object->stack_id, object->warp_id);16642 }16643 16644 bool stackInputSkyfileInsertObjects(psDB *dbh, psArray *objects)16645 {16646 for (long i = 0; i < psArrayLength(objects); i++) {16647 if (!stackInputSkyfileInsertObject(dbh, objects->data[i])) {16648 return false;16649 }16650 }16651 16652 return true;16653 }16654 16655 bool stackInputSkyfileInsertFits(psDB *dbh, const psFits *fits)16656 {16657 psArray *rowSet;16658 16659 // move to (the first?) extension named STACKINPUTSKYFILE_TABLE_NAME16660 if (!psFitsMoveExtName(fits, STACKINPUTSKYFILE_TABLE_NAME)) {16661 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", STACKINPUTSKYFILE_TABLE_NAME);16662 return false;16663 }16664 16665 // check HDU type16666 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) {16667 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");16668 return false;16669 }16670 16671 // read fits table16672 rowSet = psFitsReadTable(fits);16673 if (!rowSet) {16674 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");16675 psFree(rowSet);16676 return false;16677 }16678 16679 if (!psDBInsertRows(dbh, STACKINPUTSKYFILE_TABLE_NAME, rowSet)) {16680 psError(PS_ERR_UNKNOWN, false, "databse insert failed");16681 psFree(rowSet);16682 return false;16683 }16684 16685 psFree(rowSet);16686 16687 return true;16688 }16689 16690 bool stackInputSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)16691 {16692 psArray *rowSet;16693 16694 rowSet = psDBSelectRows(dbh, STACKINPUTSKYFILE_TABLE_NAME, where, limit);16695 if (!rowSet) {16696 return false;16697 }16698 16699 // output to fits16700 if (!psFitsWriteTable(fits, NULL, rowSet, STACKINPUTSKYFILE_TABLE_NAME)) {16701 psError(PS_ERR_UNKNOWN, false, "FITS table write failed");16702 psFree(rowSet);16703 return false;16704 }16705 16706 psFree(rowSet);16707 16708 return true;16709 }16710 16711 psMetadata *stackInputSkyfileMetadataFromObject(const stackInputSkyfileRow *object)16712 {16713 psMetadata *md = psMetadataAlloc();16714 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, NULL, object->stack_id)) {16715 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id");16716 psFree(md);16717 return false;16718 }16719 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, NULL, object->warp_id)) {16720 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id");16721 psFree(md);16722 return false;16723 }16724 16725 16726 return md;16727 }16728 16729 stackInputSkyfileRow *stackInputSkyfileObjectFromMetadata(psMetadata *md)16730 {16731 16732 bool status = false;16733 psS64 stack_id = psMetadataLookupS64(&status, md, "stack_id");16734 if (!status) {16735 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item stack_id");16736 return false;16737 }16738 psS64 warp_id = psMetadataLookupS64(&status, md, "warp_id");16739 if (!status) {16740 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item warp_id");16741 return false;16742 }16743 16744 return stackInputSkyfileRowAlloc(stack_id, warp_id);16745 }16746 psArray *stackInputSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)16747 {16748 psArray *rowSet;16749 psArray *returnSet;16750 psU64 i;16751 16752 rowSet = psDBSelectRows(dbh, STACKINPUTSKYFILE_TABLE_NAME, where, limit);16753 if (!rowSet) {16754 return NULL;16755 }16756 16757 // convert psMetadata rows to row objects16758 16759 returnSet = psArrayAllocEmpty(rowSet->n);16760 16761 for (i = 0; i < rowSet->n; i++) {16762 stackInputSkyfileRow *object = stackInputSkyfileObjectFromMetadata(rowSet->data[i]);16763 psArrayAdd(returnSet, 0, object);16764 psFree(object);16765 }16766 16767 psFree(rowSet);16768 16769 return returnSet;16770 }16771 bool stackInputSkyfileDeleteObject(psDB *dbh, const stackInputSkyfileRow *object)16772 {16773 psMetadata *where = stackInputSkyfileMetadataFromObject(object);16774 long long count = psDBDeleteRows(dbh, STACKINPUTSKYFILE_TABLE_NAME, where, 0);16775 psFree(where);16776 if (count < 0) {16777 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackInputSkyfile");16778 return false;16779 }16780 if (count > 1) {16781 // XXX should this be a psAbort() instead? It is possible that16782 // having an object match multiple rows was by design.16783 psError(PS_ERR_UNKNOWN, true, "stackInputSkyfileRow object matched more then one row. Check your database schema");16784 return false;16785 }16786 16787 return true;16788 }16789 long long stackInputSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)16790 {16791 long long deleted = 0;16792 16793 for (long long i = 0; i < objects->n; i++) {16794 stackInputSkyfileRow *object = objects->data[i];16795 psMetadata *where = stackInputSkyfileMetadataFromObject(object);16796 long long count = psDBDeleteRows(dbh, STACKINPUTSKYFILE_TABLE_NAME, where, limit);16797 psFree(where);16798 if (count < 0) {16799 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackInputSkyfile");16800 return count;16801 }16802 16803 deleted += count;16804 }16805 16806 return deleted;16807 }16808 bool stackInputSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)16809 {16810 PS_ASSERT_PTR_NON_NULL(objects, false);16811 16812 psMetadata *output = psMetadataAlloc();16813 for (long i = 0; i < psArrayLength(objects); i++) {16814 psMetadata *md = stackInputSkyfileMetadataFromObject(objects->data[i]);16815 if (!psMetadataAddMetadata(16816 output,16817 PS_LIST_TAIL,16818 STACKINPUTSKYFILE_TABLE_NAME,16819 PS_META_DUPLICATE_OK,16820 NULL,16821 md16822 )) {16823 psError(PS_ERR_UNKNOWN, false, "failed to add metadata");16824 psFree(md);16825 psFree(output);16826 return false;16827 }16828 psFree(md);16829 }16830 16831 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {16832 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");16833 psFree(output);16834 }16835 psFree(output);16836 16837 return true;16838 }16839 bool stackInputSkyfilePrintObject(FILE *stream, stackInputSkyfileRow *object, bool mdcf)16840 {16841 PS_ASSERT_PTR_NON_NULL(object, false);16842 16843 psMetadata *md = stackInputSkyfileMetadataFromObject(object);16844 16845 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {16846 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");16847 psFree(md);16848 }16849 16850 psFree(md);16851 16852 return true;16853 }16854 static void stackSumSkyfileRowFree(stackSumSkyfileRow *object);16855 16856 stackSumSkyfileRow *stackSumSkyfileRowAlloc(psS64 stack_id, const char *uri, psF64 bg, psF64 bg_stdev)16857 {16858 stackSumSkyfileRow *_object;16859 16860 _object = psAlloc(sizeof(stackSumSkyfileRow));16861 psMemSetDeallocator(_object, (psFreeFunc)stackSumSkyfileRowFree);16862 16863 _object->stack_id = stack_id;16864 _object->uri = psStringCopy(uri);16865 _object->bg = bg;16866 _object->bg_stdev = bg_stdev;16867 16868 return _object;16869 }16870 16871 static void stackSumSkyfileRowFree(stackSumSkyfileRow *object)16872 {16873 psFree(object->uri);16874 }16875 16876 bool stackSumSkyfileCreateTable(psDB *dbh)16877 {16878 psMetadata *md = psMetadataAlloc();16879 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, "Primary Key", 0)) {16880 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id");16881 psFree(md);16882 return false;16883 }16884 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) {16885 psError(PS_ERR_UNKNOWN, false, "failed to add item uri");16886 psFree(md);16887 return false;16888 }16889 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, 0.0)) {16890 psError(PS_ERR_UNKNOWN, false, "failed to add item bg");16891 psFree(md);16892 return false;16893 }16894 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, 0.0)) {16895 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev");16896 psFree(md);16897 return false;16898 }16899 16900 bool status = psDBCreateTable(dbh, STACKSUMSKYFILE_TABLE_NAME, md);16901 16902 psFree(md);16903 16904 return status;16905 }16906 16907 bool stackSumSkyfileDropTable(psDB *dbh)16908 {16909 return psDBDropTable(dbh, STACKSUMSKYFILE_TABLE_NAME);16910 }16911 16912 bool stackSumSkyfileInsert(psDB * dbh, psS64 stack_id, const char *uri, psF64 bg, psF64 bg_stdev)16913 {16914 psMetadata *md = psMetadataAlloc();16915 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, NULL, stack_id)) {16916 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id");16917 psFree(md);16918 return false;16919 }16920 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) {16921 psError(PS_ERR_UNKNOWN, false, "failed to add item uri");16922 psFree(md);16923 return false;16924 }16925 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, bg)) {16926 psError(PS_ERR_UNKNOWN, false, "failed to add item bg");16927 psFree(md);16928 return false;16929 }16930 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, bg_stdev)) {16931 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev");16932 psFree(md);16933 return false;16934 }16935 16936 bool status = psDBInsertOneRow(dbh, STACKSUMSKYFILE_TABLE_NAME, md);16937 psFree(md);16938 16939 return status;16940 }16941 16942 long long stackSumSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)16943 {16944 long long deleted = 0;16945 16946 long long count = psDBDeleteRows(dbh, STACKSUMSKYFILE_TABLE_NAME, where, limit);16947 if (count < 0) {16948 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackSumSkyfile");16949 return count;16950 16951 deleted += count;16952 }16953 16954 return deleted;16955 }16956 bool stackSumSkyfileInsertObject(psDB *dbh, stackSumSkyfileRow *object)16957 {16958 return stackSumSkyfileInsert(dbh, object->stack_id, object->uri, object->bg, object->bg_stdev);16959 }16960 16961 bool stackSumSkyfileInsertObjects(psDB *dbh, psArray *objects)16962 {16963 for (long i = 0; i < psArrayLength(objects); i++) {16964 if (!stackSumSkyfileInsertObject(dbh, objects->data[i])) {16965 return false;16966 }16967 }16968 16969 return true;16970 }16971 16972 bool stackSumSkyfileInsertFits(psDB *dbh, const psFits *fits)16973 {16974 psArray *rowSet;16975 16976 // move to (the first?) extension named STACKSUMSKYFILE_TABLE_NAME16977 if (!psFitsMoveExtName(fits, STACKSUMSKYFILE_TABLE_NAME)) {16978 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", STACKSUMSKYFILE_TABLE_NAME);16979 return false;16980 }16981 16982 // check HDU type16983 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) {16984 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");16985 return false;16986 }16987 16988 // read fits table16989 rowSet = psFitsReadTable(fits);16990 if (!rowSet) {16991 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");16992 psFree(rowSet);16993 return false;16994 }16995 16996 if (!psDBInsertRows(dbh, STACKSUMSKYFILE_TABLE_NAME, rowSet)) {16997 psError(PS_ERR_UNKNOWN, false, "databse insert failed");16998 psFree(rowSet);16999 return false;17000 }17001 17002 psFree(rowSet);17003 17004 return true;17005 }17006 17007 bool stackSumSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)17008 {17009 psArray *rowSet;17010 17011 rowSet = psDBSelectRows(dbh, STACKSUMSKYFILE_TABLE_NAME, where, limit);17012 if (!rowSet) {17013 return false;17014 }17015 17016 // output to fits17017 if (!psFitsWriteTable(fits, NULL, rowSet, STACKSUMSKYFILE_TABLE_NAME)) {17018 psError(PS_ERR_UNKNOWN, false, "FITS table write failed");17019 psFree(rowSet);17020 return false;17021 }17022 17023 psFree(rowSet);17024 17025 return true;17026 }17027 17028 psMetadata *stackSumSkyfileMetadataFromObject(const stackSumSkyfileRow *object)17029 {17030 psMetadata *md = psMetadataAlloc();17031 if (!psMetadataAdd(md, PS_LIST_TAIL, "stack_id", PS_DATA_S64, NULL, object->stack_id)) {17032 psError(PS_ERR_UNKNOWN, false, "failed to add item stack_id");17033 psFree(md);17034 return false;17035 }17036 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) {17037 psError(PS_ERR_UNKNOWN, false, "failed to add item uri");17038 psFree(md);17039 return false;17040 }17041 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, object->bg)) {17042 psError(PS_ERR_UNKNOWN, false, "failed to add item bg");17043 psFree(md);17044 return false;17045 }17046 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_stdev", PS_DATA_F64, NULL, object->bg_stdev)) {17047 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev");17048 psFree(md);17049 return false;17050 }17051 17052 17053 return md;17054 }17055 17056 stackSumSkyfileRow *stackSumSkyfileObjectFromMetadata(psMetadata *md)17057 {17058 17059 bool status = false;17060 psS64 stack_id = psMetadataLookupS64(&status, md, "stack_id");17061 if (!status) {17062 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item stack_id");17063 return false;17064 }17065 char* uri = psMetadataLookupPtr(&status, md, "uri");17066 if (!status) {17067 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri");17068 return false;17069 }17070 psF64 bg = psMetadataLookupF64(&status, md, "bg");17071 if (!status) {17072 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg");17073 return false;17074 }17075 psF64 bg_stdev = psMetadataLookupF64(&status, md, "bg_stdev");17076 if (!status) {17077 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_stdev");17078 return false;17079 }17080 17081 return stackSumSkyfileRowAlloc(stack_id, uri, bg, bg_stdev);17082 }17083 psArray *stackSumSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)17084 {17085 psArray *rowSet;17086 psArray *returnSet;17087 psU64 i;17088 17089 rowSet = psDBSelectRows(dbh, STACKSUMSKYFILE_TABLE_NAME, where, limit);17090 if (!rowSet) {17091 return NULL;17092 }17093 17094 // convert psMetadata rows to row objects17095 17096 returnSet = psArrayAllocEmpty(rowSet->n);17097 17098 for (i = 0; i < rowSet->n; i++) {17099 stackSumSkyfileRow *object = stackSumSkyfileObjectFromMetadata(rowSet->data[i]);17100 psArrayAdd(returnSet, 0, object);17101 psFree(object);17102 }17103 17104 psFree(rowSet);17105 17106 return returnSet;17107 }17108 bool stackSumSkyfileDeleteObject(psDB *dbh, const stackSumSkyfileRow *object)17109 {17110 psMetadata *where = stackSumSkyfileMetadataFromObject(object);17111 long long count = psDBDeleteRows(dbh, STACKSUMSKYFILE_TABLE_NAME, where, 0);17112 psFree(where);17113 if (count < 0) {17114 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackSumSkyfile");17115 return false;17116 }17117 if (count > 1) {17118 // XXX should this be a psAbort() instead? It is possible that17119 // having an object match multiple rows was by design.17120 psError(PS_ERR_UNKNOWN, true, "stackSumSkyfileRow object matched more then one row. Check your database schema");17121 return false;17122 }17123 17124 return true;17125 }17126 long long stackSumSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)17127 {17128 long long deleted = 0;17129 17130 for (long long i = 0; i < objects->n; i++) {17131 stackSumSkyfileRow *object = objects->data[i];17132 psMetadata *where = stackSumSkyfileMetadataFromObject(object);17133 long long count = psDBDeleteRows(dbh, STACKSUMSKYFILE_TABLE_NAME, where, limit);17134 psFree(where);17135 if (count < 0) {17136 psError(PS_ERR_UNKNOWN, true, "failed to delete row from stackSumSkyfile");17137 return count;17138 }17139 17140 deleted += count;17141 }17142 17143 return deleted;17144 }17145 bool stackSumSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)17146 {17147 PS_ASSERT_PTR_NON_NULL(objects, false);17148 17149 psMetadata *output = psMetadataAlloc();17150 for (long i = 0; i < psArrayLength(objects); i++) {17151 psMetadata *md = stackSumSkyfileMetadataFromObject(objects->data[i]);17152 if (!psMetadataAddMetadata(17153 output,17154 PS_LIST_TAIL,17155 STACKSUMSKYFILE_TABLE_NAME,17156 PS_META_DUPLICATE_OK,17157 NULL,17158 md17159 )) {17160 psError(PS_ERR_UNKNOWN, false, "failed to add metadata");17161 psFree(md);17162 psFree(output);17163 return false;17164 }17165 psFree(md);17166 }17167 17168 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {17169 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");17170 psFree(output);17171 }17172 psFree(output);17173 17174 return true;17175 }17176 bool stackSumSkyfilePrintObject(FILE *stream, stackSumSkyfileRow *object, bool mdcf)17177 {17178 PS_ASSERT_PTR_NON_NULL(object, false);17179 17180 psMetadata *md = stackSumSkyfileMetadataFromObject(object);17181 17182 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {17183 psError(PS_ERR_UNKNOWN, false, "failed to print metadata");17184 psFree(md);17185 }17186 17187 psFree(md);17188 17189 return true;17190 } -
trunk/ippdb/src/ippdb.h
r12426 r12535 20 20 /* 21 21 * 22 * This file was generated by glueforge 1.0 022 * This file was generated by glueforge 1.01 23 23 * 24 24 * Do NOT directly edit this file. … … 4404 4404 FILE *stream, ///< a stream 4405 4405 camMaskRow *object, ///< an camMaskRow object 4406 bool mdcf ///< format as mdconfig or simple 4407 ); 4408 /** warpRunRow data structure 4409 * 4410 * Structure for representing a single row of warpRun table data. 4411 */ 4412 4413 typedef struct { 4414 psS64 warp_id; 4415 char *mode; 4416 char *state; 4417 char *workdir; 4418 char *dvodb; 4419 psTime* registered; 4420 } warpRunRow; 4421 4422 /** Creates a new warpRunRow object 4423 * 4424 * @return A new warpRunRow object or NULL on failure. 4425 */ 4426 4427 warpRunRow *warpRunRowAlloc( 4428 psS64 warp_id, 4429 const char *mode, 4430 const char *state, 4431 const char *workdir, 4432 const char *dvodb, 4433 psTime* registered 4434 ); 4435 4436 /** Creates a new warpRun table 4437 * 4438 * @return true on success 4439 */ 4440 4441 bool warpRunCreateTable( 4442 psDB *dbh ///< Database handle 4443 ); 4444 4445 /** Deletes a warpRun table 4446 * 4447 * @return true on success 4448 */ 4449 4450 bool warpRunDropTable( 4451 psDB *dbh ///< Database handle 4452 ); 4453 4454 /** Insert a single row into a table 4455 * 4456 * This function constructs and inserts a single row based on it's parameters. 4457 * 4458 * @return true on success 4459 */ 4460 4461 bool warpRunInsert( 4462 psDB *dbh, ///< Database handle 4463 psS64 warp_id, 4464 const char *mode, 4465 const char *state, 4466 const char *workdir, 4467 const char *dvodb, 4468 psTime* registered 4469 ); 4470 4471 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 4472 * 4473 * @return A The number of rows removed or a negative value on error 4474 */ 4475 4476 long long warpRunDelete( 4477 psDB *dbh, ///< Database handle 4478 const psMetadata *where, ///< Row match criteria 4479 unsigned long long limit ///< Maximum number of elements to delete 4480 ); 4481 4482 /** Insert a single warpRunRow object into a table 4483 * 4484 * This function constructs and inserts a single row based on it's parameters. 4485 * 4486 * @return true on success 4487 */ 4488 4489 bool warpRunInsertObject( 4490 psDB *dbh, ///< Database handle 4491 warpRunRow *object ///< warpRunRow object 4492 ); 4493 4494 /** Insert an array of warpRunRow object into a table 4495 * 4496 * This function constructs and inserts multiple rows based on it's parameters. 4497 * 4498 * @return true on success 4499 */ 4500 4501 bool warpRunInsertObjects( 4502 psDB *dbh, ///< Database handle 4503 psArray *objects ///< array of warpRunRow objects 4504 ); 4505 4506 /** Insert data from a binary FITS table warpRunRow into the database 4507 * 4508 * This function expects a psFits object with a FITS table as the first 4509 * extension. The table must have at least one row of data in it, that is of 4510 * the appropriate format (number of columns and their type). All other 4511 * extensions are ignored. 4512 * 4513 * @return true on success 4514 */ 4515 4516 bool warpRunInsertFits( 4517 psDB *dbh, ///< Database handle 4518 const psFits *fits ///< psFits object 4519 ); 4520 4521 /** Selects up to limit from the database and returns them in a binary FITS table 4522 * 4523 * This function assumes an empty psFits object and will create a FITS table 4524 * as the first extension. 4525 * 4526 * See psDBSelectRows() for documentation on the format of where. 4527 * 4528 * @return true on success 4529 */ 4530 4531 bool warpRunSelectRowsFits( 4532 psDB *dbh, ///< Database handle 4533 psFits *fits, ///< psFits object 4534 const psMetadata *where, ///< Row match criteria 4535 unsigned long long limit ///< Maximum number of elements to return 4536 ); 4537 4538 /** Convert a warpRunRow into an equivalent psMetadata 4539 * 4540 * @return A psMetadata pointer or NULL on error 4541 */ 4542 4543 psMetadata *warpRunMetadataFromObject( 4544 const warpRunRow *object ///< fooRow to convert into a psMetadata 4545 ); 4546 4547 /** Convert a psMetadata into an equivalent fooRow 4548 * 4549 * @return A warpRunRow pointer or NULL on error 4550 */ 4551 4552 warpRunRow *warpRunObjectFromMetadata( 4553 psMetadata *md ///< psMetadata to convert into a fooRow 4554 ); 4555 /** Selects up to limit rows from the database and returns as warpRunRow objects in a psArray 4556 * 4557 * See psDBSelectRows() for documentation on the format of where. 4558 * 4559 * @return A psArray pointer or NULL on error 4560 */ 4561 4562 psArray *warpRunSelectRowObjects( 4563 psDB *dbh, ///< Database handle 4564 const psMetadata *where, ///< Row match criteria 4565 unsigned long long limit ///< Maximum number of elements to return 4566 ); 4567 /** Deletes a row from the database coresponding to an warpRun 4568 * 4569 * Note that a 'where' search psMetadata is constructed from each object and 4570 * used to find rows to delete. 4571 * 4572 * @return A The number of rows removed or a negative value on error 4573 */ 4574 4575 bool warpRunDeleteObject( 4576 psDB *dbh, ///< Database handle 4577 const warpRunRow *object ///< Object to delete 4578 ); 4579 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 4580 * 4581 * Note that a 'where' search psMetadata is constructed from each object and 4582 * used to find rows to delete. 4583 * 4584 * @return A The number of rows removed or a negative value on error 4585 */ 4586 4587 long long warpRunDeleteRowObjects( 4588 psDB *dbh, ///< Database handle 4589 const psArray *objects, ///< Array of objects to delete 4590 unsigned long long limit ///< Maximum number of elements to delete 4591 ); 4592 /** Formats and prints an array of warpRunRow objects 4593 * 4594 * When mdcf is set the formated output is in psMetadataConfig 4595 * format, otherwise it is in a simple tabular format. 4596 * 4597 * @return true on success 4598 */ 4599 4600 bool warpRunPrintObjects( 4601 FILE *stream, ///< a stream 4602 psArray *objects, ///< An array of warpRunRow objects 4603 bool mdcf ///< format as mdconfig or simple 4604 ); 4605 /** Formats and prints an warpRunRow object 4606 * 4607 * When mdcf is set the formated output is in psMetadataConfig 4608 * format, otherwise it is in a simple tabular format. 4609 * 4610 * @return true on success 4611 */ 4612 4613 bool warpRunPrintObject( 4614 FILE *stream, ///< a stream 4615 warpRunRow *object, ///< an warpRunRow object 4616 bool mdcf ///< format as mdconfig or simple 4617 ); 4618 /** warpInputExpRow data structure 4619 * 4620 * Structure for representing a single row of warpInputExp table data. 4621 */ 4622 4623 typedef struct { 4624 psS64 warp_id; 4625 psS64 cam_id; 4626 bool magiced; 4627 } warpInputExpRow; 4628 4629 /** Creates a new warpInputExpRow object 4630 * 4631 * @return A new warpInputExpRow object or NULL on failure. 4632 */ 4633 4634 warpInputExpRow *warpInputExpRowAlloc( 4635 psS64 warp_id, 4636 psS64 cam_id, 4637 bool magiced 4638 ); 4639 4640 /** Creates a new warpInputExp table 4641 * 4642 * @return true on success 4643 */ 4644 4645 bool warpInputExpCreateTable( 4646 psDB *dbh ///< Database handle 4647 ); 4648 4649 /** Deletes a warpInputExp table 4650 * 4651 * @return true on success 4652 */ 4653 4654 bool warpInputExpDropTable( 4655 psDB *dbh ///< Database handle 4656 ); 4657 4658 /** Insert a single row into a table 4659 * 4660 * This function constructs and inserts a single row based on it's parameters. 4661 * 4662 * @return true on success 4663 */ 4664 4665 bool warpInputExpInsert( 4666 psDB *dbh, ///< Database handle 4667 psS64 warp_id, 4668 psS64 cam_id, 4669 bool magiced 4670 ); 4671 4672 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 4673 * 4674 * @return A The number of rows removed or a negative value on error 4675 */ 4676 4677 long long warpInputExpDelete( 4678 psDB *dbh, ///< Database handle 4679 const psMetadata *where, ///< Row match criteria 4680 unsigned long long limit ///< Maximum number of elements to delete 4681 ); 4682 4683 /** Insert a single warpInputExpRow object into a table 4684 * 4685 * This function constructs and inserts a single row based on it's parameters. 4686 * 4687 * @return true on success 4688 */ 4689 4690 bool warpInputExpInsertObject( 4691 psDB *dbh, ///< Database handle 4692 warpInputExpRow *object ///< warpInputExpRow object 4693 ); 4694 4695 /** Insert an array of warpInputExpRow object into a table 4696 * 4697 * This function constructs and inserts multiple rows based on it's parameters. 4698 * 4699 * @return true on success 4700 */ 4701 4702 bool warpInputExpInsertObjects( 4703 psDB *dbh, ///< Database handle 4704 psArray *objects ///< array of warpInputExpRow objects 4705 ); 4706 4707 /** Insert data from a binary FITS table warpInputExpRow into the database 4708 * 4709 * This function expects a psFits object with a FITS table as the first 4710 * extension. The table must have at least one row of data in it, that is of 4711 * the appropriate format (number of columns and their type). All other 4712 * extensions are ignored. 4713 * 4714 * @return true on success 4715 */ 4716 4717 bool warpInputExpInsertFits( 4718 psDB *dbh, ///< Database handle 4719 const psFits *fits ///< psFits object 4720 ); 4721 4722 /** Selects up to limit from the database and returns them in a binary FITS table 4723 * 4724 * This function assumes an empty psFits object and will create a FITS table 4725 * as the first extension. 4726 * 4727 * See psDBSelectRows() for documentation on the format of where. 4728 * 4729 * @return true on success 4730 */ 4731 4732 bool warpInputExpSelectRowsFits( 4733 psDB *dbh, ///< Database handle 4734 psFits *fits, ///< psFits object 4735 const psMetadata *where, ///< Row match criteria 4736 unsigned long long limit ///< Maximum number of elements to return 4737 ); 4738 4739 /** Convert a warpInputExpRow into an equivalent psMetadata 4740 * 4741 * @return A psMetadata pointer or NULL on error 4742 */ 4743 4744 psMetadata *warpInputExpMetadataFromObject( 4745 const warpInputExpRow *object ///< fooRow to convert into a psMetadata 4746 ); 4747 4748 /** Convert a psMetadata into an equivalent fooRow 4749 * 4750 * @return A warpInputExpRow pointer or NULL on error 4751 */ 4752 4753 warpInputExpRow *warpInputExpObjectFromMetadata( 4754 psMetadata *md ///< psMetadata to convert into a fooRow 4755 ); 4756 /** Selects up to limit rows from the database and returns as warpInputExpRow objects in a psArray 4757 * 4758 * See psDBSelectRows() for documentation on the format of where. 4759 * 4760 * @return A psArray pointer or NULL on error 4761 */ 4762 4763 psArray *warpInputExpSelectRowObjects( 4764 psDB *dbh, ///< Database handle 4765 const psMetadata *where, ///< Row match criteria 4766 unsigned long long limit ///< Maximum number of elements to return 4767 ); 4768 /** Deletes a row from the database coresponding to an warpInputExp 4769 * 4770 * Note that a 'where' search psMetadata is constructed from each object and 4771 * used to find rows to delete. 4772 * 4773 * @return A The number of rows removed or a negative value on error 4774 */ 4775 4776 bool warpInputExpDeleteObject( 4777 psDB *dbh, ///< Database handle 4778 const warpInputExpRow *object ///< Object to delete 4779 ); 4780 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 4781 * 4782 * Note that a 'where' search psMetadata is constructed from each object and 4783 * used to find rows to delete. 4784 * 4785 * @return A The number of rows removed or a negative value on error 4786 */ 4787 4788 long long warpInputExpDeleteRowObjects( 4789 psDB *dbh, ///< Database handle 4790 const psArray *objects, ///< Array of objects to delete 4791 unsigned long long limit ///< Maximum number of elements to delete 4792 ); 4793 /** Formats and prints an array of warpInputExpRow objects 4794 * 4795 * When mdcf is set the formated output is in psMetadataConfig 4796 * format, otherwise it is in a simple tabular format. 4797 * 4798 * @return true on success 4799 */ 4800 4801 bool warpInputExpPrintObjects( 4802 FILE *stream, ///< a stream 4803 psArray *objects, ///< An array of warpInputExpRow objects 4804 bool mdcf ///< format as mdconfig or simple 4805 ); 4806 /** Formats and prints an warpInputExpRow object 4807 * 4808 * When mdcf is set the formated output is in psMetadataConfig 4809 * format, otherwise it is in a simple tabular format. 4810 * 4811 * @return true on success 4812 */ 4813 4814 bool warpInputExpPrintObject( 4815 FILE *stream, ///< a stream 4816 warpInputExpRow *object, ///< an warpInputExpRow object 4817 bool mdcf ///< format as mdconfig or simple 4818 ); 4819 /** warpSkyCellMapRow data structure 4820 * 4821 * Structure for representing a single row of warpSkyCellMap table data. 4822 */ 4823 4824 typedef struct { 4825 psS64 warp_id; 4826 char *skycell_id; 4827 char *tess_id; 4828 psS64 cam_id; 4829 char *class_id; 4830 psS16 fault; 4831 } warpSkyCellMapRow; 4832 4833 /** Creates a new warpSkyCellMapRow object 4834 * 4835 * @return A new warpSkyCellMapRow object or NULL on failure. 4836 */ 4837 4838 warpSkyCellMapRow *warpSkyCellMapRowAlloc( 4839 psS64 warp_id, 4840 const char *skycell_id, 4841 const char *tess_id, 4842 psS64 cam_id, 4843 const char *class_id, 4844 psS16 fault 4845 ); 4846 4847 /** Creates a new warpSkyCellMap table 4848 * 4849 * @return true on success 4850 */ 4851 4852 bool warpSkyCellMapCreateTable( 4853 psDB *dbh ///< Database handle 4854 ); 4855 4856 /** Deletes a warpSkyCellMap table 4857 * 4858 * @return true on success 4859 */ 4860 4861 bool warpSkyCellMapDropTable( 4862 psDB *dbh ///< Database handle 4863 ); 4864 4865 /** Insert a single row into a table 4866 * 4867 * This function constructs and inserts a single row based on it's parameters. 4868 * 4869 * @return true on success 4870 */ 4871 4872 bool warpSkyCellMapInsert( 4873 psDB *dbh, ///< Database handle 4874 psS64 warp_id, 4875 const char *skycell_id, 4876 const char *tess_id, 4877 psS64 cam_id, 4878 const char *class_id, 4879 psS16 fault 4880 ); 4881 4882 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 4883 * 4884 * @return A The number of rows removed or a negative value on error 4885 */ 4886 4887 long long warpSkyCellMapDelete( 4888 psDB *dbh, ///< Database handle 4889 const psMetadata *where, ///< Row match criteria 4890 unsigned long long limit ///< Maximum number of elements to delete 4891 ); 4892 4893 /** Insert a single warpSkyCellMapRow object into a table 4894 * 4895 * This function constructs and inserts a single row based on it's parameters. 4896 * 4897 * @return true on success 4898 */ 4899 4900 bool warpSkyCellMapInsertObject( 4901 psDB *dbh, ///< Database handle 4902 warpSkyCellMapRow *object ///< warpSkyCellMapRow object 4903 ); 4904 4905 /** Insert an array of warpSkyCellMapRow object into a table 4906 * 4907 * This function constructs and inserts multiple rows based on it's parameters. 4908 * 4909 * @return true on success 4910 */ 4911 4912 bool warpSkyCellMapInsertObjects( 4913 psDB *dbh, ///< Database handle 4914 psArray *objects ///< array of warpSkyCellMapRow objects 4915 ); 4916 4917 /** Insert data from a binary FITS table warpSkyCellMapRow into the database 4918 * 4919 * This function expects a psFits object with a FITS table as the first 4920 * extension. The table must have at least one row of data in it, that is of 4921 * the appropriate format (number of columns and their type). All other 4922 * extensions are ignored. 4923 * 4924 * @return true on success 4925 */ 4926 4927 bool warpSkyCellMapInsertFits( 4928 psDB *dbh, ///< Database handle 4929 const psFits *fits ///< psFits object 4930 ); 4931 4932 /** Selects up to limit from the database and returns them in a binary FITS table 4933 * 4934 * This function assumes an empty psFits object and will create a FITS table 4935 * as the first extension. 4936 * 4937 * See psDBSelectRows() for documentation on the format of where. 4938 * 4939 * @return true on success 4940 */ 4941 4942 bool warpSkyCellMapSelectRowsFits( 4943 psDB *dbh, ///< Database handle 4944 psFits *fits, ///< psFits object 4945 const psMetadata *where, ///< Row match criteria 4946 unsigned long long limit ///< Maximum number of elements to return 4947 ); 4948 4949 /** Convert a warpSkyCellMapRow into an equivalent psMetadata 4950 * 4951 * @return A psMetadata pointer or NULL on error 4952 */ 4953 4954 psMetadata *warpSkyCellMapMetadataFromObject( 4955 const warpSkyCellMapRow *object ///< fooRow to convert into a psMetadata 4956 ); 4957 4958 /** Convert a psMetadata into an equivalent fooRow 4959 * 4960 * @return A warpSkyCellMapRow pointer or NULL on error 4961 */ 4962 4963 warpSkyCellMapRow *warpSkyCellMapObjectFromMetadata( 4964 psMetadata *md ///< psMetadata to convert into a fooRow 4965 ); 4966 /** Selects up to limit rows from the database and returns as warpSkyCellMapRow objects in a psArray 4967 * 4968 * See psDBSelectRows() for documentation on the format of where. 4969 * 4970 * @return A psArray pointer or NULL on error 4971 */ 4972 4973 psArray *warpSkyCellMapSelectRowObjects( 4974 psDB *dbh, ///< Database handle 4975 const psMetadata *where, ///< Row match criteria 4976 unsigned long long limit ///< Maximum number of elements to return 4977 ); 4978 /** Deletes a row from the database coresponding to an warpSkyCellMap 4979 * 4980 * Note that a 'where' search psMetadata is constructed from each object and 4981 * used to find rows to delete. 4982 * 4983 * @return A The number of rows removed or a negative value on error 4984 */ 4985 4986 bool warpSkyCellMapDeleteObject( 4987 psDB *dbh, ///< Database handle 4988 const warpSkyCellMapRow *object ///< Object to delete 4989 ); 4990 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 4991 * 4992 * Note that a 'where' search psMetadata is constructed from each object and 4993 * used to find rows to delete. 4994 * 4995 * @return A The number of rows removed or a negative value on error 4996 */ 4997 4998 long long warpSkyCellMapDeleteRowObjects( 4999 psDB *dbh, ///< Database handle 5000 const psArray *objects, ///< Array of objects to delete 5001 unsigned long long limit ///< Maximum number of elements to delete 5002 ); 5003 /** Formats and prints an array of warpSkyCellMapRow objects 5004 * 5005 * When mdcf is set the formated output is in psMetadataConfig 5006 * format, otherwise it is in a simple tabular format. 5007 * 5008 * @return true on success 5009 */ 5010 5011 bool warpSkyCellMapPrintObjects( 5012 FILE *stream, ///< a stream 5013 psArray *objects, ///< An array of warpSkyCellMapRow objects 5014 bool mdcf ///< format as mdconfig or simple 5015 ); 5016 /** Formats and prints an warpSkyCellMapRow object 5017 * 5018 * When mdcf is set the formated output is in psMetadataConfig 5019 * format, otherwise it is in a simple tabular format. 5020 * 5021 * @return true on success 5022 */ 5023 5024 bool warpSkyCellMapPrintObject( 5025 FILE *stream, ///< a stream 5026 warpSkyCellMapRow *object, ///< an warpSkyCellMapRow object 5027 bool mdcf ///< format as mdconfig or simple 5028 ); 5029 /** warpSkyfileRow data structure 5030 * 5031 * Structure for representing a single row of warpSkyfile table data. 5032 */ 5033 5034 typedef struct { 5035 psS64 warp_id; 5036 char *skycell_id; 5037 char *tess_id; 5038 char *uri; 5039 psF64 bg; 5040 psF64 bg_stdev; 5041 } warpSkyfileRow; 5042 5043 /** Creates a new warpSkyfileRow object 5044 * 5045 * @return A new warpSkyfileRow object or NULL on failure. 5046 */ 5047 5048 warpSkyfileRow *warpSkyfileRowAlloc( 5049 psS64 warp_id, 5050 const char *skycell_id, 5051 const char *tess_id, 5052 const char *uri, 5053 psF64 bg, 5054 psF64 bg_stdev 5055 ); 5056 5057 /** Creates a new warpSkyfile table 5058 * 5059 * @return true on success 5060 */ 5061 5062 bool warpSkyfileCreateTable( 5063 psDB *dbh ///< Database handle 5064 ); 5065 5066 /** Deletes a warpSkyfile table 5067 * 5068 * @return true on success 5069 */ 5070 5071 bool warpSkyfileDropTable( 5072 psDB *dbh ///< Database handle 5073 ); 5074 5075 /** Insert a single row into a table 5076 * 5077 * This function constructs and inserts a single row based on it's parameters. 5078 * 5079 * @return true on success 5080 */ 5081 5082 bool warpSkyfileInsert( 5083 psDB *dbh, ///< Database handle 5084 psS64 warp_id, 5085 const char *skycell_id, 5086 const char *tess_id, 5087 const char *uri, 5088 psF64 bg, 5089 psF64 bg_stdev 5090 ); 5091 5092 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 5093 * 5094 * @return A The number of rows removed or a negative value on error 5095 */ 5096 5097 long long warpSkyfileDelete( 5098 psDB *dbh, ///< Database handle 5099 const psMetadata *where, ///< Row match criteria 5100 unsigned long long limit ///< Maximum number of elements to delete 5101 ); 5102 5103 /** Insert a single warpSkyfileRow object into a table 5104 * 5105 * This function constructs and inserts a single row based on it's parameters. 5106 * 5107 * @return true on success 5108 */ 5109 5110 bool warpSkyfileInsertObject( 5111 psDB *dbh, ///< Database handle 5112 warpSkyfileRow *object ///< warpSkyfileRow object 5113 ); 5114 5115 /** Insert an array of warpSkyfileRow object into a table 5116 * 5117 * This function constructs and inserts multiple rows based on it's parameters. 5118 * 5119 * @return true on success 5120 */ 5121 5122 bool warpSkyfileInsertObjects( 5123 psDB *dbh, ///< Database handle 5124 psArray *objects ///< array of warpSkyfileRow objects 5125 ); 5126 5127 /** Insert data from a binary FITS table warpSkyfileRow into the database 5128 * 5129 * This function expects a psFits object with a FITS table as the first 5130 * extension. The table must have at least one row of data in it, that is of 5131 * the appropriate format (number of columns and their type). All other 5132 * extensions are ignored. 5133 * 5134 * @return true on success 5135 */ 5136 5137 bool warpSkyfileInsertFits( 5138 psDB *dbh, ///< Database handle 5139 const psFits *fits ///< psFits object 5140 ); 5141 5142 /** Selects up to limit from the database and returns them in a binary FITS table 5143 * 5144 * This function assumes an empty psFits object and will create a FITS table 5145 * as the first extension. 5146 * 5147 * See psDBSelectRows() for documentation on the format of where. 5148 * 5149 * @return true on success 5150 */ 5151 5152 bool warpSkyfileSelectRowsFits( 5153 psDB *dbh, ///< Database handle 5154 psFits *fits, ///< psFits object 5155 const psMetadata *where, ///< Row match criteria 5156 unsigned long long limit ///< Maximum number of elements to return 5157 ); 5158 5159 /** Convert a warpSkyfileRow into an equivalent psMetadata 5160 * 5161 * @return A psMetadata pointer or NULL on error 5162 */ 5163 5164 psMetadata *warpSkyfileMetadataFromObject( 5165 const warpSkyfileRow *object ///< fooRow to convert into a psMetadata 5166 ); 5167 5168 /** Convert a psMetadata into an equivalent fooRow 5169 * 5170 * @return A warpSkyfileRow pointer or NULL on error 5171 */ 5172 5173 warpSkyfileRow *warpSkyfileObjectFromMetadata( 5174 psMetadata *md ///< psMetadata to convert into a fooRow 5175 ); 5176 /** Selects up to limit rows from the database and returns as warpSkyfileRow objects in a psArray 5177 * 5178 * See psDBSelectRows() for documentation on the format of where. 5179 * 5180 * @return A psArray pointer or NULL on error 5181 */ 5182 5183 psArray *warpSkyfileSelectRowObjects( 5184 psDB *dbh, ///< Database handle 5185 const psMetadata *where, ///< Row match criteria 5186 unsigned long long limit ///< Maximum number of elements to return 5187 ); 5188 /** Deletes a row from the database coresponding to an warpSkyfile 5189 * 5190 * Note that a 'where' search psMetadata is constructed from each object and 5191 * used to find rows to delete. 5192 * 5193 * @return A The number of rows removed or a negative value on error 5194 */ 5195 5196 bool warpSkyfileDeleteObject( 5197 psDB *dbh, ///< Database handle 5198 const warpSkyfileRow *object ///< Object to delete 5199 ); 5200 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 5201 * 5202 * Note that a 'where' search psMetadata is constructed from each object and 5203 * used to find rows to delete. 5204 * 5205 * @return A The number of rows removed or a negative value on error 5206 */ 5207 5208 long long warpSkyfileDeleteRowObjects( 5209 psDB *dbh, ///< Database handle 5210 const psArray *objects, ///< Array of objects to delete 5211 unsigned long long limit ///< Maximum number of elements to delete 5212 ); 5213 /** Formats and prints an array of warpSkyfileRow objects 5214 * 5215 * When mdcf is set the formated output is in psMetadataConfig 5216 * format, otherwise it is in a simple tabular format. 5217 * 5218 * @return true on success 5219 */ 5220 5221 bool warpSkyfilePrintObjects( 5222 FILE *stream, ///< a stream 5223 psArray *objects, ///< An array of warpSkyfileRow objects 5224 bool mdcf ///< format as mdconfig or simple 5225 ); 5226 /** Formats and prints an warpSkyfileRow object 5227 * 5228 * When mdcf is set the formated output is in psMetadataConfig 5229 * format, otherwise it is in a simple tabular format. 5230 * 5231 * @return true on success 5232 */ 5233 5234 bool warpSkyfilePrintObject( 5235 FILE *stream, ///< a stream 5236 warpSkyfileRow *object, ///< an warpSkyfileRow object 5237 bool mdcf ///< format as mdconfig or simple 5238 ); 5239 /** diffRunRow data structure 5240 * 5241 * Structure for representing a single row of diffRun table data. 5242 */ 5243 5244 typedef struct { 5245 psS64 diff_id; 5246 char *state; 5247 char *workdir; 5248 char *dvodb; 5249 psTime* registered; 5250 char *skycell_id; 5251 char *tess_id; 5252 } diffRunRow; 5253 5254 /** Creates a new diffRunRow object 5255 * 5256 * @return A new diffRunRow object or NULL on failure. 5257 */ 5258 5259 diffRunRow *diffRunRowAlloc( 5260 psS64 diff_id, 5261 const char *state, 5262 const char *workdir, 5263 const char *dvodb, 5264 psTime* registered, 5265 const char *skycell_id, 5266 const char *tess_id 5267 ); 5268 5269 /** Creates a new diffRun table 5270 * 5271 * @return true on success 5272 */ 5273 5274 bool diffRunCreateTable( 5275 psDB *dbh ///< Database handle 5276 ); 5277 5278 /** Deletes a diffRun table 5279 * 5280 * @return true on success 5281 */ 5282 5283 bool diffRunDropTable( 5284 psDB *dbh ///< Database handle 5285 ); 5286 5287 /** Insert a single row into a table 5288 * 5289 * This function constructs and inserts a single row based on it's parameters. 5290 * 5291 * @return true on success 5292 */ 5293 5294 bool diffRunInsert( 5295 psDB *dbh, ///< Database handle 5296 psS64 diff_id, 5297 const char *state, 5298 const char *workdir, 5299 const char *dvodb, 5300 psTime* registered, 5301 const char *skycell_id, 5302 const char *tess_id 5303 ); 5304 5305 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 5306 * 5307 * @return A The number of rows removed or a negative value on error 5308 */ 5309 5310 long long diffRunDelete( 5311 psDB *dbh, ///< Database handle 5312 const psMetadata *where, ///< Row match criteria 5313 unsigned long long limit ///< Maximum number of elements to delete 5314 ); 5315 5316 /** Insert a single diffRunRow object into a table 5317 * 5318 * This function constructs and inserts a single row based on it's parameters. 5319 * 5320 * @return true on success 5321 */ 5322 5323 bool diffRunInsertObject( 5324 psDB *dbh, ///< Database handle 5325 diffRunRow *object ///< diffRunRow object 5326 ); 5327 5328 /** Insert an array of diffRunRow object into a table 5329 * 5330 * This function constructs and inserts multiple rows based on it's parameters. 5331 * 5332 * @return true on success 5333 */ 5334 5335 bool diffRunInsertObjects( 5336 psDB *dbh, ///< Database handle 5337 psArray *objects ///< array of diffRunRow objects 5338 ); 5339 5340 /** Insert data from a binary FITS table diffRunRow into the database 5341 * 5342 * This function expects a psFits object with a FITS table as the first 5343 * extension. The table must have at least one row of data in it, that is of 5344 * the appropriate format (number of columns and their type). All other 5345 * extensions are ignored. 5346 * 5347 * @return true on success 5348 */ 5349 5350 bool diffRunInsertFits( 5351 psDB *dbh, ///< Database handle 5352 const psFits *fits ///< psFits object 5353 ); 5354 5355 /** Selects up to limit from the database and returns them in a binary FITS table 5356 * 5357 * This function assumes an empty psFits object and will create a FITS table 5358 * as the first extension. 5359 * 5360 * See psDBSelectRows() for documentation on the format of where. 5361 * 5362 * @return true on success 5363 */ 5364 5365 bool diffRunSelectRowsFits( 5366 psDB *dbh, ///< Database handle 5367 psFits *fits, ///< psFits object 5368 const psMetadata *where, ///< Row match criteria 5369 unsigned long long limit ///< Maximum number of elements to return 5370 ); 5371 5372 /** Convert a diffRunRow into an equivalent psMetadata 5373 * 5374 * @return A psMetadata pointer or NULL on error 5375 */ 5376 5377 psMetadata *diffRunMetadataFromObject( 5378 const diffRunRow *object ///< fooRow to convert into a psMetadata 5379 ); 5380 5381 /** Convert a psMetadata into an equivalent fooRow 5382 * 5383 * @return A diffRunRow pointer or NULL on error 5384 */ 5385 5386 diffRunRow *diffRunObjectFromMetadata( 5387 psMetadata *md ///< psMetadata to convert into a fooRow 5388 ); 5389 /** Selects up to limit rows from the database and returns as diffRunRow objects in a psArray 5390 * 5391 * See psDBSelectRows() for documentation on the format of where. 5392 * 5393 * @return A psArray pointer or NULL on error 5394 */ 5395 5396 psArray *diffRunSelectRowObjects( 5397 psDB *dbh, ///< Database handle 5398 const psMetadata *where, ///< Row match criteria 5399 unsigned long long limit ///< Maximum number of elements to return 5400 ); 5401 /** Deletes a row from the database coresponding to an diffRun 5402 * 5403 * Note that a 'where' search psMetadata is constructed from each object and 5404 * used to find rows to delete. 5405 * 5406 * @return A The number of rows removed or a negative value on error 5407 */ 5408 5409 bool diffRunDeleteObject( 5410 psDB *dbh, ///< Database handle 5411 const diffRunRow *object ///< Object to delete 5412 ); 5413 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 5414 * 5415 * Note that a 'where' search psMetadata is constructed from each object and 5416 * used to find rows to delete. 5417 * 5418 * @return A The number of rows removed or a negative value on error 5419 */ 5420 5421 long long diffRunDeleteRowObjects( 5422 psDB *dbh, ///< Database handle 5423 const psArray *objects, ///< Array of objects to delete 5424 unsigned long long limit ///< Maximum number of elements to delete 5425 ); 5426 /** Formats and prints an array of diffRunRow objects 5427 * 5428 * When mdcf is set the formated output is in psMetadataConfig 5429 * format, otherwise it is in a simple tabular format. 5430 * 5431 * @return true on success 5432 */ 5433 5434 bool diffRunPrintObjects( 5435 FILE *stream, ///< a stream 5436 psArray *objects, ///< An array of diffRunRow objects 5437 bool mdcf ///< format as mdconfig or simple 5438 ); 5439 /** Formats and prints an diffRunRow object 5440 * 5441 * When mdcf is set the formated output is in psMetadataConfig 5442 * format, otherwise it is in a simple tabular format. 5443 * 5444 * @return true on success 5445 */ 5446 5447 bool diffRunPrintObject( 5448 FILE *stream, ///< a stream 5449 diffRunRow *object, ///< an diffRunRow object 5450 bool mdcf ///< format as mdconfig or simple 5451 ); 5452 /** diffInputSkyfileRow data structure 5453 * 5454 * Structure for representing a single row of diffInputSkyfile table data. 5455 */ 5456 5457 typedef struct { 5458 psS64 diff_id; 5459 psS64 warp_id; 5460 char *skycell_id; 5461 char *tess_id; 5462 char *kind; 5463 bool template; 5464 } diffInputSkyfileRow; 5465 5466 /** Creates a new diffInputSkyfileRow object 5467 * 5468 * @return A new diffInputSkyfileRow object or NULL on failure. 5469 */ 5470 5471 diffInputSkyfileRow *diffInputSkyfileRowAlloc( 5472 psS64 diff_id, 5473 psS64 warp_id, 5474 const char *skycell_id, 5475 const char *tess_id, 5476 const char *kind, 5477 bool template 5478 ); 5479 5480 /** Creates a new diffInputSkyfile table 5481 * 5482 * @return true on success 5483 */ 5484 5485 bool diffInputSkyfileCreateTable( 5486 psDB *dbh ///< Database handle 5487 ); 5488 5489 /** Deletes a diffInputSkyfile table 5490 * 5491 * @return true on success 5492 */ 5493 5494 bool diffInputSkyfileDropTable( 5495 psDB *dbh ///< Database handle 5496 ); 5497 5498 /** Insert a single row into a table 5499 * 5500 * This function constructs and inserts a single row based on it's parameters. 5501 * 5502 * @return true on success 5503 */ 5504 5505 bool diffInputSkyfileInsert( 5506 psDB *dbh, ///< Database handle 5507 psS64 diff_id, 5508 psS64 warp_id, 5509 const char *skycell_id, 5510 const char *tess_id, 5511 const char *kind, 5512 bool template 5513 ); 5514 5515 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 5516 * 5517 * @return A The number of rows removed or a negative value on error 5518 */ 5519 5520 long long diffInputSkyfileDelete( 5521 psDB *dbh, ///< Database handle 5522 const psMetadata *where, ///< Row match criteria 5523 unsigned long long limit ///< Maximum number of elements to delete 5524 ); 5525 5526 /** Insert a single diffInputSkyfileRow object into a table 5527 * 5528 * This function constructs and inserts a single row based on it's parameters. 5529 * 5530 * @return true on success 5531 */ 5532 5533 bool diffInputSkyfileInsertObject( 5534 psDB *dbh, ///< Database handle 5535 diffInputSkyfileRow *object ///< diffInputSkyfileRow object 5536 ); 5537 5538 /** Insert an array of diffInputSkyfileRow object into a table 5539 * 5540 * This function constructs and inserts multiple rows based on it's parameters. 5541 * 5542 * @return true on success 5543 */ 5544 5545 bool diffInputSkyfileInsertObjects( 5546 psDB *dbh, ///< Database handle 5547 psArray *objects ///< array of diffInputSkyfileRow objects 5548 ); 5549 5550 /** Insert data from a binary FITS table diffInputSkyfileRow into the database 5551 * 5552 * This function expects a psFits object with a FITS table as the first 5553 * extension. The table must have at least one row of data in it, that is of 5554 * the appropriate format (number of columns and their type). All other 5555 * extensions are ignored. 5556 * 5557 * @return true on success 5558 */ 5559 5560 bool diffInputSkyfileInsertFits( 5561 psDB *dbh, ///< Database handle 5562 const psFits *fits ///< psFits object 5563 ); 5564 5565 /** Selects up to limit from the database and returns them in a binary FITS table 5566 * 5567 * This function assumes an empty psFits object and will create a FITS table 5568 * as the first extension. 5569 * 5570 * See psDBSelectRows() for documentation on the format of where. 5571 * 5572 * @return true on success 5573 */ 5574 5575 bool diffInputSkyfileSelectRowsFits( 5576 psDB *dbh, ///< Database handle 5577 psFits *fits, ///< psFits object 5578 const psMetadata *where, ///< Row match criteria 5579 unsigned long long limit ///< Maximum number of elements to return 5580 ); 5581 5582 /** Convert a diffInputSkyfileRow into an equivalent psMetadata 5583 * 5584 * @return A psMetadata pointer or NULL on error 5585 */ 5586 5587 psMetadata *diffInputSkyfileMetadataFromObject( 5588 const diffInputSkyfileRow *object ///< fooRow to convert into a psMetadata 5589 ); 5590 5591 /** Convert a psMetadata into an equivalent fooRow 5592 * 5593 * @return A diffInputSkyfileRow pointer or NULL on error 5594 */ 5595 5596 diffInputSkyfileRow *diffInputSkyfileObjectFromMetadata( 5597 psMetadata *md ///< psMetadata to convert into a fooRow 5598 ); 5599 /** Selects up to limit rows from the database and returns as diffInputSkyfileRow objects in a psArray 5600 * 5601 * See psDBSelectRows() for documentation on the format of where. 5602 * 5603 * @return A psArray pointer or NULL on error 5604 */ 5605 5606 psArray *diffInputSkyfileSelectRowObjects( 5607 psDB *dbh, ///< Database handle 5608 const psMetadata *where, ///< Row match criteria 5609 unsigned long long limit ///< Maximum number of elements to return 5610 ); 5611 /** Deletes a row from the database coresponding to an diffInputSkyfile 5612 * 5613 * Note that a 'where' search psMetadata is constructed from each object and 5614 * used to find rows to delete. 5615 * 5616 * @return A The number of rows removed or a negative value on error 5617 */ 5618 5619 bool diffInputSkyfileDeleteObject( 5620 psDB *dbh, ///< Database handle 5621 const diffInputSkyfileRow *object ///< Object to delete 5622 ); 5623 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 5624 * 5625 * Note that a 'where' search psMetadata is constructed from each object and 5626 * used to find rows to delete. 5627 * 5628 * @return A The number of rows removed or a negative value on error 5629 */ 5630 5631 long long diffInputSkyfileDeleteRowObjects( 5632 psDB *dbh, ///< Database handle 5633 const psArray *objects, ///< Array of objects to delete 5634 unsigned long long limit ///< Maximum number of elements to delete 5635 ); 5636 /** Formats and prints an array of diffInputSkyfileRow objects 5637 * 5638 * When mdcf is set the formated output is in psMetadataConfig 5639 * format, otherwise it is in a simple tabular format. 5640 * 5641 * @return true on success 5642 */ 5643 5644 bool diffInputSkyfilePrintObjects( 5645 FILE *stream, ///< a stream 5646 psArray *objects, ///< An array of diffInputSkyfileRow objects 5647 bool mdcf ///< format as mdconfig or simple 5648 ); 5649 /** Formats and prints an diffInputSkyfileRow object 5650 * 5651 * When mdcf is set the formated output is in psMetadataConfig 5652 * format, otherwise it is in a simple tabular format. 5653 * 5654 * @return true on success 5655 */ 5656 5657 bool diffInputSkyfilePrintObject( 5658 FILE *stream, ///< a stream 5659 diffInputSkyfileRow *object, ///< an diffInputSkyfileRow object 5660 bool mdcf ///< format as mdconfig or simple 5661 ); 5662 /** diffSkyfileRow data structure 5663 * 5664 * Structure for representing a single row of diffSkyfile table data. 5665 */ 5666 5667 typedef struct { 5668 psS64 diff_id; 5669 char *uri; 5670 psF64 bg; 5671 psF64 bg_stdev; 5672 } diffSkyfileRow; 5673 5674 /** Creates a new diffSkyfileRow object 5675 * 5676 * @return A new diffSkyfileRow object or NULL on failure. 5677 */ 5678 5679 diffSkyfileRow *diffSkyfileRowAlloc( 5680 psS64 diff_id, 5681 const char *uri, 5682 psF64 bg, 5683 psF64 bg_stdev 5684 ); 5685 5686 /** Creates a new diffSkyfile table 5687 * 5688 * @return true on success 5689 */ 5690 5691 bool diffSkyfileCreateTable( 5692 psDB *dbh ///< Database handle 5693 ); 5694 5695 /** Deletes a diffSkyfile table 5696 * 5697 * @return true on success 5698 */ 5699 5700 bool diffSkyfileDropTable( 5701 psDB *dbh ///< Database handle 5702 ); 5703 5704 /** Insert a single row into a table 5705 * 5706 * This function constructs and inserts a single row based on it's parameters. 5707 * 5708 * @return true on success 5709 */ 5710 5711 bool diffSkyfileInsert( 5712 psDB *dbh, ///< Database handle 5713 psS64 diff_id, 5714 const char *uri, 5715 psF64 bg, 5716 psF64 bg_stdev 5717 ); 5718 5719 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 5720 * 5721 * @return A The number of rows removed or a negative value on error 5722 */ 5723 5724 long long diffSkyfileDelete( 5725 psDB *dbh, ///< Database handle 5726 const psMetadata *where, ///< Row match criteria 5727 unsigned long long limit ///< Maximum number of elements to delete 5728 ); 5729 5730 /** Insert a single diffSkyfileRow object into a table 5731 * 5732 * This function constructs and inserts a single row based on it's parameters. 5733 * 5734 * @return true on success 5735 */ 5736 5737 bool diffSkyfileInsertObject( 5738 psDB *dbh, ///< Database handle 5739 diffSkyfileRow *object ///< diffSkyfileRow object 5740 ); 5741 5742 /** Insert an array of diffSkyfileRow object into a table 5743 * 5744 * This function constructs and inserts multiple rows based on it's parameters. 5745 * 5746 * @return true on success 5747 */ 5748 5749 bool diffSkyfileInsertObjects( 5750 psDB *dbh, ///< Database handle 5751 psArray *objects ///< array of diffSkyfileRow objects 5752 ); 5753 5754 /** Insert data from a binary FITS table diffSkyfileRow into the database 5755 * 5756 * This function expects a psFits object with a FITS table as the first 5757 * extension. The table must have at least one row of data in it, that is of 5758 * the appropriate format (number of columns and their type). All other 5759 * extensions are ignored. 5760 * 5761 * @return true on success 5762 */ 5763 5764 bool diffSkyfileInsertFits( 5765 psDB *dbh, ///< Database handle 5766 const psFits *fits ///< psFits object 5767 ); 5768 5769 /** Selects up to limit from the database and returns them in a binary FITS table 5770 * 5771 * This function assumes an empty psFits object and will create a FITS table 5772 * as the first extension. 5773 * 5774 * See psDBSelectRows() for documentation on the format of where. 5775 * 5776 * @return true on success 5777 */ 5778 5779 bool diffSkyfileSelectRowsFits( 5780 psDB *dbh, ///< Database handle 5781 psFits *fits, ///< psFits object 5782 const psMetadata *where, ///< Row match criteria 5783 unsigned long long limit ///< Maximum number of elements to return 5784 ); 5785 5786 /** Convert a diffSkyfileRow into an equivalent psMetadata 5787 * 5788 * @return A psMetadata pointer or NULL on error 5789 */ 5790 5791 psMetadata *diffSkyfileMetadataFromObject( 5792 const diffSkyfileRow *object ///< fooRow to convert into a psMetadata 5793 ); 5794 5795 /** Convert a psMetadata into an equivalent fooRow 5796 * 5797 * @return A diffSkyfileRow pointer or NULL on error 5798 */ 5799 5800 diffSkyfileRow *diffSkyfileObjectFromMetadata( 5801 psMetadata *md ///< psMetadata to convert into a fooRow 5802 ); 5803 /** Selects up to limit rows from the database and returns as diffSkyfileRow objects in a psArray 5804 * 5805 * See psDBSelectRows() for documentation on the format of where. 5806 * 5807 * @return A psArray pointer or NULL on error 5808 */ 5809 5810 psArray *diffSkyfileSelectRowObjects( 5811 psDB *dbh, ///< Database handle 5812 const psMetadata *where, ///< Row match criteria 5813 unsigned long long limit ///< Maximum number of elements to return 5814 ); 5815 /** Deletes a row from the database coresponding to an diffSkyfile 5816 * 5817 * Note that a 'where' search psMetadata is constructed from each object and 5818 * used to find rows to delete. 5819 * 5820 * @return A The number of rows removed or a negative value on error 5821 */ 5822 5823 bool diffSkyfileDeleteObject( 5824 psDB *dbh, ///< Database handle 5825 const diffSkyfileRow *object ///< Object to delete 5826 ); 5827 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 5828 * 5829 * Note that a 'where' search psMetadata is constructed from each object and 5830 * used to find rows to delete. 5831 * 5832 * @return A The number of rows removed or a negative value on error 5833 */ 5834 5835 long long diffSkyfileDeleteRowObjects( 5836 psDB *dbh, ///< Database handle 5837 const psArray *objects, ///< Array of objects to delete 5838 unsigned long long limit ///< Maximum number of elements to delete 5839 ); 5840 /** Formats and prints an array of diffSkyfileRow objects 5841 * 5842 * When mdcf is set the formated output is in psMetadataConfig 5843 * format, otherwise it is in a simple tabular format. 5844 * 5845 * @return true on success 5846 */ 5847 5848 bool diffSkyfilePrintObjects( 5849 FILE *stream, ///< a stream 5850 psArray *objects, ///< An array of diffSkyfileRow objects 5851 bool mdcf ///< format as mdconfig or simple 5852 ); 5853 /** Formats and prints an diffSkyfileRow object 5854 * 5855 * When mdcf is set the formated output is in psMetadataConfig 5856 * format, otherwise it is in a simple tabular format. 5857 * 5858 * @return true on success 5859 */ 5860 5861 bool diffSkyfilePrintObject( 5862 FILE *stream, ///< a stream 5863 diffSkyfileRow *object, ///< an diffSkyfileRow object 5864 bool mdcf ///< format as mdconfig or simple 5865 ); 5866 /** stackRunRow data structure 5867 * 5868 * Structure for representing a single row of stackRun table data. 5869 */ 5870 5871 typedef struct { 5872 psS64 stack_id; 5873 char *state; 5874 char *workdir; 5875 char *dvodb; 5876 psTime* registered; 5877 char *skycell_id; 5878 char *tess_id; 5879 } stackRunRow; 5880 5881 /** Creates a new stackRunRow object 5882 * 5883 * @return A new stackRunRow object or NULL on failure. 5884 */ 5885 5886 stackRunRow *stackRunRowAlloc( 5887 psS64 stack_id, 5888 const char *state, 5889 const char *workdir, 5890 const char *dvodb, 5891 psTime* registered, 5892 const char *skycell_id, 5893 const char *tess_id 5894 ); 5895 5896 /** Creates a new stackRun table 5897 * 5898 * @return true on success 5899 */ 5900 5901 bool stackRunCreateTable( 5902 psDB *dbh ///< Database handle 5903 ); 5904 5905 /** Deletes a stackRun table 5906 * 5907 * @return true on success 5908 */ 5909 5910 bool stackRunDropTable( 5911 psDB *dbh ///< Database handle 5912 ); 5913 5914 /** Insert a single row into a table 5915 * 5916 * This function constructs and inserts a single row based on it's parameters. 5917 * 5918 * @return true on success 5919 */ 5920 5921 bool stackRunInsert( 5922 psDB *dbh, ///< Database handle 5923 psS64 stack_id, 5924 const char *state, 5925 const char *workdir, 5926 const char *dvodb, 5927 psTime* registered, 5928 const char *skycell_id, 5929 const char *tess_id 5930 ); 5931 5932 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 5933 * 5934 * @return A The number of rows removed or a negative value on error 5935 */ 5936 5937 long long stackRunDelete( 5938 psDB *dbh, ///< Database handle 5939 const psMetadata *where, ///< Row match criteria 5940 unsigned long long limit ///< Maximum number of elements to delete 5941 ); 5942 5943 /** Insert a single stackRunRow object into a table 5944 * 5945 * This function constructs and inserts a single row based on it's parameters. 5946 * 5947 * @return true on success 5948 */ 5949 5950 bool stackRunInsertObject( 5951 psDB *dbh, ///< Database handle 5952 stackRunRow *object ///< stackRunRow object 5953 ); 5954 5955 /** Insert an array of stackRunRow object into a table 5956 * 5957 * This function constructs and inserts multiple rows based on it's parameters. 5958 * 5959 * @return true on success 5960 */ 5961 5962 bool stackRunInsertObjects( 5963 psDB *dbh, ///< Database handle 5964 psArray *objects ///< array of stackRunRow objects 5965 ); 5966 5967 /** Insert data from a binary FITS table stackRunRow into the database 5968 * 5969 * This function expects a psFits object with a FITS table as the first 5970 * extension. The table must have at least one row of data in it, that is of 5971 * the appropriate format (number of columns and their type). All other 5972 * extensions are ignored. 5973 * 5974 * @return true on success 5975 */ 5976 5977 bool stackRunInsertFits( 5978 psDB *dbh, ///< Database handle 5979 const psFits *fits ///< psFits object 5980 ); 5981 5982 /** Selects up to limit from the database and returns them in a binary FITS table 5983 * 5984 * This function assumes an empty psFits object and will create a FITS table 5985 * as the first extension. 5986 * 5987 * See psDBSelectRows() for documentation on the format of where. 5988 * 5989 * @return true on success 5990 */ 5991 5992 bool stackRunSelectRowsFits( 5993 psDB *dbh, ///< Database handle 5994 psFits *fits, ///< psFits object 5995 const psMetadata *where, ///< Row match criteria 5996 unsigned long long limit ///< Maximum number of elements to return 5997 ); 5998 5999 /** Convert a stackRunRow into an equivalent psMetadata 6000 * 6001 * @return A psMetadata pointer or NULL on error 6002 */ 6003 6004 psMetadata *stackRunMetadataFromObject( 6005 const stackRunRow *object ///< fooRow to convert into a psMetadata 6006 ); 6007 6008 /** Convert a psMetadata into an equivalent fooRow 6009 * 6010 * @return A stackRunRow pointer or NULL on error 6011 */ 6012 6013 stackRunRow *stackRunObjectFromMetadata( 6014 psMetadata *md ///< psMetadata to convert into a fooRow 6015 ); 6016 /** Selects up to limit rows from the database and returns as stackRunRow objects in a psArray 6017 * 6018 * See psDBSelectRows() for documentation on the format of where. 6019 * 6020 * @return A psArray pointer or NULL on error 6021 */ 6022 6023 psArray *stackRunSelectRowObjects( 6024 psDB *dbh, ///< Database handle 6025 const psMetadata *where, ///< Row match criteria 6026 unsigned long long limit ///< Maximum number of elements to return 6027 ); 6028 /** Deletes a row from the database coresponding to an stackRun 6029 * 6030 * Note that a 'where' search psMetadata is constructed from each object and 6031 * used to find rows to delete. 6032 * 6033 * @return A The number of rows removed or a negative value on error 6034 */ 6035 6036 bool stackRunDeleteObject( 6037 psDB *dbh, ///< Database handle 6038 const stackRunRow *object ///< Object to delete 6039 ); 6040 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 6041 * 6042 * Note that a 'where' search psMetadata is constructed from each object and 6043 * used to find rows to delete. 6044 * 6045 * @return A The number of rows removed or a negative value on error 6046 */ 6047 6048 long long stackRunDeleteRowObjects( 6049 psDB *dbh, ///< Database handle 6050 const psArray *objects, ///< Array of objects to delete 6051 unsigned long long limit ///< Maximum number of elements to delete 6052 ); 6053 /** Formats and prints an array of stackRunRow objects 6054 * 6055 * When mdcf is set the formated output is in psMetadataConfig 6056 * format, otherwise it is in a simple tabular format. 6057 * 6058 * @return true on success 6059 */ 6060 6061 bool stackRunPrintObjects( 6062 FILE *stream, ///< a stream 6063 psArray *objects, ///< An array of stackRunRow objects 6064 bool mdcf ///< format as mdconfig or simple 6065 ); 6066 /** Formats and prints an stackRunRow object 6067 * 6068 * When mdcf is set the formated output is in psMetadataConfig 6069 * format, otherwise it is in a simple tabular format. 6070 * 6071 * @return true on success 6072 */ 6073 6074 bool stackRunPrintObject( 6075 FILE *stream, ///< a stream 6076 stackRunRow *object, ///< an stackRunRow object 6077 bool mdcf ///< format as mdconfig or simple 6078 ); 6079 /** stackInputSkyfileRow data structure 6080 * 6081 * Structure for representing a single row of stackInputSkyfile table data. 6082 */ 6083 6084 typedef struct { 6085 psS64 stack_id; 6086 psS64 warp_id; 6087 } stackInputSkyfileRow; 6088 6089 /** Creates a new stackInputSkyfileRow object 6090 * 6091 * @return A new stackInputSkyfileRow object or NULL on failure. 6092 */ 6093 6094 stackInputSkyfileRow *stackInputSkyfileRowAlloc( 6095 psS64 stack_id, 6096 psS64 warp_id 6097 ); 6098 6099 /** Creates a new stackInputSkyfile table 6100 * 6101 * @return true on success 6102 */ 6103 6104 bool stackInputSkyfileCreateTable( 6105 psDB *dbh ///< Database handle 6106 ); 6107 6108 /** Deletes a stackInputSkyfile table 6109 * 6110 * @return true on success 6111 */ 6112 6113 bool stackInputSkyfileDropTable( 6114 psDB *dbh ///< Database handle 6115 ); 6116 6117 /** Insert a single row into a table 6118 * 6119 * This function constructs and inserts a single row based on it's parameters. 6120 * 6121 * @return true on success 6122 */ 6123 6124 bool stackInputSkyfileInsert( 6125 psDB *dbh, ///< Database handle 6126 psS64 stack_id, 6127 psS64 warp_id 6128 ); 6129 6130 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 6131 * 6132 * @return A The number of rows removed or a negative value on error 6133 */ 6134 6135 long long stackInputSkyfileDelete( 6136 psDB *dbh, ///< Database handle 6137 const psMetadata *where, ///< Row match criteria 6138 unsigned long long limit ///< Maximum number of elements to delete 6139 ); 6140 6141 /** Insert a single stackInputSkyfileRow object into a table 6142 * 6143 * This function constructs and inserts a single row based on it's parameters. 6144 * 6145 * @return true on success 6146 */ 6147 6148 bool stackInputSkyfileInsertObject( 6149 psDB *dbh, ///< Database handle 6150 stackInputSkyfileRow *object ///< stackInputSkyfileRow object 6151 ); 6152 6153 /** Insert an array of stackInputSkyfileRow object into a table 6154 * 6155 * This function constructs and inserts multiple rows based on it's parameters. 6156 * 6157 * @return true on success 6158 */ 6159 6160 bool stackInputSkyfileInsertObjects( 6161 psDB *dbh, ///< Database handle 6162 psArray *objects ///< array of stackInputSkyfileRow objects 6163 ); 6164 6165 /** Insert data from a binary FITS table stackInputSkyfileRow into the database 6166 * 6167 * This function expects a psFits object with a FITS table as the first 6168 * extension. The table must have at least one row of data in it, that is of 6169 * the appropriate format (number of columns and their type). All other 6170 * extensions are ignored. 6171 * 6172 * @return true on success 6173 */ 6174 6175 bool stackInputSkyfileInsertFits( 6176 psDB *dbh, ///< Database handle 6177 const psFits *fits ///< psFits object 6178 ); 6179 6180 /** Selects up to limit from the database and returns them in a binary FITS table 6181 * 6182 * This function assumes an empty psFits object and will create a FITS table 6183 * as the first extension. 6184 * 6185 * See psDBSelectRows() for documentation on the format of where. 6186 * 6187 * @return true on success 6188 */ 6189 6190 bool stackInputSkyfileSelectRowsFits( 6191 psDB *dbh, ///< Database handle 6192 psFits *fits, ///< psFits object 6193 const psMetadata *where, ///< Row match criteria 6194 unsigned long long limit ///< Maximum number of elements to return 6195 ); 6196 6197 /** Convert a stackInputSkyfileRow into an equivalent psMetadata 6198 * 6199 * @return A psMetadata pointer or NULL on error 6200 */ 6201 6202 psMetadata *stackInputSkyfileMetadataFromObject( 6203 const stackInputSkyfileRow *object ///< fooRow to convert into a psMetadata 6204 ); 6205 6206 /** Convert a psMetadata into an equivalent fooRow 6207 * 6208 * @return A stackInputSkyfileRow pointer or NULL on error 6209 */ 6210 6211 stackInputSkyfileRow *stackInputSkyfileObjectFromMetadata( 6212 psMetadata *md ///< psMetadata to convert into a fooRow 6213 ); 6214 /** Selects up to limit rows from the database and returns as stackInputSkyfileRow objects in a psArray 6215 * 6216 * See psDBSelectRows() for documentation on the format of where. 6217 * 6218 * @return A psArray pointer or NULL on error 6219 */ 6220 6221 psArray *stackInputSkyfileSelectRowObjects( 6222 psDB *dbh, ///< Database handle 6223 const psMetadata *where, ///< Row match criteria 6224 unsigned long long limit ///< Maximum number of elements to return 6225 ); 6226 /** Deletes a row from the database coresponding to an stackInputSkyfile 6227 * 6228 * Note that a 'where' search psMetadata is constructed from each object and 6229 * used to find rows to delete. 6230 * 6231 * @return A The number of rows removed or a negative value on error 6232 */ 6233 6234 bool stackInputSkyfileDeleteObject( 6235 psDB *dbh, ///< Database handle 6236 const stackInputSkyfileRow *object ///< Object to delete 6237 ); 6238 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 6239 * 6240 * Note that a 'where' search psMetadata is constructed from each object and 6241 * used to find rows to delete. 6242 * 6243 * @return A The number of rows removed or a negative value on error 6244 */ 6245 6246 long long stackInputSkyfileDeleteRowObjects( 6247 psDB *dbh, ///< Database handle 6248 const psArray *objects, ///< Array of objects to delete 6249 unsigned long long limit ///< Maximum number of elements to delete 6250 ); 6251 /** Formats and prints an array of stackInputSkyfileRow objects 6252 * 6253 * When mdcf is set the formated output is in psMetadataConfig 6254 * format, otherwise it is in a simple tabular format. 6255 * 6256 * @return true on success 6257 */ 6258 6259 bool stackInputSkyfilePrintObjects( 6260 FILE *stream, ///< a stream 6261 psArray *objects, ///< An array of stackInputSkyfileRow objects 6262 bool mdcf ///< format as mdconfig or simple 6263 ); 6264 /** Formats and prints an stackInputSkyfileRow object 6265 * 6266 * When mdcf is set the formated output is in psMetadataConfig 6267 * format, otherwise it is in a simple tabular format. 6268 * 6269 * @return true on success 6270 */ 6271 6272 bool stackInputSkyfilePrintObject( 6273 FILE *stream, ///< a stream 6274 stackInputSkyfileRow *object, ///< an stackInputSkyfileRow object 6275 bool mdcf ///< format as mdconfig or simple 6276 ); 6277 /** stackSumSkyfileRow data structure 6278 * 6279 * Structure for representing a single row of stackSumSkyfile table data. 6280 */ 6281 6282 typedef struct { 6283 psS64 stack_id; 6284 char *uri; 6285 psF64 bg; 6286 psF64 bg_stdev; 6287 } stackSumSkyfileRow; 6288 6289 /** Creates a new stackSumSkyfileRow object 6290 * 6291 * @return A new stackSumSkyfileRow object or NULL on failure. 6292 */ 6293 6294 stackSumSkyfileRow *stackSumSkyfileRowAlloc( 6295 psS64 stack_id, 6296 const char *uri, 6297 psF64 bg, 6298 psF64 bg_stdev 6299 ); 6300 6301 /** Creates a new stackSumSkyfile table 6302 * 6303 * @return true on success 6304 */ 6305 6306 bool stackSumSkyfileCreateTable( 6307 psDB *dbh ///< Database handle 6308 ); 6309 6310 /** Deletes a stackSumSkyfile table 6311 * 6312 * @return true on success 6313 */ 6314 6315 bool stackSumSkyfileDropTable( 6316 psDB *dbh ///< Database handle 6317 ); 6318 6319 /** Insert a single row into a table 6320 * 6321 * This function constructs and inserts a single row based on it's parameters. 6322 * 6323 * @return true on success 6324 */ 6325 6326 bool stackSumSkyfileInsert( 6327 psDB *dbh, ///< Database handle 6328 psS64 stack_id, 6329 const char *uri, 6330 psF64 bg, 6331 psF64 bg_stdev 6332 ); 6333 6334 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 6335 * 6336 * @return A The number of rows removed or a negative value on error 6337 */ 6338 6339 long long stackSumSkyfileDelete( 6340 psDB *dbh, ///< Database handle 6341 const psMetadata *where, ///< Row match criteria 6342 unsigned long long limit ///< Maximum number of elements to delete 6343 ); 6344 6345 /** Insert a single stackSumSkyfileRow object into a table 6346 * 6347 * This function constructs and inserts a single row based on it's parameters. 6348 * 6349 * @return true on success 6350 */ 6351 6352 bool stackSumSkyfileInsertObject( 6353 psDB *dbh, ///< Database handle 6354 stackSumSkyfileRow *object ///< stackSumSkyfileRow object 6355 ); 6356 6357 /** Insert an array of stackSumSkyfileRow object into a table 6358 * 6359 * This function constructs and inserts multiple rows based on it's parameters. 6360 * 6361 * @return true on success 6362 */ 6363 6364 bool stackSumSkyfileInsertObjects( 6365 psDB *dbh, ///< Database handle 6366 psArray *objects ///< array of stackSumSkyfileRow objects 6367 ); 6368 6369 /** Insert data from a binary FITS table stackSumSkyfileRow into the database 6370 * 6371 * This function expects a psFits object with a FITS table as the first 6372 * extension. The table must have at least one row of data in it, that is of 6373 * the appropriate format (number of columns and their type). All other 6374 * extensions are ignored. 6375 * 6376 * @return true on success 6377 */ 6378 6379 bool stackSumSkyfileInsertFits( 6380 psDB *dbh, ///< Database handle 6381 const psFits *fits ///< psFits object 6382 ); 6383 6384 /** Selects up to limit from the database and returns them in a binary FITS table 6385 * 6386 * This function assumes an empty psFits object and will create a FITS table 6387 * as the first extension. 6388 * 6389 * See psDBSelectRows() for documentation on the format of where. 6390 * 6391 * @return true on success 6392 */ 6393 6394 bool stackSumSkyfileSelectRowsFits( 6395 psDB *dbh, ///< Database handle 6396 psFits *fits, ///< psFits object 6397 const psMetadata *where, ///< Row match criteria 6398 unsigned long long limit ///< Maximum number of elements to return 6399 ); 6400 6401 /** Convert a stackSumSkyfileRow into an equivalent psMetadata 6402 * 6403 * @return A psMetadata pointer or NULL on error 6404 */ 6405 6406 psMetadata *stackSumSkyfileMetadataFromObject( 6407 const stackSumSkyfileRow *object ///< fooRow to convert into a psMetadata 6408 ); 6409 6410 /** Convert a psMetadata into an equivalent fooRow 6411 * 6412 * @return A stackSumSkyfileRow pointer or NULL on error 6413 */ 6414 6415 stackSumSkyfileRow *stackSumSkyfileObjectFromMetadata( 6416 psMetadata *md ///< psMetadata to convert into a fooRow 6417 ); 6418 /** Selects up to limit rows from the database and returns as stackSumSkyfileRow objects in a psArray 6419 * 6420 * See psDBSelectRows() for documentation on the format of where. 6421 * 6422 * @return A psArray pointer or NULL on error 6423 */ 6424 6425 psArray *stackSumSkyfileSelectRowObjects( 6426 psDB *dbh, ///< Database handle 6427 const psMetadata *where, ///< Row match criteria 6428 unsigned long long limit ///< Maximum number of elements to return 6429 ); 6430 /** Deletes a row from the database coresponding to an stackSumSkyfile 6431 * 6432 * Note that a 'where' search psMetadata is constructed from each object and 6433 * used to find rows to delete. 6434 * 6435 * @return A The number of rows removed or a negative value on error 6436 */ 6437 6438 bool stackSumSkyfileDeleteObject( 6439 psDB *dbh, ///< Database handle 6440 const stackSumSkyfileRow *object ///< Object to delete 6441 ); 6442 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 6443 * 6444 * Note that a 'where' search psMetadata is constructed from each object and 6445 * used to find rows to delete. 6446 * 6447 * @return A The number of rows removed or a negative value on error 6448 */ 6449 6450 long long stackSumSkyfileDeleteRowObjects( 6451 psDB *dbh, ///< Database handle 6452 const psArray *objects, ///< Array of objects to delete 6453 unsigned long long limit ///< Maximum number of elements to delete 6454 ); 6455 /** Formats and prints an array of stackSumSkyfileRow objects 6456 * 6457 * When mdcf is set the formated output is in psMetadataConfig 6458 * format, otherwise it is in a simple tabular format. 6459 * 6460 * @return true on success 6461 */ 6462 6463 bool stackSumSkyfilePrintObjects( 6464 FILE *stream, ///< a stream 6465 psArray *objects, ///< An array of stackSumSkyfileRow objects 6466 bool mdcf ///< format as mdconfig or simple 6467 ); 6468 /** Formats and prints an stackSumSkyfileRow object 6469 * 6470 * When mdcf is set the formated output is in psMetadataConfig 6471 * format, otherwise it is in a simple tabular format. 6472 * 6473 * @return true on success 6474 */ 6475 6476 bool stackSumSkyfilePrintObject( 6477 FILE *stream, ///< a stream 6478 stackSumSkyfileRow *object, ///< an stackSumSkyfileRow object 4406 6479 bool mdcf ///< format as mdconfig or simple 4407 6480 ); … … 6845 8918 bool mdcf ///< format as mdconfig or simple 6846 8919 ); 6847 /** warpRunRow data structure6848 *6849 * Structure for representing a single row of warpRun table data.6850 */6851 6852 typedef struct {6853 psS64 warp_id;6854 char *mode;6855 char *state;6856 char *workdir;6857 char *dvodb;6858 psTime* registered;6859 } warpRunRow;6860 6861 /** Creates a new warpRunRow object6862 *6863 * @return A new warpRunRow object or NULL on failure.6864 */6865 6866 warpRunRow *warpRunRowAlloc(6867 psS64 warp_id,6868 const char *mode,6869 const char *state,6870 const char *workdir,6871 const char *dvodb,6872 psTime* registered6873 );6874 6875 /** Creates a new warpRun table6876 *6877 * @return true on success6878 */6879 6880 bool warpRunCreateTable(6881 psDB *dbh ///< Database handle6882 );6883 6884 /** Deletes a warpRun table6885 *6886 * @return true on success6887 */6888 6889 bool warpRunDropTable(6890 psDB *dbh ///< Database handle6891 );6892 6893 /** Insert a single row into a table6894 *6895 * This function constructs and inserts a single row based on it's parameters.6896 *6897 * @return true on success6898 */6899 6900 bool warpRunInsert(6901 psDB *dbh, ///< Database handle6902 psS64 warp_id,6903 const char *mode,6904 const char *state,6905 const char *workdir,6906 const char *dvodb,6907 psTime* registered6908 );6909 6910 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.6911 *6912 * @return A The number of rows removed or a negative value on error6913 */6914 6915 long long warpRunDelete(6916 psDB *dbh, ///< Database handle6917 const psMetadata *where, ///< Row match criteria6918 unsigned long long limit ///< Maximum number of elements to delete6919 );6920 6921 /** Insert a single warpRunRow object into a table6922 *6923 * This function constructs and inserts a single row based on it's parameters.6924 *6925 * @return true on success6926 */6927 6928 bool warpRunInsertObject(6929 psDB *dbh, ///< Database handle6930 warpRunRow *object ///< warpRunRow object6931 );6932 6933 /** Insert an array of warpRunRow object into a table6934 *6935 * This function constructs and inserts multiple rows based on it's parameters.6936 *6937 * @return true on success6938 */6939 6940 bool warpRunInsertObjects(6941 psDB *dbh, ///< Database handle6942 psArray *objects ///< array of warpRunRow objects6943 );6944 6945 /** Insert data from a binary FITS table warpRunRow into the database6946 *6947 * This function expects a psFits object with a FITS table as the first6948 * extension. The table must have at least one row of data in it, that is of6949 * the appropriate format (number of columns and their type). All other6950 * extensions are ignored.6951 *6952 * @return true on success6953 */6954 6955 bool warpRunInsertFits(6956 psDB *dbh, ///< Database handle6957 const psFits *fits ///< psFits object6958 );6959 6960 /** Selects up to limit from the database and returns them in a binary FITS table6961 *6962 * This function assumes an empty psFits object and will create a FITS table6963 * as the first extension.6964 *6965 * See psDBSelectRows() for documentation on the format of where.6966 *6967 * @return true on success6968 */6969 6970 bool warpRunSelectRowsFits(6971 psDB *dbh, ///< Database handle6972 psFits *fits, ///< psFits object6973 const psMetadata *where, ///< Row match criteria6974 unsigned long long limit ///< Maximum number of elements to return6975 );6976 6977 /** Convert a warpRunRow into an equivalent psMetadata6978 *6979 * @return A psMetadata pointer or NULL on error6980 */6981 6982 psMetadata *warpRunMetadataFromObject(6983 const warpRunRow *object ///< fooRow to convert into a psMetadata6984 );6985 6986 /** Convert a psMetadata into an equivalent fooRow6987 *6988 * @return A warpRunRow pointer or NULL on error6989 */6990 6991 warpRunRow *warpRunObjectFromMetadata(6992 psMetadata *md ///< psMetadata to convert into a fooRow6993 );6994 /** Selects up to limit rows from the database and returns as warpRunRow objects in a psArray6995 *6996 * See psDBSelectRows() for documentation on the format of where.6997 *6998 * @return A psArray pointer or NULL on error6999 */7000 7001 psArray *warpRunSelectRowObjects(7002 psDB *dbh, ///< Database handle7003 const psMetadata *where, ///< Row match criteria7004 unsigned long long limit ///< Maximum number of elements to return7005 );7006 /** Deletes a row from the database coresponding to an warpRun7007 *7008 * Note that a 'where' search psMetadata is constructed from each object and7009 * used to find rows to delete.7010 *7011 * @return A The number of rows removed or a negative value on error7012 */7013 7014 bool warpRunDeleteObject(7015 psDB *dbh, ///< Database handle7016 const warpRunRow *object ///< Object to delete7017 );7018 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.7019 *7020 * Note that a 'where' search psMetadata is constructed from each object and7021 * used to find rows to delete.7022 *7023 * @return A The number of rows removed or a negative value on error7024 */7025 7026 long long warpRunDeleteRowObjects(7027 psDB *dbh, ///< Database handle7028 const psArray *objects, ///< Array of objects to delete7029 unsigned long long limit ///< Maximum number of elements to delete7030 );7031 /** Formats and prints an array of warpRunRow objects7032 *7033 * When mdcf is set the formated output is in psMetadataConfig7034 * format, otherwise it is in a simple tabular format.7035 *7036 * @return true on success7037 */7038 7039 bool warpRunPrintObjects(7040 FILE *stream, ///< a stream7041 psArray *objects, ///< An array of warpRunRow objects7042 bool mdcf ///< format as mdconfig or simple7043 );7044 /** Formats and prints an warpRunRow object7045 *7046 * When mdcf is set the formated output is in psMetadataConfig7047 * format, otherwise it is in a simple tabular format.7048 *7049 * @return true on success7050 */7051 7052 bool warpRunPrintObject(7053 FILE *stream, ///< a stream7054 warpRunRow *object, ///< an warpRunRow object7055 bool mdcf ///< format as mdconfig or simple7056 );7057 /** warpInputExpRow data structure7058 *7059 * Structure for representing a single row of warpInputExp table data.7060 */7061 7062 typedef struct {7063 psS64 warp_id;7064 psS64 cam_id;7065 bool magiced;7066 } warpInputExpRow;7067 7068 /** Creates a new warpInputExpRow object7069 *7070 * @return A new warpInputExpRow object or NULL on failure.7071 */7072 7073 warpInputExpRow *warpInputExpRowAlloc(7074 psS64 warp_id,7075 psS64 cam_id,7076 bool magiced7077 );7078 7079 /** Creates a new warpInputExp table7080 *7081 * @return true on success7082 */7083 7084 bool warpInputExpCreateTable(7085 psDB *dbh ///< Database handle7086 );7087 7088 /** Deletes a warpInputExp table7089 *7090 * @return true on success7091 */7092 7093 bool warpInputExpDropTable(7094 psDB *dbh ///< Database handle7095 );7096 7097 /** Insert a single row into a table7098 *7099 * This function constructs and inserts a single row based on it's parameters.7100 *7101 * @return true on success7102 */7103 7104 bool warpInputExpInsert(7105 psDB *dbh, ///< Database handle7106 psS64 warp_id,7107 psS64 cam_id,7108 bool magiced7109 );7110 7111 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.7112 *7113 * @return A The number of rows removed or a negative value on error7114 */7115 7116 long long warpInputExpDelete(7117 psDB *dbh, ///< Database handle7118 const psMetadata *where, ///< Row match criteria7119 unsigned long long limit ///< Maximum number of elements to delete7120 );7121 7122 /** Insert a single warpInputExpRow object into a table7123 *7124 * This function constructs and inserts a single row based on it's parameters.7125 *7126 * @return true on success7127 */7128 7129 bool warpInputExpInsertObject(7130 psDB *dbh, ///< Database handle7131 warpInputExpRow *object ///< warpInputExpRow object7132 );7133 7134 /** Insert an array of warpInputExpRow object into a table7135 *7136 * This function constructs and inserts multiple rows based on it's parameters.7137 *7138 * @return true on success7139 */7140 7141 bool warpInputExpInsertObjects(7142 psDB *dbh, ///< Database handle7143 psArray *objects ///< array of warpInputExpRow objects7144 );7145 7146 /** Insert data from a binary FITS table warpInputExpRow into the database7147 *7148 * This function expects a psFits object with a FITS table as the first7149 * extension. The table must have at least one row of data in it, that is of7150 * the appropriate format (number of columns and their type). All other7151 * extensions are ignored.7152 *7153 * @return true on success7154 */7155 7156 bool warpInputExpInsertFits(7157 psDB *dbh, ///< Database handle7158 const psFits *fits ///< psFits object7159 );7160 7161 /** Selects up to limit from the database and returns them in a binary FITS table7162 *7163 * This function assumes an empty psFits object and will create a FITS table7164 * as the first extension.7165 *7166 * See psDBSelectRows() for documentation on the format of where.7167 *7168 * @return true on success7169 */7170 7171 bool warpInputExpSelectRowsFits(7172 psDB *dbh, ///< Database handle7173 psFits *fits, ///< psFits object7174 const psMetadata *where, ///< Row match criteria7175 unsigned long long limit ///< Maximum number of elements to return7176 );7177 7178 /** Convert a warpInputExpRow into an equivalent psMetadata7179 *7180 * @return A psMetadata pointer or NULL on error7181 */7182 7183 psMetadata *warpInputExpMetadataFromObject(7184 const warpInputExpRow *object ///< fooRow to convert into a psMetadata7185 );7186 7187 /** Convert a psMetadata into an equivalent fooRow7188 *7189 * @return A warpInputExpRow pointer or NULL on error7190 */7191 7192 warpInputExpRow *warpInputExpObjectFromMetadata(7193 psMetadata *md ///< psMetadata to convert into a fooRow7194 );7195 /** Selects up to limit rows from the database and returns as warpInputExpRow objects in a psArray7196 *7197 * See psDBSelectRows() for documentation on the format of where.7198 *7199 * @return A psArray pointer or NULL on error7200 */7201 7202 psArray *warpInputExpSelectRowObjects(7203 psDB *dbh, ///< Database handle7204 const psMetadata *where, ///< Row match criteria7205 unsigned long long limit ///< Maximum number of elements to return7206 );7207 /** Deletes a row from the database coresponding to an warpInputExp7208 *7209 * Note that a 'where' search psMetadata is constructed from each object and7210 * used to find rows to delete.7211 *7212 * @return A The number of rows removed or a negative value on error7213 */7214 7215 bool warpInputExpDeleteObject(7216 psDB *dbh, ///< Database handle7217 const warpInputExpRow *object ///< Object to delete7218 );7219 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.7220 *7221 * Note that a 'where' search psMetadata is constructed from each object and7222 * used to find rows to delete.7223 *7224 * @return A The number of rows removed or a negative value on error7225 */7226 7227 long long warpInputExpDeleteRowObjects(7228 psDB *dbh, ///< Database handle7229 const psArray *objects, ///< Array of objects to delete7230 unsigned long long limit ///< Maximum number of elements to delete7231 );7232 /** Formats and prints an array of warpInputExpRow objects7233 *7234 * When mdcf is set the formated output is in psMetadataConfig7235 * format, otherwise it is in a simple tabular format.7236 *7237 * @return true on success7238 */7239 7240 bool warpInputExpPrintObjects(7241 FILE *stream, ///< a stream7242 psArray *objects, ///< An array of warpInputExpRow objects7243 bool mdcf ///< format as mdconfig or simple7244 );7245 /** Formats and prints an warpInputExpRow object7246 *7247 * When mdcf is set the formated output is in psMetadataConfig7248 * format, otherwise it is in a simple tabular format.7249 *7250 * @return true on success7251 */7252 7253 bool warpInputExpPrintObject(7254 FILE *stream, ///< a stream7255 warpInputExpRow *object, ///< an warpInputExpRow object7256 bool mdcf ///< format as mdconfig or simple7257 );7258 /** warpSkyCellMapRow data structure7259 *7260 * Structure for representing a single row of warpSkyCellMap table data.7261 */7262 7263 typedef struct {7264 psS64 warp_id;7265 char *skycell_id;7266 char *tess_id;7267 psS64 cam_id;7268 char *class_id;7269 psS16 fault;7270 } warpSkyCellMapRow;7271 7272 /** Creates a new warpSkyCellMapRow object7273 *7274 * @return A new warpSkyCellMapRow object or NULL on failure.7275 */7276 7277 warpSkyCellMapRow *warpSkyCellMapRowAlloc(7278 psS64 warp_id,7279 const char *skycell_id,7280 const char *tess_id,7281 psS64 cam_id,7282 const char *class_id,7283 psS16 fault7284 );7285 7286 /** Creates a new warpSkyCellMap table7287 *7288 * @return true on success7289 */7290 7291 bool warpSkyCellMapCreateTable(7292 psDB *dbh ///< Database handle7293 );7294 7295 /** Deletes a warpSkyCellMap table7296 *7297 * @return true on success7298 */7299 7300 bool warpSkyCellMapDropTable(7301 psDB *dbh ///< Database handle7302 );7303 7304 /** Insert a single row into a table7305 *7306 * This function constructs and inserts a single row based on it's parameters.7307 *7308 * @return true on success7309 */7310 7311 bool warpSkyCellMapInsert(7312 psDB *dbh, ///< Database handle7313 psS64 warp_id,7314 const char *skycell_id,7315 const char *tess_id,7316 psS64 cam_id,7317 const char *class_id,7318 psS16 fault7319 );7320 7321 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.7322 *7323 * @return A The number of rows removed or a negative value on error7324 */7325 7326 long long warpSkyCellMapDelete(7327 psDB *dbh, ///< Database handle7328 const psMetadata *where, ///< Row match criteria7329 unsigned long long limit ///< Maximum number of elements to delete7330 );7331 7332 /** Insert a single warpSkyCellMapRow object into a table7333 *7334 * This function constructs and inserts a single row based on it's parameters.7335 *7336 * @return true on success7337 */7338 7339 bool warpSkyCellMapInsertObject(7340 psDB *dbh, ///< Database handle7341 warpSkyCellMapRow *object ///< warpSkyCellMapRow object7342 );7343 7344 /** Insert an array of warpSkyCellMapRow object into a table7345 *7346 * This function constructs and inserts multiple rows based on it's parameters.7347 *7348 * @return true on success7349 */7350 7351 bool warpSkyCellMapInsertObjects(7352 psDB *dbh, ///< Database handle7353 psArray *objects ///< array of warpSkyCellMapRow objects7354 );7355 7356 /** Insert data from a binary FITS table warpSkyCellMapRow into the database7357 *7358 * This function expects a psFits object with a FITS table as the first7359 * extension. The table must have at least one row of data in it, that is of7360 * the appropriate format (number of columns and their type). All other7361 * extensions are ignored.7362 *7363 * @return true on success7364 */7365 7366 bool warpSkyCellMapInsertFits(7367 psDB *dbh, ///< Database handle7368 const psFits *fits ///< psFits object7369 );7370 7371 /** Selects up to limit from the database and returns them in a binary FITS table7372 *7373 * This function assumes an empty psFits object and will create a FITS table7374 * as the first extension.7375 *7376 * See psDBSelectRows() for documentation on the format of where.7377 *7378 * @return true on success7379 */7380 7381 bool warpSkyCellMapSelectRowsFits(7382 psDB *dbh, ///< Database handle7383 psFits *fits, ///< psFits object7384 const psMetadata *where, ///< Row match criteria7385 unsigned long long limit ///< Maximum number of elements to return7386 );7387 7388 /** Convert a warpSkyCellMapRow into an equivalent psMetadata7389 *7390 * @return A psMetadata pointer or NULL on error7391 */7392 7393 psMetadata *warpSkyCellMapMetadataFromObject(7394 const warpSkyCellMapRow *object ///< fooRow to convert into a psMetadata7395 );7396 7397 /** Convert a psMetadata into an equivalent fooRow7398 *7399 * @return A warpSkyCellMapRow pointer or NULL on error7400 */7401 7402 warpSkyCellMapRow *warpSkyCellMapObjectFromMetadata(7403 psMetadata *md ///< psMetadata to convert into a fooRow7404 );7405 /** Selects up to limit rows from the database and returns as warpSkyCellMapRow objects in a psArray7406 *7407 * See psDBSelectRows() for documentation on the format of where.7408 *7409 * @return A psArray pointer or NULL on error7410 */7411 7412 psArray *warpSkyCellMapSelectRowObjects(7413 psDB *dbh, ///< Database handle7414 const psMetadata *where, ///< Row match criteria7415 unsigned long long limit ///< Maximum number of elements to return7416 );7417 /** Deletes a row from the database coresponding to an warpSkyCellMap7418 *7419 * Note that a 'where' search psMetadata is constructed from each object and7420 * used to find rows to delete.7421 *7422 * @return A The number of rows removed or a negative value on error7423 */7424 7425 bool warpSkyCellMapDeleteObject(7426 psDB *dbh, ///< Database handle7427 const warpSkyCellMapRow *object ///< Object to delete7428 );7429 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.7430 *7431 * Note that a 'where' search psMetadata is constructed from each object and7432 * used to find rows to delete.7433 *7434 * @return A The number of rows removed or a negative value on error7435 */7436 7437 long long warpSkyCellMapDeleteRowObjects(7438 psDB *dbh, ///< Database handle7439 const psArray *objects, ///< Array of objects to delete7440 unsigned long long limit ///< Maximum number of elements to delete7441 );7442 /** Formats and prints an array of warpSkyCellMapRow objects7443 *7444 * When mdcf is set the formated output is in psMetadataConfig7445 * format, otherwise it is in a simple tabular format.7446 *7447 * @return true on success7448 */7449 7450 bool warpSkyCellMapPrintObjects(7451 FILE *stream, ///< a stream7452 psArray *objects, ///< An array of warpSkyCellMapRow objects7453 bool mdcf ///< format as mdconfig or simple7454 );7455 /** Formats and prints an warpSkyCellMapRow object7456 *7457 * When mdcf is set the formated output is in psMetadataConfig7458 * format, otherwise it is in a simple tabular format.7459 *7460 * @return true on success7461 */7462 7463 bool warpSkyCellMapPrintObject(7464 FILE *stream, ///< a stream7465 warpSkyCellMapRow *object, ///< an warpSkyCellMapRow object7466 bool mdcf ///< format as mdconfig or simple7467 );7468 /** warpSkyfileRow data structure7469 *7470 * Structure for representing a single row of warpSkyfile table data.7471 */7472 7473 typedef struct {7474 psS64 warp_id;7475 char *skycell_id;7476 char *tess_id;7477 char *uri;7478 psF64 bg;7479 psF64 bg_stdev;7480 } warpSkyfileRow;7481 7482 /** Creates a new warpSkyfileRow object7483 *7484 * @return A new warpSkyfileRow object or NULL on failure.7485 */7486 7487 warpSkyfileRow *warpSkyfileRowAlloc(7488 psS64 warp_id,7489 const char *skycell_id,7490 const char *tess_id,7491 const char *uri,7492 psF64 bg,7493 psF64 bg_stdev7494 );7495 7496 /** Creates a new warpSkyfile table7497 *7498 * @return true on success7499 */7500 7501 bool warpSkyfileCreateTable(7502 psDB *dbh ///< Database handle7503 );7504 7505 /** Deletes a warpSkyfile table7506 *7507 * @return true on success7508 */7509 7510 bool warpSkyfileDropTable(7511 psDB *dbh ///< Database handle7512 );7513 7514 /** Insert a single row into a table7515 *7516 * This function constructs and inserts a single row based on it's parameters.7517 *7518 * @return true on success7519 */7520 7521 bool warpSkyfileInsert(7522 psDB *dbh, ///< Database handle7523 psS64 warp_id,7524 const char *skycell_id,7525 const char *tess_id,7526 const char *uri,7527 psF64 bg,7528 psF64 bg_stdev7529 );7530 7531 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.7532 *7533 * @return A The number of rows removed or a negative value on error7534 */7535 7536 long long warpSkyfileDelete(7537 psDB *dbh, ///< Database handle7538 const psMetadata *where, ///< Row match criteria7539 unsigned long long limit ///< Maximum number of elements to delete7540 );7541 7542 /** Insert a single warpSkyfileRow object into a table7543 *7544 * This function constructs and inserts a single row based on it's parameters.7545 *7546 * @return true on success7547 */7548 7549 bool warpSkyfileInsertObject(7550 psDB *dbh, ///< Database handle7551 warpSkyfileRow *object ///< warpSkyfileRow object7552 );7553 7554 /** Insert an array of warpSkyfileRow object into a table7555 *7556 * This function constructs and inserts multiple rows based on it's parameters.7557 *7558 * @return true on success7559 */7560 7561 bool warpSkyfileInsertObjects(7562 psDB *dbh, ///< Database handle7563 psArray *objects ///< array of warpSkyfileRow objects7564 );7565 7566 /** Insert data from a binary FITS table warpSkyfileRow into the database7567 *7568 * This function expects a psFits object with a FITS table as the first7569 * extension. The table must have at least one row of data in it, that is of7570 * the appropriate format (number of columns and their type). All other7571 * extensions are ignored.7572 *7573 * @return true on success7574 */7575 7576 bool warpSkyfileInsertFits(7577 psDB *dbh, ///< Database handle7578 const psFits *fits ///< psFits object7579 );7580 7581 /** Selects up to limit from the database and returns them in a binary FITS table7582 *7583 * This function assumes an empty psFits object and will create a FITS table7584 * as the first extension.7585 *7586 * See psDBSelectRows() for documentation on the format of where.7587 *7588 * @return true on success7589 */7590 7591 bool warpSkyfileSelectRowsFits(7592 psDB *dbh, ///< Database handle7593 psFits *fits, ///< psFits object7594 const psMetadata *where, ///< Row match criteria7595 unsigned long long limit ///< Maximum number of elements to return7596 );7597 7598 /** Convert a warpSkyfileRow into an equivalent psMetadata7599 *7600 * @return A psMetadata pointer or NULL on error7601 */7602 7603 psMetadata *warpSkyfileMetadataFromObject(7604 const warpSkyfileRow *object ///< fooRow to convert into a psMetadata7605 );7606 7607 /** Convert a psMetadata into an equivalent fooRow7608 *7609 * @return A warpSkyfileRow pointer or NULL on error7610 */7611 7612 warpSkyfileRow *warpSkyfileObjectFromMetadata(7613 psMetadata *md ///< psMetadata to convert into a fooRow7614 );7615 /** Selects up to limit rows from the database and returns as warpSkyfileRow objects in a psArray7616 *7617 * See psDBSelectRows() for documentation on the format of where.7618 *7619 * @return A psArray pointer or NULL on error7620 */7621 7622 psArray *warpSkyfileSelectRowObjects(7623 psDB *dbh, ///< Database handle7624 const psMetadata *where, ///< Row match criteria7625 unsigned long long limit ///< Maximum number of elements to return7626 );7627 /** Deletes a row from the database coresponding to an warpSkyfile7628 *7629 * Note that a 'where' search psMetadata is constructed from each object and7630 * used to find rows to delete.7631 *7632 * @return A The number of rows removed or a negative value on error7633 */7634 7635 bool warpSkyfileDeleteObject(7636 psDB *dbh, ///< Database handle7637 const warpSkyfileRow *object ///< Object to delete7638 );7639 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.7640 *7641 * Note that a 'where' search psMetadata is constructed from each object and7642 * used to find rows to delete.7643 *7644 * @return A The number of rows removed or a negative value on error7645 */7646 7647 long long warpSkyfileDeleteRowObjects(7648 psDB *dbh, ///< Database handle7649 const psArray *objects, ///< Array of objects to delete7650 unsigned long long limit ///< Maximum number of elements to delete7651 );7652 /** Formats and prints an array of warpSkyfileRow objects7653 *7654 * When mdcf is set the formated output is in psMetadataConfig7655 * format, otherwise it is in a simple tabular format.7656 *7657 * @return true on success7658 */7659 7660 bool warpSkyfilePrintObjects(7661 FILE *stream, ///< a stream7662 psArray *objects, ///< An array of warpSkyfileRow objects7663 bool mdcf ///< format as mdconfig or simple7664 );7665 /** Formats and prints an warpSkyfileRow object7666 *7667 * When mdcf is set the formated output is in psMetadataConfig7668 * format, otherwise it is in a simple tabular format.7669 *7670 * @return true on success7671 */7672 7673 bool warpSkyfilePrintObject(7674 FILE *stream, ///< a stream7675 warpSkyfileRow *object, ///< an warpSkyfileRow object7676 bool mdcf ///< format as mdconfig or simple7677 );7678 /** diffRunRow data structure7679 *7680 * Structure for representing a single row of diffRun table data.7681 */7682 7683 typedef struct {7684 psS64 diff_id;7685 char *state;7686 char *workdir;7687 char *dvodb;7688 psTime* registered;7689 char *skycell_id;7690 char *tess_id;7691 } diffRunRow;7692 7693 /** Creates a new diffRunRow object7694 *7695 * @return A new diffRunRow object or NULL on failure.7696 */7697 7698 diffRunRow *diffRunRowAlloc(7699 psS64 diff_id,7700 const char *state,7701 const char *workdir,7702 const char *dvodb,7703 psTime* registered,7704 const char *skycell_id,7705 const char *tess_id7706 );7707 7708 /** Creates a new diffRun table7709 *7710 * @return true on success7711 */7712 7713 bool diffRunCreateTable(7714 psDB *dbh ///< Database handle7715 );7716 7717 /** Deletes a diffRun table7718 *7719 * @return true on success7720 */7721 7722 bool diffRunDropTable(7723 psDB *dbh ///< Database handle7724 );7725 7726 /** Insert a single row into a table7727 *7728 * This function constructs and inserts a single row based on it's parameters.7729 *7730 * @return true on success7731 */7732 7733 bool diffRunInsert(7734 psDB *dbh, ///< Database handle7735 psS64 diff_id,7736 const char *state,7737 const char *workdir,7738 const char *dvodb,7739 psTime* registered,7740 const char *skycell_id,7741 const char *tess_id7742 );7743 7744 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.7745 *7746 * @return A The number of rows removed or a negative value on error7747 */7748 7749 long long diffRunDelete(7750 psDB *dbh, ///< Database handle7751 const psMetadata *where, ///< Row match criteria7752 unsigned long long limit ///< Maximum number of elements to delete7753 );7754 7755 /** Insert a single diffRunRow object into a table7756 *7757 * This function constructs and inserts a single row based on it's parameters.7758 *7759 * @return true on success7760 */7761 7762 bool diffRunInsertObject(7763 psDB *dbh, ///< Database handle7764 diffRunRow *object ///< diffRunRow object7765 );7766 7767 /** Insert an array of diffRunRow object into a table7768 *7769 * This function constructs and inserts multiple rows based on it's parameters.7770 *7771 * @return true on success7772 */7773 7774 bool diffRunInsertObjects(7775 psDB *dbh, ///< Database handle7776 psArray *objects ///< array of diffRunRow objects7777 );7778 7779 /** Insert data from a binary FITS table diffRunRow into the database7780 *7781 * This function expects a psFits object with a FITS table as the first7782 * extension. The table must have at least one row of data in it, that is of7783 * the appropriate format (number of columns and their type). All other7784 * extensions are ignored.7785 *7786 * @return true on success7787 */7788 7789 bool diffRunInsertFits(7790 psDB *dbh, ///< Database handle7791 const psFits *fits ///< psFits object7792 );7793 7794 /** Selects up to limit from the database and returns them in a binary FITS table7795 *7796 * This function assumes an empty psFits object and will create a FITS table7797 * as the first extension.7798 *7799 * See psDBSelectRows() for documentation on the format of where.7800 *7801 * @return true on success7802 */7803 7804 bool diffRunSelectRowsFits(7805 psDB *dbh, ///< Database handle7806 psFits *fits, ///< psFits object7807 const psMetadata *where, ///< Row match criteria7808 unsigned long long limit ///< Maximum number of elements to return7809 );7810 7811 /** Convert a diffRunRow into an equivalent psMetadata7812 *7813 * @return A psMetadata pointer or NULL on error7814 */7815 7816 psMetadata *diffRunMetadataFromObject(7817 const diffRunRow *object ///< fooRow to convert into a psMetadata7818 );7819 7820 /** Convert a psMetadata into an equivalent fooRow7821 *7822 * @return A diffRunRow pointer or NULL on error7823 */7824 7825 diffRunRow *diffRunObjectFromMetadata(7826 psMetadata *md ///< psMetadata to convert into a fooRow7827 );7828 /** Selects up to limit rows from the database and returns as diffRunRow objects in a psArray7829 *7830 * See psDBSelectRows() for documentation on the format of where.7831 *7832 * @return A psArray pointer or NULL on error7833 */7834 7835 psArray *diffRunSelectRowObjects(7836 psDB *dbh, ///< Database handle7837 const psMetadata *where, ///< Row match criteria7838 unsigned long long limit ///< Maximum number of elements to return7839 );7840 /** Deletes a row from the database coresponding to an diffRun7841 *7842 * Note that a 'where' search psMetadata is constructed from each object and7843 * used to find rows to delete.7844 *7845 * @return A The number of rows removed or a negative value on error7846 */7847 7848 bool diffRunDeleteObject(7849 psDB *dbh, ///< Database handle7850 const diffRunRow *object ///< Object to delete7851 );7852 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.7853 *7854 * Note that a 'where' search psMetadata is constructed from each object and7855 * used to find rows to delete.7856 *7857 * @return A The number of rows removed or a negative value on error7858 */7859 7860 long long diffRunDeleteRowObjects(7861 psDB *dbh, ///< Database handle7862 const psArray *objects, ///< Array of objects to delete7863 unsigned long long limit ///< Maximum number of elements to delete7864 );7865 /** Formats and prints an array of diffRunRow objects7866 *7867 * When mdcf is set the formated output is in psMetadataConfig7868 * format, otherwise it is in a simple tabular format.7869 *7870 * @return true on success7871 */7872 7873 bool diffRunPrintObjects(7874 FILE *stream, ///< a stream7875 psArray *objects, ///< An array of diffRunRow objects7876 bool mdcf ///< format as mdconfig or simple7877 );7878 /** Formats and prints an diffRunRow object7879 *7880 * When mdcf is set the formated output is in psMetadataConfig7881 * format, otherwise it is in a simple tabular format.7882 *7883 * @return true on success7884 */7885 7886 bool diffRunPrintObject(7887 FILE *stream, ///< a stream7888 diffRunRow *object, ///< an diffRunRow object7889 bool mdcf ///< format as mdconfig or simple7890 );7891 /** diffInputSkyfileRow data structure7892 *7893 * Structure for representing a single row of diffInputSkyfile table data.7894 */7895 7896 typedef struct {7897 psS64 diff_id;7898 psS64 warp_id;7899 char *skycell_id;7900 char *tess_id;7901 char *kind;7902 bool template;7903 } diffInputSkyfileRow;7904 7905 /** Creates a new diffInputSkyfileRow object7906 *7907 * @return A new diffInputSkyfileRow object or NULL on failure.7908 */7909 7910 diffInputSkyfileRow *diffInputSkyfileRowAlloc(7911 psS64 diff_id,7912 psS64 warp_id,7913 const char *skycell_id,7914 const char *tess_id,7915 const char *kind,7916 bool template7917 );7918 7919 /** Creates a new diffInputSkyfile table7920 *7921 * @return true on success7922 */7923 7924 bool diffInputSkyfileCreateTable(7925 psDB *dbh ///< Database handle7926 );7927 7928 /** Deletes a diffInputSkyfile table7929 *7930 * @return true on success7931 */7932 7933 bool diffInputSkyfileDropTable(7934 psDB *dbh ///< Database handle7935 );7936 7937 /** Insert a single row into a table7938 *7939 * This function constructs and inserts a single row based on it's parameters.7940 *7941 * @return true on success7942 */7943 7944 bool diffInputSkyfileInsert(7945 psDB *dbh, ///< Database handle7946 psS64 diff_id,7947 psS64 warp_id,7948 const char *skycell_id,7949 const char *tess_id,7950 const char *kind,7951 bool template7952 );7953 7954 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.7955 *7956 * @return A The number of rows removed or a negative value on error7957 */7958 7959 long long diffInputSkyfileDelete(7960 psDB *dbh, ///< Database handle7961 const psMetadata *where, ///< Row match criteria7962 unsigned long long limit ///< Maximum number of elements to delete7963 );7964 7965 /** Insert a single diffInputSkyfileRow object into a table7966 *7967 * This function constructs and inserts a single row based on it's parameters.7968 *7969 * @return true on success7970 */7971 7972 bool diffInputSkyfileInsertObject(7973 psDB *dbh, ///< Database handle7974 diffInputSkyfileRow *object ///< diffInputSkyfileRow object7975 );7976 7977 /** Insert an array of diffInputSkyfileRow object into a table7978 *7979 * This function constructs and inserts multiple rows based on it's parameters.7980 *7981 * @return true on success7982 */7983 7984 bool diffInputSkyfileInsertObjects(7985 psDB *dbh, ///< Database handle7986 psArray *objects ///< array of diffInputSkyfileRow objects7987 );7988 7989 /** Insert data from a binary FITS table diffInputSkyfileRow into the database7990 *7991 * This function expects a psFits object with a FITS table as the first7992 * extension. The table must have at least one row of data in it, that is of7993 * the appropriate format (number of columns and their type). All other7994 * extensions are ignored.7995 *7996 * @return true on success7997 */7998 7999 bool diffInputSkyfileInsertFits(8000 psDB *dbh, ///< Database handle8001 const psFits *fits ///< psFits object8002 );8003 8004 /** Selects up to limit from the database and returns them in a binary FITS table8005 *8006 * This function assumes an empty psFits object and will create a FITS table8007 * as the first extension.8008 *8009 * See psDBSelectRows() for documentation on the format of where.8010 *8011 * @return true on success8012 */8013 8014 bool diffInputSkyfileSelectRowsFits(8015 psDB *dbh, ///< Database handle8016 psFits *fits, ///< psFits object8017 const psMetadata *where, ///< Row match criteria8018 unsigned long long limit ///< Maximum number of elements to return8019 );8020 8021 /** Convert a diffInputSkyfileRow into an equivalent psMetadata8022 *8023 * @return A psMetadata pointer or NULL on error8024 */8025 8026 psMetadata *diffInputSkyfileMetadataFromObject(8027 const diffInputSkyfileRow *object ///< fooRow to convert into a psMetadata8028 );8029 8030 /** Convert a psMetadata into an equivalent fooRow8031 *8032 * @return A diffInputSkyfileRow pointer or NULL on error8033 */8034 8035 diffInputSkyfileRow *diffInputSkyfileObjectFromMetadata(8036 psMetadata *md ///< psMetadata to convert into a fooRow8037 );8038 /** Selects up to limit rows from the database and returns as diffInputSkyfileRow objects in a psArray8039 *8040 * See psDBSelectRows() for documentation on the format of where.8041 *8042 * @return A psArray pointer or NULL on error8043 */8044 8045 psArray *diffInputSkyfileSelectRowObjects(8046 psDB *dbh, ///< Database handle8047 const psMetadata *where, ///< Row match criteria8048 unsigned long long limit ///< Maximum number of elements to return8049 );8050 /** Deletes a row from the database coresponding to an diffInputSkyfile8051 *8052 * Note that a 'where' search psMetadata is constructed from each object and8053 * used to find rows to delete.8054 *8055 * @return A The number of rows removed or a negative value on error8056 */8057 8058 bool diffInputSkyfileDeleteObject(8059 psDB *dbh, ///< Database handle8060 const diffInputSkyfileRow *object ///< Object to delete8061 );8062 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.8063 *8064 * Note that a 'where' search psMetadata is constructed from each object and8065 * used to find rows to delete.8066 *8067 * @return A The number of rows removed or a negative value on error8068 */8069 8070 long long diffInputSkyfileDeleteRowObjects(8071 psDB *dbh, ///< Database handle8072 const psArray *objects, ///< Array of objects to delete8073 unsigned long long limit ///< Maximum number of elements to delete8074 );8075 /** Formats and prints an array of diffInputSkyfileRow objects8076 *8077 * When mdcf is set the formated output is in psMetadataConfig8078 * format, otherwise it is in a simple tabular format.8079 *8080 * @return true on success8081 */8082 8083 bool diffInputSkyfilePrintObjects(8084 FILE *stream, ///< a stream8085 psArray *objects, ///< An array of diffInputSkyfileRow objects8086 bool mdcf ///< format as mdconfig or simple8087 );8088 /** Formats and prints an diffInputSkyfileRow object8089 *8090 * When mdcf is set the formated output is in psMetadataConfig8091 * format, otherwise it is in a simple tabular format.8092 *8093 * @return true on success8094 */8095 8096 bool diffInputSkyfilePrintObject(8097 FILE *stream, ///< a stream8098 diffInputSkyfileRow *object, ///< an diffInputSkyfileRow object8099 bool mdcf ///< format as mdconfig or simple8100 );8101 /** diffSkyfileRow data structure8102 *8103 * Structure for representing a single row of diffSkyfile table data.8104 */8105 8106 typedef struct {8107 psS64 diff_id;8108 char *uri;8109 psF64 bg;8110 psF64 bg_stdev;8111 } diffSkyfileRow;8112 8113 /** Creates a new diffSkyfileRow object8114 *8115 * @return A new diffSkyfileRow object or NULL on failure.8116 */8117 8118 diffSkyfileRow *diffSkyfileRowAlloc(8119 psS64 diff_id,8120 const char *uri,8121 psF64 bg,8122 psF64 bg_stdev8123 );8124 8125 /** Creates a new diffSkyfile table8126 *8127 * @return true on success8128 */8129 8130 bool diffSkyfileCreateTable(8131 psDB *dbh ///< Database handle8132 );8133 8134 /** Deletes a diffSkyfile table8135 *8136 * @return true on success8137 */8138 8139 bool diffSkyfileDropTable(8140 psDB *dbh ///< Database handle8141 );8142 8143 /** Insert a single row into a table8144 *8145 * This function constructs and inserts a single row based on it's parameters.8146 *8147 * @return true on success8148 */8149 8150 bool diffSkyfileInsert(8151 psDB *dbh, ///< Database handle8152 psS64 diff_id,8153 const char *uri,8154 psF64 bg,8155 psF64 bg_stdev8156 );8157 8158 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.8159 *8160 * @return A The number of rows removed or a negative value on error8161 */8162 8163 long long diffSkyfileDelete(8164 psDB *dbh, ///< Database handle8165 const psMetadata *where, ///< Row match criteria8166 unsigned long long limit ///< Maximum number of elements to delete8167 );8168 8169 /** Insert a single diffSkyfileRow object into a table8170 *8171 * This function constructs and inserts a single row based on it's parameters.8172 *8173 * @return true on success8174 */8175 8176 bool diffSkyfileInsertObject(8177 psDB *dbh, ///< Database handle8178 diffSkyfileRow *object ///< diffSkyfileRow object8179 );8180 8181 /** Insert an array of diffSkyfileRow object into a table8182 *8183 * This function constructs and inserts multiple rows based on it's parameters.8184 *8185 * @return true on success8186 */8187 8188 bool diffSkyfileInsertObjects(8189 psDB *dbh, ///< Database handle8190 psArray *objects ///< array of diffSkyfileRow objects8191 );8192 8193 /** Insert data from a binary FITS table diffSkyfileRow into the database8194 *8195 * This function expects a psFits object with a FITS table as the first8196 * extension. The table must have at least one row of data in it, that is of8197 * the appropriate format (number of columns and their type). All other8198 * extensions are ignored.8199 *8200 * @return true on success8201 */8202 8203 bool diffSkyfileInsertFits(8204 psDB *dbh, ///< Database handle8205 const psFits *fits ///< psFits object8206 );8207 8208 /** Selects up to limit from the database and returns them in a binary FITS table8209 *8210 * This function assumes an empty psFits object and will create a FITS table8211 * as the first extension.8212 *8213 * See psDBSelectRows() for documentation on the format of where.8214 *8215 * @return true on success8216 */8217 8218 bool diffSkyfileSelectRowsFits(8219 psDB *dbh, ///< Database handle8220 psFits *fits, ///< psFits object8221 const psMetadata *where, ///< Row match criteria8222 unsigned long long limit ///< Maximum number of elements to return8223 );8224 8225 /** Convert a diffSkyfileRow into an equivalent psMetadata8226 *8227 * @return A psMetadata pointer or NULL on error8228 */8229 8230 psMetadata *diffSkyfileMetadataFromObject(8231 const diffSkyfileRow *object ///< fooRow to convert into a psMetadata8232 );8233 8234 /** Convert a psMetadata into an equivalent fooRow8235 *8236 * @return A diffSkyfileRow pointer or NULL on error8237 */8238 8239 diffSkyfileRow *diffSkyfileObjectFromMetadata(8240 psMetadata *md ///< psMetadata to convert into a fooRow8241 );8242 /** Selects up to limit rows from the database and returns as diffSkyfileRow objects in a psArray8243 *8244 * See psDBSelectRows() for documentation on the format of where.8245 *8246 * @return A psArray pointer or NULL on error8247 */8248 8249 psArray *diffSkyfileSelectRowObjects(8250 psDB *dbh, ///< Database handle8251 const psMetadata *where, ///< Row match criteria8252 unsigned long long limit ///< Maximum number of elements to return8253 );8254 /** Deletes a row from the database coresponding to an diffSkyfile8255 *8256 * Note that a 'where' search psMetadata is constructed from each object and8257 * used to find rows to delete.8258 *8259 * @return A The number of rows removed or a negative value on error8260 */8261 8262 bool diffSkyfileDeleteObject(8263 psDB *dbh, ///< Database handle8264 const diffSkyfileRow *object ///< Object to delete8265 );8266 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.8267 *8268 * Note that a 'where' search psMetadata is constructed from each object and8269 * used to find rows to delete.8270 *8271 * @return A The number of rows removed or a negative value on error8272 */8273 8274 long long diffSkyfileDeleteRowObjects(8275 psDB *dbh, ///< Database handle8276 const psArray *objects, ///< Array of objects to delete8277 unsigned long long limit ///< Maximum number of elements to delete8278 );8279 /** Formats and prints an array of diffSkyfileRow objects8280 *8281 * When mdcf is set the formated output is in psMetadataConfig8282 * format, otherwise it is in a simple tabular format.8283 *8284 * @return true on success8285 */8286 8287 bool diffSkyfilePrintObjects(8288 FILE *stream, ///< a stream8289 psArray *objects, ///< An array of diffSkyfileRow objects8290 bool mdcf ///< format as mdconfig or simple8291 );8292 /** Formats and prints an diffSkyfileRow object8293 *8294 * When mdcf is set the formated output is in psMetadataConfig8295 * format, otherwise it is in a simple tabular format.8296 *8297 * @return true on success8298 */8299 8300 bool diffSkyfilePrintObject(8301 FILE *stream, ///< a stream8302 diffSkyfileRow *object, ///< an diffSkyfileRow object8303 bool mdcf ///< format as mdconfig or simple8304 );8305 /** stackRunRow data structure8306 *8307 * Structure for representing a single row of stackRun table data.8308 */8309 8310 typedef struct {8311 psS64 stack_id;8312 char *state;8313 char *workdir;8314 char *dvodb;8315 psTime* registered;8316 char *skycell_id;8317 char *tess_id;8318 } stackRunRow;8319 8320 /** Creates a new stackRunRow object8321 *8322 * @return A new stackRunRow object or NULL on failure.8323 */8324 8325 stackRunRow *stackRunRowAlloc(8326 psS64 stack_id,8327 const char *state,8328 const char *workdir,8329 const char *dvodb,8330 psTime* registered,8331 const char *skycell_id,8332 const char *tess_id8333 );8334 8335 /** Creates a new stackRun table8336 *8337 * @return true on success8338 */8339 8340 bool stackRunCreateTable(8341 psDB *dbh ///< Database handle8342 );8343 8344 /** Deletes a stackRun table8345 *8346 * @return true on success8347 */8348 8349 bool stackRunDropTable(8350 psDB *dbh ///< Database handle8351 );8352 8353 /** Insert a single row into a table8354 *8355 * This function constructs and inserts a single row based on it's parameters.8356 *8357 * @return true on success8358 */8359 8360 bool stackRunInsert(8361 psDB *dbh, ///< Database handle8362 psS64 stack_id,8363 const char *state,8364 const char *workdir,8365 const char *dvodb,8366 psTime* registered,8367 const char *skycell_id,8368 const char *tess_id8369 );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 error8374 */8375 8376 long long stackRunDelete(8377 psDB *dbh, ///< Database handle8378 const psMetadata *where, ///< Row match criteria8379 unsigned long long limit ///< Maximum number of elements to delete8380 );8381 8382 /** Insert a single stackRunRow object into a table8383 *8384 * This function constructs and inserts a single row based on it's parameters.8385 *8386 * @return true on success8387 */8388 8389 bool stackRunInsertObject(8390 psDB *dbh, ///< Database handle8391 stackRunRow *object ///< stackRunRow object8392 );8393 8394 /** Insert an array of stackRunRow object into a table8395 *8396 * This function constructs and inserts multiple rows based on it's parameters.8397 *8398 * @return true on success8399 */8400 8401 bool stackRunInsertObjects(8402 psDB *dbh, ///< Database handle8403 psArray *objects ///< array of stackRunRow objects8404 );8405 8406 /** Insert data from a binary FITS table stackRunRow into the database8407 *8408 * This function expects a psFits object with a FITS table as the first8409 * extension. The table must have at least one row of data in it, that is of8410 * the appropriate format (number of columns and their type). All other8411 * extensions are ignored.8412 *8413 * @return true on success8414 */8415 8416 bool stackRunInsertFits(8417 psDB *dbh, ///< Database handle8418 const psFits *fits ///< psFits object8419 );8420 8421 /** Selects up to limit from the database and returns them in a binary FITS table8422 *8423 * This function assumes an empty psFits object and will create a FITS table8424 * as the first extension.8425 *8426 * See psDBSelectRows() for documentation on the format of where.8427 *8428 * @return true on success8429 */8430 8431 bool stackRunSelectRowsFits(8432 psDB *dbh, ///< Database handle8433 psFits *fits, ///< psFits object8434 const psMetadata *where, ///< Row match criteria8435 unsigned long long limit ///< Maximum number of elements to return8436 );8437 8438 /** Convert a stackRunRow into an equivalent psMetadata8439 *8440 * @return A psMetadata pointer or NULL on error8441 */8442 8443 psMetadata *stackRunMetadataFromObject(8444 const stackRunRow *object ///< fooRow to convert into a psMetadata8445 );8446 8447 /** Convert a psMetadata into an equivalent fooRow8448 *8449 * @return A stackRunRow pointer or NULL on error8450 */8451 8452 stackRunRow *stackRunObjectFromMetadata(8453 psMetadata *md ///< psMetadata to convert into a fooRow8454 );8455 /** Selects up to limit rows from the database and returns as stackRunRow objects in a psArray8456 *8457 * See psDBSelectRows() for documentation on the format of where.8458 *8459 * @return A psArray pointer or NULL on error8460 */8461 8462 psArray *stackRunSelectRowObjects(8463 psDB *dbh, ///< Database handle8464 const psMetadata *where, ///< Row match criteria8465 unsigned long long limit ///< Maximum number of elements to return8466 );8467 /** Deletes a row from the database coresponding to an stackRun8468 *8469 * Note that a 'where' search psMetadata is constructed from each object and8470 * used to find rows to delete.8471 *8472 * @return A The number of rows removed or a negative value on error8473 */8474 8475 bool stackRunDeleteObject(8476 psDB *dbh, ///< Database handle8477 const stackRunRow *object ///< Object to delete8478 );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 and8482 * used to find rows to delete.8483 *8484 * @return A The number of rows removed or a negative value on error8485 */8486 8487 long long stackRunDeleteRowObjects(8488 psDB *dbh, ///< Database handle8489 const psArray *objects, ///< Array of objects to delete8490 unsigned long long limit ///< Maximum number of elements to delete8491 );8492 /** Formats and prints an array of stackRunRow objects8493 *8494 * When mdcf is set the formated output is in psMetadataConfig8495 * format, otherwise it is in a simple tabular format.8496 *8497 * @return true on success8498 */8499 8500 bool stackRunPrintObjects(8501 FILE *stream, ///< a stream8502 psArray *objects, ///< An array of stackRunRow objects8503 bool mdcf ///< format as mdconfig or simple8504 );8505 /** Formats and prints an stackRunRow object8506 *8507 * When mdcf is set the formated output is in psMetadataConfig8508 * format, otherwise it is in a simple tabular format.8509 *8510 * @return true on success8511 */8512 8513 bool stackRunPrintObject(8514 FILE *stream, ///< a stream8515 stackRunRow *object, ///< an stackRunRow object8516 bool mdcf ///< format as mdconfig or simple8517 );8518 /** stackInputSkyfileRow data structure8519 *8520 * Structure for representing a single row of stackInputSkyfile table data.8521 */8522 8523 typedef struct {8524 psS64 stack_id;8525 psS64 warp_id;8526 } stackInputSkyfileRow;8527 8528 /** Creates a new stackInputSkyfileRow object8529 *8530 * @return A new stackInputSkyfileRow object or NULL on failure.8531 */8532 8533 stackInputSkyfileRow *stackInputSkyfileRowAlloc(8534 psS64 stack_id,8535 psS64 warp_id8536 );8537 8538 /** Creates a new stackInputSkyfile table8539 *8540 * @return true on success8541 */8542 8543 bool stackInputSkyfileCreateTable(8544 psDB *dbh ///< Database handle8545 );8546 8547 /** Deletes a stackInputSkyfile table8548 *8549 * @return true on success8550 */8551 8552 bool stackInputSkyfileDropTable(8553 psDB *dbh ///< Database handle8554 );8555 8556 /** Insert a single row into a table8557 *8558 * This function constructs and inserts a single row based on it's parameters.8559 *8560 * @return true on success8561 */8562 8563 bool stackInputSkyfileInsert(8564 psDB *dbh, ///< Database handle8565 psS64 stack_id,8566 psS64 warp_id8567 );8568 8569 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.8570 *8571 * @return A The number of rows removed or a negative value on error8572 */8573 8574 long long stackInputSkyfileDelete(8575 psDB *dbh, ///< Database handle8576 const psMetadata *where, ///< Row match criteria8577 unsigned long long limit ///< Maximum number of elements to delete8578 );8579 8580 /** Insert a single stackInputSkyfileRow object into a table8581 *8582 * This function constructs and inserts a single row based on it's parameters.8583 *8584 * @return true on success8585 */8586 8587 bool stackInputSkyfileInsertObject(8588 psDB *dbh, ///< Database handle8589 stackInputSkyfileRow *object ///< stackInputSkyfileRow object8590 );8591 8592 /** Insert an array of stackInputSkyfileRow object into a table8593 *8594 * This function constructs and inserts multiple rows based on it's parameters.8595 *8596 * @return true on success8597 */8598 8599 bool stackInputSkyfileInsertObjects(8600 psDB *dbh, ///< Database handle8601 psArray *objects ///< array of stackInputSkyfileRow objects8602 );8603 8604 /** Insert data from a binary FITS table stackInputSkyfileRow into the database8605 *8606 * This function expects a psFits object with a FITS table as the first8607 * extension. The table must have at least one row of data in it, that is of8608 * the appropriate format (number of columns and their type). All other8609 * extensions are ignored.8610 *8611 * @return true on success8612 */8613 8614 bool stackInputSkyfileInsertFits(8615 psDB *dbh, ///< Database handle8616 const psFits *fits ///< psFits object8617 );8618 8619 /** Selects up to limit from the database and returns them in a binary FITS table8620 *8621 * This function assumes an empty psFits object and will create a FITS table8622 * as the first extension.8623 *8624 * See psDBSelectRows() for documentation on the format of where.8625 *8626 * @return true on success8627 */8628 8629 bool stackInputSkyfileSelectRowsFits(8630 psDB *dbh, ///< Database handle8631 psFits *fits, ///< psFits object8632 const psMetadata *where, ///< Row match criteria8633 unsigned long long limit ///< Maximum number of elements to return8634 );8635 8636 /** Convert a stackInputSkyfileRow into an equivalent psMetadata8637 *8638 * @return A psMetadata pointer or NULL on error8639 */8640 8641 psMetadata *stackInputSkyfileMetadataFromObject(8642 const stackInputSkyfileRow *object ///< fooRow to convert into a psMetadata8643 );8644 8645 /** Convert a psMetadata into an equivalent fooRow8646 *8647 * @return A stackInputSkyfileRow pointer or NULL on error8648 */8649 8650 stackInputSkyfileRow *stackInputSkyfileObjectFromMetadata(8651 psMetadata *md ///< psMetadata to convert into a fooRow8652 );8653 /** Selects up to limit rows from the database and returns as stackInputSkyfileRow objects in a psArray8654 *8655 * See psDBSelectRows() for documentation on the format of where.8656 *8657 * @return A psArray pointer or NULL on error8658 */8659 8660 psArray *stackInputSkyfileSelectRowObjects(8661 psDB *dbh, ///< Database handle8662 const psMetadata *where, ///< Row match criteria8663 unsigned long long limit ///< Maximum number of elements to return8664 );8665 /** Deletes a row from the database coresponding to an stackInputSkyfile8666 *8667 * Note that a 'where' search psMetadata is constructed from each object and8668 * used to find rows to delete.8669 *8670 * @return A The number of rows removed or a negative value on error8671 */8672 8673 bool stackInputSkyfileDeleteObject(8674 psDB *dbh, ///< Database handle8675 const stackInputSkyfileRow *object ///< Object to delete8676 );8677 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.8678 *8679 * Note that a 'where' search psMetadata is constructed from each object and8680 * used to find rows to delete.8681 *8682 * @return A The number of rows removed or a negative value on error8683 */8684 8685 long long stackInputSkyfileDeleteRowObjects(8686 psDB *dbh, ///< Database handle8687 const psArray *objects, ///< Array of objects to delete8688 unsigned long long limit ///< Maximum number of elements to delete8689 );8690 /** Formats and prints an array of stackInputSkyfileRow objects8691 *8692 * When mdcf is set the formated output is in psMetadataConfig8693 * format, otherwise it is in a simple tabular format.8694 *8695 * @return true on success8696 */8697 8698 bool stackInputSkyfilePrintObjects(8699 FILE *stream, ///< a stream8700 psArray *objects, ///< An array of stackInputSkyfileRow objects8701 bool mdcf ///< format as mdconfig or simple8702 );8703 /** Formats and prints an stackInputSkyfileRow object8704 *8705 * When mdcf is set the formated output is in psMetadataConfig8706 * format, otherwise it is in a simple tabular format.8707 *8708 * @return true on success8709 */8710 8711 bool stackInputSkyfilePrintObject(8712 FILE *stream, ///< a stream8713 stackInputSkyfileRow *object, ///< an stackInputSkyfileRow object8714 bool mdcf ///< format as mdconfig or simple8715 );8716 /** stackSumSkyfileRow data structure8717 *8718 * Structure for representing a single row of stackSumSkyfile table data.8719 */8720 8721 typedef struct {8722 psS64 stack_id;8723 char *uri;8724 psF64 bg;8725 psF64 bg_stdev;8726 } stackSumSkyfileRow;8727 8728 /** Creates a new stackSumSkyfileRow object8729 *8730 * @return A new stackSumSkyfileRow object or NULL on failure.8731 */8732 8733 stackSumSkyfileRow *stackSumSkyfileRowAlloc(8734 psS64 stack_id,8735 const char *uri,8736 psF64 bg,8737 psF64 bg_stdev8738 );8739 8740 /** Creates a new stackSumSkyfile table8741 *8742 * @return true on success8743 */8744 8745 bool stackSumSkyfileCreateTable(8746 psDB *dbh ///< Database handle8747 );8748 8749 /** Deletes a stackSumSkyfile table8750 *8751 * @return true on success8752 */8753 8754 bool stackSumSkyfileDropTable(8755 psDB *dbh ///< Database handle8756 );8757 8758 /** Insert a single row into a table8759 *8760 * This function constructs and inserts a single row based on it's parameters.8761 *8762 * @return true on success8763 */8764 8765 bool stackSumSkyfileInsert(8766 psDB *dbh, ///< Database handle8767 psS64 stack_id,8768 const char *uri,8769 psF64 bg,8770 psF64 bg_stdev8771 );8772 8773 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.8774 *8775 * @return A The number of rows removed or a negative value on error8776 */8777 8778 long long stackSumSkyfileDelete(8779 psDB *dbh, ///< Database handle8780 const psMetadata *where, ///< Row match criteria8781 unsigned long long limit ///< Maximum number of elements to delete8782 );8783 8784 /** Insert a single stackSumSkyfileRow object into a table8785 *8786 * This function constructs and inserts a single row based on it's parameters.8787 *8788 * @return true on success8789 */8790 8791 bool stackSumSkyfileInsertObject(8792 psDB *dbh, ///< Database handle8793 stackSumSkyfileRow *object ///< stackSumSkyfileRow object8794 );8795 8796 /** Insert an array of stackSumSkyfileRow object into a table8797 *8798 * This function constructs and inserts multiple rows based on it's parameters.8799 *8800 * @return true on success8801 */8802 8803 bool stackSumSkyfileInsertObjects(8804 psDB *dbh, ///< Database handle8805 psArray *objects ///< array of stackSumSkyfileRow objects8806 );8807 8808 /** Insert data from a binary FITS table stackSumSkyfileRow into the database8809 *8810 * This function expects a psFits object with a FITS table as the first8811 * extension. The table must have at least one row of data in it, that is of8812 * the appropriate format (number of columns and their type). All other8813 * extensions are ignored.8814 *8815 * @return true on success8816 */8817 8818 bool stackSumSkyfileInsertFits(8819 psDB *dbh, ///< Database handle8820 const psFits *fits ///< psFits object8821 );8822 8823 /** Selects up to limit from the database and returns them in a binary FITS table8824 *8825 * This function assumes an empty psFits object and will create a FITS table8826 * as the first extension.8827 *8828 * See psDBSelectRows() for documentation on the format of where.8829 *8830 * @return true on success8831 */8832 8833 bool stackSumSkyfileSelectRowsFits(8834 psDB *dbh, ///< Database handle8835 psFits *fits, ///< psFits object8836 const psMetadata *where, ///< Row match criteria8837 unsigned long long limit ///< Maximum number of elements to return8838 );8839 8840 /** Convert a stackSumSkyfileRow into an equivalent psMetadata8841 *8842 * @return A psMetadata pointer or NULL on error8843 */8844 8845 psMetadata *stackSumSkyfileMetadataFromObject(8846 const stackSumSkyfileRow *object ///< fooRow to convert into a psMetadata8847 );8848 8849 /** Convert a psMetadata into an equivalent fooRow8850 *8851 * @return A stackSumSkyfileRow pointer or NULL on error8852 */8853 8854 stackSumSkyfileRow *stackSumSkyfileObjectFromMetadata(8855 psMetadata *md ///< psMetadata to convert into a fooRow8856 );8857 /** Selects up to limit rows from the database and returns as stackSumSkyfileRow objects in a psArray8858 *8859 * See psDBSelectRows() for documentation on the format of where.8860 *8861 * @return A psArray pointer or NULL on error8862 */8863 8864 psArray *stackSumSkyfileSelectRowObjects(8865 psDB *dbh, ///< Database handle8866 const psMetadata *where, ///< Row match criteria8867 unsigned long long limit ///< Maximum number of elements to return8868 );8869 /** Deletes a row from the database coresponding to an stackSumSkyfile8870 *8871 * Note that a 'where' search psMetadata is constructed from each object and8872 * used to find rows to delete.8873 *8874 * @return A The number of rows removed or a negative value on error8875 */8876 8877 bool stackSumSkyfileDeleteObject(8878 psDB *dbh, ///< Database handle8879 const stackSumSkyfileRow *object ///< Object to delete8880 );8881 /** Deletes up to limit rows from the database and returns the number of rows actually deleted.8882 *8883 * Note that a 'where' search psMetadata is constructed from each object and8884 * used to find rows to delete.8885 *8886 * @return A The number of rows removed or a negative value on error8887 */8888 8889 long long stackSumSkyfileDeleteRowObjects(8890 psDB *dbh, ///< Database handle8891 const psArray *objects, ///< Array of objects to delete8892 unsigned long long limit ///< Maximum number of elements to delete8893 );8894 /** Formats and prints an array of stackSumSkyfileRow objects8895 *8896 * When mdcf is set the formated output is in psMetadataConfig8897 * format, otherwise it is in a simple tabular format.8898 *8899 * @return true on success8900 */8901 8902 bool stackSumSkyfilePrintObjects(8903 FILE *stream, ///< a stream8904 psArray *objects, ///< An array of stackSumSkyfileRow objects8905 bool mdcf ///< format as mdconfig or simple8906 );8907 /** Formats and prints an stackSumSkyfileRow object8908 *8909 * When mdcf is set the formated output is in psMetadataConfig8910 * format, otherwise it is in a simple tabular format.8911 *8912 * @return true on success8913 */8914 8915 bool stackSumSkyfilePrintObject(8916 FILE *stream, ///< a stream8917 stackSumSkyfileRow *object, ///< an stackSumSkyfileRow object8918 bool mdcf ///< format as mdconfig or simple8919 );8920 8920 8921 8921 /// @} … … 8925 8925 #endif 8926 8926 8927 #endif // STACKSUMSKYFILE_DB_H8927 #endif // DETRUNSUMMARY_DB_H -
trunk/ippdb/tests/alloc.c
r12426 r12535 854 854 855 855 { 856 warpRunRow *object; 857 858 object = warpRunRowAlloc(-64, "a string", "a string", "a string", "a string", "0001-01-01T00:00:00Z" ); 859 860 if (!object) { 861 exit(EXIT_FAILURE); 862 } 863 864 if (!object->warp_id == -64) { 865 psFree(object); 866 exit(EXIT_FAILURE); 867 } 868 if (strncmp(object->mode, "a string", MAX_STRING_LENGTH)) { 869 psFree(object); 870 exit(EXIT_FAILURE); 871 } 872 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 873 psFree(object); 874 exit(EXIT_FAILURE); 875 } 876 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) { 877 psFree(object); 878 exit(EXIT_FAILURE); 879 } 880 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) { 881 psFree(object); 882 exit(EXIT_FAILURE); 883 } 884 psFree(object); 885 exit(EXIT_FAILURE); 886 } 887 888 psFree(object); 889 } 890 891 { 892 warpInputExpRow *object; 893 894 object = warpInputExpRowAlloc(-64, -64, true ); 895 896 if (!object) { 897 exit(EXIT_FAILURE); 898 } 899 900 if (!object->warp_id == -64) { 901 psFree(object); 902 exit(EXIT_FAILURE); 903 } 904 if (!object->cam_id == -64) { 905 psFree(object); 906 exit(EXIT_FAILURE); 907 } 908 if (!object->magiced == true) { 909 psFree(object); 910 exit(EXIT_FAILURE); 911 } 912 913 psFree(object); 914 } 915 916 { 917 warpSkyCellMapRow *object; 918 919 object = warpSkyCellMapRowAlloc(-64, "a string", "a string", -64, "a string", -16 ); 920 921 if (!object) { 922 exit(EXIT_FAILURE); 923 } 924 925 if (!object->warp_id == -64) { 926 psFree(object); 927 exit(EXIT_FAILURE); 928 } 929 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 930 psFree(object); 931 exit(EXIT_FAILURE); 932 } 933 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 934 psFree(object); 935 exit(EXIT_FAILURE); 936 } 937 if (!object->cam_id == -64) { 938 psFree(object); 939 exit(EXIT_FAILURE); 940 } 941 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 942 psFree(object); 943 exit(EXIT_FAILURE); 944 } 945 if (!object->fault == -16) { 946 psFree(object); 947 exit(EXIT_FAILURE); 948 } 949 950 psFree(object); 951 } 952 953 { 954 warpSkyfileRow *object; 955 956 object = warpSkyfileRowAlloc(-64, "a string", "a string", "a string", 64.64, 64.64 ); 957 958 if (!object) { 959 exit(EXIT_FAILURE); 960 } 961 962 if (!object->warp_id == -64) { 963 psFree(object); 964 exit(EXIT_FAILURE); 965 } 966 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 967 psFree(object); 968 exit(EXIT_FAILURE); 969 } 970 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 971 psFree(object); 972 exit(EXIT_FAILURE); 973 } 974 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 975 psFree(object); 976 exit(EXIT_FAILURE); 977 } 978 if (!object->bg == 64.64) { 979 psFree(object); 980 exit(EXIT_FAILURE); 981 } 982 if (!object->bg_stdev == 64.64) { 983 psFree(object); 984 exit(EXIT_FAILURE); 985 } 986 987 psFree(object); 988 } 989 990 { 991 diffRunRow *object; 992 993 object = diffRunRowAlloc(-64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string" ); 994 995 if (!object) { 996 exit(EXIT_FAILURE); 997 } 998 999 if (!object->diff_id == -64) { 1000 psFree(object); 1001 exit(EXIT_FAILURE); 1002 } 1003 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 1004 psFree(object); 1005 exit(EXIT_FAILURE); 1006 } 1007 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) { 1008 psFree(object); 1009 exit(EXIT_FAILURE); 1010 } 1011 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) { 1012 psFree(object); 1013 exit(EXIT_FAILURE); 1014 } 1015 psFree(object); 1016 exit(EXIT_FAILURE); 1017 } 1018 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 1019 psFree(object); 1020 exit(EXIT_FAILURE); 1021 } 1022 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 1023 psFree(object); 1024 exit(EXIT_FAILURE); 1025 } 1026 1027 psFree(object); 1028 } 1029 1030 { 1031 diffInputSkyfileRow *object; 1032 1033 object = diffInputSkyfileRowAlloc(-64, -64, "a string", "a string", "a string", true ); 1034 1035 if (!object) { 1036 exit(EXIT_FAILURE); 1037 } 1038 1039 if (!object->diff_id == -64) { 1040 psFree(object); 1041 exit(EXIT_FAILURE); 1042 } 1043 if (!object->warp_id == -64) { 1044 psFree(object); 1045 exit(EXIT_FAILURE); 1046 } 1047 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 1048 psFree(object); 1049 exit(EXIT_FAILURE); 1050 } 1051 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 1052 psFree(object); 1053 exit(EXIT_FAILURE); 1054 } 1055 if (strncmp(object->kind, "a string", MAX_STRING_LENGTH)) { 1056 psFree(object); 1057 exit(EXIT_FAILURE); 1058 } 1059 if (!object->template == true) { 1060 psFree(object); 1061 exit(EXIT_FAILURE); 1062 } 1063 1064 psFree(object); 1065 } 1066 1067 { 1068 diffSkyfileRow *object; 1069 1070 object = diffSkyfileRowAlloc(-64, "a string", 64.64, 64.64 ); 1071 1072 if (!object) { 1073 exit(EXIT_FAILURE); 1074 } 1075 1076 if (!object->diff_id == -64) { 1077 psFree(object); 1078 exit(EXIT_FAILURE); 1079 } 1080 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 1081 psFree(object); 1082 exit(EXIT_FAILURE); 1083 } 1084 if (!object->bg == 64.64) { 1085 psFree(object); 1086 exit(EXIT_FAILURE); 1087 } 1088 if (!object->bg_stdev == 64.64) { 1089 psFree(object); 1090 exit(EXIT_FAILURE); 1091 } 1092 1093 psFree(object); 1094 } 1095 1096 { 1097 stackRunRow *object; 1098 1099 object = stackRunRowAlloc(-64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string" ); 1100 1101 if (!object) { 1102 exit(EXIT_FAILURE); 1103 } 1104 1105 if (!object->stack_id == -64) { 1106 psFree(object); 1107 exit(EXIT_FAILURE); 1108 } 1109 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 1110 psFree(object); 1111 exit(EXIT_FAILURE); 1112 } 1113 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) { 1114 psFree(object); 1115 exit(EXIT_FAILURE); 1116 } 1117 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) { 1118 psFree(object); 1119 exit(EXIT_FAILURE); 1120 } 1121 psFree(object); 1122 exit(EXIT_FAILURE); 1123 } 1124 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 1125 psFree(object); 1126 exit(EXIT_FAILURE); 1127 } 1128 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 1129 psFree(object); 1130 exit(EXIT_FAILURE); 1131 } 1132 1133 psFree(object); 1134 } 1135 1136 { 1137 stackInputSkyfileRow *object; 1138 1139 object = stackInputSkyfileRowAlloc(-64, -64 ); 1140 1141 if (!object) { 1142 exit(EXIT_FAILURE); 1143 } 1144 1145 if (!object->stack_id == -64) { 1146 psFree(object); 1147 exit(EXIT_FAILURE); 1148 } 1149 if (!object->warp_id == -64) { 1150 psFree(object); 1151 exit(EXIT_FAILURE); 1152 } 1153 1154 psFree(object); 1155 } 1156 1157 { 1158 stackSumSkyfileRow *object; 1159 1160 object = stackSumSkyfileRowAlloc(-64, "a string", 64.64, 64.64 ); 1161 1162 if (!object) { 1163 exit(EXIT_FAILURE); 1164 } 1165 1166 if (!object->stack_id == -64) { 1167 psFree(object); 1168 exit(EXIT_FAILURE); 1169 } 1170 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 1171 psFree(object); 1172 exit(EXIT_FAILURE); 1173 } 1174 if (!object->bg == 64.64) { 1175 psFree(object); 1176 exit(EXIT_FAILURE); 1177 } 1178 if (!object->bg_stdev == 64.64) { 1179 psFree(object); 1180 exit(EXIT_FAILURE); 1181 } 1182 1183 psFree(object); 1184 } 1185 1186 { 856 1187 detRunRow *object; 857 1188 … … 1420 1751 } 1421 1752 if (!object->fault == -16) { 1422 psFree(object);1423 exit(EXIT_FAILURE);1424 }1425 1426 psFree(object);1427 }1428 1429 {1430 warpRunRow *object;1431 1432 object = warpRunRowAlloc(-64, "a string", "a string", "a string", "a string", "0001-01-01T00:00:00Z" );1433 1434 if (!object) {1435 exit(EXIT_FAILURE);1436 }1437 1438 if (!object->warp_id == -64) {1439 psFree(object);1440 exit(EXIT_FAILURE);1441 }1442 if (strncmp(object->mode, "a string", MAX_STRING_LENGTH)) {1443 psFree(object);1444 exit(EXIT_FAILURE);1445 }1446 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) {1447 psFree(object);1448 exit(EXIT_FAILURE);1449 }1450 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) {1451 psFree(object);1452 exit(EXIT_FAILURE);1453 }1454 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) {1455 psFree(object);1456 exit(EXIT_FAILURE);1457 }1458 psFree(object);1459 exit(EXIT_FAILURE);1460 }1461 1462 psFree(object);1463 }1464 1465 {1466 warpInputExpRow *object;1467 1468 object = warpInputExpRowAlloc(-64, -64, true );1469 1470 if (!object) {1471 exit(EXIT_FAILURE);1472 }1473 1474 if (!object->warp_id == -64) {1475 psFree(object);1476 exit(EXIT_FAILURE);1477 }1478 if (!object->cam_id == -64) {1479 psFree(object);1480 exit(EXIT_FAILURE);1481 }1482 if (!object->magiced == true) {1483 psFree(object);1484 exit(EXIT_FAILURE);1485 }1486 1487 psFree(object);1488 }1489 1490 {1491 warpSkyCellMapRow *object;1492 1493 object = warpSkyCellMapRowAlloc(-64, "a string", "a string", -64, "a string", -16 );1494 1495 if (!object) {1496 exit(EXIT_FAILURE);1497 }1498 1499 if (!object->warp_id == -64) {1500 psFree(object);1501 exit(EXIT_FAILURE);1502 }1503 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {1504 psFree(object);1505 exit(EXIT_FAILURE);1506 }1507 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {1508 psFree(object);1509 exit(EXIT_FAILURE);1510 }1511 if (!object->cam_id == -64) {1512 psFree(object);1513 exit(EXIT_FAILURE);1514 }1515 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {1516 psFree(object);1517 exit(EXIT_FAILURE);1518 }1519 if (!object->fault == -16) {1520 psFree(object);1521 exit(EXIT_FAILURE);1522 }1523 1524 psFree(object);1525 }1526 1527 {1528 warpSkyfileRow *object;1529 1530 object = warpSkyfileRowAlloc(-64, "a string", "a string", "a string", 64.64, 64.64 );1531 1532 if (!object) {1533 exit(EXIT_FAILURE);1534 }1535 1536 if (!object->warp_id == -64) {1537 psFree(object);1538 exit(EXIT_FAILURE);1539 }1540 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {1541 psFree(object);1542 exit(EXIT_FAILURE);1543 }1544 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {1545 psFree(object);1546 exit(EXIT_FAILURE);1547 }1548 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {1549 psFree(object);1550 exit(EXIT_FAILURE);1551 }1552 if (!object->bg == 64.64) {1553 psFree(object);1554 exit(EXIT_FAILURE);1555 }1556 if (!object->bg_stdev == 64.64) {1557 psFree(object);1558 exit(EXIT_FAILURE);1559 }1560 1561 psFree(object);1562 }1563 1564 {1565 diffRunRow *object;1566 1567 object = diffRunRowAlloc(-64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string" );1568 1569 if (!object) {1570 exit(EXIT_FAILURE);1571 }1572 1573 if (!object->diff_id == -64) {1574 psFree(object);1575 exit(EXIT_FAILURE);1576 }1577 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) {1578 psFree(object);1579 exit(EXIT_FAILURE);1580 }1581 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) {1582 psFree(object);1583 exit(EXIT_FAILURE);1584 }1585 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) {1586 psFree(object);1587 exit(EXIT_FAILURE);1588 }1589 psFree(object);1590 exit(EXIT_FAILURE);1591 }1592 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {1593 psFree(object);1594 exit(EXIT_FAILURE);1595 }1596 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {1597 psFree(object);1598 exit(EXIT_FAILURE);1599 }1600 1601 psFree(object);1602 }1603 1604 {1605 diffInputSkyfileRow *object;1606 1607 object = diffInputSkyfileRowAlloc(-64, -64, "a string", "a string", "a string", true );1608 1609 if (!object) {1610 exit(EXIT_FAILURE);1611 }1612 1613 if (!object->diff_id == -64) {1614 psFree(object);1615 exit(EXIT_FAILURE);1616 }1617 if (!object->warp_id == -64) {1618 psFree(object);1619 exit(EXIT_FAILURE);1620 }1621 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {1622 psFree(object);1623 exit(EXIT_FAILURE);1624 }1625 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {1626 psFree(object);1627 exit(EXIT_FAILURE);1628 }1629 if (strncmp(object->kind, "a string", MAX_STRING_LENGTH)) {1630 psFree(object);1631 exit(EXIT_FAILURE);1632 }1633 if (!object->template == true) {1634 psFree(object);1635 exit(EXIT_FAILURE);1636 }1637 1638 psFree(object);1639 }1640 1641 {1642 diffSkyfileRow *object;1643 1644 object = diffSkyfileRowAlloc(-64, "a string", 64.64, 64.64 );1645 1646 if (!object) {1647 exit(EXIT_FAILURE);1648 }1649 1650 if (!object->diff_id == -64) {1651 psFree(object);1652 exit(EXIT_FAILURE);1653 }1654 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {1655 psFree(object);1656 exit(EXIT_FAILURE);1657 }1658 if (!object->bg == 64.64) {1659 psFree(object);1660 exit(EXIT_FAILURE);1661 }1662 if (!object->bg_stdev == 64.64) {1663 psFree(object);1664 exit(EXIT_FAILURE);1665 }1666 1667 psFree(object);1668 }1669 1670 {1671 stackRunRow *object;1672 1673 object = stackRunRowAlloc(-64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string" );1674 1675 if (!object) {1676 exit(EXIT_FAILURE);1677 }1678 1679 if (!object->stack_id == -64) {1680 psFree(object);1681 exit(EXIT_FAILURE);1682 }1683 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) {1684 psFree(object);1685 exit(EXIT_FAILURE);1686 }1687 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) {1688 psFree(object);1689 exit(EXIT_FAILURE);1690 }1691 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) {1692 psFree(object);1693 exit(EXIT_FAILURE);1694 }1695 psFree(object);1696 exit(EXIT_FAILURE);1697 }1698 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {1699 psFree(object);1700 exit(EXIT_FAILURE);1701 }1702 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {1703 psFree(object);1704 exit(EXIT_FAILURE);1705 }1706 1707 psFree(object);1708 }1709 1710 {1711 stackInputSkyfileRow *object;1712 1713 object = stackInputSkyfileRowAlloc(-64, -64 );1714 1715 if (!object) {1716 exit(EXIT_FAILURE);1717 }1718 1719 if (!object->stack_id == -64) {1720 psFree(object);1721 exit(EXIT_FAILURE);1722 }1723 if (!object->warp_id == -64) {1724 psFree(object);1725 exit(EXIT_FAILURE);1726 }1727 1728 psFree(object);1729 }1730 1731 {1732 stackSumSkyfileRow *object;1733 1734 object = stackSumSkyfileRowAlloc(-64, "a string", 64.64, 64.64 );1735 1736 if (!object) {1737 exit(EXIT_FAILURE);1738 }1739 1740 if (!object->stack_id == -64) {1741 psFree(object);1742 exit(EXIT_FAILURE);1743 }1744 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {1745 psFree(object);1746 exit(EXIT_FAILURE);1747 }1748 if (!object->bg == 64.64) {1749 psFree(object);1750 exit(EXIT_FAILURE);1751 }1752 if (!object->bg_stdev == 64.64) {1753 1753 psFree(object); 1754 1754 exit(EXIT_FAILURE); -
trunk/ippdb/tests/createtable.c
r12026 r12535 313 313 } 314 314 315 if(!warpRunCreateTable(dbh)) { 316 exit(EXIT_FAILURE); 317 } 318 319 psDBCleanup(dbh); 320 } 321 322 { 323 psDB *dbh; 324 325 dbh = psDBInit("localhost", "test", NULL, "test"); 326 if (!dbh) { 327 exit(EXIT_FAILURE); 328 } 329 330 if(!warpInputExpCreateTable(dbh)) { 331 exit(EXIT_FAILURE); 332 } 333 334 psDBCleanup(dbh); 335 } 336 337 { 338 psDB *dbh; 339 340 dbh = psDBInit("localhost", "test", NULL, "test"); 341 if (!dbh) { 342 exit(EXIT_FAILURE); 343 } 344 345 if(!warpSkyCellMapCreateTable(dbh)) { 346 exit(EXIT_FAILURE); 347 } 348 349 psDBCleanup(dbh); 350 } 351 352 { 353 psDB *dbh; 354 355 dbh = psDBInit("localhost", "test", NULL, "test"); 356 if (!dbh) { 357 exit(EXIT_FAILURE); 358 } 359 360 if(!warpSkyfileCreateTable(dbh)) { 361 exit(EXIT_FAILURE); 362 } 363 364 psDBCleanup(dbh); 365 } 366 367 { 368 psDB *dbh; 369 370 dbh = psDBInit("localhost", "test", NULL, "test"); 371 if (!dbh) { 372 exit(EXIT_FAILURE); 373 } 374 375 if(!diffRunCreateTable(dbh)) { 376 exit(EXIT_FAILURE); 377 } 378 379 psDBCleanup(dbh); 380 } 381 382 { 383 psDB *dbh; 384 385 dbh = psDBInit("localhost", "test", NULL, "test"); 386 if (!dbh) { 387 exit(EXIT_FAILURE); 388 } 389 390 if(!diffInputSkyfileCreateTable(dbh)) { 391 exit(EXIT_FAILURE); 392 } 393 394 psDBCleanup(dbh); 395 } 396 397 { 398 psDB *dbh; 399 400 dbh = psDBInit("localhost", "test", NULL, "test"); 401 if (!dbh) { 402 exit(EXIT_FAILURE); 403 } 404 405 if(!diffSkyfileCreateTable(dbh)) { 406 exit(EXIT_FAILURE); 407 } 408 409 psDBCleanup(dbh); 410 } 411 412 { 413 psDB *dbh; 414 415 dbh = psDBInit("localhost", "test", NULL, "test"); 416 if (!dbh) { 417 exit(EXIT_FAILURE); 418 } 419 420 if(!stackRunCreateTable(dbh)) { 421 exit(EXIT_FAILURE); 422 } 423 424 psDBCleanup(dbh); 425 } 426 427 { 428 psDB *dbh; 429 430 dbh = psDBInit("localhost", "test", NULL, "test"); 431 if (!dbh) { 432 exit(EXIT_FAILURE); 433 } 434 435 if(!stackInputSkyfileCreateTable(dbh)) { 436 exit(EXIT_FAILURE); 437 } 438 439 psDBCleanup(dbh); 440 } 441 442 { 443 psDB *dbh; 444 445 dbh = psDBInit("localhost", "test", NULL, "test"); 446 if (!dbh) { 447 exit(EXIT_FAILURE); 448 } 449 450 if(!stackSumSkyfileCreateTable(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 315 465 if(!detRunCreateTable(dbh)) { 316 466 exit(EXIT_FAILURE); … … 464 614 465 615 if(!detRunSummaryCreateTable(dbh)) { 466 exit(EXIT_FAILURE);467 }468 469 psDBCleanup(dbh);470 }471 472 {473 psDB *dbh;474 475 dbh = psDBInit("localhost", "test", NULL, "test");476 if (!dbh) {477 exit(EXIT_FAILURE);478 }479 480 if(!warpRunCreateTable(dbh)) {481 exit(EXIT_FAILURE);482 }483 484 psDBCleanup(dbh);485 }486 487 {488 psDB *dbh;489 490 dbh = psDBInit("localhost", "test", NULL, "test");491 if (!dbh) {492 exit(EXIT_FAILURE);493 }494 495 if(!warpInputExpCreateTable(dbh)) {496 exit(EXIT_FAILURE);497 }498 499 psDBCleanup(dbh);500 }501 502 {503 psDB *dbh;504 505 dbh = psDBInit("localhost", "test", NULL, "test");506 if (!dbh) {507 exit(EXIT_FAILURE);508 }509 510 if(!warpSkyCellMapCreateTable(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(!warpSkyfileCreateTable(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(!diffRunCreateTable(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(!diffInputSkyfileCreateTable(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(!diffSkyfileCreateTable(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(!stackRunCreateTable(dbh)) {586 exit(EXIT_FAILURE);587 }588 589 psDBCleanup(dbh);590 }591 592 {593 psDB *dbh;594 595 dbh = psDBInit("localhost", "test", NULL, "test");596 if (!dbh) {597 exit(EXIT_FAILURE);598 }599 600 if(!stackInputSkyfileCreateTable(dbh)) {601 exit(EXIT_FAILURE);602 }603 604 psDBCleanup(dbh);605 }606 607 {608 psDB *dbh;609 610 dbh = psDBInit("localhost", "test", NULL, "test");611 if (!dbh) {612 exit(EXIT_FAILURE);613 }614 615 if(!stackSumSkyfileCreateTable(dbh)) {616 616 exit(EXIT_FAILURE); 617 617 } -
trunk/ippdb/tests/dbcleanup.c
r12026 r12535 31 31 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS camProcessedExp"); 32 32 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS camMask"); 33 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpRun"); 34 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpInputExp"); 35 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpSkyCellMap"); 36 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpSkyfile"); 37 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS diffRun"); 38 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS diffInputSkyfile"); 39 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS diffSkyfile"); 40 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS stackRun"); 41 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS stackInputSkyfile"); 42 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS stackSumSkyfile"); 33 43 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detRun"); 34 44 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detInputExp"); … … 42 52 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detResidExp"); 43 53 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detRunSummary"); 44 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpRun");45 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpInputExp");46 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpSkyCellMap");47 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpSkyfile");48 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS diffRun");49 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS diffInputSkyfile");50 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS diffSkyfile");51 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS stackRun");52 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS stackInputSkyfile");53 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS stackSumSkyfile");54 54 55 55 psDBCleanup(dbh); -
trunk/ippdb/tests/dbsetup.c
r12026 r12535 73 73 camMaskCreateTable(dbh); 74 74 75 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpRun"); 76 warpRunCreateTable(dbh); 77 78 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpInputExp"); 79 warpInputExpCreateTable(dbh); 80 81 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpSkyCellMap"); 82 warpSkyCellMapCreateTable(dbh); 83 84 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpSkyfile"); 85 warpSkyfileCreateTable(dbh); 86 87 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS diffRun"); 88 diffRunCreateTable(dbh); 89 90 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS diffInputSkyfile"); 91 diffInputSkyfileCreateTable(dbh); 92 93 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS diffSkyfile"); 94 diffSkyfileCreateTable(dbh); 95 96 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS stackRun"); 97 stackRunCreateTable(dbh); 98 99 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS stackInputSkyfile"); 100 stackInputSkyfileCreateTable(dbh); 101 102 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS stackSumSkyfile"); 103 stackSumSkyfileCreateTable(dbh); 104 75 105 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detRun"); 76 106 detRunCreateTable(dbh); … … 106 136 detRunSummaryCreateTable(dbh); 107 137 108 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpRun");109 warpRunCreateTable(dbh);110 111 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpInputExp");112 warpInputExpCreateTable(dbh);113 114 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpSkyCellMap");115 warpSkyCellMapCreateTable(dbh);116 117 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS warpSkyfile");118 warpSkyfileCreateTable(dbh);119 120 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS diffRun");121 diffRunCreateTable(dbh);122 123 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS diffInputSkyfile");124 diffInputSkyfileCreateTable(dbh);125 126 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS diffSkyfile");127 diffSkyfileCreateTable(dbh);128 129 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS stackRun");130 stackRunCreateTable(dbh);131 132 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS stackInputSkyfile");133 stackInputSkyfileCreateTable(dbh);134 135 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS stackSumSkyfile");136 stackSumSkyfileCreateTable(dbh);137 138 138 psDBCleanup(dbh); 139 139 -
trunk/ippdb/tests/droptable.c
r12026 r12535 313 313 } 314 314 315 if (!warpRunDropTable(dbh)) { 316 exit(EXIT_FAILURE); 317 } 318 319 psDBCleanup(dbh); 320 } 321 322 { 323 psDB *dbh; 324 325 dbh = psDBInit("localhost", "test", NULL, "test"); 326 if (!dbh) { 327 exit(EXIT_FAILURE); 328 } 329 330 if (!warpInputExpDropTable(dbh)) { 331 exit(EXIT_FAILURE); 332 } 333 334 psDBCleanup(dbh); 335 } 336 337 { 338 psDB *dbh; 339 340 dbh = psDBInit("localhost", "test", NULL, "test"); 341 if (!dbh) { 342 exit(EXIT_FAILURE); 343 } 344 345 if (!warpSkyCellMapDropTable(dbh)) { 346 exit(EXIT_FAILURE); 347 } 348 349 psDBCleanup(dbh); 350 } 351 352 { 353 psDB *dbh; 354 355 dbh = psDBInit("localhost", "test", NULL, "test"); 356 if (!dbh) { 357 exit(EXIT_FAILURE); 358 } 359 360 if (!warpSkyfileDropTable(dbh)) { 361 exit(EXIT_FAILURE); 362 } 363 364 psDBCleanup(dbh); 365 } 366 367 { 368 psDB *dbh; 369 370 dbh = psDBInit("localhost", "test", NULL, "test"); 371 if (!dbh) { 372 exit(EXIT_FAILURE); 373 } 374 375 if (!diffRunDropTable(dbh)) { 376 exit(EXIT_FAILURE); 377 } 378 379 psDBCleanup(dbh); 380 } 381 382 { 383 psDB *dbh; 384 385 dbh = psDBInit("localhost", "test", NULL, "test"); 386 if (!dbh) { 387 exit(EXIT_FAILURE); 388 } 389 390 if (!diffInputSkyfileDropTable(dbh)) { 391 exit(EXIT_FAILURE); 392 } 393 394 psDBCleanup(dbh); 395 } 396 397 { 398 psDB *dbh; 399 400 dbh = psDBInit("localhost", "test", NULL, "test"); 401 if (!dbh) { 402 exit(EXIT_FAILURE); 403 } 404 405 if (!diffSkyfileDropTable(dbh)) { 406 exit(EXIT_FAILURE); 407 } 408 409 psDBCleanup(dbh); 410 } 411 412 { 413 psDB *dbh; 414 415 dbh = psDBInit("localhost", "test", NULL, "test"); 416 if (!dbh) { 417 exit(EXIT_FAILURE); 418 } 419 420 if (!stackRunDropTable(dbh)) { 421 exit(EXIT_FAILURE); 422 } 423 424 psDBCleanup(dbh); 425 } 426 427 { 428 psDB *dbh; 429 430 dbh = psDBInit("localhost", "test", NULL, "test"); 431 if (!dbh) { 432 exit(EXIT_FAILURE); 433 } 434 435 if (!stackInputSkyfileDropTable(dbh)) { 436 exit(EXIT_FAILURE); 437 } 438 439 psDBCleanup(dbh); 440 } 441 442 { 443 psDB *dbh; 444 445 dbh = psDBInit("localhost", "test", NULL, "test"); 446 if (!dbh) { 447 exit(EXIT_FAILURE); 448 } 449 450 if (!stackSumSkyfileDropTable(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 315 465 if (!detRunDropTable(dbh)) { 316 466 exit(EXIT_FAILURE); … … 464 614 465 615 if (!detRunSummaryDropTable(dbh)) { 466 exit(EXIT_FAILURE);467 }468 469 psDBCleanup(dbh);470 }471 472 {473 psDB *dbh;474 475 dbh = psDBInit("localhost", "test", NULL, "test");476 if (!dbh) {477 exit(EXIT_FAILURE);478 }479 480 if (!warpRunDropTable(dbh)) {481 exit(EXIT_FAILURE);482 }483 484 psDBCleanup(dbh);485 }486 487 {488 psDB *dbh;489 490 dbh = psDBInit("localhost", "test", NULL, "test");491 if (!dbh) {492 exit(EXIT_FAILURE);493 }494 495 if (!warpInputExpDropTable(dbh)) {496 exit(EXIT_FAILURE);497 }498 499 psDBCleanup(dbh);500 }501 502 {503 psDB *dbh;504 505 dbh = psDBInit("localhost", "test", NULL, "test");506 if (!dbh) {507 exit(EXIT_FAILURE);508 }509 510 if (!warpSkyCellMapDropTable(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 (!warpSkyfileDropTable(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 (!diffRunDropTable(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 (!diffInputSkyfileDropTable(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 (!diffSkyfileDropTable(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 (!stackRunDropTable(dbh)) {586 exit(EXIT_FAILURE);587 }588 589 psDBCleanup(dbh);590 }591 592 {593 psDB *dbh;594 595 dbh = psDBInit("localhost", "test", NULL, "test");596 if (!dbh) {597 exit(EXIT_FAILURE);598 }599 600 if (!stackInputSkyfileDropTable(dbh)) {601 exit(EXIT_FAILURE);602 }603 604 psDBCleanup(dbh);605 }606 607 {608 psDB *dbh;609 610 dbh = psDBInit("localhost", "test", NULL, "test");611 if (!dbh) {612 exit(EXIT_FAILURE);613 }614 615 if (!stackSumSkyfileDropTable(dbh)) {616 616 exit(EXIT_FAILURE); 617 617 } -
trunk/ippdb/tests/insert.c
r12426 r12535 313 313 } 314 314 315 if (!warpRunInsert(dbh, -64, "a string", "a string", "a string", "a string", "0001-01-01T00:00:00Z")) { 316 exit(EXIT_FAILURE); 317 } 318 319 psDBCleanup(dbh); 320 } 321 322 { 323 psDB *dbh; 324 325 dbh = psDBInit("localhost", "test", NULL, "test"); 326 if (!dbh) { 327 exit(EXIT_FAILURE); 328 } 329 330 if (!warpInputExpInsert(dbh, -64, -64, true)) { 331 exit(EXIT_FAILURE); 332 } 333 334 psDBCleanup(dbh); 335 } 336 337 { 338 psDB *dbh; 339 340 dbh = psDBInit("localhost", "test", NULL, "test"); 341 if (!dbh) { 342 exit(EXIT_FAILURE); 343 } 344 345 if (!warpSkyCellMapInsert(dbh, -64, "a string", "a string", -64, "a string", -16)) { 346 exit(EXIT_FAILURE); 347 } 348 349 psDBCleanup(dbh); 350 } 351 352 { 353 psDB *dbh; 354 355 dbh = psDBInit("localhost", "test", NULL, "test"); 356 if (!dbh) { 357 exit(EXIT_FAILURE); 358 } 359 360 if (!warpSkyfileInsert(dbh, -64, "a string", "a string", "a string", 64.64, 64.64)) { 361 exit(EXIT_FAILURE); 362 } 363 364 psDBCleanup(dbh); 365 } 366 367 { 368 psDB *dbh; 369 370 dbh = psDBInit("localhost", "test", NULL, "test"); 371 if (!dbh) { 372 exit(EXIT_FAILURE); 373 } 374 375 if (!diffRunInsert(dbh, -64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string")) { 376 exit(EXIT_FAILURE); 377 } 378 379 psDBCleanup(dbh); 380 } 381 382 { 383 psDB *dbh; 384 385 dbh = psDBInit("localhost", "test", NULL, "test"); 386 if (!dbh) { 387 exit(EXIT_FAILURE); 388 } 389 390 if (!diffInputSkyfileInsert(dbh, -64, -64, "a string", "a string", "a string", true)) { 391 exit(EXIT_FAILURE); 392 } 393 394 psDBCleanup(dbh); 395 } 396 397 { 398 psDB *dbh; 399 400 dbh = psDBInit("localhost", "test", NULL, "test"); 401 if (!dbh) { 402 exit(EXIT_FAILURE); 403 } 404 405 if (!diffSkyfileInsert(dbh, -64, "a string", 64.64, 64.64)) { 406 exit(EXIT_FAILURE); 407 } 408 409 psDBCleanup(dbh); 410 } 411 412 { 413 psDB *dbh; 414 415 dbh = psDBInit("localhost", "test", NULL, "test"); 416 if (!dbh) { 417 exit(EXIT_FAILURE); 418 } 419 420 if (!stackRunInsert(dbh, -64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string")) { 421 exit(EXIT_FAILURE); 422 } 423 424 psDBCleanup(dbh); 425 } 426 427 { 428 psDB *dbh; 429 430 dbh = psDBInit("localhost", "test", NULL, "test"); 431 if (!dbh) { 432 exit(EXIT_FAILURE); 433 } 434 435 if (!stackInputSkyfileInsert(dbh, -64, -64)) { 436 exit(EXIT_FAILURE); 437 } 438 439 psDBCleanup(dbh); 440 } 441 442 { 443 psDB *dbh; 444 445 dbh = psDBInit("localhost", "test", NULL, "test"); 446 if (!dbh) { 447 exit(EXIT_FAILURE); 448 } 449 450 if (!stackSumSkyfileInsert(dbh, -64, "a string", 64.64, 64.64)) { 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 315 465 if (!detRunInsert(dbh, -64, -32, "a string", "a string", "a string", "a string", "a string", "a string", "a string", "a string", "a string", 32.32, 32.32, 32.32, 32.32, 32.32, 32.32, 64.64, 64.64, "0001-01-01T00:00:00Z", "0001-01-01T00:00:00Z", "0001-01-01T00:00:00Z", "0001-01-01T00:00:00Z", "0001-01-01T00:00:00Z", 32.32, 32.32, "a string", -32)) { 316 466 exit(EXIT_FAILURE); … … 464 614 465 615 if (!detRunSummaryInsert(dbh, -64, -32, 64.64, 64.64, 64.64, true, -16)) { 466 exit(EXIT_FAILURE);467 }468 469 psDBCleanup(dbh);470 }471 472 {473 psDB *dbh;474 475 dbh = psDBInit("localhost", "test", NULL, "test");476 if (!dbh) {477 exit(EXIT_FAILURE);478 }479 480 if (!warpRunInsert(dbh, -64, "a string", "a string", "a string", "a string", "0001-01-01T00:00:00Z")) {481 exit(EXIT_FAILURE);482 }483 484 psDBCleanup(dbh);485 }486 487 {488 psDB *dbh;489 490 dbh = psDBInit("localhost", "test", NULL, "test");491 if (!dbh) {492 exit(EXIT_FAILURE);493 }494 495 if (!warpInputExpInsert(dbh, -64, -64, true)) {496 exit(EXIT_FAILURE);497 }498 499 psDBCleanup(dbh);500 }501 502 {503 psDB *dbh;504 505 dbh = psDBInit("localhost", "test", NULL, "test");506 if (!dbh) {507 exit(EXIT_FAILURE);508 }509 510 if (!warpSkyCellMapInsert(dbh, -64, "a string", "a string", -64, "a string", -16)) {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 (!warpSkyfileInsert(dbh, -64, "a string", "a string", "a string", 64.64, 64.64)) {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 (!diffRunInsert(dbh, -64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string")) {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 (!diffInputSkyfileInsert(dbh, -64, -64, "a string", "a string", "a string", true)) {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 (!diffSkyfileInsert(dbh, -64, "a string", 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 (!stackRunInsert(dbh, -64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string")) {586 exit(EXIT_FAILURE);587 }588 589 psDBCleanup(dbh);590 }591 592 {593 psDB *dbh;594 595 dbh = psDBInit("localhost", "test", NULL, "test");596 if (!dbh) {597 exit(EXIT_FAILURE);598 }599 600 if (!stackInputSkyfileInsert(dbh, -64, -64)) {601 exit(EXIT_FAILURE);602 }603 604 psDBCleanup(dbh);605 }606 607 {608 psDB *dbh;609 610 dbh = psDBInit("localhost", "test", NULL, "test");611 if (!dbh) {612 exit(EXIT_FAILURE);613 }614 615 if (!stackSumSkyfileInsert(dbh, -64, "a string", 64.64, 64.64)) {616 616 exit(EXIT_FAILURE); 617 617 } -
trunk/ippdb/tests/insertfits.c
r12026 r12535 544 544 } 545 545 546 if (!warpRunInsertFits(dbh, fits)) { 547 exit(EXIT_FAILURE); 548 } 549 550 if (!psFitsClose(fits)) { 551 exit(EXIT_FAILURE); 552 } 553 554 psDBCleanup(dbh); 555 } 556 557 { 558 psDB *dbh; 559 psFits *fits; 560 561 dbh = psDBInit("localhost", "test", NULL, "test"); 562 if (!dbh) { 563 exit(EXIT_FAILURE); 564 } 565 566 // open a temp 567 fits = psFitsOpen(TMP_FILENAME, "r"); 568 if (!fits) { 569 exit(EXIT_FAILURE); 570 } 571 572 if (!warpInputExpInsertFits(dbh, fits)) { 573 exit(EXIT_FAILURE); 574 } 575 576 if (!psFitsClose(fits)) { 577 exit(EXIT_FAILURE); 578 } 579 580 psDBCleanup(dbh); 581 } 582 583 { 584 psDB *dbh; 585 psFits *fits; 586 587 dbh = psDBInit("localhost", "test", NULL, "test"); 588 if (!dbh) { 589 exit(EXIT_FAILURE); 590 } 591 592 // open a temp 593 fits = psFitsOpen(TMP_FILENAME, "r"); 594 if (!fits) { 595 exit(EXIT_FAILURE); 596 } 597 598 if (!warpSkyCellMapInsertFits(dbh, fits)) { 599 exit(EXIT_FAILURE); 600 } 601 602 if (!psFitsClose(fits)) { 603 exit(EXIT_FAILURE); 604 } 605 606 psDBCleanup(dbh); 607 } 608 609 { 610 psDB *dbh; 611 psFits *fits; 612 613 dbh = psDBInit("localhost", "test", NULL, "test"); 614 if (!dbh) { 615 exit(EXIT_FAILURE); 616 } 617 618 // open a temp 619 fits = psFitsOpen(TMP_FILENAME, "r"); 620 if (!fits) { 621 exit(EXIT_FAILURE); 622 } 623 624 if (!warpSkyfileInsertFits(dbh, fits)) { 625 exit(EXIT_FAILURE); 626 } 627 628 if (!psFitsClose(fits)) { 629 exit(EXIT_FAILURE); 630 } 631 632 psDBCleanup(dbh); 633 } 634 635 { 636 psDB *dbh; 637 psFits *fits; 638 639 dbh = psDBInit("localhost", "test", NULL, "test"); 640 if (!dbh) { 641 exit(EXIT_FAILURE); 642 } 643 644 // open a temp 645 fits = psFitsOpen(TMP_FILENAME, "r"); 646 if (!fits) { 647 exit(EXIT_FAILURE); 648 } 649 650 if (!diffRunInsertFits(dbh, fits)) { 651 exit(EXIT_FAILURE); 652 } 653 654 if (!psFitsClose(fits)) { 655 exit(EXIT_FAILURE); 656 } 657 658 psDBCleanup(dbh); 659 } 660 661 { 662 psDB *dbh; 663 psFits *fits; 664 665 dbh = psDBInit("localhost", "test", NULL, "test"); 666 if (!dbh) { 667 exit(EXIT_FAILURE); 668 } 669 670 // open a temp 671 fits = psFitsOpen(TMP_FILENAME, "r"); 672 if (!fits) { 673 exit(EXIT_FAILURE); 674 } 675 676 if (!diffInputSkyfileInsertFits(dbh, fits)) { 677 exit(EXIT_FAILURE); 678 } 679 680 if (!psFitsClose(fits)) { 681 exit(EXIT_FAILURE); 682 } 683 684 psDBCleanup(dbh); 685 } 686 687 { 688 psDB *dbh; 689 psFits *fits; 690 691 dbh = psDBInit("localhost", "test", NULL, "test"); 692 if (!dbh) { 693 exit(EXIT_FAILURE); 694 } 695 696 // open a temp 697 fits = psFitsOpen(TMP_FILENAME, "r"); 698 if (!fits) { 699 exit(EXIT_FAILURE); 700 } 701 702 if (!diffSkyfileInsertFits(dbh, fits)) { 703 exit(EXIT_FAILURE); 704 } 705 706 if (!psFitsClose(fits)) { 707 exit(EXIT_FAILURE); 708 } 709 710 psDBCleanup(dbh); 711 } 712 713 { 714 psDB *dbh; 715 psFits *fits; 716 717 dbh = psDBInit("localhost", "test", NULL, "test"); 718 if (!dbh) { 719 exit(EXIT_FAILURE); 720 } 721 722 // open a temp 723 fits = psFitsOpen(TMP_FILENAME, "r"); 724 if (!fits) { 725 exit(EXIT_FAILURE); 726 } 727 728 if (!stackRunInsertFits(dbh, fits)) { 729 exit(EXIT_FAILURE); 730 } 731 732 if (!psFitsClose(fits)) { 733 exit(EXIT_FAILURE); 734 } 735 736 psDBCleanup(dbh); 737 } 738 739 { 740 psDB *dbh; 741 psFits *fits; 742 743 dbh = psDBInit("localhost", "test", NULL, "test"); 744 if (!dbh) { 745 exit(EXIT_FAILURE); 746 } 747 748 // open a temp 749 fits = psFitsOpen(TMP_FILENAME, "r"); 750 if (!fits) { 751 exit(EXIT_FAILURE); 752 } 753 754 if (!stackInputSkyfileInsertFits(dbh, fits)) { 755 exit(EXIT_FAILURE); 756 } 757 758 if (!psFitsClose(fits)) { 759 exit(EXIT_FAILURE); 760 } 761 762 psDBCleanup(dbh); 763 } 764 765 { 766 psDB *dbh; 767 psFits *fits; 768 769 dbh = psDBInit("localhost", "test", NULL, "test"); 770 if (!dbh) { 771 exit(EXIT_FAILURE); 772 } 773 774 // open a temp 775 fits = psFitsOpen(TMP_FILENAME, "r"); 776 if (!fits) { 777 exit(EXIT_FAILURE); 778 } 779 780 if (!stackSumSkyfileInsertFits(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 546 806 if (!detRunInsertFits(dbh, fits)) { 547 807 exit(EXIT_FAILURE); … … 805 1065 806 1066 if (!detRunSummaryInsertFits(dbh, fits)) { 807 exit(EXIT_FAILURE);808 }809 810 if (!psFitsClose(fits)) {811 exit(EXIT_FAILURE);812 }813 814 psDBCleanup(dbh);815 }816 817 {818 psDB *dbh;819 psFits *fits;820 821 dbh = psDBInit("localhost", "test", NULL, "test");822 if (!dbh) {823 exit(EXIT_FAILURE);824 }825 826 // open a temp827 fits = psFitsOpen(TMP_FILENAME, "r");828 if (!fits) {829 exit(EXIT_FAILURE);830 }831 832 if (!warpRunInsertFits(dbh, fits)) {833 exit(EXIT_FAILURE);834 }835 836 if (!psFitsClose(fits)) {837 exit(EXIT_FAILURE);838 }839 840 psDBCleanup(dbh);841 }842 843 {844 psDB *dbh;845 psFits *fits;846 847 dbh = psDBInit("localhost", "test", NULL, "test");848 if (!dbh) {849 exit(EXIT_FAILURE);850 }851 852 // open a temp853 fits = psFitsOpen(TMP_FILENAME, "r");854 if (!fits) {855 exit(EXIT_FAILURE);856 }857 858 if (!warpInputExpInsertFits(dbh, fits)) {859 exit(EXIT_FAILURE);860 }861 862 if (!psFitsClose(fits)) {863 exit(EXIT_FAILURE);864 }865 866 psDBCleanup(dbh);867 }868 869 {870 psDB *dbh;871 psFits *fits;872 873 dbh = psDBInit("localhost", "test", NULL, "test");874 if (!dbh) {875 exit(EXIT_FAILURE);876 }877 878 // open a temp879 fits = psFitsOpen(TMP_FILENAME, "r");880 if (!fits) {881 exit(EXIT_FAILURE);882 }883 884 if (!warpSkyCellMapInsertFits(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 temp905 fits = psFitsOpen(TMP_FILENAME, "r");906 if (!fits) {907 exit(EXIT_FAILURE);908 }909 910 if (!warpSkyfileInsertFits(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 temp931 fits = psFitsOpen(TMP_FILENAME, "r");932 if (!fits) {933 exit(EXIT_FAILURE);934 }935 936 if (!diffRunInsertFits(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 temp957 fits = psFitsOpen(TMP_FILENAME, "r");958 if (!fits) {959 exit(EXIT_FAILURE);960 }961 962 if (!diffInputSkyfileInsertFits(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 temp983 fits = psFitsOpen(TMP_FILENAME, "r");984 if (!fits) {985 exit(EXIT_FAILURE);986 }987 988 if (!diffSkyfileInsertFits(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 temp1009 fits = psFitsOpen(TMP_FILENAME, "r");1010 if (!fits) {1011 exit(EXIT_FAILURE);1012 }1013 1014 if (!stackRunInsertFits(dbh, fits)) {1015 exit(EXIT_FAILURE);1016 }1017 1018 if (!psFitsClose(fits)) {1019 exit(EXIT_FAILURE);1020 }1021 1022 psDBCleanup(dbh);1023 }1024 1025 {1026 psDB *dbh;1027 psFits *fits;1028 1029 dbh = psDBInit("localhost", "test", NULL, "test");1030 if (!dbh) {1031 exit(EXIT_FAILURE);1032 }1033 1034 // open a temp1035 fits = psFitsOpen(TMP_FILENAME, "r");1036 if (!fits) {1037 exit(EXIT_FAILURE);1038 }1039 1040 if (!stackInputSkyfileInsertFits(dbh, fits)) {1041 exit(EXIT_FAILURE);1042 }1043 1044 if (!psFitsClose(fits)) {1045 exit(EXIT_FAILURE);1046 }1047 1048 psDBCleanup(dbh);1049 }1050 1051 {1052 psDB *dbh;1053 psFits *fits;1054 1055 dbh = psDBInit("localhost", "test", NULL, "test");1056 if (!dbh) {1057 exit(EXIT_FAILURE);1058 }1059 1060 // open a temp1061 fits = psFitsOpen(TMP_FILENAME, "r");1062 if (!fits) {1063 exit(EXIT_FAILURE);1064 }1065 1066 if (!stackSumSkyfileInsertFits(dbh, fits)) {1067 1067 exit(EXIT_FAILURE); 1068 1068 } -
trunk/ippdb/tests/insertobject.c
r12426 r12535 447 447 { 448 448 psDB *dbh; 449 warpRunRow *object; 450 451 dbh = psDBInit("localhost", "test", NULL, "test"); 452 if (!dbh) { 453 exit(EXIT_FAILURE); 454 } 455 456 object = warpRunRowAlloc(-64, "a string", "a string", "a string", "a string", "0001-01-01T00:00:00Z"); 457 if (!object) { 458 exit(EXIT_FAILURE); 459 } 460 461 if (!warpRunInsertObject(dbh, object)) { 462 exit(EXIT_FAILURE); 463 } 464 465 psFree(object); 466 psDBCleanup(dbh); 467 } 468 469 { 470 psDB *dbh; 471 warpInputExpRow *object; 472 473 dbh = psDBInit("localhost", "test", NULL, "test"); 474 if (!dbh) { 475 exit(EXIT_FAILURE); 476 } 477 478 object = warpInputExpRowAlloc(-64, -64, true); 479 if (!object) { 480 exit(EXIT_FAILURE); 481 } 482 483 if (!warpInputExpInsertObject(dbh, object)) { 484 exit(EXIT_FAILURE); 485 } 486 487 psFree(object); 488 psDBCleanup(dbh); 489 } 490 491 { 492 psDB *dbh; 493 warpSkyCellMapRow *object; 494 495 dbh = psDBInit("localhost", "test", NULL, "test"); 496 if (!dbh) { 497 exit(EXIT_FAILURE); 498 } 499 500 object = warpSkyCellMapRowAlloc(-64, "a string", "a string", -64, "a string", -16); 501 if (!object) { 502 exit(EXIT_FAILURE); 503 } 504 505 if (!warpSkyCellMapInsertObject(dbh, object)) { 506 exit(EXIT_FAILURE); 507 } 508 509 psFree(object); 510 psDBCleanup(dbh); 511 } 512 513 { 514 psDB *dbh; 515 warpSkyfileRow *object; 516 517 dbh = psDBInit("localhost", "test", NULL, "test"); 518 if (!dbh) { 519 exit(EXIT_FAILURE); 520 } 521 522 object = warpSkyfileRowAlloc(-64, "a string", "a string", "a string", 64.64, 64.64); 523 if (!object) { 524 exit(EXIT_FAILURE); 525 } 526 527 if (!warpSkyfileInsertObject(dbh, object)) { 528 exit(EXIT_FAILURE); 529 } 530 531 psFree(object); 532 psDBCleanup(dbh); 533 } 534 535 { 536 psDB *dbh; 537 diffRunRow *object; 538 539 dbh = psDBInit("localhost", "test", NULL, "test"); 540 if (!dbh) { 541 exit(EXIT_FAILURE); 542 } 543 544 object = diffRunRowAlloc(-64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string"); 545 if (!object) { 546 exit(EXIT_FAILURE); 547 } 548 549 if (!diffRunInsertObject(dbh, object)) { 550 exit(EXIT_FAILURE); 551 } 552 553 psFree(object); 554 psDBCleanup(dbh); 555 } 556 557 { 558 psDB *dbh; 559 diffInputSkyfileRow *object; 560 561 dbh = psDBInit("localhost", "test", NULL, "test"); 562 if (!dbh) { 563 exit(EXIT_FAILURE); 564 } 565 566 object = diffInputSkyfileRowAlloc(-64, -64, "a string", "a string", "a string", true); 567 if (!object) { 568 exit(EXIT_FAILURE); 569 } 570 571 if (!diffInputSkyfileInsertObject(dbh, object)) { 572 exit(EXIT_FAILURE); 573 } 574 575 psFree(object); 576 psDBCleanup(dbh); 577 } 578 579 { 580 psDB *dbh; 581 diffSkyfileRow *object; 582 583 dbh = psDBInit("localhost", "test", NULL, "test"); 584 if (!dbh) { 585 exit(EXIT_FAILURE); 586 } 587 588 object = diffSkyfileRowAlloc(-64, "a string", 64.64, 64.64); 589 if (!object) { 590 exit(EXIT_FAILURE); 591 } 592 593 if (!diffSkyfileInsertObject(dbh, object)) { 594 exit(EXIT_FAILURE); 595 } 596 597 psFree(object); 598 psDBCleanup(dbh); 599 } 600 601 { 602 psDB *dbh; 603 stackRunRow *object; 604 605 dbh = psDBInit("localhost", "test", NULL, "test"); 606 if (!dbh) { 607 exit(EXIT_FAILURE); 608 } 609 610 object = stackRunRowAlloc(-64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string"); 611 if (!object) { 612 exit(EXIT_FAILURE); 613 } 614 615 if (!stackRunInsertObject(dbh, object)) { 616 exit(EXIT_FAILURE); 617 } 618 619 psFree(object); 620 psDBCleanup(dbh); 621 } 622 623 { 624 psDB *dbh; 625 stackInputSkyfileRow *object; 626 627 dbh = psDBInit("localhost", "test", NULL, "test"); 628 if (!dbh) { 629 exit(EXIT_FAILURE); 630 } 631 632 object = stackInputSkyfileRowAlloc(-64, -64); 633 if (!object) { 634 exit(EXIT_FAILURE); 635 } 636 637 if (!stackInputSkyfileInsertObject(dbh, object)) { 638 exit(EXIT_FAILURE); 639 } 640 641 psFree(object); 642 psDBCleanup(dbh); 643 } 644 645 { 646 psDB *dbh; 647 stackSumSkyfileRow *object; 648 649 dbh = psDBInit("localhost", "test", NULL, "test"); 650 if (!dbh) { 651 exit(EXIT_FAILURE); 652 } 653 654 object = stackSumSkyfileRowAlloc(-64, "a string", 64.64, 64.64); 655 if (!object) { 656 exit(EXIT_FAILURE); 657 } 658 659 if (!stackSumSkyfileInsertObject(dbh, object)) { 660 exit(EXIT_FAILURE); 661 } 662 663 psFree(object); 664 psDBCleanup(dbh); 665 } 666 667 { 668 psDB *dbh; 449 669 detRunRow *object; 450 670 … … 680 900 681 901 if (!detRunSummaryInsertObject(dbh, object)) { 682 exit(EXIT_FAILURE);683 }684 685 psFree(object);686 psDBCleanup(dbh);687 }688 689 {690 psDB *dbh;691 warpRunRow *object;692 693 dbh = psDBInit("localhost", "test", NULL, "test");694 if (!dbh) {695 exit(EXIT_FAILURE);696 }697 698 object = warpRunRowAlloc(-64, "a string", "a string", "a string", "a string", "0001-01-01T00:00:00Z");699 if (!object) {700 exit(EXIT_FAILURE);701 }702 703 if (!warpRunInsertObject(dbh, object)) {704 exit(EXIT_FAILURE);705 }706 707 psFree(object);708 psDBCleanup(dbh);709 }710 711 {712 psDB *dbh;713 warpInputExpRow *object;714 715 dbh = psDBInit("localhost", "test", NULL, "test");716 if (!dbh) {717 exit(EXIT_FAILURE);718 }719 720 object = warpInputExpRowAlloc(-64, -64, true);721 if (!object) {722 exit(EXIT_FAILURE);723 }724 725 if (!warpInputExpInsertObject(dbh, object)) {726 exit(EXIT_FAILURE);727 }728 729 psFree(object);730 psDBCleanup(dbh);731 }732 733 {734 psDB *dbh;735 warpSkyCellMapRow *object;736 737 dbh = psDBInit("localhost", "test", NULL, "test");738 if (!dbh) {739 exit(EXIT_FAILURE);740 }741 742 object = warpSkyCellMapRowAlloc(-64, "a string", "a string", -64, "a string", -16);743 if (!object) {744 exit(EXIT_FAILURE);745 }746 747 if (!warpSkyCellMapInsertObject(dbh, object)) {748 exit(EXIT_FAILURE);749 }750 751 psFree(object);752 psDBCleanup(dbh);753 }754 755 {756 psDB *dbh;757 warpSkyfileRow *object;758 759 dbh = psDBInit("localhost", "test", NULL, "test");760 if (!dbh) {761 exit(EXIT_FAILURE);762 }763 764 object = warpSkyfileRowAlloc(-64, "a string", "a string", "a string", 64.64, 64.64);765 if (!object) {766 exit(EXIT_FAILURE);767 }768 769 if (!warpSkyfileInsertObject(dbh, object)) {770 exit(EXIT_FAILURE);771 }772 773 psFree(object);774 psDBCleanup(dbh);775 }776 777 {778 psDB *dbh;779 diffRunRow *object;780 781 dbh = psDBInit("localhost", "test", NULL, "test");782 if (!dbh) {783 exit(EXIT_FAILURE);784 }785 786 object = diffRunRowAlloc(-64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string");787 if (!object) {788 exit(EXIT_FAILURE);789 }790 791 if (!diffRunInsertObject(dbh, object)) {792 exit(EXIT_FAILURE);793 }794 795 psFree(object);796 psDBCleanup(dbh);797 }798 799 {800 psDB *dbh;801 diffInputSkyfileRow *object;802 803 dbh = psDBInit("localhost", "test", NULL, "test");804 if (!dbh) {805 exit(EXIT_FAILURE);806 }807 808 object = diffInputSkyfileRowAlloc(-64, -64, "a string", "a string", "a string", true);809 if (!object) {810 exit(EXIT_FAILURE);811 }812 813 if (!diffInputSkyfileInsertObject(dbh, object)) {814 exit(EXIT_FAILURE);815 }816 817 psFree(object);818 psDBCleanup(dbh);819 }820 821 {822 psDB *dbh;823 diffSkyfileRow *object;824 825 dbh = psDBInit("localhost", "test", NULL, "test");826 if (!dbh) {827 exit(EXIT_FAILURE);828 }829 830 object = diffSkyfileRowAlloc(-64, "a string", 64.64, 64.64);831 if (!object) {832 exit(EXIT_FAILURE);833 }834 835 if (!diffSkyfileInsertObject(dbh, object)) {836 exit(EXIT_FAILURE);837 }838 839 psFree(object);840 psDBCleanup(dbh);841 }842 843 {844 psDB *dbh;845 stackRunRow *object;846 847 dbh = psDBInit("localhost", "test", NULL, "test");848 if (!dbh) {849 exit(EXIT_FAILURE);850 }851 852 object = stackRunRowAlloc(-64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string");853 if (!object) {854 exit(EXIT_FAILURE);855 }856 857 if (!stackRunInsertObject(dbh, object)) {858 exit(EXIT_FAILURE);859 }860 861 psFree(object);862 psDBCleanup(dbh);863 }864 865 {866 psDB *dbh;867 stackInputSkyfileRow *object;868 869 dbh = psDBInit("localhost", "test", NULL, "test");870 if (!dbh) {871 exit(EXIT_FAILURE);872 }873 874 object = stackInputSkyfileRowAlloc(-64, -64);875 if (!object) {876 exit(EXIT_FAILURE);877 }878 879 if (!stackInputSkyfileInsertObject(dbh, object)) {880 exit(EXIT_FAILURE);881 }882 883 psFree(object);884 psDBCleanup(dbh);885 }886 887 {888 psDB *dbh;889 stackSumSkyfileRow *object;890 891 dbh = psDBInit("localhost", "test", NULL, "test");892 if (!dbh) {893 exit(EXIT_FAILURE);894 }895 896 object = stackSumSkyfileRowAlloc(-64, "a string", 64.64, 64.64);897 if (!object) {898 exit(EXIT_FAILURE);899 }900 901 if (!stackSumSkyfileInsertObject(dbh, object)) {902 902 exit(EXIT_FAILURE); 903 903 } -
trunk/ippdb/tests/metadatafromobject.c
r12426 r12535 999 999 { 1000 1000 psMetadata *md; 1001 warpRunRow *object; 1002 bool status; 1003 1004 object = warpRunRowAlloc(-64, "a string", "a string", "a string", "a string", "0001-01-01T00:00:00Z"); 1005 if (!object) { 1006 exit(EXIT_FAILURE); 1007 } 1008 1009 md = warpRunMetadataFromObject(object); 1010 if (!md) { 1011 exit(EXIT_FAILURE); 1012 } 1013 1014 psFree(object); 1015 1016 psFree(md); 1017 exit(EXIT_FAILURE); 1018 } 1019 if (strncmp(psMetadataLookupPtr(&status, md, "mode"), "a string", MAX_STRING_LENGTH)) { 1020 psFree(md); 1021 exit(EXIT_FAILURE); 1022 } 1023 if (strncmp(psMetadataLookupPtr(&status, md, "state"), "a string", MAX_STRING_LENGTH)) { 1024 psFree(md); 1025 exit(EXIT_FAILURE); 1026 } 1027 if (strncmp(psMetadataLookupPtr(&status, md, "workdir"), "a string", MAX_STRING_LENGTH)) { 1028 psFree(md); 1029 exit(EXIT_FAILURE); 1030 } 1031 if (strncmp(psMetadataLookupPtr(&status, md, "dvodb"), "a string", MAX_STRING_LENGTH)) { 1032 psFree(md); 1033 exit(EXIT_FAILURE); 1034 } 1035 psFree(md); 1036 exit(EXIT_FAILURE); 1037 } 1038 1039 psFree(md); 1040 } 1041 1042 { 1043 psMetadata *md; 1044 warpInputExpRow *object; 1045 bool status; 1046 1047 object = warpInputExpRowAlloc(-64, -64, true); 1048 if (!object) { 1049 exit(EXIT_FAILURE); 1050 } 1051 1052 md = warpInputExpMetadataFromObject(object); 1053 if (!md) { 1054 exit(EXIT_FAILURE); 1055 } 1056 1057 psFree(object); 1058 1059 psFree(md); 1060 exit(EXIT_FAILURE); 1061 } 1062 psFree(md); 1063 exit(EXIT_FAILURE); 1064 } 1065 if (!psMetadataLookupBool(&status, md, "magiced") == true) { 1066 psFree(md); 1067 exit(EXIT_FAILURE); 1068 } 1069 1070 psFree(md); 1071 } 1072 1073 { 1074 psMetadata *md; 1075 warpSkyCellMapRow *object; 1076 bool status; 1077 1078 object = warpSkyCellMapRowAlloc(-64, "a string", "a string", -64, "a string", -16); 1079 if (!object) { 1080 exit(EXIT_FAILURE); 1081 } 1082 1083 md = warpSkyCellMapMetadataFromObject(object); 1084 if (!md) { 1085 exit(EXIT_FAILURE); 1086 } 1087 1088 psFree(object); 1089 1090 psFree(md); 1091 exit(EXIT_FAILURE); 1092 } 1093 if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) { 1094 psFree(md); 1095 exit(EXIT_FAILURE); 1096 } 1097 if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) { 1098 psFree(md); 1099 exit(EXIT_FAILURE); 1100 } 1101 psFree(md); 1102 exit(EXIT_FAILURE); 1103 } 1104 if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) { 1105 psFree(md); 1106 exit(EXIT_FAILURE); 1107 } 1108 psFree(md); 1109 exit(EXIT_FAILURE); 1110 } 1111 1112 psFree(md); 1113 } 1114 1115 { 1116 psMetadata *md; 1117 warpSkyfileRow *object; 1118 bool status; 1119 1120 object = warpSkyfileRowAlloc(-64, "a string", "a string", "a string", 64.64, 64.64); 1121 if (!object) { 1122 exit(EXIT_FAILURE); 1123 } 1124 1125 md = warpSkyfileMetadataFromObject(object); 1126 if (!md) { 1127 exit(EXIT_FAILURE); 1128 } 1129 1130 psFree(object); 1131 1132 psFree(md); 1133 exit(EXIT_FAILURE); 1134 } 1135 if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) { 1136 psFree(md); 1137 exit(EXIT_FAILURE); 1138 } 1139 if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) { 1140 psFree(md); 1141 exit(EXIT_FAILURE); 1142 } 1143 if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) { 1144 psFree(md); 1145 exit(EXIT_FAILURE); 1146 } 1147 if (!psMetadataLookupF64(&status, md, "bg") == 64.64) { 1148 psFree(md); 1149 exit(EXIT_FAILURE); 1150 } 1151 if (!psMetadataLookupF64(&status, md, "bg_stdev") == 64.64) { 1152 psFree(md); 1153 exit(EXIT_FAILURE); 1154 } 1155 1156 psFree(md); 1157 } 1158 1159 { 1160 psMetadata *md; 1161 diffRunRow *object; 1162 bool status; 1163 1164 object = diffRunRowAlloc(-64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string"); 1165 if (!object) { 1166 exit(EXIT_FAILURE); 1167 } 1168 1169 md = diffRunMetadataFromObject(object); 1170 if (!md) { 1171 exit(EXIT_FAILURE); 1172 } 1173 1174 psFree(object); 1175 1176 psFree(md); 1177 exit(EXIT_FAILURE); 1178 } 1179 if (strncmp(psMetadataLookupPtr(&status, md, "state"), "a string", MAX_STRING_LENGTH)) { 1180 psFree(md); 1181 exit(EXIT_FAILURE); 1182 } 1183 if (strncmp(psMetadataLookupPtr(&status, md, "workdir"), "a string", MAX_STRING_LENGTH)) { 1184 psFree(md); 1185 exit(EXIT_FAILURE); 1186 } 1187 if (strncmp(psMetadataLookupPtr(&status, md, "dvodb"), "a string", MAX_STRING_LENGTH)) { 1188 psFree(md); 1189 exit(EXIT_FAILURE); 1190 } 1191 psFree(md); 1192 exit(EXIT_FAILURE); 1193 } 1194 if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) { 1195 psFree(md); 1196 exit(EXIT_FAILURE); 1197 } 1198 if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) { 1199 psFree(md); 1200 exit(EXIT_FAILURE); 1201 } 1202 1203 psFree(md); 1204 } 1205 1206 { 1207 psMetadata *md; 1208 diffInputSkyfileRow *object; 1209 bool status; 1210 1211 object = diffInputSkyfileRowAlloc(-64, -64, "a string", "a string", "a string", true); 1212 if (!object) { 1213 exit(EXIT_FAILURE); 1214 } 1215 1216 md = diffInputSkyfileMetadataFromObject(object); 1217 if (!md) { 1218 exit(EXIT_FAILURE); 1219 } 1220 1221 psFree(object); 1222 1223 psFree(md); 1224 exit(EXIT_FAILURE); 1225 } 1226 psFree(md); 1227 exit(EXIT_FAILURE); 1228 } 1229 if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) { 1230 psFree(md); 1231 exit(EXIT_FAILURE); 1232 } 1233 if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) { 1234 psFree(md); 1235 exit(EXIT_FAILURE); 1236 } 1237 if (strncmp(psMetadataLookupPtr(&status, md, "kind"), "a string", MAX_STRING_LENGTH)) { 1238 psFree(md); 1239 exit(EXIT_FAILURE); 1240 } 1241 if (!psMetadataLookupBool(&status, md, "template") == true) { 1242 psFree(md); 1243 exit(EXIT_FAILURE); 1244 } 1245 1246 psFree(md); 1247 } 1248 1249 { 1250 psMetadata *md; 1251 diffSkyfileRow *object; 1252 bool status; 1253 1254 object = diffSkyfileRowAlloc(-64, "a string", 64.64, 64.64); 1255 if (!object) { 1256 exit(EXIT_FAILURE); 1257 } 1258 1259 md = diffSkyfileMetadataFromObject(object); 1260 if (!md) { 1261 exit(EXIT_FAILURE); 1262 } 1263 1264 psFree(object); 1265 1266 psFree(md); 1267 exit(EXIT_FAILURE); 1268 } 1269 if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) { 1270 psFree(md); 1271 exit(EXIT_FAILURE); 1272 } 1273 if (!psMetadataLookupF64(&status, md, "bg") == 64.64) { 1274 psFree(md); 1275 exit(EXIT_FAILURE); 1276 } 1277 if (!psMetadataLookupF64(&status, md, "bg_stdev") == 64.64) { 1278 psFree(md); 1279 exit(EXIT_FAILURE); 1280 } 1281 1282 psFree(md); 1283 } 1284 1285 { 1286 psMetadata *md; 1287 stackRunRow *object; 1288 bool status; 1289 1290 object = stackRunRowAlloc(-64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string"); 1291 if (!object) { 1292 exit(EXIT_FAILURE); 1293 } 1294 1295 md = stackRunMetadataFromObject(object); 1296 if (!md) { 1297 exit(EXIT_FAILURE); 1298 } 1299 1300 psFree(object); 1301 1302 psFree(md); 1303 exit(EXIT_FAILURE); 1304 } 1305 if (strncmp(psMetadataLookupPtr(&status, md, "state"), "a string", MAX_STRING_LENGTH)) { 1306 psFree(md); 1307 exit(EXIT_FAILURE); 1308 } 1309 if (strncmp(psMetadataLookupPtr(&status, md, "workdir"), "a string", MAX_STRING_LENGTH)) { 1310 psFree(md); 1311 exit(EXIT_FAILURE); 1312 } 1313 if (strncmp(psMetadataLookupPtr(&status, md, "dvodb"), "a string", MAX_STRING_LENGTH)) { 1314 psFree(md); 1315 exit(EXIT_FAILURE); 1316 } 1317 psFree(md); 1318 exit(EXIT_FAILURE); 1319 } 1320 if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) { 1321 psFree(md); 1322 exit(EXIT_FAILURE); 1323 } 1324 if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) { 1325 psFree(md); 1326 exit(EXIT_FAILURE); 1327 } 1328 1329 psFree(md); 1330 } 1331 1332 { 1333 psMetadata *md; 1334 stackInputSkyfileRow *object; 1335 bool status; 1336 1337 object = stackInputSkyfileRowAlloc(-64, -64); 1338 if (!object) { 1339 exit(EXIT_FAILURE); 1340 } 1341 1342 md = stackInputSkyfileMetadataFromObject(object); 1343 if (!md) { 1344 exit(EXIT_FAILURE); 1345 } 1346 1347 psFree(object); 1348 1349 psFree(md); 1350 exit(EXIT_FAILURE); 1351 } 1352 psFree(md); 1353 exit(EXIT_FAILURE); 1354 } 1355 1356 psFree(md); 1357 } 1358 1359 { 1360 psMetadata *md; 1361 stackSumSkyfileRow *object; 1362 bool status; 1363 1364 object = stackSumSkyfileRowAlloc(-64, "a string", 64.64, 64.64); 1365 if (!object) { 1366 exit(EXIT_FAILURE); 1367 } 1368 1369 md = stackSumSkyfileMetadataFromObject(object); 1370 if (!md) { 1371 exit(EXIT_FAILURE); 1372 } 1373 1374 psFree(object); 1375 1376 psFree(md); 1377 exit(EXIT_FAILURE); 1378 } 1379 if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) { 1380 psFree(md); 1381 exit(EXIT_FAILURE); 1382 } 1383 if (!psMetadataLookupF64(&status, md, "bg") == 64.64) { 1384 psFree(md); 1385 exit(EXIT_FAILURE); 1386 } 1387 if (!psMetadataLookupF64(&status, md, "bg_stdev") == 64.64) { 1388 psFree(md); 1389 exit(EXIT_FAILURE); 1390 } 1391 1392 psFree(md); 1393 } 1394 1395 { 1396 psMetadata *md; 1001 1397 detRunRow *object; 1002 1398 bool status; … … 1632 2028 exit(EXIT_FAILURE); 1633 2029 } 1634 psFree(md);1635 exit(EXIT_FAILURE);1636 }1637 1638 psFree(md);1639 }1640 1641 {1642 psMetadata *md;1643 warpRunRow *object;1644 bool status;1645 1646 object = warpRunRowAlloc(-64, "a string", "a string", "a string", "a string", "0001-01-01T00:00:00Z");1647 if (!object) {1648 exit(EXIT_FAILURE);1649 }1650 1651 md = warpRunMetadataFromObject(object);1652 if (!md) {1653 exit(EXIT_FAILURE);1654 }1655 1656 psFree(object);1657 1658 psFree(md);1659 exit(EXIT_FAILURE);1660 }1661 if (strncmp(psMetadataLookupPtr(&status, md, "mode"), "a string", MAX_STRING_LENGTH)) {1662 psFree(md);1663 exit(EXIT_FAILURE);1664 }1665 if (strncmp(psMetadataLookupPtr(&status, md, "state"), "a string", MAX_STRING_LENGTH)) {1666 psFree(md);1667 exit(EXIT_FAILURE);1668 }1669 if (strncmp(psMetadataLookupPtr(&status, md, "workdir"), "a string", MAX_STRING_LENGTH)) {1670 psFree(md);1671 exit(EXIT_FAILURE);1672 }1673 if (strncmp(psMetadataLookupPtr(&status, md, "dvodb"), "a string", MAX_STRING_LENGTH)) {1674 psFree(md);1675 exit(EXIT_FAILURE);1676 }1677 psFree(md);1678 exit(EXIT_FAILURE);1679 }1680 1681 psFree(md);1682 }1683 1684 {1685 psMetadata *md;1686 warpInputExpRow *object;1687 bool status;1688 1689 object = warpInputExpRowAlloc(-64, -64, true);1690 if (!object) {1691 exit(EXIT_FAILURE);1692 }1693 1694 md = warpInputExpMetadataFromObject(object);1695 if (!md) {1696 exit(EXIT_FAILURE);1697 }1698 1699 psFree(object);1700 1701 psFree(md);1702 exit(EXIT_FAILURE);1703 }1704 psFree(md);1705 exit(EXIT_FAILURE);1706 }1707 if (!psMetadataLookupBool(&status, md, "magiced") == true) {1708 psFree(md);1709 exit(EXIT_FAILURE);1710 }1711 1712 psFree(md);1713 }1714 1715 {1716 psMetadata *md;1717 warpSkyCellMapRow *object;1718 bool status;1719 1720 object = warpSkyCellMapRowAlloc(-64, "a string", "a string", -64, "a string", -16);1721 if (!object) {1722 exit(EXIT_FAILURE);1723 }1724 1725 md = warpSkyCellMapMetadataFromObject(object);1726 if (!md) {1727 exit(EXIT_FAILURE);1728 }1729 1730 psFree(object);1731 1732 psFree(md);1733 exit(EXIT_FAILURE);1734 }1735 if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {1736 psFree(md);1737 exit(EXIT_FAILURE);1738 }1739 if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {1740 psFree(md);1741 exit(EXIT_FAILURE);1742 }1743 psFree(md);1744 exit(EXIT_FAILURE);1745 }1746 if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) {1747 psFree(md);1748 exit(EXIT_FAILURE);1749 }1750 psFree(md);1751 exit(EXIT_FAILURE);1752 }1753 1754 psFree(md);1755 }1756 1757 {1758 psMetadata *md;1759 warpSkyfileRow *object;1760 bool status;1761 1762 object = warpSkyfileRowAlloc(-64, "a string", "a string", "a string", 64.64, 64.64);1763 if (!object) {1764 exit(EXIT_FAILURE);1765 }1766 1767 md = warpSkyfileMetadataFromObject(object);1768 if (!md) {1769 exit(EXIT_FAILURE);1770 }1771 1772 psFree(object);1773 1774 psFree(md);1775 exit(EXIT_FAILURE);1776 }1777 if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {1778 psFree(md);1779 exit(EXIT_FAILURE);1780 }1781 if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {1782 psFree(md);1783 exit(EXIT_FAILURE);1784 }1785 if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) {1786 psFree(md);1787 exit(EXIT_FAILURE);1788 }1789 if (!psMetadataLookupF64(&status, md, "bg") == 64.64) {1790 psFree(md);1791 exit(EXIT_FAILURE);1792 }1793 if (!psMetadataLookupF64(&status, md, "bg_stdev") == 64.64) {1794 psFree(md);1795 exit(EXIT_FAILURE);1796 }1797 1798 psFree(md);1799 }1800 1801 {1802 psMetadata *md;1803 diffRunRow *object;1804 bool status;1805 1806 object = diffRunRowAlloc(-64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string");1807 if (!object) {1808 exit(EXIT_FAILURE);1809 }1810 1811 md = diffRunMetadataFromObject(object);1812 if (!md) {1813 exit(EXIT_FAILURE);1814 }1815 1816 psFree(object);1817 1818 psFree(md);1819 exit(EXIT_FAILURE);1820 }1821 if (strncmp(psMetadataLookupPtr(&status, md, "state"), "a string", MAX_STRING_LENGTH)) {1822 psFree(md);1823 exit(EXIT_FAILURE);1824 }1825 if (strncmp(psMetadataLookupPtr(&status, md, "workdir"), "a string", MAX_STRING_LENGTH)) {1826 psFree(md);1827 exit(EXIT_FAILURE);1828 }1829 if (strncmp(psMetadataLookupPtr(&status, md, "dvodb"), "a string", MAX_STRING_LENGTH)) {1830 psFree(md);1831 exit(EXIT_FAILURE);1832 }1833 psFree(md);1834 exit(EXIT_FAILURE);1835 }1836 if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {1837 psFree(md);1838 exit(EXIT_FAILURE);1839 }1840 if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {1841 psFree(md);1842 exit(EXIT_FAILURE);1843 }1844 1845 psFree(md);1846 }1847 1848 {1849 psMetadata *md;1850 diffInputSkyfileRow *object;1851 bool status;1852 1853 object = diffInputSkyfileRowAlloc(-64, -64, "a string", "a string", "a string", true);1854 if (!object) {1855 exit(EXIT_FAILURE);1856 }1857 1858 md = diffInputSkyfileMetadataFromObject(object);1859 if (!md) {1860 exit(EXIT_FAILURE);1861 }1862 1863 psFree(object);1864 1865 psFree(md);1866 exit(EXIT_FAILURE);1867 }1868 psFree(md);1869 exit(EXIT_FAILURE);1870 }1871 if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {1872 psFree(md);1873 exit(EXIT_FAILURE);1874 }1875 if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {1876 psFree(md);1877 exit(EXIT_FAILURE);1878 }1879 if (strncmp(psMetadataLookupPtr(&status, md, "kind"), "a string", MAX_STRING_LENGTH)) {1880 psFree(md);1881 exit(EXIT_FAILURE);1882 }1883 if (!psMetadataLookupBool(&status, md, "template") == true) {1884 psFree(md);1885 exit(EXIT_FAILURE);1886 }1887 1888 psFree(md);1889 }1890 1891 {1892 psMetadata *md;1893 diffSkyfileRow *object;1894 bool status;1895 1896 object = diffSkyfileRowAlloc(-64, "a string", 64.64, 64.64);1897 if (!object) {1898 exit(EXIT_FAILURE);1899 }1900 1901 md = diffSkyfileMetadataFromObject(object);1902 if (!md) {1903 exit(EXIT_FAILURE);1904 }1905 1906 psFree(object);1907 1908 psFree(md);1909 exit(EXIT_FAILURE);1910 }1911 if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) {1912 psFree(md);1913 exit(EXIT_FAILURE);1914 }1915 if (!psMetadataLookupF64(&status, md, "bg") == 64.64) {1916 psFree(md);1917 exit(EXIT_FAILURE);1918 }1919 if (!psMetadataLookupF64(&status, md, "bg_stdev") == 64.64) {1920 psFree(md);1921 exit(EXIT_FAILURE);1922 }1923 1924 psFree(md);1925 }1926 1927 {1928 psMetadata *md;1929 stackRunRow *object;1930 bool status;1931 1932 object = stackRunRowAlloc(-64, "a string", "a string", "a string", "0001-01-01T00:00:00Z", "a string", "a string");1933 if (!object) {1934 exit(EXIT_FAILURE);1935 }1936 1937 md = stackRunMetadataFromObject(object);1938 if (!md) {1939 exit(EXIT_FAILURE);1940 }1941 1942 psFree(object);1943 1944 psFree(md);1945 exit(EXIT_FAILURE);1946 }1947 if (strncmp(psMetadataLookupPtr(&status, md, "state"), "a string", MAX_STRING_LENGTH)) {1948 psFree(md);1949 exit(EXIT_FAILURE);1950 }1951 if (strncmp(psMetadataLookupPtr(&status, md, "workdir"), "a string", MAX_STRING_LENGTH)) {1952 psFree(md);1953 exit(EXIT_FAILURE);1954 }1955 if (strncmp(psMetadataLookupPtr(&status, md, "dvodb"), "a string", MAX_STRING_LENGTH)) {1956 psFree(md);1957 exit(EXIT_FAILURE);1958 }1959 psFree(md);1960 exit(EXIT_FAILURE);1961 }1962 if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {1963 psFree(md);1964 exit(EXIT_FAILURE);1965 }1966 if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {1967 psFree(md);1968 exit(EXIT_FAILURE);1969 }1970 1971 psFree(md);1972 }1973 1974 {1975 psMetadata *md;1976 stackInputSkyfileRow *object;1977 bool status;1978 1979 object = stackInputSkyfileRowAlloc(-64, -64);1980 if (!object) {1981 exit(EXIT_FAILURE);1982 }1983 1984 md = stackInputSkyfileMetadataFromObject(object);1985 if (!md) {1986 exit(EXIT_FAILURE);1987 }1988 1989 psFree(object);1990 1991 psFree(md);1992 exit(EXIT_FAILURE);1993 }1994 psFree(md);1995 exit(EXIT_FAILURE);1996 }1997 1998 psFree(md);1999 }2000 2001 {2002 psMetadata *md;2003 stackSumSkyfileRow *object;2004 bool status;2005 2006 object = stackSumSkyfileRowAlloc(-64, "a string", 64.64, 64.64);2007 if (!object) {2008 exit(EXIT_FAILURE);2009 }2010 2011 md = stackSumSkyfileMetadataFromObject(object);2012 if (!md) {2013 exit(EXIT_FAILURE);2014 }2015 2016 psFree(object);2017 2018 psFree(md);2019 exit(EXIT_FAILURE);2020 }2021 if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) {2022 psFree(md);2023 exit(EXIT_FAILURE);2024 }2025 if (!psMetadataLookupF64(&status, md, "bg") == 64.64) {2026 psFree(md);2027 exit(EXIT_FAILURE);2028 }2029 if (!psMetadataLookupF64(&status, md, "bg_stdev") == 64.64) {2030 2030 psFree(md); 2031 2031 exit(EXIT_FAILURE); -
trunk/ippdb/tests/objectfrommetadata.c
r12426 r12535 1508 1508 { 1509 1509 psMetadata *md; 1510 warpRunRow *object; 1511 1512 md = psMetadataAlloc(); 1513 psFree(md); 1514 exit(EXIT_FAILURE); 1515 } 1516 if (!psMetadataAddStr(md, PS_LIST_TAIL, "mode", 0, NULL, "a string")) { 1517 psFree(md); 1518 exit(EXIT_FAILURE); 1519 } 1520 if (!psMetadataAddStr(md, PS_LIST_TAIL, "state", 0, NULL, "a string")) { 1521 psFree(md); 1522 exit(EXIT_FAILURE); 1523 } 1524 if (!psMetadataAddStr(md, PS_LIST_TAIL, "workdir", 0, NULL, "a string")) { 1525 psFree(md); 1526 exit(EXIT_FAILURE); 1527 } 1528 if (!psMetadataAddStr(md, PS_LIST_TAIL, "dvodb", 0, NULL, "a string")) { 1529 psFree(md); 1530 exit(EXIT_FAILURE); 1531 } 1532 psFree(md); 1533 exit(EXIT_FAILURE); 1534 } 1535 1536 object = warpRunObjectFromMetadata(md); 1537 if (!object) { 1538 psFree(md); 1539 exit(EXIT_FAILURE); 1540 } 1541 1542 psFree(md); 1543 1544 psFree(object); 1545 exit(EXIT_FAILURE); 1546 } 1547 if (strncmp(object->mode, "a string", MAX_STRING_LENGTH)) { 1548 psFree(object); 1549 exit(EXIT_FAILURE); 1550 } 1551 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 1552 psFree(object); 1553 exit(EXIT_FAILURE); 1554 } 1555 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) { 1556 psFree(object); 1557 exit(EXIT_FAILURE); 1558 } 1559 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) { 1560 psFree(object); 1561 exit(EXIT_FAILURE); 1562 } 1563 psFree(object); 1564 exit(EXIT_FAILURE); 1565 } 1566 1567 psFree(object); 1568 } 1569 1570 { 1571 psMetadata *md; 1572 warpInputExpRow *object; 1573 1574 md = psMetadataAlloc(); 1575 psFree(md); 1576 exit(EXIT_FAILURE); 1577 } 1578 psFree(md); 1579 exit(EXIT_FAILURE); 1580 } 1581 if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, NULL, true)) { 1582 psFree(md); 1583 exit(EXIT_FAILURE); 1584 } 1585 1586 object = warpInputExpObjectFromMetadata(md); 1587 if (!object) { 1588 psFree(md); 1589 exit(EXIT_FAILURE); 1590 } 1591 1592 psFree(md); 1593 1594 psFree(object); 1595 exit(EXIT_FAILURE); 1596 } 1597 psFree(object); 1598 exit(EXIT_FAILURE); 1599 } 1600 if (!object->magiced == true) { 1601 psFree(object); 1602 exit(EXIT_FAILURE); 1603 } 1604 1605 psFree(object); 1606 } 1607 1608 { 1609 psMetadata *md; 1610 warpSkyCellMapRow *object; 1611 1612 md = psMetadataAlloc(); 1613 psFree(md); 1614 exit(EXIT_FAILURE); 1615 } 1616 if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) { 1617 psFree(md); 1618 exit(EXIT_FAILURE); 1619 } 1620 if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) { 1621 psFree(md); 1622 exit(EXIT_FAILURE); 1623 } 1624 psFree(md); 1625 exit(EXIT_FAILURE); 1626 } 1627 if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) { 1628 psFree(md); 1629 exit(EXIT_FAILURE); 1630 } 1631 psFree(md); 1632 exit(EXIT_FAILURE); 1633 } 1634 1635 object = warpSkyCellMapObjectFromMetadata(md); 1636 if (!object) { 1637 psFree(md); 1638 exit(EXIT_FAILURE); 1639 } 1640 1641 psFree(md); 1642 1643 psFree(object); 1644 exit(EXIT_FAILURE); 1645 } 1646 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 1647 psFree(object); 1648 exit(EXIT_FAILURE); 1649 } 1650 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 1651 psFree(object); 1652 exit(EXIT_FAILURE); 1653 } 1654 psFree(object); 1655 exit(EXIT_FAILURE); 1656 } 1657 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 1658 psFree(object); 1659 exit(EXIT_FAILURE); 1660 } 1661 psFree(object); 1662 exit(EXIT_FAILURE); 1663 } 1664 1665 psFree(object); 1666 } 1667 1668 { 1669 psMetadata *md; 1670 warpSkyfileRow *object; 1671 1672 md = psMetadataAlloc(); 1673 psFree(md); 1674 exit(EXIT_FAILURE); 1675 } 1676 if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) { 1677 psFree(md); 1678 exit(EXIT_FAILURE); 1679 } 1680 if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) { 1681 psFree(md); 1682 exit(EXIT_FAILURE); 1683 } 1684 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) { 1685 psFree(md); 1686 exit(EXIT_FAILURE); 1687 } 1688 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 64.64)) { 1689 psFree(md); 1690 exit(EXIT_FAILURE); 1691 } 1692 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, 64.64)) { 1693 psFree(md); 1694 exit(EXIT_FAILURE); 1695 } 1696 1697 object = warpSkyfileObjectFromMetadata(md); 1698 if (!object) { 1699 psFree(md); 1700 exit(EXIT_FAILURE); 1701 } 1702 1703 psFree(md); 1704 1705 psFree(object); 1706 exit(EXIT_FAILURE); 1707 } 1708 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 1709 psFree(object); 1710 exit(EXIT_FAILURE); 1711 } 1712 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 1713 psFree(object); 1714 exit(EXIT_FAILURE); 1715 } 1716 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 1717 psFree(object); 1718 exit(EXIT_FAILURE); 1719 } 1720 if (!object->bg == 64.64) { 1721 psFree(object); 1722 exit(EXIT_FAILURE); 1723 } 1724 if (!object->bg_stdev == 64.64) { 1725 psFree(object); 1726 exit(EXIT_FAILURE); 1727 } 1728 1729 psFree(object); 1730 } 1731 1732 { 1733 psMetadata *md; 1734 diffRunRow *object; 1735 1736 md = psMetadataAlloc(); 1737 psFree(md); 1738 exit(EXIT_FAILURE); 1739 } 1740 if (!psMetadataAddStr(md, PS_LIST_TAIL, "state", 0, NULL, "a string")) { 1741 psFree(md); 1742 exit(EXIT_FAILURE); 1743 } 1744 if (!psMetadataAddStr(md, PS_LIST_TAIL, "workdir", 0, NULL, "a string")) { 1745 psFree(md); 1746 exit(EXIT_FAILURE); 1747 } 1748 if (!psMetadataAddStr(md, PS_LIST_TAIL, "dvodb", 0, NULL, "a string")) { 1749 psFree(md); 1750 exit(EXIT_FAILURE); 1751 } 1752 psFree(md); 1753 exit(EXIT_FAILURE); 1754 } 1755 if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) { 1756 psFree(md); 1757 exit(EXIT_FAILURE); 1758 } 1759 if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) { 1760 psFree(md); 1761 exit(EXIT_FAILURE); 1762 } 1763 1764 object = diffRunObjectFromMetadata(md); 1765 if (!object) { 1766 psFree(md); 1767 exit(EXIT_FAILURE); 1768 } 1769 1770 psFree(md); 1771 1772 psFree(object); 1773 exit(EXIT_FAILURE); 1774 } 1775 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 1776 psFree(object); 1777 exit(EXIT_FAILURE); 1778 } 1779 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) { 1780 psFree(object); 1781 exit(EXIT_FAILURE); 1782 } 1783 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) { 1784 psFree(object); 1785 exit(EXIT_FAILURE); 1786 } 1787 psFree(object); 1788 exit(EXIT_FAILURE); 1789 } 1790 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 1791 psFree(object); 1792 exit(EXIT_FAILURE); 1793 } 1794 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 1795 psFree(object); 1796 exit(EXIT_FAILURE); 1797 } 1798 1799 psFree(object); 1800 } 1801 1802 { 1803 psMetadata *md; 1804 diffInputSkyfileRow *object; 1805 1806 md = psMetadataAlloc(); 1807 psFree(md); 1808 exit(EXIT_FAILURE); 1809 } 1810 psFree(md); 1811 exit(EXIT_FAILURE); 1812 } 1813 if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) { 1814 psFree(md); 1815 exit(EXIT_FAILURE); 1816 } 1817 if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) { 1818 psFree(md); 1819 exit(EXIT_FAILURE); 1820 } 1821 if (!psMetadataAddStr(md, PS_LIST_TAIL, "kind", 0, NULL, "a string")) { 1822 psFree(md); 1823 exit(EXIT_FAILURE); 1824 } 1825 if (!psMetadataAdd(md, PS_LIST_TAIL, "template", PS_DATA_BOOL, NULL, true)) { 1826 psFree(md); 1827 exit(EXIT_FAILURE); 1828 } 1829 1830 object = diffInputSkyfileObjectFromMetadata(md); 1831 if (!object) { 1832 psFree(md); 1833 exit(EXIT_FAILURE); 1834 } 1835 1836 psFree(md); 1837 1838 psFree(object); 1839 exit(EXIT_FAILURE); 1840 } 1841 psFree(object); 1842 exit(EXIT_FAILURE); 1843 } 1844 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 1845 psFree(object); 1846 exit(EXIT_FAILURE); 1847 } 1848 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 1849 psFree(object); 1850 exit(EXIT_FAILURE); 1851 } 1852 if (strncmp(object->kind, "a string", MAX_STRING_LENGTH)) { 1853 psFree(object); 1854 exit(EXIT_FAILURE); 1855 } 1856 if (!object->template == true) { 1857 psFree(object); 1858 exit(EXIT_FAILURE); 1859 } 1860 1861 psFree(object); 1862 } 1863 1864 { 1865 psMetadata *md; 1866 diffSkyfileRow *object; 1867 1868 md = psMetadataAlloc(); 1869 psFree(md); 1870 exit(EXIT_FAILURE); 1871 } 1872 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) { 1873 psFree(md); 1874 exit(EXIT_FAILURE); 1875 } 1876 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 64.64)) { 1877 psFree(md); 1878 exit(EXIT_FAILURE); 1879 } 1880 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, 64.64)) { 1881 psFree(md); 1882 exit(EXIT_FAILURE); 1883 } 1884 1885 object = diffSkyfileObjectFromMetadata(md); 1886 if (!object) { 1887 psFree(md); 1888 exit(EXIT_FAILURE); 1889 } 1890 1891 psFree(md); 1892 1893 psFree(object); 1894 exit(EXIT_FAILURE); 1895 } 1896 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 1897 psFree(object); 1898 exit(EXIT_FAILURE); 1899 } 1900 if (!object->bg == 64.64) { 1901 psFree(object); 1902 exit(EXIT_FAILURE); 1903 } 1904 if (!object->bg_stdev == 64.64) { 1905 psFree(object); 1906 exit(EXIT_FAILURE); 1907 } 1908 1909 psFree(object); 1910 } 1911 1912 { 1913 psMetadata *md; 1914 stackRunRow *object; 1915 1916 md = psMetadataAlloc(); 1917 psFree(md); 1918 exit(EXIT_FAILURE); 1919 } 1920 if (!psMetadataAddStr(md, PS_LIST_TAIL, "state", 0, NULL, "a string")) { 1921 psFree(md); 1922 exit(EXIT_FAILURE); 1923 } 1924 if (!psMetadataAddStr(md, PS_LIST_TAIL, "workdir", 0, NULL, "a string")) { 1925 psFree(md); 1926 exit(EXIT_FAILURE); 1927 } 1928 if (!psMetadataAddStr(md, PS_LIST_TAIL, "dvodb", 0, NULL, "a string")) { 1929 psFree(md); 1930 exit(EXIT_FAILURE); 1931 } 1932 psFree(md); 1933 exit(EXIT_FAILURE); 1934 } 1935 if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) { 1936 psFree(md); 1937 exit(EXIT_FAILURE); 1938 } 1939 if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) { 1940 psFree(md); 1941 exit(EXIT_FAILURE); 1942 } 1943 1944 object = stackRunObjectFromMetadata(md); 1945 if (!object) { 1946 psFree(md); 1947 exit(EXIT_FAILURE); 1948 } 1949 1950 psFree(md); 1951 1952 psFree(object); 1953 exit(EXIT_FAILURE); 1954 } 1955 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 1956 psFree(object); 1957 exit(EXIT_FAILURE); 1958 } 1959 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) { 1960 psFree(object); 1961 exit(EXIT_FAILURE); 1962 } 1963 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) { 1964 psFree(object); 1965 exit(EXIT_FAILURE); 1966 } 1967 psFree(object); 1968 exit(EXIT_FAILURE); 1969 } 1970 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 1971 psFree(object); 1972 exit(EXIT_FAILURE); 1973 } 1974 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 1975 psFree(object); 1976 exit(EXIT_FAILURE); 1977 } 1978 1979 psFree(object); 1980 } 1981 1982 { 1983 psMetadata *md; 1984 stackInputSkyfileRow *object; 1985 1986 md = psMetadataAlloc(); 1987 psFree(md); 1988 exit(EXIT_FAILURE); 1989 } 1990 psFree(md); 1991 exit(EXIT_FAILURE); 1992 } 1993 1994 object = stackInputSkyfileObjectFromMetadata(md); 1995 if (!object) { 1996 psFree(md); 1997 exit(EXIT_FAILURE); 1998 } 1999 2000 psFree(md); 2001 2002 psFree(object); 2003 exit(EXIT_FAILURE); 2004 } 2005 psFree(object); 2006 exit(EXIT_FAILURE); 2007 } 2008 2009 psFree(object); 2010 } 2011 2012 { 2013 psMetadata *md; 2014 stackSumSkyfileRow *object; 2015 2016 md = psMetadataAlloc(); 2017 psFree(md); 2018 exit(EXIT_FAILURE); 2019 } 2020 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) { 2021 psFree(md); 2022 exit(EXIT_FAILURE); 2023 } 2024 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 64.64)) { 2025 psFree(md); 2026 exit(EXIT_FAILURE); 2027 } 2028 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, 64.64)) { 2029 psFree(md); 2030 exit(EXIT_FAILURE); 2031 } 2032 2033 object = stackSumSkyfileObjectFromMetadata(md); 2034 if (!object) { 2035 psFree(md); 2036 exit(EXIT_FAILURE); 2037 } 2038 2039 psFree(md); 2040 2041 psFree(object); 2042 exit(EXIT_FAILURE); 2043 } 2044 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 2045 psFree(object); 2046 exit(EXIT_FAILURE); 2047 } 2048 if (!object->bg == 64.64) { 2049 psFree(object); 2050 exit(EXIT_FAILURE); 2051 } 2052 if (!object->bg_stdev == 64.64) { 2053 psFree(object); 2054 exit(EXIT_FAILURE); 2055 } 2056 2057 psFree(object); 2058 } 2059 2060 { 2061 psMetadata *md; 1510 2062 detRunRow *object; 1511 2063 … … 2519 3071 exit(EXIT_FAILURE); 2520 3072 } 2521 psFree(object);2522 exit(EXIT_FAILURE);2523 }2524 2525 psFree(object);2526 }2527 2528 {2529 psMetadata *md;2530 warpRunRow *object;2531 2532 md = psMetadataAlloc();2533 psFree(md);2534 exit(EXIT_FAILURE);2535 }2536 if (!psMetadataAddStr(md, PS_LIST_TAIL, "mode", 0, NULL, "a string")) {2537 psFree(md);2538 exit(EXIT_FAILURE);2539 }2540 if (!psMetadataAddStr(md, PS_LIST_TAIL, "state", 0, NULL, "a string")) {2541 psFree(md);2542 exit(EXIT_FAILURE);2543 }2544 if (!psMetadataAddStr(md, PS_LIST_TAIL, "workdir", 0, NULL, "a string")) {2545 psFree(md);2546 exit(EXIT_FAILURE);2547 }2548 if (!psMetadataAddStr(md, PS_LIST_TAIL, "dvodb", 0, NULL, "a string")) {2549 psFree(md);2550 exit(EXIT_FAILURE);2551 }2552 psFree(md);2553 exit(EXIT_FAILURE);2554 }2555 2556 object = warpRunObjectFromMetadata(md);2557 if (!object) {2558 psFree(md);2559 exit(EXIT_FAILURE);2560 }2561 2562 psFree(md);2563 2564 psFree(object);2565 exit(EXIT_FAILURE);2566 }2567 if (strncmp(object->mode, "a string", MAX_STRING_LENGTH)) {2568 psFree(object);2569 exit(EXIT_FAILURE);2570 }2571 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) {2572 psFree(object);2573 exit(EXIT_FAILURE);2574 }2575 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) {2576 psFree(object);2577 exit(EXIT_FAILURE);2578 }2579 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) {2580 psFree(object);2581 exit(EXIT_FAILURE);2582 }2583 psFree(object);2584 exit(EXIT_FAILURE);2585 }2586 2587 psFree(object);2588 }2589 2590 {2591 psMetadata *md;2592 warpInputExpRow *object;2593 2594 md = psMetadataAlloc();2595 psFree(md);2596 exit(EXIT_FAILURE);2597 }2598 psFree(md);2599 exit(EXIT_FAILURE);2600 }2601 if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, NULL, true)) {2602 psFree(md);2603 exit(EXIT_FAILURE);2604 }2605 2606 object = warpInputExpObjectFromMetadata(md);2607 if (!object) {2608 psFree(md);2609 exit(EXIT_FAILURE);2610 }2611 2612 psFree(md);2613 2614 psFree(object);2615 exit(EXIT_FAILURE);2616 }2617 psFree(object);2618 exit(EXIT_FAILURE);2619 }2620 if (!object->magiced == true) {2621 psFree(object);2622 exit(EXIT_FAILURE);2623 }2624 2625 psFree(object);2626 }2627 2628 {2629 psMetadata *md;2630 warpSkyCellMapRow *object;2631 2632 md = psMetadataAlloc();2633 psFree(md);2634 exit(EXIT_FAILURE);2635 }2636 if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {2637 psFree(md);2638 exit(EXIT_FAILURE);2639 }2640 if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {2641 psFree(md);2642 exit(EXIT_FAILURE);2643 }2644 psFree(md);2645 exit(EXIT_FAILURE);2646 }2647 if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) {2648 psFree(md);2649 exit(EXIT_FAILURE);2650 }2651 psFree(md);2652 exit(EXIT_FAILURE);2653 }2654 2655 object = warpSkyCellMapObjectFromMetadata(md);2656 if (!object) {2657 psFree(md);2658 exit(EXIT_FAILURE);2659 }2660 2661 psFree(md);2662 2663 psFree(object);2664 exit(EXIT_FAILURE);2665 }2666 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {2667 psFree(object);2668 exit(EXIT_FAILURE);2669 }2670 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {2671 psFree(object);2672 exit(EXIT_FAILURE);2673 }2674 psFree(object);2675 exit(EXIT_FAILURE);2676 }2677 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) {2678 psFree(object);2679 exit(EXIT_FAILURE);2680 }2681 psFree(object);2682 exit(EXIT_FAILURE);2683 }2684 2685 psFree(object);2686 }2687 2688 {2689 psMetadata *md;2690 warpSkyfileRow *object;2691 2692 md = psMetadataAlloc();2693 psFree(md);2694 exit(EXIT_FAILURE);2695 }2696 if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {2697 psFree(md);2698 exit(EXIT_FAILURE);2699 }2700 if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {2701 psFree(md);2702 exit(EXIT_FAILURE);2703 }2704 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) {2705 psFree(md);2706 exit(EXIT_FAILURE);2707 }2708 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 64.64)) {2709 psFree(md);2710 exit(EXIT_FAILURE);2711 }2712 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, 64.64)) {2713 psFree(md);2714 exit(EXIT_FAILURE);2715 }2716 2717 object = warpSkyfileObjectFromMetadata(md);2718 if (!object) {2719 psFree(md);2720 exit(EXIT_FAILURE);2721 }2722 2723 psFree(md);2724 2725 psFree(object);2726 exit(EXIT_FAILURE);2727 }2728 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {2729 psFree(object);2730 exit(EXIT_FAILURE);2731 }2732 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {2733 psFree(object);2734 exit(EXIT_FAILURE);2735 }2736 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {2737 psFree(object);2738 exit(EXIT_FAILURE);2739 }2740 if (!object->bg == 64.64) {2741 psFree(object);2742 exit(EXIT_FAILURE);2743 }2744 if (!object->bg_stdev == 64.64) {2745 psFree(object);2746 exit(EXIT_FAILURE);2747 }2748 2749 psFree(object);2750 }2751 2752 {2753 psMetadata *md;2754 diffRunRow *object;2755 2756 md = psMetadataAlloc();2757 psFree(md);2758 exit(EXIT_FAILURE);2759 }2760 if (!psMetadataAddStr(md, PS_LIST_TAIL, "state", 0, NULL, "a string")) {2761 psFree(md);2762 exit(EXIT_FAILURE);2763 }2764 if (!psMetadataAddStr(md, PS_LIST_TAIL, "workdir", 0, NULL, "a string")) {2765 psFree(md);2766 exit(EXIT_FAILURE);2767 }2768 if (!psMetadataAddStr(md, PS_LIST_TAIL, "dvodb", 0, NULL, "a string")) {2769 psFree(md);2770 exit(EXIT_FAILURE);2771 }2772 psFree(md);2773 exit(EXIT_FAILURE);2774 }2775 if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {2776 psFree(md);2777 exit(EXIT_FAILURE);2778 }2779 if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {2780 psFree(md);2781 exit(EXIT_FAILURE);2782 }2783 2784 object = diffRunObjectFromMetadata(md);2785 if (!object) {2786 psFree(md);2787 exit(EXIT_FAILURE);2788 }2789 2790 psFree(md);2791 2792 psFree(object);2793 exit(EXIT_FAILURE);2794 }2795 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) {2796 psFree(object);2797 exit(EXIT_FAILURE);2798 }2799 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) {2800 psFree(object);2801 exit(EXIT_FAILURE);2802 }2803 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) {2804 psFree(object);2805 exit(EXIT_FAILURE);2806 }2807 psFree(object);2808 exit(EXIT_FAILURE);2809 }2810 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {2811 psFree(object);2812 exit(EXIT_FAILURE);2813 }2814 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {2815 psFree(object);2816 exit(EXIT_FAILURE);2817 }2818 2819 psFree(object);2820 }2821 2822 {2823 psMetadata *md;2824 diffInputSkyfileRow *object;2825 2826 md = psMetadataAlloc();2827 psFree(md);2828 exit(EXIT_FAILURE);2829 }2830 psFree(md);2831 exit(EXIT_FAILURE);2832 }2833 if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {2834 psFree(md);2835 exit(EXIT_FAILURE);2836 }2837 if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {2838 psFree(md);2839 exit(EXIT_FAILURE);2840 }2841 if (!psMetadataAddStr(md, PS_LIST_TAIL, "kind", 0, NULL, "a string")) {2842 psFree(md);2843 exit(EXIT_FAILURE);2844 }2845 if (!psMetadataAdd(md, PS_LIST_TAIL, "template", PS_DATA_BOOL, NULL, true)) {2846 psFree(md);2847 exit(EXIT_FAILURE);2848 }2849 2850 object = diffInputSkyfileObjectFromMetadata(md);2851 if (!object) {2852 psFree(md);2853 exit(EXIT_FAILURE);2854 }2855 2856 psFree(md);2857 2858 psFree(object);2859 exit(EXIT_FAILURE);2860 }2861 psFree(object);2862 exit(EXIT_FAILURE);2863 }2864 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {2865 psFree(object);2866 exit(EXIT_FAILURE);2867 }2868 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {2869 psFree(object);2870 exit(EXIT_FAILURE);2871 }2872 if (strncmp(object->kind, "a string", MAX_STRING_LENGTH)) {2873 psFree(object);2874 exit(EXIT_FAILURE);2875 }2876 if (!object->template == true) {2877 psFree(object);2878 exit(EXIT_FAILURE);2879 }2880 2881 psFree(object);2882 }2883 2884 {2885 psMetadata *md;2886 diffSkyfileRow *object;2887 2888 md = psMetadataAlloc();2889 psFree(md);2890 exit(EXIT_FAILURE);2891 }2892 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) {2893 psFree(md);2894 exit(EXIT_FAILURE);2895 }2896 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 64.64)) {2897 psFree(md);2898 exit(EXIT_FAILURE);2899 }2900 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, 64.64)) {2901 psFree(md);2902 exit(EXIT_FAILURE);2903 }2904 2905 object = diffSkyfileObjectFromMetadata(md);2906 if (!object) {2907 psFree(md);2908 exit(EXIT_FAILURE);2909 }2910 2911 psFree(md);2912 2913 psFree(object);2914 exit(EXIT_FAILURE);2915 }2916 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {2917 psFree(object);2918 exit(EXIT_FAILURE);2919 }2920 if (!object->bg == 64.64) {2921 psFree(object);2922 exit(EXIT_FAILURE);2923 }2924 if (!object->bg_stdev == 64.64) {2925 psFree(object);2926 exit(EXIT_FAILURE);2927 }2928 2929 psFree(object);2930 }2931 2932 {2933 psMetadata *md;2934 stackRunRow *object;2935 2936 md = psMetadataAlloc();2937 psFree(md);2938 exit(EXIT_FAILURE);2939 }2940 if (!psMetadataAddStr(md, PS_LIST_TAIL, "state", 0, NULL, "a string")) {2941 psFree(md);2942 exit(EXIT_FAILURE);2943 }2944 if (!psMetadataAddStr(md, PS_LIST_TAIL, "workdir", 0, NULL, "a string")) {2945 psFree(md);2946 exit(EXIT_FAILURE);2947 }2948 if (!psMetadataAddStr(md, PS_LIST_TAIL, "dvodb", 0, NULL, "a string")) {2949 psFree(md);2950 exit(EXIT_FAILURE);2951 }2952 psFree(md);2953 exit(EXIT_FAILURE);2954 }2955 if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {2956 psFree(md);2957 exit(EXIT_FAILURE);2958 }2959 if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {2960 psFree(md);2961 exit(EXIT_FAILURE);2962 }2963 2964 object = stackRunObjectFromMetadata(md);2965 if (!object) {2966 psFree(md);2967 exit(EXIT_FAILURE);2968 }2969 2970 psFree(md);2971 2972 psFree(object);2973 exit(EXIT_FAILURE);2974 }2975 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) {2976 psFree(object);2977 exit(EXIT_FAILURE);2978 }2979 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) {2980 psFree(object);2981 exit(EXIT_FAILURE);2982 }2983 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) {2984 psFree(object);2985 exit(EXIT_FAILURE);2986 }2987 psFree(object);2988 exit(EXIT_FAILURE);2989 }2990 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {2991 psFree(object);2992 exit(EXIT_FAILURE);2993 }2994 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {2995 psFree(object);2996 exit(EXIT_FAILURE);2997 }2998 2999 psFree(object);3000 }3001 3002 {3003 psMetadata *md;3004 stackInputSkyfileRow *object;3005 3006 md = psMetadataAlloc();3007 psFree(md);3008 exit(EXIT_FAILURE);3009 }3010 psFree(md);3011 exit(EXIT_FAILURE);3012 }3013 3014 object = stackInputSkyfileObjectFromMetadata(md);3015 if (!object) {3016 psFree(md);3017 exit(EXIT_FAILURE);3018 }3019 3020 psFree(md);3021 3022 psFree(object);3023 exit(EXIT_FAILURE);3024 }3025 psFree(object);3026 exit(EXIT_FAILURE);3027 }3028 3029 psFree(object);3030 }3031 3032 {3033 psMetadata *md;3034 stackSumSkyfileRow *object;3035 3036 md = psMetadataAlloc();3037 psFree(md);3038 exit(EXIT_FAILURE);3039 }3040 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) {3041 psFree(md);3042 exit(EXIT_FAILURE);3043 }3044 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 64.64)) {3045 psFree(md);3046 exit(EXIT_FAILURE);3047 }3048 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, 64.64)) {3049 psFree(md);3050 exit(EXIT_FAILURE);3051 }3052 3053 object = stackSumSkyfileObjectFromMetadata(md);3054 if (!object) {3055 psFree(md);3056 exit(EXIT_FAILURE);3057 }3058 3059 psFree(md);3060 3061 psFree(object);3062 exit(EXIT_FAILURE);3063 }3064 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {3065 psFree(object);3066 exit(EXIT_FAILURE);3067 }3068 if (!object->bg == 64.64) {3069 psFree(object);3070 exit(EXIT_FAILURE);3071 }3072 if (!object->bg_stdev == 64.64) {3073 3073 psFree(object); 3074 3074 exit(EXIT_FAILURE); -
trunk/ippdb/tests/selectrowsfits.c
r12026 r12535 461 461 } 462 462 463 if (!warpRunSelectRowsFits(dbh, fits, NULL, 1)) { 464 exit(EXIT_FAILURE); 465 } 466 467 psFree(fits); 468 psDBCleanup(dbh); 469 } 470 471 { 472 psDB *dbh; 473 psFits *fits; 474 475 dbh = psDBInit("localhost", "test", NULL, "test"); 476 if (!dbh) { 477 exit(EXIT_FAILURE); 478 } 479 480 fits = psFitsOpen(TMP_FILENAME, "w"); 481 if (!fits) { 482 exit(EXIT_FAILURE); 483 } 484 485 if (!warpInputExpSelectRowsFits(dbh, fits, NULL, 1)) { 486 exit(EXIT_FAILURE); 487 } 488 489 psFree(fits); 490 psDBCleanup(dbh); 491 } 492 493 { 494 psDB *dbh; 495 psFits *fits; 496 497 dbh = psDBInit("localhost", "test", NULL, "test"); 498 if (!dbh) { 499 exit(EXIT_FAILURE); 500 } 501 502 fits = psFitsOpen(TMP_FILENAME, "w"); 503 if (!fits) { 504 exit(EXIT_FAILURE); 505 } 506 507 if (!warpSkyCellMapSelectRowsFits(dbh, fits, NULL, 1)) { 508 exit(EXIT_FAILURE); 509 } 510 511 psFree(fits); 512 psDBCleanup(dbh); 513 } 514 515 { 516 psDB *dbh; 517 psFits *fits; 518 519 dbh = psDBInit("localhost", "test", NULL, "test"); 520 if (!dbh) { 521 exit(EXIT_FAILURE); 522 } 523 524 fits = psFitsOpen(TMP_FILENAME, "w"); 525 if (!fits) { 526 exit(EXIT_FAILURE); 527 } 528 529 if (!warpSkyfileSelectRowsFits(dbh, fits, NULL, 1)) { 530 exit(EXIT_FAILURE); 531 } 532 533 psFree(fits); 534 psDBCleanup(dbh); 535 } 536 537 { 538 psDB *dbh; 539 psFits *fits; 540 541 dbh = psDBInit("localhost", "test", NULL, "test"); 542 if (!dbh) { 543 exit(EXIT_FAILURE); 544 } 545 546 fits = psFitsOpen(TMP_FILENAME, "w"); 547 if (!fits) { 548 exit(EXIT_FAILURE); 549 } 550 551 if (!diffRunSelectRowsFits(dbh, fits, NULL, 1)) { 552 exit(EXIT_FAILURE); 553 } 554 555 psFree(fits); 556 psDBCleanup(dbh); 557 } 558 559 { 560 psDB *dbh; 561 psFits *fits; 562 563 dbh = psDBInit("localhost", "test", NULL, "test"); 564 if (!dbh) { 565 exit(EXIT_FAILURE); 566 } 567 568 fits = psFitsOpen(TMP_FILENAME, "w"); 569 if (!fits) { 570 exit(EXIT_FAILURE); 571 } 572 573 if (!diffInputSkyfileSelectRowsFits(dbh, fits, NULL, 1)) { 574 exit(EXIT_FAILURE); 575 } 576 577 psFree(fits); 578 psDBCleanup(dbh); 579 } 580 581 { 582 psDB *dbh; 583 psFits *fits; 584 585 dbh = psDBInit("localhost", "test", NULL, "test"); 586 if (!dbh) { 587 exit(EXIT_FAILURE); 588 } 589 590 fits = psFitsOpen(TMP_FILENAME, "w"); 591 if (!fits) { 592 exit(EXIT_FAILURE); 593 } 594 595 if (!diffSkyfileSelectRowsFits(dbh, fits, NULL, 1)) { 596 exit(EXIT_FAILURE); 597 } 598 599 psFree(fits); 600 psDBCleanup(dbh); 601 } 602 603 { 604 psDB *dbh; 605 psFits *fits; 606 607 dbh = psDBInit("localhost", "test", NULL, "test"); 608 if (!dbh) { 609 exit(EXIT_FAILURE); 610 } 611 612 fits = psFitsOpen(TMP_FILENAME, "w"); 613 if (!fits) { 614 exit(EXIT_FAILURE); 615 } 616 617 if (!stackRunSelectRowsFits(dbh, fits, NULL, 1)) { 618 exit(EXIT_FAILURE); 619 } 620 621 psFree(fits); 622 psDBCleanup(dbh); 623 } 624 625 { 626 psDB *dbh; 627 psFits *fits; 628 629 dbh = psDBInit("localhost", "test", NULL, "test"); 630 if (!dbh) { 631 exit(EXIT_FAILURE); 632 } 633 634 fits = psFitsOpen(TMP_FILENAME, "w"); 635 if (!fits) { 636 exit(EXIT_FAILURE); 637 } 638 639 if (!stackInputSkyfileSelectRowsFits(dbh, fits, NULL, 1)) { 640 exit(EXIT_FAILURE); 641 } 642 643 psFree(fits); 644 psDBCleanup(dbh); 645 } 646 647 { 648 psDB *dbh; 649 psFits *fits; 650 651 dbh = psDBInit("localhost", "test", NULL, "test"); 652 if (!dbh) { 653 exit(EXIT_FAILURE); 654 } 655 656 fits = psFitsOpen(TMP_FILENAME, "w"); 657 if (!fits) { 658 exit(EXIT_FAILURE); 659 } 660 661 if (!stackSumSkyfileSelectRowsFits(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 463 683 if (!detRunSelectRowsFits(dbh, fits, NULL, 1)) { 464 684 exit(EXIT_FAILURE); … … 682 902 683 903 if (!detRunSummarySelectRowsFits(dbh, fits, NULL, 1)) { 684 exit(EXIT_FAILURE);685 }686 687 psFree(fits);688 psDBCleanup(dbh);689 }690 691 {692 psDB *dbh;693 psFits *fits;694 695 dbh = psDBInit("localhost", "test", NULL, "test");696 if (!dbh) {697 exit(EXIT_FAILURE);698 }699 700 fits = psFitsOpen(TMP_FILENAME, "w");701 if (!fits) {702 exit(EXIT_FAILURE);703 }704 705 if (!warpRunSelectRowsFits(dbh, fits, NULL, 1)) {706 exit(EXIT_FAILURE);707 }708 709 psFree(fits);710 psDBCleanup(dbh);711 }712 713 {714 psDB *dbh;715 psFits *fits;716 717 dbh = psDBInit("localhost", "test", NULL, "test");718 if (!dbh) {719 exit(EXIT_FAILURE);720 }721 722 fits = psFitsOpen(TMP_FILENAME, "w");723 if (!fits) {724 exit(EXIT_FAILURE);725 }726 727 if (!warpInputExpSelectRowsFits(dbh, fits, NULL, 1)) {728 exit(EXIT_FAILURE);729 }730 731 psFree(fits);732 psDBCleanup(dbh);733 }734 735 {736 psDB *dbh;737 psFits *fits;738 739 dbh = psDBInit("localhost", "test", NULL, "test");740 if (!dbh) {741 exit(EXIT_FAILURE);742 }743 744 fits = psFitsOpen(TMP_FILENAME, "w");745 if (!fits) {746 exit(EXIT_FAILURE);747 }748 749 if (!warpSkyCellMapSelectRowsFits(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 (!warpSkyfileSelectRowsFits(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 (!diffRunSelectRowsFits(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 (!diffInputSkyfileSelectRowsFits(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 (!diffSkyfileSelectRowsFits(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 (!stackRunSelectRowsFits(dbh, fits, NULL, 1)) {860 exit(EXIT_FAILURE);861 }862 863 psFree(fits);864 psDBCleanup(dbh);865 }866 867 {868 psDB *dbh;869 psFits *fits;870 871 dbh = psDBInit("localhost", "test", NULL, "test");872 if (!dbh) {873 exit(EXIT_FAILURE);874 }875 876 fits = psFitsOpen(TMP_FILENAME, "w");877 if (!fits) {878 exit(EXIT_FAILURE);879 }880 881 if (!stackInputSkyfileSelectRowsFits(dbh, fits, NULL, 1)) {882 exit(EXIT_FAILURE);883 }884 885 psFree(fits);886 psDBCleanup(dbh);887 }888 889 {890 psDB *dbh;891 psFits *fits;892 893 dbh = psDBInit("localhost", "test", NULL, "test");894 if (!dbh) {895 exit(EXIT_FAILURE);896 }897 898 fits = psFitsOpen(TMP_FILENAME, "w");899 if (!fits) {900 exit(EXIT_FAILURE);901 }902 903 if (!stackSumSkyfileSelectRowsFits(dbh, fits, NULL, 1)) {904 904 exit(EXIT_FAILURE); 905 905 }
Note:
See TracChangeset
for help on using the changeset viewer.
