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
RevLine 
[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
[371]28;
[142]29; We create a structure
[371]30;   IDL> b=get_extra(ok=111, year=[1997,1998,1999], age_capitaine=35)
31;   IDL> help, b,/struct
[2]32;       ** Structure <817f4bc>, 3 tags, length=10, refs=1:
33;          AGE_CAPITAINE   INT             35
34;          OK              INT            111
35;          YEAR            INT       Array[3]
[371]36;
[142]37; We put this structure as a string
[371]38;   IDL> a=strkeywd(b)
39;   IDL> print, a
[2]40;       AGE_CAPITAINE=35, OK=111, YEAR=[1997,1998,1999]
[371]41;
[142]42; Now we can use the string a to pass keywords in a function thanks to execute!!
[371]43;   IDL> test=execute('c=get_extra('+a+')')
44;   IDL> help, c,/struct
[2]45;       ** Structure <817f2dc>, 3 tags, length=10, refs=1:
46;          AGE_CAPITAINE   INT             35
47;          OK              INT            111
48;          YEAR            INT       Array[3]
49;
[142]50; @history
[157]51; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[2]52;                      11/10/1999
[142]53;
54; @version
55; $Id$
56;
[2]57;-
58FUNCTION strkeywd, struct
[114]59;
60  compile_opt idl2, strictarrsubs
61;
[2]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.