#! /usr/local/bin/perl # This program reads the witty worm interval files and produces a # cuttlefish configuration file. use Getopt::Std; use FindBin qw($Bin); use lib "$Bin/../lib"; #use Util; use strict; my ($exicutable) = ($0 =~ /([^\/]+)$/); my $usage = "usage:$0 [-h] witty-interval-file\n"; sub Help() { print STDERR $usage; print<) { #print; $linenum++; if (/# (\d+)/) { $time = $1; } s/#.*//; next unless (/[^\s]/); my ($lat, $long, $value) = split /\s+/; if ($value =~ /^\d+$/) { my $loc = "$lat $long"; unless (defined $time) { chop; die("$file\[$linenum\] $_\n\tfailed to find time"); } my $id = $loc2id{$loc}; unless (defined $id) { $loc2id{$loc} = $id_counter++; $id = $loc2id{$loc}; } #print "time:$time id:$id\n"; $time2id2value{$time}{$id} = $value; $time2total{$time} += $value; } #last if ($linenum > 10); } #last if ($file_id++ > 10); } } sub PrintFrames() { print "# frames ------------------------------------\n"; foreach my $time (sort {$a<=>$b} keys %time2id2value) { print STDERR "total:$time ",$time2total{$time},"\n"; print "object:frame time:$time\n"; foreach my $id (sort {$a<=>$b} keys %{$time2id2value{$time}}) { my $value = $time2id2value{$time}{$id}; print "$id $value\n"; } } } sub PrintNodes() { print "# nodes ------------------------------------\n"; print "object:nodes\n"; foreach my $loc (sort {$loc2id{$a}<=>$loc2id{$b}} keys %loc2id) { my $id = $loc2id{$loc}; print "$id $loc\n"; } } sub PrintHeader { print<