[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
| 5 | ; NAME: chkeywd (change keyword) |
---|
| 6 | ; |
---|
| 7 | ; PURPOSE: ds un string qui contient une commande a executer avec |
---|
| 8 | ; EXECUTE par ex. On change la valeur d''un des mot cle. |
---|
| 9 | ; Plus generalement, ds un string, on cherche la chaine de |
---|
| 10 | ; chacarteres: ', keywdname= ..., et on change la valeur de ... |
---|
| 11 | ; |
---|
| 12 | ; CATEGORY: pour bidouiller des commandes passees par execute |
---|
| 13 | ; |
---|
| 14 | ; CALLING SEQUENCE: stringout=chkeywd(stringin, keywdname, keywdvalue) |
---|
| 15 | ; |
---|
| 16 | ; INPUTS: |
---|
| 17 | ; stringin: un string |
---|
| 18 | ; keywdname: un string designant le nom du mot clef a chercher. |
---|
| 19 | ; keywdvalue: nouvelle valeur du mot clef a considerer ds stringin |
---|
| 20 | ; |
---|
| 21 | ; KEYWORD PARAMETERS: |
---|
| 22 | ; pour chercher le mot cle, on cherche le premier signe = qui |
---|
| 23 | ; suit la position de keywdname. on substitue |
---|
| 24 | ; pardefaut tout le bout de string qui suit jusqu''a la prochaine |
---|
| 25 | ; virgule. avec les mots cles SEPARATOR et AFTER on peut modifier |
---|
| 26 | ; cette decoupe du string: |
---|
| 27 | ; SEPARATOR donne un chatactere avant (ou apres si AFTER est |
---|
| 28 | ; active) lequel il faut chercher la virgule qui delimite le mot |
---|
| 29 | ; cle ds le string. cf. les exemples |
---|
| 30 | ; |
---|
| 31 | ; OUTPUTS:stringout=stringin modifie si keywdname a ete trouve ds |
---|
| 32 | ; stringin |
---|
| 33 | ; |
---|
| 34 | ; COMMON BLOCKS:common.pro |
---|
| 35 | ; |
---|
| 36 | ; SIDE EFFECTS: |
---|
| 37 | ; |
---|
| 38 | ; Si keywdvalue est un tableau, il sera convertit en vecteur. |
---|
| 39 | ; |
---|
| 40 | ; RESTRICTIONS: |
---|
| 41 | ; |
---|
| 42 | ; attention cette fonction comporte des boucles, des if et des cases |
---|
| 43 | ; ds tous les sens. Elle ne doit donc pas etre utilisee avec des |
---|
| 44 | ; mots clefs de grosse taille (avec bcp d''elements et avec des |
---|
| 45 | ; elements etant de gros tableaux). |
---|
| 46 | ; le mot clef en entree ne doit pas contenir de Complex floating, de |
---|
| 47 | ; structure, de Double-precision complex, de Pointer, de Object |
---|
| 48 | ; reference, de Unsigned Integer, de Unsigned Longword Integer, de |
---|
| 49 | ; 64-bit Integer, de Unsigned 64-bit Integer |
---|
| 50 | ; |
---|
| 51 | ; EXAMPLE: |
---|
| 52 | ; |
---|
| 53 | ; IDL> b='ok=111, year=[1997,1998,1999], age_capitaine=35' |
---|
| 54 | ; IDL> print, b |
---|
| 55 | ; ok=111, year=[1997,1998,1999], age_capitaine=35 |
---|
| 56 | ; IDL> print, chkeywd(b,'ok','c''est bon') |
---|
| 57 | ; ok='c''est bon', year=[1997,1998,1999], age_capitaine=35 |
---|
| 58 | ; IDL> print, chkeywd(b,'YEAR',indgen(5),sep='=') |
---|
| 59 | ; ok=111, year=[0,1,2,3,4], age_capitaine=35 |
---|
| 60 | ; IDL> print, chkeywd(b,'YEAR',indgen(5),sep=']',/after) |
---|
| 61 | ; ok=111, year=[0,1,2,3,4], age_capitaine=35 |
---|
| 62 | ; IDL> b='ok=111, /year, /age_capitaine' |
---|
| 63 | ; IDL> print, chkeywd(b,'year','c''est bon') |
---|
| 64 | ; ok=111, year='c''est bon', /age_capitaine |
---|
| 65 | ; |
---|
| 66 | ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
| 67 | ; 18/10/1999 |
---|
| 68 | ; 24/11/1999: adaptation pour les mots cles |
---|
| 69 | ; commencant par / |
---|
| 70 | ;- |
---|
| 71 | ;------------------------------------------------------------ |
---|
| 72 | ;------------------------------------------------------------ |
---|
| 73 | ;------------------------------------------------------------ |
---|
| 74 | FUNCTION chkeywd, stringin, keywdname, keywdvalue, SEPARATOR = separator, AFTER = after |
---|
| 75 | |
---|
| 76 | stringout = stringin |
---|
| 77 | poskeywd = strpos(strlowcase(stringout), strlowcase(keywdname)) |
---|
| 78 | if poskeywd EQ -1 then return, stringout |
---|
| 79 | while poskeywd NE -1 do BEGIN |
---|
| 80 | ; changer un mot cle qui commence par /toto |
---|
| 81 | if strmid(stringout,poskeywd-1,1) EQ '/' then BEGIN |
---|
| 82 | ajoute = keywdname+'='+tostr(keywdvalue) |
---|
| 83 | stringout = strmid(stringout, 0, poskeywd-1)+ajoute+strmid(stringout,poskeywd+strlen(keywdname) ) |
---|
| 84 | poskeywd = poskeywd+strlen(ajoute) |
---|
| 85 | poskeywd = strpos(stringout, keywdname, poskeywd) |
---|
| 86 | ENDIF ELSE BEGIN |
---|
| 87 | ; changer un mot cle qui commence par toto= |
---|
| 88 | posegal = strpos(stringout, '=', poskeywd) |
---|
| 89 | if posegal EQ -1 then return, stringout |
---|
| 90 | |
---|
| 91 | if NOT keyword_set(separator) then separator = ',' |
---|
| 92 | posvirgule = strpos(stringout, separator, posegal+1) |
---|
| 93 | if keyword_set(after) then posvirgule = strpos(stringout, ',', posvirgule-1) $ |
---|
| 94 | ELSE posvirgule = rstrpos(stringout, ',', posvirgule+1) |
---|
| 95 | if posvirgule EQ -1 then posvirgule = strlen(stringout) |
---|
| 96 | ; |
---|
| 97 | stringout = strmid(stringout, 0, posegal+1)+tostr(keywdvalue)+strmid(stringout, posvirgule) |
---|
| 98 | ; |
---|
| 99 | poskeywd = strpos(stringout, keywdname, posvirgule+1) |
---|
| 100 | ENDELSE |
---|
| 101 | endwhile |
---|
| 102 | |
---|
| 103 | return, stringout |
---|
| 104 | end |
---|