IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:45:22 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/simmosaic_branches
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/simmosaic_branches

  • branches/simmosaic_branches/extsrc/gpcsw/gpcsrc/fits/burntool/persist_fits.c

    r23924 r27839  
    5252   AREA_TABLE_COL_SXFIT,
    5353   AREA_TABLE_COL_EXFIT,
     54   AREA_TABLE_COL_FITERR,
    5455   
    5556   /* Add new columns above this line. */
     
    8687   { "sxfit", "Starting column for fit",              "pixels",  FH_TABLE_FORMAT_INT,    3,     0 },
    8788   { "exfit", "Ending column for fit",                "pixels",  FH_TABLE_FORMAT_INT,    3,     0 },
     89   { "fiterr", "Error code of fit",                "",  FH_TABLE_FORMAT_INT,    3,     0 },
    8890};
    8991
     
    222224      for(k=0; k<cell[j].npersist; k++)
    223225      {
    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         }
    226240         num_areas++;
    227241         num_fits += cell[j].persist[k].nfit;
     
    232246      {
    233247         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         }
    237260         num_areas++;
    238261         num_fits += cell[j].burn[k].nfit;
     
    289312      (fh_table_write_value(table, data, row, AREA_TABLE_COL_NFIT,  &(area->nfit))  != FH_SUCCESS) ||
    290313      (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);
    294318      return FH_BAD_VALUE;
    295319   }
     
    329353      for(k=0; k<cell[j].npersist; k++)
    330354      {
    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         }
    333369
    334370         result = write_area_row(hu, data, table, row++, &(cell[j].persist[k]));
     
    340376      {
    341377         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         }
    345390
    346391         result = write_area_row(hu, data, table, row++, &(cell[j].burn[k]));
     
    388433      (fh_table_write_value(table, data, row, FIT_TABLE_COL_ZERO, &zero) != FH_SUCCESS))
    389434   {
    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);
    391436      return FH_BAD_VALUE;
    392437   }
     
    426471      for(k=0; k<cell[j].npersist; k++)
    427472      {
    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         }
    429485         for(i=0; i<cell[j].persist[k].nfit; i++)
    430486         {
     
    441497      {
    442498         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         }
    445509
    446510         for(i=0; i<cell[j].burn[k].nfit; i++)
     
    477541 */
    478542static fh_result
    479 read_area(fhTable * table, void * data, int row)
     543read_area(fhTable * table, void * data, int row, int apply)
    480544{
    481545   int cell_num;
     
    485549   {
    486550      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",
    488552              row);
    489553      return FH_BAD_VALUE;
     
    493557   if((cell_num < 0) || (cell_num > MAXCELL))
    494558   {
    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",
    496560              cell_num, row);
    497561      boxbuf[row].cell = -1;
     
    524588      (fh_table_read_value(table, data, row, AREA_TABLE_COL_NFIT,  &(boxbuf[row].nfit)) != FH_SUCCESS) ||
    525589      (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))
    527592   {
    528593      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",
    530595              row);
    531596      boxbuf[row].nfit = 0;
     
    544609      boxbuf[row].xfit = (int *)calloc(boxbuf[row].nfit, sizeof(int));
    545610      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;
    547620   }
    548621
     
    567640 */
    568641static fh_result
    569 read_area_table(HeaderUnit hu, fhTable * table)
     642read_area_table(HeaderUnit hu, fhTable * table, int apply)
    570643{
    571644   fh_result result = FH_INVALID;
     
    578651      (fh_get_int(hu, "TFIELDS", &num_cols) != FH_SUCCESS))
    579652   {
    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");
    581654      return FH_NOT_FOUND;
    582655   }
     
    585658   if(num_cols != table->num_cols)
    586659   {
    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",
    588661              num_cols, table->num_cols);
    589662      return FH_BAD_VALUE;
     
    593666   {
    594667      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",
    596669              MAXBURN, num_rows);
    597670      return FH_BAD_VALUE;
     
    605678   {
    606679      fprintf(stderr,
    607               "error: Unable to allocate %d bytes for area table.\n",
     680              "\rerror: Unable to allocate %d bytes for area table.\n",
    608681              table->table_size);
    609682      return FH_NO_MEMORY;
     
    613686                    table->table_size, FH_TYPESIZE_8) != FH_SUCCESS)
    614687   {
    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");
    616689      free(data);
    617690      return FH_INVALID;
     
    620693   for(i = 0; i < num_rows; i++)
    621694   {
    622       if((result = read_area(table, data, i)) != FH_SUCCESS) break;
     695      if((result = read_area(table, data, i, apply)) != FH_SUCCESS) break;
    623696   }
    624697
     
    664737   {
    665738      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",
    667740              row);
    668741      return FH_BAD_VALUE;
     
    671744   if((*cell < 0) || (*cell > MAXCELL))
    672745   {
    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",
    674747              *cell, row);
    675748     
     
    684757   {
    685758      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",
    687760              row);
    688761      return FH_BAD_VALUE;
     
    733806      (fh_get_int(hu, "TFIELDS", &num_cols) != FH_SUCCESS))
    734807   {
    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");
    736809      return FH_NOT_FOUND;
    737810   }
     
    740813   if(num_cols != table->num_cols)
    741814   {
    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",
    743816              num_cols, table->num_cols);
    744817      return FH_BAD_VALUE;
     
    756829   {
    757830      fprintf(stderr,
    758               "error: Unable to allocate %d bytes for area table.\n",
     831              "\rerror: Unable to allocate %d bytes for area table.\n",
    759832              table->table_size);
    760833      return FH_NO_MEMORY;
     
    762835   if(fh_read_image(hu, fh_file_desc(hu), data, table->table_size, FH_TYPESIZE_8) != FH_SUCCESS)
    763836   {
    764       fprintf(stderr, "error: Unable to read fit table body.\n");
     837      fprintf(stderr, "\rerror: Unable to read fit table body.\n");
    765838      free(data);
    766839      return FH_INVALID;
     
    787860         {
    788861            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 "
    790863                    "(table cell=%d cx=%d cy=%d vs. area cell=%d cx=%d cy=%d)\n",
    791864                    fit_table_row,
     
    833906 */
    834907fh_result
    835 persist_fits_read(CELL *cell, const char * filename)
     908persist_fits_read(CELL *cell, const char * filename, int apply)
    836909{
    837910   HeaderUnit phu;
     
    842915   {
    843916      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",
    845918              filename);
    846919      return FH_NO_MEMORY;
     
    850923   if ((result = fh_file(phu, filename, FH_FILE_RDONLY)) != FH_SUCCESS)
    851924   {
    852       fprintf(stderr,
    853               "error: unable to open FITS file \"%s\"\n",
     925      fprintf(stderr, "\rerror: unable to open FITS file \"%s\"\n",
    854926              filename);
    855927      fh_destroy(phu);
     
    862934   if(!area_hu || !fit_hu)
    863935   {
    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");
    866937      fh_destroy(phu);
    867938      return FH_NOT_FOUND;
     
    872943
    873944   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)
    875946   {
    876947      free(area_table.strbuf);
    877948      free(fit_table.strbuf);
    878949      fh_destroy(phu);
     950      fprintf(stderr, "\rerror: Unable to read area table from FITS file.\n");
    879951      return result;
    880952   }
     
    886958      free(fit_table.strbuf);
    887959      fh_destroy(phu);
     960      fprintf(stderr, "\rerror: Unable to read fit table from FITS file.\n");
    888961      return result;
    889962   }
     
    912985      for(k=0; k<MAXCELL; k++) {
    913986         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            }
    915991            cell[k].npersist = 0;
    916992         }
     
    9691045   {
    9701046      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");
    9721048      return FH_NO_SPACE;
    9731049   }
     
    9761052   if ((fd = fh_file_desc(phu)) == -1)
    9771053   {
    978       fprintf(stderr, "error: header passed has no associated file.\n");
     1054      fprintf(stderr, "\rerror: header passed has no associated file.\n");
    9791055      return FH_INVALID;
    9801056   }
     
    9841060   {
    9851061      fprintf(stderr,
    986               "error: Unable to seek to end of file.\n");
     1062              "\rerror: Unable to seek to end of file.\n");
    9871063      return FH_IN_ERRNO;
    9881064   }
     
    9931069   {
    9941070      fprintf(stderr,
    995               "error: Unable to create headers for correction FITS tables.\n");
     1071              "\rerror: Unable to create headers for correction FITS tables.\n");
    9961072      if(area_hu) fh_destroy(area_hu);
    9971073      if(fit_hu) fh_destroy(fit_hu);
     
    10171093      (fh_munmap_table(area_hu) != FH_SUCCESS))
    10181094   {
    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");
    10201096      fh_destroy(fit_hu);
    10211097      free(area_table.strbuf);
     
    10381114      (fh_munmap_table(fit_hu) != FH_SUCCESS))
    10391115   {
    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");
    10411117      free(area_table.strbuf);
    10421118      free(fit_table.strbuf);
     
    11001176   if(fh_get_int(phu_in, "NEXTEND", &num_extensions) != FH_SUCCESS)
    11011177   {
    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");
    11031179      return FH_INVALID;
    11041180   }
     
    11081184   {
    11091185      fprintf(stderr,
    1110               "error: Unable to find persistence info in FITS file.\n");
     1186              "\rerror: Unable to find persistence info in FITS file.\n");
    11111187      return FH_INVALID;
    11121188   }
     
    11261202   if((fd_out = open(fileout, O_CREAT | O_RDWR, 0644)) < 0)
    11271203   {
    1128       fprintf(stderr, "error: Failed to open \"%s\" for output.\n",
     1204      fprintf(stderr, "\rerror: Failed to open \"%s\" for output.\n",
    11291205              fileout);
    11301206      exit(EXIT_FAILURE);
     
    11431219      (fh_write(phu_out, fd_out) != FH_SUCCESS))
    11441220   {
    1145       fprintf(stderr, "error: Unable to copy primary header to \"%s\"\n",
     1221      fprintf(stderr, "\rerror: Unable to copy primary header to \"%s\"\n",
    11461222              fileout);
    11471223      fh_destroy(phu_out);
     
    11601236      if(!(ehu_in = fh_ehu(phu_in, i)))
    11611237      {
    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);
    11631239         fh_destroy(phu_out);
    11641240         close(fd_out);
     
    11681244      if (fh_get_str(ehu_in, "EXTNAME", extname, sizeof(extname)) != FH_SUCCESS)
    11691245      {
    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);
    11711247         fh_destroy(phu_out);
    11721248         close(fd_out);
     
    11841260            (fh_reserve(ehu_out, (2880/80)) != FH_SUCCESS))
    11851261         {
    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);
    11871263            fh_destroy(phu_out);
    11881264            close(fd_out);
     
    11991275            (fh_copy_padded_image(ehu_out, fd_out, fh_file_desc(ehu_in)) != FH_SUCCESS))
    12001276         {
    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);
    12021278            fh_destroy(phu_out);
    12031279            close(fd_out);
Note: See TracChangeset for help on using the changeset viewer.