;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ;+ ; ; @file_comments ; In a string containing an order to execute with EXECUTE by example. ; We change the value of one of keywords. ; More generally, in a string, we look for the character chain: ', keywdname= ..., ; and we change the value of... ; ; @categories ; String, keywords ; ; ; @param STRINGIN {in}{required}{type=string} ; it is a string ; ; @param KEYWDNAME {in}{required}{type=string} ; it is a string designating the name of keyword to look for. ; ; @param KEYWDVALUE {in}{required} ; The new value of the keyword to considerate in STRINGIN ; ; @keyword SEPARATOR ; To look for the keyword, we look for the first sign = which follow ; the position of keywdname. By default, we substitute the string ; before the comma. With the keyword SEPARATOR,we can modify the cut ; of the string. SEPARATOR give a Character before the one we have to ; look for the comma which delimit the keyword in the string. ; (see examples) ; ; @keyword AFTER ; To look for the keyword, we look for the first sign = which follow ; the position of keywdname. By default, we substitute the string ; before the comma. With the keyword AFTER,we can modify the cut ; of the string. AFTER give a Character after the one we have to ; look for the comma which delimit the keyword in the string. ; (see examples) ; ; @returns ; stringout=stringin modified if keywdname has been found in stringin ; ; @uses ; common.pro ; ; @restrictions ; If keywdvalue is an array, it will be convert in a vector. ; ; @restrictions ; Beware, this function has loops, ifs ad cases everywhere. So it can ; not be used by big keywords (with a lot of elements which are big ; arrays). The input keyword must not contain Complex floatings, structure, ; Double-precision complex, Pointer, Object reference, Unsigned Integer, ; Unsigned Longword Integer, 64-bit Integer or Unsigned 64-bit Integer. ; ; ; @examples ; ; IDL> b='ok=111, year=[1997,1998,1999], age_capitaine=35' ; IDL> print, b ; ok=111, year=[1997,1998,1999], age_capitaine=35 ; IDL> print, chkeywd(b,'ok','c''est bon') ; ok='c''est bon', year=[1997,1998,1999], age_capitaine=35 ; IDL> print, chkeywd(b,'YEAR',indgen(5),sep='=') ; ok=111, year=[0,1,2,3,4], age_capitaine=35 ; IDL> print, chkeywd(b,'YEAR',indgen(5),sep=']',/after) ; ok=111, year=[0,1,2,3,4], age_capitaine=35 ; IDL> b='ok=111, /year, /age_capitaine' ; IDL> print, chkeywd(b,'year','c''est bon') ; ok=111, year='c''est bon', /age_capitaine ; ; @history ; Sebastien Masson (smasson\@lodyc.jussieu.fr) ; 18/10/1999 ; 24/11/1999: adaptation for keywords starting by / ; ; @version ; $Id$ ; ;- ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ FUNCTION chkeywd, stringin, keywdname, keywdvalue, SEPARATOR = separator, AFTER = after ; compile_opt idl2, strictarrsubs ; stringout = stringin poskeywd = strpos(strlowcase(stringout), strlowcase(keywdname)) if poskeywd EQ -1 then return, stringout while poskeywd NE -1 do BEGIN ; change a keyword starting by /toto if strmid(stringout,poskeywd-1,1) EQ '/' then BEGIN ajoute = keywdname+'='+tostr(keywdvalue) stringout = strmid(stringout, 0, poskeywd-1)+ajoute+strmid(stringout,poskeywd+strlen(keywdname) ) poskeywd = poskeywd+strlen(ajoute) poskeywd = strpos(stringout, keywdname, poskeywd) ENDIF ELSE BEGIN ; change a keyword sarting by toto= posegal = strpos(stringout, '=', poskeywd) if posegal EQ -1 then return, stringout if NOT keyword_set(separator) then separator = ',' posvirgule = strpos(stringout, separator, posegal+1) if keyword_set(after) then posvirgule = strpos(stringout, ',', posvirgule-1) $ ELSE posvirgule = rstrpos(stringout, ',', posvirgule+1) if posvirgule EQ -1 then posvirgule = strlen(stringout) ; stringout = strmid(stringout, 0, posegal+1)+tostr(keywdvalue)+strmid(stringout, posvirgule) ; poskeywd = strpos(stringout, keywdname, posvirgule+1) ENDELSE endwhile return, stringout end