#!/usr/bin/perl -w # RWB January 8, 2002 # Scan files of RAFOS-detection signal for peaks, and estimate arrival # time. Call IDL routine scn1raf to do the calculations. Write results # to a file. use strict; my $iyear=2001; # year (can be changed interactively) my $iday1=245; # first day (ditto) my $iday2=245; # last day (ditto) my $iverb=3; # verbosity level my @hr1=(4.196,4.205,4.580,5.140,5.565,6.120); # Start of windows for RAFOS signal my @hr2=(4.202,4.212,4.586,5.150,5.575,6.130); # End of windows for RAFOS signal my $dummy; init(); # initialization scan1(); # Scan for peaks. # END of main script sub init() { pbanner(); # Print an introductory banner. askval(); # Set parameters interactively. } sub pbanner() { print "This PERL script finds RAFOS signals and estimates their\n"; print "arrival time. The data scanned are on 'd' files:\n"; print " r0124506.27m -> r0124506.27b -> r0124506.27w -> r0124506.27d\n"; print "The program selects a region of data near the expected time for\n"; print "the signal to arrive, finds the peak, and calculates the\n"; print "arrival time and other parameters of interest.\n"; } # Subroutine to prompt for parameters. sub askval() { my ($a,$iband); ; print "\$iyear, \$iday1, \$iday2 = $iyear, $iday1, $iday2\n"; print "year: $iyear: "; $a=; chomp($a); if(length($a) gt 0) {$iyear=$a}; print "first day: $iday1: "; $a=; chomp($a); if(length($a) gt 0) {$iday1=$a;$iday2=$iday1;} print "last day: $iday2: "; $a=; chomp($a); if(length($a) gt 0) {$iday2=$a}; print "verbosity (3=interactive) : $iverb: "; $a=; chomp($a); if(length($a) gt 0) {$iverb=$a}; for ($iband=0; $iband<@hr1; $iband++) { print "start of search window $iband (hours) (0 -> ignore) $hr1[$iband]: "; $a=; chomp($a); if(length($a) gt 0) {$hr1[$iband]=$a;} if($hr1[$iband] gt 0) { print "end of search window $iband (hours) $hr2[$iband]: "; $a=; chomp($a); if(length($a) gt 0) {$hr2[$iband]=$a}; } else {$hr1[$iband]=0; $hr2[$iband]=0;} } } ### END of subroutine askval() sub scan1() { # Scan d-files (quadrature-cross-correlation RAFOS signal) for peaks. # Search for a series of peaks. Write a record for each peak. my $nextname=''; my ($id,$iband); my @a=(); my $files = '/usr/data/bland/pioneer/2001/r01246??.??d'; # template # for searching for "d" files my $idlcom; # command and return status for spawned IDL job. my ($ihr,$imin,$hr); my $outfile='/usr/data/bland/pioneer/2001/r0124624.60a'; my $scnline='246 5 8.31'; # Buffer for scan results. substr($files,-17,4) = sprintf("%04d",$iyear); # year into the path substr($outfile,-17,4)=sprintf("%04d",$iyear); # year into out path substr($files,-11,2)=sprintf("%02d",$iyear%100); # year into file name substr($outfile,-11,2)=sprintf("%02d",$iyear%100); # year into out file name substr($outfile,-9,3)=sprintf("%03d",$iday1); # first day into out file name substr($outfile,-6,2)=sprintf("%02d",$iday2/10); #first day into out file name substr($outfile,-3,1)=sprintf("%01d",$iday2%10); #first day into out file name print "Input files will be selected according to template \$files = $files\n"; print "Output will be written to file \$outfile = $outfile\n"; if (!defined($outfile)) { print "File \$outfile already exists; enter alternate name or ". "press return to overwrite: \n"; $a=; chomp($a); if (length($a) gt 0) {$outfile=$a;} } open( OUTFILE,'>'.$outfile ); print OUTFILE " year day hr mn sec width signal noise arrival time\n"; for ($id=$iday1; $id <= $iday2; $id++) { substr($files,-9,3) = sprintf("%03d",$id); # day into file name print "Files to be processed: $files\n"; @a=glob($files); # Get file names for this day. print "The number of files found is ".@a."\n"; if(!defined(@a)) {print "No files found.\n";} while (defined($nextname = glob($files))) { # print "next file name is $nextname\n"; $ihr=substr($nextname,-6,2); $imin=substr($nextname,-3,2); $hr = $ihr+$imin/60.; # ***** Search in each of several bands. for ($iband=0; $iband<@hr1; $iband++) { if (($hr < $hr1[$iband] && $hr+2.05 > $hr2[$iband] || $hr < $hr1[$iband]+12 && $hr+2.05 > $hr2[$iband]+12) && ($hr2[$iband]>0)) { print "File $nextname selected for RAFOS search.\n"; open( TEMP,'>ptemp1.tmp' ); print TEMP ".rnew scn1raf\n"; print TEMP ".rnew scn1raf\n"; print TEMP "scn1raf,'$nextname',$hr1[$iband],$hr2[$iband]". ",iverb=$iverb\n"; print TEMP "exit\n"; close( TEMP ); $idlcom = "idl ptemp1.tmp"; # IDL command system($idlcom); unlink( "ptemp1.tmp" ); open (TEMP,'; # one-line result close( TEMP ); print "Data line from scn1raf:\n$scnline"; # display result print OUTFILE $scnline; # results from this scan } } } } close( OUTFILE ); # file of scan results } # End of subroutine scan1.