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

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • 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; @keyword _EXTRA
9; Used to pass keywords
10;
11; @returns
12;
13; @restrictions
14;
15; @examples
16;
17; @history
18;
19; @version
20; $Id$
21;
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.
42; Such as
43;
44; plot,findgen(100),_extra=string2struct('title="testing"')
45;
46; @returns
47; This function returns the string as an anonymous structure. If an
48; error was found then this function returns a structure with a null field.
49;
50; @examples
51;       The code below creates a widget that uses this routine.
52;       pro tPlot,event
53;       widget_control,event.top,get_uvalue=field
54;       widget_control,field,get_value=strval
55;       extra = string2struct(strval)
56;       plot,findgen(100),_extra=extra
57;       wshow
58;       return
59;       end
60;
61;       pro testWid
62;       ;enter any keyword to plot and see how it works
63;       base = widget_base(/col)
64;       field = cw_field(base,title='test',value='ax=0',/string)
65;       void = widget_button(base,value='plot',event_pro='tPlot')
66;       widget_control,base,/realize,set_uvalue=field
67;       xmanager,'testWid',base,/no_block
68;       return
69;       end
70;
71; @history
72;       Written by:
73;       RLK, Ronn Kling Consulting.
74;       ronn\@rlkling.com
75;       www.rlkling.com
76;               May, 1999
77;
78; @version
79; $Id$
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
Note: See TracBrowser for help on using the repository browser.