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

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

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