source: trunk/SRC/ToBeReviewed/STRING/strkeywd.pro @ 371

Last change on this file since 371 was 371, checked in by pinsard, 16 years ago

improvements of headers (alignments of IDL prompt in examples)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1;+
2;
3; @file_comments
4; Translate a structure in a string able to be used to specify keywords
5; in the calling of a function when we use EXECUTE (see example)
6;
7; @categories
8;
9; @param STRUCT
10; a structure
11;
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'
16;
17; @restrictions
18; If an element of the structure contain an array, it will be convert in a vector.
19;
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.
26;
27; @examples
28;
29; We create a structure
30;   IDL> b=get_extra(ok=111, year=[1997,1998,1999], age_capitaine=35)
31;   IDL> help, b,/struct
32;       ** Structure <817f4bc>, 3 tags, length=10, refs=1:
33;          AGE_CAPITAINE   INT             35
34;          OK              INT            111
35;          YEAR            INT       Array[3]
36;
37; We put this structure as a string
38;   IDL> a=strkeywd(b)
39;   IDL> print, a
40;       AGE_CAPITAINE=35, OK=111, YEAR=[1997,1998,1999]
41;
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;-
58FUNCTION strkeywd, struct
59;
60  compile_opt idl2, strictarrsubs
61;
62   if size(struct, /type) NE 8 then return,  ''
63   tname = tag_names(struct)
64   if n_elements(tname) EQ 0 then return,  ''
65;------------------------------------------------------------
66; on s''occupe du premier element
67;------------------------------------------------------------
68   res = strlowcase(tname[0])+'='+tostr(struct.(0))
69   if n_elements(tname) EQ 1 then return,  res
70;------------------------------------------------------------
71; on s''occupe des autres elements
72;------------------------------------------------------------
73   for n = 1,n_elements(tname)-1 do res = res+', '+strlowcase(tname[n])+'='+tostr(struct.(n))
74;
75   return,  res
76end
Note: See TracBrowser for help on using the repository browser.