#!/usr/bin/perl -w # streamlined rewrite of James Phillips' namdplot with enhancements # Ilya Balabin, 2004-2005 sub usage { die( "Usage: namdplot {field} ... \n", "Fields: TS BOND ANGLE DIHED IMPRP \n", " ELECT VDW BOUNDARY MISC KINETIC \n", " TOTAL TEMP TOTAL2 TOTAL3 TEMPAVG \n", " PRESSURE GPRESSURE VOLUME PRESSAVG GPRESSAVG \n", "More fields may be added in future NAMD releases. \n", "If no real field given, displays timing information.\n", ); }; # find where/whether xmgrace is installed $xmgrace = `which xmgrace`; chomp $xmgrace; die("ERROR: Xmgrace needed but not found in the path.\n") unless length($xmgrace); # get field name and number (or timing) $nargs = $#ARGV; $nf = -1; if ($nargs == 0) { # one argument } elsif ($nargs > 0) { # several arguments $last_file = pop(@ARGV) or usage; push(@ARGV, $last_file); open FH, "<$last_file" or die("Can not open $last_file : $!\n"); $fname = shift or usage; while () { last if /^ETITLE/; }; close FH or die("Can not close $last_file : $!\n"); @f = split; foreach $i (0..$#f) { $nf = $i, last if $f[$i] =~ /^${fname}$/i; }; # restore argument list if look for timing unshift(@ARGV, $fname) if $nf == -1; } else { # no arguments; show usage info usage; }; # spawn xmgrace open FH, "| ${xmgrace} -free -pipe -noask" or die("Can not open piping to xmgrace: $! \n"); # plot data if ($nf > 0) { # plot field while (<>) { next unless /^ENERGY:/; @f = split; print FH $f[$nf], "\n"; }; } else { # plot timing while (<>) { next unless /^TIMING/; chomp; s/^.*Wall:\s+\S+\s+(\S+)\/step.*$/$1/; print FH $_,"\n"; }; }; # close xmgrace close FH or die("Can not close piping to xmgrace: $! \n"); __END__