#!/usr/bin/perl 

# SDSS galaxies script modified by arlduc (arlduc@amnh.org)
# this script takes the star coordinates listed in "SDSS.speck" and turns them into a MEL script.
# to see the resulting animation, go to http://www.arlduc.org/3dAnim/AMNH/Archived/SDSS_HD_00511_forWeb.mov
# to download the Digital Universe atlas that includes SDSS.speck, go to http://haydenplanetarium.org/universe/
# to learn more about the Sloan Digital Sky survey, go to www.sdss.org

my ($lambertNumber, $x, $y, $z, $Rmag, $redshift, $LookbackTime, $Distance_MPC, $Distance_LY, $RA, $Dec, $reductionCtr);

$reductionCtr = 1;
$lambertNumber = 2;

open ( STARS_IN, "starsForSDSS.speck");
open ( STARS_OUT, ">SDSS_stars.mel" );

#while-loop to go through each line of the dataset
while (defined($line = <STARS_IN>)) {
    #$x = "yo";
	$line =~ s/^\s+//;
	($x, $y, $z, $Rmag, $redshift, $LookbackTime, $Distance_MPC, $Distance_LY, $RA, $Dec) = split(/\s+/, $line);
	
	#if struc to negatively-check if the line contains xyz coordinates 
	if (($x ne "#") && ($x ne "datavar") && ($z < 0) && ($x < 0)) {
		printf STARS_OUT ("polySphere -r 1 -sx 6 -sy 6 -ax 0 1 0 -tx 0 -ch 0;");
		printf STARS_OUT ("scale -r 0.1 0.1 0.1;");
		printf STARS_OUT ("move -r %s %s %s;\n", $x, $y, $z);		
	}
	$reductionCtr++;
}
printf STARS_OUT ("select -all;");
printf STARS_OUT ("group; xform -os -piv 0 0 0;");

printf STDOUT ("written to specified MEL file.\n");
