[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] More MacPerl Astrometry



Looks like Dave Seay and I have BOTH been pulling all-nighters! (Dave is also posting code to the MacPerl list in the wee hours, for those of you off-list getting this).

I've quashed all the warnings.  Next version will probably redirect STDOUT to a file.  I'm already very close to the level of functionality of the utility in C from which, the concept for this was based on, and will shortly be surpassing that (except with slower execution).  Richard Grubb is tackling the "neighborhood" calculation, which determines which stars are "travelling distance" from each other.

The "Habitablity" routines are next in line for me.  The simplistic way is just to label stars with in a certain range of luminosities "Habitable."  I'll leave off the discussion of the numerous other factors which come into play.

Tiny caveat:  this program *should* be cross-platform, except for a single 8-bit character on line 186.  It's a degree symbol, which probably looks like "°" on your system.  Replace it with the correct character, and the compatibility problem is (mostly) solved.  We do have someone running this on Unix, but no Win32 perlers yet.

#!usr/bin/perl -w

# USAGE: catalog.plx File_Name
#          where File_Name is a star catalog.
# Mac USAGE: save as droplet.  Drag & Drop target input file
# or just double-click on the droplet and let StandardFile do
# it for you.
#
# Revision History:
# ver 0.2a.r2  Brian McNett <webmaster@mycoinfo.com>
# Pulled and all-nighter. runtime warnings are GONE!
# added test for size of input string
# output getting closer to reality.
#
# ver 0.2a  Brian McNett <webmaster@mycoinfo.com>
# Redirects STDERR (for now)
# wrote calcs for cartesian coords, luminosity and distance
# prints to STDOUT (for now)
# (syntax check ok)
# IT RUNS! (but doesn't produce correct output :-( )
#
# ver 0.1a  Brian McNett <webmaster@mycoinfo.com>
# use strict and -w
# added Math::Trig (for deg2rad())
# added vars
# detect bad start on Mac
# (syntax check ok) this DOESN'T mean it RUNS!
#
# ver 0.0a Richard L. Grubb, <richard.l.grubb@boeing.com>
# slurps input file (well, it's a start)

use strict;
use Math::Trig;
use vars qw(
	$file $input_file

	$strin_len

	$ident $Comp $DistRel
	$RAh $RAm $RAs
	$DE_sign $DEd $DEm
	$pm $u_pm $pmPA
	$RV $n_RV $Sp $r_Sp
	$Vmag $r_Vmag $n_Vmag
	$B_V $r_B_V $n_B_V
	$U_B $r_U_B $n_U_B
	$R_I $r_R_I $n_R_I 
	$trplx $e_trplx
	$plx $e_plx $n_plx 
	$Mv $n_Mv $q_Mv
	$U $V  $W 
	$HD $DM $Giclas $LHS $Other
	$Remarks

	$alpha $delta
	$phi $theta $rho
	$rVect $Xe $Ye $Ze
	$Xg1950 $Yg1950 $Zg1950
	$Xg2000 $Yg2000 $Zg2000
	
	$luminosity
);

open(STDERR, '>Dev:Console:Messages');

# for Mac users who forget to drag&drop the input file
if ($^O eq 'MacOS') {
	if ($#ARGV < 0) {
		use Mac::StandardFile;
		$file = StandardGetFile('', 'TEXT');
		if ($file->sfGood()) {
			push(@ARGV, $file->sfFile());
		} else {
		  exit(1);
		}
	}
}

print STDERR "Opening input data...\n";

$input_file = $ARGV[0];
open( IN_FILE, $input_file) || die "Can't open file $input_file $!\n" ;

