;------------------------------------------------------------- ;+ ; NAME: ; EQV2 ; PURPOSE: ; Interactively plot a function on current plot. ; CATEGORY: ; CALLING SEQUENCE: ; eqv2, file ; INPUTS: ; file = equation file. in ; KEYWORD PARAMETERS: ; Keywords: ; COLOR=clr Plot color (def=!p.color). ; TOP=top Returns widget ID of top level base. ; Use widget_control to retrieve or store info structure. ; OK=wid Given ID of widget to notify when OK button pressed. ; If not given no OK button is displayed. ; WID_OK=wid Widget ID of the OK button. ; Can use to set /input_focus. ; GROUP_LEADER=grp Set group leader. ; OUTPUTS: ; COMMON BLOCKS: ; eqv2_help_com ; eqv2_help_com ; NOTES: ; Note: The QUIT button allows burning in the final curve and lists its ; values. The LIST button lists the current curve parameters. ; ; Equation file format: This file defines the equation, the x range ; and range of each adjustable parameter. The file is a text file with ; certain tags. Null and comment lines (* in first column) are allowed. ; The tags are shown by an example: ; eq: y = a + b*x + c*x^2 ; title: Parabola ; xrange: -10 10 ; n_points: 100 ; 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, 1998 Feb 24 ; R. Sterner, 1998 Apr 1 --- Added /NO_BLOCK to xmanager. ; R. Sterner, 1998 May 12 --- Added plot color. Also added TOP=top. ; R. Sterner, 1998 May 13 --- Added OK button to signal other program. ; Also GROUP_LEADER. ; R. Sterner, 1998 May 14 --- Added LOCK=lck and UNLOCK=ulck to ; eqv2_set_val and eqv2_get_val. Locks parameters. ; R. Sterner, 1998 Oct 27 --- Fixed bug added by the plot color addition. ; ; Copyright (C) 1998, 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 ; ; eqv2_print = Print plot and list settings. ; eqv2_plot = Plot x,y on display. ; eqv2_sp2v = Function to convert slider position to value. ; eqv2_sv2p = Function to convert slider value to position. ; eqv2_show_win = Show plot window. For external use. ; eqv2_get_val = Retrieve parameter values. For external use. ; eqv2_set_val = Set parameter values. For external use. ; eqv2_compile = Equation file parser ; eqv2_event = Event handler ; eqv2 = Main Equation viewer version II routine ; ;------------------------------------------------------------- ;=============================================================== ; eqv2_print = Print plot and list settings. ;=============================================================== pro eqv2_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 ;=============================================================== ; eqv2_plot = Plot x,y on display. ;=============================================================== pro eqv2_plot, _d, erase=erase, burn=burn wset, _d.dsave.window ; Set to plot window. !x = _d.xsave !y = _d.ysave !p = _d.psave ;------- Erase last plot first --------------- if _d.flag eq 1 then begin device, set_graph=6 ; XOR mode. oplot, *_d.x_ptr, *_d.y_ptr, color=_d.color device, set_graph=3 ; COPY mode (normal). if keyword_set(erase) then return if keyword_set(burn) then begin oplot, *_d.x_ptr, *_d.y_ptr, color=_d.color return endif endif ;------- Get Independent var range ---------- widget_control, _d.x1, get_val=_x1 & _x1 = _x1(0) _err = execute('_x1='+_x1) widget_control, _d.x2, get_val=_x2 & _x2 = _x2(0) _err = execute('_x2='+_x2) ;------- Get number of points ------ widget_control, _d.n, get_val=_n & _n = _n(0) if _n eq '' then begin _n = '100' widget_control, _d.n, set_val=_n endif ;------ Get x scale factor --------- ;--- Applied after calculation but before plotting --- widget_control, _d.xs, get_val=_xs & _xs = _xs(0) if _xs eq 0. then _xs=1.0 ; Avoid 0 case. ;----- Generate Independent var array ----------- if _d.var eq 'X' then begin ; Function of X. x = maken(_x1, _x2, _n) endif else begin ; Function of T. t = maken(_x1, _x2, _n) endelse ;------- 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 ;------ Compute Y(X) or X(T) & Y(T) -------------------- _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 equation text',$ ' the name of the independent variable.',$ '2. Do retall.','3. Do xmanager.','4. Press the OK button below.'] return endif ;---------------------------------------------------------- ; At this point the independent var array has been set up and the ; equation has been executed, so X and Y now both exist. ;---------------------------------------------------------- ;--------- Apply x plot scale factor (usually 1) ------- if _xs ne 1. then x=x*_xs ;--------- Plot equation ------------- device, set_graph=6 ; XOR mode. oplot, x, y, color=_d.color device, set_graph=3 ; COPY mode (normal). ptr_free, _d.x_ptr, _d.y_ptr ; Free old pointers. _d.x_ptr = ptr_new(x) ; Save X array. _d.y_ptr = ptr_new(y) ; Save Y array. _d.flag = 1 ; Set plot flag. return end ;=============================================================== ; eqv2_sp2v = Convert slider position to value. ;=============================================================== function eqv2_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 ;=============================================================== ; eqv2_sv2p = Convert slider value to position. ;=============================================================== function eqv2_sv2p, v, smax, pmin, pmax p = fix(.5+float(smax)*(v-pmin)/(pmax-pmin)) return, p>0