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

Last change on this file since 327 was 325, checked in by pinsard, 17 years ago

modification of some headers (+some corrections) to prepare usage of the new idldoc

  • 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; We create a structure
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]
35; We put this structure as a string
36;       IDL> a=strkeywd(b)
37;       IDL> print, a
38;       AGE_CAPITAINE=35, OK=111, YEAR=[1997,1998,1999]
39; Now we can use the string a to pass keywords in a function thanks to execute!!
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;
47; @history
48; Sebastien Masson (smasson\@lodyc.jussieu.fr)
49;                      11/10/1999
50;
51; @version
52; $Id$
53;
54;-
55FUNCTION strkeywd, struct
56;
57  compile_opt idl2, strictarrsubs
58;
59   if size(struct, /type) NE 8 then return,  ''
60   tname = tag_names(struct)
61   if n_elements(tname) EQ 0 then return,  ''
62;------------------------------------------------------------
63; on s''occupe du premier element
64;------------------------------------------------------------
65   res = strlowcase(tname[0])+'='+tostr(struct.(0))
66   if n_elements(tname) EQ 1 then return,  res
67;------------------------------------------------------------
68; on s''occupe des autres elements
69;------------------------------------------------------------
70   for n = 1,n_elements(tname)-1 do res = res+', '+strlowcase(tname[n])+'='+tostr(struct.(n))
71;
72   return,  res
73end
Note: See TracBrowser for help on using the repository browser.