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

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

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