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

Last change on this file since 134 was 134, checked in by navarro, 18 years ago

change *.pro file properties (del eof-style, del executable, set keywords Id

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
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;------------------------------------------------------------
74FUNCTION chkeywd, stringin, keywdname, keywdvalue, SEPARATOR = separator, AFTER = after
75;
76  compile_opt idl2, strictarrsubs
77;
78
79   stringout = stringin
80   poskeywd = strpos(strlowcase(stringout), strlowcase(keywdname))
81   if poskeywd EQ -1 then return, stringout
82   while poskeywd NE -1 do BEGIN
83; changer un mot cle qui commence par /toto
84      if strmid(stringout,poskeywd-1,1) EQ '/' then BEGIN
85         ajoute = keywdname+'='+tostr(keywdvalue)
86         stringout = strmid(stringout, 0, poskeywd-1)+ajoute+strmid(stringout,poskeywd+strlen(keywdname) )
87         poskeywd = poskeywd+strlen(ajoute)
88         poskeywd = strpos(stringout, keywdname, poskeywd)
89      ENDIF ELSE BEGIN
90; changer un mot cle qui commence par toto=
91         posegal = strpos(stringout, '=', poskeywd)
92         if posegal EQ -1 then return, stringout
93
94         if NOT keyword_set(separator) then separator = ','
95         posvirgule = strpos(stringout, separator, posegal+1)
96         if keyword_set(after) then posvirgule = strpos(stringout, ',', posvirgule-1) $
97         ELSE posvirgule = rstrpos(stringout, ',', posvirgule+1)
98         if posvirgule EQ -1 then posvirgule = strlen(stringout)
99;
100         stringout = strmid(stringout, 0, posegal+1)+tostr(keywdvalue)+strmid(stringout, posvirgule)
101;
102         poskeywd = strpos(stringout, keywdname, posvirgule+1)
103      ENDELSE
104   endwhile
105
106   return,  stringout
107end
Note: See TracBrowser for help on using the repository browser.