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