From 9f5751aaa9d666a9a1d64805be65e23e2e7cfc62 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 19 Mar 2012 15:22:03 -0300 Subject: [PATCH] cameo/fped2d2z.pl: added option -r, like in zstack.pl --- cameo/fped2d2z.pl | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/cameo/fped2d2z.pl b/cameo/fped2d2z.pl index 09a70d8..7e457de 100755 --- a/cameo/fped2d2z.pl +++ b/cameo/fped2d2z.pl @@ -14,11 +14,18 @@ sub usage { - print STDERR "usage: $0 prefix [file ...]\n"; + print STDERR "usage: $0 [-r] prefix [file ...]\n\n"; + print STDERR " -r reverse Z stacking. Also swaps X and Y.\n"; exit(1); } +if ($ARGV[0] eq "-r") { + shift @ARGV; + $reverse = 1; +} +&usage if $ARGV[0] =~ /^-/; + $pfx = shift @ARGV; &usage unless defined $pfx; @@ -31,6 +38,20 @@ while (<>) { $skip = 1; } next if $skip; - s/\s+-?\d+(\.\d*)?$/$& $z/; - print; + $z{$z} .= $_; + $zmax = $z if $z > $zmax || !defined $zmax; +} + +if ($reverse) { + for (keys %z) { + ($t{$zmax-$_} = $z{$_}) =~ + s/^(-?\d+(\.\d*)?)\s+(-?\d+(\.\d*)?)/$3 $1/mg; + } + %z = %t; +} + +# sort, to make output easier to examine manually +for (sort { $b <=> $a } keys %z) { + $z{$_} =~ s/\s+-?\d+(\.\d*)?$/$& $_/gm; + print $z{$_}; }