#!/usr/local/bin/perl $Usage = <<'EOQ'; faxis: take a bunch of output files with different parameters in the filename, and make axis plot file out of them with the filename-parameter as the X coordinate. (Why ask why?) Should be easy (?) to generalize to any X-Y plotter (see $axis) version 0.? Copyright (C) 1994 Karl J. Runge Usage: faxis [-o outfile] [-pref prefix] [-post postfix] [-axis 'axis cmd'] [-noaxis] [-ne -noerror] [-h -help] [-t] [-ns -nosort] [-sep sepvar] [-listonly] 'FileGlob1' 'FileGlob2' ... prefix is = and postfix is _ in Out_H=0.0_T=1.23 -t means put results in temporary file (i.e. view only) FileGlob's must be inside '' to protect from shell (but protection is somewhat unnecessary). Example: faxis energy T -t 'data*' TODO better regex in filename selection... pref and post detection autoname -n 1) energy_vs_T or 1) energy_vs_T_Inp_..... EOQ # Initialize some flags: $pref = '='; $post = '_'; $outfile = 'STDOUT'; $axis = 'xaxa -e '; $tmpfile = "/tmp/faxis$$"; $listonly = ''; $doerror = 'True'; $nosort = ''; $sorttype = 'cmp'; $nscount = '0'; $sepvar = ''; $sepval = 'BigBoote'; if ( $ARGV[0] =~ /^-h/ ) { print STDOUT "$Usage"; exit 0; } if ( $ARGV[0] !~ /^-/ ) { $ave = shift @ARGV; } else { die "avestring can't begin with '-': $ARGV[0]"; } if ( $ARGV[0] !~ /^-/ ) { $var = shift @ARGV; } else { die "varstring can't begin with '-': $ARGV[0]"; } LOOP: # process args while (@ARGV) { $_ = shift @ARGV; CASE: { /^-o$/ && ( $outfile = shift @ARGV, last CASE); /^-pref$/ && ( $pref = shift @ARGV, last CASE); /^-post$/ && ( $post = shift @ARGV, last CASE); /^-axis$/ && ( $axis = shift @ARGV, last CASE); /^-sep$/ && ( $sepvar = shift @ARGV, $nosort = 'True', last CASE); /^-t$/ && ( $outfile = "$tmpfile", last CASE); /^-noaxis$/ && ( $axis = '', last CASE); /^-noerror$/ && ( $doerror = '', last CASE); /^-ne$/ && ( $doerror = '', last CASE); /^-nosort$/ && ( $nosort = 'True', last CASE); /^-ns$/ && ( $nosort = 'True', last CASE); /^-listonly$/ && ( $listonly = 'True', last CASE); /^-h$/ && ( (print STDOUT "$Usage"), exit 0, last CASE); /^-help$/ && ( (print STDOUT "$Usage"), exit 0, last CASE); /^-/ && ( (print "$_ is not an option, Bye!\n"), exit 0, last CASE); unshift(ARGV,$_); # put back if done with flags last LOOP; } } if ( $nosort ) { $sorttype = 'numer'; } $nfile = 0; foreach (@ARGV) { #open(LIST,"eval ls $_ |"); open(LIST,"ls $_ |"); while () { # Get filenames to average chop; if ( -s $_) { $list[$nfile++] = $_; } } } if ( $listonly ) { print "Got these: \n"; foreach $file (@list) { print "$file\n"; } exit 0; } foreach $file (@list) { $fileT = "$file"."$post"; open(FILE, "$file") || die "can't open $file"; $value = ''; $error = ''; while () { if ( $doerror ) { $_ =~ s/\+\/-/ /; # get rid of +/- if ( $_ =~ /$ave\s+(\S+)\s+(\S+)/ ) { $value = "$1"; $error = "$2"; last; } } else { if ( $_ =~ /$ave\s+(\S+)\s+/ ) { $value = "$1"; last; } } } close(FILE); if ( $fileT =~ /$post$var$pref([^$post]+)($post)/ ) { $arg = "$1"; if ( ! $nosort ) { $Value{$arg} = $value; $Error{$arg} = $error; } else { if ( $sepvar && $fileT =~ /$post$sepvar$pref([^$post]+)($post)/ ) { $sepvalnew = "$1"; if ( $sepvalnew ne $sepval ) { $sepval = $sepvalnew; $PoundInsert{$nscount}='True'; } else { $PoundInsert{$nscount}=''; } } $Arg{$nscount} = $arg; $Value{$nscount} = $value; $Error{$nscount++} = $error; } } } select(STDOUT); if ( $outfile ne 'STDOUT' ) { open(OUT, ">$outfile") || die "can't open $outfile"; select(OUT); } if ( $doerror ) { print "a $var $ave error\n"; } else { print "a $var $ave\n"; } foreach $v (sort($sorttype keys %Value)) { if ( $nosort ) { $arg = $Arg{$v}; print "#\n" if $sepvar && $PoundInsert{$v}; } else { $arg = $v; } if ( $doerror ) { print "$arg $Value{$v} $Error{$v}\n"; } else { print "$arg $Value{$v}\n"; } } if ( $outfile ne 'STDOUT' ) { close(OUT); if ( $axis ne '' ) { system("$axis $outfile &"); } } #if ( -w $tmpfile ) { system("(sleep 15; rm -f $tmpfile ) &"); } if ( -w $tmpfile ) { system("sh -c \"(sleep 15; rm -f $tmpfile )\" &"); } sub numer { $a <=> $b; } sub cmp { $a cmp $b; }