while ( <IN_FILE> ) {

	$strin_len = length($_);       # check how long the input string is

	$ident    = substr($_,  0, 8); #A8   #Identifier ; see remarks.
	$Comp     = substr($_,  8, 2); #A2   #Components (A,B,C,... )
	$DistRel  = substr($_, 10, 1); #A1   #[pqsx] Reliability of the distance
	                               #12 is unused
	$RAh      = substr($_, 12, 2); #I2   #? Right Ascension B1950 (hours)
	                               #15 is unused
	$RAm      = substr($_, 15, 2); #I2   #? Right Ascension B1950 (minutes)
	                               #18 is unused
	$RAs      = substr($_, 18, 2); #I2   #? Right Ascension B1950 (seconds)
	                               #21 is unused
	$DE_sign  = substr($_, 21, 1); #A1   #Declination B1950 (sign)
	$DEd      = substr($_, 22, 2); #I2   #? Declination B1950 (degrees)
	                               #25 is unused
	$DEm      = substr($_, 25, 4); #F4.1 #? Declination B1950 (minutes)
	                               #30 is unused
	$pm       = substr($_, 30, 6); #F6.3 #? Total proper motion
	$u_pm     = substr($_, 36, 1); #A1   #Uncertainty flag (:) on pm
	$pmPA     = substr($_, 37, 5); #F5.1 #? Direction angle of proper motion
	                               #43 is unused
	$RV       = substr($_, 43, 6); #F6.1 #? Radial velocity
	                               #50 is unused
	$n_RV     = substr($_, 50, 3); #A3   #Remark on RV
	                               #54 is unused
	$Sp       = substr($_, 54,12); #A12  #Spectral type or color class
	$r_Sp     = substr($_, 66, 1); #A1   #Selected sources
	$Vmag     = substr($_, 67, 6); #F6.2 #Apparent magnitude
	$r_Vmag   = substr($_, 73, 1); #A1   #Note on origin of magnitude
	$n_Vmag   = substr($_, 74, 1); #A1   #[J] joint magnitude
	$B_V      = substr($_, 75, 5); #F5.2 #? color
	$r_B_V    = substr($_, 80, 1); #A1   #Note on origin of magnitude
	$n_B_V    = substr($_, 81, 1); #A1   #Joint color
	$U_B      = substr($_, 82, 5); #F5.2 #? color
	$r_U_B    = substr($_, 87, 1); #A1   #Note on origin of magnitude
	$n_U_B    = substr($_, 88, 1); #A1   #Joint color
	$R_I      = substr($_, 89, 5); #F5.2 #? color
	$r_R_I    = substr($_, 94, 1); #A1   #Note on origin of magnitude
	$n_R_I    = substr($_, 95, 1); #A1   #Joint color
	$trplx    = substr($_, 96, 6); #F6.1 #? Trigonometric parallax
	$e_trplx  = substr($_,102, 5); #F5.1 #? Standard error of trig. parallax
	                               #108 is unused
	$plx      = substr($_,108, 6); #F6.1 #? Resulting parallax
	$e_plx    = substr($_,114, 5); #F5.1 #? Standard error of res.  parallax
	$n_plx    = substr($_,119, 1); #A1   #[rwsop] Code on plx
	                               #121 is unused  
	$Mv       = substr($_,121, 5); #F5.2 #Absolute visual magnitude
	$n_Mv     = substr($_,126, 2); #A2   #Note on Mv, copied from cols 74-75
	$q_Mv     = substr($_,128, 1); #A1   #[a-f] Quality of absolute magnitude

	# Warning! CHECK THE VALIDITY OF THESE FIELDS BEFORE USING THEM!

	$U        = substr($_,131, 4); #I4   #? U space velocity component in the galactic plane and directed to the galactic center
	                               #136 is unused
	$V        = substr($_,136, 4); #I4   #? V space velocity component in the galactic plane and in the direction of galactic rotation
	                               #141 is unused
	$W        = substr($_,141, 4); #I4   #? W space velocity component in the galactic plane and in the direction of the North Galactic Pole

	# We can't be certain the line doesn't just end at this point, so...

	if ($strin_len <= 145) {
	$HD = " ";
	} else {
	$HD       = substr($_,146, 6); #I6   #[15/352860]? designation
	}
	if ($strin_len <= 152) {
	$DM = " ";
	} else {
	$DM       = substr($_,153,12); #A12  #Durchmusterung number BD / CD / CP
	}
	if ($strin_len <= 165) {
	$Giclas = " ";
	} else {
	$Giclas   = substr($_,166, 9); #A9   #number        <...>
	}
	if ($strin_len <= 175) {
	$LHS = " ";
	} else {
	$LHS      = substr($_,176, 5); #A5   #number        <...>
	}
	if ($strin_len <= 181) {
	$Other = " ";
	} else {
	$Other    = substr($_,182, 5); #A5   #Other designations
	}
	if ($strin_len <= 187) {
	$Remarks = " ";
	} else {
	$Remarks  = substr($_,188,69); #A69  #Additional identifications (LTT, LFT, Wolf, Ross, etc.) and remarks
	}

# Convert Location to Cartesian System

&calc_cartesian;

print "$ident $Comp \n==========\n" ;
print "Coordinates (Earth)    [ $Xe , $Ye , $Ze ] \n" ;
print "Coordinates (Galactic) [ $Xg1950 , $Yg1950 , $Zg1950 ]\n";
print "Alpha: $alpha  Delta: $delta\n";
print "Right Ascension:  ${RAh}h ${RAm}m ${RAs}s\n";
print "Declination:    $DE_sign ${DEd}° ${DEm}\'\n";
print "--------------------------------------------------------\n";
# Calculate Neighbors

# Determine Habitable Systems

$luminosity = 1/(2.5**($Mv - 4.85));
print "Luminosity: $luminosity \n";
print "Spectral Class: $Sp ($r_Sp -- see notes)\n";
print "\n===========================================================\n";
# Insert Planets, Moons
# Write out resource compiler sources
}


