Inform me () when using this script or encorporating it in a library.
Source code of saveplot.pro:
;+
; NAME:
; SAVEPLOT
; PURPOSE:
; Save the results of a routine as a postscript. Uses gv and
; gawk.
; CALLING SEQUENCE:
; saveplot, [fname, ]procname[, /NOGV]
; EXAMPLES:
; saveplot, 'output.eps', procname
; saves the output from procedure procname in the file fname
; saveplot, "someFunc, par1='someval'", /NOGV
; saves the output from procedure someFunc in someFunc.eps
; and doesn't show the ghostview
; KEYWORDS:
; fname = string with the filename for the output
; procname = string with the procedure name
; nogv = if set, then do not open the created file with gv
; MODIFICATION HISTORY:
; beginning 2004 Written by Sayuri Prior
; after beginning 2004 further developed by Eduard Westra
; 11/08/2004 EW added help header
; 15/12/2004 EW added color keyword to PS
; 25/01/2005 EW rewritten to not display via the X anymore, but
; just the ps file with ghostview (gv)
; 14/02/2005 EW Fixed problem with additional parameters passed
; to the executing procedure
; 07/03/2005 EW Add support for different sized PS files by
; being able to pass on DEVICE keywords to the saveplot routine
; 23/05/2005 EW Omitting the procname means saving it as
; procname.eps
; 23/05/2005 EW Added the /NOGV option to disable ghostview
; popping up when saveplot is run
; 09/01/2006 EW Added the command of how the file is created to
; the final postscript file.
;-
PRO saveplot, fname, procname, help=help, nogv=nogv, _EXTRA=extra
IF (KEYWORD_SET(HELP)) THEN BEGIN & doc_library,'saveplot' & RETURN & ENDIF
IF NOT KEYWORD_SET(procname) THEN BEGIN
procname = fname
fname = STRTRIM((STRSPLIT(fname, ",", /EXTRACT))[0],2)+'.eps'
ENDIF
IF NOT KEYWORD_SET(fname) THEN BEGIN & doc_library,'saveplot' & RETURN & ENDIF
;dir = './'
IF NOT KEYWORD_SET(nogv) THEN BEGIN & nogv = 0 & ENDIF
; send output to printer (i.e. saves as .ps)
SET_PLOT, 'ps'
IF isgdl() EQ 1 THEN DEVICE, _STRICT_EXTRA=extra ELSE DEVICE, BITS=8, /COLOR, _STRICT_EXTRA=extra
DEVICE, file=fname
void = execute(procname)
DEVICE, /CLOSE
;EW filename fix...
t1 = STRSPLIT(procname, '"', /EXTRACT)
proc = STRJOIN(t1, '\"', /SINGLE)
awkArg = '{print $0; if (NR == 6) {print "%%CreationCommand: '+proc+'"}}'
SPAWN, ['gawk', awkArg, fname], newFile, /noshell
FILE_DELETE, fname, /ALLOW_NONEXISTENT
OPENW, unit, fname, /GET_LUN
PRINTF, unit, newFile, FORMAT='(A)'
CLOSE, unit
;EW until here...
IF ((void) AND (nogv EQ 0)) THEN SPAWN,'gv '+fname
SET_PLOT, 'X'
END