Changeset 27177
- Timestamp:
- Mar 3, 2010, 5:11:47 PM (16 years ago)
- Location:
- trunk/psModules/src/objects
- Files:
-
- 4 edited
-
pmPSF_IO.c (modified) (32 diffs)
-
pmSourceIO_CMF_PS1_V1.c (modified) (6 diffs)
-
pmSourceIO_CMF_PS1_V2.c (modified) (7 diffs)
-
pmSourceIO_MatchedRefs.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmPSF_IO.c
r25979 r27177 122 122 if (view->chip == -1) { 123 123 if (!pmPSFmodelWriteFPA(fpa, view, file, config)) { 124 psError( PS_ERR_IO, false, "Failed to write PSF for fpa");124 psError(psErrorCodeLast(), false, "Failed to write PSF for fpa"); 125 125 return false; 126 126 } … … 135 135 if (view->cell == -1) { 136 136 if (!pmPSFmodelWriteChip (chip, view, file, config)) { 137 psError( PS_ERR_IO, false, "Failed to write PSF for chip");137 psError(psErrorCodeLast(), false, "Failed to write PSF for chip"); 138 138 return false; 139 139 } … … 141 141 } 142 142 143 psError(P S_ERR_IO, false, "PSF must be written at the chip level");143 psError(PM_ERR_CONFIG, true, "PSF must be written at the chip level"); 144 144 return false; 145 145 } … … 158 158 thisView->chip = i; 159 159 if (!pmPSFmodelWriteChip (chip, thisView, file, config)) { 160 psError( PS_ERR_IO, false, "Failed to write PSF for %dth chip", i);160 psError(psErrorCodeLast(), false, "Failed to write PSF for %dth chip", i); 161 161 psFree(thisView); 162 162 return false; … … 173 173 PS_ASSERT_PTR_NON_NULL(chip, false); 174 174 175 if (!pmPSFmodelWrite (chip->analysis, view, file, config)) {176 psError( PS_ERR_IO, false, "Failed to write PSF for chip");175 if (!pmPSFmodelWrite(chip->analysis, view, file, config)) { 176 psError(psErrorCodeLast(), false, "Failed to write PSF for chip"); 177 177 return false; 178 178 } … … 197 197 char *headName, *tableName, *residName; 198 198 199 if (!analysis) return false; 199 if (!analysis) { 200 psError(PM_ERR_PROG, true, "No analysis metadata for chip."); 201 return false; 202 } 200 203 201 204 // select the current recipe 202 205 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, "PSPHOT"); 203 206 if (!recipe) { 204 psError(P S_ERR_UNKNOWN, false, "missing recipe %s", "PSPHOT");207 psError(PM_ERR_CONFIG, false, "missing recipe %s", "PSPHOT"); 205 208 return false; 206 209 } … … 213 216 // get the current header 214 217 pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config, false); // Suitable FPA for writing 218 if (!fpa) { 219 psError(psErrorCodeLast(), false, "Unable to get FPA for writing."); 220 return false; 221 } 215 222 pmHDU *hdu = psMemIncrRefCounter(pmFPAviewThisHDU(view, fpa)); 216 223 psFree(fpa); 217 224 if (!hdu) { 218 psError(P S_ERR_UNKNOWN, false, "Unable to find HDU");225 psError(PM_ERR_CONFIG, false, "Unable to find HDU"); 219 226 return false; 220 227 } … … 234 241 psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES"); 235 242 if (!menu) { 236 psError(P S_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");243 psError(PM_ERR_CONFIG, true, "missing EXTNAME.RULES in camera.config"); 237 244 psFree(hdu); 238 245 return false; … … 242 249 rule = psMetadataLookupStr(&status, menu, "PSF.HEAD"); 243 250 if (!rule) { 244 psError(P S_ERR_UNKNOWN, false, "missing entry for PSF.HEAD in EXTNAME.RULES in camera.config");251 psError(PM_ERR_CONFIG, false, "missing entry for PSF.HEAD in EXTNAME.RULES in camera.config"); 245 252 psFree(hdu); 246 253 return false; … … 251 258 rule = psMetadataLookupStr(&status, menu, "PSF.TABLE"); 252 259 if (!rule) { 253 psError(P S_ERR_UNKNOWN, false, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config");260 psError(PM_ERR_CONFIG, false, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config"); 254 261 psFree (headName); 255 262 psFree(hdu); … … 261 268 rule = psMetadataLookupStr(&status, menu, "PSF.RESID"); 262 269 if (!rule) { 263 psError(P S_ERR_UNKNOWN, false, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config");270 psError(PM_ERR_CONFIG, false, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config"); 264 271 psFree (headName); 265 272 psFree (tableName); … … 294 301 } 295 302 296 psFitsWriteBlank (file->fits, hdu->header, headName); 303 if (!psFitsWriteBlank(file->fits, hdu->header, headName)) { 304 psError(psErrorCodeLast(), false, "Unable to write PSF PHU."); 305 psFree(hdu); 306 return false; 307 } 297 308 psTrace ("pmFPAfile", 5, "wrote ext head %s (type: %d)\n", file->filename, file->type); 298 309 file->header = hdu->header; … … 304 315 pmPSF *psf = psMetadataLookupPtr (&status, analysis, "PSPHOT.PSF"); 305 316 if (!psf) { 306 psError(P S_ERR_UNKNOWN, true, "missing PSF for this analysis metadata");317 psError(PM_ERR_PROG, true, "missing PSF for this analysis metadata"); 307 318 psFree (tableName); 308 319 psFree (residName); … … 322 333 psMetadataAddBool (header, PS_LIST_TAIL, "ERR_PAR", 0, "Use Poisson errors in fits?", psf->poissonErrorsParams); 323 334 324 int nPar = pmModelClassParameterCount (psf->type) ;335 int nPar = pmModelClassParameterCount (psf->type); 325 336 psMetadataAdd (header, PS_LIST_TAIL, "PSF_NPAR", PS_DATA_S32, "PSF model parameter count", nPar); 326 337 … … 436 447 // write an empty FITS segment if we have no PSF information 437 448 if (psfTable->n == 0) { 438 // XXX this is probably an error (if we have a PSF, how do we have no data?) 439 psFitsWriteBlank (file->fits, header, tableName); 449 psError(PM_ERR_PROG, true, "No PSF data to write."); 450 psFree(tableName); 451 psFree(residName); 452 psFree(psfTable); 453 psFree(header); 454 return false; 440 455 } else { 441 456 psTrace ("pmFPAfile", 5, "writing psf data %s\n", tableName); 442 if (!psFitsWriteTable (file->fits, header, psfTable, tableName)) {443 psError( PS_ERR_IO, false, "writing psf table data %s\n", tableName);457 if (!psFitsWriteTable(file->fits, header, psfTable, tableName)) { 458 psError(psErrorCodeLast(), false, "Error writing psf table data %s\n", tableName); 444 459 psFree (tableName); 445 460 psFree (residName); … … 459 474 if (psf->residuals == NULL) { 460 475 // set some header keywords to make it clear there are no residuals? 461 psFitsWriteBlank (file->fits, header, residName); 476 if (!psFitsWriteBlank(file->fits, header, residName)) { 477 psError(psErrorCodeLast(), false, "Unable to write blank PSF residual image."); 478 psFree(residName); 479 psFree(header); 480 return false; 481 } 462 482 psFree (residName); 463 483 psFree (header); … … 479 499 psArrayAdd (images, 1, psf->residuals->Ry); 480 500 481 psFitsWriteImageCube (file->fits, header, images, residName); 501 if (!psFitsWriteImageCube (file->fits, header, images, residName)) { 502 psError(psErrorCodeLast(), false, "Unable to write PSF residuals."); 503 psFree(images); 504 psFree(residName); 505 psFree(header); 506 return false; 507 } 482 508 psFree (images); 483 509 } else { 484 510 // this call creates an extension with NAXIS3 = 1 485 psFitsWriteImage(file->fits, header, psf->residuals->Ro, 0, residName); 511 if (!psFitsWriteImage(file->fits, header, psf->residuals->Ro, 0, residName)) { 512 psError(psErrorCodeLast(), false, "Unable to write PSF residuals."); 513 psFree(images); 514 psFree(residName); 515 psFree(header); 516 return false; 517 } 486 518 } 487 519 psFree (residName); … … 495 527 if (0) { 496 528 // set some header keywords to make it clear there are no residuals? 497 psFitsWriteBlank (file->fits, header, residName); 529 if (!psFitsWriteBlank (file->fits, header, residName)) { 530 psError(psErrorCodeLast(), false, "Unable to write blank PSF residuals."); 531 psFree(residName); 532 psFree(header); 533 return false; 534 } 498 535 psFree (residName); 499 536 psFree (header); … … 501 538 } 502 539 503 int DX = 65; 504 int DY = 65; 505 506 psImage *psfMosaic = psImageAlloc (DX, DY, PS_TYPE_F32); 507 psImageInit (psfMosaic, 0.0); 508 509 pmModel *modelRef = pmModelAlloc(psf->type); 510 511 // use the center of the center pixel of the image 512 float xc = 0.5*psf->fieldNx; 513 float yc = 0.5*psf->fieldNy; 514 515 // assign the x and y coords to the image center 516 // create an object with center intensity of 1000 517 modelRef->params->data.F32[PM_PAR_SKY] = 0; 518 modelRef->params->data.F32[PM_PAR_I0] = 1.000; 519 modelRef->params->data.F32[PM_PAR_XPOS] = xc; 520 modelRef->params->data.F32[PM_PAR_YPOS] = yc; 521 522 // create modelPSF from this model 523 pmModel *model = pmModelFromPSF (modelRef, psf); 524 if (model) { 525 // place the reference object in the image center 526 pmModelAddWithOffset (psfMosaic, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_CENTER, 0, 0.0, 0.0); 527 psFree (model); 528 529 if (false) { 530 // this call creates an extension with NAXIS3 = 3 531 psArray *images = psArrayAllocEmpty (3); 532 psArrayAdd (images, 1, psfMosaic); 533 // psArrayAdd (images, 1, psfModel); 534 // psArrayAdd (images, 1, psfModel); 535 536 psFitsWriteImageCube (file->fits, header, images, "PSF_MODEL"); 537 psFree (images); 538 } else { 539 // this call creates an extension with NAXIS3 = 1 540 // XXX need to replace PSF_MODEL with rule-based name like residName 541 psFitsWriteImage(file->fits, header, psfMosaic, 0, "PSF_MODEL"); 542 } 543 } 540 int DX = 65; 541 int DY = 65; 542 543 psImage *psfMosaic = psImageAlloc (DX, DY, PS_TYPE_F32); 544 psImageInit (psfMosaic, 0.0); 545 546 pmModel *modelRef = pmModelAlloc(psf->type); 547 548 // use the center of the center pixel of the image 549 float xc = 0.5*psf->fieldNx; 550 float yc = 0.5*psf->fieldNy; 551 552 // assign the x and y coords to the image center 553 // create an object with center intensity of 1000 554 modelRef->params->data.F32[PM_PAR_SKY] = 0; 555 modelRef->params->data.F32[PM_PAR_I0] = 1.000; 556 modelRef->params->data.F32[PM_PAR_XPOS] = xc; 557 modelRef->params->data.F32[PM_PAR_YPOS] = yc; 558 559 // create modelPSF from this model 560 pmModel *model = pmModelFromPSF (modelRef, psf); 561 if (model) { 562 // place the reference object in the image center 563 pmModelAddWithOffset (psfMosaic, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_CENTER, 0, 0.0, 0.0); 564 psFree (model); 565 566 if (false) { 567 // this call creates an extension with NAXIS3 = 3 568 psArray *images = psArrayAllocEmpty (3); 569 psArrayAdd (images, 1, psfMosaic); 570 // psArrayAdd (images, 1, psfModel); 571 // psArrayAdd (images, 1, psfModel); 572 573 if (!psFitsWriteImageCube (file->fits, header, images, "PSF_MODEL")) { 574 psError(psErrorCodeLast(), false, "Unable to write PSF representation."); 575 psFree(images); 576 psFree(psfMosaic); 577 psFree(modelRef); 578 psFree(header); 579 return false; 580 } 581 psFree (images); 582 } else { 583 // this call creates an extension with NAXIS3 = 1 584 // XXX need to replace PSF_MODEL with rule-based name like residName 585 if (!psFitsWriteImage(file->fits, header, psfMosaic, 0, "PSF_MODEL")) { 586 psError(psErrorCodeLast(), false, "Unable to write PSF representation."); 587 psFree(psfMosaic); 588 psFree(modelRef); 589 psFree(header); 590 return false; 591 } 592 } 593 } 544 594 545 595 psFree (psfMosaic); … … 594 644 // find the FPA phu 595 645 pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config, false); // Suitable FPA for writing 646 if (!fpa) { 647 psError(psErrorCodeLast(), false, "Unable to build FPA to write."); 648 return false; 649 } 596 650 pmHDU *phu = psMemIncrRefCounter(pmFPAviewThisPHU(view, fpa)); 597 651 psFree(fpa); … … 604 658 psMetadataCopy (outhead, phu->header); 605 659 } else { 606 pmConfigConformHeader (outhead, file->format); 660 if (!pmConfigConformHeader (outhead, file->format)) { 661 psError(psErrorCodeLast(), false, "Unable to conform header of PSF PHU."); 662 psFree(phu); 663 return false; 664 } 607 665 } 608 666 psFree(phu); 609 667 610 668 psMetadataAddBool (outhead, PS_LIST_TAIL, "EXTEND", PS_META_REPLACE, "this file has extensions", true); 611 psFitsWriteBlank (file->fits, outhead, ""); 669 if (!psFitsWriteBlank (file->fits, outhead, "")) { 670 psError(psErrorCodeLast(), false, "Unable to write PHU for PSF."); 671 psFree(outhead); 672 return false; 673 } 612 674 file->wrote_phu = true; 613 675 … … 639 701 } 640 702 641 psError(P S_ERR_IO, false, "PSF must be read at the chip level");703 psError(PM_ERR_CONFIG, true, "PSF must be read at the chip level"); 642 704 return false; 643 705 } … … 666 728 667 729 if (!pmPSFmodelRead (chip->analysis, view, file, config)) { 668 psError( PS_ERR_IO, false, "Failed to write PSF for chip");730 psError(psErrorCodeLast(), false, "Failed to write PSF for chip"); 669 731 return false; 670 732 } … … 689 751 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, "PSPHOT"); 690 752 if (!recipe) { 691 psError(P S_ERR_UNKNOWN, false, "missing recipe %s", "PSPHOT");753 psError(PM_ERR_CONFIG, false, "missing recipe %s", "PSPHOT"); 692 754 return false; 693 755 } … … 696 758 psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES"); 697 759 if (!menu) { 698 psError(P S_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");760 psError(PM_ERR_CONFIG, true, "missing EXTNAME.RULES in camera.config"); 699 761 return false; 700 762 } … … 702 764 rule = psMetadataLookupStr(&status, menu, "PSF.TABLE"); 703 765 if (!rule) { 704 psError(P S_ERR_UNKNOWN, true, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config");766 psError(PM_ERR_CONFIG, true, "missing entry for PSF.TABLE in EXTNAME.RULES in camera.config"); 705 767 return false; 706 768 } … … 709 771 rule = psMetadataLookupStr(&status, menu, "PSF.RESID"); 710 772 if (!rule) { 711 psError(P S_ERR_UNKNOWN, true, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config");773 psError(PM_ERR_CONFIG, true, "missing entry for PSF.RESID in EXTNAME.RULES in camera.config"); 712 774 return false; 713 775 } … … 717 779 // advance to the table data extension 718 780 // since we have read the IMAGE header, the TABLE header should exist 719 if (!psFitsMoveExtName (file->fits, tableName)) { 720 psAbort("cannot find data extension %s in %s", tableName, file->filename); 781 if (!psFitsMoveExtName(file->fits, tableName)) { 782 psError(psErrorCodeLast(), false, "cannot find data extension %s in %s", tableName, file->filename); 783 return false; 721 784 } 722 785 723 786 // load the PSF model table header 724 787 header = psFitsReadHeader (NULL, file->fits); 725 if (!header) psAbort("cannot read table header"); 788 if (!header) { 789 psError(psErrorCodeLast(), false, "Cannot read PSF table header."); 790 return false; 791 } 726 792 727 793 pmPSFOptions *options = pmPSFOptionsAlloc(); … … 835 901 char *modeName = psMetadataLookupStr (&status, header, name); 836 902 if (!status) { 837 psError(P S_ERR_UNKNOWN, true, "inconsistent PSF header: NX & NY defined for PAR %d, but not MD", i);903 psError(PM_ERR_IO, true, "inconsistent PSF header: NX & NY defined for PAR %d, but not MD", i); 838 904 return false; 839 905 } … … 869 935 // read the raw table data 870 936 psArray *table = psFitsReadTable (file->fits); 937 if (!table) { 938 psError(psErrorCodeLast(), false, "Unable to read PSF table."); 939 psFree(header); 940 return false; 941 } 871 942 872 943 // fill in the matching psf->params entries … … 913 984 // since we have read the IMAGE header, the TABLE header should exist 914 985 if (!psFitsMoveExtName (file->fits, imageName)) { 915 psAbort("cannot find data extension %s in %s", imageName, file->filename); 986 psError(psErrorCodeLast(), false, "Cannot find PSF data extension %s in %s", 987 imageName, file->filename); 988 return false; 916 989 } 917 990 918 991 header = psFitsReadHeader (NULL, file->fits); 992 if (!header) { 993 psError(psErrorCodeLast(), false, "Unable to read PSF header."); 994 return false; 995 } 919 996 int Naxis = psMetadataLookupS32 (&status, header, "NAXIS"); 920 997 if (Naxis != 0) { … … 936 1013 937 1014 psRegion fullImage = {0, 0, 0, 0}; 938 psFitsReadImageBuffer(psf->residuals->Ro, file->fits, fullImage, 0); // Desired pixels 1015 if (!psFitsReadImageBuffer(psf->residuals->Ro, file->fits, fullImage, 0)) { 1016 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1017 return false; 1018 } 939 1019 if (Nz > 1) { 940 1020 assert (Nz == 3); 941 psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1); // Desired pixels 942 psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2); // Desired pixels 1021 if (!psFitsReadImageBuffer(psf->residuals->Rx, file->fits, fullImage, 1)) { 1022 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1023 return false; 1024 } 1025 if (!psFitsReadImageBuffer(psf->residuals->Ry, file->fits, fullImage, 2)) { 1026 psError(psErrorCodeLast(), false, "Unable to read PSF residual image."); 1027 return false; 1028 } 943 1029 } 944 1030 // XXX notice that we are not saving the resid->mask -
trunk/psModules/src/objects/pmSourceIO_CMF_PS1_V1.c
r26964 r27177 216 216 217 217 if (table->n == 0) { 218 psFitsWriteBlank(fits, header, extname); 218 if (!psFitsWriteBlank(fits, header, extname)) { 219 psError(psErrorCodeLast(), false, "Unable to write empty sources file."); 220 psFree(table); 221 psFree(header); 222 return false; 223 } 219 224 psFree(table); 220 225 psFree(header); … … 224 229 psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname); 225 230 if (!psFitsWriteTable(fits, header, table, extname)) { 226 psError( PS_ERR_IO, false, "writing ext data %s\n", extname);231 psError(psErrorCodeLast(), false, "writing ext data %s\n", extname); 227 232 psFree(table); 228 233 psFree(header); … … 486 491 487 492 if (table->n == 0) { 488 psFitsWriteBlank (fits, outhead, extname); 493 if (!psFitsWriteBlank (fits, outhead, extname)) { 494 psError(psErrorCodeLast(), false, "Unable to write empty sources."); 495 psFree(outhead); 496 psFree(table); 497 return false; 498 } 489 499 psFree (outhead); 490 500 psFree (table); … … 494 504 psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname); 495 505 if (!psFitsWriteTable (fits, outhead, table, extname)) { 496 psError( PS_ERR_IO, false, "writing ext data %s\n", extname);506 psError(psErrorCodeLast(), false, "writing ext data %s\n", extname); 497 507 psFree (outhead); 498 508 psFree(table); … … 612 622 613 623 if (table->n == 0) { 614 psFitsWriteBlank (fits, outhead, extname); 624 if (!psFitsWriteBlank (fits, outhead, extname)) { 625 psError(psErrorCodeLast(), false, "Unable to write empty sources."); 626 psFree(outhead); 627 psFree(table); 628 return false; 629 } 615 630 psFree (outhead); 616 631 psFree (table); … … 620 635 psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname); 621 636 if (!psFitsWriteTable (fits, outhead, table, extname)) { 622 psError( PS_ERR_IO, false, "writing ext data %s\n", extname);637 psError(psErrorCodeLast(), false, "writing ext data %s\n", extname); 623 638 psFree (outhead); 624 639 psFree(table); -
trunk/psModules/src/objects/pmSourceIO_CMF_PS1_V2.c
r26964 r27177 216 216 217 217 if (table->n == 0) { 218 psFitsWriteBlank(fits, header, extname); 218 if (!psFitsWriteBlank(fits, header, extname)) { 219 psError(psErrorCodeLast(), false, "Unable to write blank sources file."); 220 psFree(table); 221 psFree(header); 222 return false; 223 } 219 224 psFree(table); 220 225 psFree(header); … … 224 229 psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname); 225 230 if (!psFitsWriteTable(fits, header, table, extname)) { 226 psError( PS_ERR_IO, false, "writing ext data %s\n", extname);231 psError(psErrorCodeLast(), false, "writing ext data %s\n", extname); 227 232 psFree(table); 228 233 psFree(header); … … 264 269 for (int i = 0; i < numSources; i++) { 265 270 psMetadata *row = psFitsReadTableRow(fits, i); // Table row 271 if (!row) { 272 psError(psErrorCodeLast(), false, "Unable to read row %d of sources", i); 273 psFree(sources); 274 return NULL; 275 } 266 276 267 277 pmSource *source = pmSourceAlloc (); … … 487 497 488 498 if (table->n == 0) { 489 psFitsWriteBlank (fits, outhead, extname); 499 if (!psFitsWriteBlank (fits, outhead, extname)) { 500 psError(psErrorCodeLast(), false, "Unable to write empty sources file."); 501 psFree(outhead); 502 psFree(table); 503 return false; 504 } 490 505 psFree (outhead); 491 506 psFree (table); … … 495 510 psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname); 496 511 if (!psFitsWriteTable (fits, outhead, table, extname)) { 497 psError( PS_ERR_IO, false, "writing ext data %s\n", extname);512 psError(psErrorCodeLast(), false, "writing ext data %s\n", extname); 498 513 psFree (outhead); 499 514 psFree(table); … … 613 628 614 629 if (table->n == 0) { 615 psFitsWriteBlank (fits, outhead, extname); 630 if (!psFitsWriteBlank (fits, outhead, extname)) { 631 psError(psErrorCodeLast(), false, "Unable to write empty sources file."); 632 psFree(outhead); 633 psFree(table); 634 return false; 635 } 616 636 psFree (outhead); 617 637 psFree (table); … … 621 641 psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname); 622 642 if (!psFitsWriteTable (fits, outhead, table, extname)) { 623 psError( PS_ERR_IO, false, "writing ext data %s\n", extname);643 psError(psErrorCodeLast(), false, "writing ext data %s\n", extname); 624 644 psFree (outhead); 625 645 psFree(table); -
trunk/psModules/src/objects/pmSourceIO_MatchedRefs.c
r26893 r27177 67 67 68 68 if (!table) { 69 table = psArrayAllocEmpty (0x1000);70 pmFPAview *view = pmFPAviewAlloc (0);69 table = psArrayAllocEmpty (0x1000); 70 pmFPAview *view = pmFPAviewAlloc (0); 71 71 72 // this loop selects the matched stars for all chips73 while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {74 psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);75 if (!chip->process || !chip->file_exists) continue;72 // this loop selects the matched stars for all chips 73 while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) { 74 psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 75 if (!chip->process || !chip->file_exists) continue; 76 76 77 char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME");77 char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); 78 78 79 while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {80 psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);81 if (!cell->process || !cell->file_exists) continue;79 while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) { 80 psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 81 if (!cell->process || !cell->file_exists) continue; 82 82 83 // process each of the readouts84 // XXX there can only be one readout per chip, right?85 while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) {86 if (! readout->data_exists) continue;83 // process each of the readouts 84 // XXX there can only be one readout per chip, right? 85 while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) { 86 if (! readout->data_exists) continue; 87 87 88 // select the raw objects for this readout89 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS");90 if (rawstars == NULL) continue;88 // select the raw objects for this readout 89 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS"); 90 if (rawstars == NULL) continue; 91 91 92 // select the raw objects for this readout93 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS");94 if (refstars == NULL) continue;95 psTrace ("psastro", 4, "Trying %ld refstars\n", refstars->n);92 // select the raw objects for this readout 93 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS"); 94 if (refstars == NULL) continue; 95 psTrace ("psastro", 4, "Trying %ld refstars\n", refstars->n); 96 96 97 97 # if (0) 98 // XXX test99 FILE *outfile = fopen ("refstars.dat", "w");100 assert (outfile);101 for (int nn = 0; nn < refstars->n; nn++) {102 pmAstromObj *ref = refstars->data[nn];103 fprintf (outfile, "%lf %lf\n", ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD);104 }105 fclose (outfile);98 // XXX test 99 FILE *outfile = fopen ("refstars.dat", "w"); 100 assert (outfile); 101 for (int nn = 0; nn < refstars->n; nn++) { 102 pmAstromObj *ref = refstars->data[nn]; 103 fprintf (outfile, "%lf %lf\n", ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD); 104 } 105 fclose (outfile); 106 106 # endif 107 107 108 psArray *matches = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.MATCH");109 if (matches == NULL) continue;108 psArray *matches = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.MATCH"); 109 if (matches == NULL) continue; 110 110 111 for (int i = 0; i < matches->n; i++) {112 pmAstromMatch *match = matches->data[i];111 for (int i = 0; i < matches->n; i++) { 112 pmAstromMatch *match = matches->data[i]; 113 113 114 pmAstromObj *raw = rawstars->data[match->raw];115 pmAstromObj *ref = refstars->data[match->ref];114 pmAstromObj *raw = rawstars->data[match->raw]; 115 pmAstromObj *ref = refstars->data[match->ref]; 116 116 117 psMetadata *row = psMetadataAlloc ();118 psMetadataAdd (row, PS_LIST_TAIL, "RA", PS_DATA_F64, "right ascension (deg, J2000)", PM_DEG_RAD*ref->sky->r);119 psMetadataAdd (row, PS_LIST_TAIL, "DEC", PS_DATA_F64, "declination (deg, J2000)", PM_DEG_RAD*ref->sky->d);120 psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP", PS_DATA_F32, "x coord on chip", raw->chip->x);121 psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP", PS_DATA_F32, "y coord on chip", raw->chip->y);122 psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP_FIT",PS_DATA_F32, "x fitted coord on chip", ref->chip->x);123 psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP_FIT",PS_DATA_F32, "y fitted coord on chip", ref->chip->y);124 psMetadataAdd (row, PS_LIST_TAIL, "X_FPA", PS_DATA_F32, "x coord on focal plane", raw->FP->x);125 psMetadataAdd (row, PS_LIST_TAIL, "Y_FPA", PS_DATA_F32, "y coord on focal plane", raw->FP->y);126 psMetadataAdd (row, PS_LIST_TAIL, "MAG_INST", PS_DATA_F32, "instrumental magnitude", raw->Mag);127 psMetadataAdd (row, PS_LIST_TAIL, "MAG_REF", PS_DATA_F32, "reference star magnitude", ref->Mag);128 psMetadataAdd (row, PS_LIST_TAIL, "COLOR_REF",PS_DATA_F32, "reference star color", ref->Color);129 psMetadataAdd (row, PS_LIST_TAIL, "CHIP_ID", PS_DATA_STRING, "chip identifier", chipName);130 // XXX need to add the reference color, but this needs getstar / dvo.photcodes for the reference to be refined.117 psMetadata *row = psMetadataAlloc (); 118 psMetadataAdd (row, PS_LIST_TAIL, "RA", PS_DATA_F64, "right ascension (deg, J2000)", PM_DEG_RAD*ref->sky->r); 119 psMetadataAdd (row, PS_LIST_TAIL, "DEC", PS_DATA_F64, "declination (deg, J2000)", PM_DEG_RAD*ref->sky->d); 120 psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP", PS_DATA_F32, "x coord on chip", raw->chip->x); 121 psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP", PS_DATA_F32, "y coord on chip", raw->chip->y); 122 psMetadataAdd (row, PS_LIST_TAIL, "X_CHIP_FIT",PS_DATA_F32, "x fitted coord on chip", ref->chip->x); 123 psMetadataAdd (row, PS_LIST_TAIL, "Y_CHIP_FIT",PS_DATA_F32, "y fitted coord on chip", ref->chip->y); 124 psMetadataAdd (row, PS_LIST_TAIL, "X_FPA", PS_DATA_F32, "x coord on focal plane", raw->FP->x); 125 psMetadataAdd (row, PS_LIST_TAIL, "Y_FPA", PS_DATA_F32, "y coord on focal plane", raw->FP->y); 126 psMetadataAdd (row, PS_LIST_TAIL, "MAG_INST", PS_DATA_F32, "instrumental magnitude", raw->Mag); 127 psMetadataAdd (row, PS_LIST_TAIL, "MAG_REF", PS_DATA_F32, "reference star magnitude", ref->Mag); 128 psMetadataAdd (row, PS_LIST_TAIL, "COLOR_REF",PS_DATA_F32, "reference star color", ref->Color); 129 psMetadataAdd (row, PS_LIST_TAIL, "CHIP_ID", PS_DATA_STRING, "chip identifier", chipName); 130 // XXX need to add the reference color, but this needs getstar / dvo.photcodes for the reference to be refined. 131 131 132 psArrayAdd (table, 100, row);133 psFree (row);134 }135 }136 }137 }138 psFree (view);132 psArrayAdd (table, 100, row); 133 psFree (row); 134 } 135 } 136 } 137 } 138 psFree (view); 139 139 140 if (table->n == 0) {141 psFree(table);142 return true;143 }140 if (table->n == 0) { 141 psFree(table); 142 return true; 143 } 144 144 } 145 145 146 146 if (!psFitsWriteTable(fits, NULL, table, "MATCHED_REFS")) { 147 psError( PS_ERR_IO, false, "writing MATCHED_REFS\n");147 psError(psErrorCodeLast(), false, "writing MATCHED_REFS\n"); 148 148 psFree(table); 149 149 return false; … … 165 165 // It is not an error to lack this entry -- psFitsMoveExtNameClean does not raise an error 166 166 if (!psFitsMoveExtNameClean (fits, "MATCHED_REFS")) { 167 psMetadataAddBool (fpa->analysis, PS_LIST_TAIL, "READ.REFMATCH", PS_META_REPLACE, "attempted to read MATCHED_REFS", true);168 return true;167 psMetadataAddBool (fpa->analysis, PS_LIST_TAIL, "READ.REFMATCH", PS_META_REPLACE, "attempted to read MATCHED_REFS", true); 168 return true; 169 169 } 170 170 171 171 // We get the size of the table, and allocate the array of sources first because the table 172 172 // is large and ephemeral --- when the table gets blown away, whatever is allocated after … … 178 178 for (int i = 0; i < numRows; i++) { 179 179 psMetadata *row = psFitsReadTableRow(fits, i); // Table row 180 rows->data[i] = row; 180 if (!row) { 181 psError(psErrorCodeLast(), false, "Unable to read row %d of matched references.", i); 182 psFree(rows); 183 return false; 184 } 185 rows->data[i] = row; 181 186 } 182 187
Note:
See TracChangeset
for help on using the changeset viewer.
