function too_cool,_extra=extra ; ; This is a really, really cool way to turn keywords into ; a structure. ; return,extra end function stringToStructure,strVal ;+ ; NAME: ; stringToStructure ; ; PURPOSE: ; Takes an input string set up as keywords and returns an anonymous structure. ; This is particularly useful for taking keywords entered by a user in a text ; field and passing then to other routines. ; ; CATEGORY: ; Utility ; ; CALLING SEQUENCE: ; extra=stringToStructure('xrange=[0,10],linestyle=2') ; plot,findgen(100),_extra=extra ; ; INPUTS: ; String set up as keywords. Keywords require a little special treatment. Such as ; plot,findgen(100),_extra=stringToStructure('title="testing"') ; ; KEYWORD PARAMETERS: ; ; None ; ; OUTPUTS: ; This function returns the string as an anonymous structure. If an ; error was found then this function returns a structure with a null field. ; ; COMMON BLOCKS: ; None. ; ; EXAMPLE: ; The code below creates a widget that uses this routine. ; pro tPlot,event ; widget_control,event.top,get_uvalue=field ; widget_control,field,get_value=strVal ; extra = stringToStructure(strVal) ; plot,findgen(100),_extra=extra ; wshow ; return ; end ; ; pro testWid ; ;enter any keyword to plot and see how it works ; base = widget_base(/col) ; field = cw_field(base,title='test',value='ax=0',/string) ; void = widget_button(base,value='plot',event_pro='tPlot') ; widget_control,base,/realize,set_uvalue=field ; xmanager,'testWid',base,/no_block ; return ; end ; ; MODIFICATION HISTORY: ; Written by: ; RLK ; Kling Research and Software, Inc. ; ronn@rlkling.com ; www.rlkling.com ; May, 1999 ; ; LICENSE ; ; This software is OSI Certified Open Source Software. ; OSI Certified is a certification mark of the Open Source Initiative. ; ; Copyright © 1997-2001 Kling Research and Software. ; ; This software is provided "as-is", without any express or ; implied warranty. In no event will the authors be held liable ; for any damages arising from the use of this software. ; ; Permission is granted to anyone to use this software for any ; purpose, including commercial applications, and to alter it and ; redistribute it freely, subject to the following restrictions: ; ; 1. The origin of this software must not be misrepresented; you must ; not claim you wrote the original software. If you use this software ; in a product, an acknowledgment in the product documentation ; would be appreciated, but is not required. ; ; 2. Altered source versions must be plainly marked as such, and must ; not be misrepresented as being the original software. ; ; 3. This notice may not be removed or altered from any source distribution. ; ; For more information on Open Source Software, visit the Open Source ; web site: http://www.opensource.org. ;- r = execute('extra = too_cool(' + strVal[0] +')') ;if r = 0 then user did not enter keywords correctly so ;return a structure with a null field. if r eq 0 then begin print,'Error in input string' return,{null:0} endif return,extra end