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

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

improvements/corrections of some *.pro headers

  • 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;-
81
82function string2struct,strVal
83;
84  compile_opt idl2, strictarrsubs
85;
86r = execute('extra = too_cool(' + strVal[0] +')')
87;if r = 0 then user did not enter keywords correctly so
88;return a structure with a null field.
89if r eq 0 then begin
90  print,'Error in input string'
91  return,{null:0}
92endif
93return,extra
94end
95
Note: See TracBrowser for help on using the repository browser.