; file: psplot_begin.idl = start loop screen/PostScript output
; last: Jan 16 2005 
; note: requires prior call @psplot_params.idl
;       requires subsequent call @psplot_end.idl
;       !p.multi may be reset in prior call @psplot_pmulti.idl
;       starts two-device loop to produce nearly equal screen and PS plots
;       screen character height varies (e.g. PS/DEC = 1.268)
;       so vertical separation x-axis labeling and y-margins differ
;       between display devices, and therefore vertical extent y-axis 
;       and x-axis tick sizes too.

; hardware device character sizes
;                 SUN   TEK    PS      SGI   ALDI  OSLO
;  !d.x_ch_size =  6     8    0.222cm   12     6    6
;  !d.y_ch_size = 12    10    0.352cm   12     9   12
;  aspect ratio =  2     1.25 1.58558    1     1.5
x_ch_sizedev=float(!d.x_ch_size)  ; this device char width
y_ch_sizedev=float(!d.y_ch_size)  ; this device char height
wcharps=0.222                     ; postscript char width in cm
hcharps=0.352                     ; postscript char height in cm

; convert sizes into floats
xsizeps=float(xsizeps)
ysizeps=float(ysizeps)

; save device parameters (restored in psplot_end.idl)
screentype_old=!d.name

; set !p.multi
!p.multi=[0,multipanel,0,0]

; screen window rescaling
;; scalewindow=1.00
;; if (!d.y_ch_size eq 10) then scalewindow=0.84 ; equal window/gv size TEK
;; if (!d.y_ch_size eq 9) then scalewindow=1.33  ; equal window/gv size ALDI
;; if (!d.y_ch_size eq 12) then scalewindow=1.76 ; equal window/gv size OSLO
;; ;if (total(multipanel) ne 0) then scalewindow=0.9
scalewindow=1.3   ;RR similar relative labeling size as gv 

; character size and margin sizes
charsize=0.6*sqrt(ysizeps)*charscale
if (!p.multi(2) gt 1) then charsize=0.8*charsize/sqrt(!p.multi(2))
charsizewin=scalewindow*charsize*(x_ch_sizedev/y_ch_sizedev)
charsizeps=charsize*(wcharps/hcharps)
!x.charsize=1.
!y.charsize=1.
!x.margin=xmargin
!y.margin=ymargin

; correct IDL multipanel charsize halving
if ((!p.multi(1) gt 2) or (!p.multi(2) gt 2)) then begin
  !x.charsize=2. 
  !y.charsize=2.
  !x.margin=2*xmargin
  !y.margin=2*ymargin
end

; plot area size (full window and full plot area, not axis frame)
xsizewin=xsizeps*(x_ch_sizedev*charsizewin)/(wcharps*charsizeps)
ysizewin=xsizewin*(ysizeps/xsizeps)

; tick lengths
; !x.ticklen=0.02*charsize*tickscale
!x.ticklen=0.01*charsize*(xsizeps/ysizeps)*tickscale
if (!p.multi(2) ne 0) then !x.ticklen=!x.ticklen*sqrt(!p.multi(2))
; !y.ticklen=0.01*charsize*(y_ch_sizedev/x_ch_sizedev)*tickscale
!y.ticklen=0.01*charsize*tickscale  ; 0.02 used in Oslo 1999
if (!p.multi(1) ne 0) then !y.ticklen=!y.ticklen*sqrt(!p.multi(1))

; start double loop over screen and PostScript output
for deviceloop=1,2 do begin

  ; first time = output to screen
  if (deviceloop eq 1) then begin
    !p.charsize=charsizewin
    !p.charthick=1
    !p.thick=1
    !x.thick=1
    !y.thick=1
    set_plot,screentype_old
    window,0,xpos=200/scalewindow,ypos=100/scalewindow,$
      xsize=xsizewin,ysize=ysizewin,pixmap=noscreen
  endif

  ; second time = output to PostScript file
  if (deviceloop eq 2) then begin
    !p.charsize=charsizeps
    !p.charthick=thickps
    !p.thick=thickps
    !x.thick=thickps
    !y.thick=thickps
    set_plot,'ps'
    device,filename=psfilename,/portrait,xsize=xsizeps,ysize=ysizeps,$
      scale_factor=1., $   ; bugfix needed after frimage in znsp.pro
      set_font='Times',/tt_font,font_size=10, $     ; Alfred true type
      bits_per_pixel=8,$
      xoff=xoffsetps, yoff=yoffsetps   ; do NOT use /encapsulated
  endif

; endfor needed here sits in file psplot_end.idl









