source: trunk/ToBeReviewed/STRING/string2struct.pro @ 18

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

upgrade of STRING according to cerbere.lodyc.jussieu.fr: /usr/home/smasson/SAXO_RD/ : files

  • 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 
1function too_cool,_extra=extra
2;
3; This is a really, really cool way to turn keywords into
4; a structure.
5;
6return,extra
7end
8
9function string2struct,strVal
10;+
11; NAME:
12;       stringToStructure
13;
14; PURPOSE:
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; CATEGORY:
20;       Utility
21;
22; CALLING SEQUENCE:
23;       extra=stringToStructure('xrange=[0,10],linestyle=2')
24;       plot,findgen(100),_extra=extra
25;
26; INPUTS:
27;       String set up as keywords. Keywords require a little special treatment. Such as
28;       plot,findgen(100),_extra=stringToStructure('title="testing"')
29;
30; KEYWORD PARAMETERS:
31;
32;       None
33;
34; OUTPUTS:
35;       This function returns the string as an anonymous structure. If an
36;       error was found then this function returns a structure with a null field.
37;
38; COMMON BLOCKS:
39;       None.
40;
41; EXAMPLE:
42;       The code below creates a widget that uses this routine.
43;       pro tPlot,event
44;       widget_control,event.top,get_uvalue=field
45;       widget_control,field,get_value=strVal
46;       extra = stringToStructure(strVal)
47;       plot,findgen(100),_extra=extra
48;       wshow
49;       return
50;       end
51;
52;       pro testWid
53;       ;enter any keyword to plot and see how it works
54;       base = widget_base(/col)
55;       field = cw_field(base,title='test',value='ax=0',/string)
56;       void = widget_button(base,value='plot',event_pro='tPlot')
57;       widget_control,base,/realize,set_uvalue=field
58;       xmanager,'testWid',base,/no_block
59;       return
60;       end
61;
62; MODIFICATION HISTORY:
63;       Written by:
64;       RLK, Ronn Kling Consulting.
65;       ronn@rlkling.com
66;       www.rlkling.com
67;               May, 1999
68;-
69
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.