IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 3, 2010, 1:00:09 PM (17 years ago)
Author:
watersc1
Message:

New burntool, with trails retained even if they had a poor slope.

Location:
trunk/extsrc/gpcsw/gpcsrc/fits/burntool
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burnfix.c

    r25070 r26766  
    109109/* Restore all the burns */
    110110   for(k=0; k<cell->npersist; k++) {
    111       if(!cell->persist[k].fiterr)
     111      if(!cell->persist[k].fiterr &&
     112         (cell->persist[k].func == BURN_PWR ||
     113          cell->persist[k].func == BURN_EXP) ) {
    112114         sub_fit(nx, ny, NX, buf, &(cell->persist[k]), -1);
     115      }
    113116   }
    114117   return(0);
    … …  
    124127/* Restore all the burns */
    125128   for(k=0; k<cell->npersist; k++) {
    126       if(!cell->persist[k].fiterr)
     129      if(!cell->persist[k].fiterr &&
     130         (cell->persist[k].func == BURN_PWR ||
     131          cell->persist[k].func == BURN_EXP) ) {
    127132         sub_fit(nx, ny, NX, buf, &(cell->persist[k]), +1);
     133      }
    128134   }
    129135   return(0);
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burntool.c

    r25438 r26766  
    5050      fprintf(stderr, "\rerror: burntool could not open file `%s'\n",
    5151              ifilename);
    52       exit(EXIT_FAILURE);
     52      exit(-314);
    5353   }
    5454   nextend = fh_extensions(ihu);
    … …  
    5757              ifilename);
    5858#ifndef JT2DHACK
    59       exit(EXIT_FAILURE);
     59      exit(-315);
    6060#endif
    6161   }
    … …  
    343343             ifilename);
    344344     if(persist_fits_remove_tables(ihu, deltablefitsfile) != FH_SUCCESS) {
    345        exit(EXIT_FAILURE);
    346      }
    347      else {
     345       exit(-316);
     346     } else {
    348347       exit(EXIT_SUCCESS);
    349348     }
    … …  
    365364/* Read the persistence data for this OTA */
    366365   if(persistfile != NULL) {                    /* Text data file */
    367       if(persist_read(OTA, persistfile)) exit(EXIT_FAILURE);
     366      if(persist_read(OTA, persistfile, apply)) exit(-317);
    368367   } else if(persistfitsfile != NULL) {         /* FITS table */
    369       if(persist_fits_read(OTA, persistfitsfile) != FH_SUCCESS)
    370          exit(EXIT_FAILURE);
     368      if(persist_fits_read(OTA, persistfitsfile, apply) != FH_SUCCESS)
     369         exit(-318);
    371370   }
    372371
    … …  
    427426                 "\rerror: Cannot read EXTNAME from `%s' for extension #%d\n",
    428427                 ifilename, ext);
    429          exit(EXIT_FAILURE);
     428         exit(-319);
    430429      }
    431430      if(fh_get_str(ehu, "XTENSION", xtension, sizeof(xtension)) != FH_SUCCESS) {
    … …  
    433432                 "\rerror: Cannot read XTENSION from `%s' for extension #%d\n",
    434433                 ifilename, ext);
    435          exit(EXIT_FAILURE);     
     434         exit(-320);
    436435      }
    437436      if(!strcmp("TABLE", xtension)) {
    … …  
    461460         fprintf(stderr,
    462461                 "\rerror: Illegal cell number %d from '%s'\n", cell, extname);
    463          exit(EXIT_FAILURE);
     462         exit(-321);
    464463      }
    465464
    … …  
    487486          (naxis >= 3 && fh_get_NAXIS3(ehu, &naxis3) != FH_SUCCESS)) {
    488487         fprintf(stderr, "\rerror: Cannot get NAXIS*'\n");
    489          exit(EXIT_FAILURE);
     488         exit(-322);
    490489      }
    491490      if (naxis != 2) {
    … …  
    503502         }
    504503         fprintf(stderr, "\rerror: 32bpp support not yet implemented in burntool.\n");
    505          exit(EXIT_FAILURE);
     504         exit(-324);
    506505      }
    507506/* Check BSCALE and warn if it is anything other than 1.0.
    … …  
    525524      }
    526525
    527       buf = (IMTYPE*)malloc(naxis1*naxis2*naxis3*sizeof(short));
     526      if( (buf = (IMTYPE*)malloc(naxis1*naxis2*naxis3*sizeof(short))) == NULL) {
     527         fprintf(stderr, "\rerror: failed to alloc FITS buffer\n");
     528         exit(-325);
     529      }
    528530      if (fh_read_padded_image(ehu, fh_file_desc(ehu), buf,
    529531                               naxis1*naxis2*naxis3*sizeof(short),
    … …  
    531533         fprintf(stderr, "\rerror: failed to read image data for extension `%s'.\n",
    532534                 extname);
    533          free(buf);
    534          exit(EXIT_FAILURE);
     535//       free(buf);
     536         exit(-326);
    535537      }
    536538
    … …  
    617619               fprintf(stderr, "\rerror: failed to re-write image data for extension `%s'.\n",
    618620                       extname);
    619                free(buf);
    620                exit(EXIT_FAILURE);
     621//             free(buf);
     622               exit(-327);
    621623            }
    622624         }
    … …  
    667669   if(2*SKY_MARG*ny > nmedian_buf) {
    668670      if(median_buf != NULL) free(median_buf);
    669       median_buf = (int *)calloc(2*SKY_MARG*ny, sizeof(int));
     671      if( (median_buf = (int *)calloc(2*SKY_MARG*ny, sizeof(int))) == NULL) {
     672         fprintf(stderr, "\rerror: failed to alloc median buffer\n");
     673         exit(-667);
     674      }
     675
    670676      nmedian_buf = 2*SKY_MARG*ny;
    671677   }
    … …  
    674680   if(NX*NY > nimbuf) {
    675681      if(imbuf != NULL) free(imbuf);
    676       imbuf = (int *)calloc(NX*NY, sizeof(DTYPE));
     682      if( (imbuf = (int *)calloc(NX*NY, sizeof(DTYPE))) == NULL) {
     683         fprintf(stderr, "\rerror: failed to alloc cell copy\n");
     684         exit(-668);
     685      }
    677686      nimbuf = NX*NY;
    678687   }
    … …  
    681690   if(NX*NY > nmbuf) {
    682691      if(mbuf != NULL) free(mbuf);
    683       mbuf = (int *)calloc(NX*NY, sizeof(MTYPE));
     692      if( (mbuf = (int *)calloc(NX*NY, sizeof(MTYPE))) == NULL) {
     693         fprintf(stderr, "\rerror: failed to alloc mask buffer\n");
     694         exit(-669);
     695      }
    684696      nmbuf = NX*NY;
    685697   }
    … …  
    688700   if(NX*NY > nmsbuf) {
    689701      if(msbuf != NULL) free(msbuf);
    690       msbuf = (int *)calloc(NX*NY, sizeof(MTYPE));
     702      if( (msbuf = (int *)calloc(NX*NY, sizeof(MTYPE))) == NULL) {
     703         fprintf(stderr, "\rerror: failed to alloc veto buffer\n");
     704         exit(-670);
     705      }
    691706      nmsbuf = NX*NY;
    692707   }
    … …  
    755770   printf(" restore={t|f}  Restore the input MEF by adding input fits?\n");
    756771   printf(" apply={t|f}    Modify the input MEF by subtracting previously calculated fits?\n");
    757    printf(" tableonly={t|f} Calculate fits but do *not* modify the input MEF images, only write tables\n");
     772   printf(" tableonly={t|f} Calculate fits but do *not* modify the input MEF pixels, only write tables\n");
    758773   printf(" in=fname       Input file for previous burn persistence streaks\n");
    759774   printf(" infits=fname   Input FITS file for previous burn persistence streaks (stored\n");
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burntool.h

    r25070 r26766  
    9191#define BURN_EXP  2             /* Exponential */
    9292#define BURN_BLASTED 3          /* Blasted top to bottom: flag only for IPP */
     93#define BURN_POSSLOPE 4         /* Positive slope fit (bad) but significant */
    9394#define PSF_STAR  9             /* Unfitted: good psf star */
    9495
    … …  
    175176STATIC int burn_restore(int nx, int ny, int NX, IMTYPE *buf, CELL *cell);
    176177STATIC int burn_apply(int nx, int ny, int NX, IMTYPE *buf, CELL *cell);
    177 STATIC int persist_read(CELL *cell, const char *infile);
     178STATIC int persist_read(CELL *cell, const char *infile, int apply);
    178179STATIC int persist_write(CELL *cell, const char *outfile);
    179180STATIC int persist_fix(int nx, int ny, int stride, IMTYPE *buf, CELL *cell);
    180181STATIC int persist_merge(CELL *cell);
     182
     183//fh_result persist_fits_read(CELL *cell, const char *filename, int apply);
     184//fh_result persist_fits_write(CELL *cell, HeaderUnit phu);
     185//fh_result persist_fits_remove_tables(HeaderUnit phu_in, const char *fileout);
    181186
    182187STATIC int star_detect(int nx, int ny, int NX, int NY, DTYPE *data,
    … …  
    208213STATIC int wlinearfit(int npt, double *x, double *y,
    209214                      double *w, double *a, double *b);
     215STATIC int linearrms(int npt, double *x, double *y, double a, double b, double *rms);
    210216STATIC int int_median(int n, int *key);
    211217STATIC double double_median(int n, double *key);
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burnutils.c

    r25070 r26766  
    290290   return(0);
    291291}
     292
     293/****************************************************************/
     294/* Return of RMS relative to Fit y = ax + b */
     295STATIC int linearrms(int npt, double *x, double *y, double a, double b,
     296                     double *rms)
     297{
     298   *rms = 0.0;
     299   while(--npt >= 0) *rms += (y[npt]-a*x[npt]-b)*(y[npt]-a*x[npt]-b);
     300   if(*rms > 0) *rms = sqrt(*rms);
     301   return(0);
     302}
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/man/burntool.1

    r25324 r26766  
    6060        correction is applied) and they will propagate from input to output
    6161        until they finally achieve a legal fit with negligible amplitude.
     62        Note that if burntool decides that a fit had a bad slope but was
     63        non-negligible it writes a function type "BURN_POSSLOPE" = 4 so
     64        the box is available for masking if desired, and can be refitted
     65        on subsequent images.
    6266
    6367        Burntool also identifies really blasted areas which are saturated from
    … …  
    227231
    228232        tableonly={t|f}
    229                 Calculate fits but do *not* modify the input MEF images,
     233                Calculate fits but do *not* modify the input MEF pixels,
    230234                only write the fit data as a FITS and/or text table (default f)
    231235
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/persist_fits.c

    r25299 r26766  
    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);
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/persist_fits.h

    r23924 r26766  
    2424
    2525fh_result
    26 persist_fits_read(CELL *cell, const char * filename);
     26persist_fits_read(CELL *cell, const char * filename, int apply);
    2727
    2828fh_result
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/persistfix.c

    r23924 r26766  
    3434         }
    3535         continue;
     36      }
     37
     38/* This had a significant positive slope, what do we do now? */
     39      if( (cell->persist)[k].func == BURN_POSSLOPE) {
     40/* try again, so let it slide through... */
    3641      }
    3742
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/persistio.c

    r25299 r26766  
    1616/****************************************************************/
    1717/* persist_read(): Read all the persistence trails from a file */
    18 STATIC int persist_read(CELL *cell, const char *infile)
     18STATIC int persist_read(CELL *cell, const char *infile, int apply)
    1919{
    2020   int i, k, nbox=0;
    … …  
    3838   while(fgets(line, 1024, fp) != NULL) {
    3939      if(line[0] == '#') continue;
    40       sscanf(line, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %lf %d %d %d",
     40      sscanf(line, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %lf %d %d %d %d",
    4141             &boxbuf[nbox].cell, &boxbuf[nbox].time,
    4242             &boxbuf[nbox].cx, &boxbuf[nbox].cy,
    … …  
    5050             &boxbuf[nbox].func, &boxbuf[nbox].up,
    5151             &boxbuf[nbox].slope, &boxbuf[nbox].nfit,
    52              &boxbuf[nbox].sxfit, &boxbuf[nbox].exfit);
     52             &boxbuf[nbox].sxfit, &boxbuf[nbox].exfit,
     53             &boxbuf[nbox].fiterr);
    5354      if(boxbuf[nbox].nfit > 0) {
    5455         boxbuf[nbox].zero = (double *)calloc(boxbuf[nbox].nfit, sizeof(double));
    5556         boxbuf[nbox].xfit = (int *)calloc(boxbuf[nbox].nfit, sizeof(int));
    5657         boxbuf[nbox].yfit = (int *)calloc(boxbuf[nbox].nfit, sizeof(int));
     58         if(boxbuf[nbox].zero == NULL ||
     59            boxbuf[nbox].xfit == NULL ||
     60            boxbuf[nbox].yfit == NULL) {
     61            fprintf(stderr, "\rerror: failed to alloc boxbuf\n");
     62            exit(-673);
     63         }
     64
    5765         for(i=0; i<boxbuf[nbox].nfit; i++) {
    5866            if(fgets(line, 1024, fp) == NULL) {
    … …  
    6472         }
    6573      }
    66       boxbuf[nbox].fiterr = 0;
     74// 100203 JT: fiterr now saved and read, refit if not just an "apply"
     75      if(!apply) boxbuf[nbox].fiterr = 0;
    6776/* Augment counts */
    6877      k = boxbuf[nbox].cell;
    … …  
    8594   for(k=0; k<MAXCELL; k++) {
    8695      if( (i=cell[k].npersist) > 0) {
    87          cell[k].persist = (OBJBOX *)calloc(i, sizeof(OBJBOX));
     96         if( (cell[k].persist = (OBJBOX *)calloc(i, sizeof(OBJBOX))) == NULL) {
     97            fprintf(stderr, "\rerror: failed to alloc cell persist buffer\n");
     98            exit(-674);
     99         }
    88100         cell[k].npersist = 0;
    89101      }
    … …  
    242254      for(k=0; k<cell[j].npersist; k++) {
    243255
     256/* Retire old burns */
     257         if(cell[j].time - cell[j].persist[k].time > EXPIRE_TRAIL_TIME)
     258            continue;
     259
    244260         if(PERSIST_RETAIN) {
    245261/* Keep fits which have a dubious slope */
    … …  
    252268            if(cell[j].persist[k].nfit <= 0) continue;
    253269         }
    254          fprintf(fp, "%3d %7d  %3d %3d %5d %3d  %3d %3d  %3d %3d  %3d %3d %3d %3d %3d %3d %3d %3d  %1d %1d %9.6f %3d %3d %3d\n",
     270         fprintf(fp, "%3d %7d  %3d %3d %5d %3d  %3d %3d  %3d %3d  %3d %3d %3d %3d %3d %3d %3d %3d  %1d %1d %9.6f %3d %3d %3d %d\n",
    255271                 j, cell[j].persist[k].time,
    256272                 cell[j].persist[k].cx, cell[j].persist[k].cy,
    … …  
    264280                 cell[j].persist[k].func, cell[j].persist[k].up,
    265281                 cell[j].persist[k].slope, cell[j].persist[k].nfit,
    266                  cell[j].persist[k].sxfit, cell[j].persist[k].exfit);
     282                 cell[j].persist[k].sxfit, cell[j].persist[k].exfit,
     283                 cell[j].persist[k].fiterr);
    267284         for(i=0; i<cell[j].persist[k].nfit; i++) {
    268285            fprintf(fp, "%3d %3d %8.4f\n", cell[j].persist[k].xfit[i],
    … …  
    288305
    289306         i = (cell[j].burn[k].ex - cell[j].burn[k].sx + 1) / 2;
    290          fprintf(fp, "%3d %7d  %3d %3d %5d %3d  %3d %3d  %3d %3d  %3d %3d %3d %3d %3d %3d %3d %3d  %1d %1d %9.6f %3d %3d %3d\n",
     307         fprintf(fp, "%3d %7d  %3d %3d %5d %3d  %3d %3d  %3d %3d  %3d %3d %3d %3d %3d %3d %3d %3d  %1d %1d %9.6f %3d %3d %3d %d\n",
    291308                 j, cell[j].burn[k].time,
    292309                 cell[j].burn[k].cx, cell[j].burn[k].cy,
    … …  
    300317                 cell[j].burn[k].func, cell[j].burn[k].up,
    301318                 cell[j].burn[k].slope, cell[j].burn[k].nfit,
    302                  cell[j].burn[k].sxfit, cell[j].burn[k].exfit);
     319                 cell[j].burn[k].sxfit, cell[j].burn[k].exfit,
     320                 cell[j].burn[k].fiterr);
    303321         for(i=0; i<cell[j].burn[k].nfit; i++) {
    304322            fprintf(fp, "%3d %3d %8.4f\n", cell[j].burn[k].xfit[i],
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/psfstamp.c

    r25438 r26766  
    112112
    113113/* Make a postage stamp for it */
    114       box[k].stamp = (IMTYPE *)calloc(size*size, sizeof(IMTYPE));
     114      if( (box[k].stamp = (IMTYPE *)calloc(size*size, sizeof(IMTYPE))) == NULL) {
     115         fprintf(stderr, "\rerror: failed to stamp buffer\n");
     116         exit(-675);
     117      }
     118
    115119      sum = 0;
    116120      for(j=y0; j<=y1; j++) {
    … …  
    136140   int i, k, l, nstar, fdout, otacx, otacy, xid, yid, ntot=0, sumax;
    137141   int cellcount, ota_xid, ota_yid;
    138    double scale, phi, fwhm[3], q[5], qt, xfp, yfp, pi=4*atan(1.0);
     142   double scale, phi, fwhm[3], q[7], qt, xfp, yfp, pi=4*atan(1.0);
    139143   IMTYPE *median_image;
    140144   CELL *cell;
    … …  
    171175
    172176/* Create a median image and write as the first one */
    173    median_image = (IMTYPE *)calloc(nx*ny, sizeof(IMTYPE));
     177   if( (median_image = (IMTYPE *)calloc(nx*ny, sizeof(IMTYPE))) == NULL) {
     178      fprintf(stderr, "\rerror: failed to alloc median PSF image\n");
     179      exit(-676);
     180   }
    174181   for(i=0; i<nx*ny; i++) {
    175182      nstar = 0;
    … …  
    256263   int k, l, cellx, celly, ota_xid, ota_yid, nfwave, nqavg;
    257264   double xota, yota, xfp, yfp, phi;
    258    double fwhm[3], q[5], fw[MAXPSFMEDIAN];
     265   double fwhm[3], q[7], fw[MAXPSFMEDIAN];
    259266   double m2[MAXPSFMEDIAN], qp[MAXPSFMEDIAN], qc[MAXPSFMEDIAN];
    260267   double qt[MAXPSFMEDIAN], fwavg[MAXPSFMEDIAN];
     268   double qpavg[MAXPSFMEDIAN], qcavg[MAXPSFMEDIAN], qtavg[MAXPSFMEDIAN];
    261269   double q3c[MAXPSFMEDIAN], q3s[MAXPSFMEDIAN];
    262    double qpavg[MAXPSFMEDIAN], qcavg[MAXPSFMEDIAN], qtavg[MAXPSFMEDIAN];
    263270   double q3cavg[MAXPSFMEDIAN], q3savg[MAXPSFMEDIAN];
     271   double q1c[MAXPSFMEDIAN], q1s[MAXPSFMEDIAN];
     272   double q1cavg[MAXPSFMEDIAN], q1savg[MAXPSFMEDIAN];
    264273   int nstar[MAXCELL], nfw[MAXCELL];
    265274   double fwmed[MAXCELL], m2med[MAXCELL];
    266275   double qpmed[MAXCELL], qcmed[MAXCELL], qtmed[MAXCELL];
    267276   double q3cmed[MAXCELL], q3smed[MAXCELL];
    268    double qpmacro, qcmacro, qtmacro, fwmacro, q3cmacro, q3smacro;
     277   double q1cmed[MAXCELL], q1smed[MAXCELL];
     278   double qpmacro, qcmacro, qtmacro, fwmacro, q3cmacro, q3smacro, q1cmacro, q1smacro;
    269279   FILE *fp;
    270280   CELL *cell;
    … …  
    310320                     q3c[nstar[k]] = q[3];
    311321                     q3s[nstar[k]] = q[4];
     322                     q1c[nstar[k]] = q[5];
     323                     q1s[nstar[k]] = q[6];
    312324/* Get the position in the focal plane and therefore the qt statistic */
    313325                     psc_cell_to_pixel(cellx, celly, 0.5*PSC_HCELL/PSC_PIXEL,
    … …  
    333345                  q3cmed[k] = double_median(nstar[k], q3c);
    334346                  q3smed[k] = double_median(nstar[k], q3s);
     347                  q1cmed[k] = double_median(nstar[k], q1c);
     348                  q1smed[k] = double_median(nstar[k], q1s);
    335349               } else {
    336350                  m2med[k] = qpmed[k] = qcmed[k] = qtmed[k] = -99.99;
    337351                  q3cmed[k] = q3smed[k] = -99.99;
     352                  q1cmed[k] = q1smed[k] = -99.99;
    338353               }
    339354/* Toss these results into the macrocell median hopper */
    … …  
    348363                     q3cavg[nqavg] = q3c[l];
    349364                     q3savg[nqavg] = q3s[l];
     365                     q1cavg[nqavg] = q1c[l];
     366                     q1savg[nqavg] = q1s[l];
    350367                     nqavg++;
    351368                  }
    … …  
    359376         q3cmacro = double_median(nqavg, q3cavg);
    360377         q3smacro = double_median(nqavg, q3savg);
    361          if(nqavg == 0) qpmacro = qcmacro = qtmacro = q3cmacro = q3smacro = -99.99;
     378         q1cmacro = double_median(nqavg, q1cavg);
     379         q1smacro = double_median(nqavg, q1savg);
     380         if(nqavg == 0) qpmacro = qcmacro = qtmacro = q3cmacro = q3smacro = q1cmacro = q1smacro = -99.99;
    362381         fwmacro = double_median(nfwave, fwavg);
    363382
    … …  
    370389               cell = ota + k;
    371390
    372                fprintf(fp, "ext=xy%1d%1d bias=%d sky=%d rmssky=%d npsf=%d fwhm=%.2f fwmed=%.2f m2=%.2f qp=%.3f qc=%.3f qt=%.3f q3c=%.3f q3s=%.3f qpm=%.3f qcm=%.3f qtm=%.3f q3cm=%.3f q3sm=%.3f\n",
     391               fprintf(fp, "ext=xy%1d%1d bias=%d sky=%d rmssky=%d npsf=%d fwhm=%.2f fwmed=%.2f m2=%.2f qp=%.3f qc=%.3f qt=%.3f q3c=%.3f q3s=%.3f q1c=%.3f q1s=%.3f qpm=%.3f qcm=%.3f qtm=%.3f q3cm=%.3f q3sm=%.3f q1cm=%.3f q1sm=%.3f\n",
    373392                       cellx, celly, cell->bias, cell->sky, cell->rms,
    374393                       nstar[k], fwmed[k], fwmacro, m2med[k],
    375                        qpmed[k], qcmed[k], qtmed[k], q3cmed[k], q3smed[k],
    376                        qpmacro, qcmacro, qtmacro, q3cmacro, q3smacro);
     394                       qpmed[k], qcmed[k], qtmed[k], q3cmed[k], q3smed[k],
     395                       q1cmed[k], q1smed[k],
     396                       qpmacro, qcmacro, qtmacro, q3cmacro, q3smacro,
     397                       q1cmacro, q1smacro);
    377398            }
    378399         }
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/stardetect.c

    r25070 r26766  
    193193   cell->burn = (OBJBOX *)calloc(cell->nburn, sizeof(OBJBOX));
    194194   cell->star = (OBJBOX *)calloc(cell->nstar, sizeof(OBJBOX));
     195   if( cell->burn == NULL || cell->star == NULL) {
     196      fprintf(stderr, "\rerror: failed to alloc burn box\n");
     197      exit(-678);
     198   }
    195199
    196200/* Copy the boxes to the cell info structure */
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/trailfit.c

    r25299 r26766  
    3030
    3131   if(box->func != BURN_PWR && box->func != BURN_EXP) {
    32       fprintf(stderr, "error: unimplemented fit function %d\n", box->func);
     32      fprintf(stderr, "error: unimplemented fit function %d (err %d)\n",
     33              box->func, box->fiterr);
    3334      return(-1);
    3435   }
    … …  
    137138   box->xfit = (int *)calloc(xe-xs+1, sizeof(int));
    138139   box->yfit = (int *)calloc(xe-xs+1, sizeof(int));
     140   if(box->zero == NULL || box->xfit == NULL || box->yfit == NULL) {
     141      fprintf(stderr, "\rerror: failed to alloc box memory\n");
     142      exit(-679);
     143   }
    139144/* Some defaults */
    140145   box->slope = 0.0;
    … …  
    229234      box->nfit = 0;
    230235      box->fiterr = FIT_SLOPE_ERROR;
     236/* Check whether it's a significant trail (but with pos slope) or just noise */
     237      linearrms(nfit, ybuf+y1, zbuf+y1, slope, zero, &trial);
     238/* 100203 JT: bad idea: appears to be a bug in read/writing ABS(nfit) */
     239//      if(trial > 2*rms) box->nfit = -box->nfit;
     240      if(trial > 2*rms) box->func = BURN_POSSLOPE;
    231241      return(-1);
    232242   }
    … …  
    268278/* FIXME: what's a really good criterion for negligible fit? */
    269279/* 100 pixels up fit is zsum or ~zsum/e */
    270       if(zsum > NEGLIGIBLE_TRAIL*rms) {
     280//      if(zsum > NEGLIGIBLE_TRAIL*rms) {
     281      if(zsum > NEGLIGIBLE_TRAIL*rms ||
     282/* 100113: but also evaluate at the end of the fit for stubby trails */
     283         zbuf[y2]*zsum > NEGLIGIBLE_TRAIL*rms) {
    271284
    272285/* Ascertain the starting point of where the fit is good */
Note: See TracChangeset for help on using the changeset viewer.