-
Notifications
You must be signed in to change notification settings - Fork 0
/
PS_open.pro
632 lines (576 loc) · 16.7 KB
/
PS_open.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
;*************************************************************************
; Copyright (c) 2002 The University of Chicago, as Operator of Argonne
; National Laboratory.
; Copyright (c) 2002 The Regents of the University of California, as
; Operator of Los Alamos National Laboratory.
; This file is distributed subject to a Software License Agreement found
; in the file LICENSE that is included with this distribution.
;*************************************************************************
;
; this routine is requied for generate the runtime executable
;
PRO os_init
;+
; NAME:
; OS_INIT
;
; PURPOSE:
; Defines the structure of main operating system variables. All the
; operating system dependent varibles used in data catcher are
; assembled in this routine.
;
; CATEGORY:
; Global System Variables !os.
;
; CALLING SEQUENCE:
; OS_INIT
;
; PARAMETER FIELDS:
; ARCH: IDL detected operating system architecture
; OS: IDL detected operating system
; OS_FAMILY: IDL detected operating system family
; RELEASE: IDL release number
; FONT: Bold font used in highlight label in dialog
; DEVICE: Default output device
; FILE_SEP: Operating sytem file separator, '/' for unix '\' for W95
; CHMOD: Command change file permission mode, 'chmod'
; MV: Command rename file, 'mv' for unix, 'rename' for W95
; CP: Command copy file, 'cp' for unix, 'copy' for W95
; RM: Command remove file, 'rm' for unix, 'del' for W95
; LPR: Command print PS file, 'lpr' for unix, 'print' for W95
; PRT: Command print text file, 'enscript' for unix, 'print' for W95
; PRINTER: Default printer name, ''
; WC: Command return line count, 'wc' for unix
;
; COMMON BLOCKS:
; COMMON SYSTEM_BLOCK
;
; SIDE EFFECTS:
; This routine defines the OS_SYSTEM structure and the global
; system variable !os. All the system dependent varialbes used in
; data catcher and data viewer are kept in this routine.
;
; RESTRICTIONS:
; Current version works for Unix and W95 operating system.
;
; PROCEDURE:
; Porting to other operating system, the corresponding
; fields in 'os.init' may need to be modified accordingly.
;
; EXAMPLE:
;
; OS_INIT
;
; MODIFICATION HISTORY:
; Written by: Ben-chin K. Cha, 6-01-97.
; xx-xx-xx iii - comment
;-
@os.init
END
;
; PS_open,'name.ps' name defalut to idl
;
PRO PS_init
COMMON PRINTER_BLOCK,printer_info
COMMON colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
if n_elements (printer_info) eq 0 then $
printer_info = { $
name: '', $
color: 1, $
reverse: 0, $
base: 0L, $
ptr_field:0L }
; inherit from the parent process
if n_elements(r_curr) eq 0 then begin
tvlct,r,g,b,/get
r_orig = r
g_orig = g
b_orig = b
r_curr = r
g_curr = g
b_curr = b
end
END
PRO PS_close
;+
; NAME:
; PS_CLOSE
;
; PURPOSE:
; This routine closes the PostScript output device and resets the
; the original system graphic device as the output plot device.
;
; CALLING SEQUENCE:
; PS_CLOSE
;
; INPUTS:
; None.
;
; OUTPUTS:
; None.
;
; KEYWORD PARAMETERS:
; None.
;
; COMMON BLOCKS:
; COMMON SYSTEM_BLOCK
; COMMON COLORS
;
; RESTRICTIONS:
; The program 'PS_open.pro' must be loaded into IDL prior calling
; this routine.
;
; EXAMPLE:
;
; PS_OPEN, 'myfile.ps'
; tvscl,scan
; PS_CLOSE
;
; MODIFICATION HISTORY:
; Written by: Ben-chin K. Cha, 03-23-95.
;
; 07-28-97 bkc Add the support for reverse PostScript color scheme.
; Add handling capability for different operating system
;-
COMMON SYSTEM_BLOCK,OS_SYSTEM
COMMON colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
if !d.name eq 'PS' then begin
!P.FONT=-1
device,/close
r_curr = r_orig
g_curr = g_orig
b_curr = b_orig
TVLCT,r_orig,g_orig,b_orig
set_plot,OS_SYSTEM.device
end
END
PRO PS_TVRD,file=file,wid=wid,xoffset=xoffset,yoffset=yoffset,scale=scale
;+
; NAME:
; PS_TVRD
;
; PURPOSE:
; This routine dumps the WID contents to PS file it works for
; both 8bits or 24 bits devices
;
; CALLING SEQUENCE:
; PS_TVRD,wid=wid,file=file
;
; KEYWORDS:
; file - Specifies the PS output filename for TVRD, if not specified,
; the default 'idl.ps' is assumed.
; wid - Specifies the drawing window id to be dumped, if not specified,
; the current drawing window assumed.
; xoffset - specifies x offset center meter, default 2.54
; yoffset - specifies y offset center meter, default 2.54
; scale - specifies PS scale factor, default 1.1
;
; OUTPUTS:
; A copy of the specified wid is saved on the user specified PS file
; and a copy of PS file is sent to the user selected printer.
;
; EXAMPLE:
; Dump the current window content to the post script file idl.ps
;
; PS_TVRD
;
; MODIFICATION HISTORY:
; Written by: Ben-chin K. Cha, 03-23-04.
;
;-
COMMON SYSTEM_BLOCK,OS_SYSTEM
if keyword_set(wid) then WSET,wid
if keyword_set(file) eq 0 then file = 'idl.ps'
if keyword_set(yoffset) eq 0 then yoffset=2.54
if keyword_set(xoffset) eq 0 then xoffset=2.54
if keyword_set(scale) eq 0 then scale=1.1
tvlct,red,green,blue,/get
if !d.n_colors gt !d.table_size then begin
t_arr = TVRD(/true)
arr = color_quan(t_arr,1,r,g,b)
tvlct,r,g,b
endif else arr = TVRD()
sz = size(arr)
xs = sz(1)
ys = sz(2)
width = float(xs)/40
height = float(ys)/40
set_plot,'PS'
device,filename=file,/color,bits=8, $
xoffset=xoffset, yoffset=yoffset, $
scale_factor=scale, $
xsize=width,ysize=height
TV,arr
device,/close
set_plot,OS_SYSTEM.device
PS_close
PS_print,file
if !d.n_colors gt !d.table_size then tvlct,red,green,blue
END
PRO PS_enscript,fileName
;+
; NAME:
; PS_ENSCRIPT
;
; PURPOSE:
; This routine uses the system printing command to print
; an ASCII text file. On unix operating system the command
; 'enscript -r' is used.
;
; CALLING SEQUENCE:
; PS_ENSCRIPT, 'filename'
;
; INPUTS:
; filename : Specifies the ASCII filename to be printed.
;
; OUTPUTS:
; A copy of the specified file is sent to the user selected
; printer.
;
; KEYWORD PARAMETERS:
;
; COMMON BLOCKS:
; COMMON SYSTEM_BLOCK
;
; RESTRICTIONS:
; The program 'PS_open.pro' must be loaded into IDL prior calling
; this routine.
;
; EXAMPLE:
;
; PS_ENSCRIPT, 'myfile'
;
; MODIFICATION HISTORY:
; Written by: Ben-chin K. Cha, 03-23-95.
;
; 07-28-97 bkc Add handling capability for different operating system
;-
COMMON SYSTEM_BLOCK,OS_SYSTEM
if n_elements(fileName) eq 0 then begin
print,'Usage: PS_enscript, <fileName>'
return
end
if strtrim(fileName,2) eq '' then begin
print,'Usage: PS_enscript, <fileName>'
return
end
if OS_SYSTEM.os_family eq 'unix' then begin
if OS_SYSTEM.printer eq '' then $
str = OS_SYSTEM.prt + ' -r '+ fileName else $
str = OS_SYSTEM.prt + OS_SYSTEM.printer + ' -r '+ fileName
spawn,str
endif else $
spawn,[OS_SYSTEM.prt, fileName, OS_SYSTEM.printer]
END
PRO PS_print,psfile
;+
; NAME:
; PS_PRINT
;
; PURPOSE:
; This routine uses the system printing command to print
; a PostScript or ASCII text file. On the unix operating
; system the command 'lpr' is used.
;
; CALLING SEQUENCE:
; PS_PRINT, 'myfile.ps'
;
; INPUTS:
; myfile: Specifies either the PostScript or ASCII text filename
; to be printed.
;
; OUTPUTS:
; A copy of the specified file is sent to the user selected
; printer.
;
; KEYWORD PARAMETERS:
;
; COMMON BLOCKS:
; COMMON SYSTEM_BLOCK
;
; RESTRICTIONS:
; The program 'PS_open.pro' must be loaded into IDL prior calling
; this routine.
;
; EXAMPLE:
;
; PS_PRINT, 'myfile.ps'
;
; MODIFICATION HISTORY:
; Written by: Ben-chin K. Cha, 03-23-95.
;
; 07-28-97 bkc Add handling capability for different operating system
; 05-14-98 bkc Add the checking for unreadable color on the PS plot
; On unix if the color is too light use the gv to preview
; pops up setup printer and info dialog
;-
COMMON SYSTEM_BLOCK,OS_SYSTEM
COMMON PRINTER_BLOCK,printer_info
COMMON colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
if (n_elements(psfile) ne 0) then begin
if strtrim(psfile,2) eq '' then begin
print,'Usage: PS_print, <filename>'
return
end
end else psfile = 'idl.ps'
if OS_SYSTEM.os_family eq 'unix' then begin
if OS_SYSTEM.printer eq '' then $
str = OS_SYSTEM.lpr + ' ' + psfile else $
str = OS_SYSTEM.lpr + OS_SYSTEM.printer +' '+ psfile
if n_elements(r_curr) then begin
color = r_curr(0) + g_curr(0)*256L + b_curr(0)*256L ^2
if color ge 16777200 then begin
temp = ['Warning:','',$
'There may be problem of unreadable title or legend on PS plot.',$
'The ghostview is brought up for you to preview the PS plot.', $
'If the PS plot looks fine you may use the ghostview to send the',$
'print job and then close the ghostview and Printer Setup Dialog.',$
'','If you can not see the title and legend, please close', $
'the ghostview program first, try different color table or set the ',$
'Reverse_Legend_Color to "Y" in Printer Setup Dialog first then', $
'try Print again']
res=dialog_message(temp,/info,title='PS legend problem')
PS_printer
spawn,'gv '+psfile + ' &'
end
endif else spawn,str
endif else begin
str = OS_SYSTEM.lpr + ' ' + psfile + ' ' + OS_SYSTEM.printer
spawn,str
end
print,str
END
PRO PS_printer_Event, Event
COMMON SYSTEM_BLOCK,OS_SYSTEM
COMMON PRINTER_BLOCK,printer_info
WIDGET_CONTROL,Event.Id,GET_UVALUE=Ev
CASE Ev OF
'PS_REVERSE': BEGIN
printer_info.reverse = Event.Index
END
'BGROUP3': BEGIN
CASE Event.Value OF
0: begin
Print,'Button B/W Pressed'
printer_info.color = 0
end
1: begin
Print,'Button Color Pressed'
printer_info.color = 1
end
ELSE: Message,'Unknown button pressed'
ENDCASE
END
'FIELD5': BEGIN
WIDGET_CONTROL, printer_info.ptr_field, GET_VALUE=str
printer_info.name = strtrim(str(0),2)
!os.printer = printer_info.name
END
'BGROUP7': BEGIN
CASE Event.Value OF
0: begin
WIDGET_CONTROL, printer_info.ptr_field, GET_VALUE=str
printer_info.name = strtrim(str(0),2)
WIDGET_CONTROL, printer_info.base, /DESTROY, BAD_ID=bad
end
1: begin
WIDGET_CONTROL, printer_info.base, /DESTROY, BAD_ID=bad
end
ELSE: Message,'Unknown button pressed'
ENDCASE
END
ENDCASE
if printer_info.name ne '' then begin
if OS_SYSTEM.os_family eq 'unix' then $
OS_SYSTEM.printer = ' -P '+printer_info.name + ' ' else $
OS_SYSTEM.printer = printer_info.name
end
END
PRO PS_printer, GROUP=Group
;+
; NAME:
; PS_PRINTER
;
; PURPOSE:
; This widget dialog allows the user to set up PostScript printer
; and printer name to be used by the IDL session. Default setting
; is color PS using default printer.
;
; CATEGORY:
; Widgets.
;
; CALLING SEQUENCE:
; PS_PRINTER [,GROUP=Group]
;
; INPUTS:
; None.
;
; KEYWORD PARAMETERS:
; GROUP: The widget ID of the group leader of the widget. If this
; keyword is specified, the death of the group leader results in
; the death of PS_PRINTER.
;
; OUTPUTS:
;
; COMMON BLOCKS:
; COMMON PRINTER_BLOCK
;
; SIDE EFFECTS:
; Initially the system printer is set to the user's default
; printer. If a null printer name is specified, whatever the
; system printer was previously set will be used.
;
; RESTRICTIONS:
; The program 'PS_open.pro' must be loaded into IDL prior calling
; this routine.
;
; PROCEDURE:
;
; EXAMPLE:
;
; PS_PRINTER
;
; MODIFICATION HISTORY:
; Written by: Ben-chin K. Cha, 6-01-97.
; 10-15-97 bkc - Add droplist Y/N for reverse color option
; Now it defaults to non reverse color option.
; 05-14-98 bkc - Remove the B/W option, use the xloadct to select B/W
; Change reverse video to reverse legeng color if legend
; is in white color
;-
COMMON PRINTER_BLOCK,printer_info
if XRegistered('PS_printer') then return
IF N_ELEMENTS(Group) EQ 0 THEN GROUP=0
PS_init
junk = { CW_PDMENU_S, flags:0, name:'' }
PS_printer_base = WIDGET_BASE(GROUP_LEADER=Group, $
TITLE='Setup Printer', $
ROW=1, $
MAP=1, $
UVALUE='PS_PRINTER')
printer_info.base = PS_printer_base
BASE2 = WIDGET_BASE(PS_printer_base, $
COLUMN=1, $
MAP=1, $
UVALUE='BASE2')
LABEL3 = WIDGET_LABEL( BASE2, $
; FONT=!os.font, $
UVALUE='LABEL3', $
VALUE='Setup PS Printer')
; Btns167 = [ $
; 'B/W', $
; 'Color' ]
; BGROUP3 = CW_BGROUP( BASE2, Btns167, $
; ROW=1, $
; EXCLUSIVE=1, $
; LABEL_LEFT='Output PS', $
; UVALUE='BGROUP3')
; WIDGET_CONTROL,BGROUP3,SET_VALUE= printer_info.color
Btn168 = ['N','Y']
ps_reverse = WIDGET_DROPLIST(BASE2, VALUE=Btn168, $
UVALUE='PS_REVERSE',TITLE='Reverse Legend Color')
WIDGET_CONTROL,ps_reverse,SET_DROPLIST_SELECT=printer_info.reverse
FieldVal269 = [ $
'' ]
FIELD5 = CW_FIELD( BASE2,VALUE=FieldVal269, $
ROW=1, RETURN_EVENTS=1, $
STRING=1, $
TITLE='Printer Name', $
UVALUE='FIELD5', $
XSIZE=10)
printer_info.ptr_field = FIELD5
if strtrim(printer_info.name,2) ne '' then $
WIDGET_CONTROL,FIELD5,SET_VALUE=printer_info.name
Btns342 = [ 'Accept', 'Cancel' ]
BGROUP7 = CW_BGROUP( BASE2, Btns342, $
ROW=1, $
UVALUE='BGROUP7')
WIDGET_CONTROL, PS_printer_base, /REALIZE
XMANAGER, 'PS_printer', PS_printer_base
END
PRO PS_open,psfile,TV=TV,xoffset=xoffset,yoffset=yoffset,xsize=xsize,ysize=ysize,scale_factor=scale_factor,font=font
;+
; NAME:
; PS_OPEN
;
; PURPOSE:
; This routine sets the current graphics device to PostScript.
; and saves plot in a user specified PostScript file.
;
; CALLING SEQUENCE:
; PS_OPEN, 'myfile.ps' [,/TV]
;
; INPUTS:
; myfile.ps: Specifies the PostScript filename to be saved.
;
; OUTPUTS:
; The PostScript graphic output is saved which can be sent to
; any PostScript printer or viewer.
;
; KEYWORD PARAMETERS:
; TV: Specifies whether TV image plot to be used in PS.
; XOFFSET: Specifies xoffset in centimeter, default 1.905
; YOFFSET: Specifies yoffset in centimeter, default 7.
; XSIZE: Specifies yoffset in centimeter, default 15
; YSIZE: Specifies yoffset in centimeter, default 15
; SCALE_FACTOR: Specifies scale factor, default 1
; FONT: Specifies font string
;
; COMMON BLOCKS:
; COMMON PRINTER_BLOCK
; COMMON COLORS
;
; RESTRICTIONS:
; The program 'PS_open.pro' must be loaded into IDL first before
; calling this routine.
;
; EXAMPLE:
;
; PS_OPEN, 'myfile.ps'
; tvscl,image
; PS_CLOSE
;
; MODIFICATION HISTORY:
; Written by: Ben-chin K. Cha, 03-23-95.
;
; 07-28-97 bkc Add the support for color PostScript
; Add the support for reverse video
; Add handling capability for different operating system
; 05-15-98 bkc Change the reverse video to reverse legend color for
; 2D TV plot, to get reverse video use the xloadct's
; option, reverse feature
; 03-03-03 bkc add keyword xoffset,yoffset,xsize,ysize
; 05-19-04 bkc add keyword font string
;-
COMMON PRINTER_BLOCK,printer_info
COMMON colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
PS_init
set_plot,'PS'
!P.FONT=-1
if (n_elements(psfile) ne 0) then begin
scale = 1
if keyword_set(scale_factor) then scale=scale_factor
if keyword_set(TV) then begin
; use xloadct reverse video, reverse legend only
if keyword_set(yoffset) eq 0 then yoffset=7.
if keyword_set(xoffset) eq 0 then xoffset=1.905
if keyword_set(xsize) eq 0 then xsize=15
if keyword_set(ysize) eq 0 then ysize=15
if keyword_set(font) eq 0 then font='Courier'
if printer_info.color gt 0 then $
device,filename=psfile,/color,bits=8, set_font=font,/Bold, $
scale_factor=scale,xoffset=xoffset, $
yoffset=yoffset, xsize=xsize, ysize=ysize else $
device,filename=psfile,/Courier,/Bold
endif else begin
if printer_info.color gt 0 then begin
device,filename=psfile,/color,bits=8,set_font=font,/Bold, $
scale_factor=scale, $
yoffset=7, xsize=17.78, ysize=12.7
endif else $
device,filename=psfile,set_font=font,/Bold, $
scale_factor=scale, $
yoffset=7, xsize=17.78, ysize=12.7
end
end
END