source: trunk/SRC/ToBeReviewed/STRING/string2struct.pro @ 174

Last change on this file since 174 was 157, checked in by navarro, 18 years ago

header improvements + xxx doc

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