Help on coding time evolution of spectrum

Hi,
I am writing code to display a series of energy spectrum that changes with time. Basically the intensity of the curve decreases at a certain energy value while at other energy value the intensity decreases with time. Since I know how my spectrum are from the data I have, I wrote an equation to fit the spectrum and fixed all the parameters except the intensities at two different energy points. The fitting curve is good. Now I am trying to include a time variable in the equation to get a series of spectrum evolving with time. However keeping time variable in the coding displays 'expected assignment error'. It does not let me put the time in the equation. Since I am learning step by step how to code, any help would be great.
Below is my coding and also I have attached the igor file for clarity.
#pragma rtGlobals=3     // Use modern global access method and strict wave access.
Function MySpectrum(ww)

    WAVE ww    
    //Variable xx                                                                    
                                         
    Variable w1=0, w2=0, w3=0, w4=0, w5=0, w6=0, w7=0, w8=0, i, t=0, qq                  // local variable
    make/O /N=46 xx=1.64+0.04*p                                 //x axis energy values; start:step:end = 1.64:0.04:3.24 for fit
   
// Body code
 
    for(i=0;i<40;i+=1)
     t=1                                                                             //time step
    w1 = exp(0.5*(0.055/0.27)^2-(xx-1.905)/0.27)  
    w2 = erfc(0.707*(0.055/0.27-(xx-1.905)/0.055))
    w3 =  ww[0]*exp(-3.70*i*t)                                                //ww[0]=intensity of first peak which decreases with time
    w4 = 0.5*w3/0.27
    w5 = exp(0.5*(0.1/0.105)^2-(xx-2.19)/0.105)  
    w6 = erfc(0.707*(0.1/0.105-(xx-2.19)/0.1))
    w7 = ww[1]*exp(1-3.70*i*t)                                     // ww[0]/ww[1] = 1.5, where ww[1]=intensity that increases slowly with time
    w8 = 0.5*w7/0.105
   
    qq(i*t) = (w4*w1)*w2+(w8*w5)*w6
     
    endfor
   
    return qq
      Display qq(i*t)


Test_file.pxp (521.9 KB)
One problem is that qq is a variable but you are trying to assign to it as if it were a wave:
qq(i*t) = (w4*w1)*w2+(w8*w5)*w6


Perhaps you meant it to be a wave. Then you need to create it using Make, not Variable.

Another issue which I see in Igor7 but not in Igor 6.37 is that xx is a wave but you are treating it like variable. For example:
w1 = exp(0.5*(0.055/0.27)^2-(xx-1.905)/0.27)


You need to specify which point of xx you want to use in the assignment to the variable. Perhaps xx[i] is what you want.

You have an extraneous statement at the end, after the return statement.
Display qq(i*t)

hrodstein wrote:
One problem is that qq is a variable but you are trying to assign to it as if it were a wave:
qq(i*t) = (w4*w1)*w2+(w8*w5)*w6


Perhaps you meant it to be a wave. Then you need to create it using Make, not Variable.

Another issue which I see in Igor7 but not in Igor 6.37 is that xx is a wave but you are treating it like variable. For example:
w1 = exp(0.5*(0.055/0.27)^2-(xx-1.905)/0.27)


You need to specify which point of xx you want to use in the assignment to the variable. Perhaps xx[i] is what you want.

You have an extraneous statement at the end, after the return statement.
Display qq(i*t)

TRK
Thanks for the suggestion. The return function qq[i*t] is a wave which changes with time. I used (i*t) to display the wave for a particular time. As suggested, I used make command to create an array of 41 points for qq.
xx is a wave which I created using make command and I want every value of xx to subtract a fixed assigned number i.e, 1.905 and 2.19 so I am not sure if I need to write xx[i] but I tried with both.
And I removed the display function at the end but still the problem exists in code compiling
Tika wrote:
hrodstein wrote:
One problem is that qq is a variable but you are trying to assign to it as if it were a wave:
qq(i*t) = (w4*w1)*w2+(w8*w5)*w6


Perhaps you meant it to be a wave. Then you need to create it using Make, not Variable.

