[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
| 5 | ; NAME: strkeywd (string keywords) |
---|
| 6 | ; |
---|
| 7 | ; PURPOSE: traduit une sturcture en un string pouvant etre utilise |
---|
| 8 | ; pour specifier des keywords ds l''appelle d''une fonction qd on |
---|
| 9 | ; utilise execute (cf l''exemple) |
---|
| 10 | ; |
---|
| 11 | ; CATEGORY: pour passer des mots cles avec execute ! |
---|
| 12 | ; |
---|
| 13 | ; CALLING SEQUENCE:res=strkeywd(struct) |
---|
| 14 | ; |
---|
| 15 | ; INPUTS:struct: une structure |
---|
| 16 | ; |
---|
| 17 | ; KEYWORD PARAMETERS: |
---|
| 18 | ; |
---|
| 19 | ; OUTPUTS:un string compose de la facon suivante: |
---|
| 20 | ; pour chaque element de la structure, on ecrit une partie du |
---|
| 21 | ; string sous la forme: |
---|
| 22 | ; 'nom_de_l''element=contennu de l''element' |
---|
| 23 | ; |
---|
| 24 | ; COMMON BLOCKS: |
---|
| 25 | ; |
---|
| 26 | ; SIDE EFFECTS: |
---|
| 27 | ; |
---|
| 28 | ; Si un element de la structure contient un tableau, il sera |
---|
| 29 | ; convertit en vecteur. |
---|
| 30 | ; |
---|
| 31 | ; RESTRICTIONS: |
---|
| 32 | ; |
---|
| 33 | ; attention cette fonction comporte des boucles, des if et des cases |
---|
| 34 | ; ds tous les sens. Elle ne doit donc pas etre utilisee avec des |
---|
| 35 | ; structure de grosse taille (avec bcp d''elements et avec des |
---|
| 36 | ; elements etant de gros tableaux). |
---|
| 37 | ; la structure en entree ne doit pas contenir de Complex floating, de |
---|
| 38 | ; structure, de Double-precision complex, de Pointer, de Object |
---|
| 39 | ; reference, de Unsigned Integer, de Unsigned Longword Integer, de |
---|
| 40 | ; 64-bit Integer, de Unsigned 64-bit Integer |
---|
| 41 | ; |
---|
| 42 | ; |
---|
| 43 | ; |
---|
| 44 | ; EXAMPLE: |
---|
| 45 | ; |
---|
| 46 | ; on cree une structure |
---|
| 47 | ; IDL> b=get_extra(ok=111, year=[1997,1998,1999], age_capitaine=35) |
---|
| 48 | ; IDL> help, b,/struct |
---|
| 49 | ; ** Structure <817f4bc>, 3 tags, length=10, refs=1: |
---|
| 50 | ; AGE_CAPITAINE INT 35 |
---|
| 51 | ; OK INT 111 |
---|
| 52 | ; YEAR INT Array[3] |
---|
| 53 | ; on met cette structure sous forme de string |
---|
| 54 | ; IDL> a=strkeywd(b) |
---|
| 55 | ; IDL> print, a |
---|
| 56 | ; AGE_CAPITAINE=35, OK=111, YEAR=[1997,1998,1999] |
---|
| 57 | ; maintenant on peut utiliser le string a pour passer des mots cles ds |
---|
| 58 | ; une fonction a l''aide de execute!! |
---|
| 59 | ; IDL> test=execute('c=get_extra('+a+')') |
---|
| 60 | ; IDL> help, c,/struct |
---|
| 61 | ; ** Structure <817f2dc>, 3 tags, length=10, refs=1: |
---|
| 62 | ; AGE_CAPITAINE INT 35 |
---|
| 63 | ; OK INT 111 |
---|
| 64 | ; YEAR INT Array[3] |
---|
| 65 | ; |
---|
| 66 | ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
| 67 | ; 11/10/1999 |
---|
| 68 | ;- |
---|
| 69 | ;------------------------------------------------------------ |
---|
| 70 | ;------------------------------------------------------------ |
---|
| 71 | ;------------------------------------------------------------ |
---|
| 72 | FUNCTION strkeywd, struct |
---|
| 73 | if size(struct, /type) NE 8 then return, '' |
---|
| 74 | tname = tag_names(struct) |
---|
| 75 | if n_elements(tname) EQ 0 then return, '' |
---|
| 76 | ;------------------------------------------------------------ |
---|
| 77 | ; on s''occupe du premier element |
---|
| 78 | ;------------------------------------------------------------ |
---|
| 79 | res = strlowcase(tname[0])+'='+tostr(struct.(0)) |
---|
| 80 | if n_elements(tname) EQ 1 then return, res |
---|
| 81 | ;------------------------------------------------------------ |
---|
| 82 | ; on s''occupe des autres elements |
---|
| 83 | ;------------------------------------------------------------ |
---|
| 84 | for n = 1,n_elements(tname)-1 do res = res+', '+strlowcase(tname[n])+'='+tostr(struct.(n)) |
---|
| 85 | ; |
---|
| 86 | return, res |
---|
| 87 | end |
---|