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

Last change on this file since 97 was 97, checked in by pinsard, 18 years ago

start to modify headers of Obsolete *.pro files for better idldoc output

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