;+
; NAME:
;	fname_extract
; PURPOSE:
;	From a file name string containing the full directory
;	referance, extract only the filename.
; CALLING SEQUENCE:
;	fname_extract, file_in, file_extract
; INPUTS:
;	file_in: The input filename that may contain the directory
;	         referance
;
; KEYWORDS:
;       remove_extension: remove also extension from filename
; OUTPUTS:
;       Returns the filename withouth directory referance
; PROCEDURE:
;	checks if filename contains directory separator character.
;       If thats the case, strip off all characters until the last
;       occurence of directory separator in "file_in"
;
; RESTRICTIONS:
;       A real filename without it's directory referance should not
;       contain directory separator characters. In that case, this
;       function will assume a part of the filename is a directory
;       and strip it off. 
;
; MODIFICATION HISTORY:
;       Written by Oivind Wikstol, June-24-2004
;
function fname_extract, file_in, remove_extension = remove_extension

  home = getenv('HOME')
  dirsep = get_delim()

  ; search file_in for any contents of dirsep
;  dir = strmatch(file_in, '*'+dirsep+'*')

;  if dir then begin
    file_split = strsplit(file_in, dirsep, /extract)
    nstr = n_elements(file_split)
    file_out = file_split[nstr-1]
;  endif

  if keyword_set(remove_extension) then begin
    file_split = strsplit(file_out, '.', /extract)
    file_out = file_split[0]
  endif

  return, file_out
end
    
