Viewing contents of file '../idllib/contrib/mallozzi/break_file.pro'
pro break_file, file, disk_log, dir, filnam, ext, fversion, node
;
;+
;NAME:
; break_file
;PURPOSE:
; Given a file name, break the filename into the parts
; of disk/logical, the directory, the filename, the
; extension, and the file version (for VMS)
;INPUT:
; file - The file name
;OUTPUT:
; disk_log- The disk or logical (looks for a ":")
; This is generally only valid on VMS machines
; dir - The directory
; filnam - The filename (excluding the ".")
; ext - The filename extension (including the ".")
; fversion- The file version (only VMS)
; node - The Node name (only VMS)
;RESTRICTIONS:
; VMS:
; Assumes that : always precedes []
; ULTRIX:
; Right now it has trouble with the ultrix option of use
; of "." or ".."
;HISTORY:
; Written 1988 by M.Morrison
; Aug-91 (MDM) Changed to handle Unix filename convensions
; 28-Feb-92 (MDM) * Adjusted to handle arrays
; 11-Mar-92 (MDM) - Perform a STRTRIM(x,2) on input string before
; doing the "break-up"
; 1-Dec-92 (MDM) - Moved code to do filename, extension and version
; number for both VMS and Unix (previously it
; did not do version number code for Unix)
; 29-Jan-93 (DMZ/MDM) - checked for node in file name
; 11-Nov-83 (DMZ) - checked for ".][" and "[000000" in VMS concealed directory names
; 5-Apr-95 (RSM) - didn't work for Windows. Easiest fix was to put old
; code in an IF block, and then add the Windows code:
; IF (!VERSION.OS NE 'WINDOWS') THEN BEGIN
; ...old code...
; ENDIF ELSE BEGIN
; ...new Windows code...
; ENDELSE
; 12-Jul-96 (RSM) - Good old IDL changed the !VERSION.OS string for
; Window95 to 'Win32'. Added this to the IF block
;-
IF ((STRUPCASE(!VERSION.OS) NE 'WINDOWS') AND $
(STRUPCASE(!VERSION.OS) NE 'WIN32')) THEN BEGIN
qvms = 1
;dummy is where filename has /
dummy = where(strpos(file, '/') ne -1, count)
;if there is a /, then count ne 0, and therefore
; it is not VMS (lots of negatives there)
if (count ne 0) then qvms = 0
n = n_elements(file)
node = strarr(n)
disk_log = strarr(n)
dir = strarr(n)
filnam = strarr(n)
ext = strarr(n)
fversion = strarr(n)
for ifil=0,n-1 do begin
file0 = file(ifil)
file0 = strtrim(file0, 2) ;MDM added 11-Mar-92
len=strlen(file0)
;-- node name present ;DMZ added Jan'93
; (if so then strip it off now and then add it back later)
dcolon=strpos(file0,'::')
if dcolon gt -1 then begin
node(ifil)=strmid(file0,0,dcolon+2)
file0=strmid(file0,dcolon+2,1000)
endif
if (qvms) then begin
p=strpos(file0,':')
if (p ne 1) then disk_log(ifil)=strmid(file0,0,p+1) ;includes :
len=len-p+1
file0=strmid(file0, p+1, len)
;-- check for .][ in dir ;-- DMZ added Nov'93
if strpos(file0,'.][') ne -1 then file0=str_replace(file0,'.][','.')
p=strpos(file0,']')
if (p ne -1) then dir(ifil)=strmid(file0,0,p+1) ;includes ]
;-- check for .000000 in dir ;-- DMZ added Nov'93
temp=dir(ifil)
if strpos(temp,'.000000') ne -1 then dir(ifil)=str_replace(temp,'.000000','')
len=len-p+1
file0=strmid(file0, p+1, len)
end else begin
p = 0
while (strpos(file0,'/', p+1) ne -1) do p = strpos(file0,'/',p+1) ;find last /
dir(ifil) = strmid(file0, 0, p+1)
file0 = strmid(file0, p+1, len-(p+1))
end
p=strpos(file0,'.')
if (p eq -1) then begin
filnam(ifil) = strmid(file0,0,len)
p=len
end else filnam(ifil) = strmid(file0,0,p) ;not include .
len=len-p
file0=strmid(file0, p, len)
p=strpos(file0,';')
if (p eq -1) then begin
ext(ifil) = strmid(file0,0,len)
p=len
;includes . but not ;
end else ext(ifil) = strmid(file0,0,p)
len=len-p
file0=strmid(file0, p, len)
fversion(ifil) = ''
if (len ne 0) then fversion(ifil) = file0
;-- now prefix disk name with node name
if node(ifil) ne '' then disk_log(ifil)=node(ifil)+disk_log(ifil)
end
if (n eq 1) then begin ;turn output into scalars
disk_log = disk_log(0)
dir = dir(0)
filnam = filnam(0)
ext = ext(0)
fversion = fversion(0)
node = node(0)
end
ENDIF ELSE BEGIN
n = n_elements(file)
node = strarr(n)
disk_log = strarr(n)
dir = strarr(n)
filnam = strarr(n)
ext = strarr(n)
fversion = strarr(n)
for ifil=0,n-1 do begin
file0 = file(ifil)
file0 = STRTRIM(file0, 2) ;MDM added 11-Mar-92
len = STRLEN(file0)
COLON = STRPOS(FILE0, ':')
IF (COLON NE -1) THEN BEGIN
DISK_LOG(IFIL) = STRMID(FILE0, 0, COLON + 1)
ENDIF ELSE BEGIN
COLON = 0
DISK_LOG(IFIL) = ''
ENDELSE
DIR_COUNTER = -1
FOR J=LEN-1, 0, -1 DO BEGIN
TEMP_CHAR = STRMID(FILE0, J, 1)
IF (TEMP_CHAR EQ '\') THEN BEGIN
DIR_COUNTER = J
GOTO, FOUND_DIR
ENDIF
ENDFOR
FOUND_DIR:
IF (COLON EQ 0) THEN BEGIN
DIR(IFIL) = STRMID(FILE0, COLON, DIR_COUNTER + 1)
FILNAM(IFIL) = STRMID(FILE0, DIR_COUNTER + 1, 999)
ENDIF ELSE BEGIN
DIR(IFIL) = STRMID(FILE0, COLON + 1, DIR_COUNTER - 1)
FILNAM(IFIL) = STRMID(FILE0, DIR_COUNTER + 1, 999)
ENDELSE
DOT = STRPOS(FILNAM(IFIL), '.')
IF (DOT NE -1) THEN BEGIN
EXT(IFIL) = STRMID(FILNAM(IFIL), DOT, 999)
FILNAM(IFIL) = STRMID(FILNAM(IFIL), 0, DOT)
ENDIF ELSE BEGIN
EXT(IFIL) = ''
ENDELSE
endfor
if (n eq 1) then begin ;turn output into scalars
disk_log = disk_log(0)
dir = dir(0)
filnam = filnam(0)
ext = ext(0)
fversion = fversion(0)
node = node(0)
end
ENDELSE ; Windows
end