	function shortfilename, files, names=names, all = all, extensions = extensions, short_names = short_names

;+
;
; NAME:
;	SHORTFILENAME
;
; PURPOSE:
;
;	Function SHORTFILENAME returns the string-type
;	array containing extracted file name from the
;	input full path name; file name without extension;
;	extension and lengthes of all of these values
;	correspondingly. All the output values are of lower
;	case.
;
;	EXAMPLE:
;		If INPUT is file C:\DATA\TEST1.DAT:
;			A=SHORTFILENAME(INPUT)
;			PRINT,A
;	IDL prints: test1.dat  test1  dat
;
;		To extract, e.g., the extension only, you
;	can print such a statement:
;		PRINT,SHORTFILENAME(INPUT, /ext)
;	IDL prints: dat
;
;
; CATEGORY:
;	File reading
;
; CALLING SEQUENCE:
;	SNAME = SHORTFILENAME(file)
;
; INPUTS:
;	File name - scalar string. This array may be of ASCII code.
;
; OPTIONAL INPUT PARAMETERS:
;	None
;
; KEYWORD PARAMETERS:
;	ALL - output of file name from the
;	input full path name; file name without extension;
;	extension and lengthes of all of these values
;	correspondingly
;
;   NAME - extracted full file name from the
;	input full path name
;
;   EXTENSIONS - output of extension
;
;   SHORT_NAME - output of file name without extension
;
; OUTPUTS:
;	String array
;
; COMMON BLOCKS:
;	None.
;
; SIDE EFFECTS:
;	None.
;
; RESTRICTIONS:
;	None.
; PROCEDURE:
;	Straightforward.
;-

	CASE strlowcase(!version.os_family) OF

'windows': 	Delim='\'
'unix':	 	Delim='/'

	ELSE: 	begin
		message, 'Not supported on this platform.'
			end
	ENDCASE

len = strlen(files)

N = n_elements(files)

dot_pos = rstrpos(files, '.')
slash_pos = rstrpos(files, Delim)

if keyword_set(all) then filenames = strarr(N, 3) else filenames = strarr(N)


	CASE 1 OF

keyword_set(names): for j=0, N-1 do filenames[j] = strmid(files[j], slash_pos[j]+1, len[j]-slash_pos[j])

keyword_set(extensions):  for j=0, N-1 do filenames[j] = strmid(files[j], dot_pos[j]+1, len[j]-dot_pos[j])

keyword_set(short_names): for j=0, N-1 do filenames[j] = strmid(files[j], slash_pos[j]+1, dot_pos[j]-slash_pos[j]-1)

keyword_set(all): for j=0, N-1 do filenames[j, *] = $
	[strmid(files[j], slash_pos[j]+1, len[j]-slash_pos[j]), $
		strmid(files[j], slash_pos[j]+1, dot_pos[j]-slash_pos[j]-1), $
			strmid(files[j], dot_pos[j]+1, len[j]-dot_pos[j])]


	ELSE: for j=0, N-1 do filenames[j] = strmid(files[j], slash_pos[j]+1, len[j]-slash_pos[j])

	ENDCASE

if n_elements(filenames) eq 1 then filenames = filenames[0]

return, filenames

	end
