Subs::LightCurves (version 0.1)


package Subs::LightCurves;
##############################################################################
#
# DESCRIPTION: This is a generic subroutine meant to serve as a superclass
# DESCRIPTION: for subroutines for extracting and plotting lightcurves.
# DESCRIPTION: It provides functionality for plotting the lightcurves
#
# HISTORY: 0.0 -> 0.1 2003-04-28
# HISTORY: Provided an overridable method for listing the lightcurves 
# HISTORY: for plotting. 
#
# VERSION: 0.1
#
##############################################################################


use Subs::Sub;
use Util::Xanadu;

@ISA = ("Subs::Sub");
use strict;

sub new {
    my $proto=shift;
    my $self=$proto->SUPER::new();

    $self->{DESCRIPTION}="Extracting and plotting light curves";

    return $self;
}

##################
# METHODS:
##################

sub body {
    my $self=shift;

    my $log     =$self->log();
    my $filename=$self->filename();
    my $procpar =$self->procpar();
    my $jobpar  =$self->jobpar();

    ##############################
    # extract the lightcurves
    ##############################
    $self->extract_lightcurves();


    ##############################
    # plot the lightcurves
    ##############################
    $self->plot_lightcurves();


} # end of body method

############################################################################
# This method does nothing. Subclasses should override it.
############################################################################
sub extract_lightcurves {


}

############################################################################
# This method lists all the lightcurves which should be plotted
# it defaults to listing all files of type "lightcurve", but subclasses
# may override this - particularly if they have more than one subclass
# of this class.
############################################################################
sub list_lightcurves {
    my $self = shift;

    return $self->filename()->any("lightcurve");
}


############################################################################
# plot all the lightcurves
############################################################################
sub plot_lightcurves {
    my $self=shift;

    my $log     =$self->log();
    my $filename=$self->filename();
    my $procpar =$self->procpar();
    my $jobpar  =$self->jobpar();

    $log->entry("Plotting all lightcurves");

    #######################################
    # set up lcplot tool
    #######################################
    my $plotter = Util::Ftool->new("lcurve")
                             ->params({nser=>1,
                                       window   => "-",
                                       dtnb     => "INDEF",
                                       nbint    => "INDEF",
                                       outfile  => " ",
                                       plot     => "yes",
                                       plotdev  => "/null",
                                       plotfile => "-"     });

    my $command_file="lightcurve_plot_commands.tmp";

    ################################
    # loop over all the lightcurves
    ################################
    my $lightcurve;
    foreach $lightcurve ($self->list_lightcurves()) {

        ########################################
        # get the name of the plot file
        ########################################
        my $plot=$filename->corresponding("lightcurve", "lcplot", $lightcurve);
        unlink $plot;

        ##################################
        # set up plot command file
        ##################################
        unlink $command_file;
        open  COMMAND, ">$command_file";
        print COMMAND "dev $plot/ps\n";
        print COMMAND "LA File $lightcurve\n";
        print COMMAND "plot\n";
        print COMMAND "quit\n";
        close COMMAND;

        #############################################
        # plot the lightcurve
        #############################################
        $log->entry("Plotting $lightcurve in $plot");
        $log->file($command_file);

        unlink $plot;
        $plotter->params({cfile1 => $lightcurve})
                ->stdin("\@$command_file\n")
                ->run();

        ##################################################
        # check for silent errors
        # lcurve can fail without reporting it to stderr
        ##################################################
        unless($plotter->had_error() ||  -s $plot ) {
            $log->error(2,"Light curve plot failed");
            unlink $plot;
        }

    } # end of loop over lightcurves

    unlink $command_file;

} # end of plot_lightcurves method