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

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

improvements of some *.pro

  • 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 a structure.
4;
5; @categories
6;
7;
8; @keyword _EXTRA
9; used to pass your keywords
10;
11; @returns
12;
13; @restrictions
14;
15; @examples
16;
17;
18; @history
19;
20; @version
21; $Id$
22;-
23function too_cool,_extra=extra
24;
25  compile_opt idl2, strictarrsubs
26;
27return,extra
28end
29
30;+
31;
32; @file_comments
33; Takes an input string set up as keywords and returns an anonymous structure.
34; This is particularly useful for taking keywords entered by a user in a text
35; field and passing then to other routines.
36;
37; @categories
38; Utilities
39;
40; @param STRVAL {IN}{REQUIRED}
41; String set up as keywords. Keywords require a little special treatment. Such as
42; plot,findgen(100),_extra=stringToStructure('title="testing"')
43;
44; @returns
45; This function returns the string as an anonymous structure. If an
46; error was found then this function returns a structure with a null field.
47;
48; @examples
49;       The code below creates a widget that uses this routine.
50;       pro tPlot,event
51;       widget_control,event.top,get_uvalue=field
52;       widget_control,field,get_value=strVal
53;       extra = stringToStructure(strVal)
54;       plot,findgen(100),_extra=extra
55;       wshow
56;       return
57;       end
58;
59;       pro testWid
60;       ;enter any keyword to plot and see how it works
61;       base = widget_base(/col)
62;       field = cw_field(base,title='test',value='ax=0',/string)
63;       void = widget_button(base,value='plot',event_pro='tPlot')
64;       widget_control,base,/realize,set_uvalue=field
65;       xmanager,'testWid',base,/no_block
66;       return
67;       end
68;
69; @history
70;       Written by:
71;       RLK, Ronn Kling Consulting.
72;       ronn\@rlkling.com
73;       www.rlkling.com
74;               May, 1999
75;
76; @version
77; $Id$
78;
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.