PRO Every_Function

;+
; NAME
; 	 Every_Function
; PURPOSE
;	Computes operations from the type
;		y = a*f(b*y^c + d) + e*g(h*x^i + j) + k
;	f and g are interactively entered and represent
;	a one-argument function programmed in WAVE.
;	y is redefined and x is the x axis values.
;	The user introduces on the keyboard
; 	the constants a, b, c, d,e ,h, i,j and k. This procedure
;	is a part of the mdisp analyser.
;	The operation is performed only on selected plots
; CATEGORY:
;	1D
; CALLING SEQUENCE:
;	Every_Function
; COMMON BLOCK:
;	EveryRetr: for intern use only
; SIDE EFFECTS:
;	The Selectioner of mdisp is used, and a new plot is
;	created.
; RESTRICTION:
;	To use ONLY together with the mdisp selectioner.
; -
; MODIFICATION HISTORY
;	Created: June 91, A.Csillaghy

COMMON EveryRetr, everyNr

IF N_Elements(everyNr) EQ 0 THEN everyNr= 0B
nbSel = N_Selected()

a = '' & b = '' & c = '' & d = '' & e = '' & f = '' & g = '' &  h = '' 
i = '' & j = '' & k = '' 

Clear_Screen
PTo,5,5,'Function a*f(b*y^c + d) + e*g(h*x^i + j) + k'
Print,' '
Print,' 1. Functions: '
Read,'          Insert the function f: ', f
Read,'          Insert the function g: ', g
Print,' 2. Constants: '
Read_Test, '         Insert a ',1.0,a
Read_Test,'          Insert b ',1.0, b
Read_Test,'          Insert c ',1.0, c
Read_Test,'          Insert d ',0.0, d
Read_Test,'          Insert e ',0.0, e
Read_Test,'          Insert h ',1.0,h
Read_Test,'          Insert i ',1.0,i
Read_Test,'          Insert j ',0.0,j
Read_Test,'          Insert k ',0.0, k
  
instruction = 'newY = '+ a+'*'+f+'('+b+'*y^'+ c +'+'+ d+ $
	') + '+e+'*'+g+'('+h+'*x^'+i+' + '+j+') +'+ k

FOR i = 1,nbSel DO BEGIN
  name = Selection(i)
  Load_Plot, name, x,y,q
  IF NOT Execute(instruction) THEN BEGIN
    Print,'The functions are not known ... '
    Wait,3
    RETURN
  ENDIF
  newName = name + '_ot'+StrTrim(everyNr,2)
  everyNr = everyNr +1 

  Store_Plot, newName, x,newY
  Remove_Sel,name
  Insert_Sel, newName
ENDFOR

END