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

Last change on this file since 163 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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