added Bands to allow on 6m
[spider.git] / perl / gdx.pl
index 3d311e38264d4d36a5be378c331c1faba986c047..f88761ab5ec5285a35f7078955c50576491a18db 100755 (executable)
@@ -3,84 +3,40 @@
 # grep for expressions in various fields of the dx file
 #
 
-use FileHandle;
-use DXUtil;
-use DXDebug;
-use spot;
-
-# initialise spots file
-STDOUT->autoflush(1);
-
-print "reading in spot data ..";
-$t = time;
-$count = spot->init();
-$t = time - $t;
-print "done ($t secs)\n";
+# search local then perl directories
+BEGIN {
+       # 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";
+}
 
-dbgadd('spot');
+use IO::Handle;
+use DXUtil;
+use Bands;
+use Spot;
 
-$field = $ARGV[0];
-$expr = $ARGV[1];
-$time = time;
+$dxdir = "/spider/cmd/show";
+$dxcmd = "dx.pl";
+$s = readfilestr($dxdir, $dxcmd);
+$dxproc = eval "sub { $s }";
+die $@ if $@;
 
-print "$count database records read in\n";
+STDOUT->autoflush(1);
+Spot::init();
+Bands::load();
 
-#loada();
 for (;;) {
-  print "field: ";
-  $field = <STDIN>;
-  last if $field =~ /^q/i;
   print "expr: ";
   $expr = <STDIN>;
+  last if $expr =~ /^q/i;
 
-  chomp $field;
   chomp $expr;
 
-  print "doing field $field with /$expr/\n";
-
-#a();
-  b();
-}
-
-sub b
-{
-  my @spots;
-  my @dx;
-  my $ref;
-  my $count;
-  
-  @spots = spot->search($field, $expr);
-  
-  foreach $ref (@spots) {
-    @dx = @$ref;
-       my $t = ztime($dx[2]);
-       my $d = cldate($dx[2]);
-       print "$dx[0] $dx[1] $d $t $dx[4] <$dx[3]>\n";
-       ++$count;
-  }
-  print "$count records found\n";
-}
-
-sub loada
-{
-  while (<IN>) {
-    chomp;
-       my @dx =  split /\^/;
-       next if $time - $dx[2] > (84600 * 60);  
-       unshift @spots, [ @dx ];
-       ++$count;
-  }
-}
-
-sub a
-{
-  foreach $ref (@spots) {
-    if ($$ref[$field] =~ /$expr/i) {
-         my @dx = @$ref;
-         my $t = ztime($dx[2]);
-         my $d = cldate($dx[2]);
-      print "$dx[0] $dx[1] $d $t $dx[4] <$dx[3]>\n";
-       }
-  }
+  my @out = map {"$_\n"} &$dxproc({priv=>0,call=>'GDX'}, $expr);
+  shift @out;   # remove return code
+  print @out;
 }