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

Last change on this file since 142 was 142, checked in by navarro, 18 years ago

english and nicer header (2a)

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