Index: /trunk/SRC/Postscript/printps.pro
===================================================================
--- /trunk/SRC/Postscript/printps.pro	(revision 379)
+++ /trunk/SRC/Postscript/printps.pro	(revision 380)
@@ -44,5 +44,5 @@
 ;
 ;-
-PRO printps_event, event
+PRO printps_event, event, uval = uval
 ;
   compile_opt idl2, strictarrsubs
@@ -54,5 +54,5 @@
 ;------------------------------------------------------------
 ; What kind of event do we have ?
-  widget_control, event.id, get_uvalue = uval
+  IF NOT keyword_set(uval) THEN widget_control, event.id, get_uvalue = uval
 ; case on the event
   CASE uval.name OF
@@ -135,5 +135,5 @@
   ENDCASE
 ; we destroy the widget
-  widget_control, event.top, /destroy
+  IF n_tags(event) GT 1 THEN widget_control, event.top, /destroy
 ; if the file was originally gzipped, then we re-gzip it and exit
   IF uval.gzip THEN BEGIN
@@ -196,4 +196,14 @@
 ; be completed by .ps and/or .gz.
 ;
+; @keyword ARCHIVE {default=0} {type=integer 0 or 1}
+; activate to bypass the widget and directly archive the postcript
+; (useful to use printps in batch mode)
+;
+; @keyword DIRECTPRINT {default=not defined} {type=string}
+; bypass the widget and directly define the printer that must be used
+; to print the postcript file. DIRECTPRINT must correspond to one of
+; the names defined in the comoon variables printer_machine_names or
+; printer_human_names. useful to use printps in batch mode 
+;
 ; @uses
 ; <pro>cm_4ps</pro>
@@ -214,5 +224,5 @@
 ;
 ;-
-PRO printps, psfilename
+PRO printps, psfilename, ARCHIVE = archive, DIRECTPRINT = directprint
 ;
 ; this is working only with unix/linux/osX machines
@@ -263,60 +273,89 @@
   gzipped = strpos(nameps, '.gz')
 ; if the file is gzipped we call gunzip and change its name
-  IF gzipped NE -1 THEN BEGIN
+  IF gzipped NE -1 AND NOT keyword_set(archive) THEN BEGIN
     spawn, '\gunzip ' + nameps
     nameps = strmid(nameps, 0, gzipped)
-  endif
+  ENDIF
+;------------------------------------------------------------
+; what should we do?
+;------------------------------------------------------------
+  CASE 1 OF
+;------------------------------------------------------------
+; direct archiving...
+;------------------------------------------------------------
+    keyword_set(archive):IF gzipped EQ -1 THEN printps_event, uval = {name:'archive', nameps:nameps, gzip:gzipped NE -1}
 ;------------------------------------------------------------
 ; build the widget
 ;------------------------------------------------------------
-  base = widget_base(/row, title = 'Postscript file: ' $
-                     + file_basename(nameps))
+    keyword_set(directprint): BEGIN 
+; check if directprint is well defined
+      printnumb = (where(strlowcase(printer_machine_names) EQ strlowcase(directprint)))[0]
+      IF printnumb EQ -1 THEN BEGIN
+        printnumb = (where(strlowcase(printer_human_names) EQ strlowcase(directprint)))[0]
+        IF printnumb EQ -1 THEN BEGIN
+          dummy = report('directprint does not correspond to any printer defined in printer_machine_names or printer_human_names common variable')
+          return
+        ENDIF
+      ENDIF
+; call printps_event with predefined event and uvalue
+      printps_event, {value:printnumb}, uval = {name:'print', nameps:nameps, gzip:gzipped NE -1}
+    END
+;------------------------------------------------------------
+; build the widget
+;------------------------------------------------------------
+    ELSE:BEGIN 
+      base = widget_base(/row, title = 'Postscript file: ' $
+                         + file_basename(nameps))
 ; ps viewers grouped button
