home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 334_02 / lasergnu < prev    next >
Text File  |  1991-02-05  |  4KB  |  161 lines

  1. #!/bin/csh -f
  2. #
  3. # Print gnuplot output on an Imagen or Postscript laser printer.
  4.  
  5. set print_banner = on    # Print a banner page unless told otherwise.
  6. set input_files = ()    # the plot input command files
  7. set lpr_opts = ()        # options to lpr
  8.  
  9. # Default printer set by shell variable PRINTER.
  10. if (! $?PRINTER) then 
  11.     if ($?LASER) then
  12.           set PRINTER=$LASER
  13.     else
  14.            set PRINTER="lw0"
  15.     endif
  16. endif
  17. set printer = (-P$PRINTER)
  18.  
  19. # File for plot commands, and for plot output
  20. set TMP=/tmp/plot$$
  21. set outfile=$TMP.out    # the output file
  22. onintr cleanup
  23.  
  24. # default is Imagen mode for Imagen printer; see -p option
  25. set setterm="set terminal imagen"
  26. set LANG="-Limpress"
  27.  
  28. set usage="usage: lasergnu [-Pprinter] [-b] [-p] [-t title] [-f file] ['plot command']...."
  29.  
  30. # Loop through the command-line arguments.
  31.  
  32. top:
  33.     if ($#argv > 0) then
  34.  
  35.         switch ("$argv[1]")
  36.  
  37.         case -b*:    # Do not print a banner page.
  38.         case -J*:    # Compatible with imprint.
  39.             set print_banner = off
  40.                      set lpr_opts=($lpr_opts -h)
  41.             shift argv
  42.             goto top
  43.  
  44.         case -f?*:    # Specify file containing plot commands
  45.             set input_files = ($input_files `echo $argv[1] | sed 's/^-f//'`)
  46.             shift argv
  47.             goto top
  48.  
  49.         case -f:    # Specify file containing plot commands
  50.             shift argv
  51.             if ($#argv > 0) then
  52.                 set input_files = ($input_files $argv[1])
  53.                 shift argv
  54.             else
  55.                 echo "Usage: -f file ..."
  56.                 echo "Type    lasergnu -help    for help."
  57.                 exit (1)
  58.             endif
  59.             goto top
  60.  
  61.         case -t?*:    # Specify title of plot
  62.             echo set title \""`echo $argv[1] | sed 's/^-t//'`"\" >> $TMP
  63.             shift argv
  64.             goto top
  65.  
  66.         case -t:    # Specify title of plot
  67.             shift argv
  68.             if ($#argv > 0) then
  69.                 echo set title \""$1"\" >> $TMP
  70.                 shift argv
  71.             else
  72.                 echo "Usage: -t title ..."
  73.                 echo "Type    lasergnu -help    for help."
  74.                 exit (1)
  75.             endif
  76.             goto top
  77.           case -help:
  78.             echo "$usage"
  79.             exit(1)
  80.  
  81.         case -P?*:    # Set the printer, exactly as by itroff.
  82.             set printer = $argv[1]
  83.             shift argv
  84.             goto top
  85.  
  86.         case -P:    # Set the printer, exactly as by itroff.
  87.             shift argv
  88.             if ($#argv > 0) then
  89.                 set printer = (-P$argv[1])
  90.                 shift argv
  91.             else
  92.                 echo "Usage: -P printer ..."
  93.                 echo "Type    lasergnu -help    for help."
  94.                 exit (1)
  95.             endif
  96.             goto top
  97.  
  98.                 # use impress 
  99.            case -I:
  100.                 echo Imagen is the default mode now
  101.              shift argv
  102.                 goto top
  103.  
  104.                 # use postscript instead of impress language
  105.            case -p:
  106.                 set setterm="set term postscript"
  107.                 set LANG="-Lpostscript"
  108.              shift argv
  109.                 goto top
  110.  
  111.         case -?*:
  112.             echo "I do not recognize option $argv[1]."
  113.             echo "$usage"
  114.             exit (1)
  115.  
  116.         default:
  117.               echo "$argv[1]"    >> $TMP
  118.             shift argv
  119.             goto top
  120.  
  121.         endsw
  122.     endif
  123.  
  124. # try to devine the printer type
  125. if ($printer =~ -Plw*) then
  126.     set setterm="set term postscript"
  127.     set LANG="-Lpostscript"
  128. endif
  129.  
  130. if ($printer =~ -Pim*) then
  131.     set setterm="set term imagen"
  132.     set LANG="-Limpress"
  133. endif
  134.  
  135. # Set up input file
  136. echo $setterm > $TMP.plt
  137. echo set output \"$outfile\" >> $TMP.plt
  138. if (-e $TMP) cat $TMP >> $TMP.plt
  139.  
  140. # If input file is specified AND command line contains plot commands, then
  141. #    do command line args first, then plot commands in input file.
  142. gnuplot $TMP.plt $input_files
  143.  
  144. if ($status == 0 && -e $outfile && ! -z $outfile) then
  145.     # The printer is whatever printer was last specified,
  146.     # or the default printer if none was specified.
  147.     if ($LANG == -Limpress) then
  148.         /usr/local/bin/ipr $LANG $printer \
  149.            -D"jobheader $print_banner" \
  150.            -D"pagereversal on" \
  151.            -D"program lasergnu" $outfile
  152.     else if ($LANG == -Lpostscript) then
  153.            lpr $lpr_opts $printer $outfile
  154.     endif
  155. else
  156.     echo "lasergnu: error in plotting or empty plot; nothing printed."
  157. endif
  158.  
  159. cleanup:
  160. rm -f $TMP* $outfile
  161.