IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

updates from trunk

Location:
branches/tap_branches
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/tap_branches

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

    r25299 r27838  
    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      {
     226/* Retire old burns */
     227         if(cell[j].time - cell[j].persist[k].time > EXPIRE_TRAIL_TIME)
     228            continue;
     229
    224230         if(PERSIST_RETAIN) {
    225231/* Keep fits which have a dubious slope */
     
    306312      (fh_table_write_value(table, data, row, AREA_TABLE_COL_NFIT,  &(area->nfit))  != FH_SUCCESS) ||
    307313      (fh_table_write_value(table, data, row, AREA_TABLE_COL_SXFIT, &(area->sxfit)) != FH_SUCCESS) ||
    308       (fh_table_write_value(table, data, row, AREA_TABLE_COL_EXFIT, &(area->exfit)) != FH_SUCCESS))
    309    {
    310       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);
    311318      return FH_BAD_VALUE;
    312319   }
     
    346353      for(k=0; k<cell[j].npersist; k++)
    347354      {
     355/* Retire old burns */
     356         if(cell[j].time - cell[j].persist[k].time > EXPIRE_TRAIL_TIME)
     357            continue;
     358
    348359         if(PERSIST_RETAIN) {
    349360/* Keep fits which have a dubious slope */
     
    422433      (fh_table_write_value(table, data, row, FIT_TABLE_COL_ZERO, &zero) != FH_SUCCESS))
    423434   {
    424       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);
    425436      return FH_BAD_VALUE;
    426437   }
     
    460471      for(k=0; k<cell[j].npersist; k++)
    461472      {
     473/* Retire old burns */
     474         if(cell[j].time - cell[j].persist[k].time > EXPIRE_TRAIL_TIME)
     475            continue;
     476
    462477         if(PERSIST_RETAIN) {
    463478/* Keep fits which have a dubious slope */
     
    526541 */
    527542static fh_result
    528 read_area(fhTable * table, void * data, int row)
     543read_area(fhTable * table, void * data, int row, int apply)
    529544{
    530545   int cell_num;
     
    534549   {
    535550      fprintf(stderr,
    536               "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",
    537552              row);
    538553      return FH_BAD_VALUE;
     
    542557   if((cell_num < 0) || (cell_num > MAXCELL))
    543558   {
    544       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",
    545560              cell_num, row);
    546561      boxbuf[row].cell = -1;
     
    573588      (fh_table_read_value(table, data, row, AREA_TABLE_COL_NFIT,  &(boxbuf[row].nfit)) != FH_SUCCESS) ||
    574589      (fh_table_read_value(table, data, row, AREA_TABLE_COL_SXFIT, &(boxbuf[row].sxfit)) != FH_SUCCESS) ||
    575       (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))
    576592   {
    577593      fprintf(stderr,
    578               "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",
    579595              row);
    580596      boxbuf[row].nfit = 0;
     
    593609      boxbuf[row].xfit = (int *)calloc(boxbuf[row].nfit, sizeof(int));
    594610      boxbuf[row].yfit = (int *)calloc(boxbuf[row].nfit, sizeof(int));
    595       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;
    596620   }
    597621
     
    616640 */
    617641static fh_result
    618 read_area_table(HeaderUnit hu, fhTable * table)
     642read_area_table(HeaderUnit hu, fhTable * table, int apply)
    619643{
    620644   fh_result result = FH_INVALID;
     
    627651      (fh_get_int(hu, "TFIELDS", &num_cols) != FH_SUCCESS))
    628652   {
    629       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");
    630654      return FH_NOT_FOUND;
    631655   }
     
    634658   if(num_cols != table->num_cols)
    635659   {
    636       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",
    637661              num_cols, table->num_cols);
    638662      return FH_BAD_VALUE;
     
    642666   {
    643667      fprintf(stderr,
    644               "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",
    645669              MAXBURN, num_rows);
    646670      return FH_BAD_VALUE;
     
    654678   {
    655679      fprintf(stderr,
    656               "error: Unable to allocate %d bytes for area table.\n",
     680              "\rerror: Unable to allocate %d bytes for area table.\n",
    657681              table->table_size);
    658682      return FH_NO_MEMORY;
     
    662686                    table->table_size, FH_TYPESIZE_8) != FH_SUCCESS)
    663687   {
    664       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");
    665689      free(data);
    666690      return FH_INVALID;
     
    669693   for(i = 0; i < num_rows; i++)
    670694   {
    671       if((result = read_area(table, data, i)) != FH_SUCCESS) break;
     695      if((result = read_area(table, data, i, apply)) != FH_SUCCESS) break;
    672696   }
    673697
     
    713737   {
    714738      fprintf(stderr,
    715               "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",
    716740              row);
    717741      return FH_BAD_VALUE;
     
    720744   if((*cell < 0) || (*cell > MAXCELL))
    721745   {
    722       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",
    723747              *cell, row);
    724748     
     
    733757   {
    734758      fprintf(stderr,
    735               "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",
    736760              row);
    737761      return FH_BAD_VALUE;
     
    782806      (fh_get_int(hu, "TFIELDS", &num_cols) != FH_SUCCESS))
    783807   {
    784       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");
    785809      return FH_NOT_FOUND;
    786810   }
     
    789813   if(num_cols != table->num_cols)
    790814   {
    791       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",
    792816              num_cols, table->num_cols);
    793817      return FH_BAD_VALUE;
     
    805829   {
    806830      fprintf(stderr,
    807               "error: Unable to allocate %d bytes for area table.\n",
     831              "\rerror: Unable to allocate %d bytes for area table.\n",
    808832              table->table_size);
    809833      return FH_NO_MEMORY;
     
    811835   if(fh_read_image(hu, fh_file_desc(hu), data, table->table_size, FH_TYPESIZE_8) != FH_SUCCESS)
    812836   {
    813       fprintf(stderr, "error: Unable to read fit table body.\n");
     837      fprintf(stderr, "\rerror: Unable to read fit table body.\n");
    814838      free(data);
    815839      return FH_INVALID;
     
    836860         {
    837861            fprintf(stderr,
    838                     "error: Fit in table row %d does not match current area "
     862                    "\rerror: Fit in table row %d does not match current area "
    839863                    "(table cell=%d cx=%d cy=%d vs. area cell=%d cx=%d cy=%d)\n",
    840864                    fit_table_row,
     
    882906 */
    883907fh_result
    884 persist_fits_read(CELL *cell, const char * filename)
     908persist_fits_read(CELL *cell, const char * filename, int apply)
    885909{
    886910   HeaderUnit phu;
     
    891915   {
    892916      fprintf(stderr,
    893               "error: unable to create header structure for FITS file \"%s\"\n",
     917              "\rerror: unable to create header structure for FITS file \"%s\"\n",
    894918              filename);
    895919      return FH_NO_MEMORY;
     
    899923   if ((result = fh_file(phu, filename, FH_FILE_RDONLY)) != FH_SUCCESS)
    900924   {
    901       fprintf(stderr,
    902               "error: unable to open FITS file \"%s\"\n",
     925      fprintf(stderr, "\rerror: unable to open FITS file \"%s\"\n",
    903926              filename);
    904927      fh_destroy(phu);
     
    911934   if(!area_hu || !fit_hu)
    912935   {
    913       fprintf(stderr,
    914               "error: Unable to find persistence info in FITS file.\n");
     936      fprintf(stderr, "\rerror: Unable to find persistence info in FITS file.\n");
    915937      fh_destroy(phu);
    916938      return FH_NOT_FOUND;
     
    921943
    922944   fh_ehu_by_extname(phu, DEFAULT_EXTNAME_AREA_TABLE);
    923    if((result = read_area_table(area_hu, &area_table)) != FH_SUCCESS)
     945   if((result = read_area_table(area_hu, &area_table, apply)) != FH_SUCCESS)
    924946   {
    925947      free(area_table.strbuf);
    926948      free(fit_table.strbuf);
    927949      fh_destroy(phu);
     950      fprintf(stderr, "\rerror: Unable to read area table from FITS file.\n");
    928951      return result;
    929952   }
     
    935958      free(fit_table.strbuf);
    936959      fh_destroy(phu);
     960      fprintf(stderr, "\rerror: Unable to read fit table from FITS file.\n");
    937961      return result;
    938962   }
     
    961985      for(k=0; k<MAXCELL; k++) {
    962986         if( (i=cell[k].npersist) > 0) {
    963             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            }
    964991            cell[k].npersist = 0;
    965992         }
     
    10181045   {
    10191046      fprintf(stderr,
    1020               "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");
    10211048      return FH_NO_SPACE;
    10221049   }
     
    10251052   if ((fd = fh_file_desc(phu)) == -1)
    10261053   {
    1027       fprintf(stderr, "error: header passed has no associated file.\n");
     1054      fprintf(stderr, "\rerror: header passed has no associated file.\n");
    10281055      return FH_INVALID;
    10291056   }
     
    10331060   {
    10341061      fprintf(stderr,
    1035               "error: Unable to seek to end of file.\n");
     1062              "\rerror: Unable to seek to end of file.\n");
    10361063      return FH_IN_ERRNO;
    10371064   }
     
    10421069   {
    10431070      fprintf(stderr,
    1044               "error: Unable to create headers for correction FITS tables.\n");
     1071              "\rerror: Unable to create headers for correction FITS tables.\n");
    10451072      if(area_hu) fh_destroy(area_hu);
    10461073      if(fit_hu) fh_destroy(fit_hu);
     
    10661093      (fh_munmap_table(area_hu) != FH_SUCCESS))
    10671094   {
    1068       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");
    10691096      fh_destroy(fit_hu);
    10701097      free(area_table.strbuf);
     
    10871114      (fh_munmap_table(fit_hu) != FH_SUCCESS))
    10881115   {
    1089       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");
    10901117      free(area_table.strbuf);
    10911118      free(fit_table.strbuf);
     
    11491176   if(fh_get_int(phu_in, "NEXTEND", &num_extensions) != FH_SUCCESS)
    11501177   {
    1151       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");
    11521179      return FH_INVALID;
    11531180   }
     
    11571184   {
    11581185      fprintf(stderr,
    1159               "error: Unable to find persistence info in FITS file.\n");
     1186              "\rerror: Unable to find persistence info in FITS file.\n");
    11601187      return FH_INVALID;
    11611188   }
     
    11751202   if((fd_out = open(fileout, O_CREAT | O_RDWR, 0644)) < 0)
    11761203   {
    1177       fprintf(stderr, "error: Failed to open \"%s\" for output.\n",
     1204      fprintf(stderr, "\rerror: Failed to open \"%s\" for output.\n",
    11781205              fileout);
    11791206      exit(EXIT_FAILURE);
     
    11921219      (fh_write(phu_out, fd_out) != FH_SUCCESS))
    11931220   {
    1194       fprintf(stderr, "error: Unable to copy primary header to \"%s\"\n",
     1221      fprintf(stderr, "\rerror: Unable to copy primary header to \"%s\"\n",
    11951222              fileout);
    11961223      fh_destroy(phu_out);
     
    12091236      if(!(ehu_in = fh_ehu(phu_in, i)))
    12101237      {
    1211          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);
    12121239         fh_destroy(phu_out);
    12131240         close(fd_out);
     
    12171244      if (fh_get_str(ehu_in, "EXTNAME", extname, sizeof(extname)) != FH_SUCCESS)
    12181245      {
    1219          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);
    12201247         fh_destroy(phu_out);
    12211248         close(fd_out);
     
    12331260            (fh_reserve(ehu_out, (2880/80)) != FH_SUCCESS))
    12341261         {
    1235             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);
    12361263            fh_destroy(phu_out);
    12371264            close(fd_out);
     
    12481275            (fh_copy_padded_image(ehu_out, fd_out, fh_file_desc(ehu_in)) != FH_SUCCESS))
    12491276         {
    1250             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);
    12511278            fh_destroy(phu_out);
    12521279            close(fd_out);
Note: See TracChangeset for help on using the changeset viewer.