1 | ;+ |
---|
2 | ; |
---|
3 | ; @file_comments |
---|
4 | ; In a string containing an order to execute with EXECUTE by example. |
---|
5 | ; We change the value of one of keywords. |
---|
6 | ; More generally, in a string, we look for the character chain: ', keywdname= ..., |
---|
7 | ; and we change the value of... |
---|
8 | ; |
---|
9 | ; @categories |
---|
10 | ; String, keywords |
---|
11 | ; |
---|
12 | ; @param STRINGIN {in}{required}{type=string} |
---|
13 | ; it is a string |
---|
14 | ; |
---|
15 | ; @param KEYWDNAME {in}{required}{type=string} |
---|
16 | ; it is a string designating the name of keyword to look for. |
---|
17 | ; |
---|
18 | ; @param KEYWDVALUE {in}{required} |
---|
19 | ; The new value of the keyword to considerate in STRINGIN |
---|
20 | ; |
---|
21 | ; @keyword SEPARATOR |
---|
22 | ; To look for the keyword, we look for the first sign = which follow |
---|
23 | ; the position of keywdname. By default, we substitute the string |
---|
24 | ; before the comma. With the keyword SEPARATOR,we can modify the cut |
---|
25 | ; of the string. SEPARATOR give a Character before the one we have to |
---|
26 | ; look for the comma which delimit the keyword in the string. |
---|
27 | ; (see examples) |
---|
28 | ; |
---|
29 | ; @keyword AFTER |
---|
30 | ; To look for the keyword, we look for the first sign = which follow |
---|
31 | ; the position of keywdname. By default, we substitute the string |
---|
32 | ; before the comma. With the keyword AFTER,we can modify the cut |
---|
33 | ; of the string. AFTER give a Character after the one we have to |
---|
34 | ; look for the comma which delimit the keyword in the string. |
---|
35 | ; (see examples) |
---|
36 | ; |
---|
37 | ; @returns |
---|
38 | ; stringout=stringin modified if keywdname has been found in stringin |
---|
39 | ; |
---|
40 | ; @uses |
---|
41 | ; common.pro |
---|
42 | ; |
---|
43 | ; @restrictions |
---|
44 | ; If keywdvalue is an array, it will be convert in a vector. |
---|
45 | ; |
---|
46 | ; @restrictions |
---|
47 | ; Beware, this function has loops, ifs ad cases everywhere. So it can |
---|
48 | ; not be used by big keywords (with a lot of elements which are big |
---|
49 | ; arrays). The input keyword must not contain Complex floatings, structure, |
---|
50 | ; Double-precision complex, Pointer, Object reference, Unsigned Integer, |
---|
51 | ; Unsigned Longword Integer, 64-bit Integer or Unsigned 64-bit Integer. |
---|
52 | ; |
---|
53 | ; |
---|
54 | ; @examples |
---|
55 | ; |
---|
56 | ; IDL> b='ok=111, year=[1997,1998,1999], age_capitaine=35' |
---|
57 | ; IDL> print, b |
---|
58 | ; ok=111, year=[1997,1998,1999], age_capitaine=35 |
---|
59 | ; IDL> print, chkeywd(b,'ok','c''est bon') |
---|
60 | ; ok='c''est bon', year=[1997,1998,1999], age_capitaine=35 |
---|
61 | ; IDL> print, chkeywd(b,'YEAR',indgen(5),sep='=') |
---|
62 | ; ok=111, year=[0,1,2,3,4], age_capitaine=35 |
---|
63 | ; IDL> print, chkeywd(b,'YEAR',indgen(5),sep=']',/after) |
---|
64 | ; ok=111, year=[0,1,2,3,4], age_capitaine=35 |
---|
65 | ; IDL> b='ok=111, /year, /age_capitaine' |
---|
66 | ; IDL> print, chkeywd(b,'year','c''est bon') |
---|
67 | ; ok=111, year='c''est bon', /age_capitaine |
---|
68 | ; |
---|
69 | ; @history |
---|
70 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
71 | ; 18/10/1999 |
---|
72 | ; 24/11/1999: adaptation for keywords starting by / |
---|
73 | ; |
---|
74 | ; @version |
---|
75 | ; $Id$ |
---|
76 | ; |
---|
77 | ;- |
---|
78 | FUNCTION chkeywd, stringin, keywdname, keywdvalue, SEPARATOR = separator, AFTER = after |
---|
79 | ; |
---|
80 | compile_opt idl2, strictarrsubs |
---|
81 | ; |
---|
82 | |
---|
83 | stringout = stringin |
---|
84 | poskeywd = strpos(strlowcase(stringout), strlowcase(keywdname)) |
---|
85 | if poskeywd EQ -1 then return, stringout |
---|
86 | while poskeywd NE -1 do BEGIN |
---|
87 | ; change a keyword starting by /toto |
---|
88 | if strmid(stringout,poskeywd-1,1) EQ '/' then BEGIN |
---|
89 | ajoute = keywdname+'='+tostr(keywdvalue) |
---|
90 | stringout = strmid(stringout, 0, poskeywd-1)+ajoute+strmid(stringout,poskeywd+strlen(keywdname) ) |
---|
91 | poskeywd = poskeywd+strlen(ajoute) |
---|
92 | poskeywd = strpos(stringout, keywdname, poskeywd) |
---|
93 | ENDIF ELSE BEGIN |
---|
94 | ; change a keyword sarting by toto= |
---|
95 | posegal = strpos(stringout, '=', poskeywd) |
---|
96 | if posegal EQ -1 then return, stringout |
---|
97 | |
---|
98 | if NOT keyword_set(separator) then separator = ',' |
---|
99 | posvirgule = strpos(stringout, separator, posegal+1) |
---|
100 | if keyword_set(after) then posvirgule = strpos(stringout, ',', posvirgule-1) $ |
---|
101 | ELSE posvirgule = rstrpos(stringout, ',', posvirgule+1) |
---|
102 | if posvirgule EQ -1 then posvirgule = strlen(stringout) |
---|
103 | ; |
---|
104 | stringout = strmid(stringout, 0, posegal+1)+tostr(keywdvalue)+strmid(stringout, posvirgule) |
---|
105 | ; |
---|
106 | poskeywd = strpos(stringout, keywdname, posvirgule+1) |
---|
107 | ENDELSE |
---|
108 | endwhile |
---|
109 | |
---|
110 | return, stringout |
---|
111 | end |
---|