;PURPOSE  Extract an arbitrary linear cross-section from a 2-d image
;	  (=a "line"), defined from the display by clicking the mouse.
;	  Uses function 'expix.pro' to define endpoints.
;CALLING SEQUENCE line=exln(img)
;INPUT  img: the 2-d image to extract a 1-d cross-section from
;OUTPUT line: array containing the extracted 1-d cross-section
;---> Will always store 'line' in ascending order of extracted indices,
;     regardless of the sequence in which the endpoints have been defined!

function exln,img
;Get & define needed values
  dim=size(img)
  x=intarr(3) & y=intarr(3)
  x=intarr(3) & y=intarr(3)
;Get & display the beginning and endpoint of line to extract
  line=expix(img,2) & x(0)=line MOD dim(1) & y(0)=line/dim(1)
;Distinguish two cases depending on the slope of line to get best results
  if (abs(y(1)-y(0)) ge abs(x(1)-x(0))) then begin
    x(2)=max(x(0:1)) & y(2)=min(y(0:1))
    if (x(2) eq x(0)) then x(2)=x(0)+10
    line=polyfillv(x,y,dim(1),dim(2),1)
    line=img(line(lindgen(n_elements(line)/2)*2+1))
  endif else begin
    x(2)=min(x(0:1)) & y(2)=max(y(0:1))
    if (y(2) eq y(0)) then y(2)=y(0)+10
    line=polyfillv(y,x,dim(2),dim(1),1)
    line=(transpose(img))(line(lindgen(n_elements(line)/2)*2+1))
  endelse
  print,'Length='+strtrim(string(n_elements(line)),2)
return,line
end