IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25299


Ignore:
Timestamp:
Sep 8, 2009, 5:32:55 PM (17 years ago)
Author:
watersc1
Message:

Merge my branch back into the trunk. This includes:

ipp_cleanup.pl : and associated edits to allow cleanup to work
burntool : updated to newest version, ipp_apply_burntool.pl modified to use persist=t options
ppImageBurntoolMask.c : masks region burntool identifies
psastro : allow selection of wcs header format
addtool : splits addstar step off from the camera stage

Location:
trunk
Files:
47 edited
14 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/DataStore/scripts/dsget

    r25280 r25299  
    6969        undef $copies;
    7070    }
    71     if ($copies < 1) {
     71    elsif ($copies < 1) {
    7272        die "--copies must be >= 1";
    7373    }
  • trunk/dbconfig/changes.txt

    r25256 r25299  
    12111211ALTER TABLE publishDone ADD COLUMN hostname VARCHAR(64) AFTER path_base;
    12121212ALTER TABLE publishDone ADD COLUMN dtime_script FLOAT AFTER hostname;
     1213
     1214-- Version 1.1.55
     1215-- addstar stage tables:
     1216
     1217CREATE TABLE addRun (
     1218    add_id BIGINT AUTO_INCREMENT,
     1219    cam_id BIGINT,
     1220    state VARCHAR(64),
     1221    workdir VARCHAR(255),
     1222    workdir_state VARCHAR(64),
     1223    label VARCHAR(64),
     1224    dvodb VARCHAR(255),
     1225    magicked BIGINT,
     1226    PRIMARY KEY(add_id),
     1227    KEY(add_id),
     1228    KEY(cam_id),
     1229    KEY(state),
     1230    KEY(workdir_state),
     1231    KEY(label),
     1232    INDEX(add_id, cam_id),
     1233    FOREIGN KEY(cam_id) REFERENCES camRun(cam_id)
     1234) ENGINE=innodb DEFAULT CHARSET=latin1;
     1235
     1236CREATE TABLE addProcessedExp (
     1237    add_id BIGINT AUTO_INCREMENT,
     1238    dtime_addstar FLOAT,
     1239    n_stars INT,
     1240    path_base VARCHAR(255),
     1241    fault SMALLINT NOT NULL,
     1242    PRIMARY KEY(add_id),
     1243    FOREIGN KEY(add_id) REFERENCES addRun(add_id)
     1244) ENGINE=innodb DEFAULT CHARSET=latin1;
     1245
     1246CREATE TABLE addMask (
     1247    label VARCHAR(64),
     1248    PRIMARY KEY(label)
     1249) ENGINE=innodb DEFAULT CHARSET=latin1;
  • trunk/dbconfig/ipp.m4

    r24512 r25299  
    1414include(chip.md)
    1515include(cam.md)
     16include(add.md)
    1617include(fake.md)
    1718include(warp.md)
  • trunk/doc/misc/docgen.pl

  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burnparams.h

    r23924 r25299  
    5555EXTERN int EXPIRE_TRAIL_TIME;   /* Expire trails after this interval */
    5656
     57EXTERN int PERSIST_RETAIN;      /* Retain bad-slope persistence fits */
     58
    5759#endif /* _INCLUDED_burnparams_ */
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burntool.c

    r24391 r25299  
    100100   EXPIRE_TRAIL_TIME = 2000;    /* Expire a persist after this [sec] */
    101101
     102   PERSIST_RETAIN = 0;          /* Retain persists with bad slopes? */
     103
    102104/* Parse the args */
    103105   cellxy = -1;
     
    174176      } else if(strncmp(argv[i], "infits=", 7) == 0) { /* infits=fname */
    175177         persistfitsfile = argv[i] + 7;
     178
     179/* Keep persistence streaks which had a bad slope? */
     180      } else if(strncmp(argv[i], "persist=", 8) == 0) {/* persist={t|f} */
     181         PERSIST_RETAIN = argv[i][8] == 'y' || argv[i][8] == '1' || argv[i][8] == 't';
    176182
    177183/* Output file for PSF gallery */
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/man/burntool.1

    r24391 r25299  
    5353        power laws; downward burns as exponentials.
    5454       
     55        The fit to downward, persistence burns may have an unreasonable "slope"
     56        (meaning exponential sign), increasing away from the burn origin.
     57        These are discarded unless "persist=t" is invoked.  It is possible
     58        for the fit to be fooled by uncataloged stars, so the persistence
     59        can be kept in the output file with "persist=t" (although no fit
     60        correction is applied) and they will propagate from input to output
     61        until they finally achieve a legal fit with negligible amplitude.
     62
    5563        Burntool also identifies really blasted areas which are saturated from
    5664        top to bottom.  These cannot be fitted, but are carried along for
     
    231239                'in' takes precedence.
    232240
     241        persist={t|f}
     242                Retain persistence streaks whose fit slope turned out to be
     243                unreasonable.
     244
    233245        out=fname     
    234246                Output file for burn streaks
     
    332344BUGS:
    333345        090224: Still in development
     346        090810: Squished a few memory bugs
    334347
    335348SEE ALSO:
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/persist_fits.c

    r23924 r25299  
    222222      for(k=0; k<cell[j].npersist; k++)
    223223      {
    224          if(cell[j].persist[k].fiterr) continue;
    225          if(cell[j].persist[k].nfit <= 0) continue;
     224         if(PERSIST_RETAIN) {
     225/* Keep fits which have a dubious slope */
     226            if(cell[j].persist[k].fiterr != FIT_SLOPE_ERROR) {
     227               if(cell[j].persist[k].fiterr) continue;
     228               if(cell[j].persist[k].nfit <= 0) continue;
     229            }
     230         } else {
     231            if(cell[j].persist[k].fiterr) continue;
     232            if(cell[j].persist[k].nfit <= 0) continue;
     233         }
    226234         num_areas++;
    227235         num_fits += cell[j].persist[k].nfit;
     
    232240      {
    233241         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;
     242         if(PERSIST_RETAIN) {
     243/* Keep fits which have a dubious slope */
     244            if(cell[j].burn[k].fiterr != FIT_SLOPE_ERROR) {
     245               if(cell[j].burn[k].fiterr &&
     246                  cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
     247               if(cell[j].burn[k].nfit <= 0) continue;
     248            }
     249         } else {
     250            if(cell[j].burn[k].fiterr &&
     251               cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
     252            if(cell[j].burn[k].nfit <= 0) continue;
     253         }
    237254         num_areas++;
    238255         num_fits += cell[j].burn[k].nfit;
     
    329346      for(k=0; k<cell[j].npersist; k++)
    330347      {
    331          if(cell[j].persist[k].fiterr) continue;
    332          if(cell[j].persist[k].nfit <= 0) continue;     
     348         if(PERSIST_RETAIN) {
     349/* Keep fits which have a dubious slope */
     350            if(cell[j].persist[k].fiterr != FIT_SLOPE_ERROR) {
     351               if(cell[j].persist[k].fiterr) continue;
     352               if(cell[j].persist[k].nfit <= 0) continue;     
     353            }
     354         } else {
     355            if(cell[j].persist[k].fiterr) continue;
     356            if(cell[j].persist[k].nfit <= 0) continue;     
     357         }
    333358
    334359         result = write_area_row(hu, data, table, row++, &(cell[j].persist[k]));
     
    340365      {
    341366         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;
     367         if(PERSIST_RETAIN) {
     368/* Keep fits which have a dubious slope */
     369            if(cell[j].burn[k].fiterr != FIT_SLOPE_ERROR) {
     370               if(cell[j].burn[k].fiterr &&
     371                  cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
     372               if(cell[j].burn[k].nfit <= 0) continue;
     373            }
     374         } else {
     375            if(cell[j].burn[k].fiterr &&
     376               cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
     377            if(cell[j].burn[k].nfit <= 0) continue;
     378         }
    345379
    346380         result = write_area_row(hu, data, table, row++, &(cell[j].burn[k]));
     
    426460      for(k=0; k<cell[j].npersist; k++)
    427461      {
    428          if(cell[j].persist[k].fiterr) continue;
     462         if(PERSIST_RETAIN) {
     463/* Keep fits which have a dubious slope */
     464            if(cell[j].persist[k].fiterr != FIT_SLOPE_ERROR) {
     465               if(cell[j].persist[k].fiterr) continue;
     466            }
     467         } else {
     468            if(cell[j].persist[k].fiterr) continue;
     469         }
    429470         for(i=0; i<cell[j].persist[k].nfit; i++)
    430471         {
     
    441482      {
    442483         if(!cell[j].burn[k].burned) continue;
    443          if(cell[j].burn[k].fiterr &&
    444             cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
     484         if(PERSIST_RETAIN) {
     485/* Keep fits which have a dubious slope */
     486            if(cell[j].burn[k].fiterr != FIT_SLOPE_ERROR) {
     487               if(cell[j].burn[k].fiterr &&
     488                  cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
     489            }
     490         } else {
     491            if(cell[j].burn[k].fiterr &&
     492               cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
     493         }
    445494
    446495         for(i=0; i<cell[j].burn[k].nfit; i++)
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/persistio.c

    r23924 r25299  
    5151             &boxbuf[nbox].slope, &boxbuf[nbox].nfit,
    5252             &boxbuf[nbox].sxfit, &boxbuf[nbox].exfit);
    53       if(boxbuf[nbox].nfit <= 0) continue;
    54       boxbuf[nbox].zero = (double *)calloc(boxbuf[nbox].nfit, sizeof(double));
    55       boxbuf[nbox].xfit = (int *)calloc(boxbuf[nbox].nfit, sizeof(int));
    56       boxbuf[nbox].yfit = (int *)calloc(boxbuf[nbox].nfit, sizeof(int));
    57       for(i=0; i<boxbuf[nbox].nfit; i++) {
    58          if(fgets(line, 1024, fp) == NULL) {
    59             fprintf(stderr, "\rerror: short read of burn lines\n");
    60             return(-1);
    61          }
    62          sscanf(line, "%d %d %lf\n", &boxbuf[nbox].xfit[i],
    63                 &boxbuf[nbox].yfit[i], &boxbuf[nbox].zero[i]);
     53      if(boxbuf[nbox].nfit > 0) {
     54         boxbuf[nbox].zero = (double *)calloc(boxbuf[nbox].nfit, sizeof(double));
     55         boxbuf[nbox].xfit = (int *)calloc(boxbuf[nbox].nfit, sizeof(int));
     56         boxbuf[nbox].yfit = (int *)calloc(boxbuf[nbox].nfit, sizeof(int));
     57         for(i=0; i<boxbuf[nbox].nfit; i++) {
     58            if(fgets(line, 1024, fp) == NULL) {
     59               fprintf(stderr, "\rerror: short read of burn lines\n");
     60               return(-1);
     61            }
     62            sscanf(line, "%d %d %lf\n", &boxbuf[nbox].xfit[i],
     63                   &boxbuf[nbox].yfit[i], &boxbuf[nbox].zero[i]);
     64         }
    6465      }
    6566      boxbuf[nbox].fiterr = 0;
     
    147148      for(kp=0; kp<n; kp++) {
    148149         k = boxid[kp];
    149          zk = box[k].zero[box[k].nfit/2];
     150         zk = 0.0;
     151         if(box[k].nfit > 0) zk = box[k].zero[box[k].nfit/2];
    150152         for(jp=kp+1; jp<n; jp++) {
    151153            j = boxid[jp];
    152             zj = box[j].zero[box[j].nfit/2];
     154            zj = 0.0;
     155            if(box[j].nfit > 0) zj = box[j].zero[box[j].nfit/2];
    153156            if(ABS(yctr[jp]-yctr[kp]) > DIFFERENT_STREAK) {
    154157/* Trim back the feebler streak */
     
    238241/* First: patched up persists */
    239242      for(k=0; k<cell[j].npersist; k++) {
    240          if(cell[j].persist[k].fiterr) continue;
    241          if(cell[j].persist[k].nfit <= 0) continue;
     243
     244         if(PERSIST_RETAIN) {
     245/* Keep fits which have a dubious slope */
     246            if(cell[j].persist[k].fiterr != FIT_SLOPE_ERROR) {
     247               if(cell[j].persist[k].fiterr) continue;
     248               if(cell[j].persist[k].nfit <= 0) continue;
     249            }
     250         } else {
     251            if(cell[j].persist[k].fiterr) continue;
     252            if(cell[j].persist[k].nfit <= 0) continue;
     253         }
    242254         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",
    243255                 j, cell[j].persist[k].time,
     
    262274      for(k=0; k<cell[j].nburn; k++) {
    263275         if(!cell[j].burn[k].burned) continue;
    264          if(cell[j].burn[k].fiterr &&
    265             cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
    266          if(cell[j].burn[k].nfit <= 0) continue;
     276         if(PERSIST_RETAIN) {
     277/* Keep fits which have a dubious slope */
     278            if(cell[j].burn[k].fiterr != FIT_SLOPE_ERROR) {
     279               if(cell[j].burn[k].fiterr &&
     280                  cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
     281               if(cell[j].burn[k].nfit <= 0) continue;
     282            }
     283         } else {
     284            if(cell[j].burn[k].fiterr &&
     285               cell[j].burn[k].fiterr != FIT_TOP_ERROR) continue;
     286            if(cell[j].burn[k].nfit <= 0) continue;
     287         }
    267288
    268289         i = (cell[j].burn[k].ex - cell[j].burn[k].sx + 1) / 2;
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/trailfit.c

    r25070 r25299  
    226226/* FIXME: sanity check fits */
    227227   if(slope >= FIT_MAX_SLOPE || slope < FIT_MIN_SLOPE) {
     228      box->slope = slope;
     229      box->nfit = 0;
    228230      box->fiterr = FIT_SLOPE_ERROR;
    229231      return(-1);
  • trunk/extsrc/gpcsw/gpcsrc/fits/libfh/fh.c

    r24391 r25299  
    10391039         newval[strlen(newval) - 1] = '\0';
    10401040         fh_set_str(hu, idx, name, newval, comment);
     1041         free(newval);
    10411042         return;
    10421043      }
     
    15191520      i++;
    15201521   }
     1522   return FH_SUCCESS;
     1523}
     1524
     1525static void
     1526pad_header(HeaderUnit hu, int n)
     1527{
     1528   int i;
     1529   double idx = 900000000;
     1530
     1531   for (i = 0; i < n; i++)
     1532   {
     1533      fh_set_card(hu, idx++, FH_RESERVE);
     1534   }
     1535}
     1536
     1537fh_result
     1538fh_copy(HeaderUnit hu, const HeaderUnit source_)
     1539{
     1540   fh_result result;
     1541   int reserve;
     1542
     1543   result = fh_merge(hu, source_);
     1544   if (result != FH_SUCCESS) return result;
     1545   reserve = fh_get_reserve(source_);
     1546   if (reserve) pad_header(hu, reserve);
    15211547   return FH_SUCCESS;
    15221548}
     
    17571783}
    17581784
     1785int
     1786fh_get_reserve(HeaderUnit hu)
     1787{
     1788   HeaderUnitStruct* list = FH_HU(hu);
     1789
     1790   if (!list)
     1791   {
     1792      log_error("invalid argument to fh_get_reserve()");
     1793      return -1;
     1794   }
     1795
     1796   if (list->reserve)
     1797      return list->reserve;
     1798   else
     1799      return list->reserve_found;
     1800}
     1801
    17591802fh_result
    17601803fh_rewrite(HeaderUnit hu)
  • trunk/extsrc/gpcsw/gpcsrc/fits/libfh/fh.h

    r23924 r25299  
    174174 * is used to create a new FITS header.  NOT for use with fh_rewrite().
    175175 */
     176int fh_get_reserve(HeaderUnit hu);
     177/*
     178 * Get the current setting or the number of reserve cards found in
     179 * a header unit.  Returns -1 if hu is invalid.
     180 */
    176181fh_result fh_validate(HeaderUnit hu); /* fh_validate.c; for use by fhtool.c */
    177182
     
    386391double fh_idx(HeaderUnit hu); /* idx of the last card returned by fh_next */
    387392fh_result fh_merge(HeaderUnit hu, const HeaderUnit source); /* source unchanged */
     393fh_result fh_copy(HeaderUnit hu, const HeaderUnit source); /* fh_merge+keep reserve */
    388394
    389395/* ---------------------------------------------------------
     
    459465 */
    460466
    461 
    462467#endif /* _INCLUDED_fh */
  • trunk/ippScripts/Build.PL

    r24726 r25299  
    4949        scripts/chip_imfile.pl
    5050        scripts/camera_exp.pl
     51        scripts/addstar_run.pl
    5152        scripts/fake_imfile.pl
    5253        scripts/warp_overlap.pl
  • trunk/ippScripts/scripts/camera_exp.pl

    r24465 r25299  
    9393&my_die("Unrecognised JPEG recipe", $cam_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe2;
    9494
    95 my $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use
    96 &my_die("Unrecognised ADDSTAR recipe", $cam_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_addstar;
     95#my $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use
     96#&my_die("Unrecognised ADDSTAR recipe", $cam_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_addstar;
    9797
    9898my $recipe_psastro = $ipprc->reduction($reduction, 'PSASTRO'); # Recipe to use
     
    205205}
    206206
    207 my $dtime_addstar = 0;
     207#my $dtime_addstar = 0;
    208208
    209209unless ($no_op) {
     
    297297
    298298        # run addstar on the output fpaObjects (if a DVO database is defined)
    299         if (defined $dvodbReal and ($run_state eq 'new')) {
    300 
    301             ## XXX the camera analysis can either save the full set of
    302             ## detections, or just the image metadata, in the dvodb
    303 
    304             ## get the addstar recipe for this camera and CAMERA reduction
    305             $command = "$ppConfigDump -camera $camera -recipe ADDSTAR $recipe_addstar -dump-recipe ADDSTAR -";
    306             ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    307                 run(command => $command, verbose => $verbose);
    308             unless ($success) {
    309                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    310                 &my_die("Unable to perform ppConfigDump: $error_code", $cam_id, $PS_EXIT_SYS_ERROR);
    311             }
    312             my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
    313                 &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_SYS_ERROR);
    314 
    315             ## allow the dvodb to save only images, or the full detection set
    316             my $imagesOnly = metadataLookupBool($recipeData, 'IMAGES.ONLY');
    317 
    318             # XXX this construct requires the user to have a valid .ptolemyrc
    319             # XXX which in turn points at ippconfig/dvo.site
    320             # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
    321             # XXX this needs to be converted to addstar_client...
    322 
    323             my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
    324             my $command;
    325             $command  = "$addstar -D CAMERA $camdir -update";
    326             $command .= " -image" if $imagesOnly;
    327             $command .= " -D CATDIR $dvodbReal";
    328 
    329             my $realFile = $ipprc->file_resolve($fpaObjects);
    330             $command .= " $realFile";
    331 
    332             my $mjd_addstar_start = DateTime->now->mjd;   # MJD of starting script
    333 
    334             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    335                 run(command => $command, verbose => $verbose);
    336             unless ($success) {
    337                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    338                 &my_die("Unable to perform addstar: $error_code", $cam_id, $error_code);
    339             }
    340             $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start);   # MJD of starting script
    341         }
     299#         if (defined $dvodbReal and ($run_state eq 'new')) {
     300
     301#             ## XXX the camera analysis can either save the full set of
     302#             ## detections, or just the image metadata, in the dvodb
     303
     304#             ## get the addstar recipe for this camera and CAMERA reduction
     305#             $command = "$ppConfigDump -camera $camera -recipe ADDSTAR $recipe_addstar -dump-recipe ADDSTAR -";
     306#             ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     307#                 run(command => $command, verbose => $verbose);
     308#             unless ($success) {
     309#                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     310#                 &my_die("Unable to perform ppConfigDump: $error_code", $cam_id, $PS_EXIT_SYS_ERROR);
     311#             }
     312#             my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
     313#                 &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_SYS_ERROR);
     314
     315#             ## allow the dvodb to save only images, or the full detection set
     316#             my $imagesOnly = metadataLookupBool($recipeData, 'IMAGES.ONLY');
     317
     318#             # XXX this construct requires the user to have a valid .ptolemyrc
     319#             # XXX which in turn points at ippconfig/dvo.site
     320#             # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
     321#             # XXX this needs to be converted to addstar_client...
     322
     323#             my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
     324#             my $command;
     325#             $command  = "$addstar -D CAMERA $camdir -update";
     326#             $command .= " -image" if $imagesOnly;
     327#             $command .= " -D CATDIR $dvodbReal";
     328
     329#             my $realFile = $ipprc->file_resolve($fpaObjects);
     330#             $command .= " $realFile";
     331
     332#             my $mjd_addstar_start = DateTime->now->mjd;   # MJD of starting script
     333
     334#             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     335#                 run(command => $command, verbose => $verbose);
     336#             unless ($success) {
     337#                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     338#                 &my_die("Unable to perform addstar: $error_code", $cam_id, $error_code);
     339#             }
     340#             $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start);   # MJD of starting script
     341#         }
    342342    }
    343343}
     
    353353    $fpaCommand .= " -hostname $host" if defined $host;
    354354    $fpaCommand .= " -dtime_script $dtime_script";
    355     $fpaCommand .= " -dtime_addstar $dtime_addstar";
     355#    $fpaCommand .= " -dtime_addstar $dtime_addstar";
    356356} else {
    357357    $fpaCommand .= " -updaterun -state full";
  • trunk/ippScripts/scripts/ipp_cleanup.pl

    r24642 r25299  
    6060
    6161
    62 my %stages = ( chip => 1, camera => 1, fake => 1, warp => 1, stack => 1, diff  => 1,
    63                detrend.process.imfile => 1, detrend.process.exp => 1, detrend.stack.imfile => 1,
    64                detrend.normstat.imfile => 1, detrend.norm.imfile => 1, detrend.norm.exp => 1,
    65                detrend.resid.imfile => 1, detrend.resid.exp => 1 );
     62my %stages = ( "chip" => 1, "camera" => 1, "fake" => 1, "warp" => 1, "stack" => 1, "diff"  => 1,
     63               "detrend.process.imfile" => 1, "detrend.process.exp" => 1, "detrend.stack.imfile" => 1,
     64               "detrend.normstat.imfile" => 1, "detrend.norm.imfile" => 1, "detrend.norm.exp" => 1,
     65               "detrend.resid.imfile" => 1, "detrend.resid.exp" => 1 );
    6666unless ($stages{$stage}) {
    6767    die "unknown stage $stage for ipp_cleanup.pl\n";
     
    119119        # don't clean up unless the data needed to update is available
    120120        # modes goto_purged and goto_scrubbed will remove files even if the config is non-existent
     121        # goto_scrubbed now requires the config file to not exist.
    121122        if ($mode eq "goto_cleaned") {
    122123            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id);
    123             print STDERR "CHIP: CONFIG_FILE : $config_file\n";
     124
    124125            if (!$config_file or ! -e $config_file) {
    125126                print STDERR "skipping cleanup for chipRun $stage_id $class_id "
     
    128129            }
    129130        }
     131        elsif ($mode eq "goto_scrubbed") {
     132            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id);
     133
     134            if ($config_file and -e $config_file) {
     135                print STDERR "skipping scrubbed for chipRun $stage_id $class_id "
     136                    . " because config file is present\n";
     137                $status = 0;
     138            }
     139        }
    130140
    131141        if ($status) {
     
    160170            if ($mode eq "goto_purged") {
    161171                $command .= " -topurgedimfile";
    162             } else {
     172            }
     173            elsif ($mode eq "goto_cleaned") {
    163174                $command .= " -tocleanedimfile";
    164175            }
     176            elsif ($mode eq "goto_scrubbed") {
     177                $command .= " -toscrubbedimfile";
     178            }
     179
    165180            $command .= " -dbname $dbname" if defined $dbname;
    166181
     
    218233    my $status = 1;
    219234    # don't clean up unless the data needed to update is available
     235    # goto_scrubbed now requires the config file to not be present
    220236    if ($mode eq "goto_cleaned") {
    221237        my $config_file = $ipprc->filename("PSASTRO.CONFIG", $path_base);
     
    225241            $status = 0;
    226242        }
     243    }
     244    elsif ($mode eq "goto_scrubbed") {
     245        my $config_file = $ipprc->filename("PSASTRO.CONFIG", $path_base);
     246
     247        if ($config_file and -e $config_file) {
     248            print STDERR "skipping cleanup for camRun $stage_id because config file ($config_file) is present\n";
     249            $status = 0;
     250        }
    227251    }
    228252    if ($status) {
     
    246270        }
    247271        if ($mode eq "goto_scrubbed") {
    248             $command = "$camtool -updaterun -cam_id $stage_id -set_state cleaned";
     272            $command = "$camtool -updaterun -cam_id $stage_id -set_state scrubbed";
    249273        }
    250274        if ($mode eq "goto_purged") {
     
    311335            }
    312336        }
     337        elsif ($mode eq "goto_scrubbed") {
     338            my $config_file = $ipprc->filename("PSWARP.CONFIG", $path_base, $skycell_id);
     339
     340            if ($config_file and -e $config_file) {
     341                print STDERR "skipping scrubbed for warpRun $stage_id $skycell_id" .
     342                    " because config file is present\n";
     343                $status = 0;
     344            }
     345        }
    313346        if ($status) {
    314347            # delete the temporary image datafiles
     
    337370            if ($mode eq "goto_purged") {
    338371                $command .= " -topurgedskyfile";
    339             } else {
     372            }
     373            elsif ($mode eq "goto_cleaned") {
    340374                $command .= " -tocleanedskyfile";
    341375            }
     376            elsif ($mode eq "goto_scrubbed") {
     377                $command .= " -toscrubbedskyfile";
     378            }
    342379            $command .= " -dbname $dbname" if defined $dbname;
    343380
     
    395432        if ($mode eq "goto_cleaned") {
    396433            my $config_file = $ipprc->filename("PPSTACK.CONFIG", $path_base, $skycell_id);
    397             print STDERR "MY CONFIG FILE = $config_file\n";
    398             printf(STDERR "BOOLS: %d %d %d %s\n",!$config_file, ! -e $config_file, -e $config_file,$config_file);
     434
    399435            $config_file =~ s%^file://%%;
    400436            if (!$config_file or ! -e $config_file) {
     
    404440            }
    405441            $config_file = 'file://' . $config_file;
     442        }
     443        elsif ($mode eq "goto_scrubbed") {
     444            my $config_file = $ipprc->filename("PPSTACK.CONFIG", $path_base, $skycell_id);
     445            $config_file =~ s%^file://%%;
     446            if ($config_file and -e $config_file) {
     447                print STDERR "skipping scrubbed for stackRun $stage_id $skycell_id" .
     448                    " because config file is present\n";
     449                $status = 0;
     450            }
    406451        }
    407452        if ($status) {
     
    428473            if ($mode eq "goto_purged") {
    429474                $command .= " -updaterun -state purged";
    430             } else {
     475            }
     476            elsif ($mode eq "goto_cleaned") {
    431477                $command .= " -updaterun -state cleaned";
     478            }
     479            elsif ($mode eq "goto_scrubbed") {
     480                $command .= " -updaterun -state scrubbed";
    432481            }
    433482            $command .= " -dbname $dbname" if defined $dbname;
     
    485534        if ($mode eq "goto_cleaned") {
    486535            my $config_file = $ipprc->filename("PPSUB.CONFIG", $path_base, $skycell_id);
    487             print STDERR "MY CONFIG FILE = $config_file\n";
    488             printf(STDERR "BOOLS: %d %d %d %s\n",!$config_file, ! -e $config_file, -e $config_file,$config_file);
     536
    489537            $config_file =~ s%^file://%%;
    490538            if (!$config_file or ! -e $config_file) {
     
    494542            }
    495543            $config_file = 'file://' . $config_file;
     544        }
     545        elsif ($mode eq "goto_scrubbed") {
     546            my $config_file = $ipprc->filename("PPSUB.CONFIG", $path_base, $skycell_id);
     547            $config_file =~ s%^file://%%;
     548            if ($config_file and -e $config_file) {
     549                print STDERR "skipping scrubbed for diffRun $stage_id $skycell_id" .
     550                    " because config file ($config_file) is present\n";
     551                $status = 0;
     552            }
    496553        }
    497554        if ($status) {
     
    529586        if ($status) {
    530587            my $command = "$difftool -diff_id $stage_id";
    531 #           my $command = "$difftool -diff_id $stage_id -skycell_id $skycell_id";
     588
    532589            if ($mode eq "goto_purged") {
    533590                $command .= " -updaterun -state purged";
    534             } else {
     591            }
     592            elsif ($mode eq "goto_cleaned") {
    535593                $command .= " -updaterun -state cleaned";
    536594            }
     595            elsif ($mode eq "goto_scrubbed") {
     596                $command .= " -updaterun -state scrubbed";
     597            }
     598
    537599            $command .= " -dbname $dbname" if defined $dbname;
    538600           
     
    545607        } else {
    546608            my $command = "$difftool -updaterun -diff_id $stage_id -state $error_state";
    547 #           my $command = "$difftool -updaterun -diff_id $stage_id -skycell_id $skycell_id -state $error_state";
     609
    548610            $command .= " -dbname $dbname" if defined $dbname;
    549611           
     
    560622}
    561623if ($stage eq 'fake') {
    562     die "ipp_cleanup.pl -stage fake not yet implemented. Probably will just mark database cleaned.\n";
     624    print STDERR "This does not seem to work at present, as no files exist. Terminating quietly.\n";
     625    exit(0);
     626    die "--stage_id required for stage fake\n" if !$stage_id;
     627    ### select the imfiles for this entry
     628
     629    # this stage uses 'chiptool'
     630    my $faketool = can_run('faketool') or die "Can't find faketool";
     631
     632    # Get list of component imfiles
     633    # XXX may need a different my_die for each stage
     634    my $imfiles;                      # Array of component files
     635    my $command = "$faketool -pendingcleanupimfile -fake_id $stage_id"; # Command to run
     636    $command .= " -dbname $dbname" if defined $dbname;
     637    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     638    unless ($success) {
     639        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     640        &my_die("Unable to perform faketool: $error_code", "fake", $stage_id, $error_code);
     641    }
     642
     643    # if there are no fakeProcessedImfiles (@$stdout_buf == 0), the reset the state to 'new'
     644    if (@$stdout_buf == 0)  {
     645        my $command = "$faketool -fake_id $stage_id -updaterun -set_state new";
     646        $command .= " -dbname $dbname" if defined $dbname;
     647
     648        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     649            run(command => $command, verbose => $verbose);
     650        unless ($success) {
     651            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     652            &my_die("Unable to perform faketool: $error_code", "fake", $stage_id, $error_code);
     653        }
     654        exit 0;
     655    }
     656
     657    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     658        &my_die("Unable to parse metadata config doc", "fake", $stage_id, $PS_EXIT_PROG_ERROR);
     659
     660    # extract the metadata for the files into a hash list
     661    $imfiles = parse_md_list($metadata) or
     662        &my_die("Unable to parse metadata list", "fake", $stage_id, $PS_EXIT_PROG_ERROR);
     663
     664    # loop over all of the imfiles, determine the path_base and class_id for each
     665    foreach my $imfile (@$imfiles) {
     666        my $class_id = $imfile->{class_id};
     667        my $path_base = $imfile->{path_base};
     668        my $status = 1;
     669
     670        # don't clean up unless the data needed to update is available
     671        # modes goto_purged and goto_scrubbed will remove files even if the config is non-existent
     672        # goto_scrubbed now requires the config file to not exist.
     673        if ($mode eq "goto_cleaned") {
     674            my $config_file = $ipprc->filename("PPSIM.CONFIG", $path_base, $class_id);
     675
     676            if (!$config_file or ! -e $config_file) {
     677                print STDERR "skipping cleanup for fakeRun $stage_id $class_id "
     678                    . " because config file is missing\n";
     679                $status = 0;
     680            }
     681        }
     682        elsif ($mode eq "goto_scrubbed") {
     683            my $config_file = $ipprc->filename("PPSIM.CONFIG", $path_base, $class_id);
     684
     685            if ($config_file and -e $config_file) {
     686                print STDERR "skipping scrubbed for fakeRun $stage_id $class_id "
     687                    . " because config file is present\n";
     688                $status = 0;
     689            }
     690        }
     691
     692        if ($status) {
     693            # array of actual filenames to delete
     694            my @files = ();
     695
     696            # delete the temporary image datafiles
     697            addFilename (\@files, "PPSIM.OUTPUT.MEF", $path_base, $class_id);
     698            addFilename (\@files, "PPSIM.OUTPUT.SPL", $path_base, $class_id);
     699            addFilename (\@files, "PPSIM.FAKE.CHIP", $path_base, $class_id);
     700            addFilename (\@files, "PPSIM.FORCE.CHIP", $path_base, $class_id);
     701            if ($mode eq "goto_purged") {
     702                # additional files to remove for 'purge' mode
     703                addFilename (\@files, "PPSIM.SOURCES", $path_base, $class_id);
     704                addFilename (\@files, "PPSIM.FAKE.SOURCES", $path_base, $class_id);
     705                addFilename (\@files, "PPSIM.FORCE.SOURCES", $path_base, $class_id);
     706            }
     707
     708            # actual command to delete the files
     709            $status = &delete_files (\@files);
     710        }
     711
     712        if ($status)  {
     713            my $command = "$faketool -fake_id $stage_id -class_id $class_id";
     714            if ($mode eq "goto_purged") {
     715                $command .= " -topurgedimfile";
     716            }
     717            elsif ($mode eq "goto_cleaned") {
     718                $command .= " -tocleanedimfile";
     719            }
     720            elsif ($mode eq "goto_scrubbed") {
     721                $command .= " -toscrubbedimfile";
     722            }
     723
     724            $command .= " -dbname $dbname" if defined $dbname;
     725
     726            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     727                    run(command => $command, verbose => $verbose);
     728            unless ($success) {
     729                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     730                &my_die("Unable to perform faketool: $error_code", "fake", $stage_id, $error_code);
     731            }
     732        } else {
     733
     734            # if an error happens for one chip, the chipRun will stay in goto_*, but the chips will go to error_* (matching the goto_*)
     735            my $command = "$faketool -updateprocessedimfile -fake_id $stage_id -class_id $class_id -set_state $error_state";
     736            $command .= " -dbname $dbname" if defined $dbname;
     737
     738            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     739                    run(command => $command, verbose => $verbose);
     740            unless ($success) {
     741                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     742                &my_die("Unable to perform faketool: $error_code", "fake", $stage_id, $error_code);
     743            }
     744        }
     745    }
     746    exit 0;
     747
    563748}
    564 # fake : faketool : -pendingcleanupimfile (loop over imfiles)
     749# Detrend stages
     750if ($stage eq "detrend.process.imfile") {
     751
     752    die "--stage_id required for stage detrend.process.imfile\n" if !$stage_id;
     753    ### select the imfiles for this entry
     754
     755    # this stage uses 'dettool'
     756    my $dettool = can_run('dettool') or die "Can't find chiptool";
     757
     758    # Get list of component imfiles
     759    # XXX may need a different my_die for each stage
     760    my $imfiles;                      # Array of component files
     761    my $command = "$dettool -pendingcleanup_processedimfile -det_id $stage_id"; # Command to run
     762    $command .= " -dbname $dbname" if defined $dbname;
     763    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     764    unless ($success) {
     765        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     766        &my_die("Unable to perform dettool: $error_code", "detrend.process.imfile", $stage_id, $error_code);
     767    }
     768
     769    # if there are no detProcessedImfiles (@$stdout_buf == 0), the reset the state to 'new'
     770    if (@$stdout_buf == 0)  {
     771        exit 0; # Silently exit if there's nothing to do.  I don't know how we'd ever get here, but let's be safe.
     772    }
     773
     774    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     775        &my_die("Unable to parse metadata config doc", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     776
     777    # extract the metadata for the files into a hash list
     778    $imfiles = parse_md_list($metadata) or
     779        &my_die("Unable to parse metadata list", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     780
     781    # loop over all of the imfiles, determine the path_base and class_id for each
     782    foreach my $imfile (@$imfiles) {
     783        my $exp_id   = $imfile->{exp_id};
     784        my $class_id = $imfile->{class_id};
     785        my $path_base = $imfile->{path_base};
     786        my $status = 1;
     787
     788        # don't clean up unless the data needed to update is available
     789        # modes goto_purged and goto_scrubbed will remove files even if the config is non-existent
     790        # goto_scrubbed now requires the config file to not exist.
     791       
     792        # Possibly not the correct config file, but simtest doesn't leave any around to check.
     793        if ($mode eq "goto_cleaned") {
     794            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id);
     795
     796            if (!$config_file or ! -e $config_file) {
     797                print STDERR "skipping cleanup for detrend.process.imfile $stage_id $class_id "
     798                    . " because config file is missing\n";
     799                $status = 0;
     800            }
     801        }
     802        elsif ($mode eq "goto_scrubbed") {
     803            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id);
     804
     805            if ($config_file and -e $config_file) {
     806                print STDERR "skipping scrubbed for detrend.process.imfile $stage_id $class_id "
     807                    . " because config file is present\n";
     808                $status = 0;
     809            }
     810        }
     811
     812        if ($status) {
     813            # array of actual filenames to delete
     814            my @files = ();
     815
     816            # delete the temporary image datafiles
     817            addFilename (\@files, "PPIMAGE.OUTPUT", $path_base, $class_id);
     818            addFilename (\@files, "PPIMAGE.OUTPUT.MASK", $path_base, $class_id);
     819            addFilename (\@files, "PPIMAGE.OUTPUT.VARIANCE", $path_base, $class_id);
     820            if ($mode eq "goto_purged") {
     821                # additional files to remove for 'purge' mode
     822                addFilename (\@files, "PPIMAGE.BIN1", $path_base, $class_id);
     823                addFilename (\@files, "PPIMAGE.BIN2", $path_base, $class_id);
     824                addFilename (\@files, "PPIMAGE.STATS", $path_base, $class_id);
     825            }
     826
     827            # actual command to delete the files
     828            $status = &delete_files (\@files);
     829        }
     830
     831        if ($status)  {
     832            my $command = "$dettool -det_id $stage_id -exp_id $exp_id -class_id $class_id -updateprocessedimfile";
     833            if ($mode eq "goto_purged") {
     834                $command .= " -data_state purged";
     835            }
     836            elsif ($mode eq "goto_cleaned") {
     837                $command .= " -data_state cleaned";
     838            }
     839            elsif ($mode eq "goto_scrubbed") {
     840                $command .= " -data_state scrubbed";
     841            }
     842
     843            $command .= " -dbname $dbname" if defined $dbname;
     844
     845            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     846                    run(command => $command, verbose => $verbose);
     847            unless ($success) {
     848                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     849                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     850            }
     851
     852        } else {
     853
     854            # if an error happens for one chip, the chipRun will stay in goto_*, but the chips will go to error_* (matching the goto_*)
     855            my $command = "$dettool -updateprocessedimfile -det_id $stage_id -exp_id $exp_id -class_id $class_id -data_state $error_state";
     856            $command .= " -dbname $dbname" if defined $dbname;
     857
     858            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     859                    run(command => $command, verbose => $verbose);
     860            unless ($success) {
     861                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     862                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     863            }
     864        }
     865    }
     866
     867    # Check to see if we can mark the whole detRunSummary object as cleaned.
     868
     869    $command = "$dettool -pendingcleanup_detrunsummary -det_id $stage_id";
     870    $command .= " -dbname $dbname" if defined $dbname;
     871    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     872    unless ($success) {
     873        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     874        &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     875    }
     876    if (@$stdout_buf != 0) {
     877        $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     878            &my_die("Unable to parse metadata config doc", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     879        my $exps = parse_md_list($metadata) or
     880            &my_die("Unable to parse metadata list", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     881       
     882        foreach my $exp (@$exps) {
     883            my $iteration = $exp->{iteration};
     884            my $command;
     885            if ($mode eq "goto_cleaned") {
     886                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state cleaned";
     887            }
     888            if ($mode eq "goto_scrubbed") {
     889                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state scrubbed";
     890            }
     891            if ($mode eq "goto_purged") {
     892                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state purged";
     893            }
     894            $command .= " -dbname $dbname" if defined $dbname;
     895            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     896                run(command => $command, verbose => $verbose);
     897            unless ($success) {
     898                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     899                &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     900            }
     901        }
     902    }
     903   
     904    exit 0;
     905}
     906if ($stage eq "detrend.process.exp") {
     907    die "--stage_id required for stage $stage\n" if !$stage_id;
     908    # this stage uses 'dettool'
     909    my $dettool = can_run('dettool') or die "Can't find dettool";
     910
     911    # Get list of component imfiles
     912    # XXX may need a different my_die for each stage
     913    my $exps;                      # Array of component files
     914    my $command = "$dettool -pendingcleanup_processedexp -det_id $stage_id"; # Command to run
     915    $command .= " -dbname $dbname" if defined $dbname;
     916    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     917    unless ($success) {
     918        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     919        &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     920    }
     921   
     922    if (@$stdout_buf == 0) {
     923        exit 0; #silently abort. I need to fix this for propers
     924    }
     925
     926    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     927        &my_die("Unable to parse metadata config doc", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     928
     929    $exps = parse_md_list($metadata) or
     930        &my_die("Unable to parse metadata list", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     931
     932
     933    foreach my $exp (@$exps) {
     934        my $path_base = $exp->{path_base};
     935        my $exp_id    = $exp->{exp_id};
     936
     937        my $status = 1;
     938        # don't clean up unless the data needed to update is available
     939        # goto_scrubbed now requires the config file to not be present
     940        if ($mode eq "goto_cleaned") {
     941            my $config_file = $ipprc->filename("PSIMAGE.CONFIG", $path_base);
     942           
     943            if (!$config_file or ! -e $config_file) {
     944                print STDERR "skipping cleanup for $stage $stage_id because config file is missing\n";
     945                $status = 0;
     946            }
     947        }
     948        elsif ($mode eq "goto_scrubbed") {
     949            my $config_file = $ipprc->filename("PSIMAGE.CONFIG", $path_base);
     950           
     951            if ($config_file and -e $config_file) {
     952                print STDERR "skipping cleanup for $stage $stage_id because config file ($config_file) is present\n";
     953                $status = 0;
     954            }
     955        }
     956        if ($status) {
     957            my @files = ();
     958            # delete the temporary image datafiles
     959            # I can't find anything to put here
     960            if ($mode eq "goto_purged") {
     961                # additional files to remove for 'purge' mode
     962                addFilename (\@files, "PPIMAGE.JPEG1", $path_base);
     963                addFilename (\@files, "PPIMAGE.JPEG2", $path_base);
     964            }
     965            # actual command to delete the files
     966            $status = &delete_files (\@files);
     967        }
     968       
     969        if ($status)  {
     970            my $command;
     971            if ($mode eq "goto_cleaned") {
     972                $command = "$dettool -updateprocessedexp -det_id $stage_id -exp_id $exp_id -data_state cleaned";
     973            }
     974            if ($mode eq "goto_scrubbed") {
     975                $command = "$dettool -updateprocessedexp -det_id $stage_id -exp_id $exp_id -data_state scrubbed";
     976            }
     977            if ($mode eq "goto_purged") {
     978                $command = "$dettool -updateprocessedexp -det_id $stage_id -exp_id $exp_id -data_state purged";
     979            }
     980            $command .= " -dbname $dbname" if defined $dbname;
     981            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     982                run(command => $command, verbose => $verbose);
     983            unless ($success) {
     984                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     985                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     986            }
     987        } else {
     988            # since 'camera' has only a single imfile, we can just update the run
     989            my $command = "$dettool -updateprocessedexp -det_id $stage_id -exp_id $exp_id -data_state $error_state";
     990            $command .= " -dbname $dbname" if defined $dbname;
     991           
     992            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     993                run(command => $command, verbose => $verbose);
     994            unless ($success) {
     995                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     996                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     997            }
     998            exit $PS_EXIT_UNKNOWN_ERROR;
     999        }
     1000    }
     1001    # Check to see if we can mark the whole detRunSummary object as cleaned.
     1002
     1003    $command = "$dettool -pendingcleanup_detrunsummary -det_id $stage_id";
     1004    $command .= " -dbname $dbname" if defined $dbname;
     1005    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1006    unless ($success) {
     1007        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1008        &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1009    }
     1010    if (@$stdout_buf != 0) {
     1011        $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     1012            &my_die("Unable to parse metadata config doc", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1013        $exps = parse_md_list($metadata) or
     1014            &my_die("Unable to parse metadata list", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1015       
     1016        foreach my $exp (@$exps) {
     1017            my $iteration = $exp->{iteration};
     1018            my $command;
     1019            if ($mode eq "goto_cleaned") {
     1020                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state cleaned";
     1021            }
     1022            if ($mode eq "goto_scrubbed") {
     1023                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state scrubbed";
     1024            }
     1025            if ($mode eq "goto_purged") {
     1026                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state purged";
     1027            }
     1028            $command .= " -dbname $dbname" if defined $dbname;
     1029            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1030                run(command => $command, verbose => $verbose);
     1031            unless ($success) {
     1032                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1033                &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1034            }
     1035        }
     1036    }
     1037
     1038    exit 0;
     1039}
     1040if ($stage eq "detrend.stack.imfile") {
     1041   
     1042    die "--stage_id required for stage $stage\n" if !$stage_id;
     1043
     1044    # this stage uses 'dettool'
     1045    my $dettool = can_run('dettool') or die "Can't find dettool";
     1046
     1047    # Get list of component imfiles
     1048    my $stacks;                  # Array reference of component files
     1049    my $command = "$dettool -pendingcleanup_stacked -det_id $stage_id"; # Command to run
     1050    $command .= " -dbname $dbname" if defined $dbname;
     1051    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1052    unless ($success) {
     1053        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1054        &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1055    }
     1056    my $metadata = $mdcParser->parse(join "", @{ $stdout_buf }) or
     1057        &my_die("Unable to parse metadata config doc", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     1058
     1059    $stacks = parse_md_list($metadata) or
     1060        &my_die("Unable to parse metadata list", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     1061   
     1062    my @files = ();
     1063    foreach my $stack (@{ $stacks }) {
     1064        # detStackedImfile does not have a path_base column.  This is inconvenient, as it means we need to calculate it.
     1065        my $path_base = $stack->{uri};
     1066        my $iteration = $stack->{iteration};
     1067        my $class_id  = $stack->{class_id};
     1068
     1069        $path_base =~ s/\.fits$//; # That should do it?
     1070
     1071        my $status = 1;
     1072
     1073#       if ($mode eq "goto_cleaned") {
     1074#           my $config_file = $ipprc->filename("PPMERGE.CONFIG", $path_base, $stage_id);
     1075
     1076#           $config_file =~ s%^file://%%;
     1077#           if (!$config_file or ! -e $config_file) {
     1078#               print STDERR "skipping cleanup for $stage $stage_id $path_base" .
     1079#                   " because config file is missing\n";
     1080#               $status = 0;
     1081#           }
     1082#           $config_file = 'file://' . $config_file;
     1083#       }
     1084#       elsif ($mode eq "goto_scrubbed") {
     1085#           my $config_file = $ipprc->filename("PPMERGE.CONFIG", $path_base, $stage_id);
     1086#           $config_file =~ s%^file://%%;
     1087#           if ($config_file and -e $config_file) {
     1088#               print STDERR "skipping scrubbed for $stage $stage_id $path_base" .
     1089#                   " because config file is present\n";
     1090#               $status = 0;
     1091#           }
     1092#       }
     1093
     1094        if ($status) {
     1095            # delete the temporary image datafiles
     1096            # There's no convenient way to get the detrend type, so I'm queueing all of them for deletion.
     1097            # I understand that they all point to the same filename right now, but that may not be true in
     1098            # the future.
     1099            addFilename(\@files, "PPMERGE.OUTPUT.MASK", $path_base, $stage_id);
     1100            addFilename(\@files, "PPMERGE.OUTPUT.BIAS", $path_base, $stage_id);
     1101            addFilename(\@files, "PPMERGE.OUTPUT.DARK", $path_base, $stage_id);
     1102            addFilename(\@files, "PPMERGE.OUTPUT.SHUTTER", $path_base, $stage_id);
     1103            addFilename(\@files, "PPMERGE.OUTPUT.FLAT", $path_base, $stage_id);
     1104            addFilename(\@files, "PPMERGE.OUTPUT.FRINGE", $path_base, $stage_id);
     1105           
     1106
     1107            addFilename(\@files, "PPMERGE.OUTPUT.SIGMA", $path_base, $stage_id);
     1108            addFilename(\@files, "PPMERGE.OUTPUT.COUNT", $path_base, $stage_id);
     1109
     1110            if ($mode eq "goto_purged") {
     1111                # additional files to remove for 'purge' mode
     1112#               addFilename(\@files, "PPMERGE.OUTPUT", $path_base, $stage_id);
     1113            }
     1114
     1115            $status = &delete_files(\@files);
     1116        }
     1117
     1118        if ($status) {
     1119            my $command = "$dettool -det_id $stage_id -iteration $iteration -class_id $class_id";
     1120            if ($mode eq "goto_purged") {
     1121                $command .= " -updatestacked -data_state purged";
     1122            }
     1123            elsif ($mode eq "goto_cleaned") {
     1124                $command .= " -updatestacked -data_state cleaned";
     1125            }
     1126            elsif ($mode eq "goto_scrubbed") {
     1127                $command .= " -updatestacked -data_state scrubbed";
     1128            }
     1129            $command .= " -dbname $dbname" if defined $dbname;
     1130           
     1131            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1132                run(command => $command, verbose => $verbose);
     1133            unless ($success) {
     1134                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1135                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1136            }
     1137        } else {
     1138            my $command = "$dettool -updatestacked  -det_id $stage_id -iteration $iteration -class_id $class_id -data_state $error_state";
     1139            $command .= " -dbname $dbname" if defined $dbname;
     1140           
     1141            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1142                run(command => $command, verbose => $verbose);
     1143            unless ($success) {
     1144                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1145                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1146            }
     1147            exit $PS_EXIT_UNKNOWN_ERROR;
     1148        }
     1149    }
     1150    # Check to see if we can mark the whole detRunSummary object as cleaned.
     1151
     1152    $command = "$dettool -pendingcleanup_detrunsummary -det_id $stage_id";
     1153    $command .= " -dbname $dbname" if defined $dbname;
     1154    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1155    unless ($success) {
     1156        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1157        &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1158    }
     1159    if (@$stdout_buf != 0) {
     1160        $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     1161            &my_die("Unable to parse metadata config doc", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1162        my $exps = parse_md_list($metadata) or
     1163            &my_die("Unable to parse metadata list", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1164       
     1165        foreach my $exp (@$exps) {
     1166            my $iteration = $exp->{iteration};
     1167            my $command;
     1168            if ($mode eq "goto_cleaned") {
     1169                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state cleaned";
     1170            }
     1171            if ($mode eq "goto_scrubbed") {
     1172                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state scrubbed";
     1173            }
     1174            if ($mode eq "goto_purged") {
     1175                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state purged";
     1176            }
     1177            $command .= " -dbname $dbname" if defined $dbname;
     1178            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1179                run(command => $command, verbose => $verbose);
     1180            unless ($success) {
     1181                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1182                &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1183            }
     1184        }
     1185    }
     1186    exit 0;
     1187}
     1188if ($stage eq "detrend.normstat.imfile") {
     1189    print STDERR "I'm not convinced there's anything to clean up from stage $stage\n";
     1190    die "--stage_id required for stage $stage\n" if !$stage_id;
     1191    # this stage uses 'camtool'
     1192    my $dettool = can_run('dettool') or die "Can't find dettool";
     1193
     1194    my $command = "$dettool -pendingcleanup_normalizedstat -det_id $stage_id"; # Command to run
     1195    $command .= " -dbname $dbname" if defined $dbname;
     1196    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1197    unless ($success) {
     1198        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1199        &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1200    }
     1201    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     1202        &my_die("Unable to parse metadata config doc", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     1203
     1204    my $exps = parse_md_list($metadata) or
     1205        &my_die("Unable to parse metadata list", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     1206
     1207    foreach my $exp (@$exps) {
     1208#       my $path_base = $exp->{path_base};
     1209        my $iteration = $exp->{iteration};
     1210        my $class_id  = $exp->{class_id};
     1211
     1212        my $status = 1;
     1213        if ($status)  {
     1214            my $command = "$dettool -updatenormalizedstat -det_id $stage_id -iteration $iteration -class_id $class_id";
     1215            if ($mode eq "goto_cleaned") {
     1216                $command .= " -data_state cleaned";
     1217            }
     1218            if ($mode eq "goto_scrubbed") {
     1219                $command .= " -data_state scrubbed";
     1220            }
     1221            if ($mode eq "goto_purged") {
     1222                $command .= " -data_state purged";
     1223            }
     1224            $command .= " -dbname $dbname" if defined $dbname;
     1225            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1226                run(command => $command, verbose => $verbose);
     1227            unless ($success) {
     1228                print STDERR "WTF: $success TTT $error_code QQQ\n";
     1229                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1230                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1231            }
     1232        } else {
     1233            my $command = "$dettool -updatenormalizedstat -det_id $stage_id -iteration $iteration -class_id $class_id -data_state $error_state";
     1234            $command .= " -dbname $dbname" if defined $dbname;
     1235           
     1236            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1237                run(command => $command, verbose => $verbose);
     1238            unless ($success) {
     1239                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1240                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1241            }
     1242            exit $PS_EXIT_UNKNOWN_ERROR;
     1243        }
     1244    }
     1245    # Check to see if we can mark the whole detRunSummary object as cleaned.
     1246
     1247    $command = "$dettool -pendingcleanup_detrunsummary -det_id $stage_id";
     1248    $command .= " -dbname $dbname" if defined $dbname;
     1249    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1250    unless ($success) {
     1251        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1252        &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1253    }
     1254    if (@$stdout_buf != 0) {
     1255        $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     1256            &my_die("Unable to parse metadata config doc", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1257        $exps = parse_md_list($metadata) or
     1258            &my_die("Unable to parse metadata list", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1259       
     1260        foreach my $exp (@$exps) {
     1261            my $iteration = $exp->{iteration};
     1262            my $command;
     1263            if ($mode eq "goto_cleaned") {
     1264                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state cleaned";
     1265            }
     1266            if ($mode eq "goto_scrubbed") {
     1267                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state scrubbed";
     1268            }
     1269            if ($mode eq "goto_purged") {
     1270                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state purged";
     1271            }
     1272            $command .= " -dbname $dbname" if defined $dbname;
     1273            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1274                run(command => $command, verbose => $verbose);
     1275            unless ($success) {
     1276                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1277                &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1278            }
     1279        }
     1280    }
     1281
     1282    exit 0;
     1283
     1284}
     1285if ($stage eq "detrend.norm.imfile") {
     1286    die "--stage_id required for stage $stage\n" if !$stage_id;
     1287    # this stage uses 'dettool'
     1288    my $dettool = can_run('dettool') or die "Can't find dettool";
     1289
     1290    # Get list of component imfiles
     1291    # XXX may need a different my_die for each stage
     1292    my $exps;                      # Array of component files
     1293    my $command = "$dettool -pendingcleanup_normalizedimfile -det_id $stage_id"; # Command to run
     1294    $command .= " -dbname $dbname" if defined $dbname;
     1295    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1296    unless ($success) {
     1297        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1298        &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1299    }
     1300    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     1301        &my_die("Unable to parse metadata config doc", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     1302
     1303    $exps = parse_md_list($metadata) or
     1304        &my_die("Unable to parse metadata list", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     1305
     1306    foreach my $exp (@$exps) {
     1307        my $path_base = $exp->{path_base};
     1308        my $iteration = $exp->{iteration};
     1309        my $class_id  = $exp->{class_id};
     1310
     1311        my $status = 1;
     1312        # don't clean up unless the data needed to update is available
     1313        # goto_scrubbed now requires the config file to not be present
     1314        if ($mode eq "goto_cleaned") {
     1315            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base);
     1316           
     1317            if (!$config_file or ! -e $config_file) {
     1318                print STDERR "skipping cleanup for $stage $stage_id because config file is missing\n";
     1319                $status = 0;
     1320            }
     1321        }
     1322        elsif ($mode eq "goto_scrubbed") {
     1323            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base);
     1324           
     1325            if ($config_file and -e $config_file) {
     1326                print STDERR "skipping cleanup for $stage $stage_id because config file ($config_file) is present\n";
     1327                $status = 0;
     1328            }
     1329        }
     1330        if ($status) {
     1331            my @files = ();
     1332
     1333            if ($mode eq "goto_purged") {
     1334                # additional files to remove for 'purge' mode
     1335                addFilename (\@files, "PPIMAGE.OUTPUT.FPA1", $path_base);
     1336                addFilename (\@files, "PPIMAGE.OUTPUT.FPA2", $path_base);
     1337
     1338                addFilename (\@files, "PPIMAGE.OUTPUT", $path_base);
     1339                addFilename (\@files, "PPIMAGE.STATS", $path_base);
     1340            }
     1341            # actual command to delete the files
     1342            $status = &delete_files (\@files);
     1343        }
     1344       
     1345        if ($status)  {
     1346            my $command = "$dettool -updatenormalizedimfile -det_id $stage_id -iteration $iteration -class_id $class_id";
     1347            if ($mode eq "goto_cleaned") {
     1348                $command .= " -data_state cleaned";
     1349            }
     1350            if ($mode eq "goto_scrubbed") {
     1351                $command .= " -data_state scrubbed";
     1352            }
     1353            if ($mode eq "goto_purged") {
     1354                $command .= " -data_state purged";
     1355            }
     1356            $command .= " -dbname $dbname" if defined $dbname;
     1357            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1358                run(command => $command, verbose => $verbose);
     1359            unless ($success) {
     1360                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1361                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1362            }
     1363        } else {
     1364            my $command = "$dettool -updatenormalizedimfile -det_id $stage_id -iteration $iteration -class_id $class_id -data_state $error_state";
     1365            $command .= " -dbname $dbname" if defined $dbname;
     1366           
     1367            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1368                run(command => $command, verbose => $verbose);
     1369            unless ($success) {
     1370                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1371                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1372            }
     1373            exit $PS_EXIT_UNKNOWN_ERROR;
     1374        }
     1375    }
     1376    # Check to see if we can mark the whole detRunSummary object as cleaned.
     1377
     1378    $command = "$dettool -pendingcleanup_detrunsummary -det_id $stage_id";
     1379    $command .= " -dbname $dbname" if defined $dbname;
     1380    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1381    unless ($success) {
     1382        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1383        &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1384    }
     1385    if (@$stdout_buf != 0) {
     1386        $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     1387            &my_die("Unable to parse metadata config doc", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1388        $exps = parse_md_list($metadata) or
     1389            &my_die("Unable to parse metadata list", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1390       
     1391        foreach my $exp (@$exps) {
     1392            my $iteration = $exp->{iteration};
     1393            my $command;
     1394            if ($mode eq "goto_cleaned") {
     1395                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state cleaned";
     1396            }
     1397            if ($mode eq "goto_scrubbed") {
     1398                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state scrubbed";
     1399            }
     1400            if ($mode eq "goto_purged") {
     1401                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state purged";
     1402            }
     1403            $command .= " -dbname $dbname" if defined $dbname;
     1404            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1405                run(command => $command, verbose => $verbose);
     1406            unless ($success) {
     1407                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1408                &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1409            }
     1410        }
     1411    }
     1412
     1413    exit 0;
     1414}
     1415if ($stage eq "detrend.norm.exp") {
     1416    die "--stage_id required for stage $stage\n" if !$stage_id;
     1417    # this stage uses 'dettool'
     1418    my $dettool = can_run('dettool') or die "Can't find dettool";
     1419
     1420    # Get list of component imfiles
     1421    # XXX may need a different my_die for each stage
     1422    my $exps;                      # Array of component files
     1423    my $command = "$dettool -pendingcleanup_normalizedexp -det_id $stage_id"; # Command to run
     1424    $command .= " -dbname $dbname" if defined $dbname;
     1425    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1426    unless ($success) {
     1427        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1428        &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1429    }
     1430
     1431    if (@$stdout_buf == 0) {
     1432        exit 0;
     1433    }
     1434    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     1435        &my_die("Unable to parse metadata config doc", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     1436
     1437    $exps = parse_md_list($metadata) or
     1438        &my_die("Unable to parse metadata list", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     1439
     1440    foreach my $exp (@$exps) {
     1441        my $exp_id = $exp->{exp_id};
     1442        my $iteration = $exp->{iteration};
     1443        my $path_base = $exp->{path_base};
     1444
     1445        my $status = 1;
     1446        # don't clean up unless the data needed to update is available
     1447        # goto_scrubbed now requires the config file to not be present
     1448        if ($mode eq "goto_cleaned") {
     1449            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base);
     1450           
     1451            if (!$config_file or ! -e $config_file) {
     1452                print STDERR "skipping cleanup for $stage $stage_id because config file is missing\n";
     1453                $status = 0;
     1454            }
     1455        }
     1456        elsif ($mode eq "goto_scrubbed") {
     1457            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base);
     1458           
     1459            if ($config_file and -e $config_file) {
     1460                print STDERR "skipping cleanup for $stage $stage_id because config file ($config_file) is present\n";
     1461                $status = 0;
     1462            }
     1463        }
     1464        if ($status) {
     1465            my @files = ();
     1466            # delete the temporary image datafiles
     1467            if ($mode eq "goto_purged") {
     1468                # additional files to remove for 'purge' mode
     1469                addFilename (\@files, "PPIMAGE.JPEG1", $path_base);
     1470                addFilename (\@files, "PPIMAGE.JPEG2", $path_base);
     1471            }
     1472            # actual command to delete the files
     1473            $status = &delete_files (\@files);
     1474        }
     1475       
     1476        if ($status)  {
     1477            my $command = "$dettool -updatenormalizedexp -det_id $stage_id -iteration $iteration";
     1478            if ($mode eq "goto_cleaned") {
     1479                $command .= " -data_state cleaned";
     1480            }
     1481            if ($mode eq "goto_scrubbed") {
     1482                $command .= " -data_state scrubbed";
     1483            }
     1484            if ($mode eq "goto_purged") {
     1485                $command .= " -data_state purged";
     1486            }
     1487            $command .= " -dbname $dbname" if defined $dbname;
     1488            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1489                run(command => $command, verbose => $verbose);
     1490            unless ($success) {
     1491                print STDERR " residexp had an issue setting the state:? $success $error_code\n";
     1492                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1493                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1494            }
     1495        } else {
     1496            my $command = "$dettool -updatenormalizedexp -det_id $stage_id -exp_id $exp_id -iteration $iteration -data_state $error_state";
     1497            $command .= " -dbname $dbname" if defined $dbname;
     1498           
     1499            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1500                run(command => $command, verbose => $verbose);
     1501            unless ($success) {
     1502                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1503                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1504            }
     1505            exit $PS_EXIT_UNKNOWN_ERROR;
     1506        }
     1507    }
     1508    # Check to see if we can mark the whole detRunSummary object as cleaned.
     1509
     1510    $command = "$dettool -pendingcleanup_detrunsummary -det_id $stage_id";
     1511    $command .= " -dbname $dbname" if defined $dbname;
     1512    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1513    unless ($success) {
     1514        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1515        &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1516    }
     1517    if (@$stdout_buf != 0) {
     1518        $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     1519            &my_die("Unable to parse metadata config doc", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1520        $exps = parse_md_list($metadata) or
     1521            &my_die("Unable to parse metadata list", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1522       
     1523        foreach my $exp (@$exps) {
     1524            my $iteration = $exp->{iteration};
     1525            my $command;
     1526            if ($mode eq "goto_cleaned") {
     1527                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state cleaned";
     1528            }
     1529            if ($mode eq "goto_scrubbed") {
     1530                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state scrubbed";
     1531            }
     1532            if ($mode eq "goto_purged") {
     1533                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state purged";
     1534            }
     1535            $command .= " -dbname $dbname" if defined $dbname;
     1536            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1537                run(command => $command, verbose => $verbose);
     1538            unless ($success) {
     1539                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1540                &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1541            }
     1542        }
     1543    }
     1544    exit 0;
     1545}
     1546if ($stage eq "detrend.resid.imfile") {
     1547
     1548    die "--stage_id required for stage $stage\n" if !$stage_id;
     1549    ### select the imfiles for this entry
     1550
     1551    # this stage uses 'dettool'
     1552    my $dettool = can_run('dettool') or die "Can't find dettool";
     1553
     1554    # Get list of component imfiles
     1555    # XXX may need a different my_die for each stage
     1556    my $imfiles;                      # Array of component files
     1557    my $command = "$dettool -pendingcleanup_residimfile -det_id $stage_id"; # Command to run
     1558    $command .= " -dbname $dbname" if defined $dbname;
     1559    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1560    unless ($success) {
     1561        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1562        &my_die("Unable to perform dettool: $error_code", "detrend.process.imfile", $stage_id, $error_code);
     1563    }
     1564
     1565    if (@$stdout_buf == 0) {
     1566        exit 0;
     1567    }
     1568
     1569    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     1570        &my_die("Unable to parse metadata config doc", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     1571
     1572    # extract the metadata for the files into a hash list
     1573    $imfiles = parse_md_list($metadata) or
     1574        &my_die("Unable to parse metadata list", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     1575
     1576    # loop over all of the imfiles, determine the path_base and class_id for each
     1577    foreach my $imfile (@$imfiles) {
     1578        my $class_id = $imfile->{class_id};
     1579        my $iteration = $imfile->{iteration};
     1580        my $exp_id = $imfile->{exp_id};
     1581        my $path_base = $imfile->{path_base};
     1582        my $status = 1;
     1583
     1584        # don't clean up unless the data needed to update is available
     1585        # modes goto_purged and goto_scrubbed will remove files even if the config is non-existent
     1586        # goto_scrubbed now requires the config file to not exist.
     1587       
     1588        # Possibly not the correct config file, but simtest doesn't leave any around to check.
     1589        if ($mode eq "goto_cleaned") {
     1590            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id);
     1591
     1592            if (!$config_file or ! -e $config_file) {
     1593                print STDERR "skipping cleanup for $stage $stage_id $class_id "
     1594                    . " because config file is missing\n";
     1595                $status = 0;
     1596            }
     1597        }
     1598        elsif ($mode eq "goto_scrubbed") {
     1599            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id);
     1600
     1601            if ($config_file and -e $config_file) {
     1602                print STDERR "skipping scrubbed for $stage $stage_id $class_id "
     1603                    . " because config file is present\n";
     1604                $status = 0;
     1605            }
     1606        }
     1607
     1608        if ($status) {
     1609            # array of actual filenames to delete
     1610            my @files = ();
     1611
     1612            # delete the temporary image datafiles
     1613            addFilename (\@files, "PPIMAGE.OUTPUT", $path_base, $class_id);
     1614            if ($mode eq "goto_purged") {
     1615                # additional files to remove for 'purge' mode
     1616                addFilename (\@files, "PPIMAGE.BIN1", $path_base, $class_id);
     1617                addFilename (\@files, "PPIMAGE.BIN2", $path_base, $class_id);
     1618                addFilename (\@files, "PPIMAGE.STATS", $path_base, $class_id);
     1619            }
     1620
     1621            # actual command to delete the files
     1622            $status = &delete_files (\@files);
     1623        }
     1624
     1625        if ($status)  {
     1626            my $command = "$dettool -updateresidimfile -det_id $stage_id -exp_id $exp_id -iteration $iteration -class_id $class_id";
     1627            if ($mode eq "goto_purged") {
     1628                $command .= " -data_state purged";
     1629            }
     1630            elsif ($mode eq "goto_cleaned") {
     1631                $command .= " -data_state cleaned";
     1632            }
     1633            elsif ($mode eq "goto_scrubbed") {
     1634                $command .= " -data_state scrubbed";
     1635            }
     1636
     1637            $command .= " -dbname $dbname" if defined $dbname;
     1638
     1639            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1640                    run(command => $command, verbose => $verbose);
     1641            unless ($success) {
     1642                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1643                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1644            }
     1645        } else {
     1646            my $command = "$dettool -updateresidimfile -det_id $stage_id -exp_id $exp_id -iteration $iteration -class_id $class_id -data_state $error_state";
     1647            $command .= " -dbname $dbname" if defined $dbname;
     1648
     1649            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1650                    run(command => $command, verbose => $verbose);
     1651            unless ($success) {
     1652                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1653                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1654            }
     1655        }
     1656    }
     1657    # Check to see if we can mark the whole detRunSummary object as cleaned.
     1658
     1659    $command = "$dettool -pendingcleanup_detrunsummary -det_id $stage_id";
     1660    $command .= " -dbname $dbname" if defined $dbname;
     1661    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1662    unless ($success) {
     1663        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1664        &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1665    }
     1666    if (@$stdout_buf != 0) {
     1667        $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     1668            &my_die("Unable to parse metadata config doc", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1669        my $exps = parse_md_list($metadata) or
     1670            &my_die("Unable to parse metadata list", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1671       
     1672        foreach my $exp (@$exps) {
     1673            my $iteration = $exp->{iteration};
     1674            my $command;
     1675            if ($mode eq "goto_cleaned") {
     1676                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state cleaned";
     1677            }
     1678            if ($mode eq "goto_scrubbed") {
     1679                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state scrubbed";
     1680            }
     1681            if ($mode eq "goto_purged") {
     1682                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state purged";
     1683            }
     1684            $command .= " -dbname $dbname" if defined $dbname;
     1685            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1686                run(command => $command, verbose => $verbose);
     1687            unless ($success) {
     1688                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1689                &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1690            }
     1691        }
     1692    }
     1693
     1694    exit 0;
     1695}
     1696if ($stage eq "detrend.resid.exp") {
     1697    die "--stage_id required for stage $stage\n" if !$stage_id;
     1698    # this stage uses 'camtool'
     1699    my $dettool = can_run('dettool') or die "Can't find dettool";
     1700
     1701    # Get list of component imfiles
     1702    # XXX may need a different my_die for each stage
     1703    my $exps;                      # Array of component files
     1704    my $command = "$dettool -pendingcleanup_residexp -det_id $stage_id"; # Command to run
     1705    $command .= " -dbname $dbname" if defined $dbname;
     1706    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1707    unless ($success) {
     1708        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1709        &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1710    }
     1711    # This is a hack to bomb out until I can diagnose why pantasks wants to keep running this
     1712    if (@$stdout_buf == 0) {
     1713        exit 0;
     1714    }
     1715    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     1716        &my_die("Unable to parse metadata config doc", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     1717
     1718    $exps = parse_md_list($metadata) or
     1719        &my_die("Unable to parse metadata list", "$stage", $stage_id, $PS_EXIT_PROG_ERROR);
     1720
     1721    foreach my $exp (@$exps) {
     1722        my $exp_id = $exp->{exp_id};
     1723        my $iteration = $exp->{iteration};
     1724        my $path_base = $exp->{path_base};
     1725#       my $class_id  = $exp->{class_id}
     1726        my $status = 1;
     1727        # don't clean up unless the data needed to update is available
     1728        # goto_scrubbed now requires the config file to not be present
     1729        if ($mode eq "goto_cleaned") {
     1730            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base);
     1731           
     1732            if (!$config_file or ! -e $config_file) {
     1733                print STDERR "skipping cleanup for $stage $stage_id because config file is missing\n";
     1734                $status = 0;
     1735            }
     1736        }
     1737        elsif ($mode eq "goto_scrubbed") {
     1738            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base);
     1739           
     1740            if ($config_file and -e $config_file) {
     1741                print STDERR "skipping cleanup for $stage $stage_id because config file ($config_file) is present\n";
     1742                $status = 0;
     1743            }
     1744        }
     1745        if ($status) {
     1746            my @files = ();
     1747            # delete the temporary image datafiles
     1748            if ($mode eq "goto_purged") {
     1749                # additional files to remove for 'purge' mode
     1750                addFilename (\@files, "PPIMAGE.JPEG1", $path_base);#, $class_id);
     1751                addFilename (\@files, "PPIMAGE.JPEG2", $path_base);#, $class_id);
     1752            }
     1753            # actual command to delete the files
     1754            $status = &delete_files (\@files);
     1755        }
     1756       
     1757        if ($status)  {
     1758            my $command = "$dettool -updateresidexp -det_id $stage_id -exp_id $exp_id -iteration $iteration";
     1759            if ($mode eq "goto_cleaned") {
     1760                $command .= " -data_state cleaned";
     1761            }
     1762            if ($mode eq "goto_scrubbed") {
     1763                $command .= " -data_state scrubbed";
     1764            }
     1765            if ($mode eq "goto_purged") {
     1766                $command .= " -data_state purged";
     1767            }
     1768            $command .= " -dbname $dbname" if defined $dbname;
     1769            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1770                run(command => $command, verbose => $verbose);
     1771            unless ($success) {
     1772                print STDERR " residexp had an issue setting the state:? $success $error_code\n";
     1773                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1774                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1775            }
     1776        } else {
     1777            my $command = "$dettool -updateresidexp -det_id $stage_id -exp_id $exp_id -iteration $iteration -data_state $error_state";
     1778            $command .= " -dbname $dbname" if defined $dbname;
     1779           
     1780            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1781                run(command => $command, verbose => $verbose);
     1782            unless ($success) {
     1783                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1784                &my_die("Unable to perform dettool: $error_code", "$stage", $stage_id, $error_code);
     1785            }
     1786            exit $PS_EXIT_UNKNOWN_ERROR;
     1787        }
     1788    }
     1789    # Check to see if we can mark the whole detRunSummary object as cleaned.
     1790
     1791    $command = "$dettool -pendingcleanup_detrunsummary -det_id $stage_id";
     1792    $command .= " -dbname $dbname" if defined $dbname;
     1793    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1794    unless ($success) {
     1795        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1796        &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1797    }
     1798    if (@$stdout_buf != 0) {
     1799        $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     1800            &my_die("Unable to parse metadata config doc", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1801        $exps = parse_md_list($metadata) or
     1802            &my_die("Unable to parse metadata list", "$stage (detRunSummary)", $stage_id, $PS_EXIT_PROG_ERROR);
     1803       
     1804        foreach my $exp (@$exps) {
     1805            my $iteration = $exp->{iteration};
     1806            my $command;
     1807            if ($mode eq "goto_cleaned") {
     1808                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state cleaned";
     1809            }
     1810            if ($mode eq "goto_scrubbed") {
     1811                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state scrubbed";
     1812            }
     1813            if ($mode eq "goto_purged") {
     1814                $command = "$dettool -updatedetrunsummary -det_id $stage_id -iteration $iteration -data_state purged";
     1815            }
     1816            $command .= " -dbname $dbname" if defined $dbname;
     1817            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1818                run(command => $command, verbose => $verbose);
     1819            unless ($success) {
     1820                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1821                &my_die("Unable to perform dettool: $error_code", "$stage (detRunSummary)", $stage_id, $error_code);
     1822            }
     1823        }
     1824    }
     1825    exit 0;
     1826}
     1827
    5651828
    5661829die "ipp_cleanup.pl -stage $stage not yet implemented\n";
     
    5701833    my $files = shift; # reference to a list of files to unlink
    5711834
     1835#     open(TMPLOG,">>/tmp/czw.cleanup.log");
     1836#     flock(TMPLOG,2);
     1837
    5721838    # this script is, of course, very dangerous.
    5731839    foreach my $file (@$files) {
    5741840        print STDERR "unlinking $file\n";
     1841#       print TMPLOG "$stage $stage_id $file";
     1842#       my $ff = $file;
     1843#       $ff =~ s%^file://%%;
     1844#       unless (-e $ff) {
     1845#           print TMPLOG "\t File not found\n";
     1846#       }
     1847#       else {
     1848#           print TMPLOG "\n";
     1849#       }
     1850
    5751851        $ipprc->file_delete($file);
    5761852    }
     1853
     1854#     flock(TMPLOG,8);
     1855#     close(TMPLOG);
     1856
    5771857    return 1;
    5781858}
  • trunk/ippScripts/scripts/magic_destreak_revert.pl

  • trunk/ippScripts/scripts/stack_skycell.pl

    r23745 r25299  
    6565
    6666my $ipprc = PS::IPP::Config->new() or my_die( "Unable to set up", $stack_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
     67$| = 1;
     68print "I've set up: $stack_id\n";
    6769
    6870# XXX camera is not known here; cannot use filerules...
     
    107109&my_die("Stack list contains less than two elements", $stack_id, $PS_EXIT_SYS_ERROR) unless
    108110    scalar @$files >= 2;
     111
     112print "I've loaded my inputs: $stack_id\n";
    109113
    110114# Parse the list of input files to get the tesselation, skycell identifiers and camera
     
    146150}
    147151
     152print "I've configured everything: $stack_id\n";
     153
    148154# Generate MDC file with the inputs
    149155my $tess_base = basename($tess_id);
     
    180186    print $listFile "END\n\n";
    181187}
     188
     189print "I've checked everything: $stack_id\n";
    182190
    183191# Get the output filenames
     
    200208
    201209my $cmdflags;
     210
    202211
    203212# Perform stacking
     
    265274#       &my_die("Couldn't find expected output file: $bin2Name",    $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name);
    266275    }
    267 
     276   
     277    print "I've stacked $listName: $stack_id\n";
    268278}
    269279
     
    298308}
    299309
     310print "I've updated teh database: $stack_id\n";
     311
    300312
    301313my $my_die_called = 0;
     
    372384}
    373385
     386print "I've reached the end of processing with a code of $?: $stack_id\n";
    374387
    375388END {
  • trunk/ippTasks/Makefile.am

    r24929 r25299  
    1313        chip.pro \
    1414        camera.pro \
     15        addstar.pro \
    1516        fake.pro \
    1617        warp.pro \
  • trunk/ippTasks/pantasks.pro

    r24848 r25299  
    213213  chip.on
    214214  camera.on
     215  addstar.on
    215216  fake.on
    216217  warp.on
     
    225226  chip.off
    226227  camera.off
     228  addstar.off
    227229  fake.off
    228230  warp.off
     
    242244  module chip.pro
    243245  module camera.pro
     246  module addstar.pro
    244247  module fake.pro
    245248  module warp.pro
  • trunk/ippTasks/summit.copy.pro

    r24054 r25299  
    449449        end
    450450        if (("$MD5SUM" != "NULL") && ("$MD5SUM" != "0") && (not($COMPRESS)))
     451# && (($YEAR > 2008) || (("$YEAR" = "2007") && ($MONTH > 8))))
    451452            $run = $run --md5 $MD5SUM
    452453        end
  • trunk/ippTools/share/Makefile.am

    r25284 r25299  
    44
    55dist_pkgdata_DATA = \
     6     addtool_find_pendingexp.sql \
     7     addtool_queue_cam_id.sql \
     8     addtool_reset_faulted_runs.sql \
     9     addtool_revertprocessedexp.sql \
    610     camtool_donecleanup.sql \
    711     camtool_find_chip_id.sql \
  • trunk/ippTools/share/dettool_pendingcleanup_normalizedimfile.sql

    r19092 r25299  
    1 SELECT
     1SELECT DISTINCT
    22    detNormalizedImfile.*,
    33    detRunSummary.data_state
  • trunk/ippTools/share/dettool_pendingcleanup_stacked.sql

    r19092 r25299  
    1 SELECT
     1SELECT DISTINCT
    22    detStackedImfile.*,
    33    detRunSummary.data_state
  • trunk/ippTools/share/pxadmin_create_tables.sql

    r25256 r25299  
    451451) ENGINE=innodb DEFAULT CHARSET=latin1;
    452452
     453CREATE TABLE addRun (
     454    add_id BIGINT AUTO_INCREMENT,
     455    cam_id BIGINT,
     456    state VARCHAR(64),
     457    workdir VARCHAR(255),
     458    workdir_state VARCHAR(64),
     459    label VARCHAR(64),
     460    dvodb VARCHAR(255),
     461    magicked BIGINT,
     462    PRIMARY KEY(add_id),
     463    KEY(add_id),
     464    KEY(cam_id),
     465    KEY(state),
     466    KEY(workdir_state),
     467    KEY(label),
     468    INDEX(add_id, cam_id),
     469    FOREIGN KEY(cam_id) REFERENCES camRun(cam_id)
     470) ENGINE=innodb DEFAULT CHARSET=latin1;
     471
     472CREATE TABLE addProcessedExp (
     473    add_id BIGINT AUTO_INCREMENT,
     474    dtime_addstar FLOAT,
     475    n_stars INT,
     476    path_base VARCHAR(255),
     477    fault SMALLINT NOT NULL,
     478    PRIMARY KEY(add_id),
     479    FOREIGN KEY(add_id) REFERENCES addRun(add_id)
     480) ENGINE=innodb DEFAULT CHARSET=latin1;
     481
     482CREATE TABLE addMask (
     483    label VARCHAR(64),
     484    PRIMARY KEY(label)
     485) ENGINE=innodb DEFAULT CHARSET=latin1;
     486
    453487CREATE TABLE fakeRun (
    454488    fake_id BIGINT AUTO_INCREMENT,
     
    10861120        KEY(magic_id),
    10871121        KEY(label),
    1088         FOREIGN KEY(magic_id) REFERENCES magicRun(magic_id)
     1122        FOREIGN KEY(magic_id) REFERENCES magicRun(magic_id),
     1123        FOREIGN KEY(inv_magic_id) REFERENCES magicRun(magic_id)
    10891124        FOREIGN KEY(inv_magic_id) REFERENCES magicRun(magic_id)
    10901125) ENGINE=innodb DEFAULT CHARSET=latin1;
  • trunk/ippTools/share/pxadmin_drop_tables.sql

    r24531 r25299  
    1919DROP TABLE IF EXISTS detRun;
    2020DROP TABLE IF EXISTS detInputExp;
     21DROP TABLE IF EXISTS addRun;
     22DROP TABLE IF EXISTS addProcessedExp;
     23DROP TABLE IF EXISTS addMask;
    2124DROP TABLE IF EXISTS fakeRun;
    2225DROP TABLE IF EXISTS fakeProcessedImfile;
  • trunk/ippTools/src/Makefile.am

    r24512 r25299  
    11bin_PROGRAMS = \
     2        addtool \
    23        caltool \
    34        camtool \
     
    2829
    2930pkginclude_HEADERS = \
     31        pxadd.h \
    3032        pxadmin.h \
    3133        pxcam.h \
     
    4244
    4345noinst_HEADERS = \
     46        addtool.h \
    4447        caltool.h \
    4548        camtool.h \
     
    6871libpxtools_la_LDFLAGS   = -release $(PACKAGE_VERSION)
    6972libpxtools_la_SOURCES   = \
     73        pxadd.c \
    7074        pxcam.c \
    7175        pxchip.c \
     
    96100    pstamptool.c \
    97101    pstamptoolConfig.c
     102
     103addtool_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS)
     104addtool_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(IPPDB_LIBS) libpxtools.la
     105addtool_SOURCES = \
     106    addtool.c \
     107    addtoolConfig.c
    98108
    99109caltool_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS)
  • trunk/ippTools/src/camtool.c

    r24681 r25299  
    656656        return false;
    657657    }
     658
     659    if (!pxaddQueueByCamID(config,
     660                           pendingRow->cam_id,
     661                           pendingRow->workdir,
     662                           pendingRow->label,
     663                           pendingRow->reduction,
     664                           pendingRow->dvodb
     665    )) {
     666        // rollback
     667        if (!psDBRollback(config->dbh)) {
     668            psError(PS_ERR_UNKNOWN, false, "database error");
     669        }
     670        psError(PS_ERR_UNKNOWN, false, "failed to queue new addRun");
     671        psFree(pendingRow);
     672        return false;
     673    }
     674
    658675    psFree(pendingRow);
    659676
  • trunk/ippTools/src/dettoolConfig.c

    r24866 r25299  
    7070    psMetadataAddF64(definebytagArgs, PS_LIST_TAIL, "-sun_angle_min",  0,            "define min solar angle", NAN);
    7171    psMetadataAddF64(definebytagArgs, PS_LIST_TAIL, "-sun_angle_max",  0,            "define max solar angle", NAN);
     72
    7273
    7374    psMetadataAddTime(definebytagArgs, PS_LIST_TAIL, "-registered",  0,            "time detrend run was registered", now);
     
    138139    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-comment",                0,          "search by comment field (LIKE comparison)", NULL);
    139140
     141
     142    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_moon_angle_min",  0,          "define min moon angle", NAN);
     143    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_moon_angle_max",  0,          "define max moon angle", NAN);
     144    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_moon_alt_min",  0,            "define min moon alt", NAN);
     145    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_moon_alt_max",  0,            "define max moon alt", NAN);
     146    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_moon_phase_min",  0,          "define min moon phase", NAN);
     147    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_moon_phase_max",  0,          "define max moon phase", NAN);
     148    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-comment",                0,          "search by comment field (LIKE comparison)", NULL);
     149
    140150    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-pretend",  0,            "print the exposures that would be included in the detrend run and exit", false);
    141151    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-reduction",  0,            "define reduction class for processing", NULL);
  • trunk/ippTools/src/pxtools.h

    r24733 r25299  
    3737#include "pxtoolsErrorCodes.h"
    3838
     39#include "pxadd.h"
    3940#include "pxcam.h"
    4041#include "pxchip.h"
  • trunk/ippTools/src/regtool.c

    r24866 r25299  
    331331    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
    332332    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     333    PXOPT_LOOKUP_BOOL(ordered_by_date, config->args, "-ordered_by_date", false);
    333334
    334335    psString query = pxDataGet("regtool_processedimfile.sql");
     
    352353        // don't list faulted rows
    353354        psStringAppend(&query, " %s", "AND rawImfile.fault = 0");
     355    }
     356
     357    // add the ORDER BY statement if desired
     358    if (ordered_by_date) {
     359        psStringAppend(&query, " ORDER BY dateobs");
    354360    }
    355361
     
    923929    PXOPT_COPY_F64(config->args,   where,  "-posang_max", "posang", "<");
    924930    PXOPT_COPY_STR(config->args,   where,  "-object", "object", "==");
    925     PXOPT_COPY_F32(config->args,   where,  "-sun_angle_min", "sun_angle", ">=");
    926     PXOPT_COPY_F32(config->args,   where,  "-sun_angle_max", "sun_angle", "<");
     931    PXOPT_COPY_F32(config->args,   where,  "-solang_min", "solang", ">=");
     932    PXOPT_COPY_F32(config->args,   where,  "-solang_max", "solang", "<");
    927933
    928934    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
  • trunk/ippTools/src/warptool.c

    r24956 r25299  
    234234    PXOPT_COPY_F64(config->args,   where, "-posang_max",         "rawExp.posang",         "<");
    235235    PXOPT_COPY_STR(config->args,   where, "-object",             "rawExp.object",         "==");
    236     PXOPT_COPY_F32(config->args,   where, "-sun_angle_min",      "rawExp.sun_angle",      ">=");
    237     PXOPT_COPY_F32(config->args,   where, "-sun_angle_max",      "rawExp.sun_angle",      "<");
     236    PXOPT_COPY_F32(config->args,   where, "-solang_min",         "rawExp.solang",         ">=");
     237    PXOPT_COPY_F32(config->args,   where, "-solang_max",         "rawExp.solang",         "<");
    238238    PXOPT_COPY_STR(config->args,   where, "-reduction",          "fakeRun.reduction",     "==");
    239239    pxAddLabelSearchArgs (config,  where, "-label",             "fakeRun.label",         "==");
  • trunk/ippconfig/gpc1/format_20090220.config

    r24895 r25299  
    185185        FPA.ALT         STR     ALT
    186186        FPA.AZ          STR     AZ
    187         FPA.TEMP        STR     DETTEM
     187        # FPA.TEMP        STR     DETTEM
    188188        FPA.M1X         STR     M1X
    189189        FPA.M1Y         STR     M1Y   
     
    501501# How to translation PS concepts into database lookups
    502502DATABASE        METADATA
     503        # this rule is fragile : does not match the camera
     504        FPA.TEMP        STR     SELECT ccd_temp FROM rawExp WHERE dateobs >= '{FPA.DATE}' and abs(timediff(dateobs, cast('{FPA.TIME}' as datetime))) < 2
    503505END
    504506
  • trunk/ippconfig/recipes/masks.16bit.config

    r23498 r25299  
    2020
    2121# Mask values which represent non-astronomical structures
     22BURNTOOL        U16     0x0080          # Pixel may contain uncorrected streak.
    2223CR              U16     0x0100          # Pixel contains a cosmic ray
    2324SPIKE           U16     0x0200          # Pixel contains a diffraction spike
  • trunk/ippconfig/recipes/ppImage.config

    r24904 r25299  
    1616MASK.SATURATED     BOOL    TRUE            # Mask the saturated pixels
    1717MASK.LOW           BOOL    TRUE            # Mask pixels below valid range
     18MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
    1819VARIANCE.BUILD     BOOL    FALSE           # Build internal variance image
    1920PATTERN            BOOL    FALSE           # Fit and remove pattern noise?
     
    5455## if we use multithreaded detrending, detrend this number of rows per thread
    5556SCAN.ROWS        S32     100
     57
     58BURNTOOL.TRAILS U16 0x01
    5659
    5760# Non-linearity correction
  • trunk/ippconfig/recipes/psastro.config

    r24654 r25299  
    33PSASTRO.ONLY.REFSTARS      BOOL FALSE  # skip all but refstar matches
    44PSASTRO.SAVE.REFMATCH      BOOL FALSE  # save refstar matches as table in output smf file
     5
     6# select which WCS style to use on output images.
     7PSASTRO.WCS.USECDKEYS    BOOL FALSE
    58
    69# perform single-chip astrometry?
  • trunk/ppImage/src/Makefile.am

    r24229 r25299  
    5454        ppImageDefineFile.c \
    5555        ppImageSetMaskBits.c \
     56        ppImageBurntoolMask.c \
    5657        ppImageParityFlip.c \
    5758        ppImageCheckCTE.c \
  • trunk/ppImage/src/ppImage.h

    r24903 r25299  
    2626    bool doMaskBuild;                   // Build internal mask
    2727    bool doVarianceBuild;               // Build internal variance map
     28    bool doMaskBurntool;                // mask potential burntool trails
    2829    bool doMaskSat;                     // mask saturated pixels
    2930    bool doMaskLow;                     // mask low pixels
     
    7475    psImageMaskType darkMask;           // Mask value to give bad dark pixels
    7576    psImageMaskType blankMask;          // Mask value to give blank pixels
    76 
     77    psImageMaskType burntoolMask;       // Suspect pixels that fall where a burntool trail is expected.
    7778    // non-linear correction parameters
    7879    psDataType nonLinearType;
     
    8283    // options for the analysis
    8384    pmOverscanOptions *overscan;        // Overscan options
    84 
     85    int burntoolTrails;
    8586    // binning parameters
    8687    int xBin1;                          // x-binning, scale 1
     
    156157bool ppImageCheckCTE(pmConfig *config, ppImageOptions *options, pmFPAview *view);
    157158
     159bool ppImageBurntoolMask(pmConfig *config, ppImageOptions *options, pmFPAview *view, pmReadout *mask);
     160
    158161// Record which detrend file was used for the detrending
    159162bool ppImageDetrendRecord(
  • trunk/ppImage/src/ppImageDetrendReadout.c

    r24903 r25299  
    2626        pmMaskBadPixels(input, mask, options->maskValue);
    2727    }
     28    if (options->doMaskBurntool) {
     29      ppImageBurntoolMask(config,options,view,input);
     30    }
     31
    2832
    2933# if 0
  • trunk/ppImage/src/ppImageOptions.c

    r24903 r25299  
    2121    options->doMaskSat       = false;   // mask saturated pixels
    2222    options->doMaskLow       = false;   // mask low pixels
     23    options->doMaskBurntool  = false;   // mask potential burntool trails
    2324    options->doVarianceBuild = false;   // Build internal variance
    2425    options->doMask          = false;   // Mask bad pixels
     
    6465    options->blankMask       = 0x00;    // Blank (no data, cell gap) pixels (supplied to pmChipMosaic, pmFPAMosaic)
    6566    options->markValue       = 0x00;    // A safe bit for internal marking
    66 
     67    options->burntoolMask    = 0x00;    // Suspect pixels that fall where a burntool trail is expected.
     68    options->burntoolTrails  = 0x00;    // Which types of burntool areas to mask.
    6769    // crosstalk options
    6870    options->doCrosstalkMeasure = false;   // measure crosstalk
     
    219221    options->doMaskSat   = psMetadataLookupBool(NULL, recipe, "MASK.SATURATED");
    220222    options->doMaskLow   = psMetadataLookupBool(NULL, recipe, "MASK.LOW");
     223    options->doMaskBurntool = psMetadataLookupBool(NULL, recipe, "MASK.BURNTOOL");
    221224    options->doVarianceBuild = psMetadataLookupBool(NULL, recipe, "VARIANCE.BUILD");
    222225
     
    245248    options->applyParity = psMetadataLookupBool(NULL, recipe, "APPLY.CELL.PARITY");
    246249
     250    options->burntoolTrails = psMetadataLookupU16(&status, recipe, "BURNTOOL.TRAILS");
     251    if (!status) {
     252      psWarning("BURNTOOL.TRAILS not found in recipe: setting to default value.\n");
     253    }
     254   
    247255    // binned image options
    248256    options->xBin1 = psMetadataLookupS32(&status, recipe, "BIN1.XBIN");
    249257    if (!status) {
    250258        psWarning("BIN1.XBIN not found in recipe: setting to default value.\n");
     259        options->xBin1 = 4;
    251260    }
    252261    options->yBin1 = psMetadataLookupS32(&status, recipe, "BIN1.YBIN");
    253262    if (!status) {
    254263        psWarning("BIN1.YBIN not found in recipe: setting to default value.\n");
    255         options->yBin1 = 16;
     264        options->yBin1 = 4;
    256265    }
    257266
  • trunk/ppImage/src/ppImageSetMaskBits.c

    r24079 r25299  
    3838    psAssert (options->lowMask, "low mask not set");
    3939
     40    // mask for suspect regions due to burntool
     41    options->burntoolMask = pmConfigMaskGet("BURNTOOL",config);
     42    psAssert (options->burntoolMask, "burntool mask not set");
     43   
    4044    // save MASK and MARK on the PSPHOT recipe
    4145    psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
  • trunk/psModules/src/astrom/pmAstrometryWCS.c

    r24052 r25299  
    289289    // test the CDELTi varient
    290290    if (pcKeys) {
     291        wcs->wcsCDkeys = 0;
     292
    291293        wcs->cdelt1 = psMetadataLookupF64 (&status, header, "CDELT1");
    292294        wcs->cdelt2 = psMetadataLookupF64 (&status, header, "CDELT2");
     
    334336    // test the CDi_j varient
    335337    if (cdKeys) {
     338        wcs->wcsCDkeys = 1;
     339
    336340        wcs->trans->x->coeff[1][0] = psMetadataLookupF64 (&status, header, "CD1_1"); // == PC1_1
    337341        wcs->trans->x->coeff[0][1] = psMetadataLookupF64 (&status, header, "CD1_2"); // == PC1_2
     
    375379    // XXX make it optional to write out CDi_j terms, or other versions
    376380    // apply CDELT1,2 (degrees / pixel) to yield PCi,j terms of order unity
    377     double cdelt1 = wcs->cdelt1;
    378     double cdelt2 = wcs->cdelt2;
    379     psMetadataAddF64 (header, PS_LIST_TAIL, "CDELT1", PS_META_REPLACE, "", cdelt1);
    380     psMetadataAddF64 (header, PS_LIST_TAIL, "CDELT2", PS_META_REPLACE, "", cdelt2);
    381 
    382     // test the PC00i00j varient:
    383     psMetadataAddF64 (header, PS_LIST_TAIL, "PC001001", PS_META_REPLACE, "", wcs->trans->x->coeff[1][0] / cdelt1); // == PC1_1
    384     psMetadataAddF64 (header, PS_LIST_TAIL, "PC001002", PS_META_REPLACE, "", wcs->trans->x->coeff[0][1] / cdelt2); // == PC1_2
    385     psMetadataAddF64 (header, PS_LIST_TAIL, "PC002001", PS_META_REPLACE, "", wcs->trans->y->coeff[1][0] / cdelt1); // == PC2_1
    386     psMetadataAddF64 (header, PS_LIST_TAIL, "PC002002", PS_META_REPLACE, "", wcs->trans->y->coeff[0][1] / cdelt2); // == PC2_2
    387 
    388     // Elixir-style polynomial terms
    389     // XXX currently, Elixir/DVO cannot accept mixed orders
    390     // XXX need to respect the masks
    391     // XXX is wcs->cdelt1,2 always consistent?
    392     int fitOrder = wcs->trans->x->nX;
    393     if (fitOrder > 1) {
     381
     382    if (!(wcs->wcsCDkeys)) {
     383
     384      double cdelt1 = wcs->cdelt1;
     385      double cdelt2 = wcs->cdelt2;
     386      psMetadataAddF64 (header, PS_LIST_TAIL, "CDELT1", PS_META_REPLACE, "", cdelt1);
     387      psMetadataAddF64 (header, PS_LIST_TAIL, "CDELT2", PS_META_REPLACE, "", cdelt2);
     388     
     389      // test the PC00i00j varient:
     390      psMetadataAddF64 (header, PS_LIST_TAIL, "PC001001", PS_META_REPLACE, "", wcs->trans->x->coeff[1][0] / cdelt1); // == PC1_1
     391      psMetadataAddF64 (header, PS_LIST_TAIL, "PC001002", PS_META_REPLACE, "", wcs->trans->x->coeff[0][1] / cdelt2); // == PC1_2
     392      psMetadataAddF64 (header, PS_LIST_TAIL, "PC002001", PS_META_REPLACE, "", wcs->trans->y->coeff[1][0] / cdelt1); // == PC2_1
     393      psMetadataAddF64 (header, PS_LIST_TAIL, "PC002002", PS_META_REPLACE, "", wcs->trans->y->coeff[0][1] / cdelt2); // == PC2_2
     394     
     395      // Elixir-style polynomial terms
     396      // XXX currently, Elixir/DVO cannot accept mixed orders
     397      // XXX need to respect the masks
     398      // XXX is wcs->cdelt1,2 always consistent?
     399      int fitOrder = wcs->trans->x->nX;
     400      if (fitOrder > 1) {
    394401        for (int i = 0; i <= fitOrder; i++) {
    395             for (int j = 0; j <= fitOrder; j++) {
    396                 if (i + j < 2)
    397                     continue;
    398                 if (i + j > fitOrder)
    399                     continue;
    400                 sprintf (name, "PCA1X%1dY%1d", i, j);
    401                 psMetadataAddF64 (header, PS_LIST_TAIL, name, PS_META_REPLACE, "", wcs->trans->x->coeff[i][j] / pow(cdelt1, i) / pow(cdelt2, j));
    402                 sprintf (name, "PCA2X%1dY%1d", i, j);
    403                 psMetadataAddF64 (header, PS_LIST_TAIL, name, PS_META_REPLACE, "", wcs->trans->y->coeff[i][j] / pow(cdelt1, i) / pow(cdelt2, j));
    404             }
     402          for (int j = 0; j <= fitOrder; j++) {
     403            if (i + j < 2)
     404              continue;
     405            if (i + j > fitOrder)
     406              continue;
     407            sprintf (name, "PCA1X%1dY%1d", i, j);
     408            psMetadataAddF64 (header, PS_LIST_TAIL, name, PS_META_REPLACE, "", wcs->trans->x->coeff[i][j] / pow(cdelt1, i) / pow(cdelt2, j));
     409            sprintf (name, "PCA2X%1dY%1d", i, j);
     410            psMetadataAddF64 (header, PS_LIST_TAIL, name, PS_META_REPLACE, "", wcs->trans->y->coeff[i][j] / pow(cdelt1, i) / pow(cdelt2, j));
     411          }
    405412        }
    406413        psMetadataAddS32 (header, PS_LIST_TAIL, "NPLYTERM", PS_META_REPLACE, "", fitOrder);
    407     }
    408 
    409     // remove any existing 'CDi_j style' wcs keywords
    410     if (psMetadataLookup(header, "CD1_1")) {
     414      }
     415     
     416      // remove any existing 'CDi_j style' wcs keywords
     417      if (psMetadataLookup(header, "CD1_1")) {
    411418        psMetadataRemoveKey(header, "CD1_1");
    412419        psMetadataRemoveKey(header, "CD1_2");
    413420        psMetadataRemoveKey(header, "CD2_1");
    414421        psMetadataRemoveKey(header, "CD2_2");
     422      }
     423    }
     424    if (wcs->wcsCDkeys) {
     425      psMetadataAddF64 (header, PS_LIST_TAIL, "CD1_1", PS_META_REPLACE, "", wcs->trans->x->coeff[1][0]);
     426      psMetadataAddF64 (header, PS_LIST_TAIL, "CD1_2", PS_META_REPLACE, "", wcs->trans->x->coeff[0][1]);
     427      psMetadataAddF64 (header, PS_LIST_TAIL, "CD2_1", PS_META_REPLACE, "", wcs->trans->y->coeff[1][0]);
     428      psMetadataAddF64 (header, PS_LIST_TAIL, "CD2_2", PS_META_REPLACE, "", wcs->trans->y->coeff[0][1]);
     429
     430      if (psMetadataLookup(header, "PC001001")) {
     431        psMetadataRemoveKey(header, "PC001001");
     432        psMetadataRemoveKey(header, "PC001002");
     433        psMetadataRemoveKey(header, "PC002001");
     434        psMetadataRemoveKey(header, "PC002002");
     435      }
    415436    }
    416437
     
    535556        fpa->toSky->R -= 2.0*M_PI;
    536557
     558    fpa->wcsCDkeys = wcs->wcsCDkeys;
     559
    537560    psTrace ("psastro", 5, "toFPA: %f %f  (%f,%f),(%f,%f)\n",
    538561             chip->toFPA->x->coeff[0][0], chip->toFPA->y->coeff[0][0],
     
    682705    wcs->cdelt2 = hypot (wcs->trans->y->coeff[1][0], wcs->trans->y->coeff[0][1]);
    683706
     707    wcs->wcsCDkeys = fpa->wcsCDkeys;
    684708    psFree (toTPA);
    685709
     
    922946    wcs->trans = psPlaneTransformAlloc (nXorder, nYorder);
    923947    wcs->toSky = NULL;
     948    wcs->wcsCDkeys = 0;
    924949
    925950    memset (wcs->ctype1, 0, PM_ASTROM_WCS_TYPE_SIZE);
  • trunk/psModules/src/astrom/pmAstrometryWCS.h

    r24766 r25299  
    2323    double crpix1, crpix2;
    2424    double cdelt1, cdelt2;
     25    bool wcsCDkeys;
    2526    psProjection *toSky;
    2627    psPlaneTransform *trans;
  • trunk/psModules/src/camera/pmFPA.h

    r21363 r25299  
    4848    psPlaneTransform *toTPA;  ///< Transformation from focal plane to tangent plane, or NULL
    4949    psProjection *toSky;         ///< Projection from tangent plane to sky, or NULL
     50    bool wcsCDkeys;
    5051    // Information
    5152    psMetadata *concepts;               ///< FPA-level concepts
  • trunk/psModules/src/camera/pmReadoutFake.c

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/psastro/src/psastroChipAstrom.c

    r24036 r25299  
    9797                // write the elapsed time here; this will be updated in psastroMosaicAstrometry, if called
    9898                psMetadataAddF32 (updates, PS_LIST_TAIL, "DT_ASTR", PS_META_REPLACE, "elapsed psastro time", psTimerMark ("psastroAnalysis"));
    99 
     99               
     100                fpa->wcsCDkeys = psMetadataLookupBool(&status, recipe , "PSASTRO.WCS.USECDKEYS");
    100101                pmAstromWriteWCS (updates, fpa, chip, NONLIN_TOL);
    101102
  • trunk/tools/ipp_apply_burntool.pl

    r24859 r25299  
    172172
    173173        if ($RAWTABLES) {
    174             $status = vsystem ("$burntool $tmpImfileReal out=$artImfileReal $prevFileOpt", $REALRUN);
     174            $status = vsystem ("$burntool $tmpImfileReal out=$artImfileReal $prevFileOpt persist=t", $REALRUN);
    175175        } else {
    176             $status = vsystem ("$burntool $tmpImfileReal $prevFileOpt", $REALRUN);
     176            $status = vsystem ("$burntool $tmpImfileReal $prevFileOpt persist=t", $REALRUN);
    177177        }
    178178        if ($status) {
Note: See TracChangeset for help on using the changeset viewer.