#! /usr/bin/perl if ( ($#ARGV < 0) || ($#ARGV > 1) ) { print "showplot: Wrong number of arguments.\n"; print "\n"; print "Usage: showplot input_filename [ 'plot_arguments' ]\n"; print "\n"; exit 1; } # Do not buffer STDIN. $old_select = select(STDIN); $| = 1; select($old_select); # Do not buffer STDOUT. $old_select = select(STDOUT); $| = 1; select($old_select); # Process the command line arguments. $input_filename = $ARGV[0]; if ( $#ARGV == 0 ) { $plot_arguments = "\$f[0]"; } else { $plot_arguments = $ARGV[1]; } # Open the input file. open(INPUT, $input_filename) || die "Cannot open file '$input_filename'"; # Open a pipe to plotgnu. open(PLOTGNU, "| perl -S -- plotgnu.pl") || die "Cannot open pipe to plotgnu"; # Do not buffer the plotgnu pipe. $old_select = select(PLOTGNU); $| = 1; select($old_select); # Initialize the plot. print PLOTGNU "start_plot;1;0;$plot_arguments\n"; print PLOTGNU "set title 'Datafile = $input_filename'\n"; #### Look for file type identifier in the first line of the file. #### $input_line = ; if ( ! defined( $input_line ) ) { print STDERR "No text in plot file.\n"; exit 1; } @line1 = split(/ /, $input_line); if ( $line1[0] eq "#" ) { if ( $line1[1] eq "SFF" ) { # Skip header of current SFF file. $num_header_lines = $line1[3]; for ( $i = 0; $i < $num_header_lines; $i++ ) { $input_line = ; if ( ! defined( $input_line ) ) { print STDERR "SFF header terminated at line $i\n"; } } } } if ( $line1[0] eq "SFF" ) { # Skip header of old SFF file. $num_header_lines = $line1[2]; for ( $i = 0; $i < $num_header_lines; $i++ ) { $input_line = ; if ( ! defined( $input_line ) ) { print STDERR "SFF header terminated at line $i\n"; } } } if ( $line1[0] eq "MRCAT_XAFS" ) { # Skip header of MRCAT XAFS file. $num_header_lines = 17; for ( $i = 0; $i < $num_header_lines; $i++ ) { $input_line = ; if ( ! defined( $input_line ) ) { print STDERR "MRCAT_XAFS header terminated at line $i\n"; } } } #### Send the rest of the data file to plotgnu. #### while ($input_line = ) { print PLOTGNU "data "; # The variable $input_line should have a newline at the end, so we # don't have to send one explicitly. print PLOTGNU $input_line; } close(INPUT); # Tell plotgnu to display the plot. print PLOTGNU "plot\n"; print "Hit the return key to close the plot..."; $junk = getc; print PLOTGNU "exit\n"; close(PLOTGNU); print "done.\n";