Viewing contents of file '../idllib/contrib/tappin/graffer/gr_fra2norm.pro'
pro Gr_fra2norm, xf, yf, xn, yn, invert=invert

;+
; GR_FRA2NORM
;	Convert "Frame" coordinates to normalized coordinates
;
; Usage:
;	gr_fra2norm, xf, yf, xn, yn
;
; Arguments:
;	xf, yf	float	input	X & Y coordinates in "Frame" system
;	xn, yn	float	output	X & Y coordinates in normalized
;				system.
;
; Keyword:
;	invert	??	input	If set, then take normalized
;				coordinates and return frame coords
;
; History:
;	Original: 30/1/97; SJT
;-

if (!X.type) then xc = 10^!X.crange $
else xc = !X.crange
if (!Y.type) then yc = 10^!Y.crange $
else yc = !Y.crange

fcorn = convert_coord(/data, /to_norm, xc, yc)
rx = fcorn(0, 1)-fcorn(0, 0)
ry = fcorn(1, 1)-fcorn(1, 0)

if (keyword_set(invert)) then begin
    xn = (xf - fcorn(0, 0))/rx
    yn = (yf - fcorn(1, 0))/ry
endif else begin
    xn = xf*rx + fcorn(0, 0)
    yn = yf*ry + fcorn(1, 0)
endelse

end