source: trunk/SRC/ToBeReviewed/STRING/chkeywd.pro @ 238

Last change on this file since 238 was 238, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
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;
79FUNCTION chkeywd, stringin, keywdname, keywdvalue, SEPARATOR = separator, AFTER = after
80;
81  compile_opt idl2, strictarrsubs
82;
83
84   stringout = stringin
85   poskeywd = strpos(strlowcase(stringout), strlowcase(keywdname))
86   if poskeywd EQ -1 then return, stringout
87   while poskeywd NE -1 do BEGIN
88; change a keyword starting by /toto
89      if strmid(stringout,poskeywd-1,1) EQ '/' then BEGIN
90         ajoute = keywdname+'='+tostr(keywdvalue)
91         stringout = strmid(stringout, 0, poskeywd-1)+ajoute+strmid(stringout,poskeywd+strlen(keywdname) )
92         poskeywd = poskeywd+strlen(ajoute)
93         poskeywd = strpos(stringout, keywdname, poskeywd)
94      ENDIF ELSE BEGIN
95; change a keyword sarting by toto=
96         posegal = strpos(stringout, '=', poskeywd)
97         if posegal EQ -1 then return, stringout
98
99         if NOT keyword_set(separator) then separator = ','
100         posvirgule = strpos(stringout, separator, posegal+1)
101         if keyword_set(after) then posvirgule = strpos(stringout, ',', posvirgule-1) $
102         ELSE posvirgule = rstrpos(stringout, ',', posvirgule+1)
103         if posvirgule EQ -1 then posvirgule = strlen(stringout)
104;
105         stringout = strmid(stringout, 0, posegal+1)+tostr(keywdvalue)+strmid(stringout, posvirgule)
106;
107         poskeywd = strpos(stringout, keywdname, posvirgule+1)
108      ENDELSE
109   endwhile
110
111   return,  stringout
112end
Note: See TracBrowser for help on using the repository browser.