Changeset 9942 for trunk/ippTools/src/dettool.c
- Timestamp:
- Nov 9, 2006, 3:00:07 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/dettool.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/dettool.c
r9940 r9942 33 33 static bool definebytagMode(pxConfig *config); 34 34 static bool definebyqueryMode(pxConfig *config); 35 static bool definebydetrunMode(pxConfig *config); 35 36 static bool runsMode(pxConfig *config); 36 37 static bool inputMode(pxConfig *config); … … 97 98 MODECASE(DETTOOL_MODE_DEFINEBYTAG, definebytagMode); 98 99 MODECASE(DETTOOL_MODE_DEFINEBYQUERY, definebyqueryMode); 100 MODECASE(DETTOOL_MODE_DEFINEBYDETRUN, definebydetrunMode); 99 101 MODECASE(DETTOOL_MODE_RUNS, runsMode); 100 102 MODECASE(DETTOOL_MODE_INPUT, inputMode); … … 504 506 505 507 static bool definebyqueryMode(pxConfig *config) 508 { 509 bool status = false; 510 511 PS_ASSERT_PTR_NON_NULL(config, false); 512 513 // what type of detRun is this? 514 // det_type is required 515 psString det_type = psMetadataLookupStr(&status, config->args, "-det_type"); 516 if (!status) { 517 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_type"); 518 return false; 519 } 520 if (!det_type) { 521 psError(PS_ERR_UNKNOWN, true, "-det_type is required"); 522 return false; 523 } 524 525 psMetadata *where = psMetadataAlloc(); 526 { 527 bool status = false; 528 psString exp_type = psMetadataLookupStr(&status, config->args, "-exp_type"); if (!status) { 529 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_type"); 530 return false; 531 } 532 if (exp_type) { 533 if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_type", 0, "==", exp_type)) { 534 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_type"); 535 psFree(where); 536 return false; 537 } 538 } 539 // map -inst -> camera 540 psString camera = psMetadataLookupStr(&status, config->args, "-inst"); 541 if (!status) { 542 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst"); 543 return false; 544 } 545 if (camera) { 546 if (!psMetadataAddStr(where, PS_LIST_TAIL, "camera", 0, "==", camera)) { 547 psError(PS_ERR_UNKNOWN, false, "failed to add item inst"); 548 psFree(where); 549 return false; 550 } 551 } 552 psString telescope = psMetadataLookupStr(&status, config->args, "-telescope"); if (!status) { 553 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -telescope"); 554 return false; 555 } 556 if (telescope) { 557 if (!psMetadataAddStr(where, PS_LIST_TAIL, "telescope", 0, "==", telescope)) { 558 psError(PS_ERR_UNKNOWN, false, "failed to add item telescope"); 559 psFree(where); 560 return false; 561 } 562 } 563 psString filter = psMetadataLookupStr(&status, config->args, "-filter"); 564 if (!status) { 565 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -filter"); 566 return false; 567 } 568 if (filter) { 569 if (!psMetadataAddStr(where, PS_LIST_TAIL, "filter", 0, "==", filter)) { 570 psError(PS_ERR_UNKNOWN, false, "failed to add item filter"); 571 psFree(where); 572 return false; 573 } 574 } 575 psString uri = psMetadataLookupStr(&status, config->args, "-uri"); 576 if (!status) { 577 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -filter"); 578 return false; 579 } 580 if (uri) { 581 if (!psMetadataAddStr(where, PS_LIST_TAIL, "uri", 0, "==", uri)) { 582 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 583 psFree(where); 584 return false; 585 } 586 } 587 } 588 if (!psListLength(where->list)) { 589 psFree(where); 590 where = NULL; 591 } 592 593 // there is some namespace overlap between the names of the fields we'd 594 // like to search by to setup a detrun and the names of the fields we'd 595 // like to assign values to so I've seperated them but prepending set- to 596 // the assigned values 597 598 // optional 599 psString exp_type = psMetadataLookupStr(&status, config->args, "-set_exp_type"); 600 if (!status) { 601 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_exp_type"); 602 return false; 603 } 604 605 psString filter = psMetadataLookupStr(&status, config->args, "-set_filter"); 606 if (!status) { 607 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_filter"); 608 return false; 609 } 610 611 psF32 airmass = psMetadataLookupF32(&status, config->args, "-set_airmass"); 612 if (!status) { 613 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_airmass"); 614 return false; 615 } 616 617 psF32 exp_time = psMetadataLookupF32(&status, config->args, "-set_exp_time"); 618 if (!status) { 619 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_exp_time"); 620 return false; 621 } 622 623 psF32 ccd_temp = psMetadataLookupF32(&status, config->args, "-set_ccd_temp"); 624 if (!status) { 625 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_ccd_temp"); 626 return false; 627 } 628 629 psF64 posang = psMetadataLookupF32(&status, config->args, "-set_posang"); 630 if (!status) { 631 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_posang"); 632 return false; 633 } 634 635 psString object = psMetadataLookupStr(&status, config->args, "-set_object"); 636 if (!status) { 637 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_object"); 638 return false; 639 } 640 psTime *registered = NULL; 641 { 642 psString registeredStr = psMetadataLookupStr(&status, config->args, "-set_registered"); 643 if (!status) { 644 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_registered"); 645 return false; 646 } 647 // pass through NULL as this is an optional field 648 if (registeredStr) { 649 registered = psTimeFromISO(registeredStr, PS_TIME_UTC); 650 } else { 651 registered = NULL; 652 } 653 } 654 655 psTime *use_begin = NULL; 656 { 657 psString use_beginStr = psMetadataLookupStr(&status, config->args, "-set_use_begin"); 658 if (!status) { 659 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_use_begin"); 660 return false; 661 } 662 // pass through NULL as this is an optional field 663 if (use_beginStr) { 664 use_begin = psTimeFromISO(use_beginStr, PS_TIME_UTC); 665 } else { 666 use_begin = NULL; 667 } 668 } 669 670 psTime *use_end = NULL; 671 { 672 psString use_endStr = psMetadataLookupStr(&status, config->args, "-set_use_end"); 673 if (!status) { 674 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_use_end"); 675 return false; 676 } 677 // pass through NULL as this is an optional field 678 if (use_endStr) { 679 use_end = psTimeFromISO(use_endStr, PS_TIME_UTC); 680 } else { 681 use_end = NULL; 682 } 683 } 684 685 // search for rawDetrendExps with the specified options 686 psArray *detrendExps = rawDetrendExpSelectRowObjects(config->dbh, where, 0); 687 psFree(where); 688 // make sure that we found at least one rawDetrendExp 689 if (!detrendExps) { 690 psError(PS_ERR_UNKNOWN, false, "no rawDetrendExp rows found"); 691 return false; 692 } 693 694 // start a transaction so we don't end up with orphaned det_ids 695 if (!psDBTransaction(config->dbh)) { 696 psError(PS_ERR_UNKNOWN, false, "database error"); 697 psFree(detrendExps); 698 return false; 699 } 700 701 // the first iteration is always 0 702 // XXX det_id 703 detRunInsert(config->dbh, 704 0, 705 0, 706 det_type, 707 "run", 708 exp_type, 709 filter, 710 airmass, 711 exp_time, 712 ccd_temp, 713 posang, 714 object, 715 registered, 716 use_begin, 717 use_end 718 ); 719 psFree(registered); 720 psFree(use_begin); 721 psFree(use_end); 722 long det_id = psDBLastInsertID(config->dbh); 723 724 // create new detInputExp row(s) from the rawDetrendExp row(s) 725 psArray *inputExps = psArrayAllocEmpty(psArrayLength(detrendExps)); 726 for (long i = 0; i < psArrayLength(detrendExps); i++) { 727 detInputExpRow *inputExp = rawDetrenTodetInputExpRow( 728 detrendExps->data[i], 729 det_id, 730 0 // the first iteration is explicitly 0 731 ); 732 psArrayAdd(inputExps, 0, inputExp); 733 psFree(inputExp); 734 } 735 736 psFree(detrendExps); 737 738 // insert detInputExp objects into the database 739 if (!detInputExpInsertObjects(config->dbh, inputExps)) { 740 psError(PS_ERR_UNKNOWN, false, "database error"); 741 // rollback 742 if (!psDBRollback(config->dbh)) { 743 psError(PS_ERR_UNKNOWN, false, "database error"); 744 } 745 psFree(inputExps); 746 return false; 747 } 748 psFree(inputExps); 749 750 // point of no return for det_id creation 751 if (!psDBCommit(config->dbh)) { 752 psError(PS_ERR_UNKNOWN, false, "database error"); 753 return false; 754 } 755 756 bool simple = false; 757 { 758 bool status = false; 759 simple = psMetadataLookupBool(&status, config->args, "-simple"); 760 if (!status) { 761 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 762 return false; 763 } 764 } 765 766 // print the new det_id 767 psArray *detRuns = NULL; 768 { 769 psMetadata *where = psMetadataAlloc(); 770 psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==", det_id); 771 detRuns = psDBSelectRows(config->dbh, "detRun", where, 0); 772 psFree(where); 773 } 774 if (!detRuns) { 775 psError(PS_ERR_UNKNOWN, false, "can't find the detRun we just created"); 776 return false; 777 } 778 // sanity check results 779 if (psArrayLength(detRuns) != 1) { 780 psAbort(config->argv[0], "found more then one detRun matching det_id %ld(this should not happen)", det_id); 781 return false; 782 } 783 784 // convert det_id to a string externaly 785 if (!convertDetIdToStr(detRuns)) { 786 psError(PS_ERR_UNKNOWN, false, "failed to convert det_id to a string"); 787 psFree(detRuns); 788 return false; 789 } 790 791 // negative simple so the default is true 792 if (!ippdbPrintMetadatas(stdout, detRuns, "detRun", !simple)) { 793 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 794 psFree(detRuns); 795 return false; 796 } 797 psFree(detRuns); 798 799 return true; 800 } 801 802 static bool definebydetrunMode(pxConfig *config) 506 803 { 507 804 bool status = false;
Note:
See TracChangeset
for help on using the changeset viewer.
