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

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.9 KB
RevLine 
[2]1;+
2;
[142]3; @file_comments
[238]4; In a string containing an order to execute with EXECUTE by example.
[142]5; We change the value of one of keywords.
[163]6; More generally, in a string, we look for the character chain: ', keywdname= ...,
[142]7; and we change the value of...
[2]8;
[142]9; @categories
[157]10; String, keywords
[2]11;
[163]12; @param STRINGIN {in}{required}{type=string}
[142]13; it is a string
[2]14;
[163]15; @param KEYWDNAME {in}{required}{type=string}
[142]16; it is a string designating the name of keyword to look for.
[2]17;
[238]18; @param KEYWDVALUE {in}{required}
[142]19; The new value of the keyword to considerate in STRINGIN
[2]20;
[142]21; @keyword SEPARATOR
[238]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
[142]26; look for the comma which delimit the keyword in the string.
27; (see examples)
[2]28;
[142]29; @keyword AFTER
[238]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
[142]34; look for the comma which delimit the keyword in the string.
35; (see examples)
[2]36;
[238]37; @returns
[142]38; stringout=stringin modified if keywdname has been found in stringin
[2]39;
[238]40; @uses
[142]41; common.pro
[2]42;
[142]43; @restrictions
44; If keywdvalue is an array, it will be convert in a vector.
[2]45;
[142]46; @restrictions
[238]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,
[142]51; Unsigned Longword Integer, 64-bit Integer or Unsigned 64-bit Integer.
52;
[238]53;
[142]54; @examples
55;
[2]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;
[142]69; @history
[157]70; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[2]71;                      18/10/1999
[142]72;                      24/11/1999: adaptation for keywords starting by /
[238]73;
[142]74; @version
75; $Id$
76;
[2]77;-
78FUNCTION chkeywd, stringin, keywdname, keywdvalue, SEPARATOR = separator, AFTER = after
[114]79;
80  compile_opt idl2, strictarrsubs
81;
[2]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
[142]87; change a keyword starting by /toto
[2]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)
[238]93      ENDIF ELSE BEGIN
[142]94; change a keyword sarting by toto=
[2]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)
[238]107      ENDELSE
[2]108   endwhile
109
110   return,  stringout
111end
Note: See TracBrowser for help on using the repository browser.