source: trunk/Postscript/printps.pro @ 69

Last change on this file since 69 was 16, checked in by pinsard, 18 years ago

upgrade of POSTSCRIPT/Postscript according to cerbere.lodyc.jussieu.fr: /usr/home/smasson/SAXO_RD/ : files

  • Property svn:executable set to *
File size: 11.9 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME:
6;       printps
7;
8; PURPOSE: postscript visualisation/archiving/printing
9;
10; CATEGORY: for the postscripts
11;
12; CALLING SEQUENCE:
13;       imprime [,psfilename]
14;     
15; INPUTS:
16
17;       psfilename: the name of the postscript file we want to
18;           visualize and/or print and/or archive. It can also refer
19;           to a gzipped postscript file. If needed, this name will
20;           be completed by .ps and/or .gz
21;
22; KEYWORD PARAMETERS: None
23;
24; COMMON BLOCKS: cm_4ps
25;
26; SIDE EFFECTS:
27
28; - archiving possibilities -
29;
30; if archive_ps (common variable of cm_4ps) ne 0 then the postscript
31; can be saved for archiving if it is printed or if the button
32; "archive ps" is pressed. if it is printed and archive_ps = 1 then
33; the archiving is done automatically whereas we ask if the postscript
34; file must be archived or not.
35; If the postcript name is "idl.ps" (default name) then this name will
36; be changed to number.ps (number automatically found to be 1 larger
37; that any of the existing ps file).
38;
39; RESTRICTIONS:
40;
41; 1) this is working only with unix/linux/osX machines
42;
43; 2) definition of the printing command
44;
45; the printing command is defined by the common variable "print_command"
46; in cm_4ps. This command must be defind/build in a way that it the
47; instruction:
48;     print_command[i]+printer_machine_names[i]+' '+file.ps
49; or
50;     print_command+printer_machine_names[i]+' '+file.ps
51; is working. default definition is '\lpr -P'
52;
53; EXAMPLE: IDL> printps
54;
55; MODIFICATION HISTORY: Sebastien Masson (smasson@lodyc.jussieu.fr)
56;                       21/12/98
57;                       25/8/19999 utilisation des widgets
58;                       8/9/1999 utilisation de cw_bgroup
59; June 2005: Sebastien Masson: cleaning, english version with new commons
60;-
61;------------------------------------------------------------
62;------------------------------------------------------------
63;------------------------------------------------------------
64PRO printps_event, event
65;------------------------------------------------------------
66; include commons
67@cm_4ps
68  IF NOT keyword_set(key_forgetold) THEN BEGIN
69@updatenew
70  ENDIF
71;------------------------------------------------------------
72; What kind of event do we have ?
73  widget_control, event.id, get_uvalue = uval
74; case on the event
75  CASE uval.name OF
76;------------------------------------------------------------
77; visualize case : postscript visualization
78;------------------------------------------------------------
79    'visualize':BEGIN
80; paper orientation
81      if key_portrait EQ 1 then ori = 'portrait' ELSE ori = 'seascape'
82; paper format
83      CASE round(10*(total(page_size))) OF
84        round(10*(83.9611 + 118.816)) : papsize = 'a0'
85        round(10*(59.4078 + 83.9611)) : papsize = 'a1'
86        round(10*(41.9806 + 59.4078)) : papsize = 'a2'
87        round(10*(29.7039 + 41.9806)) : papsize = 'a3'
88        round(10*(20.9903 + 29.7039)) : papsize = 'a4'
89        round(10*(14.8519 + 20.9903)) : papsize = 'a5'
90        round(10*(10.4775 + 14.8519)) : papsize = 'a6'
91        round(10*(7.40833 + 10.4775)) : papsize = 'a7'
92        round(10*(5.22111 + 7.40833)) : papsize = 'a8'
93        round(10*(3.70417 + 5.22111)) : papsize = 'a9'
94        round(10*(2.61056 + 3.70417)) : papsize = 'a10'
95        round(10*(100.048 + 141.393)) : papsize = 'b0'
96        round(10*(70.6967 + 100.048)) : papsize = 'b1'
97        round(10*(50.0239 + 70.6967)) : papsize = 'b2'
98        round(10*(35.3483 + 50.0239)) : papsize = 'b3'
99        round(10*(25.0119 + 35.3483)) : papsize = 'b4'
100        round(10*(17.6742 + 25.0119)) : papsize = 'b5'
101        round(10*(22.86 + 30.48)) : papsize = 'archA'
102        round(10*(30.48 + 45.72)) : papsize = 'archB'
103        round(10*(45.72 + 60.96)) : papsize = 'archC'
104        round(10*(60.96 + 91.44)) : papsize = 'archD'
105        round(10*(91.44 + 121.92)) : papsize = 'archE'
106        round(10*(21.59 + 33.02)) : papsize = 'flsa'
107        round(10*(21.59 + 33.02)) : papsize = 'flse'
108        round(10*(13.97 + 21.59)) : papsize = 'halfletter'
109        round(10*(19.05 + 25.4)) : papsize = 'note'
110        round(10*(21.59 + 27.94)) : papsize = 'letter'
111        round(10*(21.59 + 35.56)) : papsize = 'legal'
112        round(10*(27.94 + 43.18)) : papsize = '11x17'
113        round(10*(43.18 + 27.94)) : papsize = 'ledger'
114        ELSE:papsize = 'a4'
115      ENDCASE   
116; call the viewers
117      CASE event.value OF
118        'Ghostview':spawn, '\ghostview -'+papsize+' -quiet -'+ori+' '+uval.nameps
119        'Ghostscript':spawn, '\gs -sPAPERSIZE='+papsize+' -q '+uval.nameps
120        'Kghostview':spawn, '\kghostview '+uval.nameps
121      ENDCASE
122      return
123    END
124;------------------------------------------------------------
125; print case: print and archive the file if needed
126;------------------------------------------------------------
127    'print':BEGIN
128; printer selection
129      printer = printer_machine_names[event.value]
130; print
131      CASE n_elements(print_command) OF
132        0:ptcmd = '\lpr -P'
133        1:ptcmd = print_command[0]
134        n_elements(printer_machine_names):ptcmd = print_command[event.value]
135        ELSE:BEGIN
136          ng = report('bad definition of print_command, common variable of cm_4ps. !C we did not print the postscript file', /simple)
137          return
138        END
139      ENDCASE
140      spawn, ptcmd + printer + ' ' + uval.nameps
141; ; printing informations...
142;       spawn, '\lpq -P'+imprimante+' -l', info
143; ; display them
144;       xdisplayfile, 'nothing', text = info $
145;                     , title = 'Printing Info '+file_basename(uval.nameps) $
146;                     , height = n_elements(info) <  24
147    END
148    ELSE:
149  ENDCASE
150; we destroy the widget
151  widget_control, event.top, /destroy
152; if the file was originaly gzipped, then we re-gzip it and exit
153  IF uval.gzip THEN BEGIN
154    spawn, '\gzip ' + uval.nameps
155    return
156  ENDIF
157;------------------------------------------------------------
158; archiving...
159;------------------------------------------------------------
160  IF (uval.name EQ 'print' OR uval.name EQ 'archive') $
161    AND keyword_set(archive_ps) THEN BEGIN
162    IF archive_ps NE 1 AND uval.name EQ 'print' then begin
163      wesave = report('Shall we archive the postcript?', /defaul_no, /question)
164      IF wesave EQ 0 THEN RETURN
165    ENDIF
166; if the name of the postscript is idl.ps then we change it
167    IF file_basename(uval.nameps) EQ 'idl.ps' then BEGIN
168; get the name of all the *.ps or *.ps.gz files available in psdir
169       allps = file_search(psdir+'*[.ps|.ps.gz|.pdf]', /test_regular, /nosort)
170       allps = file_basename(file_basename(allps,'.gz'),'.ps')
171       allps = file_basename(allps,'.pdf')
172; find which of these names corresponds to numbers...
173; get ascii codes of the names
174       testnumb = byte(allps)
175; longest name
176       maxstrlen = (size(testnumb, /dimensions))[0]
177; ascii codes can be 0 or between byte('0') and byte('9')
178       testnumb = testnumb EQ 0 OR $
179                  (testnumb GE (byte('0'))[0] AND testnumb LE (byte('9'))[0])
180       testnumb = where(total(testnumb, 1) EQ maxstrlen, count)
181       IF count NE 0 THEN BEGIN
182; get the largest number
183         psnumber = fix(allps[testnumb])
184         psnumber = (psnumber[reverse(sort(psnumber))])[0] + 1
185       ENDIF ELSE psnumber = 0
186; update uval.nameps
187      dirname = file_dirname(uval.nameps, /mark_directory)
188      uval.nameps = dirname+strtrim(psnumber, 2)+'.ps'
189; change the name of the file
190      file_move, dirname+'idl.ps', uval.nameps
191    ENDIF
192    spawn, '\gzip ' + uval.nameps
193  ENDIF
194
195  return
196end
197;------------------------------------------------------------
198;------------------------------------------------------------
199;------------------------------------------------------------
200;------------------------------------------------------------
201pro printps, psfilename
202;
203; this is working only with unix/linux/osX machines
204  thisOS = strupcase(strmid(!version.os_family, 0, 3))
205  CASE thisOS OF
206    'MAC':return
207    'WIN':return
208    ELSE:
209  ENDCASE
210;------------------------------------------------------------
211; include commons
212@cm_4ps
213  IF NOT keyword_set(key_forgetold) THEN BEGIN
214@updatenew
215  ENDIF
216;------------------------------------------------------------
217; we get the name of the latest created postscript.
218;------------------------------------------------------------
219  psdir = isadirectory(psdir, title = 'Select psdir')
220  CASE N_PARAMS() OF
221    0: BEGIN
222      nameps = file_search(psdir+'*.ps', /test_regular, /nosort)
223      IF nameps[0] EQ '' THEN BEGIN
224        ras = report('no postsrcipt file (ending with .ps) found in : ' + psdir)
225        RETURN
226      ENDIF
227      dates = (file_info(nameps)).mtime
228      lastdate = (reverse(sort(temporary(dates))))[0]
229      nameps = nameps[lastdate]
230    END
231    1: nameps = psfilename
232    ELSE: BEGIN
233      ras = report('printps accept only one element: psfilename')
234      RETURN
235    END
236  ENDCASE       
237;------------------------------------------------------------
238; we check if the file is exist in psdir. if necessary we complete
239; its name with .ps and/or ,gz
240;------------------------------------------------------------
241  nameps = find(nameps+'{.ps,}{.gz,}', iodir = psdir, /nopro)
242  IF nameps EQ 'NOT FOUND' THEN BEGIN
243    ng = report('file '+nameps+'[.ps][.gz] does not exist ')
244    return
245  ENDIF
246  gzipped = strpos(nameps, '.gz')
247; if the file is gzipped we call gunzip et change its name
248  IF gzipped NE -1 THEN BEGIN
249    spawn, '\gunzip ' + nameps
250    nameps = strmid(nameps, 0, gzipped)
251  endif
252;------------------------------------------------------------
253; build the widget
254;------------------------------------------------------------
255  base = widget_base(/row, title = 'Postscript file: ' $
256                     + file_basename(nameps))
257; ps viewers grouped button
258  psviewers = ['no psviewers found']
259  IF file_which(getenv('PATH'), 'ghostview') NE '' THEN $
260    psviewers = [psviewers, 'Ghostview']
261  IF file_which(getenv('PATH'), 'gs') NE '' THEN $
262    psviewers = [psviewers, 'Ghostscript']
263  IF file_which(getenv('PATH'), 'kghostview') NE '' THEN $
264    psviewers = [psviewers, 'Kghostview']
265; if at least one of viewer was found we define these buttons
266  IF n_elements(psviewers) GT 1 THEN BEGIN
267    psviewers = psviewers[1:*]
268    notused = cw_bgroup(base, psviewers, /frame, label_top = 'Visualize' $
269                        , uvalue = {name:'visualize', nameps:nameps} $
270                        , /column, /return_name)
271  ENDIF
272; printers list grouped buttons
273; are the common variables printer_human_names and printer_human_names
274; defined in a proper way?
275  CASE 1 OF
276    n_elements(printer_human_names) eq 0: $
277      noting = report('the cm_4ps variable printer_human_names is not defined... !CWe could not propose any printer', /simple)
278    n_elements(printer_human_names) NE n_elements(printer_machine_names): $
279      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)
280    printer_human_names[0] EQ '':
281    ELSE:notused = $
282      cw_bgroup(base, printer_human_names, /frame, /column $
283                , label_top = 'Select printer' $
284                , uvalue = {name:'print', nameps:nameps, gzip:gzipped NE -1})
285  ENDCASE
286; 'archive ps' button, can be created only if archive_ps ne 0
287  IF keyword_set(archive_ps) THEN $
288    notused = widget_button(base, value = 'archive ps' $
289                            , uvalue = {name:'archive', nameps:nameps $
290                                        , gzip:gzipped NE -1})
291; quit button
292  notused = widget_button(base, value = 'quit' $
293                          , uvalue = {name:'quit', nameps:nameps $
294                                      , gzip:gzipped NE -1})
295;------------------------------------------------------------
296  widget_control, base, /realize
297;------------------------------------------------------------
298  xmanager, 'printps', base, /no_block
299;------------------------------------------------------------
300  return
301end
302
303
Note: See TracBrowser for help on using the repository browser.