[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Tool Needed
hi Tom,
please use the updated script below instead of the one sent yestrday.
-ron
----cut here----
#!/usr/bin/perl
# program name select.pl
# fixed bug that fails to find lines it should when the file size is large
# assumes file format is like:
# 3 18 269.9027 5.6286 2452461.72943 V 13.884 0.278 0 I 12.001 0.059 0
# 3 18 269.9028 5.6292 2452487.65160 V 13.244 0.153 0 I 11.998 0.051 0
# 3 18 269.9028 5.6283 2452461.73120 V 13.443 0.194 0 I 11.994 0.054 0
# where RA is field 2 and DEC is field 3 (based on splitting on white space)
# star list file name
$STARS = "test.data";
# output file name root (will have RA and Dec added)
$OUT = "selected";
# default search box delta
$box = .1;
$| = 1; # turn off buffering so screen will be udated to show progress
print "This is program select.pl\n\n";
print "input file \(default $STARS\): ";
$in = <STDIN>; chomp $in;
$STARS = $in unless ($in eq "");
print "RA = "; $RA = <STDIN>; chomp $RA;
print "DEC = "; $DEC = <STDIN>; chomp $DEC;
print "search box size \(default $box\): ";
$in = <STDIN>; chomp $in;
$box = $in unless //;
$RAl = $RA - $box / 2;
$RAu = $RA + $box / 2;
$DECl = $DEC - $box / 2;
$DECu = $DEC + $box / 2;
$OUT = ">$OUT-$RA-$DEC";
open (OUT) or die "Could not open file $OUT for writing $!\n";
open (STARS) or die "Could not open file $STARS $!\n";
print "opened $STARS for read\n and $OUT for write\n";
# comment out following line if search criteria should not be first line
print OUT "input file=$STARS RA=$RA DEC=$DEC Search Box=$box\n";
$t = 0; $i = 1; $j = 1; # initialize counter variables
while (<STARS>) { # read lines until end of file
$in = $_;
$in =~ s/^\s+//; # get rid of initial white space
@in = (split /\s+/, $in); # split line on one or more space characters
$ra = $in[2];
$dec = $in[3];
if (($ra < $RAu) && ($ra > $RAl) && ($dec < $DECu) && ($dec > $DECl)) {
print "+"; $t++; # print character on screen to show a hit
print OUT "$_";
} # endif
$i++; # print the number of records
if ($i > 10000) { # searched, in ten thousands.
print " $j"; # comment out if not desired,
$j++ ; # which will also slightly speed
$i = 0; # up program execution.
} # endif # end of section
} # end while
close IN; close OUT;
$OUT =~ s/^>//;
print "\nfinished. wrote $t lines to file \"$OUT\".\n";
----cut here----