#! /usr/bin/perl if ( ($#ARGV < 1) || ($#ARGV > 2) ) { print "plot2ps: Wrong number of arguments.\n"; print "\n"; print "Usage: plot2ps input_filename output_filename [ 'plot_arguments' ]\n"; print "\n"; exit 1; } # Process the command line arguments. $input_filename = $ARGV[0]; $output_filename = $ARGV[1]; if ( $#ARGV == 1 ) { $plot_arguments = "\$f[0]"; } else { $plot_arguments = $ARGV[2]; } # 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 terminal postscript\n"; print PLOTGNU "set output '$output_filename'\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 generate the plot. print PLOTGNU "plot\n"; print PLOTGNU "exit\n"; close(PLOTGNU);