;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ;+ ; NAME: chkeywd (change keyword) ; ; PURPOSE: ds un string qui contient une commande a executer avec ; EXECUTE par ex. On change la valeur d''un des mot cle. ; Plus generalement, ds un string, on cherche la chaine de ; chacarteres: ', keywdname= ..., et on change la valeur de ... ; ; CATEGORY: pour bidouiller des commandes passees par execute ; ; CALLING SEQUENCE: stringout=chkeywd(stringin, keywdname, keywdvalue) ; ; INPUTS: ; stringin: un string ; keywdname: un string designant le nom du mot clef a chercher. ; keywdvalue: nouvelle valeur du mot clef a considerer ds stringin ; ; KEYWORD PARAMETERS: ; pour chercher le mot cle, on cherche le premier signe = qui ; suit la position de keywdname. on substitue ; pardefaut tout le bout de string qui suit jusqu''a la prochaine ; virgule. avec les mots cles SEPARATOR et AFTER on peut modifier ; cette decoupe du string: ; SEPARATOR donne un chatactere avant (ou apres si AFTER est ; active) lequel il faut chercher la virgule qui delimite le mot ; cle ds le string. cf. les exemples ; ; OUTPUTS:stringout=stringin modifie si keywdname a ete trouve ds ; stringin ; ; COMMON BLOCKS:common.pro ; ; SIDE EFFECTS: ; ; Si keywdvalue est un tableau, il sera convertit en vecteur. ; ; RESTRICTIONS: ; ; attention cette fonction comporte des boucles, des if et des cases ; ds tous les sens. Elle ne doit donc pas etre utilisee avec des ; mots clefs de grosse taille (avec bcp d''elements et avec des ; elements etant de gros tableaux). ; le mot clef en entree ne doit pas contenir de Complex floating, de ; structure, de Double-precision complex, de Pointer, de Object ; reference, de Unsigned Integer, de Unsigned Longword Integer, de ; 64-bit Integer, de Unsigned 64-bit Integer ; ; EXAMPLE: ; ; 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 ; ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) ; 18/10/1999 ; 24/11/1999: adaptation pour les mots cles ; commencant par / ;- ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ FUNCTION chkeywd, stringin, keywdname, keywdvalue, SEPARATOR = separator, AFTER = after stringout = stringin poskeywd = strpos(strlowcase(stringout), strlowcase(keywdname)) if poskeywd EQ -1 then return, stringout while poskeywd NE -1 do BEGIN ; changer un mot cle qui commence par /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 ; changer un mot cle qui commence par 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