;+ ; NAME: ; GetFileSpec ; PURPOSE: ; Retrieve file name information from the common block ; set by SetFileSpec. ; CATEGORY: ; I/O, string manipulation ; CALLING SEQUENCE: FUNCTION GetFileSpec, setfile, $ from = From , $ upto = Upto , $ part = Part , $ strict = strict, $ asfilename = AsFileName ; INPUTS: ; setfile ; array; type: string ; array of file names is fed into SetFileSpec before anything ; else is done. If not specified then the information set up by ; a previous call to SetFileSpec is used. ; From, UpTo, Part ; scalar; type: string ; Any of the following six strings can be used: ; 'NODE','DEVICE','DIRECTORY','NAME','TYPE','VERSION' ; (a prefix 'FILE' is permitted, as in 'FILENAME') ; The input is case-insensitive ; Only a unique starting substrings has to be specified ; If From is not specified, From='NODE' is assumed ; If UpTo is not specified, From='VERSION' is assumed ; OPTIONAL INPUT PARAMETERS: ; /AsFileName if UpTo = 'Directory' and AsFileName is set than the ; directory names are returned as file names, i.e. ; in vms a *.DIR name is returned; in Win32 and Unix ; the trailing (back)slash is removed. MacOS is not ; implemented. ; OUTPUTS: ; Result string array ; The array structure is determined by the input to the ; SetFileSpec call that set up the internal data. ; Includes all FileParts in between and including the ; From and UpTo strings ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; SetFileSpec, IsType, InitVar, os_separator, strposn, SyncDims ; EXAMPLE: ; SetFileSpec, 'ud1:[test]file.txt' Establishes internal data ; print, GetFileSpec() Prints: ud1:[test]file.txt ; print, GetFileSpec(upto='dir') Prints: ud1:[test] ; print, GetFileSpec(from='name') Prints: file.txt ; print, GetFileSpect(from='dev',upto='dev') Prints: ud1: ; INCLUDE: @filespec_common.pro ; Common block with arrays File and Parts ; SIDE EFFECTS: ; > Input is converted to uppercase ; RESTRICTIONS: ; > Internal data must have been set up by SetFileSpec ; PROCEDURE: ; Extracts data from common block set by SetFileSpec ; MODIFICATION HISTORY: ; DEC-1997, Paul Hick ; JAN-2001, Paul Hick (UCSD/CASS) ; Added part keyword ; OCT-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Added setfile keyword ;- IF IsType(setfile, /defined) THEN SetFileSpec, setfile, strict=strict IF IsType(File, /undefined) THEN message, 'SetFileSpec must be called before GetFileSpec' InitVar, AsFileName, /key IF IsType(Part, /defined) THEN BEGIN From = Part Upto = Part ENDIF InitVar, From, 'NODE' From = strupcase(From) iFrom = strposn(From,'FILE',tmp, From, /trailing) iFrom = (where( From EQ strmid(Parts,0,strlen(From)) ))[0] InitVar, Upto, 'VERSION' UpTo = strupcase(UpTo) iUpTo = strposn(Upto,'FILE',tmp, Upto, /trailing) iUpto = (where( Upto EQ strmid(Parts,0,strlen(UpTo)) ))[0] Result = '' ; Initialize (Just in case iUpTo < iFrom) IF iUpTo NE 2 OR NOT AsFileName THEN $ FOR i=iFrom,iUpTo DO Result += File[i,*] $ ELSE BEGIN ; Strip off trailing delimiter i = strposn(File[2,*], os_separator(/dir), DirStr, Back, /last, /front) CASE !version.os OF 'vms' : BEGIN i = strposn(DirStr, '[', Front, DirStr, /trail) ; Strip leading '[' i = strposn(DirStr, '.', Dirstr, Back, /last) ; Locate '.' p = where( strlen(Front) NE 0 AND i EQ -1) ; Where no '.' present IF p[0] NE -1 THEN Front[p] += '000000' p = where( strlen(Front) NE 0 ) IF p[0] NE -1 THEN DirStr[p] = Front[p]+DirStr[p]+']'+Back+'.DIR' END ELSE: ENDCASE FOR i=iFrom,iUpTo-1 DO Result += File[i,*] Result += DirStr ENDELSE SyncDims, Result, size=FileSize RETURN, Result & END