IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42229


Ignore:
Timestamp:
Jun 30, 2022, 3:42:01 PM (4 years ago)
Author:
tdeboer
Message:

Modify code to allow high FWHM image to progress to warp, and not be queued for wwdiffs

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/camera_exp.pl

    r42155 r42229  
    178178
    179179    # Determine if FWHM is too large to bother continuing.
    180     my $maxFWHM = metadataLookupF32($recipeData, 'PSASTRO.MAX.ALLOWED.FWHM');
     180    my $maxFWHM = metadataLookupF32($recipeData, 'PSASTRO.MAX.PROCESS.FWHM');
    181181    if ($maxFWHM) {
    182182        my $expFWHM;
  • trunk/ippScripts/scripts/nightly_science.pl

    r42155 r42229  
    142142my %unique_filter_hash = ();
    143143
     144#set up the camera config
     145my $ipprcam = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up camera", $PS_EXIT_CONFIG_ERROR ); # IPP camera configuration
     146
    144147# Grab the configuration data.
    145148my $conf_cmd = "$ppConfigDump -camera $camera -dump-recipe NIGHTLY_SCIENCE -";
     
    155158foreach my $entry (@{ $metadata }) {
    156159    if (@{ $entry }{name} eq 'CLEAN_MODES') {
    157         my @mode_data = @{ ${ $entry }{value} };
    158         my $this_mode = '';
    159         foreach my $mentry (@mode_data) {
    160             if (${ $mentry }{name} eq 'MODE') {
    161                 $this_mode = ${ $mentry }{value};
    162             }
    163             elsif (${ $mentry }{name} eq 'COMMAND') {
    164                 $clean_config{$this_mode}{COMMAND} = ${ $mentry }{value};
    165             }
    166             elsif (${ $mentry }{name} eq 'RETENTION_TIME') {
    167                 $clean_config{$this_mode}{RETENTION_TIME} = ${ $mentry }{value};
    168             }
    169         }
     160        my @mode_data = @{ ${ $entry }{value} };
     161        my $this_mode = '';
     162        foreach my $mentry (@mode_data) {
     163            if (${ $mentry }{name} eq 'MODE') {
     164                $this_mode = ${ $mentry }{value};
     165            }
     166            elsif (${ $mentry }{name} eq 'COMMAND') {
     167                $clean_config{$this_mode}{COMMAND} = ${ $mentry }{value};
     168            }
     169            elsif (${ $mentry }{name} eq 'RETENTION_TIME') {
     170                $clean_config{$this_mode}{RETENTION_TIME} = ${ $mentry }{value};
     171            }
     172        }
    170173    }
    171174    elsif (${ $entry }{name} eq 'FILTERS') {
    172         $unique_filter_hash{ ${ $entry }{value} } = 1;
     175        $unique_filter_hash{ ${ $entry }{value} } = 1;
    173176#        push @filter_list, ${ $entry }{value};
    174177    }
     
    177180    }
    178181    elsif (${ $entry }{name} eq 'MACRO_DEFINITIONS') {
    179         my @macro_data = @{ ${ $entry }{value} };
    180         my $this_mode = '';
    181         foreach my $mentry (@macro_data) {
    182             if (${ $mentry }{name} eq 'PROC_MODE') {
    183                 $this_mode = ${ $mentry }{value};
    184             }
    185             elsif (${ $mentry }{name} eq 'MACRO') {
    186                 $macro_config{$this_mode} = ${ $mentry }{value};
    187             }
    188         }
     182        my @macro_data = @{ ${ $entry }{value} };
     183        my $this_mode = '';
     184        foreach my $mentry (@macro_data) {
     185            if (${ $mentry }{name} eq 'PROC_MODE') {
     186                $this_mode = ${ $mentry }{value};
     187            }
     188            elsif (${ $mentry }{name} eq 'MACRO') {
     189                $macro_config{$this_mode} = ${ $mentry }{value};
     190            }
     191        }
    189192    }
    190193    elsif (${ $entry }{name} eq 'TARGETS') {
     
    194197            if (${ $tentry }{name} eq 'NAME') {
    195198                $this_target = ${ $tentry }{value};
    196                 $science_config{$this_target}{DISTRIBUTION} = $this_target; # Set the default dist_group
    197             }
    198             else {
    199                 $science_config{$this_target}{ ${ $tentry }{name} } = ${ $tentry }{value};
    200             }
     199                $science_config{$this_target}{DISTRIBUTION} = $this_target; # Set the default dist_group
     200            }
     201            else {
     202                $science_config{$this_target}{ ${ $tentry }{name} } = ${ $tentry }{value};
     203            }
    201204        }
    202205    }
    203206    elsif (${ $entry }{name} eq 'DETRENDS') {
    204         my @detrend_data = @{ ${ $entry }{value} };
    205         my $this_detrend = '';
    206         foreach my $dentry (@detrend_data) {
    207             if (${ $dentry }{name} eq 'NAME') {
    208                 $this_detrend = ${ $dentry }{value};
    209             }
    210             else {
    211                 $detrend_config{$this_detrend}{ ${ $dentry }{name} } = ${ $dentry }{value};
    212             }
    213         }
    214     }           
     207        my @detrend_data = @{ ${ $entry }{value} };
     208        my $this_detrend = '';
     209        foreach my $dentry (@detrend_data) {
     210            if (${ $dentry }{name} eq 'NAME') {
     211                $this_detrend = ${ $dentry }{value};
     212            }
     213            else {
     214                $detrend_config{$this_detrend}{ ${ $dentry }{name} } = ${ $dentry }{value};
     215            }
     216        }
     217    }           
    215218    elsif (${ $entry }{name} eq 'END_OF_NIGHT') {
    216         my @eon_data = @{ ${ $entry }{value} };
    217         my $this_eon = '';
    218         foreach my $tentry (@eon_data) {
    219             if (${ $tentry }{name} eq 'NAME') {
    220                 $this_eon = ${ $tentry }{value};
    221             }
    222             else {
    223                 $eon_config{$this_eon}{ ${ $tentry }{name} } = ${ $tentry }{value};
    224             }
    225         }
     219        my @eon_data = @{ ${ $entry }{value} };
     220        my $this_eon = '';
     221        foreach my $tentry (@eon_data) {
     222            if (${ $tentry }{name} eq 'NAME') {
     223                $this_eon = ${ $tentry }{value};
     224            }
     225            else {
     226                $eon_config{$this_eon}{ ${ $tentry }{name} } = ${ $tentry }{value};
     227            }
     228        }
    226229    }
    227230}
     
    231234    my $time;
    232235    if ($date =~ / /) {
    233         ($date,$time) = split / /, $date;
     236        ($date,$time) = split / /, $date;
    234237    }
    235238    elsif ($date =~ /T/) {
    236         ($date,$time) = split /T/, $date;
     239        ($date,$time) = split /T/, $date;
    237240    }
    238241    my ($year,$month,$day) = split /-/, $date;
    239242    if (defined($time)) {
    240         my ($hour,$min,$sec) = split /\:/, $time; #/;
    241         $datetime = DateTime->new( year => $year,
    242                                    month => $month,
    243                                    day => $day,
    244                                    hour => $hour,
    245                                    min => $min,
    246                                    second => $sec,
    247                                    time_zone => 'UTC');
     243        my ($hour,$min,$sec) = split /\:/, $time; #/;
     244        $datetime = DateTime->new( year => $year,
     245                                   month => $month,
     246                                   day => $day,
     247                                   hour => $hour,
     248                                   min => $min,
     249                                   second => $sec,
     250                                   time_zone => 'UTC');
    248251    }
    249252    else {
    250         $datetime = DateTime->now(time_zone => 'UTC');
    251         $datetime->set_year($year);
    252         $datetime->set_day($day);
    253         $datetime->set_month($month);
    254     }
    255 }    
     253        $datetime = DateTime->now(time_zone => 'UTC');
     254        $datetime->set_year($year);
     255        $datetime->set_day($day);
     256        $datetime->set_month($month);
     257    }
     258}   
    256259else {
    257260    $datetime = DateTime->now(time_zone => 'UTC'); # time_zone   => 'Pacific/Honolulu');
     
    263266    foreach my $t (keys %science_config) {
    264267        if ($t ne $this_target_only) {
    265             undef($science_config{$t});
     268            undef($science_config{$t});
    266269        }
    267270    }
     
    282285    foreach my $t (keys %clean_config) {
    283286        if ($t ne $this_mode_only) {
    284             undef($clean_config{$t});
     287            undef($clean_config{$t});
    285288        }
    286289    }
     
    295298
    296299if (defined($desdiffdt) == 0) {
    297         $desdiffdt = 1.5;
     300        $desdiffdt = 1.5;
    298301}
    299302
    300303#Build in a safety for desdiffdt
    301304if ((defined($desdiffdt) == 1) && ($desdiffdt <= 0.5)) {
    302         $desdiffdt = 0.5;
     305        $desdiffdt = 0.5;
    303306}
    304307
     
    312315    my $v;
    313316    foreach $z (sort (keys %science_config)) {
    314         foreach $v (keys %{ $science_config{$z} }) {
    315             print "SCIENCE: $z $v $science_config{$z}{$v}\n";
    316         }
     317        foreach $v (keys %{ $science_config{$z} }) {
     318            print "SCIENCE: $z $v $science_config{$z}{$v}\n";
     319        }
    317320    }
    318321    foreach $z (sort (keys %detrend_config)) {
    319         foreach $v (keys %{ $detrend_config{$z} }) {
    320             print "DETREND: $z $v $detrend_config{$z}{$v}\n";
    321         }
     322        foreach $v (keys %{ $detrend_config{$z} }) {
     323            print "DETREND: $z $v $detrend_config{$z}{$v}\n";
     324        }
    322325    }
    323326    foreach $z (keys (%clean_config)) {
    324         foreach $v (keys %{ $clean_config{$z} }) {
    325             print "CLEAN: $z $v $clean_config{$z}{$v}\n";
    326         }
     327        foreach $v (keys %{ $clean_config{$z} }) {
     328            print "CLEAN: $z $v $clean_config{$z}{$v}\n";
     329        }
    327330    }
    328331    foreach $z (@filter_list) {
    329         print "FILTER: $z\n";
     332        print "FILTER: $z\n";
    330333    }
    331334    foreach $z (keys (%macro_config)) {
    332         print "MACROS: $z $macro_config{$z}\n";
     335        print "MACROS: $z $macro_config{$z}\n";
    333336    }
    334337}
     
    397400    &execute_stacks($date,$metadata_out{nsObservingState});
    398401    if ($metadata_out{nsStackState} eq 'QUEUESTACKING') {
    399         $metadata_out{nsStackState} = 'STACKING_POSSIBLE_ERROR';
     402        $metadata_out{nsStackState} = 'STACKING_POSSIBLE_ERROR';
    400403    }
    401404    return_metadata($date);
     
    416419    &execute_diffs($date,$metadata_out{nsObservingState});
    417420    if ($metadata_out{nsDiffState} eq 'QUEUESTACKING') {
    418         $metadata_out{nsDiffState} = 'STACKING_POSSIBLE_ERROR';
     421        $metadata_out{nsDiffState} = 'STACKING_POSSIBLE_ERROR';
    419422    }
    420423    return_metadata($date);
     
    481484        my ($exp_name,$registered,$dateobs,$imfiles,$summit_fault,
    482485            $download_state,$download_count,$new_state,$exp_id,$exp_type) = @{ $row_ref };
    483         $Nsummit_imfiles += $imfiles;
    484         $Ndownload_imfiles += $download_count;
     486        $Nsummit_imfiles += $imfiles;
     487        $Ndownload_imfiles += $download_count;
    485488        $Nsummit_exps++;
    486489        if ($summit_fault) {
    487             print STDERR "check_summit_copy: $date $exp_name has summit_fault $summit_fault";
     490            print STDERR "check_summit_copy: $date $exp_name has summit_fault $summit_fault";
    488491            if (($exp_type ne 'OBJECT')||($exp_name =~ /^c.*/)) {
    489492                print STDERR " (but I don't care).\n";
     
    526529    }
    527530    elsif ($Ndownload_imfiles != $Nsummit_imfiles) {
    528         print STDERR "Not done downloading from the summit for $date (Summit: $Nsummit_imfiles, Downloaded: $Ndownload_imfiles)\n";
    529         $metadata_out{nsRegState} = 'NEW';
     531        print STDERR "Not done downloading from the summit for $date (Summit: $Nsummit_imfiles, Downloaded: $Ndownload_imfiles)\n";
     532        $metadata_out{nsRegState} = 'NEW';
    530533    }
    531534    else {
     
    615618    }
    616619    if (defined($reduction)) {
    617         $cmd .= " -set_reduction $reduction ";
     620        $cmd .= " -set_reduction $reduction ";
    618621    }
    619622    $cmd .= " $select ";
     
    674677
    675678    foreach my $target (sort (keys %science_config)) {
    676         my ($Nexposures,$Nimfiles,$Nburntooled,$Nalready) = check_chip_status($date,$target);
    677         print "BTSTATS: $date $target $Nexposures $Nimfiles $Nburntooled $Nalready\n";
     679        my ($Nexposures,$Nimfiles,$Nburntooled,$Nalready) = check_chip_status($date,$target);
     680        print "BTSTATS: $date $target $Nexposures $Nimfiles $Nburntooled $Nalready\n";
    678681    }
    679682}
     
    695698    $cmd .= " -set_label dqstats.nightlyscience ";
    696699    if ($debug == 1) {
    697         $cmd .= ' -pretend ';
     700        $cmd .= ' -pretend ';
    698701    }
    699702    print STDERR "$cmd\n";
     
    703706sub pre_dqstats_queue {
    704707    my $date = shift;
    705     
     708   
    706709    my $command = construct_dqstats_cmd($date) . ' -pretend ';
    707710    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    711714        &my_die("Unable to perform dqstatstool: $error_code",1,1,,$date, $PS_EXIT_SYS_ERROR);
    712715    }
    713     
     716   
    714717    my @input_exposures = split /\n/, (join '', @$stdout_buf);
    715718
     
    735738    my ($Nexposures,$Nchips,$Ncams) = pre_dqstats_queue($date);
    736739    if ($Nexposures == 0) {
    737         print STDERR "execute_dqstats: No exposures on date $date.\n";
     740        print STDERR "execute_dqstats: No exposures on date $date.\n";
    738741    }
    739742    elsif ($Ncams != $Nchips) {
    740         print STDERR "execute_dqstats: Not done processing data through camera stage.\n";
     743        print STDERR "execute_dqstats: Not done processing data through camera stage.\n";
    741744    }
    742745    else {
    743         unless(defined($pretend)) {
    744             dqstats_queue($date);
    745         }
    746         if (defined($pretend)) {
    747             add_to_macro_list('check_dqstats',1,$date);
    748         }
    749         else {
    750             add_to_macro_list('queue_dqstats',1,$date);
    751         }
     746        unless(defined($pretend)) {
     747            dqstats_queue($date);
     748        }
     749        if (defined($pretend)) {
     750            add_to_macro_list('check_dqstats',1,$date);
     751        }
     752        else {
     753            add_to_macro_list('queue_dqstats',1,$date);
     754        }
    752755    }
    753756}   
     
    761764
    762765    my ($label,$workdir,$filter,$exp_type,$det_type,$ref_det_id,$ref_iter,$maxN) = get_dettool_parameters($date,$target);
    763     
     766   
    764767    my $select = "-select_dateobs_begin ${date}T00:00:00 -select_dateobs_end ${date}T23:59:59 ";
    765768    my $use_limits = " -use_begin ${date}T00:00:00 -use_end ${date}T23:59:59 ";
     
    778781    $cmd .= " $use_limits ";
    779782    if ($maxN > 0) {
    780         $cmd .= " -random_subset -random_limit $maxN ";
     783        $cmd .= " -random_subset -random_limit $maxN ";
    781784    }
    782785    if ($debug == 1) {
    783         $cmd .= ' -pretend ';
     786        $cmd .= ' -pretend ';
    784787    }
    785788    print STDERR "$cmd\n";
    786789    return($cmd);
    787 }    
     790}   
    788791
    789792sub verify_uniqueness_detverify {
     
    792795
    793796    my ($label,$workdir,$filter,$exp_type,$det_type,$ref_det_id,$ref_iter,$maxN) = get_dettool_parameters($date,$target);
    794     
     797   
    795798    my $db = init_gpc_db();
    796799    my $sth = "SELECT * FROM detRun WHERE workdir = '$workdir' AND ref_det_id = $ref_det_id AND ref_iter = $ref_iter";
     
    803806    my $date = shift;
    804807    my $target = shift;
    805     
     808   
    806809    my $command = construct_dettool_cmd($date,$target) . ' -pretend ';
    807810    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    808         run ( command => $command, verbose => $verbose);
     811        run ( command => $command, verbose => $verbose);
    809812    unless ($success) {
    810         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    811         &my_die("Unable to perform dettool: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR);
    812     }
    813     
     813        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     814        &my_die("Unable to perform dettool: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR);
     815    }
     816   
    814817    my @input_exposures = split /\n/, (join '', @$stdout_buf);
    815818    return($#input_exposures + 1);
     
    819822    my $date = shift;
    820823    my $target = shift;
    821     
     824   
    822825    my $command = construct_dettool_cmd($date,$target);
    823826    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    824         run ( command => $command, verbose => $verbose);
     827        run ( command => $command, verbose => $verbose);
    825828    unless ($success) {
    826         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    827         &my_die("Unable to perform chiptool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     829        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     830        &my_die("Unable to perform chiptool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    828831    }
    829832    $metadata_out{nsDetState} = 'DETREND_QUEUED';
     
    836839    my $exposures = 0;
    837840    foreach my $target (sort (keys %detrend_config)) {
    838         my ($Nexposures) = pre_detrend_queue($date,$target);
    839         if ($Nexposures == 0) {
    840             print STDERR "execute_detrends: Target $target on $date had no exposures.\n";
    841             next;
    842         }
    843         $exposures++;
    844         unless(defined($pretend)) {
    845             detrend_queue($date,$target);
    846         }
    847         if (defined($pretend)) {
    848             add_to_macro_list('check_detrends',1,$date,$target,"dettool");
    849         }
    850         else {
    851             add_to_macro_list('queue_detrends',1,$date,$target,"dettool");
    852         }
     841        my ($Nexposures) = pre_detrend_queue($date,$target);
     842        if ($Nexposures == 0) {
     843            print STDERR "execute_detrends: Target $target on $date had no exposures.\n";
     844            next;
     845        }
     846        $exposures++;
     847        unless(defined($pretend)) {
     848            detrend_queue($date,$target);
     849        }
     850        if (defined($pretend)) {
     851            add_to_macro_list('check_detrends',1,$date,$target,"dettool");
     852        }
     853        else {
     854            add_to_macro_list('queue_detrends',1,$date,$target,"dettool");
     855        }
    853856    }
    854857    if ($exposures == 0) {
    855         $metadata_out{nsDetState} = 'DETREND_DROP';
     858        $metadata_out{nsDetState} = 'DETREND_DROP';
    856859    }
    857860    if (($metadata_out{nsDetState} eq 'CHECKDETRENDS') && ($exposures > 0)) {
    858         $metadata_out{nsDetState} eq 'QUEUEDETRENDS';
     861        $metadata_out{nsDetState} eq 'QUEUEDETRENDS';
    859862    }
    860863}
     
    882885#     $cmd .= " $select ";
    883886#     if ($debug == 1) {
    884 #       $cmd .= ' -pretend ';
     887#       $cmd .= ' -pretend ';
    885888#     }
    886889#     print STDERR "$cmd\n";
     
    895898
    896899    my $dt = DateTime->new(year => $year, month => $month, day => $day,
    897                            hour => 0, minute => 0, second => 0, nanosecond => 0,
    898                            time_zone => 'Pacific/Honolulu');
     900                           hour => 0, minute => 0, second => 0, nanosecond => 0,
     901                           time_zone => 'Pacific/Honolulu');
    899902    do {
    900         $dt->add(days => 1);
    901         my $ymd = $dt->ymd;
    902         my $md_cmd = "moondata $ymd 0 0";
    903         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    904             run ( command => $md_cmd, verbose => $verbose);
    905         unless ($success) {
    906             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    907             &my_die("Unable to perform moondata: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR);
    908         }
    909         my @result = split /\s+/,(join "\n", @$stdout_buf);
    910         if (abs($result[6]) <= 0.6) {
    911             $dateobs_end = $ymd;
    912         }
     903        $dt->add(days => 1);
     904        my $ymd = $dt->ymd;
     905        my $md_cmd = "moondata $ymd 0 0";
     906        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     907            run ( command => $md_cmd, verbose => $verbose);
     908        unless ($success) {
     909            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     910            &my_die("Unable to perform moondata: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR);
     911        }
     912        my @result = split /\s+/,(join "\n", @$stdout_buf);
     913        if (abs($result[6]) <= 0.6) {
     914            $dateobs_end = $ymd;
     915        }
    913916    } while (!defined($dateobs_end));
    914     
     917   
    915918    do {
    916         $dt->subtract(days => 1);
    917         my $ymd = $dt->ymd;
    918         my $md_cmd = "moondata $ymd 0 0";
    919         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    920             run ( command => $md_cmd, verbose => $verbose);
    921         unless ($success) {
    922             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    923             &my_die("Unable to perform moondata: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR);
    924         }
    925         my @result = split /\s+/,(join "", @$stdout_buf);
    926         if (abs($result[6]) <= 0.6) {
    927             $dateobs_begin = $ymd;
    928         }
     919        $dt->subtract(days => 1);
     920        my $ymd = $dt->ymd;
     921        my $md_cmd = "moondata $ymd 0 0";
     922        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     923            run ( command => $md_cmd, verbose => $verbose);
     924        unless ($success) {
     925            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     926            &my_die("Unable to perform moondata: $error_code", 0,0, $date, $PS_EXIT_SYS_ERROR);
     927        }
     928        my @result = split /\s+/,(join "", @$stdout_buf);
     929        if (abs($result[6]) <= 0.6) {
     930            $dateobs_begin = $ymd;
     931        }
    929932    } while (!defined($dateobs_begin));
    930        
     933       
    931934    return($dateobs_begin,$dateobs_end);
    932935}
    933936
    934 # sub pre_sweetspot_queue { 
     937# sub pre_sweetspot_queue {
    935938#     my $date = shift;
    936939#     my $command = construct_sweetspot_cmd($date) . ' -pretend ';
    937940#     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    938 #       run ( command => $command, verbose => $verbose );
     941#       run ( command => $command, verbose => $verbose );
    939942#     unless ($success) {
    940943#         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     
    943946#     my @stacks = split /\n/, (join '', @$stdout_buf);
    944947#     my $Nstacks = $#stacks + 1;
    945         
     948       
    946949#     return(1,$Nstacks);
    947950# }
     
    951954#     my $command = construct_sweetspot_cmd($date);
    952955#     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    953 #       run ( command => $command, verbose => $verbose );
     956#       run ( command => $command, verbose => $verbose );
    954957#     unless ($success) {
    955958#         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     
    958961#     my @stacks = split /\n/, (join '', @$stdout_buf);
    959962#     my $Nstacks = $#stacks + 1;
    960     
     963   
    961964#     return(1,$Nstacks);
    962965# }
    963966
    964 # sub execute_sweetspot {    
     967# sub execute_sweetspot {   
    965968#     my $date = shift;
    966969#     my $pretend = shift;
    967     
     970   
    968971#     my ($is_lunation_date,$Nstacks) = pre_sweetspot_queue($date);
    969972#     if ($Nstacks == 0) {
    970 #       print STDERR "execute_sweetspot: No new stacks to make ($Nstacks)\n";
    971 #       $metadata_out{nsSSState} = 'SS_EMPTY';
    972 #       return();
     973#       print STDERR "execute_sweetspot: No new stacks to make ($Nstacks)\n";
     974#       $metadata_out{nsSSState} = 'SS_EMPTY';
     975#       return();
    973976#     }
    974977#     if ($Nstacks < 10) {
    975 #       print STDERR "execute_sweetspot: Too few new stacks to make ($Nstacks)\n";
    976 #       $metadata_out{nsSSState} = 'SS_FEW';
    977 #       return();
     978#       print STDERR "execute_sweetspot: Too few new stacks to make ($Nstacks)\n";
     979#       $metadata_out{nsSSState} = 'SS_FEW';
     980#       return();
    978981#     }
    979982#     if ($is_lunation_date == 0) {
    980 #       print STDERR "execute_sweetspot: Invalid lunation date. ($date $is_lunation_date)\n";
    981 #       $metadata_out{nsSSState} = 'SS_ERROR';
    982 #       return();
     983#       print STDERR "execute_sweetspot: Invalid lunation date. ($date $is_lunation_date)\n";
     984#       $metadata_out{nsSSState} = 'SS_ERROR';
     985#       return();
    983986#     }
    984987#     $metadata_out{nsSSState} = 'SS_QUEUE';
    985988#     $metadata_out{nsSweetSpot} = $Nstacks;
    986989#     unless(defined($pretend)) {
    987 #       $metadata_out{nsSSState} = 'SS_DONE';
    988 #       sweetspot_queue($date);
     990#       $metadata_out{nsSSState} = 'SS_DONE';
     991#       sweetspot_queue($date);
    989992#     }
    990993#     if (defined($pretend)) {
    991 #       add_to_macro_list('check_sweetspot',1,$date);
     994#       add_to_macro_list('check_sweetspot',1,$date);
    992995#     }
    993996#     else {
    994 #       add_to_macro_list('queue_sweetspot',1,$date);
     997#       add_to_macro_list('queue_sweetspot',1,$date);
    995998#     }
    996999# }
     
    10201023    $cmd .= " -select_good_frac_min 0.05";
    10211024    if (defined($reduction)) {
    1022         $cmd .= " -set_reduction $reduction ";
     1025        $cmd .= " -set_reduction $reduction ";
    10231026    }
    10241027    else {
    1025         $cmd .= " -set_reduction NIGHTLY_STACK ";
     1028        $cmd .= " -set_reduction NIGHTLY_STACK ";
    10261029    }
    10271030    if (defined($science_config{$target}{ADDITIONAL_STACK_LABEL})) {
    1028         # Grab list of skycells
    1029         my $skycell_select = '';
    1030         {
    1031             my %skycells = ();
    1032             my $warpcmd = "$warptool -warped -label $label -data_group $data_group  -dbname $dbname";
    1033             my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) =
    1034                 run(command => $warpcmd, verbose => $verbose);
    1035             unless($success) {
    1036                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    1037                 &my_die("Unabel to perform warptool -warped to determine skycell_ids: $error_code",$target);
    1038             }
    1039             my $runs = $mdcParser->parse_list(join "", @$stdout_buf) or
    1040                 &my_die("Unabel to parse warptool -warped to determine skycell_ids: $error_code",$target);
    1041             if ($#{ $runs } != -1) {
    1042                 for my $warp (@$runs) {
    1043                     $skycells{$warp->{skycell_id}} = 1;
    1044                 }
    1045                 foreach my $skycell (sort (keys (%skycells))) {
    1046                     $skycell_select .= " -select_skycell_id $skycell ";
    1047                 }
    1048                 $cmd .= " -select_label $science_config{$target}{ADDITIONAL_STACK_LABEL} $skycell_select ";
    1049             }
    1050         }
     1031        # Grab list of skycells
     1032        my $skycell_select = '';
     1033        {
     1034            my %skycells = ();
     1035            my $warpcmd = "$warptool -warped -label $label -data_group $data_group  -dbname $dbname";
     1036            my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) =
     1037                run(command => $warpcmd, verbose => $verbose);
     1038            unless($success) {
     1039                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1040                &my_die("Unabel to perform warptool -warped to determine skycell_ids: $error_code",$target);
     1041            }
     1042            my $runs = $mdcParser->parse_list(join "", @$stdout_buf) or
     1043                &my_die("Unabel to parse warptool -warped to determine skycell_ids: $error_code",$target);
     1044            if ($#{ $runs } != -1) {
     1045                for my $warp (@$runs) {
     1046                    $skycells{$warp->{skycell_id}} = 1;
     1047                }
     1048                foreach my $skycell (sort (keys (%skycells))) {
     1049                    $skycell_select .= " -select_skycell_id $skycell ";
     1050                }
     1051                $cmd .= " -select_label $science_config{$target}{ADDITIONAL_STACK_LABEL} $skycell_select ";
     1052            }
     1053        }
    10511054    }
    10521055    $cmd .= " $select ";
     
    10901093    my $where_possibly_faulted = $where . " AND ( " ;
    10911094    foreach my $acceptable_quality (@unrecoverable_quality) {
    1092         $where_possibly_faulted .= " quality = $acceptable_quality OR ";
     1095        $where_possibly_faulted .= " quality = $acceptable_quality OR ";
    10931096    }
    10941097    $where_possibly_faulted .= " 0 )";
     
    11191122        $Nalready += $trash[0];
    11201123    }
    1121     
     1124   
    11221125    my $minimum_required_warp;
    11231126    if ($observing_state eq 'OBSERVING') {
    1124         $minimum_required_warp = $science_config{$target}{MIN_STACK};
     1127        $minimum_required_warp = $science_config{$target}{MIN_STACK};
    11251128    }
    11261129    unless (defined($minimum_required_warp)) {
    1127         $minimum_required_warp = 0;
     1130        $minimum_required_warp = 0;
    11281131    }
    11291132
     
    11431146        &my_die("Unable to perform stacktool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    11441147    }
    1145     
    1146     
     1148   
     1149   
    11471150    return(0);
    11481151}
     
    11581161    my $is_registering;
    11591162    if ($metadata_out{nsRegistrationState} eq 'REGISTERED') {
    1160         $is_registering = 0;
     1163        $is_registering = 0;
    11611164    }
    11621165    else {
    1163         $is_registering = 1;
     1166        $is_registering = 1;
    11641167    }
    11651168
    11661169    foreach my $target (sort (keys %science_config)) {
    1167         if ($science_config{$target}{STACKABLE} == 1) {
    1168             foreach my $filter (@filter_list) {
     1170        if ($science_config{$target}{STACKABLE} == 1) {
     1171            foreach my $filter (@filter_list) {
    11691172                my ($Nexposures,$NprocChips,$NprocWarps,$NrequiredWarps,$Nalready) = pre_stack_queue($date,$observing_state,$target,$filter);
    11701173                if ((!defined($force_stack_count))&&($NprocChips != $NprocWarps)) { # This makes me sad. :(
    1171                     if ($debug == 1) {
    1172                         print STDERR "execute_stacks: Target $target on $date is not fully processed. ($NprocChips $NprocWarps)\n";
    1173                     }
    1174                     $is_processing = 1;
     1174                    if ($debug == 1) {
     1175                        print STDERR "execute_stacks: Target $target on $date is not fully processed. ($NprocChips $NprocWarps)\n";
     1176                    }
     1177                    $is_processing = 1;
    11751178                    $metadata_out{nsStackState} = 'FORCETOWARP';
    11761179                    next;
    11771180                }
    11781181                if ($Nexposures == 0) {
    1179                     if ($debug == 1) {
    1180                         print STDERR "execute_stacks: Target $target in filter $filter on $date has no exposures.\n";
    1181                     }
     1182                    if ($debug == 1) {
     1183                        print STDERR "execute_stacks: Target $target in filter $filter on $date has no exposures.\n";
     1184                    }
    11821185                    next;
    11831186                }
    1184                 if ($NprocWarps < $NrequiredWarps) {
    1185                     if ($debug == 1) {
    1186                         print STDERR "execute_stacks: Target $target in filter $filter on $date has too few warps to begin stacking. ($NprocWarps $NrequiredWarps)\n";
    1187                     }
    1188                     next;
    1189                 }
    1190                 $Npotential++;
     1187                if ($NprocWarps < $NrequiredWarps) {
     1188                    if ($debug == 1) {
     1189                        print STDERR "execute_stacks: Target $target in filter $filter on $date has too few warps to begin stacking. ($NprocWarps $NrequiredWarps)\n";
     1190                    }
     1191                    next;
     1192                }
     1193                $Npotential++;
    11911194                if ($Nalready != 0) {
    1192                     $Nqueued++;
    1193                     if ($debug == 1) {
    1194                         print STDERR "execute_stacks: Not queueing $target in filter $filter on $date due to already existing stacks.\n";
    1195                     }
    1196                     unless ($metadata_out{nsStackState} eq 'FORCETOWARP') {
    1197                         $metadata_out{nsStackState} = 'STACKING';
    1198                     }
     1195                    $Nqueued++;
     1196                    if ($debug == 1) {
     1197                        print STDERR "execute_stacks: Not queueing $target in filter $filter on $date due to already existing stacks.\n";
     1198                    }
     1199                    unless ($metadata_out{nsStackState} eq 'FORCETOWARP') {
     1200                        $metadata_out{nsStackState} = 'STACKING';
     1201                    }
    11991202                    next;
    12001203                }
     
    12031206                }
    12041207                unless(defined($pretend)) {
    1205                     if ($debug == 1) {
    1206                         print STDERR "execute_stacks: Target $target in filter $filter on $date has exposures and will be queued.\n";
    1207                     }
     1208                    if ($debug == 1) {
     1209                        print STDERR "execute_stacks: Target $target in filter $filter on $date has exposures and will be queued.\n";
     1210                    }
    12081211                    stack_queue($date,$target,$filter);
    1209                     $Nqueued ++;
    1210                 }
    1211                 if (defined($pretend)) {
    1212                     add_to_macro_list('check_stacks',$science_config{$target}{STACKABLE},$date,$target,$filter);
    1213                 }
    1214                 else {
    1215                     add_to_macro_list('queue_stacks',$science_config{$target}{STACKABLE},$date,$target,$filter);
    1216                 }
    1217             }
    1218         }
    1219         else {
    1220             if ($debug == 1) {
    1221                 print STDERR "execute_stacks: Target $target is not auto-stackable.\n";
    1222             }
     1212                    $Nqueued ++;
     1213                }
     1214                if (defined($pretend)) {
     1215                    add_to_macro_list('check_stacks',$science_config{$target}{STACKABLE},$date,$target,$filter);
     1216                }
     1217                else {
     1218                    add_to_macro_list('queue_stacks',$science_config{$target}{STACKABLE},$date,$target,$filter);
     1219                }
     1220            }
     1221        }
     1222        else {
     1223            if ($debug == 1) {
     1224                print STDERR "execute_stacks: Target $target is not auto-stackable.\n";
     1225            }
    12231226        }
    12241227    }
     
    12261229    $metadata_out{nsStackQueued}    = $Nqueued;
    12271230    if (($Npotential == $Nqueued)&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')&&($is_processing == 0)&&($is_registering == 0)) {
    1228         $metadata_out{nsStackState} = 'FINISHED_STACKS';
    1229     }   
     1231        $metadata_out{nsStackState} = 'FINISHED_STACKS';
     1232    }   
    12301233}
    12311234
     
    12461249    $stack_done_sth .= " AND ((state = 'full') OR (state = 'new' && fault != 0)) ";
    12471250    if ($debug == 1) {
    1248         print STDERR "post_stack_queue: database queries:\n";
    1249         print STDERR "$stack_full_sth\n";
    1250         print STDERR "$stack_done_sth\n";
     1251        print STDERR "post_stack_queue: database queries:\n";
     1252        print STDERR "$stack_full_sth\n";
     1253        print STDERR "$stack_done_sth\n";
    12511254    }
    12521255    my $stack_full_ref = $db->selectall_arrayref( $stack_full_sth );
     
    12591262    my $date = shift;
    12601263    my $pretend = shift;
    1261     
     1264   
    12621265    foreach my $target (sort (keys %science_config)) {
    12631266        if ($science_config{$target}{STACKABLE} == 1) {
    1264             my ($Nstacks, $Nattempted) = post_stack_queue($date,$target);
    1265             if ($debug == 1) {
    1266                 print STDERR "confirm_stacks: Target $target on $date has $Nattempted attempts on $Nstacks.\n";
    1267             }
    1268             if ($Nstacks != $Nattempted) {
    1269                 if ($debug == 1) {
    1270                     print STDERR "confirm_stacks: Target $target on $date is not done stacking. $Nstacks $Nattempted\n";
    1271                 }
    1272                 if ($metadata_out{nsStackState} eq 'CONFIRM_STACKING') {
    1273                     $metadata_out{nsStackState} = 'STACKING';
    1274                 }
    1275                 next;
    1276             }
    1277             if ($Nstacks == 0) {
    1278                 if ($debug == 1) {
    1279                     print STDERR "confirm_stacks: Target $target on $date has no stacks. Skipping.\n";
    1280                 }
    1281                 next;
    1282             }
    1283             if ($metadata_out{nsStackState} eq 'CONFIRM_STACKING') {
    1284                 if (defined($pretend)) {
    1285                     add_to_macro_list('check_confirm_stacks',$science_config{$target}{STACKABLE},$date,$target);
    1286                 }
    1287                 else {
    1288                     add_to_macro_list('confirm_stacks',$science_config{$target}{STACKABLE},$date,$target);
    1289                 }
    1290             }
    1291         }
    1292     }
    1293 }          
     1267            my ($Nstacks, $Nattempted) = post_stack_queue($date,$target);
     1268            if ($debug == 1) {
     1269                print STDERR "confirm_stacks: Target $target on $date has $Nattempted attempts on $Nstacks.\n";
     1270            }
     1271            if ($Nstacks != $Nattempted) {
     1272                if ($debug == 1) {
     1273                    print STDERR "confirm_stacks: Target $target on $date is not done stacking. $Nstacks $Nattempted\n";
     1274                }
     1275                if ($metadata_out{nsStackState} eq 'CONFIRM_STACKING') {
     1276                    $metadata_out{nsStackState} = 'STACKING';
     1277                }
     1278                next;
     1279            }
     1280            if ($Nstacks == 0) {
     1281                if ($debug == 1) {
     1282                    print STDERR "confirm_stacks: Target $target on $date has no stacks. Skipping.\n";
     1283                }
     1284                next;
     1285            }
     1286            if ($metadata_out{nsStackState} eq 'CONFIRM_STACKING') {
     1287                if (defined($pretend)) {
     1288                    add_to_macro_list('check_confirm_stacks',$science_config{$target}{STACKABLE},$date,$target);
     1289                }
     1290                else {
     1291                    add_to_macro_list('confirm_stacks',$science_config{$target}{STACKABLE},$date,$target);
     1292                }
     1293            }
     1294        }
     1295    }
     1296}          
    12941297
    12951298#
     
    13081311
    13091312    my $count = 0;
    1310     
     1313   
    13111314    my $sth = "SELECT DISTINCT diff_id from diffRun JOIN diffInputSkyfile USING(diff_id) where data_group = '$data_group' AND warp1 = $warp_id_1 AND warp2 = $warp_id_2";
    13121315    my $data_ref = $db->selectall_arrayref( $sth );
     
    13311334
    13321335    my $count = 0;
    1333     
     1336   
    13341337    my $sth = "SELECT DISTINCT diff_id from diffRun JOIN diffInputSkyfile USING(diff_id) where (label = '$label' OR label = 'goto_cleaned') AND warp1 = $warp_id_1 AND warp2 = $warp_id_2";
    13351338    my $data_ref = $db->selectall_arrayref( $sth );
     
    13491352    my $filter = shift;
    13501353    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
    1351     
     1354   
    13521355    my $db = init_gpc_db();
    13531356
     
    13581361    my $where_possibly_faulted = $where . " AND ( " ;
    13591362    foreach my $acceptable_quality (@unrecoverable_quality) {
    1360         $where_possibly_faulted .= " quality = $acceptable_quality OR ";
     1363        $where_possibly_faulted .= " quality = $acceptable_quality OR ";
    13611364    }
    13621365    $where_possibly_faulted .= " 0 )";
     
    13831386    my $is_registering;
    13841387    if ($metadata_out{nsRegistrationState} eq 'REGISTERED') {
    1385         $is_registering = 0;
     1388        $is_registering = 0;
    13861389    }
    13871390    else {
    1388         $is_registering = 1;
     1391        $is_registering = 1;
    13891392    }
    13901393
    13911394    foreach my $target (sort (keys %science_config)) {
    1392         if ($science_config{$target}{DIFFABLE} == 1) {
    1393             foreach my $filter (@filter_list) {
    1394                 $Npotential ++;
    1395                 my ($NprocChips,$NprocWarps) = pre_diff_queue($date,$observing_state,$target,$filter);
    1396                 if ((!defined($force_diff_count))&&($NprocChips != $NprocWarps)) {
    1397                     if ($debug == 1) {
    1398                         print STDERR "execute_diffs: Target $target in filter $filter on $date is not fully processed. ($NprocChips $NprocWarps)\n";
    1399                     }
    1400                     $is_processing = 1;
    1401                 }
     1395        if ($science_config{$target}{DIFFABLE} == 1) {
     1396
     1397            my $config_reduction = "DEFAULT";
     1398            if($science_config{$target}{REDUCTION}) {$config_reduction=$science_config{$target}{REDUCTION};}
     1399            print STDERR "execute_diffs: Trying target $target on $date $camera $science_config{$target}{REDUCTION} $config_reduction\n";
     1400
     1401            my $recipe_psastro = $ipprcam->reduction($config_reduction, 'PSASTRO'); # Recipe to use
     1402            &my_die("Unrecognised PSASTRO recipe", $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro;
     1403
     1404            my $recipeData;
     1405            {
     1406                # Get the PSASTRO recipe
     1407                my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -";
     1408                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1409                    run(command => $command);
     1410                unless ($success) {
     1411                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1412                    &my_die("Unable to perform ppConfigDump: $error_code", $PS_EXIT_CONFIG_ERROR);
     1413                }
     1414                $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
     1415                    &my_die("Unable to parse metadata config doc", $PS_EXIT_CONFIG_ERROR);
     1416            }
     1417
     1418            my $maxFWHM = metadataLookupF32($recipeData, 'PSASTRO.MAX.ALLOWED.FWHM');
     1419            print STDERR "execute_diffs: Max FWHM= $maxFWHM for $target\n";
     1420
     1421            foreach my $filter (@filter_list) {
     1422                $Npotential ++;
     1423                my ($NprocChips,$NprocWarps) = pre_diff_queue($date,$observing_state,$target,$filter);
     1424                if ((!defined($force_diff_count))&&($NprocChips != $NprocWarps)) {
     1425                    if ($debug == 1) {
     1426                        print STDERR "execute_diffs: Target $target in filter $filter on $date is not fully processed. ($NprocChips $NprocWarps)\n";
     1427                    }
     1428                    $is_processing = 1;
     1429                }
    14021430                if ($NprocChips == 0) {
    1403                     $Nnoexp ++;
    1404                     if ($debug == 1) {
    1405                         print STDERR "execute_diffs: Target $target in filter $filter on $date has no exposures.\n";
    1406                     }
     1431                    $Nnoexp ++;
     1432                    if ($debug == 1) {
     1433                        print STDERR "execute_diffs: Target $target in filter $filter on $date has no exposures.\n";
     1434                    }
    14071435                    next;
    14081436                }
     
    14101438                    $metadata_out{nsDiffState} = 'QUEUEDIFFS';
    14111439                }
    1412                 if ($debug == 1) {
    1413                     print STDERR "execute_diffs: Target $target in filter $filter on $date has exposures and will be queued.\n";
    1414                 }
    1415                 diff_queue($date,$target,$filter,$pretend);
    1416 
    1417                 #Queue up desperate diffs if the conditions are right for them  
    1418                 if ((defined($science_config{$target}{DESPERATE_DIFFS})) && ($science_config{$target}{DESPERATE_DIFFS} == 1)) {
    1419                     desperate_diff_singles($date,$target,$filter,$pretend);
    1420                 }
    1421 
    1422                 if (defined($pretend)) {
    1423                     add_to_macro_list('check_diffs',$science_config{$target}{DIFFABLE},$date,$target,$filter);
    1424                 }
    1425                 else {
    1426                     add_to_macro_list('queue_diffs',$science_config{$target}{DIFFABLE},$date,$target,$filter);
    1427                 }
    1428             }
    1429         }
    1430         else {
    1431             if ($debug == 1) {
    1432                 print STDERR "execute_diffs: Target $target is not auto-diffable.\n";
    1433             }
     1440                if ($debug == 1) {
     1441                    print STDERR "execute_diffs: Target $target in filter $filter on $date has exposures and will be queued.\n";
     1442                }
     1443                diff_queue($date,$target,$filter,$maxFWHM,$pretend);
     1444
     1445                #Queue up desperate diffs if the conditions are right for them
     1446                if ((defined($science_config{$target}{DESPERATE_DIFFS})) && ($science_config{$target}{DESPERATE_DIFFS} == 1)) {
     1447                    desperate_diff_singles($date,$target,$filter,$maxFWHM,$pretend);
     1448                }
     1449
     1450                if (defined($pretend)) {
     1451                    add_to_macro_list('check_diffs',$science_config{$target}{DIFFABLE},$date,$target,$filter);
     1452                }
     1453                else {
     1454                    add_to_macro_list('queue_diffs',$science_config{$target}{DIFFABLE},$date,$target,$filter);
     1455                }
     1456            }
     1457        }
     1458        else {
     1459            if ($debug == 1) {
     1460                print STDERR "execute_diffs: Target $target is not auto-diffable.\n";
     1461            }
    14341462        }
    14351463    }
    14361464    if ($debug == 1) {
    1437         print "$metadata_out{nsObservingState} $metadata_out{nsDiffPotential} $metadata_out{nsDiffQueued} $is_processing $is_registering\n";
     1465        print "$metadata_out{nsObservingState} $metadata_out{nsDiffPotential} $metadata_out{nsDiffQueued} $is_processing $is_registering\n";
    14381466    }
    14391467
    14401468    if ($metadata_out{nsObservingState} eq 'END_OF_NIGHT') {
    1441         if ($is_processing == 1) {
    1442             $metadata_out{nsDiffState} = 'DIFFING';
    1443         }
    1444         elsif ($is_registering == 0) {
    1445             if ($Npotential == $Nnoexp) {
    1446                 $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
    1447             }
    1448             elsif ($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued}) {
    1449                 $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
    1450             }
    1451         }
    1452         else {
    1453             $metadata_out{nsDiffState} = 'DIFFING';
    1454         }
     1469        if ($is_processing == 1) {
     1470            $metadata_out{nsDiffState} = 'DIFFING';
     1471        }
     1472        elsif ($is_registering == 0) {
     1473            if ($Npotential == $Nnoexp) {
     1474                $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
     1475            }
     1476            elsif ($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued}) {
     1477                $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
     1478            }
     1479        }
     1480        else {
     1481            $metadata_out{nsDiffState} = 'DIFFING';
     1482        }
    14551483    }
    14561484    else {
    1457         $metadata_out{nsDiffState} = 'DIFFING';
     1485        $metadata_out{nsDiffState} = 'DIFFING';
    14581486    }
    14591487    if ($metadata_out{nsDiffState} eq 'FINISHED_DIFFS') {
    1460         foreach my $target (sort (keys %science_config)) {
    1461             # CZW: We should only arrive at this point once, so we can construct a diff report and mail it now.
    1462             if ((defined($science_config{$target}{DESPERATE_DIFFS})) && ($science_config{$target}{DESPERATE_DIFFS} == 1)) {
    1463                 foreach my $filter (@filter_list) {
    1464                     desperate_diff_queue($date,$target,$filter,$pretend);
    1465                 }
    1466             }
    1467 
    1468             if ((defined($science_config{$target}{SELF_WSDIFFS})) && ($science_config{$target}{SELF_WSDIFFS} == 1)) {
    1469                 foreach my $filter (@filter_list) {
    1470                     # This one needs to return a state to see if we need to wait on stacking before checking again.
    1471                     $metadata_out{nsDiffState} = self_WS_diff_queue($date,$target,$filter,$pretend);
    1472                 }
    1473             }
    1474         }
     1488        foreach my $target (sort (keys %science_config)) {
     1489
     1490            my $config_reduction = "DEFAULT";
     1491            if($science_config{$target}{REDUCTION}) {$config_reduction=$science_config{$target}{REDUCTION};}
     1492            print STDERR "execute_diffs: Trying target $target on $date $camera $science_config{$target}{REDUCTION} $config_reduction\n";
     1493
     1494            my $recipe_psastro = $ipprcam->reduction($config_reduction, 'PSASTRO'); # Recipe to use
     1495            &my_die("Unrecognised PSASTRO recipe", $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro;
     1496
     1497            my $recipeData;
     1498            {
     1499                # Get the PSASTRO recipe
     1500                my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -";
     1501                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1502                    run(command => $command);
     1503                unless ($success) {
     1504                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1505                    &my_die("Unable to perform ppConfigDump: $error_code", $PS_EXIT_CONFIG_ERROR);
     1506                }
     1507                $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
     1508                    &my_die("Unable to parse metadata config doc", $PS_EXIT_CONFIG_ERROR);
     1509            }
     1510
     1511            my $maxFWHM = metadataLookupF32($recipeData, 'PSASTRO.MAX.ALLOWED.FWHM');
     1512
     1513            # CZW: We should only arrive at this point once, so we can construct a diff report and mail it now.
     1514            if ((defined($science_config{$target}{DESPERATE_DIFFS})) && ($science_config{$target}{DESPERATE_DIFFS} == 1)) {
     1515                foreach my $filter (@filter_list) {
     1516                    desperate_diff_queue($date,$target,$filter,$maxFWHM,$pretend);
     1517                }
     1518            }
     1519
     1520            if ((defined($science_config{$target}{SELF_WSDIFFS})) && ($science_config{$target}{SELF_WSDIFFS} == 1)) {
     1521                foreach my $filter (@filter_list) {
     1522                    # This one needs to return a state to see if we need to wait on stacking before checking again.
     1523                    $metadata_out{nsDiffState} = self_WS_diff_queue($date,$target,$filter,$pretend);
     1524                }
     1525            }
     1526        }
    14751527    }
    14761528
    14771529#     if (($Npotential == $Nnoexp)&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')&&($is_processing == 0)) {
    1478 #       $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
    1479 #     } 
     1530#       $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
     1531#     }
    14801532
    14811533#     if ($is_processing == 1) {
    1482 #       $metadata_out{nsDiffState} = 'DIFFING';
     1534#       $metadata_out{nsDiffState} = 'DIFFING';
    14831535#     }
    14841536}
     
    14881540    my $target = shift;
    14891541    my $filter = shift;
     1542    my $maxFWHM = shift;
    14901543    my $pretend = shift;
    14911544    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
     
    15001553    my $Npotential = 0;
    15011554    my $Nqueued = 0;
    1502     
     1555   
    15031556    foreach my $object_row (@{ $object_ref }) {
    1504         my $this_object = shift @{ $object_row };       
    1505         my $this_chunk = shift @{ $object_row };
    1506         my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality FROM ";
    1507         $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
    1508         $input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
    1509         $input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs ";
    1510 
    1511         my $warps = $db->selectall_arrayref( $input_sth );
    1512 
    1513         # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra.
    1514         my %comment_hash = ();
    1515         foreach my $this_warp (@{ $warps }) {
    1516             my $this_comment = ${ $this_warp }[3];
    1517             my $this_exp_id  = ${ $this_warp }[0];
    1518             my $this_quality = ${ $this_warp }[5];
    1519             my $this_state   = ${ $this_warp }[4];
    1520             if (($this_quality != 0) || ($this_state eq 'drop') ) {
    1521                 print STDERR "diff_queue: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality or state $this_state\n";
    1522             }
    1523             else {
    1524                 $comment_hash{$this_comment} = $this_exp_id;
    1525             }
    1526         }
    1527         # Exclude any warps that are not stored in the comment_hash.
    1528         my @keep_warps = ();
    1529         foreach my $this_warp (@{ $warps }) {
    1530             my $this_comment = ${ $this_warp }[3];
    1531             my $this_exp_id  = ${ $this_warp }[0];
    1532             if ((exists($comment_hash{$this_comment}))&&
    1533                 ($comment_hash{$this_comment} == $this_exp_id)) {
    1534                 push @keep_warps, $this_warp;
    1535             }
    1536             else {
    1537                 print STDERR "diff_queue: excluding $this_exp_id for $this_object due to not being an accepted comment string $this_comment\n";
    1538             }
    1539         }
    1540         @{ $warps } = @keep_warps;
    1541 
    1542         # Exclude the last entry if we do not have an even number of warps.
    1543         if (($#{ $warps } + 1) % 2 != 0) {
    1544             print STDERR "diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } ";
    1545             if ($#{ $warps} + 1 == 1) {
    1546                 print STDERR ": I can do no diffs with only one exposure.\n";
    1547                 next;
    1548             }
    1549             else {
    1550                 my $rejected_warp = pop @{ $warps };
    1551                 my $rejected_exp_id = ${ $rejected_warp }[0];
    1552                 print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n";
    1553             }
    1554         }
    1555        
    1556         while ($#{ $warps } > -1) {
    1557             # The array is sorted in pairs of input/template.
    1558             my $input_warp = shift @{ $warps };
    1559             my $template_warp = shift @{ $warps };
    1560 
    1561             my $input_exp_id = ${ $input_warp }[0];
    1562             my $input_comment = ${ $input_warp }[3];
    1563 
    1564             my $template_exp_id = ${ $template_warp }[0];
    1565             my $template_comment = ${ $template_warp }[3];
    1566 
    1567             my $input_warp_id = ${ $input_warp }[1];
    1568             my $template_warp_id = ${ $template_warp }[1];
    1569 
    1570             my $input_warp_state = ${ $input_warp }[4];
    1571             my $template_warp_state = ${ $template_warp }[4];
    1572 
    1573             my $input_warp_camQuality = ${ $input_warp }[5];
    1574             my $template_warp_camQuality = ${ $template_warp }[5];
    1575 
    1576             $Npotential++;
    1577 
    1578             unless (defined($input_warp_id) && defined($template_warp_id) &&
    1579                     ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {
    1580                 print STDERR "Diff for this $date $target $input_exp_id $template_exp_id not fully processed ($input_warp_state $template_warp_state) ($input_warp_camQuality $template_warp_camQuality)\n";
    1581                 if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) {
    1582                     # This should now never be reached.
    1583                     # CZW: Trigger backup plan here?  Or simply set up framework?
    1584                     print STDERR "  ...but this is due to a camera stage astrometry quality\n";
    1585                     $Npotential--;
    1586                 }
    1587                 next;
    1588             }
    1589 
    1590             if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
    1591                 $Nqueued++;
    1592                 print STDERR "Diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
    1593                 next;
    1594             }
    1595             else {
    1596                 print STDERR "Preparing to diff $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
    1597             }
    1598            
    1599             my $cmd = "$difftool -dbname $dbname  -definewarpwarp  ";
    1600             $cmd .= "-input_label $label  -template_label $label -good_frac 0.1 ";
    1601             $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.
    1602             $cmd .= "-set_workdir $workdir  -set_dist_group $dist_group  -set_data_group $data_group ";
    1603             $cmd .= " -simple  -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";
    1604 #               $cmd .= " -pretend ";
    1605             if (defined($reduction)) {
    1606                 $cmd .= " -set_reduction $reduction ";
    1607             }
    1608 
    1609             if (defined($pretend)) {
    1610                 $cmd .= ' -pretend ';
    1611             }
    1612             if ($debug == 1) {
    1613                 $cmd .= ' -pretend ';
    1614                 print STDERR "diff_queue: $cmd\n";
    1615                 print STDERR " $input_warp_id $template_warp_id\n";
    1616             }
    1617            
    1618             if (($debug == 0)&&(!defined($pretend))) {
    1619                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    1620                     run ( command => $cmd, verbose => $verbose );
    1621                 unless ($success) {
    1622                     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    1623                     &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    1624                 }
    1625                 $Nqueued++;
    1626             }
    1627         }
     1557        my $this_object = shift @{ $object_row };       
     1558        my $this_chunk = shift @{ $object_row };
     1559        my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality FROM ";
     1560        $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
     1561        $input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
     1562        $input_sth .=   " AND camProcessedExp.fwhm_major <= $maxFWHM ";
     1563        $input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs ";
     1564
     1565        my $warps = $db->selectall_arrayref( $input_sth );
     1566
     1567        # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra.
     1568        my %comment_hash = ();
     1569        foreach my $this_warp (@{ $warps }) {
     1570            my $this_comment = ${ $this_warp }[3];
     1571            my $this_exp_id  = ${ $this_warp }[0];
     1572            my $this_quality = ${ $this_warp }[5];
     1573            my $this_state   = ${ $this_warp }[4];
     1574            if (($this_quality != 0) || ($this_state eq 'drop') ) {
     1575                print STDERR "diff_queue: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality or state $this_state\n";
     1576            }
     1577            else {
     1578                $comment_hash{$this_comment} = $this_exp_id;
     1579            }
     1580        }
     1581        # Exclude any warps that are not stored in the comment_hash.
     1582        my @keep_warps = ();
     1583        foreach my $this_warp (@{ $warps }) {
     1584            my $this_comment = ${ $this_warp }[3];
     1585            my $this_exp_id  = ${ $this_warp }[0];
     1586            if ((exists($comment_hash{$this_comment}))&&
     1587                ($comment_hash{$this_comment} == $this_exp_id)) {
     1588                push @keep_warps, $this_warp;
     1589            }
     1590            else {
     1591                print STDERR "diff_queue: excluding $this_exp_id for $this_object due to not being an accepted comment string $this_comment\n";
     1592            }
     1593        }
     1594        @{ $warps } = @keep_warps;
     1595
     1596        # Exclude the last entry if we do not have an even number of warps.
     1597        if (($#{ $warps } + 1) % 2 != 0) {
     1598            print STDERR "diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } ";
     1599            if ($#{ $warps} + 1 == 1) {
     1600                print STDERR ": I can do no diffs with only one exposure.\n";
     1601                next;
     1602            }
     1603            else {
     1604                my $rejected_warp = pop @{ $warps };
     1605                my $rejected_exp_id = ${ $rejected_warp }[0];
     1606                print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n";
     1607            }
     1608        }
     1609       
     1610        while ($#{ $warps } > -1) {
     1611            # The array is sorted in pairs of input/template.
     1612            my $input_warp = shift @{ $warps };
     1613            my $template_warp = shift @{ $warps };
     1614
     1615            my $input_exp_id = ${ $input_warp }[0];
     1616            my $input_comment = ${ $input_warp }[3];
     1617
     1618            my $template_exp_id = ${ $template_warp }[0];
     1619            my $template_comment = ${ $template_warp }[3];
     1620
     1621            my $input_warp_id = ${ $input_warp }[1];
     1622            my $template_warp_id = ${ $template_warp }[1];
     1623
     1624            my $input_warp_state = ${ $input_warp }[4];
     1625            my $template_warp_state = ${ $template_warp }[4];
     1626
     1627            my $input_warp_camQuality = ${ $input_warp }[5];
     1628            my $template_warp_camQuality = ${ $template_warp }[5];
     1629
     1630            $Npotential++;
     1631
     1632            unless (defined($input_warp_id) && defined($template_warp_id) &&
     1633                    ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {
     1634                print STDERR "Diff for this $date $target $input_exp_id $template_exp_id not fully processed ($input_warp_state $template_warp_state) ($input_warp_camQuality $template_warp_camQuality)\n";
     1635                if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) {
     1636                    # This should now never be reached.
     1637                    # CZW: Trigger backup plan here?  Or simply set up framework?
     1638                    print STDERR "  ...but this is due to a camera stage astrometry quality\n";
     1639                    $Npotential--;
     1640                }
     1641                next;
     1642            }
     1643
     1644            if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
     1645                $Nqueued++;
     1646                print STDERR "Diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
     1647                next;
     1648            }
     1649            else {
     1650                print STDERR "Preparing to diff $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
     1651            }
     1652           
     1653            my $cmd = "$difftool -dbname $dbname  -definewarpwarp  ";
     1654            $cmd .= "-input_label $label  -template_label $label -good_frac 0.1 ";
     1655            $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.
     1656            $cmd .= "-set_workdir $workdir  -set_dist_group $dist_group  -set_data_group $data_group ";
     1657            $cmd .= " -simple  -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";
     1658#               $cmd .= " -pretend ";
     1659            if (defined($reduction)) {
     1660                $cmd .= " -set_reduction $reduction ";
     1661            }
     1662
     1663            if (defined($pretend)) {
     1664                $cmd .= ' -pretend ';
     1665            }
     1666            if ($debug == 1) {
     1667                $cmd .= ' -pretend ';
     1668                print STDERR "diff_queue: $cmd\n";
     1669                print STDERR " $input_warp_id $template_warp_id\n";
     1670            }
     1671           
     1672            if (($debug == 0)&&(!defined($pretend))) {
     1673                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1674                    run ( command => $cmd, verbose => $verbose );
     1675                unless ($success) {
     1676                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1677                    &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     1678                }
     1679                $Nqueued++;
     1680            }
     1681        }
    16281682    }
    16291683    $metadata_out{nsDiffPotential} += $Npotential;
    16301684    $metadata_out{nsDiffQueued}    += $Nqueued;
    16311685#      if (($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued})&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')) {
    1632      $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
    1633 #      }       
     1686     $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
     1687#      }       
    16341688
    16351689}
     
    16391693    my $target = shift;
    16401694    my $filter = shift;
     1695    my $maxFWHM = shift;
    16411696    my $pretend = shift;
    16421697    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
     
    16551710    my $Nqueued = 0;
    16561711
    1657     #Before considering making diffs, we should check if there are no issues with summit download and/or registration. 
     1712    #Before considering making diffs, we should check if there are no issues with summit download and/or registration.
    16581713    #summitExp has limited information, so see if the number of exps in rawExp and summitExp match up before most recent dateobs of chunk
    16591714    #be careful here, since dateobs is not quite completely the same in both tables. Therefore, allow numbers to be off by 1
     
    16731728        $rawdate=~/^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
    16741729        my $date1=DateTime->new(year=>$1,month=>$2,day=>$3,hour=>$4,minute=>$5,second=>$6,time_zone=>"UTC");
    1675   
     1730 
    16761731        $summitdate=~/^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
    16771732        my $date2=DateTime->new(year=>$1,month=>$2,day=>$3,hour=>$4,minute=>$5,second=>$6,time_zone=>"UTC");
     
    16861741    if (($summittimediff > 10.)||($noff >10)) {
    16871742        if ($debug == 1) {
    1688         print STDERR "desp_diff_singles: No desperate diffs will be attempted, since the number of exps at the summit and in rawExp do not match ($nsummitexps $nrawexps), or the timestamps are off ($summittimediff)\n";
    1689         }
    1690     }
    1691     else {    
     1743        print STDERR "desp_diff_singles: No desperate diffs will be attempted, since the number of exps at the summit and in rawExp do not match ($nsummitexps $nrawexps), or the timestamps are off ($summittimediff)\n";
     1744        }
     1745    }
     1746    else {   
    16921747        foreach my $object_row (@{ $object_ref }) {
    1693             my $this_object = shift @{ $object_row };
    1694             my $this_chunk = shift @{ $object_row };
    1695        
    1696             my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality,substr(comment, 1, position(' ' in comment)) FROM ";
    1697             $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
    1698             $input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
    1699             $input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs ";
    1700 
    1701             my $warps = $db->selectall_arrayref( $input_sth );
    1702 
    1703             # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra.
    1704             my %comment_hash = ();
    1705             foreach my $this_warp (@{ $warps }) {
    1706                 my $this_comment = ${ $this_warp }[3];
    1707                 my $this_exp_id  = ${ $this_warp }[0];
    1708                 my $this_quality = ${ $this_warp }[5];
    1709                 my $this_state   = ${ $this_warp }[4];
    1710                 if (($this_quality != 0) || ($this_state eq 'drop') ) {
    1711                     print STDERR "desp_diff_singles: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality or state $this_state\n";
    1712                 }
    1713                 else {
    1714                     $comment_hash{$this_comment} = $this_exp_id;
    1715                 }
    1716             }
    1717             # Exclude any warps that are not stored in the comment_hash.
    1718             my @keep_warps = ();
    1719             foreach my $this_warp (@{ $warps }) {
    1720                 my $this_comment = ${ $this_warp }[3];
    1721                 my $this_exp_id  = ${ $this_warp }[0];
    1722                 if ((exists($comment_hash{$this_comment}))&&
    1723                     ($comment_hash{$this_comment} == $this_exp_id)) {
    1724                     push @keep_warps, $this_warp;
     1748            my $this_object = shift @{ $object_row };
     1749            my $this_chunk = shift @{ $object_row };
     1750       
     1751            my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality,substr(comment, 1, position(' ' in comment)),camProcessedExp.fwhm_major FROM ";
     1752            $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
     1753            $input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
     1754            $input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs ";
     1755
     1756            my $warps = $db->selectall_arrayref( $input_sth );
     1757            my $warpsBQ = $db->selectall_arrayref( $input_sth );;
     1758
     1759            # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra.
     1760            my %comment_hash = ();
     1761            my %comment_hash_good = ();
     1762            foreach my $this_warp (@{ $warps }) {
     1763                my $this_comment = ${ $this_warp }[3];
     1764                my $this_exp_id  = ${ $this_warp }[0];
     1765                my $this_quality = ${ $this_warp }[5];
     1766                my $this_state   = ${ $this_warp }[4];
     1767                my $this_fwhm   = ${ $this_warp }[7];
     1768                if (($this_quality != 0) || ($this_state eq 'drop') || ($this_fwhm > $maxFWHM)) {
     1769                    print STDERR "desp_diff_singles: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality or state $this_state or FWHM $this_fwhm\n";
     1770                }
     1771                else {
     1772                    $comment_hash_good{$this_comment} = $this_exp_id;
     1773                }
     1774               
     1775                #also save the entries which are ok, but not best quality
     1776                if (($this_quality == 0) && ($this_state ne 'drop') ) {
     1777                    $comment_hash{$this_comment} = $this_exp_id;
     1778                }
     1779            }
     1780
     1781            # Exclude any warps that are not stored in the comment_hash_good.
     1782            my @keep_warps = ();
     1783            foreach my $this_warp (@{ $warps }) {
     1784                my $this_comment = ${ $this_warp }[3];
     1785                my $this_exp_id  = ${ $this_warp }[0];
     1786                if ((exists($comment_hash_good{$this_comment}))&&
     1787                    ($comment_hash_good{$this_comment} == $this_exp_id)) {
     1788                    push @keep_warps, $this_warp;
    17251789                    $this_date  = ${ $this_warp }[2];
    17261790                    $chunk_name  = ${ $this_warp }[6];
    1727                 }
    1728                 else {
    1729                     print STDERR "desp_diff_singles: excluding $this_exp_id for $this_object due to being rejected $this_comment\n";
    1730                 }
    1731             }
    1732             @{ $warps } = @keep_warps;
    1733 
     1791                }
     1792                else {
     1793                    print STDERR "desp_diff_singles: excluding $this_exp_id for $this_object due to being rejected $this_comment\n";
     1794                }
     1795            }
     1796            @{ $warps } = @keep_warps;
     1797            my $nwarps = ($#{ $warps } + 1);
     1798           
    17341799            #find the time of the most recent exposure in that chunk
    1735             my $input_chunk = "select max(dateobs) FROM rawExp WHERE substr(comment, 1, position(' ' in comment)) = '$chunk_name' AND filter = '$filter' ";
    1736             my $chunk = $db->selectall_arrayref( $input_chunk );
    1737             foreach my $this_chunk (@{ $chunk }) {
    1738                 $this_date = ${ $this_chunk }[0];
     1800            my $input_chunk = "select max(dateobs) FROM rawExp WHERE substr(comment, 1, position(' ' in comment)) = '$chunk_name' AND filter = '$filter' ";
     1801            my $chunk = $db->selectall_arrayref( $input_chunk );
     1802            foreach my $this_chunk (@{ $chunk }) {
     1803                $this_date = ${ $this_chunk }[0];
    17391804            }
    17401805 
    17411806            #compute and store some stats for potential on-the-fly desperate diffs
    1742             my $nwarps = ($#{ $warps } + 1);
    17431807            my $timediff = 0;
    17441808            my $now=DateTime->now;
     
    17521816                }
    17531817            }
    1754 
    1755             #Consider the special case of on-the-fly desperate diffs
    1756             #The conditions are: uneven nr of warps greater than 3, and the most recent observations is more than $desdiffdt hours old
    1757             if (($nwarps % 2 != 0) && ($nwarps >= 3) && ($timediff < $desdiffdt)) {
    1758                 print STDERR "desp_diff_singles: There are potential desperate diffs to be done, but the time criterium is not met.\n";
    1759                 next;
    1760             }
    1761             if (($nwarps % 2 == 0) || ($nwarps == 1) || ($timediff < $desdiffdt)) {
    1762                 next;
    1763             }
    1764 
    1765             # We are attempting to do the missing diffs, so reverse the list of retained warps.
    1766             # Good objects with all visits will be skipped due to the duplicate check.
    1767             # Bad objects will have the earliest visit rejected, and the visits repaired in a way that will produce all desired pairs.
    1768             @{ $warps } = reverse @keep_warps;
    1769 
    1770             # Exclude the last entry if we do not have an even number of warps.
    1771             if (($#{ $warps } + 1) % 2 != 0) {
    1772                 print STDERR "desp_diff_singles: Number of input warps to make diffs is not even for target $target and object $this_object!";
    1773                 my $rejected_warp = pop @{ $warps };
    1774                 my $rejected_exp_id = ${ $rejected_warp }[0];
    1775                 print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n";
    1776             }
    1777        
    1778             while ($#{ $warps } > -1) {
    1779                 # The array is sorted in pairs of input/template.
    1780                 my $template_warp = shift @{ $warps };
    1781                 my $input_warp = shift @{ $warps };
    1782    
    1783                 my $input_exp_id = ${ $input_warp }[0];
    1784                 my $input_comment = ${ $input_warp }[3];
    1785 
    1786                 my $template_exp_id = ${ $template_warp }[0];
    1787                 my $template_comment = ${ $template_warp }[3];
    1788 
    1789                 my $input_warp_id = ${ $input_warp }[1];
    1790                 my $template_warp_id = ${ $template_warp }[1];
    1791 
    1792                 my $input_warp_state = ${ $input_warp }[4];
    1793                 my $template_warp_state = ${ $template_warp }[4];
    1794 
    1795                 my $input_warp_camQuality = ${ $input_warp }[5];
    1796                 my $template_warp_camQuality = ${ $template_warp }[5];
    1797 
    1798                 $Npotential++;
    1799 
    1800                 unless (defined($input_warp_id) && defined($template_warp_id) &&
    1801                     ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {
    1802                     print STDERR "Desp diff for this $date $target $input_exp_id $template_exp_id not fully processed ($input_warp_state $template_warp_state) ($input_warp_camQuality $template_warp_camQuality)\n";
    1803                     if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) {
    1804                         # This should now never be reached.
    1805                         # CZW: Trigger backup plan here?  Or simply set up framework?
    1806                         print STDERR "  ...but this is due to a camera stage astrometry quality\n";
    1807                         $Npotential--;
    1808                     }
    1809                     next;
    1810                 }
    1811 
    1812                 if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
    1813                     $Nqueued++;
    1814                     print STDERR "Desp diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
    1815                     next;
    1816                 }
    1817                 else {
    1818                     print STDERR "Preparing to diff $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
    1819                 }
    1820            
    1821                 my $cmd = "$difftool -dbname $dbname  -definewarpwarp  ";
    1822                 $cmd .= "-input_label $label  -template_label $label -good_frac 0.1 ";
    1823                 $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.
    1824                 $cmd .= "-rerun "; # Needed because we may have some diffs that already use some of the exposures
    1825                 $cmd .= "-set_workdir $workdir  -set_dist_group $dist_group  -set_data_group $data_group ";
    1826                 $cmd .= " -simple  -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";
    1827                 if (defined($reduction)) {
    1828                     $cmd .= " -set_reduction $reduction ";
    1829                 }
    1830        
    1831                 if (defined($pretend)) {
    1832                     $cmd .= ' -pretend ';
    1833                 }
    1834                 if ($debug == 1) {
    1835                     $cmd .= ' -pretend ';
    1836                     print STDERR "desp_diff_singles: $cmd\n";
    1837                     print STDERR " $input_warp_id $template_warp_id\n";
    1838                 }
    1839            
    1840                 if (($debug == 0)&&(!defined($pretend))) {
    1841                     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    1842                         run ( command => $cmd, verbose => $verbose );
    1843                     unless ($success) {
    1844                         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    1845                         &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    1846                     }
    1847                     $Nqueued++;
    1848                 }
    1849             }
     1818           
     1819            ################################
     1820            #We reach a junction here, where having more than 3 (but uneven) warps will result in desperate diffs
     1821            #Conversely, less than 3 good quality warps might result in dirty diffs
     1822            ################################
     1823            if($nwarps >= 3) {     
     1824                #Consider the special case of on-the-fly desperate diffs
     1825                #The conditions are: uneven nr of warps greater than 3, and the most recent observations is more than $desdiffdt hours old
     1826                if (($nwarps % 2 != 0) && ($nwarps >= 3) && ($timediff < $desdiffdt)) {
     1827                    print STDERR "desp_diff_singles: There are potential desperate diffs to be done, but the time criterium is not met.\n";
     1828                    next;
     1829                }
     1830                if (($nwarps % 2 == 0) || ($nwarps == 1) || ($timediff < $desdiffdt)) {
     1831                    next;
     1832                }
     1833
     1834                # We are attempting to do the missing diffs, so reverse the list of retained warps.
     1835                # Good objects with all visits will be skipped due to the duplicate check.
     1836                # Bad objects will have the earliest visit rejected, and the visits repaired in a way that will produce all desired pairs.
     1837                @{ $warps } = reverse @keep_warps;
     1838
     1839                # Exclude the last entry if we do not have an even number of warps.
     1840                if (($#{ $warps } + 1) % 2 != 0) {
     1841                    print STDERR "desp_diff_singles: Number of input warps to make diffs is not even for target $target and object $this_object!";
     1842                    my $rejected_warp = pop @{ $warps };
     1843                    my $rejected_exp_id = ${ $rejected_warp }[0];
     1844                    print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n";
     1845                }
     1846       
     1847                while ($#{ $warps } > -1) {
     1848                    # The array is sorted in pairs of input/template.
     1849                    my $template_warp = shift @{ $warps };
     1850                    my $input_warp = shift @{ $warps };
     1851   
     1852                    my $input_exp_id = ${ $input_warp }[0];
     1853                    my $input_comment = ${ $input_warp }[3];
     1854
     1855                    my $template_exp_id = ${ $template_warp }[0];
     1856                    my $template_comment = ${ $template_warp }[3];
     1857
     1858                    my $input_warp_id = ${ $input_warp }[1];
     1859                    my $template_warp_id = ${ $template_warp }[1];
     1860
     1861                    my $input_warp_state = ${ $input_warp }[4];
     1862                    my $template_warp_state = ${ $template_warp }[4];
     1863
     1864                    my $input_warp_camQuality = ${ $input_warp }[5];
     1865                    my $template_warp_camQuality = ${ $template_warp }[5];
     1866
     1867                    $Npotential++;
     1868
     1869                    unless (defined($input_warp_id) && defined($template_warp_id) &&
     1870                        ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {
     1871                        print STDERR "Desp diff for this $date $target $input_exp_id $template_exp_id not fully processed ($input_warp_state $template_warp_state) ($input_warp_camQuality $template_warp_camQuality)\n";
     1872                        if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) {
     1873                            # This should now never be reached.
     1874                            # CZW: Trigger backup plan here?  Or simply set up framework?
     1875                            print STDERR "  ...but this is due to a camera stage astrometry quality\n";
     1876                            $Npotential--;
     1877                        }
     1878                        next;
     1879                    }
     1880
     1881                    if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
     1882                        $Nqueued++;
     1883                        print STDERR "Desp diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
     1884                        next;
     1885                    }
     1886                    else {
     1887                        print STDERR "Preparing to diff $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
     1888                    }
     1889           
     1890                    my $cmd = "$difftool -dbname $dbname  -definewarpwarp  ";
     1891                    $cmd .= "-input_label $label  -template_label $label -good_frac 0.1 ";
     1892                    $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.
     1893                    $cmd .= "-rerun "; # Needed because we may have some diffs that already use some of the exposures
     1894                    $cmd .= "-set_workdir $workdir  -set_dist_group $dist_group  -set_data_group $data_group ";
     1895                    $cmd .= " -simple  -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";
     1896                    if (defined($reduction)) {
     1897                        $cmd .= " -set_reduction $reduction ";
     1898                    }
     1899       
     1900                    if (defined($pretend)) {
     1901                        $cmd .= ' -pretend ';
     1902                    }
     1903                    if ($debug == 1) {
     1904                        $cmd .= ' -pretend ';
     1905                        print STDERR "desp_diff_singles: $cmd\n";
     1906                        print STDERR " $input_warp_id $template_warp_id\n";
     1907                    }
     1908           
     1909                    if (($debug == 0)&&(!defined($pretend))) {
     1910                        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1911                            run ( command => $cmd, verbose => $verbose );
     1912                        unless ($success) {
     1913                            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1914                            &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     1915                        }
     1916                        $Nqueued++;
     1917                    }
     1918                }           
     1919           
     1920            } else {       
     1921                print STDERR "desp_diff_singles: There is a possibility for dirty diffs to be made\n";     
     1922                #Consider the case of on-the-fly dirty desperate diffs
     1923                #The conditions are: uneven nr of bad quality warps greater than 3, and the most recent observations is more than $desdiffdt hours old
     1924
     1925#                # Exclude any warps that are not stored in the more general comment_hash.
     1926#                my @keep_warps = ();
     1927#                foreach my $this_warp (@{ $warpsBQ }) {
     1928#                    my $this_comment = ${ $this_warp }[3];
     1929#                    my $this_exp_id  = ${ $this_warp }[0];
     1930#                    if ((exists($comment_hash{$this_comment}))&&
     1931#                        ($comment_hash{$this_comment} == $this_exp_id)) {
     1932#                        push @keep_warps, $this_warp;
     1933#                        $this_date  = ${ $this_warp }[2];
     1934#                        $chunk_name  = ${ $this_warp }[6];
     1935#                    }
     1936#                    else {
     1937#                        print STDERR "desp_diff_singles: excluding $this_exp_id for $this_object due to being rejected $this_comment\n";
     1938#                    }
     1939#                }
     1940#                @{ $warpsBQ } = @keep_warps;
     1941#
     1942#                if ($nwarps >= 2) {
     1943#                    #one regular diff has already been made. So, need only one more. Strip a good entry from the array             
     1944#                    my $nrem = 0;
     1945#                    my @keep_warps = ();
     1946#                    foreach my $this_warp (@{ $warpsBQ }) {
     1947#                        my $this_comment = ${ $this_warp }[3];
     1948#                        my $this_exp_id  = ${ $this_warp }[0];
     1949#                        my $this_fwhm   = ${ $this_warp }[7];
     1950#                        if (($nrem <1) && ($this_fwhm <= $maxFWHM)) {
     1951#                            $nrem++;
     1952#                            print STDERR "desp_diff_singles: excluding $this_exp_id for $this_object from dirty desp diffs $this_comment\n";
     1953#                        } else {
     1954#                            push @keep_warps, $this_warp;                       
     1955#                        }
     1956#                    }
     1957#                    @{ $warpsBQ } = @keep_warps;
     1958#                }
     1959#
     1960#                # We are attempting to do the missing diffs, so reverse the list of retained warps.
     1961#                # Good objects with all visits will be skipped due to the duplicate check.
     1962#                # Bad objects will have the earliest visit rejected, and the visits repaired in a way that will produce all desired pairs.
     1963#                @{ $warpsBQ } = reverse @{ $warpsBQ };
     1964#
     1965#                # Exclude the last entry if we do not have an even number of warps.
     1966#                if (($#{ $warpsBQ } + 1) % 2 != 0) {
     1967#                    print STDERR "desp_diff_singles: Number of input warps to make dirty diffs is not even for target $target and object $this_object!";
     1968#                    my $rejected_warp = pop @{ $warpsBQ };
     1969#                    my $rejected_exp_id = ${ $rejected_warp }[0];
     1970#                    print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n";
     1971#                }
     1972#                my $nwarpsBQ = ($#{$warpsBQ} + 1);
     1973#       
     1974#       
     1975#                if (($nwarpsBQ >= 2) && ($timediff < $desdiffdt)) {
     1976#                    print STDERR "desp_diff_singles: There are potential dirty desperate diffs to be done, but the time criterium is not met.\n";
     1977#                    next;
     1978#                }
     1979#                if (($nwarpsBQ <= 1) || ($timediff < $desdiffdt)) {
     1980#                    next;
     1981#                }
     1982#       
     1983#                while ($#{ $warpsBQ } > -1) {
     1984#                    # The array is sorted in pairs of input/template.
     1985#                    my $template_warp = shift @{ $warpsBQ };
     1986#                    my $input_warp = shift @{ $warpsBQ };
     1987#   
     1988#                    my $input_exp_id = ${ $input_warp }[0];
     1989#                    my $input_comment = ${ $input_warp }[3];
     1990#
     1991#                    my $template_exp_id = ${ $template_warp }[0];
     1992#                    my $template_comment = ${ $template_warp }[3];
     1993#
     1994#                    my $input_warp_id = ${ $input_warp }[1];
     1995#                    my $template_warp_id = ${ $template_warp }[1];
     1996#
     1997#                    my $input_warp_state = ${ $input_warp }[4];
     1998#                    my $template_warp_state = ${ $template_warp }[4];
     1999#
     2000#                    my $input_warp_camQuality = ${ $input_warp }[5];
     2001#                    my $template_warp_camQuality = ${ $template_warp }[5];
     2002#
     2003#                    $Npotential++;
     2004#
     2005#                    unless (defined($input_warp_id) && defined($template_warp_id) &&
     2006#                        ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {
     2007#                        print STDERR "Desp diff for this $date $target $input_exp_id $template_exp_id not fully processed ($input_warp_state $template_warp_state) ($input_warp_camQuality $template_warp_camQuality)\n";
     2008#                        if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) {
     2009#                            # This should now never be reached.
     2010#                            # CZW: Trigger backup plan here?  Or simply set up framework?
     2011#                            print STDERR "  ...but this is due to a camera stage astrometry quality\n";
     2012#                            $Npotential--;
     2013#                        }
     2014#                        next;
     2015#                    }
     2016#
     2017#                    if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
     2018#                        $Nqueued++;
     2019#                        print STDERR "Desp diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
     2020#                        next;
     2021#                    }
     2022#                    else {
     2023#                        print STDERR "Preparing to dirty diff $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
     2024#                    }
     2025#           
     2026#                    my $cmd = "$difftool -dbname $dbname  -definewarpwarp  ";
     2027#                    $cmd .= "-input_label $label  -template_label $label -good_frac 0.1 ";
     2028#                    $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.
     2029#                    $cmd .= "-rerun "; # Needed because we may have some diffs that already use some of the exposures
     2030#                    $cmd .= "-set_workdir $workdir  -set_dist_group $dist_group  -set_data_group $data_group ";
     2031#                    $cmd .= " -simple  -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";
     2032#                    if (defined($reduction)) {
     2033#                        $cmd .= " -set_reduction $reduction ";
     2034#                    }
     2035#       
     2036#                    if (defined($pretend)) {
     2037#                        $cmd .= ' -pretend ';
     2038#                    }
     2039#                    if ($debug == 1) {
     2040#                        $cmd .= ' -pretend ';
     2041#                        print STDERR "desp_diff_singles: $cmd\n";
     2042#                        print STDERR " $input_warp_id $template_warp_id\n";
     2043#                    }
     2044#           
     2045#                    if (($debug == 0)&&(!defined($pretend))) {
     2046#                        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     2047#                            run ( command => $cmd, verbose => $verbose );
     2048#                        unless ($success) {
     2049#                            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     2050#                            &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     2051#                        }
     2052#                        $Nqueued++;
     2053#                    }
     2054#                }
     2055           
     2056           
     2057           
     2058            }
    18502059        }
    18512060    }
     
    18582067    my $target = shift;
    18592068    my $filter = shift;
     2069    my $maxFWHM = shift;
    18602070    my $pretend = shift;
    18612071    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
     
    18722082    my $Nqueued = 0;
    18732083
    1874     #Before considering making diffs, we should check if there are no issues with summit download and/or registration. 
     2084    #Before considering making diffs, we should check if there are no issues with summit download and/or registration.
    18752085    #summitExp has limited information, so see if the number of exps in rawExp and summitExp match up before most recent dateobs of chunk
    18762086    #be careful here, since dateobs is not quite completely the same in both tables. Therefore, allow numbers to be off by 1
     
    18902100        $rawdate=~/^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
    18912101        my $date1=DateTime->new(year=>$1,month=>$2,day=>$3,hour=>$4,minute=>$5,second=>$6,time_zone=>"UTC");
    1892   
     2102 
    18932103        $summitdate=~/^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
    18942104        my $date2=DateTime->new(year=>$1,month=>$2,day=>$3,hour=>$4,minute=>$5,second=>$6,time_zone=>"UTC");
     
    19032113    if (($summittimediff > 10.)||($noff >10)) {
    19042114        if ($debug == 1) {
    1905         print STDERR "desp_diff_queue: No desperate diffs will be attempted, since the number of exps at the summit and in rawExp do not match ($nsummitexps $nrawexps), or the timestamps are off ($summittimediff)\n";
     2115        print STDERR "desp_diff_queue: No desperate diffs will be attempted, since the number of exps at the summit and in rawExp do not match ($nsummitexps $nrawexps), or the timestamps are off ($summittimediff)\n";
    19062116        }
    19072117    }
    19082118    else {
    19092119        foreach my $object_row (@{ $object_ref }) {
    1910             my $this_object = shift @{ $object_row };
    1911             my $this_chunk = shift @{ $object_row };
    1912        
    1913             my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality FROM ";
    1914             $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
    1915             $input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
    1916             $input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs ";
    1917 
    1918             my $warps = $db->selectall_arrayref( $input_sth );
    1919 
    1920             # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra.
    1921             my %comment_hash = ();
    1922             foreach my $this_warp (@{ $warps }) {
    1923                 my $this_comment = ${ $this_warp }[3];
    1924                 my $this_exp_id  = ${ $this_warp }[0];
    1925                 my $this_quality = ${ $this_warp }[5];
    1926                 my $this_state   = ${ $this_warp }[4];
    1927                 if (($this_quality != 0) || ($this_state eq 'drop') ) {
    1928                     print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality or state $this_state\n";
    1929                 }
    1930                 else {
    1931                     $comment_hash{$this_comment} = $this_exp_id;
    1932                 }
    1933             }
    1934             # Exclude any warps that are not stored in the comment_hash.
    1935             my @keep_warps = ();
    1936             foreach my $this_warp (@{ $warps }) {
    1937                 my $this_comment = ${ $this_warp }[3];
    1938                 my $this_exp_id  = ${ $this_warp }[0];
    1939                 if ((exists($comment_hash{$this_comment}))&&
    1940                     ($comment_hash{$this_comment} == $this_exp_id)) {
    1941                     push @keep_warps, $this_warp;
    1942                 }
    1943                 else {
    1944                     print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object due to not being an accepted comment string $this_comment\n";
    1945                 }
    1946             }
    1947             # We are attempting to do the missing diffs, so reverse the list of retained warps.
    1948             # Good objects with all visits will be skipped due to the duplicate check.
    1949             # Bad objects will have the earliest visit rejected, and the visits repaired in a way that will produce all desired pairs.
    1950             @{ $warps } = reverse @keep_warps;
    1951                    
    1952             # Exclude the last entry if we do not have an even number of warps.
    1953             if (($#{ $warps } + 1) % 2 != 0) {
    1954                 print STDERR "desp_diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } ";
    1955                 if ($#{ $warps} + 1 == 1) {
    1956                     print STDERR ": I can do no diffs with only one exposure.\n";
    1957                     next;
    1958                 }
    1959                 else {
    1960                     my $rejected_warp = pop @{ $warps };
    1961                     my $rejected_exp_id = ${ $rejected_warp }[0];
    1962                     print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n";
    1963                 }
    1964             }
    1965        
    1966             while ($#{ $warps } > -1) {
    1967                 # In this mode, the array is sorted in pairs of template/input, counter to the standard queue.
    1968                 my $template_warp = shift @{ $warps };
    1969                 my $input_warp = shift @{ $warps };
    1970 
    1971                 my $input_exp_id = ${ $input_warp }[0];
    1972                 my $input_comment = ${ $input_warp }[3];
    1973 
    1974                 my $template_exp_id = ${ $template_warp }[0];
    1975                 my $template_comment = ${ $template_warp }[3];
    1976 
    1977                 my $input_warp_id = ${ $input_warp }[1];
    1978                 my $template_warp_id = ${ $template_warp }[1];
    1979 
    1980                 my $input_warp_state = ${ $input_warp }[4];
    1981                 my $template_warp_state = ${ $template_warp }[4];
    1982 
    1983                 my $input_warp_camQuality = ${ $input_warp }[5];
    1984                 my $template_warp_camQuality = ${ $template_warp }[5];
    1985 
    1986                 $Npotential++;
    1987 
    1988                 unless (defined($input_warp_id) && defined($template_warp_id) &&
    1989                         ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {
    1990                     print STDERR "Diff for this $date $target $input_exp_id $template_exp_id not fully processed ($input_warp_state $template_warp_state) ($input_warp_camQuality $template_warp_camQuality)\n";
    1991                     if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) {
    1992                         # This should now never be reached.
    1993                         # CZW: Trigger backup plan here?  Or simply set up framework?
    1994                         print STDERR "  ...but this is due to a camera stage astrometry quality\n";
    1995                         $Npotential--;
    1996                     }
    1997                     next;
    1998                 }
    1999 
    2000                 if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
    2001                     $Nqueued++;
    2002                     print STDERR "Diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
    2003                     next;
    2004                 }
    2005                 else {
    2006                     print STDERR "Preparing to diff $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
    2007                 }
     2120            my $this_object = shift @{ $object_row };
     2121            my $this_chunk = shift @{ $object_row };
     2122       
     2123            my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality,camProcessedExp.fwhm_major FROM ";
     2124            $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
     2125            $input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
     2126            $input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs ";
     2127
     2128            my $warps = $db->selectall_arrayref( $input_sth );
     2129            my $warpsBQ = $db->selectall_arrayref( $input_sth );;
     2130
     2131            # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra.
     2132            my %comment_hash = ();
     2133            my %comment_hash_good = ();
     2134            foreach my $this_warp (@{ $warps }) {
     2135                my $this_comment = ${ $this_warp }[3];
     2136                my $this_exp_id  = ${ $this_warp }[0];
     2137                my $this_quality = ${ $this_warp }[5];
     2138                my $this_state   = ${ $this_warp }[4];
     2139                my $this_fwhm    = ${ $this_warp }[7];
     2140                if (($this_quality != 0) || ($this_state eq 'drop') || ($this_fwhm > $maxFWHM)) {
     2141                    print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality or state $this_state or FWHM $this_fwhm\n";
     2142                }
     2143                else {
     2144                    $comment_hash_good{$this_comment} = $this_exp_id;
     2145                }
     2146               
     2147                #also save the entries which are ok, but not best quality
     2148                if (($this_quality == 0) && ($this_state ne 'drop') ) {
     2149                    $comment_hash{$this_comment} = $this_exp_id;
     2150                }
     2151            }
     2152
     2153            # Exclude any warps that are not stored in the comment_hash_good.
     2154            my @keep_warps = ();
     2155            foreach my $this_warp (@{ $warps }) {
     2156                my $this_comment = ${ $this_warp }[3];
     2157                my $this_exp_id  = ${ $this_warp }[0];
     2158                if ((exists($comment_hash_good{$this_comment}))&&
     2159                    ($comment_hash_good{$this_comment} == $this_exp_id)) {
     2160                    push @keep_warps, $this_warp;
     2161                    my $this_date  = ${ $this_warp }[2];
     2162                    my $chunk_name  = ${ $this_warp }[6];
     2163                }
     2164                else {
     2165                    print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object due to being rejected $this_comment\n";
     2166                }
     2167            }
     2168            @{ $warps } = @keep_warps;
     2169            my $nwarps = ($#{ $warps } + 1);
     2170
     2171            ################################
     2172            #We reach a junction here, where having more than 3 (but uneven) warps will result in desperate diffs
     2173            #Conversely, less than 3 warps might result in dirty diffs
     2174            ################################
     2175            if($nwarps >= 3) {     
     2176                # We are attempting to do the missing diffs, so reverse the list of retained warps.
     2177                # Good objects with all visits will be skipped due to the duplicate check.
     2178                # Bad objects will have the earliest visit rejected, and the visits repaired in a way that will produce all desired pairs.
     2179                @{ $warps } = reverse @keep_warps;
     2180
     2181                # Exclude the last entry if we do not have an even number of warps.
     2182                if (($#{ $warps } + 1) % 2 != 0) {
     2183                    print STDERR "desp_diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } ";
     2184                    if ($#{ $warps} + 1 == 1) {
     2185                        print STDERR ": I can do no diffs with only one exposure.\n";
     2186                        next;
     2187                    }
     2188                    else {
     2189                        my $rejected_warp = pop @{ $warps };
     2190                        my $rejected_exp_id = ${ $rejected_warp }[0];
     2191                        print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n";
     2192                    }
     2193                }
     2194       
     2195                while ($#{ $warps } > -1) {
     2196                    # The array is sorted in pairs of input/template.
     2197                    my $template_warp = shift @{ $warps };
     2198                    my $input_warp = shift @{ $warps };
     2199   
     2200                    my $input_exp_id = ${ $input_warp }[0];
     2201                    my $input_comment = ${ $input_warp }[3];
     2202
     2203                    my $template_exp_id = ${ $template_warp }[0];
     2204                    my $template_comment = ${ $template_warp }[3];
     2205
     2206                    my $input_warp_id = ${ $input_warp }[1];
     2207                    my $template_warp_id = ${ $template_warp }[1];
     2208
     2209                    my $input_warp_state = ${ $input_warp }[4];
     2210                    my $template_warp_state = ${ $template_warp }[4];
     2211
     2212                    my $input_warp_camQuality = ${ $input_warp }[5];
     2213                    my $template_warp_camQuality = ${ $template_warp }[5];
     2214
     2215                    $Npotential++;
     2216
     2217                    unless (defined($input_warp_id) && defined($template_warp_id) &&
     2218                        ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {
     2219                        print STDERR "Desp diff for this $date $target $input_exp_id $template_exp_id not fully processed ($input_warp_state $template_warp_state) ($input_warp_camQuality $template_warp_camQuality)\n";
     2220                        if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) {
     2221                            # This should now never be reached.
     2222                            # CZW: Trigger backup plan here?  Or simply set up framework?
     2223                            print STDERR "  ...but this is due to a camera stage astrometry quality\n";
     2224                            $Npotential--;
     2225                        }
     2226                        next;
     2227                    }
     2228
     2229                    if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
     2230                        $Nqueued++;
     2231                        print STDERR "Desp diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
     2232                        next;
     2233                    }
     2234                    else {
     2235                        print STDERR "Preparing to diff $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
     2236                    }
     2237           
     2238                    my $cmd = "$difftool -dbname $dbname  -definewarpwarp  ";
     2239                    $cmd .= "-input_label $label  -template_label $label -good_frac 0.1 ";
     2240                    $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.
     2241                    $cmd .= "-rerun "; # Needed because we may have some diffs that already use some of the exposures
     2242                    $cmd .= "-set_workdir $workdir  -set_dist_group $dist_group  -set_data_group $data_group ";
     2243                    $cmd .= " -simple  -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";
     2244                    if (defined($reduction)) {
     2245                        $cmd .= " -set_reduction $reduction ";
     2246                    }
     2247       
     2248                    if (defined($pretend)) {
     2249                        $cmd .= ' -pretend ';
     2250                    }
     2251                    if ($debug == 1) {
     2252                        $cmd .= ' -pretend ';
     2253                        print STDERR "desp_diff_queue: $cmd\n";
     2254                        print STDERR " $input_warp_id $template_warp_id\n";
     2255                    }
     2256           
     2257                    if (($debug == 0)&&(!defined($pretend))) {
     2258                        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     2259                            run ( command => $cmd, verbose => $verbose );
     2260                        unless ($success) {
     2261                            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     2262                            &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     2263                        }
     2264                        $Nqueued++;
     2265                    }
     2266                }           
     2267           
     2268            } else {       
     2269                print STDERR "desp_diff_queue: There is a possibility for dirty diffs to be made\n";
     2270                #Consider the case of on-the-fly dirty desperate diffs
     2271                #The conditions are: uneven nr of bad quality warps greater than 3, and the most recent observations is more than $desdiffdt hours old
     2272
     2273#                # Exclude any warps that are not stored in the more general comment_hash.
     2274#                my @keep_warps = ();
     2275#                foreach my $this_warp (@{ $warpsBQ }) {
     2276#                    my $this_comment = ${ $this_warp }[3];
     2277#                    my $this_exp_id  = ${ $this_warp }[0];
     2278#                    if ((exists($comment_hash{$this_comment}))&&
     2279#                        ($comment_hash{$this_comment} == $this_exp_id)) {
     2280#                        push @keep_warps, $this_warp;
     2281#                        my $this_date  = ${ $this_warp }[2];
     2282#                        my $chunk_name  = ${ $this_warp }[6];
     2283#                    }
     2284#                    else {
     2285#                        print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object due to being rejected $this_comment\n";
     2286#                    }
     2287#                }
     2288#                @{ $warpsBQ } = @keep_warps;
     2289#
     2290#                if ($nwarps >= 2) {
     2291#                    #one regular diff has already been made. So, need only one more. Strip a good entry from the array             
     2292#                    my $nrem = 0;
     2293#                    my @keep_warps = ();
     2294#                    foreach my $this_warp (@{ $warpsBQ }) {
     2295#                        my $this_comment = ${ $this_warp }[3];
     2296#                        my $this_exp_id  = ${ $this_warp }[0];
     2297#                        my $this_fwhm   = ${ $this_warp }[7];
     2298#                        if (($nrem <1) && ($this_fwhm <= $maxFWHM)) {
     2299#                            $nrem++;
     2300#                            print STDERR "desp_diff_queue: excluding $this_exp_id for $this_object from dirty desp diffs $this_comment\n";
     2301#                        } else {
     2302#                            push @keep_warps, $this_warp;                       
     2303#                        }
     2304#                    }
     2305#                    @{ $warpsBQ } = @keep_warps;
     2306#                }
     2307#
     2308#                # We are attempting to do the missing diffs, so reverse the list of retained warps.
     2309#                # Good objects with all visits will be skipped due to the duplicate check.
     2310#                # Bad objects will have the earliest visit rejected, and the visits repaired in a way that will produce all desired pairs.
     2311#                @{ $warpsBQ } = reverse @{ $warpsBQ };
     2312#
     2313#                # Exclude the last entry if we do not have an even number of warps.
     2314#                if (($#{ $warpsBQ } + 1) % 2 != 0) {
     2315#                    print STDERR "desp_diff_queue: Number of input warps to make dirty diffs is not even for target $target and object $this_object!";
     2316#                    my $rejected_warp = pop @{ $warpsBQ };
     2317#                    my $rejected_exp_id = ${ $rejected_warp }[0];
     2318#                    print STDERR ": Rejecting ${rejected_exp_id} to force visit count.\n";
     2319#                }
     2320#                my $nwarpsBQ = ($#{$warpsBQ} + 1);
     2321#       
     2322#               
     2323#                while ($#{ $warpsBQ } > -1) {
     2324#                    # The array is sorted in pairs of input/template.
     2325#                    my $template_warp = shift @{ $warpsBQ };
     2326#                    my $input_warp = shift @{ $warpsBQ };
     2327#   
     2328#                    my $input_exp_id = ${ $input_warp }[0];
     2329#                    my $input_comment = ${ $input_warp }[3];
     2330#
     2331#                    my $template_exp_id = ${ $template_warp }[0];
     2332#                    my $template_comment = ${ $template_warp }[3];
     2333#
     2334#                    my $input_warp_id = ${ $input_warp }[1];
     2335#                    my $template_warp_id = ${ $template_warp }[1];
     2336#
     2337#                    my $input_warp_state = ${ $input_warp }[4];
     2338#                    my $template_warp_state = ${ $template_warp }[4];
     2339#
     2340#                    my $input_warp_camQuality = ${ $input_warp }[5];
     2341#                    my $template_warp_camQuality = ${ $template_warp }[5];
     2342#
     2343#                    $Npotential++;
     2344#
     2345#                    unless (defined($input_warp_id) && defined($template_warp_id) &&
     2346#                        ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {
     2347#                        print STDERR "Desp diff for this $date $target $input_exp_id $template_exp_id not fully processed ($input_warp_state $template_warp_state) ($input_warp_camQuality $template_warp_camQuality)\n";
     2348#                        if (($input_warp_camQuality == 4007)||($template_warp_camQuality == 4007)) {
     2349#                            # This should now never be reached.
     2350#                            # CZW: Trigger backup plan here?  Or simply set up framework?
     2351#                            print STDERR "  ...but this is due to a camera stage astrometry quality\n";
     2352#                            $Npotential--;
     2353#                        }
     2354#                        next;
     2355#                    }
     2356#
     2357#                    if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
     2358#                        $Nqueued++;
     2359#                        print STDERR "Desp diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
     2360#                        next;
     2361#                    }
     2362#                    else {
     2363#                        print STDERR "Preparing to dirty diff $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment $template_comment\n";
     2364#                    }
     2365#           
     2366#                    my $cmd = "$difftool -dbname $dbname  -definewarpwarp  ";
     2367#                    $cmd .= "-input_label $label  -template_label $label -good_frac 0.1 ";
     2368#                    $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.
     2369#                    $cmd .= "-rerun "; # Needed because we may have some diffs that already use some of the exposures
     2370#                    $cmd .= "-set_workdir $workdir  -set_dist_group $dist_group  -set_data_group $data_group ";
     2371#                    $cmd .= " -simple  -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";
     2372#                    if (defined($reduction)) {
     2373#                        $cmd .= " -set_reduction $reduction ";
     2374#                    }
     2375#       
     2376#                    if (defined($pretend)) {
     2377#                        $cmd .= ' -pretend ';
     2378#                    }
     2379#                    if ($debug == 1) {
     2380#                        $cmd .= ' -pretend ';
     2381#                        print STDERR "desp_diff_queue: $cmd\n";
     2382#                        print STDERR " $input_warp_id $template_warp_id\n";
     2383#                    }
     2384#           
     2385#                    if (($debug == 0)&&(!defined($pretend))) {
     2386#                        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     2387#                            run ( command => $cmd, verbose => $verbose );
     2388#                        unless ($success) {
     2389#                            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     2390#                            &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     2391#                        }
     2392#                        $Nqueued++;
     2393#                    }
     2394#                }
    20082395           
    2009                 my $cmd = "$difftool -dbname $dbname  -definewarpwarp  ";
    2010                 $cmd .= "-input_label $label  -template_label $label -good_frac 0.1 ";
    2011                 $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.
    2012                 $cmd .= "-rerun "; # Needed because we may have some diffs that already use some of the exposures
    2013                 $cmd .= "-set_workdir $workdir  -set_dist_group $dist_group  -set_data_group $data_group ";
    2014                 $cmd .= " -simple  -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";
    2015 #                   $cmd .= " -pretend ";
    2016                 if (defined($reduction)) {
    2017                     $cmd .= " -set_reduction $reduction ";
    2018                 }
    2019 
    2020                 if (defined($pretend)) {
    2021                     $cmd .= ' -pretend ';
    2022                 }
    2023                 if ($debug == 1) {
    2024                     $cmd .= ' -pretend ';
    2025                     print STDERR "desp_diff_queue: $cmd\n";
    2026                     print STDERR " $input_warp_id $template_warp_id\n";
    2027                 }
    20282396           
    2029                 if (($debug == 0)&&(!defined($pretend))) {
    2030                     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    2031                         run ( command => $cmd, verbose => $verbose );
    2032                     unless ($success) {
    2033                         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    2034                         &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    2035                     }
    2036                     $Nqueued++;
    2037                 }
    2038             }
     2397           
     2398             }
    20392399        }
    20402400    }
    20412401    $metadata_out{nsDiffPotential} += $Npotential;
    20422402    $metadata_out{nsDiffQueued}    += $Nqueued;
    2043 #      if (($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued})&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')) {
    2044 #       $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
    2045 #      }       
    2046 
    20472403}
    20482404
     
    20642420    my $Npotential = 0;
    20652421    my $Nqueued = 0;
    2066     
     2422   
    20672423    foreach my $object_row (@{ $object_ref }) {
    2068         my $this_object = shift @{ $object_row };
    2069 #       my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";
    2070 #       $input_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
    2071 #       $input_sth .= " ORDER BY dateobs ";
    2072        
    2073         my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state FROM ";
    2074         $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
    2075         $input_sth .=   " WHERE warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
    2076         $input_sth .=   " ORDER BY dateobs ";
    2077 
    2078         my $warps = $db->selectall_arrayref( $input_sth );
    2079 
    2080         # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra.
    2081         my %comment_hash = ();
    2082         foreach my $this_warp (@{ $warps }) {
    2083             my $this_comment = ${ $this_warp }[3];
    2084             my $this_exp_id  = ${ $this_warp }[0];
    2085             $comment_hash{$this_comment} = $this_exp_id;
    2086         }
    2087        
    2088         if (($#{ $warps } + 1) % 2 != 0) {
    2089             print STDERR "md_diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } ";
    2090             if ($#{ $warps} + 1 == 1) {
    2091                 print STDERR ": I can do no diffs with only one exposure.\n";
    2092                 next;
    2093             }
    2094             else {
    2095                 print STDERR ": I should declare an exposure to be faulty.\n";
    2096                 my @keep_warps = ();
    2097 #               print "@{ $warps }\n";
    2098                 foreach my $this_warp (@{ $warps }) {
    2099                     my $this_comment = ${ $this_warp }[3];
    2100                     my $this_exp_id  = ${ $this_warp }[0];
    2101                     if ($comment_hash{$this_comment} == $this_exp_id) {
    2102                         push @keep_warps, $this_warp;
    2103                     }
    2104                     else {
    2105                         print STDERR "md_diff_queue: excluding $this_exp_id for $this_object\n";
    2106                     }
    2107                 }
    2108                 @{ $warps } = @keep_warps;
    2109 #               print "@{ $warps }\n";
    2110             }
    2111         }
    2112        
    2113         while ($#{ $warps } > -1) {
    2114             my $input_warp = shift @{ $warps };
    2115             my $input_exp_id = ${ $input_warp }[0];
    2116             my $input_comment = ${ $input_warp }[3];
    2117 
    2118            
    2119             my $template_warp = shift @{ $warps };
    2120 
    2121             my $template_exp_id = ${ $template_warp }[0];
    2122            
    2123             my $input_warp_id = ${ $input_warp }[1];
    2124             my $template_warp_id = ${ $template_warp }[1];
    2125 
    2126             my $input_warp_state = ${ $input_warp }[4];
    2127             my $template_warp_state = ${ $template_warp }[4];
    2128            
    2129             unless(defined($template_warp)&& defined($template_exp_id)) {
    2130                 print STDERR "md_diff received an undef! $input_exp_id $input_comment $this_object T: $template_warp V: @$template_warp\n";
    2131                 next;
    2132             }
    2133             $Npotential++;
    2134            
    2135             unless (defined($input_warp_id) && defined($template_warp_id) &&
    2136                     ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {
    2137                 print STDERR "md_Diff for this $date $target $input_exp_id ($input_warp_id $input_warp_state) $template_exp_id ($template_warp_id $template_warp_state) not fully processed\n";
    2138                 next;
    2139             }
    2140 
    2141             if (multi_date_verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
    2142                 $Nqueued++;
    2143                 print STDERR "md_Diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment\n";
    2144                 next;
    2145             }
    2146 
    2147             my $new_data_group = "${data_group}.multi";
    2148             my $cmd = "$difftool -dbname $dbname  -definewarpwarp ";
    2149             $cmd .= "-input_label $label  -template_label $label -good_frac 0.1 ";
    2150             $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.
    2151             $cmd .= "-set_workdir $workdir  -set_dist_group $dist_group  -set_data_group $new_data_group ";
    2152             $cmd .= " -simple  -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";
    2153             if (defined($reduction)) {
    2154                 $cmd .= " -set_reduction $reduction ";
    2155             }
    2156 
    2157 #               $cmd .= " -pretend ";
    2158             if (defined($pretend)) {
    2159                 $cmd .= ' -pretend ';
    2160             }
    2161             if ($debug == 1) {
    2162                 $cmd .= ' -pretend ';
    2163                 print STDERR "md_Diffs would like to queue for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment\n";
    2164                 print STDERR "md_diff_queue: $cmd\n";
    2165                 print STDERR " $input_warp_id $template_warp_id\n";
    2166             }
    2167            
    2168             if (($debug == 0)&&(!defined($pretend))) {
    2169                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    2170                     run ( command => $cmd, verbose => $verbose );
    2171                 unless ($success) {
    2172                     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    2173                     &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    2174                 }
    2175                 $Nqueued++;
    2176             }
    2177         }
     2424        my $this_object = shift @{ $object_row };
     2425#       my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";
     2426#       $input_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
     2427#       $input_sth .= " ORDER BY dateobs ";
     2428       
     2429        my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state FROM ";
     2430        $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
     2431        $input_sth .=   " WHERE warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
     2432        $input_sth .=   " ORDER BY dateobs ";
     2433
     2434        my $warps = $db->selectall_arrayref( $input_sth );
     2435
     2436        # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra.
     2437        my %comment_hash = ();
     2438        foreach my $this_warp (@{ $warps }) {
     2439            my $this_comment = ${ $this_warp }[3];
     2440            my $this_exp_id  = ${ $this_warp }[0];
     2441            $comment_hash{$this_comment} = $this_exp_id;
     2442        }
     2443       
     2444        if (($#{ $warps } + 1) % 2 != 0) {
     2445            print STDERR "md_diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } ";
     2446            if ($#{ $warps} + 1 == 1) {
     2447                print STDERR ": I can do no diffs with only one exposure.\n";
     2448                next;
     2449            }
     2450            else {
     2451                print STDERR ": I should declare an exposure to be faulty.\n";
     2452                my @keep_warps = ();
     2453#               print "@{ $warps }\n";
     2454                foreach my $this_warp (@{ $warps }) {
     2455                    my $this_comment = ${ $this_warp }[3];
     2456                    my $this_exp_id  = ${ $this_warp }[0];
     2457                    if ($comment_hash{$this_comment} == $this_exp_id) {
     2458                        push @keep_warps, $this_warp;
     2459                    }
     2460                    else {
     2461                        print STDERR "md_diff_queue: excluding $this_exp_id for $this_object\n";
     2462                    }
     2463                }
     2464                @{ $warps } = @keep_warps;
     2465#               print "@{ $warps }\n";
     2466            }
     2467        }
     2468       
     2469        while ($#{ $warps } > -1) {
     2470            my $input_warp = shift @{ $warps };
     2471            my $input_exp_id = ${ $input_warp }[0];
     2472            my $input_comment = ${ $input_warp }[3];
     2473
     2474          
     2475            my $template_warp = shift @{ $warps };
     2476
     2477            my $template_exp_id = ${ $template_warp }[0];
     2478          
     2479            my $input_warp_id = ${ $input_warp }[1];
     2480            my $template_warp_id = ${ $template_warp }[1];
     2481
     2482            my $input_warp_state = ${ $input_warp }[4];
     2483            my $template_warp_state = ${ $template_warp }[4];
     2484          
     2485            unless(defined($template_warp)&& defined($template_exp_id)) {
     2486                print STDERR "md_diff received an undef! $input_exp_id $input_comment $this_object T: $template_warp V: @$template_warp\n";
     2487                next;
     2488            }
     2489            $Npotential++;
     2490          
     2491            unless (defined($input_warp_id) && defined($template_warp_id) &&
     2492                    ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {
     2493                print STDERR "md_Diff for this $date $target $input_exp_id ($input_warp_id $input_warp_state) $template_exp_id ($template_warp_id $template_warp_state) not fully processed\n";
     2494                next;
     2495            }
     2496
     2497            if (multi_date_verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
     2498                $Nqueued++;
     2499                print STDERR "md_Diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment\n";
     2500                next;
     2501            }
     2502
     2503            my $new_data_group = "${data_group}.multi";
     2504            my $cmd = "$difftool -dbname $dbname  -definewarpwarp ";
     2505            $cmd .= "-input_label $label  -template_label $label -good_frac 0.1 ";
     2506            $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.
     2507            $cmd .= "-set_workdir $workdir  -set_dist_group $dist_group  -set_data_group $new_data_group ";
     2508            $cmd .= " -simple  -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";
     2509            if (defined($reduction)) {
     2510                $cmd .= " -set_reduction $reduction ";
     2511            }
     2512
     2513#               $cmd .= " -pretend ";
     2514            if (defined($pretend)) {
     2515                $cmd .= ' -pretend ';
     2516            }
     2517            if ($debug == 1) {
     2518                $cmd .= ' -pretend ';
     2519                print STDERR "md_Diffs would like to queue for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment\n";
     2520                print STDERR "md_diff_queue: $cmd\n";
     2521                print STDERR " $input_warp_id $template_warp_id\n";
     2522            }
     2523          
     2524            if (($debug == 0)&&(!defined($pretend))) {
     2525                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     2526                    run ( command => $cmd, verbose => $verbose );
     2527                unless ($success) {
     2528                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     2529                    &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     2530                }
     2531                $Nqueued++;
     2532            }
     2533        }
    21782534    }
    21792535    $metadata_out{nsDiffPotential} += $Npotential;
    21802536    $metadata_out{nsDiffQueued}    += $Nqueued;
    21812537#      if (($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued})&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')) {
    2182      $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
    2183 #      }       
     2538     $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
     2539#      }       
    21842540
    21852541}
     
    22002556
    22012557
    2202 # Get a list of exposures that could be diffed    
     2558# Get a list of exposures that could be diffed   
    22032559    my $new_data_group = "${data_group}.offnight";
    22042560    my $new_dist_group = "${dist_group}.offnight";
     
    22102566    $check_cmd .= " -dateobs_begin ${lunation_start}T00:00:00 -dateobs_end ${lunation_end}T23:59:59 -distance 1.5 ";
    22112567    if (defined($reduction)) {
    2212         $check_cmd .= " -set_reduction $reduction ";
     2568        $check_cmd .= " -set_reduction $reduction ";
    22132569    }
    22142570
    22152571    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    2216         run ( command => $check_cmd, verbose => $verbose );
     2572        run ( command => $check_cmd, verbose => $verbose );
    22172573    unless ($success) {
    2218         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    2219         &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    2220     }
    2221     
     2574        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     2575        &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     2576    }
     2577   
    22222578    # Parse results
    22232579    my $diffs = $mdcParser->parse_list(join "", @$stdout_buf) or
    2224         &my_die("Unable to parse metadata from difftool -definewarpwarp", 0, 0, $date, $PS_EXIT_PROG_ERROR);
     2580        &my_die("Unable to parse metadata from difftool -definewarpwarp", 0, 0, $date, $PS_EXIT_PROG_ERROR);
    22252581    foreach my $diff (@$diffs) {
    2226         unless (multi_date_verify_uniqueness_diff($diff->{input_warp_id},$diff->{template_warp_id},$date,$target)) {
    2227             # If we don't already have a diff with these inputs, make a diff with these inputs.
    2228             my $cmd = "$difftool -dbname $dbname -definewarpwarp -good_frac 0.1 ";
    2229             $cmd   .= "-input_label $label -template_label $label ";
    2230             $cmd   .= "-warp_id $diff->{input_warp_id} -template_warp_id $diff->{template_warp_id} ";
    2231             $cmd .= "-set_workdir $workdir  -set_dist_group $new_dist_group  -set_data_group $new_data_group ";
    2232             $cmd .= " -mintimediff 40000 ";
    2233             $cmd .= " -simple  -rerun -set_label $label -filter $filter ";
    2234             $cmd .= " -dateobs_begin ${lunation_start}T00:00:00 -dateobs_end ${lunation_end}T23:59:59 -distance 1.5 ";
    2235             if (defined($reduction)) {
    2236                 $cmd .= " -set_reduction $reduction ";
    2237             }
    2238 
    2239             if (defined($pretend)) {
    2240                 $cmd .= ' -pretend ';
    2241             }
    2242             print STDERR "ON_diffs wants to run this command: $cmd\n";
    2243            
    2244             if (($debug == 0)&&(!defined($pretend))) {
    2245                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    2246                     run ( command => $cmd, verbose => $verbose );
    2247                 unless ($success) {
    2248                     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    2249                     &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    2250                 }
    2251             }
    2252         }
     2582        unless (multi_date_verify_uniqueness_diff($diff->{input_warp_id},$diff->{template_warp_id},$date,$target)) {
     2583            # If we don't already have a diff with these inputs, make a diff with these inputs.
     2584            my $cmd = "$difftool -dbname $dbname -definewarpwarp -good_frac 0.1 ";
     2585            $cmd   .= "-input_label $label -template_label $label ";
     2586            $cmd   .= "-warp_id $diff->{input_warp_id} -template_warp_id $diff->{template_warp_id} ";
     2587            $cmd .= "-set_workdir $workdir  -set_dist_group $new_dist_group  -set_data_group $new_data_group ";
     2588            $cmd .= " -mintimediff 40000 ";
     2589            $cmd .= " -simple  -rerun -set_label $label -filter $filter ";
     2590            $cmd .= " -dateobs_begin ${lunation_start}T00:00:00 -dateobs_end ${lunation_end}T23:59:59 -distance 1.5 ";
     2591            if (defined($reduction)) {
     2592                $cmd .= " -set_reduction $reduction ";
     2593            }
     2594
     2595            if (defined($pretend)) {
     2596                $cmd .= ' -pretend ';
     2597            }
     2598            print STDERR "ON_diffs wants to run this command: $cmd\n";
     2599          
     2600            if (($debug == 0)&&(!defined($pretend))) {
     2601                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     2602                    run ( command => $cmd, verbose => $verbose );
     2603                unless ($success) {
     2604                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     2605                    &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     2606                }
     2607            }
     2608        }
    22532609    }
    22542610}
     
    22642620    my ($stacks_to_finish,$stacks_total) = check_stack_count($label);
    22652621    if (($stacks_to_finish == 0)&&($stacks_total != 0)) {
    2266         my $cmd = "$difftool -dbname $dbname -definewarpstack ";
    2267         $cmd .= " -good_frac 0.2 ";
    2268         $cmd .= " -warp_label $label -stack_label $label -set_label $label ";
    2269         $cmd .= " -set_workdir $workdir -available -set_reduction WARPSTACK -set_dist_group $dist_group ";
    2270         $cmd .= " -rerun ";
    2271     }
    2272 }          
     2622        my $cmd = "$difftool -dbname $dbname -definewarpstack ";
     2623        $cmd .= " -good_frac 0.2 ";
     2624        $cmd .= " -warp_label $label -stack_label $label -set_label $label ";
     2625        $cmd .= " -set_workdir $workdir -available -set_reduction WARPSTACK -set_dist_group $dist_group ";
     2626        $cmd .= " -rerun ";
     2627    }
     2628}          
    22732629
    22742630sub check_stack_count {
     
    23012657    my $retention_time;
    23022658    if (exists($science_config{$target}{$mode})) {
    2303         $retention_time = $science_config{$target}{$mode};
     2659        $retention_time = $science_config{$target}{$mode};
    23042660    }
    23052661    else {
    2306         $retention_time = $clean_config{$mode}{RETENTION_TIME};
     2662        $retention_time = $clean_config{$mode}{RETENTION_TIME};
    23072663    }
    23082664    if ($retention_time <= 0) {
    2309         return("no clean","true");
     2665        return("no clean","true");
    23102666    }
    23112667
    23122668    my ($year,$month,$day) = split /-/,$date;
    23132669    my $dt = DateTime->new(year => $year, month => $month, day => $day,
    2314                            hour => 0, minute => 0, second => 0, nanosecond => 0,
    2315                            time_zone => 'Pacific/Honolulu');
    2316        
     2670                           hour => 0, minute => 0, second => 0, nanosecond => 0,
     2671                           time_zone => 'Pacific/Honolulu');
     2672       
    23172673    $dt->subtract(days => $retention_time);
    23182674    my $cleaning_date = $dt->ymd;
    23192675
    23202676    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($cleaning_date,$target);
    2321     
     2677   
    23222678    $command =~ s/\@DBNAME\@/$dbname/;
    23232679    $command =~ s/\@LABEL\@/$label/;
     
    23302686    $command =~ s/\@REDUCTION\@/$reduction/;
    23312687    $command =~ s/\@CURRENT_DATE\@/$cleaning_date/;
    2332     
     2688   
    23332689    if ($debug == 1) {
    23342690        $command .= ' -pretend ';
     
    23422698
    23432699    foreach my $mode (sort (keys %clean_config)) {
    2344         foreach my $target (sort (keys %science_config)) {
    2345             if (exists($science_config{$target}{NOCLEAN})) {
    2346                 next;
    2347             }
    2348             my ($cleaning_date,$command) = construct_cleantool_args($date,$target,$mode);
    2349 
    2350             if ($cleaning_date eq 'no clean') {
    2351                 next;
    2352             }           
    2353             print STDERR "$command\n";
    2354             if (!(defined($pretend) || $debug == 1)) {
     2700        foreach my $target (sort (keys %science_config)) {
     2701            if (exists($science_config{$target}{NOCLEAN})) {
     2702                next;
     2703            }
     2704            my ($cleaning_date,$command) = construct_cleantool_args($date,$target,$mode);
     2705
     2706            if ($cleaning_date eq 'no clean') {
     2707                next;
     2708            }           
     2709            print STDERR "$command\n";
     2710            if (!(defined($pretend) || $debug == 1)) {
    23552711#           print STDERR "BEAR IS DRIVING!?\n";
    2356                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    2357                     run ( command => $command, verbose => $verbose );
    2358                 unless ($success) {
    2359                     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    2360                     &my_die("Unable to perform cleantool ($command): $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    2361                 }
    2362                 add_to_macro_list('clean_old',1,$date,$target,$mode);
    2363             }
    2364             if ($mode eq 'DIFF') {
    2365                 my $WS_command = $command;
    2366                 $WS_command =~ s/$target/${target}.WS/;
    2367                 print STDERR "$WS_command\n";
    2368                 if (!(defined($pretend) || $debug == 1)) {
    2369                    
    2370                     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    2371                         run ( command => $WS_command, verbose => $verbose );
    2372                     unless ($success) {
    2373                         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    2374                         &my_die("Unable to perform cleantool ($WS_command): $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    2375                     }
    2376                 }
    2377             }
    2378 
    2379         }
     2712                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     2713                    run ( command => $command, verbose => $verbose );
     2714                unless ($success) {
     2715                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     2716                    &my_die("Unable to perform cleantool ($command): $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     2717                }
     2718                add_to_macro_list('clean_old',1,$date,$target,$mode);
     2719            }
     2720            if ($mode eq 'DIFF') {
     2721                my $WS_command = $command;
     2722                $WS_command =~ s/$target/${target}.WS/;
     2723                print STDERR "$WS_command\n";
     2724                if (!(defined($pretend) || $debug == 1)) {
     2725                  
     2726                    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     2727                        run ( command => $WS_command, verbose => $verbose );
     2728                    unless ($success) {
     2729                        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     2730                        &my_die("Unable to perform cleantool ($WS_command): $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     2731                    }
     2732                }
     2733            }
     2734
     2735        }
    23802736    }
    23812737    return(0);
     
    23892745    my $date = shift;
    23902746    my $eon_dt = DateTime->new( year   => $datetime->year,
    2391                                 month  => $datetime->month,
    2392                                 day    => $datetime->day,
    2393                                 hour   => 17, # 7,
    2394                                 minute => 30,
    2395                                 second => 0,
    2396                                 time_zone => 'UTC');
    2397     
     2747                                month  => $datetime->month,
     2748                                day    => $datetime->day,
     2749                                hour   => 17, # 7,
     2750                                minute => 30,
     2751                                second => 0,
     2752                                time_zone => 'UTC');
     2753   
    23982754    foreach my $eon (keys %eon_config) {
    2399         my $command = "$regtool -processedexp -simple ";
    2400         $command .= " -dbname $dbname ";
    2401         $command .= " -dateobs_begin ${date}T00:00:00 -dateobs_end ${date}T23:59:59 ";
    2402         $command .= " -object $eon_config{$eon}{OBJECT} " if defined($eon_config{$eon}{OBJECT});
    2403         $command .= " -obs_mode $eon_config{$eon}{OBSMODE} " if defined($eon_config{$eon}{OBSMODE});
    2404         $command .= " -exp_type $eon_config{$eon}{EXPTYPE} " if defined($eon_config{$eon}{EXPTYPE});
    2405         $command .= " -comment $eon_config{$eon}{COMMENT} " if defined($eon_config{$eon}{COMMENT});
    2406 
    2407         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    2408             run ( command => $command, verbose => $verbose );
    2409         unless ($success) {
    2410             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    2411             &my_die("Unable to perform regtool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    2412         }
    2413         my @eon_exposures = split /\n/, (join '', @$stdout_buf);
    2414         if ($#eon_exposures >= 0) {
    2415             return("END_OF_NIGHT");
    2416         }
    2417     }   
     2755        my $command = "$regtool -processedexp -simple ";
     2756        $command .= " -dbname $dbname ";
     2757        $command .= " -dateobs_begin ${date}T00:00:00 -dateobs_end ${date}T23:59:59 ";
     2758        $command .= " -object $eon_config{$eon}{OBJECT} " if defined($eon_config{$eon}{OBJECT});
     2759        $command .= " -obs_mode $eon_config{$eon}{OBSMODE} " if defined($eon_config{$eon}{OBSMODE});
     2760        $command .= " -exp_type $eon_config{$eon}{EXPTYPE} " if defined($eon_config{$eon}{EXPTYPE});
     2761        $command .= " -comment $eon_config{$eon}{COMMENT} " if defined($eon_config{$eon}{COMMENT});
     2762
     2763        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     2764            run ( command => $command, verbose => $verbose );
     2765        unless ($success) {
     2766            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     2767            &my_die("Unable to perform regtool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     2768        }
     2769        my @eon_exposures = split /\n/, (join '', @$stdout_buf);
     2770        if ($#eon_exposures >= 0) {
     2771            return("END_OF_NIGHT");
     2772        }
     2773    }   
    24182774    if ($force_registration) {
    2419         return("END_OF_NIGHT");
     2775        return("END_OF_NIGHT");
    24202776    }
    24212777#    print "$now $eon_dt " . DateTime->compare($now,$eon_dt) . "\n";
    24222778    if (DateTime->compare($now,$eon_dt) < 1) {
    2423         return("OBSERVING");
     2779        return("OBSERVING");
    24242780    }
    24252781    else {
    2426         return("END_OF_NIGHT");
     2782        return("END_OF_NIGHT");
    24272783    }
    24282784}
     
    24332789
    24342790    foreach my $eon (keys %eon_config) {
    2435         my $command = "$regtool -processedexp -simple ";
    2436         $command .= " -dbname $dbname ";
    2437         $command .= " -dateobs_begin ${date}T00:00:00 -dateobs_end ${date}T23:59:59 ";
    2438         $command .= " -object $eon_config{$eon}{OBJECT} " if defined($eon_config{$eon}{OBJECT});
    2439         $command .= " -obs_mode $eon_config{$eon}{OBSMODE} " if defined($eon_config{$eon}{OBSMODE});
    2440         $command .= " -exp_type $eon_config{$eon}{EXPTYPE} " if defined($eon_config{$eon}{EXPTYPE});
    2441         $command .= " -comment $eon_config{$eon}{COMMENT} " if defined($eon_config{$eon}{COMMENT});
    2442 
    2443         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    2444             run ( command => $command, verbose => $verbose );
    2445         unless ($success) {
    2446             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    2447             &my_die("Unable to perform regtool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    2448         }
    2449         my @eon_exposures = split /\n/, (join '', @$stdout_buf);
    2450         if ($#eon_exposures >= 0) {
    2451             return("REGISTERED");
    2452         }
    2453     }   
     2791        my $command = "$regtool -processedexp -simple ";
     2792        $command .= " -dbname $dbname ";
     2793        $command .= " -dateobs_begin ${date}T00:00:00 -dateobs_end ${date}T23:59:59 ";
     2794        $command .= " -object $eon_config{$eon}{OBJECT} " if defined($eon_config{$eon}{OBJECT});
     2795        $command .= " -obs_mode $eon_config{$eon}{OBSMODE} " if defined($eon_config{$eon}{OBSMODE});
     2796        $command .= " -exp_type $eon_config{$eon}{EXPTYPE} " if defined($eon_config{$eon}{EXPTYPE});
     2797        $command .= " -comment $eon_config{$eon}{COMMENT} " if defined($eon_config{$eon}{COMMENT});
     2798
     2799        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     2800            run ( command => $command, verbose => $verbose );
     2801        unless ($success) {
     2802            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     2803            &my_die("Unable to perform regtool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     2804        }
     2805        my @eon_exposures = split /\n/, (join '', @$stdout_buf);
     2806        if ($#eon_exposures >= 0) {
     2807            return("REGISTERED");
     2808        }
     2809    }   
    24542810    return("NOT_REGISTERED");
    24552811}
    24562812
    2457     
     2813   
    24582814
    24592815sub get_tool_parameters {
     
    24892845    my $internal_filter;
    24902846    if (defined($det_filter)) {
    2491         $internal_filter = $det_filter; $internal_filter =~ s/\..*//;
    2492         $internal_filter = '.' . $internal_filter;
     2847        $internal_filter = $det_filter; $internal_filter =~ s/\..*//;
     2848        $internal_filter = '.' . $internal_filter;
    24932849    }
    24942850    else {
    2495         $internal_filter = '';
     2851        $internal_filter = '';
    24962852    }
    24972853    unless (defined($maxN)) {
    2498         $maxN = 0;
     2854        $maxN = 0;
    24992855    }
    25002856    my $lc_type = lc($exp_type);
     
    25122868
    25132869    if ((defined($macro_config{$proc_mode}))&&($do_or_do_not)) {
    2514         unless (defined($metadata_out{N_MACROS})) {
    2515             $metadata_out{N_MACROS} = 0;
    2516         }
    2517         my $N = $metadata_out{N_MACROS};
    2518         $metadata_out{"ns${N}Macro"} = $macro_config{$proc_mode};
    2519         if ($debug == 1) {
    2520             print STDERR "WORKING ON A MACRO: ns${N}Macro $proc_mode $macro_config{$proc_mode}\n";
    2521         }
    2522         if (defined($date)&&(defined($target))) {
    2523 
    2524             my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction)
    2525                 = get_tool_parameters($date,$target);
    2526             $metadata_out{"ns${N}Macro"} =~ s/\@LABEL\@/$label/;
    2527             $metadata_out{"ns${N}Macro"} =~ s/\@WORKDIR\@/$workdir/;
    2528             $metadata_out{"ns${N}Macro"} =~ s/\@OBSMODE\@/$obs_mode/;
    2529             $metadata_out{"ns${N}Macro"} =~ s/\@OBJECT\@/$object/;
    2530             $metadata_out{"ns${N}Macro"} =~ s/\@COMMENT\@/$comment/;
    2531             $metadata_out{"ns${N}Macro"} =~ s/\@TESS_ID\@/$tess_id/;
    2532             $metadata_out{"ns${N}Macro"} =~ s/\@DIST_GROUP\@/$dist_group/;
    2533             $metadata_out{"ns${N}Macro"} =~ s/\@DATA_GROUP\@/$data_group/;
    2534             $metadata_out{"ns${N}Macro"} =~ s/\@REDUCTION\@/$reduction/;
    2535         }
    2536         if (defined($mode)) {
    2537             $metadata_out{"ns${N}Macro"} =~ s/\@EXTRA\@/$mode/;
    2538         }
    2539         if (defined($date)) {
    2540             $metadata_out{"ns${N}Macro"} =~ s/\@DATE\@/$date/;
    2541         }
    2542         if ($debug == 1) {
    2543             print STDERR "DONE WITH A MACRO: ns${N}Macro $proc_mode $macro_config{$proc_mode}\n";
    2544         }
    2545         $metadata_out{N_MACROS} ++;
     2870        unless (defined($metadata_out{N_MACROS})) {
     2871            $metadata_out{N_MACROS} = 0;
     2872        }
     2873        my $N = $metadata_out{N_MACROS};
     2874        $metadata_out{"ns${N}Macro"} = $macro_config{$proc_mode};
     2875        if ($debug == 1) {
     2876            print STDERR "WORKING ON A MACRO: ns${N}Macro $proc_mode $macro_config{$proc_mode}\n";
     2877        }
     2878        if (defined($date)&&(defined($target))) {
     2879
     2880            my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction)
     2881                = get_tool_parameters($date,$target);
     2882            $metadata_out{"ns${N}Macro"} =~ s/\@LABEL\@/$label/;
     2883            $metadata_out{"ns${N}Macro"} =~ s/\@WORKDIR\@/$workdir/;
     2884            $metadata_out{"ns${N}Macro"} =~ s/\@OBSMODE\@/$obs_mode/;
     2885            $metadata_out{"ns${N}Macro"} =~ s/\@OBJECT\@/$object/;
     2886            $metadata_out{"ns${N}Macro"} =~ s/\@COMMENT\@/$comment/;
     2887            $metadata_out{"ns${N}Macro"} =~ s/\@TESS_ID\@/$tess_id/;
     2888            $metadata_out{"ns${N}Macro"} =~ s/\@DIST_GROUP\@/$dist_group/;
     2889            $metadata_out{"ns${N}Macro"} =~ s/\@DATA_GROUP\@/$data_group/;
     2890            $metadata_out{"ns${N}Macro"} =~ s/\@REDUCTION\@/$reduction/;
     2891        }
     2892        if (defined($mode)) {
     2893            $metadata_out{"ns${N}Macro"} =~ s/\@EXTRA\@/$mode/;
     2894        }
     2895        if (defined($date)) {
     2896            $metadata_out{"ns${N}Macro"} =~ s/\@DATE\@/$date/;
     2897        }
     2898        if ($debug == 1) {
     2899            print STDERR "DONE WITH A MACRO: ns${N}Macro $proc_mode $macro_config{$proc_mode}\n";
     2900        }
     2901        $metadata_out{N_MACROS} ++;
    25462902    }
    25472903}
  • trunk/ippTools/src/pztoolConfig.c

    r42154 r42229  
    171171    psMetadataAddStr(updatepzexpArgs, PS_LIST_TAIL, "-set_state",  0,            "define new state (required)", NULL);
    172172   
     173# if (0)
    173174    // -updatesummitexp
    174175    psMetadata *updatesummitexpArgs = psMetadataAlloc();
     
    178179    psMetadataAddStr(updatesummitexpArgs, PS_LIST_TAIL, "-telescope",  0,            "search by telescope (required)", NULL);
    179180    psMetadataAddS32(updatesummitexpArgs, PS_LIST_TAIL, "-set_fault",  0,            "define new fault (required)", 0);
     181# endif
    180182   
    181183    // -updatenewexp
  • trunk/ippconfig/recipes/psastro.config

    r42109 r42229  
    244244# maximum allowed fwhm_major (moved from */camera.config)
    245245PSASTRO.MAX.ALLOWED.FWHM    F32     0
     246PSASTRO.MAX.PROCESS.FWHM    F32     30
    246247
    247248#PSASTRO.CATDIR                STR      PS1.REF.20140713
  • trunk/ppViz/src/ppCoord/ppCoord.h

    r42154 r42229  
    1414    psString rawName;                   // Filename with raw image (or NULL)
    1515    psString pixelsName;                // Filename with pixel coordinates
    16     psString fpaName;                   // Filename with FPA coordinates
    1716    psString chipName;                  // Name of chip of interest
    1817    psString radecName;                 // Filename with sky coordinates
  • trunk/ppViz/src/ppCoord/ppCoordArguments.c

    r42154 r42229  
    4949    psMetadataAddStr(arguments, PS_LIST_TAIL, "-raw", 0, "Filename with raw data", NULL);
    5050    psMetadataAddStr(arguments, PS_LIST_TAIL, "-pixels", 0, "Filename with pixel coordinates", NULL);
    51     psMetadataAddStr(arguments, PS_LIST_TAIL, "-fpa", 0, "Filename with FPA coordinates", NULL);
    5251    psMetadataAddStr(arguments, PS_LIST_TAIL, "-chip", 0, "Chip for pixel coordinates", NULL);
    5352    psMetadataAddStr(arguments, PS_LIST_TAIL, "-radec", 0, "Filename with RA,Dec (default decimal degrees)", NULL);
     
    6766    data->rawName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-raw"));
    6867    data->pixelsName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-pixels"));
    69     data->fpaName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-fpa"));
    7068    data->chipName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-chip"));
    7169    data->radecName = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-radec"));
     
    9896    }
    9997
    100     if (!data->pixelsName && !data->radecName && !data->fpaName && !data->streaksName && !data->clustersName) {
    101         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Neither -pixels nor -radec nor -fpa provided.");
     98    if (!data->pixelsName && !data->radecName && !data->streaksName && !data->clustersName) {
     99        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Neither -pixels nor -radec provided.");
    102100        return false;
    103101    }
  • trunk/ppViz/src/ppCoord/ppCoordData.c

    r42154 r42229  
    1616    psFree(data->rawName);
    1717    psFree(data->pixelsName);
    18     psFree(data->fpaName);
    1918    psFree(data->chipName);
    2019    psFree(data->radecName);
     
    3837    data->rawName = NULL;
    3938    data->pixelsName = NULL;
    40     data->fpaName = NULL;
    4139    data->chipName = NULL;
    4240    data->radecName = NULL;
  • trunk/ppViz/src/ppCoord/ppCoordLoop.c

    r42154 r42229  
    7979        NULL; // File with raw image
    8080
    81     psArray *pixels = NULL, *radec = NULL, *fpas = NULL, *streaks = NULL, *clusters = NULL; // Array of coordinate vectors
    82     psArray *radecOut = NULL,*fpaOut = NULL, *streaksOut = NULL, *clustersOut = NULL;        // Output for sky coordinates
     81    psArray *pixels = NULL, *radec = NULL, *streaks = NULL, *clusters = NULL; // Array of coordinate vectors
     82    psArray *radecOut = NULL, *streaksOut = NULL, *clustersOut = NULL;        // Output for sky coordinates
    8383    if (data->pixelsName) {
    8484        pixels = psVectorsReadFromFile(data->pixelsName, "%f %f");
     
    107107        psVectorInit(radecOut->data[1], NAN);
    108108        psVectorInit(radecOut->data[2], NAN);
    109     }
    110 
    111     if (data->fpaName) {
    112         fpas = psVectorsReadFromFile(data->fpaName, "%f %f");
    113         if (!fpas || fpas->n != 2) {
    114             psError(psErrorCodeLast(), false, "Unable to read FPA coordinates");
    115             return false;
    116         }
    117         psVector *fpa_x = fpas->data[0];  // FPA x coordinates
    118         long num = fpa_x->n;               // Number of coordinates
    119         fpaOut = psArrayAlloc(6);
    120         fpaOut->data[0] = psArrayAlloc(num);
    121         fpaOut->data[1] = psVectorAlloc(num, PS_TYPE_F32);
    122         fpaOut->data[2] = psVectorAlloc(num, PS_TYPE_F32);
    123         fpaOut->data[3] = psArrayAlloc(num);
    124         fpaOut->data[4] = psVectorAlloc(num, PS_TYPE_F32);
    125         fpaOut->data[5] = psVectorAlloc(num, PS_TYPE_F32);
    126         psVectorInit(fpaOut->data[1], NAN);
    127         psVectorInit(fpaOut->data[2], NAN);
    128         psVectorInit(fpaOut->data[4], NAN);
    129         psVectorInit(fpaOut->data[5], NAN);
    130109    }
    131110
     
    415394                yTP->data.F32[i] = src.tp.y;
    416395            }
    417         }
    418 
    419         if (fpas) {
    420             psVector *fpa_x = fpas->data[0], *fpa_y = fpas->data[1]; // FPA coordinates
    421             long num = fpa_x->n;                                     // Number of coordinates
    422 
    423             int numCols = psMetadataLookupS32(NULL, hdu->header, "IMNAXIS1"); // Number of columns
    424             int numRows = psMetadataLookupS32(NULL, hdu->header, "IMNAXIS2"); // Number of rows
    425             if (numCols <= 0 || numRows <= 0) {
    426                 psError(psErrorCodeLast(), false, "Unable to read size of chip.");
    427                 return false;
    428             }
    429 
    430             psArray *chipPix = fpaOut->data[0]; // Chip for pixels
    431             psVector *xPix = fpaOut->data[1];   // x coordinate for pixels
    432             psVector *yPix = fpaOut->data[2];   // y coordinate for pixels
    433             psArray *cellPix = fpaOut->data[3]; // Cell for pixels
    434             psVector *xCell = fpaOut->data[4];   // x coordinate for cell
    435             psVector *yCell = fpaOut->data[5];   // y coordinate for cell
    436 
    437             psPlane *pix = psPlaneAlloc();   // Pixel coordinates on chip
    438             psPlane *fp = psPlaneAlloc();    // Focal plane coordinates
    439 
    440             for (long i = 0; i < num; i++) {
    441                 float x, y;             // Pixel coordinates
    442                 fp->x = fpa_x->data.F32[i];
    443                 fp->y = fpa_y->data.F32[i];
    444 
    445                 psPlaneTransformApply(pix, chip->fromFPA, fp);
    446                 psTrace("ppCoord",2,"fpa2pix tr1: %f %f\n",pix->x,pix->y);
    447 
    448                 x = pix->x;
    449                 y = pix->y;
    450 
    451                 if ((x < 0 || x > numCols || y < 0 || y > numRows)) {
    452                     // Not on this chip
    453                     continue;
    454                 }
    455 
    456                 chipPix->data[i] = psStringCopy(chipName);
    457                 xPix->data.F32[i] = x;
    458                 yPix->data.F32[i] = y;
    459 
    460                 if (rawChip) {
    461                     psString cellName = NULL; // Name of cell
    462                     coordChip2Cell(&cellName, &x, &y, x, y, cellNames, cellBounds,
    463                                    cellX0, cellY0, cellParityX, cellParityY, cellBinX, cellBinY);
    464                     cellPix->data[i] = cellName;
    465                     xCell->data.F32[i] = x;
    466                     yCell->data.F32[i] = y;
    467                 }
    468 
    469             }
    470             psFree(pix);
    471             psFree(fp);
    472396        }
    473397
     
    632556    }
    633557
    634     if (fpaOut) {
    635         psArray *chipPix = fpaOut->data[0]; // Chip for pixels
    636         psVector *xPix = fpaOut->data[1];   // x coordinate for pixels
    637         psVector *yPix = fpaOut->data[2];   // y coordinate for pixels
    638         psArray *cellPix = fpaOut->data[3]; // Cell for pixels
    639         psVector *xCell = fpaOut->data[4];   // x coordinate for pixels
    640         psVector *yCell = fpaOut->data[5];   // y coordinate for pixels
    641         psVector *fpa_x = fpas->data[0];        // FPA x coordinate
    642         psVector *fpa_y = fpas->data[1];       // FPA y coordinate
    643 
    644         for (long i = 0; i < chipPix->n; i++) {
    645             const char *chipName = chipPix->data[i]; // Name of chip
    646             const char *cellName = cellPix->data[i]; // Name of cell, or NULL
    647             if (!data->all && (!isfinite(xPix->data.F32[i]) || !isfinite(yPix->data.F32[i]) ||
    648                                !chipName || (rawFile && !cellName))) {
    649                 continue;
    650             }
    651             if (!rawFile && data->ds9) {
    652                 // Region file is only appropriate if we're not mapping all the way back to cell coordinates
    653                 fprintf(data->ds9, "image;circle(%f,%f,%f) # color=%s\n",
    654                         xPix->data.F32[i], yPix->data.F32[i], data->ds9radius, data->ds9color);
    655             } else if (rawFile) {
    656                 fprintf(stdout, "%.3f %.3f --> %.3f %.3f %s %.3f %.3f %s\n",
    657                         fpa_x->data.F32[i], fpa_y->data.F32[i], xPix->data.F32[i], yPix->data.F32[i],
    658                         chipName ? chipName : "UNKNOWN",
    659                         xCell->data.F32[i], yCell->data.F32[i],
    660                         cellName ? cellName : "UNKNOWN");
    661             } else {
    662                 fprintf(stdout, "%.3f %.3f --> %.3f %.3f %s\n",
    663                         fpa_x->data.F32[i], fpa_y->data.F32[i], xPix->data.F32[i], yPix->data.F32[i],
    664                         chipName ? chipName : "UNKNOWN");
    665             }
    666         }
    667     }
    668 
    669558    if (streaksOut) {
    670559        psArray *chipPix1 = streaksOut->data[0]; // Chip for point 1
  • trunk/pswarp/src/pswarpMapGrid.c

    r42154 r42229  
    3838    int nYpts = (int)(Ny / nYpix) + 1;
    3939
    40     psLogMsg("pswarp", 3, "in grid sampling\n");
    4140    // create the grid of maps
    4241    pswarpMapGrid *grid = pswarpMapGridAlloc (nXpts, nYpts);
     
    5049    }
    5150
    52     //if (0) {
     51    if (0) {
    5352        // test the transformation sky<->chip for chip in smf:
    5453        if (fout == NULL) { fout = fopen ("map.grid.txt", "w"); }
     
    8988                fprintf (fout, "%f %f < %f %f < %f %f \n", TP1->x, TP1->y, FP1->x, FP1->y, CH1->x, CH1->y);
    9089
    91                 psLogMsg("pswarp", 3, "testing grid sampling\n");
    92                 psLogMsg("pswarp", 3, "%f %f > %f %f > %f %f > %f %f | ", CH0->x, CH0->y, FP0->x, FP0->y, TP0->x, TP0->y, sky->r*180/M_PI, sky->d*180/M_PI);
    93                 psLogMsg("pswarp", 3, "%f %f < %f %f < %f %f \n", TP1->x, TP1->y, FP1->x, FP1->y, CH1->x, CH1->y);
    94 
    9590            }
    9691        }
     
    106101
    107102        psFree (sky);
    108     //}
     103    }
    109104
    110105    grid->nXpix = nXpix;
  • trunk/pswarp/src/pswarpTransformReadout.c

    r42154 r42229  
    104104    // pswarpMapGridFromImage builds a set of locally-linear maps which convert the
    105105    // output coordinates to input coordinates
    106     psLogMsg("pswarp", 3, "going into MapGrid \n");
    107106    pswarpMapGrid *grid = pswarpMapGridFromImage(input, output, nGridX, nGridY);
    108107   
Note: See TracChangeset for help on using the changeset viewer.