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
RevLine 
[2]1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
[142]6; @file_comments
[163]7; In a string containing an order to execute with EXECUTE by example.
[142]8; We change the value of one of keywords.
[163]9; More generally, in a string, we look for the character chain: ', keywdname= ...,
[142]10; and we change the value of...
[2]11;
[142]12; @categories
[157]13; String, keywords
[2]14;
15;
[163]16; @param STRINGIN {in}{required}{type=string}
[142]17; it is a string
[2]18;
[163]19; @param KEYWDNAME {in}{required}{type=string}
[142]20; it is a string designating the name of keyword to look for.
[2]21;
[142]22; @param KEYWDVALUE {in}{required}
23; The new value of the keyword to considerate in STRINGIN
[2]24;
[142]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
[163]29; of the string. SEPARATOR give a Character before the one we have to
[142]30; look for the comma which delimit the keyword in the string.
31; (see examples)
[2]32;
[142]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
[163]37; of the string. AFTER give a Character after the one we have to
[142]38; look for the comma which delimit the keyword in the string.
39; (see examples)
[2]40;
[142]41; @returns
42; stringout=stringin modified if keywdname has been found in stringin
[2]43;
[142]44; @uses
45; common.pro
[2]46;
[142]47; @restrictions
48; If keywdvalue is an array, it will be convert in a vector.
[2]49;
[142]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;
[2]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;
[142]73; @history
[157]74; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[2]75;                      18/10/1999
[142]76;                      24/11/1999: adaptation for keywords starting by /
77;
78; @version
79; $Id$
80;
[2]81;-
82;------------------------------------------------------------
83;------------------------------------------------------------
84;------------------------------------------------------------
85FUNCTION chkeywd, stringin, keywdname, keywdvalue, SEPARATOR = separator, AFTER = after
[114]86;
87  compile_opt idl2, strictarrsubs
88;
[2]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
[142]94; change a keyword starting by /toto
[2]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
[142]101; change a keyword sarting by toto=
[2]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.