-  psviewers = ['no psviewers found']
-  IF file_which(getenv('PATH'), 'gv') NE '' THEN $
-    psviewers = [psviewers, 'GNU Ghostview']
-  IF file_which(getenv('PATH'), 'ggv') NE '' THEN $
-    psviewers = [psviewers, 'Gnome Ghostview']
-  IF file_which(getenv('PATH'), 'ghostview') NE '' THEN $
-    psviewers = [psviewers, 'Ghostview']
-  IF file_which(getenv('PATH'), 'gs') NE '' THEN $
-    psviewers = [psviewers, 'Ghostscript']
-  IF file_which(getenv('PATH'), 'kghostview') NE '' THEN $
-    psviewers = [psviewers, 'Kghostview']
+      psviewers = ['no psviewers found']
+      IF file_which(getenv('PATH'), 'gv') NE '' THEN $
+         psviewers = [psviewers, 'GNU Ghostview']
+      IF file_which(getenv('PATH'), 'ggv') NE '' THEN $
+         psviewers = [psviewers, 'Gnome Ghostview']
+      IF file_which(getenv('PATH'), 'ghostview') NE '' THEN $
+         psviewers = [psviewers, 'Ghostview']
+      IF file_which(getenv('PATH'), 'gs') NE '' THEN $
+         psviewers = [psviewers, 'Ghostscript']
+      IF file_which(getenv('PATH'), 'kghostview') NE '' THEN $
+         psviewers = [psviewers, 'Kghostview']
 ; if at least one of viewer was found we define these buttons
-  IF n_elements(psviewers) GT 1 THEN BEGIN
-    psviewers = psviewers[1:*]
-    notused = cw_bgroup(base, psviewers, /frame, label_top = 'Visualize' $
-                        , uvalue = {name:'visualize', nameps:nameps} $
-                        , /column, /return_name)
-  ENDIF
+      IF n_elements(psviewers) GT 1 THEN BEGIN
+        psviewers = psviewers[1:*]
+        notused = cw_bgroup(base, psviewers, /frame, label_top = 'Visualize' $
+                            , uvalue = {name:'visualize', nameps:nameps} $
+                            , /column, /return_name)
+      ENDIF
 ; printers list grouped buttons
 ; are the common variables printer_human_names and printer_human_names
 ; defined in a proper way?
-  CASE 1 OF
-    n_elements(printer_human_names) eq 0: $
-      noting = report('the cm_4ps variable printer_human_names is not defined... !CWe could not propose any printer', /simple)
-    n_elements(printer_human_names) NE n_elements(printer_machine_names): $
-      noting = report('the cm_4ps variables printer_human_names and !Cprinter_machine_names do not have the same number of arguments... !CWe could not propose any printer', /simple)
-    printer_human_names[0] EQ '':
-    ELSE:notused = $
-      cw_bgroup(base, printer_human_names, /frame, /column $
-                , label_top = 'Select printer' $
-                , uvalue = {name:'print', nameps:nameps, gzip:gzipped NE -1})
+      CASE 1 OF
+        n_elements(printer_human_names) eq 0: $
+           noting = report('the cm_4ps variable printer_human_names is not defined... !CWe could not propose any printer', /simple)
+        n_elements(printer_human_names) NE n_elements(printer_machine_names): $
+           noting = report('the cm_4ps variables printer_human_names and !Cprinter_machine_names do not have the same number of arguments... !CWe could not propose any printer', /simple)
+        printer_human_names[0] EQ '':
+        ELSE:notused = $
+           cw_bgroup(base, printer_human_names, /frame, /column $
+                     , label_top = 'Select printer' $
+                     , uvalue = {name:'print', nameps:nameps, gzip:gzipped NE -1})
+      ENDCASE
+; 'archive ps' button, can be created only if archive_ps ne 0
+      IF keyword_set(archive_ps) THEN $
+         notused = widget_button(base, value = 'archive ps' $
+                                 , uvalue = {name:'archive', nameps:nameps $
+                                             , gzip:gzipped NE -1})
+; quit button
+      notused = widget_button(base, value = 'quit' $
+                              , uvalue = {name:'quit', nameps:nameps $
+                                          , gzip:gzipped NE -1})
+;------------------------------------------------------------
+      widget_control, base, /realize
+;------------------------------------------------------------
+      xmanager, 'printps', base, /no_block
+;------------------------------------------------------------
+    END
   ENDCASE
-; 'archive ps' button, can be created only if archive_ps ne 0
-  IF keyword_set(archive_ps) THEN $
-    notused = widget_button(base, value = 'archive ps' $
-                            , uvalue = {name:'archive', nameps:nameps $
-                                        , gzip:gzipped NE -1})
-; quit button
-  notused = widget_button(base, value = 'quit' $
-                          , uvalue = {name:'quit', nameps:nameps $
-                                      , gzip:gzipped NE -1})
-;------------------------------------------------------------
-  widget_control, base, /realize
-;------------------------------------------------------------
-  xmanager, 'printps', base, /no_block
-;------------------------------------------------------------
+
+
   return
 end
