;------------------------------------------------------------- ;+ ; NAME: ; REPCHR ; PURPOSE: ; Replace all occurrences of one character with another in a text string. ; CATEGORY: ; CALLING SEQUENCE: ; new = repchr(old, c1, [c2]) ; INPUTS: ; old = original text string. in ; c1 = character to replace. in ; c2 = character to replace it with. in ; default is space. ; KEYWORD PARAMETERS: ; OUTPUTS: ; new = edited string. out ; COMMON BLOCKS: ; NOTES: ; MODIFICATION HISTORY: ; R. Sterner. 28 Oct, 1986. ; Johns Hopkins Applied Physics Lab. ; RES 1 Sep, 1989 --- converted to SUN. ; R. Sterner, 27 Jan, 1993 --- dropped reference to array. ; ; Copyright (C) 1986, Johns Hopkins University/Applied Physics Laboratory ; This software may be used, copied, or redistributed as long as it is not ; sold and this copyright notice is reproduced on each copy made. This ; routine is provided as is without any express or implied warranties ; whatsoever. Other limitations apply as described in the file disclaimer.txt. ;- ;------------------------------------------------------------- FUNCTION REPCHR, OLD, C1, C2, help=hlp if (n_params(0) lt 2) or keyword_set(help) then begin print,' Replace all occurrences of one character with another '+$ 'in a text string.' print,' new = repchr(old, c1, [c2])' print,' old = original text string. in' print,' c1 = character to replace. in' print,' c2 = character to replace it with. in' print,' default is space.' print,' new = edited string. out' return, -1 endif B = BYTE(OLD) ; convert string to a byte array. CB1 = BYTE(C1) ; convert char 1 to byte. W = WHERE(B EQ CB1(0)) ; find occurrences of char 1. IF W(0) EQ -1 THEN RETURN, OLD ; if none, return old string. IF N_PARAMS(0) LT 3 THEN C2 = ' ' ; default char 2 is space. CB2 = BYTE(C2) ; convert char 2 to byte. B(W) = CB2(0) ; replace char 1 by char 2. RETURN, STRING(B) ; return new string. END ;------------------------------------------------------------- ;+ ; NAME: ; RFINDFILE ; PURPOSE: ; To restore the feature of FINDFILE (under Unix and VMS) which ; prepends the full path of the file to the filename returned. ; CATEGORY: ; Utility. ; CALLING SEQUENCE: ; x = RFINDFILE( FILE, COUNT = count, DEBUG = debug, VERBOSE = verbose) ; INPUTS: ; FILE: A file name (which may include wild cards) to be sought ; using the IDL built-in function FINDFILE. ; OPTIONAL INPUTS: ; None. ; KEYWORD PARAMETERS: ; COUNT: The number of matching files found. ; /DEBUG: Displays debugging information. ; /VERBOSE: Types the matching file name(s) to the screen. ; OUTPUTS: ; A STRING array of all matching file names found. If no matches are ; found, the returned array is ['']. ; OPTIONAL OUTPUTS: ; None. ; COMMON BLOCKS: ; None. ; SIDE EFFECTS: ; None. ; RESTRICTIONS: ; None. ; PROCEDURE: ; Straightforward. ; EXAMPLE: ; ; SEE ALSO: ; FINDFILE ; MODIFICATION HISTORY: ; Written by: D P Steele, ISR, 1993-94. ;- ;------------------------------------------------------------- FUNCTION rfindfile,path,count=count,debug=debug,verbose=verbose ; This function is a wrapper around FINDFILE for the IDL for Windows ; environment. It prepends the path to any file names found by FINDFILE, ; thereby restoring the useful feature found in FINDFILE for Unix or VMS. @isitdos IF N_ELEMENTS(path) EQ 0 THEN path='*.*' ; to avoid crashing IDL flist=FINDFILE(path,COUNT=count) IF count EQ 0 THEN RETURN,flist wholepath=(0 LE STRPOS(flist(0),dd)) AND (STRPOS(flist(0),dd) LE 2) IF NOT wholepath THEN BEGIN lastchar=STRMID(flist(0),STRLEN(flist(0))-1,1) tmp=repchr(path,dd) fndwrd,tmp,nwds,loc,len IF (lastchar EQ dd) AND (STRMID(path,STRLEN(path)-1,1) EQ '.') $ THEN lostlen=loc(nwds-2) $ ELSE lostlen=loc(nwds-1) lostroot=STRMID(path,0,lostlen) IF KEYWORD_SET(verbose) THEN PRINT,lostroot,FORMAT='("Lost root is ",A)' ENDIF ELSE lostroot='' IF KEYWORD_SET(debug) THEN STOP retval=lostroot+flist IF dos THEN retval=STRLOWCASE(retval) RETURN,retval END