#!/usr/bin/perl # converts an evolver file to a v file # Usage: evol2v [-d dimension] [evolverfile] # if no evolverfile specified, reads from stdin # option -d to give dimension if "SPACE_DIMENSION" # is not present in the file # can handle "//" comments only for evolver input. however, # vertices /* coordinates */ # edges /* something */ # are both fine # The first two integers of a v file are number of vertices # and dimension, respectively. After these two numbers, # the vertices are listed. Whitespace, newlines are irrelevant. # Can deal with "#" comments. $dim = 3 ; if( @ARGV[0] =~ /^-d$/ ) { shift(@ARGV) ; $dim = shift(@ARGV) ; } while(<>) { @toks = get_line_tokens($_) ; $dim = $toks[1] if $toks[0] =~ /^SPACE_DIMENSION$/ ; last if $toks[0] =~ /^vertices$/ ; } $toks[0] =~ /^vertices$/ || die "can't find vertices.\n" ; while(<>) { @toks = get_line_tokens($_) ; last if $toks[0] =~ /^edges$/ ; next if @toks == 0 ; #skip blank or comment line shift(@toks) ; #don't care about vertex number ++$nvert ; for( $i = 0 ; $i < $dim ; $i++ ) { $v[$nvert-1][$i] = shift(@toks) ; } } $toks[0] =~ /^edges$/ || die "can't find edges.\n" ; print "$nvert $dim\n" ; for( $i = 0 ; $i < $nvert ; $i++ ) { for( $j = 0 ; $j < $dim ; $j++ ) { print "$v[$i][$j] " ; } print "\n" ; } #ignores double-slash comments sub get_line_tokens { $line = $_[0] ; chomp($line) ; $line =~ s/^\s*// ; #split fn doesn't ignore leading white. perl bug? if($line =~ /\/\//) { #ignore after "//" return split(/\s+/, $`) ; } else { return split(/\s+/, $line) ; } }