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

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

improvements of headers (alignments)

  • 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
19; vector.
20;
21; @restrictions
22; Beware, this function has loops, ifs and cases everywhere. So it can
23; not be used by big keywords (with a lot of elements which are big
24; arrays). The input keyword must not contain Complex floatings, structure,
25; Double-precision complex, Pointer, Object reference, Unsigned Integer,
26; Unsigned Longword Integer, 64-bit Integer or Unsigned 64-bit Integer.
27;
28; @examples
29;
30; We create a structure:
31;   IDL> b=get_extra(ok=111, year=[1997,1998,1999], age_capitaine=35)
32;   IDL> help, b,/struct
33;       ** Structure <817f4bc>, 3 tags, length=10, refs=1:
34;          AGE_CAPITAINE   INT             35
35;          OK              INT            111
36;          YEAR            INT       Array[3]
37;
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;
43; Now we can use the string a to pass keywords in a function thanks to execute!!
44;   IDL> test=execute('c=get_extra('+a+')')
45;   IDL> help, c,/struct
46;       ** Structure <817f2dc>, 3 tags, length=10, refs=1:
47;          AGE_CAPITAINE   INT             35
48;          OK              INT            111
49;          YEAR            INT       Array[3]
50;
51; @history
52; Sebastien Masson (smasson\@lodyc.jussieu.fr)
53;                      11/10/1999
54;
55; @version
56; $Id$
57;
58;-
59FUNCTION strkeywd, struct
60;
61  compile_opt idl2, strictarrsubs
62;
63   if size(struct, /type) NE 8 then return,  ''
64   tname = tag_names(struct)
65   if n_elements(tname) EQ 0 then return,  ''
66;------------------------------------------------------------
67; on s''occupe du premier element
68;------------------------------------------------------------
69   res = strlowcase(tname[0])+'='+tostr(struct.(0))
70   if n_elements(tname) EQ 1 then return,  res
71;------------------------------------------------------------
72; on s''occupe des autres elements
73;------------------------------------------------------------
74   for n = 1,n_elements(tname)-1 do res = res+', '+strlowcase(tname[n])+'='+tostr(struct.(n))
75;
76   return,  res
77end
Note: See TracBrowser for help on using the repository browser.