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

Last change on this file since 231 was 231, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
RevLine 
[157]1;+
[231]2;
[157]3; @file_comments
[223]4; This is a really, really cool way to turn keywords into a structure.
5;
[157]6; @categories
[2]7;
[157]8;
9; @keyword _EXTRA
[231]10; Used to pass keywords
[157]11;
12; @returns
13;
14; @restrictions
15;
16; @examples
17;
18; @history
19;
20; @version
21; $Id$
22;-
[114]23;
[231]24FUNCTION too_cool,_extra=extra
25;
[114]26  compile_opt idl2, strictarrsubs
27;
[2]28return,extra
29end
30
31;+
32;
[142]33; @file_comments
34; Takes an input string set up as keywords and returns an anonymous structure.
35; This is particularly useful for taking keywords entered by a user in a text
36; field and passing then to other routines.
[2]37;
[142]38; @categories
[157]39; Utilities
[2]40;
[142]41; @param STRVAL {IN}{REQUIRED}
42; String set up as keywords. Keywords require a little special treatment. Such as
43; plot,findgen(100),_extra=stringToStructure('title="testing"')
[2]44;
[223]45; @returns
[142]46; This function returns the string as an anonymous structure. If an
47; error was found then this function returns a structure with a null field.
[2]48;
[142]49; @examples
[2]50;       The code below creates a widget that uses this routine.
51;       pro tPlot,event
52;       widget_control,event.top,get_uvalue=field
53;       widget_control,field,get_value=strVal
54;       extra = stringToStructure(strVal)
55;       plot,findgen(100),_extra=extra
56;       wshow
57;       return
58;       end
59;
60;       pro testWid
61;       ;enter any keyword to plot and see how it works
62;       base = widget_base(/col)
63;       field = cw_field(base,title='test',value='ax=0',/string)
64;       void = widget_button(base,value='plot',event_pro='tPlot')
65;       widget_control,base,/realize,set_uvalue=field
66;       xmanager,'testWid',base,/no_block
67;       return
68;       end
69;
[142]70; @history
[2]71;       Written by:
72;       RLK, Ronn Kling Consulting.
[157]73;       ronn\@rlkling.com
[2]74;       www.rlkling.com
75;               May, 1999
[142]76;
77; @version
78; $Id$
79;
[2]80;-
81
[97]82function string2struct,strVal
[114]83;
84  compile_opt idl2, strictarrsubs
85;
[2]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
95
Note: See TracBrowser for help on using the repository browser.