1

I wrote a procedure for making a wave out of another with some calculations. The procedure look like this:

Function elipticity_calculation(rotation, elipticity, energy, calculated_elipticity)
    Wave rotation, elipticity, energy
    String calculated_elipticity

    Wave lambda
    lambda = 1240/energy
    Wave KK
    KK = lambda*lambda
    Wave w
    w = 1 - 93.33/KK
    Wave Q
    Q = 1/(w*w*lambda*sqrt(1+135/w))
    Wave delta
    delta = (Q*1.6*100000+2)*pi/180

    Duplicate/O rotation, $calculated_elipticity
    WAVE wOut = $calculated_elipticity
    wOut = (elipticity-rotation*cos(delta)/sin(delta))
End

However, when I put the function in the command window (see below), it gives me an syntax error:

expected wave name.

elipticity_calculation(wave1, wave2, wave3, "calculated_elipticity")

Where am I wrong?

Thanks

Edit:

I also tried this:

Function elipticity_calculation(rotation, elipticity, energy,     calculated_elipticity)
    Wave rotation, elipticity, energy
    String calculated_elipticity

    Make $"lambda"/WAVE=lambda;
    lambda = 1240/energy
    Make $"KK"/WAVE=KK;
    KK = lambda*lambda
    Make $"w"/WAVE=w;
    w = 1 - 93.0665/KK

    Make $"Q"/WAVE=Q;
    Q = 1/(w*w*lambda*sqrt(1+136.24/w))
    Make $"delta"/WAVE=delta;
    delta = (Q*1.69508759865*100000+2.884488929)*pi/180

    Duplicate/O rotation, $calculated_elipticity
   WAVE wOut  = $calculated_elipticity
   wOut = (elipticity-rotation*cos(delta))/sin(delta)
End

However, this code create new waves for every calculated point and also create wave wOut empty.

edit:

I tried this. However. It is not working:

Function elipticity_calculation(rotation, elipticity, energy, calculated_elipticity)
Wave rotation, elipticity, energy
String calculated_elipticity

Make/FREE lambda 
lambda = 1240/energy
Make/FREE KK
KK = lambda*lambda
Make/FREE w
w = 1 - 93.0665/KK
Make/FREE kve
kve = 1/(w*w*lambda*sqrt(1+136.24/w))
Make/FREE delta
delta = (kve*1.69508759865*100000+2.884488929)*pi/180

Duplicate/O rotation, $calculated_elipticity
Make wOut = (elipticity-rotation*cos(delta))/sin(delta)

End

Is it possible to rewrite a wave after doing some calculation on it? Like in Excel?

Hannsek
  • 13
  • 4

2 Answers2

0

Do the waves lambda/KK/w/Q/delta exist in the current datafolder?

The passed waves wave1/wave2/wave3 need to exist as well in the current data folder.

You can turn on debugging and debug on error so that Igor Pro pops into the debugger when an error happens.

t-b
  • 152
  • 1
  • 7
  • the waves lambda/KK/w/Q/delta do not exists. These waves are suppose to be "constants" made out of wave3 (energy) for every point. I don't need the waves lambdaKK/w/Q/delta to exist outside of the script. It is only for calculation of wOut. – Hannsek Jul 24 '20 at 13:30
  • The `WAVE` statement does not create a wave. The `MAKE` operation does that. You can pass `/FREE` to create free waves which will not be present in the DataBrowser. The wave creation then reads something like `Make/FREE lambda`, you also don't need a trailing semicolon. – t-b Jul 25 '20 at 16:26
0

I solved it this way below:

Function elipticity_calculation(rotation, elipticity, energy, calculated_elipticity)

Wave rotation, elipticity, energy
String calculated_elipticity

Duplicate/O elipticity, $calculated_elipticity
Wave calc_elipticity = $calculated_elipticity

Duplicate/FREE energy, lambda
lambda = ...
Duplicate/FREE energy, KK
KK = ...
Duplicate/FREE energy, w
w = ...
Duplicate/FREE energy, Q_1
Q_1 = ...
Duplicate/FREE energy, delta
delta = ...


calc_elipticity = ((elipticity-rotation*cos(delta))/sin(delta))

End
Hannsek
  • 13
  • 4