;+ ; ; @file_comments ; This is a really, really cool way to turn keywords into a structure. ; ; @categories ; ; ; @keyword _EXTRA ; Used to pass keywords ; ; @returns ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ; ;- FUNCTION too_cool, _EXTRA=extra ; compile_opt idl2, strictarrsubs ; return,extra end ;+ ; ; @file_comments ; 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. ; ; @categories ; Utilities ; ; @param STRVAL {IN}{REQUIRED} ; String set up as keywords. Keywords require a little special treatment. Such as ; plot,findgen(100),_extra=stringToStructure('title="testing"') ; ; @returns ; This function returns the string as an anonymous structure. If an ; error was found then this function returns a structure with a null field. ; ; @examples ; 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 ; ; @history ; Written by: ; RLK, Ronn Kling Consulting. ; ronn\@rlkling.com ; www.rlkling.com ; May, 1999 ; ; @version ; $Id$ ; ;- FUNCTION string2struct,strVal ; compile_opt idl2, strictarrsubs ; 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