#!/usr/local/bin/perl -w
open (INPUT, "ngc188.catal") || die "died opening input\n";
open (STDOUT, ">sortedngc") || die "died opening output\n";
$n =0;
while ($inline = ) {
@firstline = split(/\s+/, $inline);
#########################################
$pi = 3.141592654;
$cos = cos(($firstline[3] * $pi) / 180);
$x = abs(($firstline[2]* $cos) - (11.083333 * cos((85.315 * $pi) / 180)));
$x2 = $x * $x; #squaring the x-xo term
$y = abs($firstline[3] - 85.3150000);
$y2 = $y * $y; #squaring the y-yo term
$r2 = $y2 + $x2; #distance in decimal degree
########################variable definition#############################
$id[$r2] = $firstline[1];#id
$ra[$r2] = $firstline[2];#RA
$dec[$r2] = $firstline[3];#dec
$prob[$r2] = $firstline[11];#probablity
$mag[$r2] = $firstline[12];#magnitude
$bv[$r2] = $firstline[13];#b-v
###################################pushing########################
push (@dist, $r2);
$n++;
}
sub numerically { $a <=> $b};
@sorted = sort numerically @dist;
@nindex = (0..$n-1);
foreach $i (@nindex) {
print STDOUT "$id[$sorted[$i]] $ra[$sorted[$i]] $dec[$sorted[$i]] $prob[$sorted[$i]] $mag[$sorted[$i]] $bv[$sorted[$i]] $sorted[$i]\n";
}
####
9596 13.4454218 85.0299299 0 17.256 0.907 1.19274490573905e-06
9596 13.4454218 85.0299299 0 17.256 0.907 7.9866617413342e-06
9596 13.4454218 85.0299299 0 17.256 0.907 1.43567635042601e-05
9596 13.4454218 85.0299299 0 17.256 0.907 1.87711214620725e-05
9596 13.4454218 85.0299299 0 17.256 0.907 3.03218139005967e-05
9596 13.4454218 85.0299299 0 17.256 0.907 3.45815761885486e-05
9596 13.4454218 85.0299299 0 17.256 0.907 3.59984633166351e-05
9596 13.4454218 85.0299299 0 17.256 0.907 7.01615131685114e-05
9596 13.4454218 85.0299299 0 17.256 0.907 9.57233947085147e-05
9596 13.4454218 85.0299299 0 17.256 0.907 9.70028702157815e-05
9596 13.4454218 85.0299299 0 17.256 0.907 9.78283014973695e-05
9596 13.4454218 85.0299299 0 17.256 0.907 9.99000064463008e-05
. . .
####
0043 13.35673 85.10234 0 17.256 0.245 1.19274490573905e-06
0521 13.89567 85.987636 0 12.234 0.907 7.9866617413342e-06
1000 13.235678 85.985463 0 18.314 0.907 1.43567635042601e-05
. . .