- Timestamp:
- May 3, 2010, 8:45:22 AM (16 years ago)
- Location:
- branches/simmosaic_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
extsrc/gpcsw/gpcsrc/fits/burntool/persist_fits.c (modified) (51 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simmosaic_branches
- Property svn:mergeinfo changed
-
branches/simmosaic_branches/extsrc/gpcsw/gpcsrc/fits/burntool/persist_fits.c
r23924 r27839 52 52 AREA_TABLE_COL_SXFIT, 53 53 AREA_TABLE_COL_EXFIT, 54 AREA_TABLE_COL_FITERR, 54 55 55 56 /* Add new columns above this line. */ … … 86 87 { "sxfit", "Starting column for fit", "pixels", FH_TABLE_FORMAT_INT, 3, 0 }, 87 88 { "exfit", "Ending column for fit", "pixels", FH_TABLE_FORMAT_INT, 3, 0 }, 89 { "fiterr", "Error code of fit", "", FH_TABLE_FORMAT_INT, 3, 0 }, 88 90 }; 89 91 … … 222 224 for(k=0; k<cell[j].npersist; k++) 223 225 { 224 if(cell[j].persist[k].fiterr) continue; 225 if(cell[j].persist[k].nfit <= 0) continue; 226 /* Retire old burns */ 227 if(cell[j].time - cell[j].persist[k].time > EXPIRE_TRAIL_TIME) 228 continue; 229 230 if(PERSIST_RETAIN) { 231 /* Keep fits which have a dubious slope */ 232 if(cell[j].persist[k].fiterr != FIT_SLOPE_ERROR) { 233 if(cell[j].persist[k].fiterr) continue; 234 if(cell[j].persist[k].nfit <= 0) continue; 235 } 236 } else { 237 if(cell[j].persist[k].fiterr) continue; 238 if(cell[j].persist[k].nfit <= 0) continue; 239 } 226 240 num_areas++; 227 241 num_fits += cell[j].persist[k].nfit; … … 232 246 { 233 247 if(!cell[j].burn[k].burned) continue; 234 if(cell[j].burn[k].fiterr && 235 cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue; 236 if(cell[j].burn[k].nfit <= 0) continue; 248 if(PERSIST_RETAIN) { 249 /* Keep fits which have a dubious slope */ 250 if(cell[j].burn[k].fiterr != FIT_SLOPE_ERROR) { 251 if(cell[j].burn[k].fiterr && 252 cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue; 253 if(cell[j].burn[k].nfit <= 0) continue; 254 } 255 } else { 256 if(cell[j].burn[k].fiterr && 257 cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue; 258 if(cell[j].burn[k].nfit <= 0) continue; 259 } 237 260 num_areas++; 238 261 num_fits += cell[j].burn[k].nfit; … … 289 312 (fh_table_write_value(table, data, row, AREA_TABLE_COL_NFIT, &(area->nfit)) != FH_SUCCESS) || 290 313 (fh_table_write_value(table, data, row, AREA_TABLE_COL_SXFIT, &(area->sxfit)) != FH_SUCCESS) || 291 (fh_table_write_value(table, data, row, AREA_TABLE_COL_EXFIT, &(area->exfit)) != FH_SUCCESS)) 292 { 293 fprintf(stderr, "error: Error writing data to row %d of area table.\n", row); 314 (fh_table_write_value(table, data, row, AREA_TABLE_COL_EXFIT, &(area->exfit)) != FH_SUCCESS) || 315 (fh_table_write_value(table, data, row, AREA_TABLE_COL_FITERR, &(area->fiterr)) != FH_SUCCESS)) 316 { 317 fprintf(stderr, "\rerror: Error writing data to row %d of area table.\n", row); 294 318 return FH_BAD_VALUE; 295 319 } … … 329 353 for(k=0; k<cell[j].npersist; k++) 330 354 { 331 if(cell[j].persist[k].fiterr) continue; 332 if(cell[j].persist[k].nfit <= 0) continue; 355 /* Retire old burns */ 356 if(cell[j].time - cell[j].persist[k].time > EXPIRE_TRAIL_TIME) 357 continue; 358 359 if(PERSIST_RETAIN) { 360 /* Keep fits which have a dubious slope */ 361 if(cell[j].persist[k].fiterr != FIT_SLOPE_ERROR) { 362 if(cell[j].persist[k].fiterr) continue; 363 if(cell[j].persist[k].nfit <= 0) continue; 364 } 365 } else { 366 if(cell[j].persist[k].fiterr) continue; 367 if(cell[j].persist[k].nfit <= 0) continue; 368 } 333 369 334 370 result = write_area_row(hu, data, table, row++, &(cell[j].persist[k])); … … 340 376 { 341 377 if(!cell[j].burn[k].burned) continue; 342 if(cell[j].burn[k].fiterr && 343 cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue; 344 if(cell[j].burn[k].nfit <= 0) continue; 378 if(PERSIST_RETAIN) { 379 /* Keep fits which have a dubious slope */ 380 if(cell[j].burn[k].fiterr != FIT_SLOPE_ERROR) { 381 if(cell[j].burn[k].fiterr && 382 cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue; 383 if(cell[j].burn[k].nfit <= 0) continue; 384 } 385 } else { 386 if(cell[j].burn[k].fiterr && 387 cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue; 388 if(cell[j].burn[k].nfit <= 0) continue; 389 } 345 390 346 391 result = write_area_row(hu, data, table, row++, &(cell[j].burn[k])); … … 388 433 (fh_table_write_value(table, data, row, FIT_TABLE_COL_ZERO, &zero) != FH_SUCCESS)) 389 434 { 390 fprintf(stderr, " error: Error writing data to row %d of fit table.\n", row);435 fprintf(stderr, "\rerror: Error writing data to row %d of fit table.\n", row); 391 436 return FH_BAD_VALUE; 392 437 } … … 426 471 for(k=0; k<cell[j].npersist; k++) 427 472 { 428 if(cell[j].persist[k].fiterr) continue; 473 /* Retire old burns */ 474 if(cell[j].time - cell[j].persist[k].time > EXPIRE_TRAIL_TIME) 475 continue; 476 477 if(PERSIST_RETAIN) { 478 /* Keep fits which have a dubious slope */ 479 if(cell[j].persist[k].fiterr != FIT_SLOPE_ERROR) { 480 if(cell[j].persist[k].fiterr) continue; 481 } 482 } else { 483 if(cell[j].persist[k].fiterr) continue; 484 } 429 485 for(i=0; i<cell[j].persist[k].nfit; i++) 430 486 { … … 441 497 { 442 498 if(!cell[j].burn[k].burned) continue; 443 if(cell[j].burn[k].fiterr && 444 cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue; 499 if(PERSIST_RETAIN) { 500 /* Keep fits which have a dubious slope */ 501 if(cell[j].burn[k].fiterr != FIT_SLOPE_ERROR) { 502 if(cell[j].burn[k].fiterr && 503 cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue; 504 } 505 } else { 506 if(cell[j].burn[k].fiterr && 507 cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue; 508 } 445 509 446 510 for(i=0; i<cell[j].burn[k].nfit; i++) … … 477 541 */ 478 542 static fh_result 479 read_area(fhTable * table, void * data, int row )543 read_area(fhTable * table, void * data, int row, int apply) 480 544 { 481 545 int cell_num; … … 485 549 { 486 550 fprintf(stderr, 487 " error: Unable to get cell number from row %d of burn area table\n",551 "\rerror: Unable to get cell number from row %d of burn area table\n", 488 552 row); 489 553 return FH_BAD_VALUE; … … 493 557 if((cell_num < 0) || (cell_num > MAXCELL)) 494 558 { 495 fprintf(stderr, " error: illegal cell %d in area table row %d\n",559 fprintf(stderr, "\rerror: illegal cell %d in area table row %d\n", 496 560 cell_num, row); 497 561 boxbuf[row].cell = -1; … … 524 588 (fh_table_read_value(table, data, row, AREA_TABLE_COL_NFIT, &(boxbuf[row].nfit)) != FH_SUCCESS) || 525 589 (fh_table_read_value(table, data, row, AREA_TABLE_COL_SXFIT, &(boxbuf[row].sxfit)) != FH_SUCCESS) || 526 (fh_table_read_value(table, data, row, AREA_TABLE_COL_EXFIT, &(boxbuf[row].exfit)) != FH_SUCCESS)) 590 (fh_table_read_value(table, data, row, AREA_TABLE_COL_EXFIT, &(boxbuf[row].exfit)) != FH_SUCCESS) || 591 (fh_table_read_value(table, data, row, AREA_TABLE_COL_FITERR, &(boxbuf[row].fiterr)) != FH_SUCCESS)) 527 592 { 528 593 fprintf(stderr, 529 " error: Error reading values from row %d of burn area table\n",594 "\rerror: Error reading values from row %d of burn area table\n", 530 595 row); 531 596 boxbuf[row].nfit = 0; … … 544 609 boxbuf[row].xfit = (int *)calloc(boxbuf[row].nfit, sizeof(int)); 545 610 boxbuf[row].yfit = (int *)calloc(boxbuf[row].nfit, sizeof(int)); 546 boxbuf[row].fiterr = 0; 611 612 if(boxbuf[row].zero == NULL || 613 boxbuf[row].xfit == NULL || 614 boxbuf[row].yfit == NULL) { 615 fprintf(stderr, "\rerror: failed to alloc boxbuf\n"); 616 exit(-671); 617 } 618 // 100203 JT: fiterr now saved and read, refit if not just an "apply" 619 if(!apply) boxbuf[row].fiterr = 0; 547 620 } 548 621 … … 567 640 */ 568 641 static fh_result 569 read_area_table(HeaderUnit hu, fhTable * table )642 read_area_table(HeaderUnit hu, fhTable * table, int apply) 570 643 { 571 644 fh_result result = FH_INVALID; … … 578 651 (fh_get_int(hu, "TFIELDS", &num_cols) != FH_SUCCESS)) 579 652 { 580 fprintf(stderr, " error: Unable to find required keywords for area table dimensions\n");653 fprintf(stderr, "\rerror: Unable to find required keywords for area table dimensions\n"); 581 654 return FH_NOT_FOUND; 582 655 } … … 585 658 if(num_cols != table->num_cols) 586 659 { 587 fprintf(stderr, " error: %d-column area table found, expected %d cols.\n",660 fprintf(stderr, "\rerror: %d-column area table found, expected %d cols.\n", 588 661 num_cols, table->num_cols); 589 662 return FH_BAD_VALUE; … … 593 666 { 594 667 fprintf(stderr, 595 " error: too many boxes in area table. Max is %d, got %d\n",668 "\rerror: too many boxes in area table. Max is %d, got %d\n", 596 669 MAXBURN, num_rows); 597 670 return FH_BAD_VALUE; … … 605 678 { 606 679 fprintf(stderr, 607 " error: Unable to allocate %d bytes for area table.\n",680 "\rerror: Unable to allocate %d bytes for area table.\n", 608 681 table->table_size); 609 682 return FH_NO_MEMORY; … … 613 686 table->table_size, FH_TYPESIZE_8) != FH_SUCCESS) 614 687 { 615 fprintf(stderr, " error: Unable to map area table body for reading.\n");688 fprintf(stderr, "\rerror: Unable to map area table body for reading.\n"); 616 689 free(data); 617 690 return FH_INVALID; … … 620 693 for(i = 0; i < num_rows; i++) 621 694 { 622 if((result = read_area(table, data, i )) != FH_SUCCESS) break;695 if((result = read_area(table, data, i, apply)) != FH_SUCCESS) break; 623 696 } 624 697 … … 664 737 { 665 738 fprintf(stderr, 666 " error: Unable to get cell number from row %d of fit table\n",739 "\rerror: Unable to get cell number from row %d of fit table\n", 667 740 row); 668 741 return FH_BAD_VALUE; … … 671 744 if((*cell < 0) || (*cell > MAXCELL)) 672 745 { 673 fprintf(stderr, " error: illegal cell %d in fit table row %d\n",746 fprintf(stderr, "\rerror: illegal cell %d in fit table row %d\n", 674 747 *cell, row); 675 748 … … 684 757 { 685 758 fprintf(stderr, 686 " error: Error reading values from row %d of burn area table\n",759 "\rerror: Error reading values from row %d of burn area table\n", 687 760 row); 688 761 return FH_BAD_VALUE; … … 733 806 (fh_get_int(hu, "TFIELDS", &num_cols) != FH_SUCCESS)) 734 807 { 735 fprintf(stderr, " error: Unable to find required keywords for fit table dimensions\n");808 fprintf(stderr, "\rerror: Unable to find required keywords for fit table dimensions\n"); 736 809 return FH_NOT_FOUND; 737 810 } … … 740 813 if(num_cols != table->num_cols) 741 814 { 742 fprintf(stderr, " error: %d-column fit table found, expected %d cols.\n",815 fprintf(stderr, "\rerror: %d-column fit table found, expected %d cols.\n", 743 816 num_cols, table->num_cols); 744 817 return FH_BAD_VALUE; … … 756 829 { 757 830 fprintf(stderr, 758 " error: Unable to allocate %d bytes for area table.\n",831 "\rerror: Unable to allocate %d bytes for area table.\n", 759 832 table->table_size); 760 833 return FH_NO_MEMORY; … … 762 835 if(fh_read_image(hu, fh_file_desc(hu), data, table->table_size, FH_TYPESIZE_8) != FH_SUCCESS) 763 836 { 764 fprintf(stderr, " error: Unable to read fit table body.\n");837 fprintf(stderr, "\rerror: Unable to read fit table body.\n"); 765 838 free(data); 766 839 return FH_INVALID; … … 787 860 { 788 861 fprintf(stderr, 789 " error: Fit in table row %d does not match current area "862 "\rerror: Fit in table row %d does not match current area " 790 863 "(table cell=%d cx=%d cy=%d vs. area cell=%d cx=%d cy=%d)\n", 791 864 fit_table_row, … … 833 906 */ 834 907 fh_result 835 persist_fits_read(CELL *cell, const char * filename )908 persist_fits_read(CELL *cell, const char * filename, int apply) 836 909 { 837 910 HeaderUnit phu; … … 842 915 { 843 916 fprintf(stderr, 844 " error: unable to create header structure for FITS file \"%s\"\n",917 "\rerror: unable to create header structure for FITS file \"%s\"\n", 845 918 filename); 846 919 return FH_NO_MEMORY; … … 850 923 if ((result = fh_file(phu, filename, FH_FILE_RDONLY)) != FH_SUCCESS) 851 924 { 852 fprintf(stderr, 853 "error: unable to open FITS file \"%s\"\n", 925 fprintf(stderr, "\rerror: unable to open FITS file \"%s\"\n", 854 926 filename); 855 927 fh_destroy(phu); … … 862 934 if(!area_hu || !fit_hu) 863 935 { 864 fprintf(stderr, 865 "error: Unable to find persistence info in FITS file.\n"); 936 fprintf(stderr, "\rerror: Unable to find persistence info in FITS file.\n"); 866 937 fh_destroy(phu); 867 938 return FH_NOT_FOUND; … … 872 943 873 944 fh_ehu_by_extname(phu, DEFAULT_EXTNAME_AREA_TABLE); 874 if((result = read_area_table(area_hu, &area_table )) != FH_SUCCESS)945 if((result = read_area_table(area_hu, &area_table, apply)) != FH_SUCCESS) 875 946 { 876 947 free(area_table.strbuf); 877 948 free(fit_table.strbuf); 878 949 fh_destroy(phu); 950 fprintf(stderr, "\rerror: Unable to read area table from FITS file.\n"); 879 951 return result; 880 952 } … … 886 958 free(fit_table.strbuf); 887 959 fh_destroy(phu); 960 fprintf(stderr, "\rerror: Unable to read fit table from FITS file.\n"); 888 961 return result; 889 962 } … … 912 985 for(k=0; k<MAXCELL; k++) { 913 986 if( (i=cell[k].npersist) > 0) { 914 cell[k].persist = (OBJBOX *)calloc(i, sizeof(OBJBOX)); 987 if( (cell[k].persist = (OBJBOX *)calloc(i, sizeof(OBJBOX))) == NULL) { 988 fprintf(stderr, "\rerror: failed to alloc cell persist buffer\n"); 989 exit(-672); 990 } 915 991 cell[k].npersist = 0; 916 992 } … … 969 1045 { 970 1046 fprintf(stderr, 971 " error: Unable to write correction info to FITS file. Correction FITS tables already exist.\n");1047 "\rerror: Unable to write correction info to FITS file. Correction FITS tables already exist.\n"); 972 1048 return FH_NO_SPACE; 973 1049 } … … 976 1052 if ((fd = fh_file_desc(phu)) == -1) 977 1053 { 978 fprintf(stderr, " error: header passed has no associated file.\n");1054 fprintf(stderr, "\rerror: header passed has no associated file.\n"); 979 1055 return FH_INVALID; 980 1056 } … … 984 1060 { 985 1061 fprintf(stderr, 986 " error: Unable to seek to end of file.\n");1062 "\rerror: Unable to seek to end of file.\n"); 987 1063 return FH_IN_ERRNO; 988 1064 } … … 993 1069 { 994 1070 fprintf(stderr, 995 " error: Unable to create headers for correction FITS tables.\n");1071 "\rerror: Unable to create headers for correction FITS tables.\n"); 996 1072 if(area_hu) fh_destroy(area_hu); 997 1073 if(fit_hu) fh_destroy(fit_hu); … … 1017 1093 (fh_munmap_table(area_hu) != FH_SUCCESS)) 1018 1094 { 1019 fprintf(stderr, " error: Error encountered writing area table to FITS file.\n");1095 fprintf(stderr, "\rerror: Error encountered writing area table to FITS file.\n"); 1020 1096 fh_destroy(fit_hu); 1021 1097 free(area_table.strbuf); … … 1038 1114 (fh_munmap_table(fit_hu) != FH_SUCCESS)) 1039 1115 { 1040 fprintf(stderr, " error: Error encountered writing area table to FITS file.\n");1116 fprintf(stderr, "\rerror: Error encountered writing area table to FITS file.\n"); 1041 1117 free(area_table.strbuf); 1042 1118 free(fit_table.strbuf); … … 1100 1176 if(fh_get_int(phu_in, "NEXTEND", &num_extensions) != FH_SUCCESS) 1101 1177 { 1102 fprintf(stderr, " error: Unable to get NEXTEND from input primary FITS header.\n");1178 fprintf(stderr, "\rerror: Unable to get NEXTEND from input primary FITS header.\n"); 1103 1179 return FH_INVALID; 1104 1180 } … … 1108 1184 { 1109 1185 fprintf(stderr, 1110 " error: Unable to find persistence info in FITS file.\n");1186 "\rerror: Unable to find persistence info in FITS file.\n"); 1111 1187 return FH_INVALID; 1112 1188 } … … 1126 1202 if((fd_out = open(fileout, O_CREAT | O_RDWR, 0644)) < 0) 1127 1203 { 1128 fprintf(stderr, " error: Failed to open \"%s\" for output.\n",1204 fprintf(stderr, "\rerror: Failed to open \"%s\" for output.\n", 1129 1205 fileout); 1130 1206 exit(EXIT_FAILURE); … … 1143 1219 (fh_write(phu_out, fd_out) != FH_SUCCESS)) 1144 1220 { 1145 fprintf(stderr, " error: Unable to copy primary header to \"%s\"\n",1221 fprintf(stderr, "\rerror: Unable to copy primary header to \"%s\"\n", 1146 1222 fileout); 1147 1223 fh_destroy(phu_out); … … 1160 1236 if(!(ehu_in = fh_ehu(phu_in, i))) 1161 1237 { 1162 fprintf(stderr, " error: Unable to read extension %d from input FITS file\n", i);1238 fprintf(stderr, "\rerror: Unable to read extension %d from input FITS file\n", i); 1163 1239 fh_destroy(phu_out); 1164 1240 close(fd_out); … … 1168 1244 if (fh_get_str(ehu_in, "EXTNAME", extname, sizeof(extname)) != FH_SUCCESS) 1169 1245 { 1170 fprintf(stderr, " error: Unable to get EXTNAME from extension %d in input FITS file.\n", i);1246 fprintf(stderr, "\rerror: Unable to get EXTNAME from extension %d in input FITS file.\n", i); 1171 1247 fh_destroy(phu_out); 1172 1248 close(fd_out); … … 1184 1260 (fh_reserve(ehu_out, (2880/80)) != FH_SUCCESS)) 1185 1261 { 1186 fprintf(stderr, " error: Unable to copy extension %d to %s.\n", i, fileout);1262 fprintf(stderr, "\rerror: Unable to copy extension %d to %s.\n", i, fileout); 1187 1263 fh_destroy(phu_out); 1188 1264 close(fd_out); … … 1199 1275 (fh_copy_padded_image(ehu_out, fd_out, fh_file_desc(ehu_in)) != FH_SUCCESS)) 1200 1276 { 1201 fprintf(stderr, " error: Unable to copy extension %d to %s.\n", i, fileout);1277 fprintf(stderr, "\rerror: Unable to copy extension %d to %s.\n", i, fileout); 1202 1278 fh_destroy(phu_out); 1203 1279 close(fd_out);
Note:
See TracChangeset
for help on using the changeset viewer.
