#!/usr/bin/perl # # perl interpolcmdinwf.pl in out cmd # # Throws in a distance dependendent command after each jump # # in can be a file with like 'part1' or 'part1_snap' # # e.g. part1_tripthruhipparcos_snap outfile 0.1+0.3\*\(DIST/860\) g8 slum DISTDEPVALUE # # Note that you need to put backslashes before * and ( and ). # The above eg should be interpreted as # define DISTDEPVALUE := 0.1+0.3*(DIST/860) # where DIST is the distance from the camera to the origin # and then the statement "g8 slum x", where x is the value of DISTDEPVALUE # is inserted in the input file (in) after each jump statement # to produce the resulting output file (out). $in = $ARGV[0]; $out = $ARGV[1]; $distfn = $ARGV[2]; # defines the function of distance print "$distfn\n\n"; $distcmd = $ARGV[3]; # defines the command to place after each jump command for ($i=4; $i<=$#ARGV; $i++) { $distcmd = $distcmd." ".$ARGV[$i]; } open (IN,"$in"); open (OUT,">$out"); while ($line = ) { chomp $line; @tmp = split /[\t\n ]+/, $line; print OUT $line, "\n"; if ($line =~ /jump/) { $start = 0; while (length($tmp[$start]) == 0) {$start++;} $x = $tmp[$start+2]; $y = $tmp[$start+3]; $z = $tmp[$start+4]; $dist = sqrt ($x*$x + $y*$y + $z*$z); # print "$x $y $z ... $dist "; $somecmd = "\$val = $distfn;"; $somecmd =~ s/DIST/$dist/; eval ($somecmd); # print $somecmd, "\n";; # print $val , "\n"; # print "------\n"; $somecmd = "\$cmd = \"echo $distcmd\""; $somecmd =~ s/DISTDEPVALUE/$val/; eval ($somecmd); # print $somecmd, "\n";; # print $cmd , "\n"; # print "------\n"; print OUT "$cmd\n"; } } sub min { my ($a, $b) = @_; if ($a < $b) {return $a;} else {return $b;} }