;------------------------------------------------------------- ;+ ; NAME: ; EQV3 ; PURPOSE: ; Execute IDL code using interactively varied parameters. ; CATEGORY: ; CALLING SEQUENCE: ; eqv3, file ; INPUTS: ; file = equation file. in ; Instead of file name the contents of the file may be ; given in a text array (same format). ; KEYWORD PARAMETERS: ; Keywords: ; P1=var1, P2=var2, ... P5=var5 Up to 5 variables. ; may be passed into the program using these keywords. ; May reference p1, p2, ... in the IDL code to execute. ; /WAIT means wait until the routine is exited instead ; returning right after startup. ; PARVALS=pv Structure with parameter names and values. ; Must be used with /WAIT or pv will be undefined. ; EXITCODE=excd 0=normal, 1=cancel. Must use with /WAIT. ; RES=res Returned widget ID of an unused top level ; base that will on exit from EQV3 contain a structure ; with parameter names and final values. ; widget_control,res,get_uval=s,/dest ; s.name and s.val are arrays of names and values. ; TOP=top Returns widget ID of top level base. ; Use widget_control to retrieve or store info structure. ; OK=wid ID of widget to notify when OK button pressed. ; If not given no OK button is displayed. ; Useful to allow a higher level widget routine to call ; EQV3. The OK button then sends an event to the higher ; level widget which can then destroy the eqv3 widget. ; WID_OK=wid Returned widget ID of the OK button. ; Can use to set /input_focus. ; GROUP_LEADER=grp Set group leader. ; XOFFSET=xoff, YOFFSET=yoff Widget position. ; ; OUTPUTS: ; COMMON BLOCKS: ; eqv3_var_com ; eqv3_var_com ; eqv3_help_com ; eqv3_var_com ; eqv3_help_com ; NOTES: ; Notes: Use the Help button for more details. ; Equation file format: This text file defines the IDL code, ; and range of each adjustable parameter. ; Null and comment lines (* in first column) are allowed. ; The tags are shown by an example: ; title: Parabola ; eq: x=maken(-10,10,100) & plot,a + b*x + c*x^2 ; par: a -50 50 0 ; par: b -50 50 0 ; par: c -10 10 1 ; ; The parameter tags are followed by 4 items: Parameter name (as in the ; equation), min value, max value, initial value. An optional 5th item ; may be the word int to force an integer value (for flags or harmonics). ; MODIFICATION HISTORY: ; R. Sterner, 2000 May 11 --- From EQV2. ; R. Sterner, 2000 Aug 21 --- Added XOFFSET, YOFFSET. ; R. Sterner, 2001 Jun 19 --- Upgraded snapshot. ; R. Sterner, 2001 Jun 20 --- Added optional parameter units. ; ; Copyright (C) 2000, Johns Hopkins University/Applied Physics Laboratory ; This software may be used, copied, or redistributed as long as it is not ; sold and this copyright notice is reproduced on each copy made. This ; routine is provided as is without any express or implied warranties ; whatsoever. Other limitations apply as described in the file disclaimer.txt. ;- ;------------------------------------------------------------- ;------------------------------------------------------------- ; Index of routines ; ; eqv3_print = Print plot and list settings. ; eqv3_plot = Execute equation text. ; eqv3_sp2v = Function to convert slider position to value. ; eqv3_sv2p = Function to convert slider value to position. ; eqv3_show_win = Show plot window. For external use. ; eqv3_get_val = Retrieve parameter values. For external use. ; eqv3_set_val = Set parameter values. For external use. ; eqv3_compile = Equation file parser ; eqv3_quit = Execute any exit code ; eqv3_grabpar = Grab parameters and values ; eqv3_event = Event handler ; eqv3 = Main Equation viewer version II routine ; ;------------------------------------------------------------- ;=============================================================== ; eqv3_print = Print plot and list settings. ;=============================================================== pro eqv3_print, pnum, d wset, d.dsave.window ; Select plot window. !x = d.xsave !y = d.ysave !p = d.psave xmess,' Printing current display . . .',/nowait,wid=wid ;------- Print image ------------ a = tvrd() ; Grab screen image. tvlct,r,g,b,/get ; Grab current color table. psinit, pnum, /auto, cflag=flag ; Set to specified printer. ;------- Deal with BW ----------- if flag eq 0 then begin ; Color flag not set so BW. print,' Converting image to Black and White . . .' lum = ROUND(.3 * r + .59 * g + .11 * b) < 255 ; Image brightness. a = lum(a) ; To B&W. if total(a lt 128)/total(a ge 128) gt 5. then begin bell if xyesno('Reverse brightness for printout?') eq 'Y' then $ a = 255-a endif endif tvlct,r,g,b ; Load color table. psimg, a ; Display image. ;------- List equation and settings --------- widget_control, d.equat, get_val=equat ; Get equation. equat = strtrim(equat(0),2) n = n_elements(d.pname) ; List parameters. txt = strarr(n) for i=0,n-1 do txt(i)=strtrim(d.pname(i),2)+' = '+ $ strtrim(d.pval(i),2) txtarr = ['Current parameter values for',equat,' ',txt] xprint,/init,!x.window(0),-.1,dy=1.5,/norm,chars=1.2 ; Set xprint. for i=0,n_elements(txtarr)-1 do xprint,txtarr(i) ; Print. psterm ; Plot all done. widget_control, wid,/ dest ; Kill message widget. return end ;=============================================================== ; eqv3_plot = Execute equation text. ;=============================================================== pro eqv3_plot, _d common eqv3_var_com, p1, p2, p3, p4, p5 wset, _d.dsave.window ; Set to plot window. !x = _d.xsave !y = _d.ysave !p = _d.psave ;------- Read equation ------------- widget_control, _d.equat, get_val=_equat _equat = _equat(0) ;----- Set parameters to their values ------ for _i = 0, n_elements(_d.pname)-1 do begin _t = _d.pname(_i)+'='+string(_d.pval(_i)) _err = execute(_t) endfor ;----- Set flags to their values ------ if _d.flagnam(0) ne '' then begin for _i = 0, n_elements(_d.flagnam)-1 do begin _t = _d.flagnam(_i)+'='+string(_d.flagset(_i)) _err = execute(_t) endfor endif ;------ Execute code -------------------- _err = execute(_equat) if _err ne 1 then begin xhelp,exit='OK',['Error executing:',_equat,!err_string,$ ' ','Do the following to recover:',$ '1. Correct any errors in the executable text',$ ' the name of the independent variable.',$ '2. Do retall.','3. Do xmanager.','4. Press the OK button below.'] return endif return end ;=============================================================== ; eqv3_sp2v = Convert slider position to value. ;=============================================================== function eqv3_sp2v, p, smax, pmin, pmax, int=int if keyword_set(int) then begin return, fix((p/float(smax))*(pmax-pmin) + pmin) endif else begin return, (p/float(smax))*(pmax-pmin) + pmin endelse end ;=============================================================== ; eqv3_sv2p = Convert slider value to position. ;=============================================================== function eqv3_sv2p, v, smax, pmin, pmax p = fix(.5+float(smax)*(v-pmin)/(pmax-pmin)) return, p>0