[Kst] branches/kstars/summer/kdeedu/kstars/kstars/data/tools

Akarsh Simha akarshsimha at gmail.com
Mon Jun 2 04:36:25 CEST 2008


SVN commit 815516 by asimha:

+ Fixing bug in datatomysql.pl that was causing trixel to be reported
incorrectly. The RA string was passed directly in HH:MM format without
converting into a number.

+ datatomysql.pl now empties the contents of the table before writing,
to prevent duplicate entries



 M  +2 -1      README.tools  
 M  +11 -2     datatomysql.pl  


--- branches/kstars/summer/kdeedu/kstars/kstars/data/tools/README.tools #815515:815516
@@ -16,7 +16,8 @@
 sort-hip-by-pm.pl  Sort the Hiparcos catalog data by proper motion
 
 datatomysql.pl     Reads star catalog files and puts them into a MySQL 
-                   database (server on localhost)
+                   database (server on localhost). CAUTION: This script will
+		   empty the table that it is writing into.
 
 binfiletester.c    C Program to test KStars' star data in binary format
 
--- branches/kstars/summer/kdeedu/kstars/kstars/data/tools/datatomysql.pl #815515:815516
@@ -1,6 +1,8 @@
 #!/usr/bin/perl
 #
 # datatomysql.pl   Put star data from file (in the plain-text data format used by KStars) into a database
+#
+# CAUTION: Will truncate the table supplied!
 
 use strict;
 use DBI;
@@ -46,6 +48,8 @@
   KEY `trixel` (`trixel`,`pm`,`mag`)
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;/;
 
+my $tbl_trunc_query = qq/TRUNCATE TABLE `allstars`/;
+
 # For the HTMesh
 my $level = 3;
 
@@ -61,6 +65,7 @@
 $dbh->do($db_query);
 $dbh->do($db_select_query);
 $dbh->do($tbl_query);
+$dbh->do($tbl_trunc_query);
 $dbh->commit();
 
 while(<>) {
@@ -74,8 +79,12 @@
     $star->{line} = $.;
 
     $VERBOSE and print_star_line($star);
-
-    $star->{trixel} = $mesh->lookup_name($star->{ra_hm}, $star->{dec});
+    my $rah;
+    my $ram;
+    $star->{ra_hm} =~ /^(\d\d):/ and $rah = $1 or print "Format error in RA HM string\n";
+    $star->{ra_hm} =~ /:(\d\d)$/ and $ram = $1 or print "Format error in RA HM string\n";
+    $star->{trixel} = $mesh->lookup_name($rah + $ram/60.0, $star->{dec});
+    $VERBOSE > 1 and print "Looked up " . ($rah + $ram/60.0) . " and " . $star->{dec} . " and got trixel = " . $star->{trixel};
     $star->{var_range} eq '' and $star->{var_range} = '0';
     $star->{var_period} eq '' and $star->{var_period} = '0';
  


More information about the Kst mailing list