error: expected wave name----help

Hello,

I wrote a procedure to deal with my experiment data.
When running it, the error message "expected wave name" popped up.

I attached the file and error message below.

Could anyone take a look and help me out.

Thanks,
Felix

-----------------------------------
#pragma rtGlobals=3     // Use modern global access method and strict wave access.

function experiment20151116_RBS_Chi_Cal(r1,c1,c2,c3,c4,c5)
wave r1, c1, c2, c3, c4, c5

make /O/N=5 chi_all


string thewave
variable index


//---------loop-----------------
for(index=1; index<6;index+=1)
thewave="c"+num2str(index)
duplicate $thewave, w          //error: expected wave name
chi_all[index-1]=RBS_Chi_Cal(r1,w,670, 720)//call "RBS_Chi_Cal" function
endfor
//---------loop------------------

edit chi_all
end
procedure.ipf (3.6 KB)
#pragma rtGlobals=3     // Use modern global access method and strict wave access.
 
function experiment20151116_RBS_Chi_Cal(r1,c1,c2,c3,c4,c5)
wave r1, c1, c2, c3, c4, c5
 
make /O/N=5 chi_all
 
 
string thewave
variable index
 
 
//---------loop-----------------
for(index=1; index<6;index+=1)
thewave="c"+num2str(index)
WAVE wr=$thewave
duplicate/O wr, w
chi_all[index-1]=RBS_Chi_Cal(r1,w,670, 720)//call "RBS_Chi_Cal" function
endfor
//---------loop------------------
 
edit chi_all
end

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
Hi Jim,

Thanks for promote reply. I tried again. There's still something not right.
Error message shows:"while executing duplicate, the following error occurred: expected wave name."



JimProuty wrote:
#pragma rtGlobals=3     // Use modern global access method and strict wave access.
 
function experiment20151116_RBS_Chi_Cal(r1,c1,c2,c3,c4,c5)
wave r1, c1, c2, c3, c4, c5
 
make /O/N=5 chi_all
 
 
string thewave
variable index
 
 
//---------loop-----------------
for(index=1; index<6;index+=1)
thewave="c"+num2str(index)
WAVE wr=$thewave
duplicate/O wr, w
chi_all[index-1]=RBS_Chi_Cal(r1,w,670, 720)//call "RBS_Chi_Cal" function
endfor
//---------loop------------------
 
edit chi_all
end

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
Ah, I see: you're passiing wave parameters using local names c1 through c5 and trying to use $str to refer to them.

That's not really something that WAVE w=$str is designed to do.
You can assign WAVE references, though, so something like:

WAVE cw
switch(index)
case 1:
cw=c1
break
case 2:
cw=c2
break
case 3:
cw=c3
break
case 4:
cw=c4
break
case 5
cw=c5
break
endswitch
//Duplicate/O cw/w why?
chi_all[index-1]= RGS_Chi_Cal(r1,cw,670,720)
...

may be what you need to do.


--Jim Prouty
Software Engineer, WaveMetrics, Inc.
How about passing a wave of wave references?
Have a look at the /WAVE options:
DisplayHelpTopic "Wave Reference Waves"
HJ

PS - Bonus: You are "not" limited by the amount of waves to pass.
Thanks. I tried the code below. It does do the magic.
But I am still wondering if there's some way that I don't need to assign the value to "wave reference wave" value one by one.
5 items is fine in this case, but 100 items would kill me.

#pragma rtGlobals=3     // Use modern global access method and strict wave access.

function experiment20151116_RBS_Chi_Cal(r1,c1,c2,c3,c4,c5)
wave r1, c1, c2, c3, c4, c5

make /wave/o wr
wr[0]=c1;wr[1]=c2;wr[2]=c3;wr[3]=c4;wr[4]=c5// Is there any alternative way I could not have to  assign the value one by one?
make /O/N=5 chi_all



variable index

//--------loop-----------
for (index=0;index<5;index+=1)
chi_all[index]=RBS_Chi_Cal(r1,wr[index],670, 720)//call "RBS_Chi_Cal" function
endfor
//--------loop-----------

print chi_all
end




HJDrescher wrote:
How about passing a wave of wave references?
Have a look at the /WAVE options:
DisplayHelpTopic "Wave Reference Waves"
HJ

PS - Bonus: You are "not" limited by the amount of waves to pass.
shuiye wrote:

Thanks. I tried the code below. It does do the magic.
But I am still wondering if there's some way that I don't need to assign the value to "wave reference wave" value one by one.
5 items is fine in this case, but 100 items would kill me.


The only way I see that this works is when c1 ... cN are waves that are only 1 point long or contain exactly the same value. Otherwise, it is entirely confusing. Please tell us what c1 ... cN really are. Are they waves that have only 1 point in them or waves that have the same value in them?

Also, please tell us what the function RBS_Chi_Calc(...) takes as input. As near as I can tell, it must take a wave and three variables.

The best I can guess is that you probably want something like this ...

Function MyExperimentSetup(nexp)
    variable nexp

    … do what is needed to create r1 and cwave from your data …
    … I am guessing here

    make/N=(nexp) cwave

    … whatever is needed to do this next step is left as an exercise for the reader

    cwave[0] = c0
    cwave[1] = c1
    …

    … do the calculations

    make/O/N=(nexp) chi_all
   
    chi_all = RBS_Chi_Calc(r1,cwave[p],670,720)
    edit chi_all
    return 0
end


--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
The basic idea would be to pass the references as follows
function experiment20151116_RBS_Chi_Cal(r1,c_wave)
wave r1
wave /WAVE c_wave //  <<----------------
for (i=0;i<numpnts(c_wave);i+=1)
WAVE process_c= c_wave[i]  //  <<----------------
...
endfor

HJ