[proFit-list] Dynamically Adding Variables
Kurt Sutter
kurt at quansoft.com
Fri Aug 8 10:14:05 CDT 2014
Dear Frederic
Please apologise the belated reply, I was on holidays.
Anyway, you can also do that in Python using *args parameters, which are basically placeholder for a variable number of arguments. In Python, the same thing would look as follows:
## function MyPoly
## input 0, constant, 'deg'
## input 1, inactive, 'a0'
def MyPoly_check(pNumber, *a):
if pNumber == 1: # if a[0] has changed
if a[0] < 1 or a[0] > 100:
return 2 # reject parameter change
pf.GetFunctionObject(function = '').nrParams = a[0] + 1
for i in range(0, int(a[0])+ 1):
pf.GetParameterObject(parameter = i+1).name = 'a' + str(i)
return 0 # update parameter window
return 1 # return 1 if the parameter is fine
def MyPoly(x, deg, *a):
y = 0
for i in range(0, int(deg)):
y = x * y + a[i]
return y
Hope this helps
Kurt Sutter
QuantumSoft
On 14 Jul 2014, at 9:09, BOURDAROT Frederic 136372 <frederic.bourdarot at cea.fr> wrote:
> Dear all,
> I wanted to do the same thing in python but I do not manage. The function check in python needs as parameters the 'ai' parameters, then it becomes difficult to make it dynamical? Do you have a solution or an exemple for this?
> Best regards
> Frederic Bourdarot
>
> Andrew
>
> Yes, you can do that. Basically, you call SetFunctionProperties for
> nrParameters in Check. Here is an example, which basically sets the
> number of parameters to the value you enter in a[1].
>
>
> function MyPoly;
>
> var i;
>
> function Check;
> begin
> if pNumber = 1 then // if a[1] has changed
> if (a[1] < 1) or (a[1] > 100) then
> Check := bad
> else
> begin
> SetFunctionProperties(function '', nrParams a[1]+1);
> Check := update; // redraw the parameter window
> end;
> end;
>
> begin
> y := 0;
> for i := 1 to a[1] do
> y := x*y + a[i+1];
> end;
>
>
> You can also set the names of the parameters using
> SetParameterProperties,
>
> Good luck
>
> Kurt
>
> Frédéric Bourdarot
> CEA-Grenoble
> INAC/SPSMS/MDN-C5-410
> 17, rue des martyrs
> 38054 GRENOBLE CEDEX 9
> France
> Tel. +33 438784126
> frederic.bourdarot at cea.fr
>
>
>
>
> _______________________________________________
> proFit-list mailing list
> proFit-list at quantum-soft.com
> http://quantum-soft.com/mailman/listinfo/profit-list_quantum-soft.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://quantum-soft.com/pipermail/profit-list_quantum-soft.com/attachments/20140808/10cb311f/attachment.html>
More information about the proFit-list
mailing list