Another issue which I see in Igor7 but not in Igor 6.37 is that xx is a wave but you are treating it like variable. For example:
w1 = exp(0.5*(0.055/0.27)^2-(xx-1.905)/0.27)


You need to specify which point of xx you want to use in the assignment to the variable. Perhaps xx[i] is what you want.

You have an extraneous statement at the end, after the return statement.
Display qq(i*t)

TRK
Thanks for the suggestion. The return function qq[i*t] is a wave which changes with time. I used (i*t) to display the wave for a particular time. As suggested, I used make command to create an array of 41 points for qq.
xx is a wave which I created using make command and I want every value of xx to subtract a fixed assigned number i.e, 1.905 and 2.19 so I am not sure if I need to write xx[i] but I tried with both.
And I removed the display function at the end but still the problem exists in code compiling

TRK

Hi
This is a follow up to my previous post. I was able to program how spectrum evolves with time though it did not match perfectly to my data. Hence I want to use the actual population which I have saved in data folder named as peak1 and peak2. Taking help from the igor help, I wrote a code to call the waves peak1 and peak2 in the main function but there occurs compiling error saying unkonwn/appropriate name or symbol. How do we call a wave from the data folder to a user defined function ? I would appreciate any help/comments to resolve this. I have attached the igor file.
Here is the code
#pragma rtGlobals=3     // Use modern global access method and strict wave access.

Function TimeEvolutionSpectrum()    //code for the time evolution of the spectrum

    WAVE qqq
    //variable xx
    WAVE xx
    WAVE w1,w2,w5,w6
    //variable w1, w2,w5,w6
    WAVE w3, w4,w7,w8
                                                                         
    Variable  t,i,j        
    make/O /N=41 xx    
                             
   
// Body code
 
    for(i=0;i<46;i+=1)
    for(j=0;j<41;j+=1)
    xx[j] = 1.64+0.04*j
     t=1
     //DFREF dfr = root:ps_2:peak1
     //DFREF dfr = root:ps_2:peak2
    //Display dfr:peak1  
    String path1 = "root:ps_2:peak1"
    Display $path1
    path1 ="root:ps_2:peak1"
    DFREF dfr = $path1
    String path2 = "root:ps_2:peak2"
    Display $path2
    path2 ="root:ps_2:peak2"
    DFREF dfr = $path2  
    //Display dfr:peak1                                                                          
    make/O /N=41 w1
    make/O /N=41 w2
    make/O /N=46 w3
    make/O /N=46 w4
    make/O /N=41 w5
    make/O /N=41 w6
    make/O /N=46 w7
    make/O /N=46 w8
    w1[j] = exp(0.5*(0.055/0.27)^2-(xx[j]-1.905)/0.27)  
    w2[j] = erfc(0.707*(0.055/0.27-(xx[j]-1.905)/0.055))
    w5[j] = exp(0.5*(0.1/0.105)^2-(xx[j]-2.19)/0.105)  
    w6[j] = erfc(0.707*(0.1/0.105-(xx[j]-2.19)/0.1))
    w3[i] =  910*exp(-0.70*i*t)
    //w4[i] = 0.5*w3[i]/0.27
    w4[i] =  peak1[i]
    w7[i] = 14*exp(1-0.108*i*t )
    //w8[i] = 0.5*w7[i]/0.105
    w8[i] =  peak2[i]
    make/O /N=(41,46) qqq                                        
    //qqq[j][i] = ((0.5*w3[i]/0.27)*(exp(0.5*(0.055/0.27)^2-(xx[j]-1.905)/0.27))*erfc(0.707*(0.055/0.27-(xx[j]-1.905)/0.055)))+((0.5*w7[i]/0.105)*exp(0.5*(0.1/0.105)^2-(xx[j]-2.19)/0.105)*erfc(0.707*(0.1/0.105-(xx[j]-2.19)/0.1)))
    qqq[j][i] = (w4[i]*w1[j])*w2[j]+(w8[i]*w5[j])*w6[j]
     endfor
     endfor
     return w1
     return w2
    //return w3
    return w4
    return w5
    return w6
    //return w7
    return w8
    return qqq
   