### SUBROUTINES ###

sub calc_cartesian {
if ($RAh eq '  ') {

$Xe     = 0.000;
$Ye     = 0.000;
$Ze     = 0.000;

$Xg1950 = 0.000;
$Yg1950 = 0.000;
$Zg1950 = 0.000;

$alpha = 0;
$delta = 0;

# $Xg2000 = 0.000;
# $Yg2000 = 0.000;
# $Zg2000 = 0.000;

} else {

	$rho = 1000/$plx;

	$alpha = (($RAh * 15)+($RAm * 0.25)+($RAs * 0.0041666));
	$delta = (($DEd + $DEm/60) * join('' , $DE_sign,1));

	# calculate Phi, Theta (in radians)
	# ---------------------------------
	$phi     = deg2rad($alpha);
	$theta   = deg2rad($delta);

	# Earth-equatorial cartesian coords
	# ---------------------------------
	$rVect = $rho   * cos($theta);
	$Xe    = $rVect * cos($phi);
	$Ye    = $rVect * sin($phi);
	$Ze    = $rho   * sin($theta);

	# Galactic-equatorial cartesian coords (B1950)
	# --------------------------------------------
	$Xg1950 = -(0.0672 * $Xe) - (0.8727 * $Ye) - (0.4835 * $Ze);
	$Yg1950 =  (0.4927 * $Xe) - (0.4504 * $Ye) + (0.7445 * $Ze);
	$Zg1950 = -(0.8676 * $Xe) - (0.1884 * $Ye) + (0.4602 * $Ze);

	# Galactic-equatorial cartesian coords (J2000)
	# commented out until implementation
	# --------------------------------------------
	# $Xg2000 = -(0.0550 * $Xe) - (0.8734 * $Ye) - (0.4839 * $Ze);
	# $Yg2000 =  (0.4940 * $Xe) - (0.4449 * $Ye) + (0.7470 * $Ze);
	# $Zg2000 = -(0.8677 * $Xe) - (0.1979 * $Ye) + (0.4560 * $Ze);
	}
}


# Fungal Parataxonomy                   Mycology Information (Mycoinfo)
# Webmaster, Staff Writer      **The World's First Mycology E-Journal**   
# <mailto:webmaster@mycoinfo.com>            <http://www.mycoinfo.com/> 
#
# First they ignore you. Then they laugh at you. Then they fight you.
# Then you win.                                     --Mohandas Gandhi


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org