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