PERL SCRIPT FOR SCIENCE STAR PHOTOMETRY
This is used to calculate science star photometry.
#!/usr/bin/perl
# This perl script is to calculate the extra-atmosphere magnitude
# for science stars.
# revision history:
# 1. origional written by WCJ (08/29/2003)
# 2. shuffle columns to match photometry master list by WCJ (08/14/2007)
# 3. fix bug at the if statement to correctly calculate VRI mags by WCJ. (3/18/08)
system("rm -rf science.ans");
print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
print "This program is ONLY for transformation equation as following\n";
print "V=mv+v1+v2*AM+v3*(mv-mi)+v4*(mv-mi)*AM\n";
print "R=mr+r1+r2*AM+r3*(mr-mi)+r4*(mr-mi)*AM\n";
print "I=mi+i1+i2*AM+i3*(mr-mi)+i4*(mr-mi)*AM\n";
print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n";
print STDOUT " Who are you?\n";
$who=;
chomp($who);
#-------------------------------
# read in coefficient file name
#-------------------------------
use Date::Format;
$Ldate = time2str("%Y-%m-%d", time);
print "PLEAE MAKE SURE THAT THIS COEFFICIENT FILE ONLY HAVE 3 BLOCKS (3 FILTERS)\n";
print STDOUT "Enter the fitted coefficient file name:\n";
$cf=;
#-------------------------------
# read in the file name contains mag/airmass
#-------------------------------
print STDOUT "Enter the output file name from MKNOBSFILE task:\n";
$of=;
open(cfile,$cf) or die "Can't open $cf file";
open(ofile,$of) or die "Can't open $of file";
chop(@obsdata=);
close(ofile);
open(scimts,"science.imsets");
chop(@fname=);
open(output,">>science.ans");
printf output "DATE OBJECT FILTER A/M AP MAG SNerr S*err flg DATE RED. WHO STATUS MULTIPLE SEPARATION NOTES \n";
#------------------------------------------------
# extract the Coefficient from standard.coeff file
#-------------------------------------------------
$read_values = 0;
$read_errors = 0;
$i=0;
$j=0;
@coeff[23]=0;
while() {
s/\s+//;
s/\s+$//;
if (/^stdeviation/) {
($string[$j],$standerr[$j])=split(" ",$_);
$j++;
}
if (/^values/) {
$read_values = 1;
$read_errors = 0;
next;
}
if ($read_values && /^[-,0-9]/) {
next if ("$_" == "0.1");
# print "Value: \t $_\n";
@coeff[$i]=$_;
$i++;
}
if ($read_errors && /^[-,0-9]/){
next if ("$_" == "0.1");
# print "Error: \t $_\n";
@coeff[$i]=$_;
$i++;
}
if (/^errors/) {
$read_values = 0;
$read_errors = 1;
next;
}
}
close(cfile);
#---------------------------------------------------------
# calculate how many lines in *.obs file ($line)
# calculate how many stars are in this file ($starnum)
#---------------------------------------------------------
$line=@obsdata;
$starnum=($line-3)/3;
for ($i=0;$i<=$starnum;$i++) {
($starname[$i],$column[$i],$vfile[$i], $rfile[$i],$ifile[$i])=split(" ",$fname[$i],5);
}
# split the array into several columns...
for ($i=3;$i<=$line-1;$i++) {
($id[$i-3],$filter[$i-3],$time[$i-3],$am[$i-3],$x[$i-3],$y[$i-3],$mag[$i-3],$snerr[$i-3])
=split(" ",$obsdata[$i],8);
}
for ($i=0;$i<$starnum;$i++) {
$vi=$mag[$i*3]-$mag[$i*3+2];
$ri=$mag[$i*3+1]-$mag[$i*3+2];
$vr=$mag[$i*3]-$mag[$i*3+1];
#---------------------------------------------------------------
#The following calculates the extra-atmosphere magnitude for VRI
#---------------------------------------------------------------
if ($mag[$i*3] == "INDEF" || $mag[$i*3+2] == "INDEF") {
$V[$i]=99.999;
} else {
$V[$i]=calmag($mag[$i*3],$vi,$coeff[0],$coeff[1],$coeff[2],$coeff[3],$am[$i*3]);
}
if ($mag[$i*3+1] == "INDEF" || $mag[$i*3+2] == "INDEF") {
$I[$i]=99.999;
$R[$i]=99.999;
} else {
$R[$i]=calmag($mag[$i*3+1],$ri,$coeff[8],$coeff[9],$coeff[10],$coeff[11],$am[$i*3+1]);
}
if ($mag[$i*3+2] == "INDEF" || $mag[$i*3+1] == "INDEF") {
$I[$i]=99.999;
$R[$i]=99.999;
} else {
$I[$i]=calmag($mag[$i*3+2],$ri,$coeff[16],$coeff[17],$coeff[18],$coeff[19],$am[$i*3+2]);
}
printf output "%-23s%-16s%-7s%5.3f %-5s %6.3f %5.3f %5.3f %2s %10s %3s %1s%28s%27s\n",
@vfile[$i], $id[$i*3], $filter[$i*3], $am[$i*3], "---", $V[$i], $snerr[$i*3], $standerr[0], "--", $Ldate, $who, ".", ".", ".";
printf output "%-23s%-16s%-7s%5.3f %-5s %6.3f %5.3f %5.3f %2s %10s %3s %1s%28s%27s\n",
@rfile[$i], $id[$i*3], $filter[$i*3+1], $am[$i*3+1], "---", $R[$i], $snerr[$i*3+1], $standerr[1], "--", $Ldate, $who, ".", ".", ".";
printf output "%-23s%-16s%-7s%5.3f %-5s %6.3f %5.3f %5.3f %2s %10s %3s %1s%28s%27s\n",
@ifile[$i], $id[$i*3], $filter[$i*3+2], $am[$i*3+2], "---", $I[$i], $snerr[$i*3+2], $standerr[2], "--", $Ldate, $who, ".", ".", ".";
}
print "Make Sure to Enter Aperture Size and Photometry Codes in science.ans file\n";
sub calmag {
my($m,$color,$c1,$c2,$c3,$c4,$air)=@_;
$exmag=$m+$c1+$c2*$air+$c3*$color+$c4*$color*$air;
return $exmag;
}