]> dxcluster.org Git - spider.git/commitdiff
add spot2sql.pl for experiment sql support
authorminima <minima>
Sun, 8 May 2005 15:21:47 +0000 (15:21 +0000)
committerminima <minima>
Sun, 8 May 2005 15:21:47 +0000 (15:21 +0000)
perl/DXCommandmode.pm
perl/spot2sql.pl [new file with mode: 0755]

index 5f89ac2369f7e28b48bec355ceacb12ad0627278..080cf666ce0cbc3dc99032bbc4a1d9452af24bd1 100644 (file)
@@ -440,7 +440,7 @@ sub run_cmd
                # strip out // and .. on command only
                $cmd =~ s|//|/|g;
                $cmd =~ s|^/||g;                # no leading / either
-               $cmd =~ s|[^-\w/]||g;   # and no funny characters
+               $cmd =~ s|[^-?\w/]||g;  # and no funny characters
                                        
                my ($path, $fcmd);
                        
diff --git a/perl/spot2sql.pl b/perl/spot2sql.pl
new file mode 100755 (executable)
index 0000000..7ffb758
--- /dev/null
@@ -0,0 +1,68 @@
+#
+# $Id$
+#
+# Copyright (c) 2005 Dirk Koopman G1TLH
+#
+# Load all the spots you have into the spider.sdb SQLite
+# SQL database.
+# 
+BEGIN {
+
+       sub mkver {};
+       
+       # root of directory tree for this system
+       $root = "/spider";
+       $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
+       
+       unshift @INC, "$root/perl";     # this IS the right way round!
+       unshift @INC, "$root/local";
+}
+
+use DXUtil;
+use Spot;
+use DBI;
+use DBD::SQLite;
+
+Spot::init();
+
+my $dbh = DBI->connect("dbi:SQLite:dbname=$root/data/spider.sdb","","")
+       or die "cannot open $root/data/spider.sdb";
+
+opendir DIR, "$root/data/spots" or die "No spot directory $!\n";
+my @years = grep {/^\d/} readdir DIR;
+closedir DIR;
+
+$dbh->do("delete from spots");
+
+my $sth = $dbh->prepare("insert into spots values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)") or die "prepare\n";
+
+foreach my $year (@years) {
+       opendir DIR, "$root/data/spots/$year" or next;
+       my @days = grep {/^\d+\.dat/} readdir DIR;
+       closedir DIR;
+       my $j = Julian::Day->new(time);
+       for (@days) {
+               my ($day) = /^(\d+)/;
+               my $count;
+               $j->[0] = $year;
+               $j->[1] = $day-0;
+               printf "\rdoing $year %03d", $day;
+               my $fh = $Spot::fp->open($j); # get the next file
+               if ($fh) {
+                       $dbh->begin_work;
+                       while (<$fh>) {
+                               my @s = split /\^/;
+                               push @s, undef while @s < 14;
+                               $sth->execute(@s);
+                               $count++;
+                       }
+                       $dbh->commit;
+               }
+               print " $count\n";
+       }
+}
+print "\n";
+$sth->finish;
+$dbh->disconnect;
+
+