#!/usr/bin/env /proj/axaf/bin/perlwrap use warnings; # The above will probably need to be changed to reflect your local # perl installation. /usr/bin/perl is a good possibility. ############################################################################### # # This program is a bare-bones example of how to automate the usage of # the 'fix_offset' thread. It expects as input the same lines which you # would cut-and-paste into the text window of the Web thread tool. # # All this program does is emulate the thread tool Web page and post the # appropriate form data to the CGI script. That CGI script retrieves aspect # files from the Chandra archive and the CXCDS CALDB, which is the reason it # cannot be run completely local to the users machine. # # Typical usage: # dmlist aspcorr_evt2.fits header,raw,clean | egrep 'TCTYP|TCRVL|ASCDSVER|DATE|OBS_ID' | fix_batch # # The program could easily be modified to take as input an event file name # and do everything from there. # # Copyright 2002 Tom Aldcroft # ############################################################################### ########################################################################## # INSTALLATION NOTES (Courtesy S. Gallagher) # # Modules required # (can be downloaded from http://www.cpan.org/modules/01modules.index.html) # # HTML-Tree-3.13.tar.gz # (requires HTML-Tagset-3.03.tar.gz and HTML-Parser-3.26.tar.gz) # HTML-Format-1.23.tar.gz # (requires Font-AFM-1.18.tar.gz) # libwww-perl-5.65.tar.gz # (requires URI-1.22.tar.gz) # # Module installation instructions are available at # http://www.cpan.org/modules/INSTALL.html # or by typing # perldoc permodinstall # at the command line. # ########################################################################## # Load Perl libraries (available from CPAN) which make it easy to # do an HTTP request and parse the results use HTML::TreeBuilder; use HTML::FormatText; use HTTP::Request::Common qw(POST); use LWP::UserAgent; # Get the lines containing event file header keywords from STDIN @input = ; $header_input = join '', @input; # Generate a new Web user agent $ua = LWP::UserAgent->new; # Generate an HTTP request as if posting form data $req = POST 'http://cxc.harvard.edu/cal/ASPECT/fix_offset/fix_offset.cgi', [ header => $header_input, "Click here" => 1]; # .. and post the form data $response_html = $ua->request($req)->as_string; # Now parse the returned HTML and print it $html = HTML::TreeBuilder->new(); $formatter = HTML::FormatText->new(leftmargin=>0, rightmargin=>80); $response = $formatter->format( $html->parse($response_html) ); print $response, "\n"; # A possible enhancement is to have the code automatically do the header # updates, though it may be safer to explicitly view the results and # cut-n-paste for each one. # # foreach ( grep /dmhedit/, split("\n",$response) ) { # print "$_\n"; # system $_; # }