Commit 6f1b4ae2f233d9c54cf4dad3bff8e9ea91f40f98
1 parent
4519580a
Exists in
master
removed redundant files from idl_misc directory
Showing
7 changed files
with
0 additions
and
474 deletions
Show diff stats
src/idl_misc/nexttok.pro deleted
... | ... | @@ -1,116 +0,0 @@ |
1 | -; | |
2 | -;+ | |
3 | -; NAME: | |
4 | -; NEXTTOK | |
5 | -; PURPOSE: | |
6 | -; Find the next occurance of any of a set of characters in a | |
7 | -; string and return the character which occurs next. | |
8 | -; CATEGORY: | |
9 | -; text/strings | |
10 | -; CALLING SEQUENCE: | |
11 | -; tok = nexttok( strn, tokens ) | |
12 | -; INPUTS: | |
13 | -; strn -- string to be searched for sub/superscripts in | |
14 | -; tokens -- string containing characters to be found. in | |
15 | -; KEYWORD PARAMETERS: | |
16 | -; POSITION -- Set to a named variable to get position out | |
17 | -; of next token, or -1 if none found. | |
18 | -; /HELP -- Print useful message and exit. | |
19 | -; OUTPUTS: | |
20 | -; tok -- Contains the character among tokens which out | |
21 | -; occurs next in strn, or null '' if none found. | |
22 | -; COMMON BLOCKS: | |
23 | -; SIDE EFFECTS: | |
24 | -; NOTES: | |
25 | -; EXAMPLE: | |
26 | -; nexttok( 'x^2 + N_j^3', '^_', position=pos ) returns '^' and sets | |
27 | -; pos to 1. | |
28 | -; MODIFICATION HISTORY: | |
29 | -; $Id: nexttok.pro,v 1.3 1996/06/14 20:00:27 mcraig Exp $ | |
30 | -; $Log: nexttok.pro,v $ | |
31 | -; Revision 1.3 1996/06/14 20:00:27 mcraig | |
32 | -; Updated Copyright info. | |
33 | -; | |
34 | -; Revision 1.2 1996/05/09 00:22:17 mcraig | |
35 | -; Generalized so that the next occurence of any of a set of characters will | |
36 | -; be returned. | |
37 | -; | |
38 | -; Revision 1.1 1996/01/31 18:41:06 mcraig | |
39 | -; Initial revision | |
40 | -; | |
41 | -; RELEASE: | |
42 | -; $Name: Rel_2_1 $ | |
43 | -; | |
44 | -; COPYRIGHT: | |
45 | -; Copyright (C) 1996 The Regents of the University of California, All | |
46 | -; Rights Reserved. Written by Matthew W. Craig. | |
47 | -; See the file COPYRIGHT for restrictions on distrubting this code. | |
48 | -; This code comes with absolutely NO warranty; see DISCLAIMER for details. | |
49 | -;- | |
50 | -FUNCTION nexttok, strn, tokens, $ | |
51 | - POSITION=position, $ | |
52 | - HELP=Help | |
53 | - | |
54 | -; Return to caller on error. | |
55 | - On_error, 2 | |
56 | - | |
57 | -; Help those in need of it. | |
58 | - IF (n_params() NE 2) OR keyword_set(Help) THEN BEGIN | |
59 | - offset = ' ' | |
60 | - print, offset+'Find the next occurance of any of a set of characters in a' | |
61 | - print, offset+'string and return the character which occurs next.' | |
62 | -; CALLING SEQUENCE: | |
63 | - print, offset+'tok = nexttok( strn, tokens )' | |
64 | -; INPUTS: | |
65 | - print, offset+'Inputs:' | |
66 | - print, offset+offset+'strn -- string to be searched for sub/superscripts in' | |
67 | - print, offset+offset+'tokens -- string containing characters to be found. in' | |
68 | -; KEYWORD PARAMETERS: | |
69 | - print, offset+'Keywords:' | |
70 | - print, offset+offset+'POSITION -- Set to a named variable to get position out' | |
71 | - print, offset+offset+' of next token, or -1 if none found.' | |
72 | - print, offset+offset+'/HELP -- Print useful message and exit.' | |
73 | -; OUTPUTS: | |
74 | - print, offset+'Outputs:' | |
75 | - print, offset+offset+'tok -- Contains the character among tokens which out' | |
76 | - print, offset+offset+" occurs next in strn, or null '' if none found." | |
77 | -; EXAMPLE: | |
78 | - print, offset+'Example:' | |
79 | - print, offset+offset+"nexttok( 'x^2 + N_j^3', '^_', position=pos ) returns '^' and sets" | |
80 | - print, offset+offset+'pos to 1.' | |
81 | - return, '' | |
82 | - ENDIF | |
83 | - | |
84 | - TmpStr = byte(strn) | |
85 | - TmpTok = byte(tokens) | |
86 | - NumToks = n_elements(TmpTok) | |
87 | - | |
88 | - MatchIdx = 0L | |
89 | - Matches = 0L | |
90 | - FOR j=0, NumToks-1 DO BEGIN | |
91 | - TmpMatch = where(TmpStr EQ TmpTok(j), TmpCnt) | |
92 | - IF (TmpCnt GT 0) THEN BEGIN | |
93 | - MatchIdx = [MatchIdx, Replicate(j, TmpCnt)] | |
94 | - Matches = [Matches, TmpMatch] | |
95 | - ENDIF | |
96 | - ENDFOR | |
97 | - | |
98 | - IF n_elements(MatchIdx) EQ 1 THEN BEGIN | |
99 | - Position = -1 | |
100 | - return, '' | |
101 | - ENDIF | |
102 | - | |
103 | - MatchIdx = MatchIdx(1:*) | |
104 | - Matches = Matches(1:*) | |
105 | - | |
106 | - SortInd = sort(Matches) | |
107 | - | |
108 | - Position = Matches(SortInd(0)) | |
109 | - | |
110 | - Tok = string(TmpTok(MatchIdx(SortInd(0)))) | |
111 | - | |
112 | - return, Tok | |
113 | -END | |
114 | - | |
115 | - | |
116 | - |
src/idl_misc/repchr.pro deleted
... | ... | @@ -1,57 +0,0 @@ |
1 | -;------------------------------------------------------------- | |
2 | -;+ | |
3 | -; NAME: | |
4 | -; REPCHR | |
5 | -; PURPOSE: | |
6 | -; Replace all occurrences of one character with another in a text string. | |
7 | -; CATEGORY: | |
8 | -; CALLING SEQUENCE: | |
9 | -; new = repchr(old, c1, [c2]) | |
10 | -; INPUTS: | |
11 | -; old = original text string. in | |
12 | -; c1 = character to replace. in | |
13 | -; c2 = character to replace it with. in | |
14 | -; default is space. | |
15 | -; KEYWORD PARAMETERS: | |
16 | -; OUTPUTS: | |
17 | -; new = edited string. out | |
18 | -; COMMON BLOCKS: | |
19 | -; NOTES: | |
20 | -; MODIFICATION HISTORY: | |
21 | -; R. Sterner. 28 Oct, 1986. | |
22 | -; Johns Hopkins Applied Physics Lab. | |
23 | -; RES 1 Sep, 1989 --- converted to SUN. | |
24 | -; R. Sterner, 27 Jan, 1993 --- dropped reference to array. | |
25 | -; | |
26 | -; Copyright (C) 1986, Johns Hopkins University/Applied Physics Laboratory | |
27 | -; This software may be used, copied, or redistributed as long as it is not | |
28 | -; sold and this copyright notice is reproduced on each copy made. This | |
29 | -; routine is provided as is without any express or implied warranties | |
30 | -; whatsoever. Other limitations apply as described in the file disclaimer.txt. | |
31 | -; Converted to IDL V5.0 W. Landsman September 1997 | |
32 | -;- | |
33 | -;------------------------------------------------------------- | |
34 | - | |
35 | - FUNCTION REPCHR, OLD, C1, C2, help=hlp | |
36 | - | |
37 | - if (n_params(0) lt 2) or keyword_set(help) then begin | |
38 | - print,' Replace all occurrences of one character with another '+$ | |
39 | - 'in a text string.' | |
40 | - print,' new = repchr(old, c1, [c2])' | |
41 | - print,' old = original text string. in' | |
42 | - print,' c1 = character to replace. in' | |
43 | - print,' c2 = character to replace it with. in' | |
44 | - print,' default is space.' | |
45 | - print,' new = edited string. out' | |
46 | - return, -1 | |
47 | - endif | |
48 | - | |
49 | - B = BYTE(OLD) ; convert string to a byte array. | |
50 | - CB1 = BYTE(C1) ; convert char 1 to byte. | |
51 | - W = WHERE(B EQ CB1[0]) ; find occurrences of char 1. | |
52 | - IF W[0] EQ -1 THEN RETURN, OLD ; if none, return old string. | |
53 | - IF N_PARAMS(0) LT 3 THEN C2 = ' ' ; default char 2 is space. | |
54 | - CB2 = BYTE(C2) ; convert char 2 to byte. | |
55 | - B[W] = CB2[0] ; replace char 1 by char 2. | |
56 | - RETURN, STRING(B) ; return new string. | |
57 | - END |
src/idl_misc/str_token.pro deleted
... | ... | @@ -1,112 +0,0 @@ |
1 | -; | |
2 | -;+ | |
3 | -; NAME: | |
4 | -; STR_TOKEN | |
5 | -; PURPOSE: | |
6 | -; Retrieve portion of string up to token. | |
7 | -; CATEGORY: | |
8 | -; text/strings | |
9 | -; CALLING SEQUENCE: | |
10 | -; new = str_token( old, token ) | |
11 | -; INPUTS: | |
12 | -; old -- String to be split. Contains text after in, out | |
13 | -; token on output. | |
14 | -; token -- Token to use in splitting old. in | |
15 | -; KEYWORD PARAMETERS: | |
16 | -; /TRIM -- set to remove leading blanks from old | |
17 | -; before returning. | |
18 | -; /HELP -- print useful message and exit. | |
19 | -; OUTPUTS: | |
20 | -; new -- portion of string up to token. out | |
21 | -; old -- portion of old after token. out, in | |
22 | -; COMMON BLOCKS: | |
23 | -; SIDE EFFECTS: | |
24 | -; Input parameter old is modified. | |
25 | -; NOTES: | |
26 | -; Token may be one or more characters. | |
27 | -; If token is not found, returns old and sets old to ''. | |
28 | -; EXAMPLE: | |
29 | -; If old is 'foo44 bar', then str_token( old, '44' ) would return | |
30 | -; 'foo', and upon return, old will be left with ' bar'. If /TRIM | |
31 | -; were set, old would be 'bar' on return. | |
32 | -; | |
33 | -; If old='xyz', then new=str_token(old,'a') would return with | |
34 | -; new='xyz' and old=''. | |
35 | -; THANKS: | |
36 | -; To D. Linder who wrote GETTOK, part of the goddard library, | |
37 | -; upon which this is based. | |
38 | -; MODIFICATION HISTORY: | |
39 | -; $Id: str_token.pro,v 1.1 2000/06/14 19:09:22 mcraig Exp $ | |
40 | -; $Log: str_token.pro,v $ | |
41 | -; Revision 1.1 2000/06/14 19:09:22 mcraig | |
42 | -; Changed name of strtok str_token to avoid conflict in IDL 5.3. | |
43 | -; | |
44 | -; Revision 1.3 1996/06/14 20:00:27 mcraig | |
45 | -; Updated Copyright info. | |
46 | -; | |
47 | -; Revision 1.2 1996/05/09 00:22:17 mcraig | |
48 | -; Added built in help. | |
49 | -; | |
50 | -; Revision 1.1 1996/01/31 18:47:37 mcraig | |
51 | -; Initial revision | |
52 | -; | |
53 | -; RELEASE: | |
54 | -; $Name: Rel_2_1 $ | |
55 | -; | |
56 | -; COPYRIGHT: | |
57 | -; Copyright (C) 1996 The Regents of the University of California, All | |
58 | -; Rights Reserved. Written by Matthew W. Craig. | |
59 | -; See the file COPYRIGHT for restrictions on distrubting this code. | |
60 | -; This code comes with absolutely NO warranty; see DISCLAIMER for details. | |
61 | -;- | |
62 | -FUNCTION Str_token, string, token, $ | |
63 | - TRIM=trim, HELP=Help | |
64 | - | |
65 | -; Back to the caller if error occurs. | |
66 | - On_error, 2 | |
67 | - | |
68 | - IF (n_params() NE 2) OR keyword_set(Help) THEN BEGIN | |
69 | - offset = ' ' | |
70 | - print, offset+'Retrieve portion of string up to token.' | |
71 | - print, offset+'new = str_token( old, token )' | |
72 | - print, offset+'Inputs:' | |
73 | - print, offset+offset+'old -- String to be split. Contains text after in, out' | |
74 | - print, offset+offset+' token on output.' | |
75 | - print, offset+offset+'token -- Token to use in splitting old. in' | |
76 | - print, offset+'Keywords:' | |
77 | - print, offset+offset+'/TRIM -- set to remove leading blanks from old ' | |
78 | - print, offset+offset+' before returning.' | |
79 | - print, offset+offset+'/HELP -- print useful message and exit.' | |
80 | - print, offset+'Outputs:' | |
81 | - print, offset+offset+'new -- portion of string up to token. out' | |
82 | - print, offset+offset+'old -- portion of old after token. out, in' | |
83 | - print, offset+'Side effects:' | |
84 | - print, offset+offset+'Input parameter old is modified.' | |
85 | - print, offset+'Notes:' | |
86 | - print, offset+offset+'Token may be one or more characters.' | |
87 | - print, offset+offset+"If token is not found, returns old and sets old to ''." | |
88 | - print, offset+'Examples:' | |
89 | - print, offset+offset+"If old is 'foo44 bar', then str_token( old, '44' ) would return'" | |
90 | - print, offset+offset+" 'foo', and upon return, old will be left with ' bar'. If /TRIM" | |
91 | - print, offset+offset+" were set, old would be 'bar' on return." | |
92 | -;' | |
93 | - print, offset+offset+"If old='xyz', then new=str_token(old,'a') would return with" | |
94 | - print, offset+offset+" new='xyz' and old=''." | |
95 | - return, -1 | |
96 | - ENDIF | |
97 | - | |
98 | - pos = strpos(string, token) | |
99 | - | |
100 | - IF (pos GE 0) THEN BEGIN | |
101 | - front = strmid(string, 0, pos) | |
102 | - string = strmid(string, pos + strlen(token), strlen(string)) | |
103 | - IF keyword_set(trim) THEN string = strtrim(string, 1) | |
104 | - return, front | |
105 | - ENDIF | |
106 | - | |
107 | - front = string | |
108 | - string = '' | |
109 | - return, front | |
110 | - | |
111 | -END | |
112 | - |
src/idl_misc/strcnt.pro deleted
... | ... | @@ -1,109 +0,0 @@ |
1 | -; | |
2 | -;+ | |
3 | -; NAME: | |
4 | -; STRCNT | |
5 | -; PURPOSE: | |
6 | -; Count number of occurrences of a substring in a string. | |
7 | -; CATEGORY: | |
8 | -; text/strings | |
9 | -; CALLING SEQUENCE: | |
10 | -; num = strcnt(strn, substring, [pos]) | |
11 | -; INPUTS: | |
12 | -; string -- The string in which to count occurences. in | |
13 | -; substring -- The substring to count occurrences of. in | |
14 | -; pos -- the position at which to begin the search. [in] | |
15 | -; If not supplied, start at beginning of | |
16 | -; string. | |
17 | -; KEYWORD PARAMETERS: | |
18 | -; /HELP -- Print useful message and return. | |
19 | -; OUTPUTS: | |
20 | -; num -- Number of occurances of substring in string. out | |
21 | -; COMMON BLOCKS: | |
22 | -; SIDE EFFECTS: | |
23 | -; NOTES: | |
24 | -; Overlapping occurances are not counted separately. For | |
25 | -; example, counting occurances of 'bb' in 'blah bbb' returns one | |
26 | -; occurance. | |
27 | -; EXAMPLE: | |
28 | -; MODIFICATION HISTORY: | |
29 | -; $Id: strcnt.pro,v 1.3 1996/06/14 20:00:27 mcraig Exp $ | |
30 | -; $Log: strcnt.pro,v $ | |
31 | -; Revision 1.3 1996/06/14 20:00:27 mcraig | |
32 | -; Updated Copyright info. | |
33 | -; | |
34 | -; Revision 1.2 1996/05/09 00:22:17 mcraig | |
35 | -; Added fast processing using BYTE arrays if we are counting occurences of | |
36 | -; a single character. Added error handling. | |
37 | -; | |
38 | -; Revision 1.1 1996/01/31 18:47:37 mcraig | |
39 | -; Initial revision | |
40 | -; | |
41 | -; RELEASE: | |
42 | -; $Name: Rel_2_1 $ | |
43 | -; | |
44 | -; COPYRIGHT: | |
45 | -; Copyright (C) 1996 The Regents of the University of California, All | |
46 | -; Rights Reserved. Written by Matthew W. Craig. | |
47 | -; See the file COPYRIGHT for restrictions on distrubting this code. | |
48 | -; This code comes with absolutely NO warranty; see DISCLAIMER for details. | |
49 | -;- | |
50 | -FUNCTION Strcnt, strn, substrn, startpos, $ | |
51 | - HELP=Help | |
52 | - | |
53 | -; Return to caller if error. | |
54 | - On_error, 2 | |
55 | - | |
56 | -; Help user, if needed. | |
57 | - IF (n_params() LT 2) OR keyword_set(Help) THEN BEGIN | |
58 | - offset = ' ' | |
59 | - print, offset+'Count number of occurrences of a substring in a string.' | |
60 | - print, offset+'num = strcnt(strn, substring, [pos])' | |
61 | - print, offset+'Inputs:' | |
62 | - print,offset+offset+'string -- The string in which to count occurences. in' | |
63 | - print,offset+offset+'substring -- The substring to count occurrences of. in' | |
64 | - print,offset+offset+'pos -- the position at which to begin the search. [in]' | |
65 | - print,offset+offset+' If not supplied, start at beginning of' | |
66 | - print,offset+offset+' string.' | |
67 | - print, offset+'Keywords:' | |
68 | - print,offset+offset+'/HELP -- Print useful message and return.' | |
69 | - print, offset+'Outputs:' | |
70 | - print,offset+offset+'num -- Number of occurances of substring in string. out' | |
71 | - return, -1 | |
72 | - ENDIF | |
73 | - | |
74 | - IF n_params() EQ 2 THEN startpos = 0 | |
75 | - | |
76 | -; return if we weren't really given a substring to search for. . . | |
77 | - IF strlen(substrn) EQ 0 THEN BEGIN | |
78 | - print, "Error: Can't count occurances of null string." | |
79 | - return, -1 | |
80 | - ENDIF | |
81 | - | |
82 | -; . . .or if we were told to start at the end of the string. | |
83 | - tmpstrn = strmid(strn, startpos, strlen(strn)) | |
84 | - IF strlen(tmpstrn) EQ 0 THEN return, 0 | |
85 | - | |
86 | -; If looking for occurences of single character, process using BYTE | |
87 | -; array. | |
88 | - IF strlen(substrn) EQ 1 THEN BEGIN | |
89 | - tmpstrn = byte(TmpStrn) | |
90 | - count = n_elements(where(TmpStrn EQ (byte(substrn))(0))) | |
91 | - ENDIF ELSE BEGIN | |
92 | - count = 0L | |
93 | - pos = rstrpos(tmpstrn, substrn) | |
94 | - WHILE pos GE 0 DO BEGIN | |
95 | - count = count + 1 | |
96 | - pos = rstrpos(tmpstrn, substrn, pos) | |
97 | - ENDWHILE | |
98 | - ENDELSE | |
99 | - | |
100 | - return, count | |
101 | -END | |
102 | - | |
103 | - | |
104 | - | |
105 | - | |
106 | - | |
107 | - | |
108 | - | |
109 | - |
src/idl_misc/strnumber.pro deleted
... | ... | @@ -1,78 +0,0 @@ |
1 | -function strnumber, st, val, hex = hexflg, NaN = nan | |
2 | -;+ | |
3 | -; NAME: | |
4 | -; STRNUMBER() | |
5 | -; PURPOSE: | |
6 | -; Function to determine if a string is a valid numeric value. | |
7 | -; | |
8 | -; EXPLANATION: | |
9 | -; A string is considered a valid numeric value if IDL can convert it | |
10 | -; to a numeric variable without error. | |
11 | -; CALLING SEQUENCE: | |
12 | -; result = strnumber( st, [val, /HEX] ) | |
13 | -; | |
14 | -; INPUTS: | |
15 | -; st - any IDL scalar string | |
16 | -; | |
17 | -; OUTPUTS: | |
18 | -; 1 is returned as the function value if the string st has a | |
19 | -; valid numeric value, otherwise, 0 is returned. | |
20 | -; | |
21 | -; OPTIONAL OUTPUT: | |
22 | -; val - (optional) value of the string. real*8 | |
23 | -; | |
24 | -; OPTIONAL INPUT KEYWORD: | |
25 | -; /HEX - If present and nonzero, the string is treated as a hexadecimal | |
26 | -; longword integer. | |
27 | -; /NAN - if set, then the value of an empty string is returned as NaN, | |
28 | -; by default the returned value is 0.0d. In either case, | |
29 | -; an empty string is considered a valid numeric value. | |
30 | -; | |
31 | -; EXAMPLES: | |
32 | -; IDL> res = strnumber('0.2d', val) | |
33 | -; returns res=1 (a valid number), and val = 0.2000d | |
34 | -; | |
35 | -; NOTES: | |
36 | -; (1) STRNUMBER was modified in August 2006 so that an empty string is | |
37 | -; considered a valid number. Earlier versions of strnumber.pro did not | |
38 | -; do this because in very early (pre-V4.0) versions of IDL | |
39 | -; this could corrupt the IDL session. | |
40 | -; | |
41 | -; (2) STRNUMBER will return a string such as '23.45uyrg' as a valid | |
42 | -; number (=23.45) since this is how IDL performs the type conversion. If | |
43 | -; you want a stricter definition of valid number then use the VALID_NUM | |
44 | -; function. | |
45 | -; HISTORY: | |
46 | -; version 1 By D. Lindler Aug. 1987 | |
47 | -; test for empty string, W. Landsman February, 1993 | |
48 | -; Converted to IDL V5.0 W. Landsman September 1997 | |
49 | -; Hex keyword added. MRG, RITSS, 15 March 2000. | |
50 | -; An empty string is a valid number W. Landsman August 2006 | |
51 | -; Added /NAN keyword W. Landsman August 2006 | |
52 | -;- | |
53 | - if N_params() EQ 0 then begin | |
54 | - print,'Syntax - result = strnumber( st, [val, /HEX, /NAN] )' | |
55 | - return, 0 | |
56 | - endif | |
57 | - | |
58 | - newstr = strtrim( st ) | |
59 | - if keyword_set(NAN) then if newstr EQ '' then begin | |
60 | - val = !VALUES.D_NAN | |
61 | - return, 1 | |
62 | - endif | |
63 | - | |
64 | - On_IOerror, L1 ;Go to L1 if conversion error occurs | |
65 | - | |
66 | - If (NOT keyword_set(hexflg)) Then Begin | |
67 | - val = double( newstr ) | |
68 | - EndIf Else Begin | |
69 | - val = 0L | |
70 | - reads, newstr, val, Format="(Z)" | |
71 | - EndElse | |
72 | - | |
73 | - return, 1 ;No conversion error | |
74 | - | |
75 | - L1: return, 0 ;Conversion error occured | |
76 | - | |
77 | - end | |
78 | - |
src/idl_misc/strtrans.pro deleted
... | ... | @@ -1 +0,0 @@ |
1 | -; ;+ ; NAME: ; STRTRANS ; PURPOSE: ; Translate all occurences of one substring to another. ; CATEGORY: ; text/strings ; CALLING SEQUENCE: ; new = strtrans(oldstr,from,to,ned) ; INPUTS: ; oldstr -- string on which to operate. in ; May be an array. ; from -- substrings to be translated. May be in ; an array. ; to -- what strings in from should be in ; translated to. May be an array. ; KEYWORD PARAMETERS: ; /HELP -- Set this to print useful message and ; exit. ; OUTPUTS: ; new -- Translated string. Array if oldstr is out ; an array. ; ned -- number of substitutions performed in out ; oldstr. Array if oldstr is an array. ; COMMON BLOCKS: ; SIDE EFFECTS: ; NOTES: ; - Any of old, from, and to can be arrays. ; - from and to must have the same number of elements. ; EXAMPLE: ; inp='Many*bad!chars+in_here' ; from=['*','!','+','_'] ; to =[' ',' ',' ',' '] ; out = strtrans(inp,from,to,ned) ; Will produce out='Many bad chars in here', and set ned to 4. ; MODIFICATION HISTORY: ; $Id: strtrans.pro,v 1.4 2001/11/21 19:13:23 mcraig Exp $ ; $Log: strtrans.pro,v $ ; Revision 1.4 2001/11/21 19:13:23 mcraig ; Changed str_sep to strsplit. The former is now considered obsolete by RSI. ; ; Revision 1.3 1996/06/14 20:00:27 mcraig ; Updated Copyright info. ; ; Revision 1.2 1996/05/09 00:22:17 mcraig ; Sped up significantly by using str_sep to handle the translation. No longer ; relies on routines fromother user libraries. ; ; Revision 1.1 1996/01/31 18:47:37 mcraig ; Initial revision ; ; RELEASE: ; $Name: Rel_2_1 $ ; ; COPYRIGHT: ; Copyright (C) 1996 The Regents of the University of California, All ; Rights Reserved. Written by Matthew W. Craig. ; See the file COPYRIGHT for restrictions on distrubting this code. ; This code comes with absolutely NO warranty; see DISCLAIMER for details. ;- ; FUNCTION strtrans, InputString, from, to, ned, $ HELP=Help ; Bomb out to caller if error. On_error, 2 ; Offer help if we don't have at least InputString, from, and to, or ; if the user asks for it. IF (n_params() LT 3) OR keyword_set(help) THEN BEGIN offset = ' ' print, offset+'Translate all occurences of one substring to another.' print, offset+'new = strtrans(oldstr,from,to,ned)' print, offset+'Inputs:' print, offset+offset+'oldstr -- string on which to operate. in' print, offset+offset+' May be an array.' print, offset+offset+'from -- substrings to be translated. May be in' print, offset+offset+' an array.' print, offset+offset+'to -- what strings in from should be in' print, offset+offset+' translated to. May be an array.' print, offset+'Outputs:' print, offset+offset+'new -- Translated string. Array if oldstr is out' print, offset+offset+' an array.' print, offset+offset+'ned -- number of substitutions performed in out' print, offset+offset+' oldstr. Array if oldstr is an array.' print, offset+'Notes:' print, offset+offset+'- Any of old, from, and to can be arrays. ' print, offset+offset+'- from and to must have the same number of elements.' return, -1 ENDIF strn = InputString ; Check that From/To have same number of elements. RETURN if they don't. NFrom = n_elements(from) NTo = n_elements(to) IF (NFrom EQ 0) OR (NTo EQ 0) THEN return, strn IF NFrom NE NTo THEN BEGIN print,'Error: Number of elements in from/to unequal' return,-1 ENDIF ; Make sure there are no null strings in From. RETURN if there are. FromLen = strlen(From) IF (total(FromLen EQ 0) GT 0) THEN BEGIN print, 'Error: elements of From must have nonzero length.' return, -1 ENDIF NStrings = n_elements(strn) ned = lonarr(NStrings) tmpned = 0L ; Say strn='a#b#c', from='#' and to='@'. Then the approach here is to ; first split strn at all occurances of '#', then recombine the pieces ; with '@' inserted instead. Do this for all elements of strn, and ; all elements of from. FOR i = 0L, NStrings-1 DO BEGIN ned(i) = 0L st=strn(i) FOR j=0L, NFrom-1 DO BEGIN strn(i)=textoidl_str_replace(strn(i),from(j),to(j)) ;jpb patch using JD's routine ; SepStr = strsplit(strn(i), from(j)) ;jpb patch ; pos=strposmulti(strn(i),from(j),count) ; SepStr = strsplit(strn(i), from(j),/extract) ;jpb patch ; NSubs = n_elements(SepStr) - 1 ; IF count NE 0 THEN BEGIN ; stop ; SepStr = strsplit(strn(i), from(j),/extract) ; NSubs = n_elements(SepStr) - 1 ; strn(i) = SepStr(0) ; FOR k=1L, NSubs DO strn(i) = strn(i) + To(j) + SepStr(k) ; ned(i) = ned(i) + NSubs ; ENDIF ENDFOR ENDFOR return, strn END | |
2 | 0 | \ No newline at end of file |
src/idl_misc/textoidl_str_replace.pro deleted
... | ... | @@ -1 +0,0 @@ |
1 | -FUNCTION TEXTOIDL_STR_REPLACE, str, outstring, instring ;+ ; NAME: ; STR_REPLACE ; PURPOSE: ; replace a substring by another in an input string ; CALLING SEQUENCE: ; result = STR_REPLACE(str, outstring, instring) ; INPUT: ; str : input string ; outstring : substring to be searched for and replaced ; instring : substring to be put in str in replacement of outstring ; OUTPUT: ; input string with outstring replaced by instring ; KEYWORDS: ; none ; EXAMPLES: ; IDL> str = 'tralala tsoin tsoin' ; IDL> PRINT, STR_REPLACE(str, 'tsoin', 'ploum') ; (IDL prints 'tralala ploum ploum') ; ALGORITHM: ; simple string manipulation ; SIDE EFFECTS: ; none ; RESTRICTIONS: ; Report any bugs to Jacques Delabrouille ; j.delabrouille@cdf.in2p3.fr ; PROCEDURES CALLED: ; none ; REVISION HISTORY ; Written, Jacques Delabrouille June 2000 ; Bug (infinite loop) when instring contains outstring fixed, JD, May 2001 ;- IF ( N_PARAMS() EQ 0 ) THEN BEGIN print,' CALL IS : result = STR_REPLACE(str, outstring, instring)' ; print,' Keywords :' GOTO, closing ENDIF search = 1 begin_string = '' endstring = str WHILE search EQ 1 DO BEGIN whout = STRPOS(endstring,outstring) IF whout EQ -1 THEN BEGIN RETURN, begin_string+endstring GOTO, closing ENDIF ELSE BEGIN begin_string = begin_string + STRMID(endstring,0,whout) + instring endstring = STRMID(endstring,whout+STRLEN(outstring)) ENDELSE ENDWHILE RETURN, newstr closing: END | |
2 | 0 | \ No newline at end of file |