END
test file.pxp (535.9 KB)
You should take a look at the programming help file. Execute:

displayhelptopic "User-Defined Functions"

Try to write a smaller and simpler function. Once you can get that to work, build up to the calculation you're trying to achieve.
tony wrote:
You should take a look at the programming help file. Execute:

displayhelptopic "User-Defined Functions"

Try to write a smaller and simpler function. Once you can get that to work, build up to the calculation you're trying to achieve.

TRK
Thanks Tony, I have been looking at data folder references subtopic of of programming help file and had tried my best before posting the problem. Any example on how the wave in a data folder can be applied to a user defined function would be appreciated.
Tika wrote:
tony wrote:
You should take a look at the programming help file. Execute:

displayhelptopic "User-Defined Functions"

Try to write a smaller and simpler function. Once you can get that to work, build up to the calculation you're trying to achieve.

TRK
Thanks Tony, I have been looking at data folder references subtopic of of programming help file and had tried my best before posting the problem. Any example on how the wave in a data folder can be applied to a user defined function would be appreciated.


You can declare a wave in a function like this:

wave wave1=w1

wave1 will be a wave reference in your function for the wave w1 in the current data folder.

displayhelptopic "wave"

you can also pass wave references, variables, etc to the function, but you cannot return the wave because it already exists outside of the function.

execute displayhelptopic "User-Defined Functions" and look at the third example function.

tony wrote:
Tika wrote:
tony wrote:
You should take a look at the programming help file. Execute:

displayhelptopic "User-Defined Functions"

Try to write a smaller and simpler function. Once you can get that to work, build up to the calculation you're trying to achieve.

TRK
Thanks Tony, I have been looking at data folder references subtopic of of programming help file and had tried my best before posting the problem. Any example on how the wave in a data folder can be applied to a user defined function would be appreciated.


You can declare a wave in a function like this:

wave wave1=w1

wave1 will be a wave reference in your function for the wave w1 in the current data folder.

displayhelptopic "wave"

you can also pass wave references, variables, etc to the function, but you cannot return the wave because it already exists outside of the function.

execute displayhelptopic "User-Defined Functions" and look at the third example function.

TRK
Thank you so much Tony ! Works perfectly and looks so simple now. I am still wondering if the data folder references could be used to call a wave in the user defined function.
Tika][quote=tony wrote:

TRK
Thank you so much Tony ! Works perfectly and looks so simple now. I am still wondering if the data folder references could be used to call a wave in the user defined function.


By "call" do you mean to work on a wave in your function? If so, then what Tony showed you was most of the story but you may need to read up on data folders in IgorPro. The basic idea is that if you are trying to reference a wave that is not in the current data folder, you have to specify a full path when declaring the wave reference.

So if your function is working in root: but the wave you want to work on is in e.g. root:folder1 then you would want to make that declaration as follows:

WAVE wave1 = root:folder1:w1

Once you have that reference all set up, you can then code with wave1 without worrying about giving the full path, because IgorPro now knows where to find that specific wave each time you want to use it for something.
Yanick][quote=Tika wrote:
tony wrote:

TRK
Thank you so much Tony ! Works perfectly and looks so simple now. I am still wondering if the data folder references could be used to call a wave in the user defined function.


By "call" do you mean to work on a wave in your function? If so, then what Tony showed you was most of the story but you may need to read up on data folders in IgorPro. The basic idea is that if you are trying to reference a wave that is not in the current data folder, you have to specify a full path when declaring the wave reference.

So if your function is working in root: but the wave you want to work on is in e.g. root:folder1 then you would want to make that declaration as follows:

WAVE wave1 = root:folder1:w1

Once you have that reference all set up, you can then code with wave1 without worrying about giving the full path, because IgorPro now knows where to find that specific wave each time you want to use it for something.

TRK
Thanks Yanick! This is exactly what I am doing. Since the subtopic 'data folder references' under topic 'programming' in help menu also talks about calling wave, I was just curious how to apply this in a user defined function.