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

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