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