pro write_ps,filename,image,landscape=landscape,xcm=xcm,ycm=ycm,gct=gct,lct=lct

scr = !d.name

IF N_ELEMENTS (image) EQ 0 THEN RETURN
IF N_ELEMENTS (filename) EQ 0 THEN filename = "lasco.ps"
IF N_ELEMENTS ( def_ps ) EQ 0 THEN def_ps = [ 0,0,1,8,20,20,3.5,7.5]

IF KEYWORD_SET(landscape) THEN def_ps(0) = 1
IF KEYWORD_SET(xcm) THEN def_ps(4) = xcm
IF KEYWORD_SET(ycm) THEN def_ps(5) = ycm

;def_ps = [ 0.0  ; portrait (pl), $
;           0.0  ; non-encapsulated (ec), $
;           1.0  ; color on (co), $
;           8.0  ; bits_per_pixel (bpp), $
;          15.0  ; xcm , $
;          15.0  ; ycm, $
;           3.5  ; x offset, $
;           7.5  ; y offset ]

sz = size(image)

xcm = def_ps(4)
ycm = def_ps(5)

ycm = FLOAT(sz(2))/FLOAT(sz(1)) * xcm
def_ps(5) = ycm

print,xcm,ycm

xoff = def_ps(6)
yoff = def_ps(7)

IF N_ELEMENTS(a4) EQ 0 THEN a4 = { x:21.0, y:29.7 }
set_plot,'PS',/INTERPOLATE

IF def_ps(0) EQ 0 THEN BEGIN	; portrait
    DEVICE,/PORTRAIT
    xoff = a4.x/2.0 - xcm/2.0 + 1.0
    yoff = a4.y/2.0 - ycm/2.0
ENDIF ELSE BEGIN		; landscape
    DEVICE,/LANDSCAPE
    xoff = a4.x/2.0 - ycm/2.0 
    yoff = a4.y - ( a4.y/2.0 - xcm/2.0 ) 
ENDELSE

DEVICE,BITS_PER_PIXEL=def_ps(3)

DEVICE,/COLOR
loadct,lct
IF def_ps(2) EQ 0 THEN loadct,0 
IF KEYWORD_SET(gct) THEN gamma_ct,gct
  
        
IF def_ps(1) EQ 1 THEN DEVICE,/ENCAPSULATED 

DEVICE, BITS_PER_PIXEL = def_ps(3)
DEVICE, XSIZE = xcm, YSIZE = ycm
DEVICE, XOFFSET = xoff, YOFFSET = yoff
DEVICE,FILENAME=filename

TVSCL,image

DEVICE,/CLOSE

set_plot,scr

return
end
