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

Last change on this file since 373 was 372, checked in by pinsard, 16 years ago

improvements of headers (alignments)

  • 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. 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;-
80FUNCTION string2struct,strVal
81;
82  compile_opt idl2, strictarrsubs
83;
84r = execute('extra = too_cool(' + strVal[0] +')')
85;if r = 0 then user did not enter keywords correctly so
86;return a structure with a null field.
87if r eq 0 then begin
88  print,'Error in input string'
89  return,{null:0}
90endif
91return,extra
92end
93
Note: See TracBrowser for help on using the repository browser.