1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; |
---|
6 | ; @file_comments |
---|
7 | ; Translate a sturcture in a string able to be used to specify keywords |
---|
8 | ; in the calling of a function when we use EXECUTE (see example) |
---|
9 | ; |
---|
10 | ; @categories |
---|
11 | ; |
---|
12 | ; @param STRUCT |
---|
13 | ; a structure |
---|
14 | ; |
---|
15 | ; @returns |
---|
16 | ; a string composed like following: |
---|
17 | ; For each element of the structure, we write a part of the string as: |
---|
18 | ; 'name_of_the_element=content_of_the_element' |
---|
19 | ; |
---|
20 | ; @restrictions |
---|
21 | ; If an element of the structure contain an array, it will be convert in a vector. |
---|
22 | ; |
---|
23 | ; @restrictions |
---|
24 | ; Beware, this function has loops, ifs ad cases everywhere. So it can |
---|
25 | ; not be used by big keywords (with a lot of elements which are big |
---|
26 | ; arrays). The input keyword must not contain Complex floatings, structure, |
---|
27 | ; Double-precision complex, Pointer, Object reference, Unsigned Integer, |
---|
28 | ; Unsigned Longword Integer, 64-bit Integer or Unsigned 64-bit Integer. |
---|
29 | ; |
---|
30 | ; @examples |
---|
31 | ; We create a structure |
---|
32 | ; IDL> b=get_extra(ok=111, year=[1997,1998,1999], age_capitaine=35) |
---|
33 | ; IDL> help, b,/struct |
---|
34 | ; ** Structure <817f4bc>, 3 tags, length=10, refs=1: |
---|
35 | ; AGE_CAPITAINE INT 35 |
---|
36 | ; OK INT 111 |
---|
37 | ; YEAR INT Array[3] |
---|
38 | ; We put this structure as a string |
---|
39 | ; IDL> a=strkeywd(b) |
---|
40 | ; IDL> print, a |
---|
41 | ; AGE_CAPITAINE=35, OK=111, YEAR=[1997,1998,1999] |
---|
42 | ; Now we can use the string a to pass keywords in a function thanks to execute!! |
---|
43 | ; IDL> test=execute('c=get_extra('+a+')') |
---|
44 | ; IDL> help, c,/struct |
---|
45 | ; ** Structure <817f2dc>, 3 tags, length=10, refs=1: |
---|
46 | ; AGE_CAPITAINE INT 35 |
---|
47 | ; OK INT 111 |
---|
48 | ; YEAR INT Array[3] |
---|
49 | ; |
---|
50 | ; @history |
---|
51 | ; Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
52 | ; 11/10/1999 |
---|
53 | ; |
---|
54 | ; @version |
---|
55 | ; $Id$ |
---|
56 | ; |
---|
57 | ;- |
---|
58 | ;------------------------------------------------------------ |
---|
59 | ;------------------------------------------------------------ |
---|
60 | ;------------------------------------------------------------ |
---|
61 | FUNCTION strkeywd, struct |
---|
62 | ; |
---|
63 | compile_opt idl2, strictarrsubs |
---|
64 | ; |
---|
65 | if size(struct, /type) NE 8 then return, '' |
---|
66 | tname = tag_names(struct) |
---|
67 | if n_elements(tname) EQ 0 then return, '' |
---|
68 | ;------------------------------------------------------------ |
---|
69 | ; on s''occupe du premier element |
---|
70 | ;------------------------------------------------------------ |
---|
71 | res = strlowcase(tname[0])+'='+tostr(struct.(0)) |
---|
72 | if n_elements(tname) EQ 1 then return, res |
---|
73 | ;------------------------------------------------------------ |
---|
74 | ; on s''occupe des autres elements |
---|
75 | ;------------------------------------------------------------ |
---|
76 | for n = 1,n_elements(tname)-1 do res = res+', '+strlowcase(tname[n])+'='+tostr(struct.(n)) |
---|
77 | ; |
---|
78 | return, res |
---|
79 | end |
---|