#!/usr/bin/perl -w
# convolve the way it should be.
use DRAORed;
if($#ARGV != 2){
print
"Use: rtconv A B C
A = file that needs to be convolved
B = any file that has the beam you want
C = output file
";
exit 1;
}
unless(-d "logs"){
if(-f "logs"){
die "You should set up a logs directory before running rtconv.";
}
mkdir "logs" || die "Error in mkdir logs";
}
my ($infile, $beamfile, $outfile) = @ARGV;
my $cline = "rtconv $infile $beamfile $outfile";
my $inind = fileindex($infile);
my $beamind = fileindex($beamfile);
my %inp_header = readdef($inind);
my $inscalfact = $inp_header{SCALFACT};
my ($inbmaj, $inbmin, $inpa) = getbeam($inind); # getbeam(ind) converts
my ($outbmaj, $outbmin, $outpa) = getbeam($beamind); # minutes into s.
# Convolve $infile so that it has $beamfile's beam, and put the result in
# ${outfile}BSF (BSF = bad scaling factor).
open(CONV, "|convolve > convolve.log 2>&1") or die "Could not start convolve";
print CONV "\n"; #! Do you wish to run in batch mo
print CONV "\n"; #! Do you want to create a log? [
print CONV "\n"; #! Is log file to be printed on e
print CONV "$inind\n"; #! File definition number [DEFI
print CONV "\n"; #! Do you wish to define resoluti
print CONV "\n"; #! Is input-data smoothing wanted
print CONV "$outbmaj $outbmin $outpa\n"; #! angle from horiz-axis to maj
print CONV "\n"; #! File definition number [DEFI
print CONV "${outfile}BSF\n"; #! File name (max 52 chars) [] ("
print CONV "\n"; #! Data type (IRD) [R]:
print CONV "\n"; #! Are the parameters that you en
print CONV "\n"; #! Do you want a comment? [N]:
print CONV "\n"; #! Do you want to save this defin;
close(CONV) or warn "Error closing convolve";
my $clog = `ls -t1 convolve*.LOG | head -1`;
chomp $clog;
mvlogww($clog);
my $olog = $outfile;
$olog =~ s/\..*/.html/;
open(LOG, ">>logs/index.html") or
die "Ran convolve but could not add entry to index.html";
print LOG "$cline
\n";
close(LOG) or die "Could not close index.html";
open(LOG, ">logs/$olog") or warn "Could not open logs/$olog";
print LOG "$clog
\n";
END { close(LOG) or die "Could not close logs/$olog"; };
# Copy ${outfile}BSF to $outfile, but with the right scaling factor.
my $bsfind = fileindex("${outfile}BSF");
unless($bsfind > 0){
die "Nonsense index \'$bsfind\' for ${outfile}BSF";
}
my $gsfind = get_first_slot();
my $scalfact = 1000.0 * $inscalfact * $outbmaj * $outbmin / ($inbmaj * $inbmin);
my $mlog = $olog;
$mlog =~ s/\.html/.madrout/;
open(MADR, "|madr > logs/fixscalfact$mlog 2>&1") or
die "Could not start madr with logging to logs/fixscalfact$mlog 2>&1";
print MADR "copy f$bsfind $gsfind\n";
print MADR "def f$gsfind\n";
print MADR "$outfile\n"; # File name
print MADR "\n"; # Data type (IRD) [R]:
print MADR "\n"; # Dimensions:
print MADR "\n"; # Subset [NONE]:
print MADR "\n"; # Take the default for allowing undefined data.
print MADR "\n"; # 0 = undefined/dimensionless 4
print MADR "0.0010\n"; # Scaling factor [10.000 E-4]:
print MADR "\n"; # Are the parameters that you entere
print MADR "\n"; # Define coordinates (astronomical p
print MADR "\n"; # Type of file (RD,RV,VD,UV,XY) [RD]
print MADR "\n"; # Sky projection (SEGTVACF) [S]:
print MADR "\n"; # Epoch for projection (1950 or 2000
print MADR "\n"; # Select velocity-like coordinate (V
print MADR "\n"; # RA of reference element [19H 59M 2
print MADR "\n"; # DEC of reference record [40D 44' 2
print MADR "\n"; # Reference ELEMENT for RA [129.000]
print MADR "\n"; # Reference RECORD for DEC [129.000]
print MADR "0\'20.000\"\n"; # DELTA "RA" per element (unsigned) (Default
print MADR "0\'20.000\"\n"; # DELTA "DEC" per record (unsigned) fails!)
print MADR "\n"; # Define file (3rd dimension) coordi
print MADR "\n"; # Define resolution (beam and veloci
print MADR "\n"; # Define auxiliary astronomical para
print MADR "\n"; # Central heliocentric frequency (MH
print MADR "\n"; # LR, RL, LL, RR, I, Q, U, V, None,
print MADR "\n"; # Data-set bandwidth (MHz) [7.500]:
print MADR "\n"; # Observation epoch (e.g. 1984.6) [1
print MADR "\n"; # Are the entered astrophysical para
print MADR "\n"; # Do you want a comment? [N]:
print MADR "\n";
print MADR "\n";
print MADR "\n";
print MADR "\n";
print MADR "manip\n";
print MADR "f$gsfind = $scalfact * f$bsfind\n";
print MADR "exit\n"; # Exit manip
print MADR "neg f$bsfind\n";
print MADR "y\n";
print MADR "y\n";
print MADR "exit\n"; # Exit madr
close(MADR) or die "Error closing madr";
#print "madr index of result: $gsfind\n";
print LOG "\U${outfile}\EBSF copied and ";
print LOG "rescaled with madr to \U$outfile\E.
\n";
# See END statement above.