;+ ; ; @file_comments ; Translate a structure in a string able to be used to specify keywords ; in the calling of a function when we use EXECUTE (see example) ; ; @categories ; ; @param STRUCT ; a structure ; ; @returns ; a string composed like following: ; For each element of the structure, we write a part of the string as: ; 'name_of_the_element=content_of_the_element' ; ; @restrictions ; If an element of the structure contain an array, it will be convert in a vector. ; ; @restrictions ; Beware, this function has loops, ifs ad cases everywhere. So it can ; not be used by big keywords (with a lot of elements which are big ; arrays). The input keyword must not contain Complex floatings, structure, ; Double-precision complex, Pointer, Object reference, Unsigned Integer, ; Unsigned Longword Integer, 64-bit Integer or Unsigned 64-bit Integer. ; ; @examples ; We create a structure ; IDL> b=get_extra(ok=111, year=[1997,1998,1999], age_capitaine=35) ; IDL> help, b,/struct ; ** Structure <817f4bc>, 3 tags, length=10, refs=1: ; AGE_CAPITAINE INT 35 ; OK INT 111 ; YEAR INT Array[3] ; We put this structure as a string ; IDL> a=strkeywd(b) ; IDL> print, a ; AGE_CAPITAINE=35, OK=111, YEAR=[1997,1998,1999] ; Now we can use the string a to pass keywords in a function thanks to execute!! ; IDL> test=execute('c=get_extra('+a+')') ; IDL> help, c,/struct ; ** Structure <817f2dc>, 3 tags, length=10, refs=1: ; AGE_CAPITAINE INT 35 ; OK INT 111 ; YEAR INT Array[3] ; ; @history ; Sebastien Masson (smasson\@lodyc.jussieu.fr) ; 11/10/1999 ; ; @version ; $Id$ ; ;- FUNCTION strkeywd, struct ; compile_opt idl2, strictarrsubs ; if size(struct, /type) NE 8 then return, '' tname = tag_names(struct) if n_elements(tname) EQ 0 then return, '' ;------------------------------------------------------------ ; on s''occupe du premier element ;------------------------------------------------------------ res = strlowcase(tname[0])+'='+tostr(struct.(0)) if n_elements(tname) EQ 1 then return, res ;------------------------------------------------------------ ; on s''occupe des autres elements ;------------------------------------------------------------ for n = 1,n_elements(tname)-1 do res = res+', '+strlowcase(tname[n])+'='+tostr(struct.(n)) ; return, res end