Changeset 8279 for trunk/ippTools/src/regtool.c
- Timestamp:
- Aug 10, 2006, 3:16:23 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/regtool.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/regtool.c
r8268 r8279 12 12 static bool updateexpMode(pxConfig *config); 13 13 static bool updateimfileMode(pxConfig *config); 14 static psArray *newFrameSearchPending(pxConfig *config); 15 static p1PendingExpRow *newToP1PendingExp(newExpRow *newExp); 14 // static p1PendingExpRow *newToP1PendingExp(newExpRow *newExp); 16 15 static p2PendingExpRow *newToP2PendingExp(pxConfig *config, newExpRow *newExp); 17 static p2PendingImfileRow *newImfileToP2PendingImfile(newImfileRow *newImfile); 18 static rawScienceFrame *newToRawScienceFrame(pxConfig *config, newFrame *newFrame); 16 static p2PendingImfileRow *rawImfileToP2PendingImfile(pxConfig *config, rawImfileRow *rawImfile); 19 17 static rawScienceExpRow *newToRawScienceExp(pxConfig *config, newExpRow *exp); 20 18 static rawDetrendExpRow *newToRawDetrendExp(pxConfig *config, newExpRow *exp); … … 179 177 if (!status) { 180 178 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id"); 179 psFree(query); 181 180 return false; 182 181 } … … 188 187 if (!p_psDBRunQuery(config->dbh, query)) { 189 188 psError(PS_ERR_UNKNOWN, false, "database error"); 190 return false; 191 } 189 psFree(query); 190 return false; 191 } 192 psFree(query); 192 193 193 194 psArray *output = p_psDBFetchResult(config->dbh); … … 205 206 } 206 207 208 // start a transaction so we don't end up with an exp in 209 // rawScience/DetrendExp and in newExp 210 if (!psDBTransaction(config->dbh)) { 211 psError(PS_ERR_UNKNOWN, false, "database error"); 212 psFree(output); 213 return false; 214 } 215 216 // if it's a detrend exp 217 if (detrend) { 218 for (long i = 0; psArrayLength(output) > i; i++) { 219 psMetadata *row = output->data[i]; 220 // convert metadata into a newExp object 221 newExpRow *newExp = newExpObjectFromMetadata(row); 222 // convert newExp object into a rawDetrendExp object 223 rawDetrendExpRow *rawExp = newToRawDetrendExp(config, newExp); 224 if (!rawExp) { 225 // rollback 226 if (!psDBRollback(config->dbh)) { 227 psError(PS_ERR_UNKNOWN, false, "database error"); 228 } 229 psError(PS_ERR_UNKNOWN, false, "failed to convert newExp to rawDetrendExp"); 230 psFree(newExp); 231 psFree(output); 232 return false; 233 } 234 // insert the rawDetrendExp object into the database 235 if (!rawDetrendExpInsertObject(config->dbh, rawExp)) { 236 // rollback 237 if (!psDBRollback(config->dbh)) { 238 psError(PS_ERR_UNKNOWN, false, "database error"); 239 } 240 psError(PS_ERR_UNKNOWN, false, "database error"); 241 psFree(rawExp); 242 psFree(newExp); 243 psFree(output); 244 return false; 245 } 246 psFree(rawExp); 247 // delete the newExp object from the database 248 if (!newExpDeleteObject(config->dbh, newExp)) { 249 // rollback 250 if (!psDBRollback(config->dbh)) { 251 psError(PS_ERR_UNKNOWN, false, "database error"); 252 } 253 psError(PS_ERR_UNKNOWN, false, "database error"); 254 psFree(newExp); 255 psFree(output); 256 return false; 257 } 258 psFree(newExp); 259 } 260 } 261 262 // else 263 // it's a science exp 207 264 for (long i = 0; psArrayLength(output) > i; i++) { 265 psMetadata *row = output->data[i]; 266 // convert metadata into a newExp object 267 newExpRow *newExp = newExpObjectFromMetadata(row); 268 // convert newExp object into a rawDetrendExp object 269 rawScienceExpRow *rawExp = newToRawScienceExp(config, newExp); 270 if (!rawExp) { 271 // rollback 272 if (!psDBRollback(config->dbh)) { 273 psError(PS_ERR_UNKNOWN, false, "database error"); 274 } 275 psError(PS_ERR_UNKNOWN, false, "failed to convert newExp to rawScienceExp"); 276 psFree(newExp); 277 psFree(output); 278 return false; 279 } 280 // insert the rawDetrendExp object into the database 281 if (!rawScienceExpInsertObject(config->dbh, rawExp)) { 282 // rollback 283 if (!psDBRollback(config->dbh)) { 284 psError(PS_ERR_UNKNOWN, false, "database error"); 285 } 286 psError(PS_ERR_UNKNOWN, false, "database error"); 287 psFree(rawExp); 288 psFree(newExp); 289 psFree(output); 290 return false; 291 } 292 psFree(rawExp); 293 // delete the newExp object from the database 294 if (!newExpDeleteObject(config->dbh, newExp)) { 295 // rollback 296 if (!psDBRollback(config->dbh)) { 297 psError(PS_ERR_UNKNOWN, false, "database error"); 298 } 299 psError(PS_ERR_UNKNOWN, false, "database error"); 300 psFree(newExp); 301 psFree(output); 302 return false; 303 } 304 // insert an entry into the p2PendingExp table 305 p2PendingExpRow *p2PendingExp = newToP2PendingExp(config, newExp); 306 if (!p2PendingExp) { 307 psError(PS_ERR_UNKNOWN, false, "failed to convert newExp to p2PendingExp"); 308 psFree(newExp); 309 psFree(output); 310 return false; 311 } 312 // insert the p2PendingExp object into the database 313 if (!p2PendingExpInsertObject(config->dbh, p2PendingExp)) { 314 // rollback 315 if (!psDBRollback(config->dbh)) { 316 psError(PS_ERR_UNKNOWN, false, "database error"); 317 } 318 psError(PS_ERR_UNKNOWN, false, "database error"); 319 psFree(p2PendingExp); 320 psFree(newExp); 321 psFree(output); 322 return false; 323 } 324 psFree(p2PendingExp); 325 // find all of the rawImfiles associated with the p2PendingExp object 326 psArray *rawImfiles = NULL; 327 { 328 psMetadata *where = psMetadataAlloc(); 329 if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", newExp->exp_id)) { 330 // rollback 331 if (!psDBRollback(config->dbh)) { 332 psError(PS_ERR_UNKNOWN, false, "database error"); 333 } 334 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id"); 335 psFree(where); 336 psFree(newExp); 337 psFree(output); 338 return false; 339 } 340 rawImfiles = rawImfileSelectRowObjects(config->dbh, where, 0); 341 psFree(where); 342 } 343 // sanity check the number of rawImfiles found 344 if (!rawImfiles) { 345 // rollback 346 if (!psDBRollback(config->dbh)) { 347 psError(PS_ERR_UNKNOWN, false, "database error"); 348 } 349 psError(PS_ERR_UNKNOWN, false, "found no rawImfiles associated with exp_id %s", newExp->exp_id); 350 psFree(newExp); 351 psFree(output); 352 return false; 353 } 354 if (psArrayLength(rawImfiles) != newExp->imfiles) { 355 // rollback 356 if (!psDBRollback(config->dbh)) { 357 psError(PS_ERR_UNKNOWN, false, "database error"); 358 } 359 psError(PS_ERR_UNKNOWN, false, "found %d rawImfiles but expected %d", 360 psArrayLength(rawImfiles), newExp->imfiles); 361 psFree(newExp); 362 psFree(output); 363 return false; 364 } 365 // convert the rawImfiles into p2PendingImfiles and insert them into 366 // the database 367 for (long i = 0; i < psArrayLength(rawImfiles); i++) { 368 rawImfileRow *rawImfile = rawImfiles->data[i]; 369 p2PendingImfileRow *pendingImfile = rawImfileToP2PendingImfile(config, rawImfile); 370 if (!p2PendingImfileInsertObject(config->dbh, pendingImfile)){ 371 // rollback 372 if (!psDBRollback(config->dbh)) { 373 psError(PS_ERR_UNKNOWN, false, "database error"); 374 } 375 psError(PS_ERR_UNKNOWN, false, "database error"); 376 psFree(pendingImfile); 377 psFree(rawImfiles); 378 psFree(newExp); 379 psFree(output); 380 } 381 psFree(pendingImfile); 382 } 383 psFree(rawImfiles); 384 psFree(newExp); 385 } 386 387 psFree(output); 388 389 if (!psDBCommit(config->dbh)) { 390 psError(PS_ERR_UNKNOWN, false, "database error"); 391 return false; 208 392 } 209 393 … … 349 533 } 350 534 351 #if 0 352 static psArray *newFrameSearchPending(pxConfig *config) 353 { 354 PS_ASSERT_PTR_NON_NULL(config, NULL); 355 356 char *query = "select newImfile.* from newImfile 357 LEFT JOIN newExp USING(exp_id) 358 LEFT JOIN rawScienceExp USING(exp_id) 359 LEFT JOIN rawDetrendExp USING (exp_id) 360 WHERE newExp.exp_id is NOT NULL 361 AND rawScienceExp.exp_id IS NULL 362 AND rawDetrendExp.exp_id IS NULL"; 363 364 if (!p_psDBRunQuery(config->dbh, query)) { 365 psError(PS_ERR_UNKNOWN, false, "database error"); 366 return false; 367 } 368 369 psArray *newExp = p_psDBFetchResult(config->dbh); 370 if (!output) { 371 // XXX check psError here 372 psError(PS_ERR_UNKNOWN, false, "failed to fetch the database result"); 373 return false; 374 } 375 376 for (long i = 0; i < psArrayLength(newExp); i++) { 377 newExpRow *exp = newExp->data[i]; 378 psMetadata *where = psMetadataAlloc(); 379 if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, NULL, exp->exp_id)) { 380 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id"); 381 psFree(where); 382 psFree(newExp); 383 return NULL; 384 } 385 new 386 387 psFree(where); 388 } 389 390 391 return new; 392 } 393 394 #endif 395 535 # if 0 396 536 static p1PendingExpRow *newToP1PendingExp(newExpRow *newExp) 397 537 { … … 412 552 ); 413 553 } 554 #endif 414 555 415 556 static p2PendingExpRow *newToP2PendingExp(pxConfig *config, newExpRow *exp) … … 418 559 PS_ASSERT_PTR_NON_NULL(exp, NULL); 419 560 420 bool status = false;421 psString filter = psMetadataLookupStr(&status, config->args, "-filter");422 if (!status) {423 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -filter");424 return false;425 }426 if (!filter) {427 psError(PS_ERR_UNKNOWN, true, "-filter is required");428 return false;429 }430 psF32 airmass = psMetadataLookupF32(&status, config->args, "-airmass");431 if (!status) {432 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -airmass");433 return false;434 }435 if (isnan(airmass)) {436 psError(PS_ERR_UNKNOWN, true, "-airmass is required");437 return false;438 }439 psF64 ra = psMetadataLookupF64(&status, config->args, "-ra");440 if (!status) {441 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ra");442 return false;443 }444 if (isnan(ra)) {445 psError(PS_ERR_UNKNOWN, true, "-ra is required");446 return false;447 }448 psF64 decl = psMetadataLookupF64(&status, config->args, "-decl");449 if (!status) {450 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -decl");451 return false;452 }453 if (isnan(decl)) {454 psError(PS_ERR_UNKNOWN, true, "-decl is required");455 return false;456 }457 psF32 exp_time = psMetadataLookupF32(&status, config->args, "-exp_time");458 if (!status) {459 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_time");460 return false;461 }462 if (isnan(exp_time)) {463 psError(PS_ERR_UNKNOWN, true, "-exp_time is required");464 return false;465 }466 psF64 background = psMetadataLookupF64(&status, config->args, "-background");467 if (!status) {468 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -background");469 return false;470 }471 if (isnan(background)) {472 psError(PS_ERR_UNKNOWN, true, "-background is required");473 return false;474 }475 476 561 return p2PendingExpRowAlloc( 477 562 exp->exp_id, 478 exp->camera,479 exp->telescope,480 exp->exp_type,481 exp->imfiles,482 filter,483 airmass,484 ra,485 decl,486 exp_time,487 background,488 563 "my recipe", 489 564 0xff, // XXX calc version number … … 492 567 } 493 568 494 static p2PendingImfileRow * newImfileToP2PendingImfile(newImfileRow *newImfile)569 static p2PendingImfileRow *rawImfileToP2PendingImfile(pxConfig *config, rawImfileRow *rawImfile) 495 570 { 496 571 return p2PendingImfileRowAlloc( 497 newImfile->exp_id,498 newImfile->class_id,499 newImfile->uri,572 rawImfile->exp_id, 573 rawImfile->class_id, 574 rawImfile->uri, 500 575 "my recipe", 501 576 0xff, // XXX calc version number … … 504 579 } 505 580 506 #if 0507 static rawScienceFrame *newToRawScienceFrame(pxConfig *config, newFrame *newFrame)508 {509 PS_ASSERT_PTR_NON_NULL(config, NULL);510 PS_ASSERT_PTR_NON_NULL(newFrame, NULL);511 512 newExpRow *newExp = newFrame->exposure;513 rawScienceExpRow *rawScienceExp = newToRawScienceExp(config, newExp);514 if (!rawScienceExp) {515 psError(PS_ERR_UNKNOWN, false, "failed to convert newExp to rawScienceExp");516 return NULL;517 }518 519 psArray *newImages = newFrame->images;520 psArray *rawImages = psArrayAlloc(psArrayLength(newImages));521 for (long i = 0; i < psArrayLength(newImages); i++) {522 newImfileRow *newImfile = newImages->data[i];523 rawImfileRow *rawImfile = rawImfileRowAlloc(524 newImfile->exp_id,525 newImfile->class,526 newImfile->class_id,527 newImfile->uri528 );529 psArrayAdd(rawImages, 0, rawImfile);530 psFree(rawImfile);531 }532 533 rawScienceFrame *rawScienceFrame = rawScienceFrameAlloc(rawScienceExp, rawImages);534 psFree(rawScienceExp);535 psFree(rawImages);536 537 return rawScienceFrame;538 }539 540 #endif541 542 581 static rawScienceExpRow *newToRawScienceExp(pxConfig *config, newExpRow *exp) 543 582 { … … 545 584 PS_ASSERT_PTR_NON_NULL(exp, NULL); 546 585 547 bool status = false; 548 psString filter = psMetadataLookupStr(&status, config->args, "-filter"); 549 if (!status) { 550 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -filter"); 551 return NULL; 552 } 553 if (!filter) { 554 psError(PS_ERR_UNKNOWN, true, "-filter is required"); 555 return NULL; 556 } 557 psF32 airmass = psMetadataLookupF32(&status, config->args, "-airmass"); 558 if (!status) { 559 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -airmass"); 560 return NULL; 561 } 562 if (isnan(airmass)) { 563 psError(PS_ERR_UNKNOWN, true, "-airmass is required"); 564 return NULL; 565 } 566 psF64 ra = psMetadataLookupF64(&status, config->args, "-ra"); 567 if (!status) { 568 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ra"); 569 return NULL; 570 } 571 if (isnan(ra)) { 572 psError(PS_ERR_UNKNOWN, true, "-ra is required"); 573 return NULL; 574 } 575 psF64 decl = psMetadataLookupF64(&status, config->args, "-decl"); 576 if (!status) { 577 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -decl"); 578 return NULL; 579 } 580 if (isnan(decl)) { 581 psError(PS_ERR_UNKNOWN, true, "-decl is required"); 582 return NULL; 583 } 584 psF32 exp_time = psMetadataLookupF32(&status, config->args, "-exp_time"); 585 if (!status) { 586 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_time"); 587 return NULL; 588 } 589 if (isnan(exp_time)) { 590 psError(PS_ERR_UNKNOWN, true, "-exp_time is required"); 591 return NULL; 592 } 593 psF64 background = psMetadataLookupF64(&status, config->args, "-background"); 594 if (!status) { 595 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -background"); 596 return NULL; 597 } 598 if (isnan(background)) { 599 psError(PS_ERR_UNKNOWN, true, "-background is required"); 600 return NULL; 601 } 602 603 return rawScienceExpRowAlloc( 604 exp->exp_id, 605 exp->camera, 606 exp->telescope, 607 exp->exp_type, 608 exp->imfiles, 609 filter, 610 airmass, 611 ra, 612 decl, 613 exp_time, 614 background 615 ); 586 // XXX this is dangerous but we should be able to get away with this as 587 // long rawScienceExp & rawDetrendExp are idetnical 588 return (rawScienceExpRow *)newToRawDetrendExp(config, exp); 616 589 } 617 590 … … 667 640 return false; 668 641 } 669 psF64 background = psMetadataLookupF64(&status, config->args, "-background"); 670 if (!status) { 671 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -background"); 672 return false; 673 } 674 if (!exp_time) { 675 psError(PS_ERR_UNKNOWN, true, "-background is required"); 642 psF64 bg = psMetadataLookupF64(&status, config->args, "-bg"); 643 if (!status) { 644 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg"); 645 return false; 646 } 647 if (isnan(bg)) { 648 psError(PS_ERR_UNKNOWN, true, "-bg is required"); 649 return false; 650 } 651 psF64 bg_stdev = psMetadataLookupF64(&status, config->args, "-bg_stdev"); 652 if (!status) { 653 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_stdev"); 654 return false; 655 } 656 if (isnan(bg_stdev)) { 657 psError(PS_ERR_UNKNOWN, true, "-bg_stdev is required"); 658 return false; 659 } 660 psF64 bg_mean_stdev = psMetadataLookupF64(&status, config->args, "-bg_mean_stdev"); 661 if (!status) { 662 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_mean_stdev"); 663 return false; 664 } 665 if (isnan(bg_mean_stdev)) { 666 psError(PS_ERR_UNKNOWN, true, "-bg_mean_stdev is required"); 667 return false; 668 } 669 psF64 alt = psMetadataLookupF64(&status, config->args, "-alt"); 670 if (!status) { 671 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -alt"); 672 return false; 673 } 674 if (isnan(alt)) { 675 psError(PS_ERR_UNKNOWN, true, "-alt is required"); 676 return false; 677 } 678 psF64 az = psMetadataLookupF64(&status, config->args, "-az"); 679 if (!status) { 680 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -az"); 681 return false; 682 } 683 if (isnan(az)) { 684 psError(PS_ERR_UNKNOWN, true, "-az is required"); 685 return false; 686 } 687 psF32 ccd_temp = psMetadataLookupF32(&status, config->args, "-ccd_temp"); 688 if (!status) { 689 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ccd_temp"); 690 return false; 691 } 692 if (isnan(ccd_temp)) { 693 psError(PS_ERR_UNKNOWN, true, "-ccd_temp is required"); 694 return false; 695 } 696 psF64 posang = psMetadataLookupF32(&status, config->args, "-posang"); 697 if (!status) { 698 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -posang"); 699 return false; 700 } 701 if (isnan(posang)) { 702 psError(PS_ERR_UNKNOWN, true, "-posang is required"); 676 703 return false; 677 704 } … … 688 715 decl, 689 716 exp_time, 690 background 717 bg, 718 bg_stdev, 719 bg_mean_stdev, 720 alt, 721 az, 722 ccd_temp, 723 posang 691 724 ); 692 725 } … … 752 785 return false; 753 786 } 754 psF64 bg_stdev = psMetadataLookupF64(&status, config->args, "-bg ");787 psF64 bg_stdev = psMetadataLookupF64(&status, config->args, "-bg_stdev"); 755 788 if (!status) { 756 789 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_stdev"); … … 761 794 return false; 762 795 } 763 psF64 bg_mean_stdev = psMetadataLookupF64(&status, config->args, "-bg ");796 psF64 bg_mean_stdev = psMetadataLookupF64(&status, config->args, "-bg_mean_stdev"); 764 797 if (!status) { 765 798 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_mean_stdev"); … … 770 803 return false; 771 804 } 772 psF64 alt = psMetadataLookupF64(&status, config->args, "- bg");805 psF64 alt = psMetadataLookupF64(&status, config->args, "-alt"); 773 806 if (!status) { 774 807 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -alt"); … … 779 812 return false; 780 813 } 781 psF64 az = psMetadataLookupF64(&status, config->args, "- bg");814 psF64 az = psMetadataLookupF64(&status, config->args, "-az"); 782 815 if (!status) { 783 816 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -az"); … … 788 821 return false; 789 822 } 790 psF32 ccd_temp = psMetadataLookupF32(&status, config->args, "- bg");823 psF32 ccd_temp = psMetadataLookupF32(&status, config->args, "-ccd_temp"); 791 824 if (!status) { 792 825 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ccd_temp"); … … 797 830 return false; 798 831 } 799 psF64 posang = psMetadataLookupF32(&status, config->args, "- bg");832 psF64 posang = psMetadataLookupF32(&status, config->args, "-posang"); 800 833 if (!status) { 801 834 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -posang");
Note:
See TracChangeset
for help on using the changeset viewer.
