speeded up search and load of dx spots (a lot)
[spider.git] / perl / gdx.pl
1 #!/usr/bin/perl
2 #
3 # grep for expressions in various fields of the dx file
4 #
5
6 use FileHandle;
7 use DXUtil;
8 use DXDebug;
9 use spot;
10
11 # initialise spots file
12 STDOUT->autoflush(1);
13
14 print "reading in spot data ..";
15 $t = time;
16 $count = spot->init();
17 $t = time - $t;
18 print "done ($t secs)\n";
19
20 dbgadd('spot');
21
22 $field = $ARGV[0];
23 $expr = $ARGV[1];
24 $time = time;
25
26 print "$count database records read in\n";
27
28 #loada();
29 for (;;) {
30   print "field: ";
31   $field = <STDIN>;
32   last if $field =~ /^q/i;
33   print "expr: ";
34   $expr = <STDIN>;
35
36   chomp $field;
37   chomp $expr;
38
39   print "doing field $field with /$expr/\n";
40
41 #a();
42   b();
43 }
44
45 sub b
46 {
47   my @spots;
48   my @dx;
49   my $ref;
50   my $count;
51   
52   @spots = spot->search($field, $expr);
53   
54   foreach $ref (@spots) {
55     @dx = @$ref;
56         my $t = ztime($dx[2]);
57         my $d = cldate($dx[2]);
58         print "$dx[0] $dx[1] $d $t $dx[4] <$dx[3]>\n";
59         ++$count;
60   }
61   print "$count records found\n";
62 }
63
64 sub loada
65 {
66   while (<IN>) {
67     chomp;
68         my @dx =  split /\^/;
69         next if $time - $dx[2] > (84600 * 60);  
70         unshift @spots, [ @dx ];
71         ++$count;
72   }
73 }
74
75 sub a
76 {
77   foreach $ref (@spots) {
78     if ($$ref[$field] =~ /$expr/i) {
79           my @dx = @$ref;
80           my $t = ztime($dx[2]);
81           my $d = cldate($dx[2]);
82       print "$dx[0] $dx[1] $d $t $dx[4] <$dx[3]>\n";
83         }
84   }
85 }
86