source: trunk/SRC/ToBeReviewed/STRING/string2struct.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.0 KB
Line 
1;+
2;
3; @file_comments
4; This is a really, really cool way to turn keywords into a structure.
5;
6; @categories
7;
8;
9; @keyword _EXTRA
10; Used to pass keywords
11;
12; @returns
13;
14; @restrictions
15;
16; @examples
17;
18; @history
19;
20; @version
21; $Id$
22;
23;-
24FUNCTION too_cool, _EXTRA=extra
25;
26  compile_opt idl2, strictarrsubs
27;
28return,extra
29end
30
31;+
32;
33; @file_comments
34; Takes an input string set up as keywords and returns an anonymous structure.
35; This is particularly useful for taking keywords entered by a user in a text
36; field and passing then to other routines.
37;
38; @categories
39; Utilities
40;
41; @param STRVAL {IN}{REQUIRED}
42; String set up as keywords. Keywords require a little special treatment. Such as
43; plot,findgen(100),_extra=stringToStructure('title="testing"')
44;
45; @returns
46; This function returns the string as an anonymous structure. If an
47; error was found then this function returns a structure with a null field.
48;
49; @examples
50;       The code below creates a widget that uses this routine.
51;       pro tPlot,event
52;       widget_control,event.top,get_uvalue=field
53;       widget_control,field,get_value=strVal
54;       extra = stringToStructure(strVal)
55;       plot,findgen(100),_extra=extra
56;       wshow
57;       return
58;       end
59;
60;       pro testWid
61;       ;enter any keyword to plot and see how it works
62;       base = widget_base(/col)
63;       field = cw_field(base,title='test',value='ax=0',/string)
64;       void = widget_button(base,value='plot',event_pro='tPlot')
65;       widget_control,base,/realize,set_uvalue=field
66;       xmanager,'testWid',base,/no_block
67;       return
68;       end
69;
70; @history
71;       Written by:
72;       RLK, Ronn Kling Consulting.
73;       ronn\@rlkling.com
74;       www.rlkling.com
75;               May, 1999
76;
77; @version
78; $Id$
79;
80;-
81FUNCTION string2struct,strVal
82;
83  compile_opt idl2, strictarrsubs
84;
85r = execute('extra = too_cool(' + strVal[0] +')')
86;if r = 0 then user did not enter keywords correctly so
87;return a structure with a null field.
88if r eq 0 then begin
89  print,'Error in input string'
90  return,{null:0}
91endif
92return,extra
93end
94
Note: See TracBrowser for help on using the repository browser.