How could I call a function in a macro on a wave defined as a string variable
Hi everybody,
I'm trying to write a macro to create some automatic fitting of some waves using some specific functions (not predefined ones). More specific, I want to fit 7 waves by "copying" the fitting instructions and by using a coefficient wave that I generated by fitting previously one wave (no #1/8). Nevertheless, the steps consider defining some waves based on some functions, step in which I receive the error "got "BackgroundDublet" instead of a string variable or string function name."
The error occurs starting with the command:
$Wave_BCK=$WaveC[18]+ $WaveC[19]*$WaveX + BackgroundDublet($WaveC[20], $WaveC[12], $WaveC[6], $WaveC[21], $WaveX)+BackgroundDublet($WaveC[22], $WaveC[8], $WaveC[5], $WaveC[23], $WaveX)
Macro MultipleFitSeries(NameSet)
String WaveX, WaveY, NameSet, WaveC, WaveC_before, Wave_BCK, Wave_W, Wave_c1, Wave_c2, Wave_c3, Wave_c4, Wave_c5, Wave_f, Wavesv
Variable i, imax
i=2;
imax=8
// NameSet = "1"
do
WaveX="x_"+NameSet+num2str(i)
WaveY="y_"+NameSet+num2str(i)
Wave_BCK="y_"+NameSet+num2str(i)+"_bck"
Wave_W="y_"+NameSet+num2str(i)+"_w"
Wave_c1="y_"+NameSet+num2str(i)+"_c1"
Wave_c2="y_"+NameSet+num2str(i)+"_c2"
Wave_c3="y_"+NameSet+num2str(i)+"_c3"
Wave_c4="y_"+NameSet+num2str(i)+"_c4"
Wave_c5="y_"+NameSet+num2str(i)+"_c5"
Wave_f="y_"+NameSet+num2str(i)+"_f"
Wavesv="Wavesv"
WaveC="c_"+NameSet+num2str(i)
WaveC_before="c_"+NameSet+num2str(i-1)
Make/O/N=(DimSize($WaveX, 0)) $WaveX
Make/O/N=(DimSize($WaveX, 0)) $WaveY
Make/O/N=(DimSize($WaveX, 0)) $Wave_Bck
Make/O/N=(DimSize($WaveX, 0)) $Wave_W
Make/O/N=(DimSize($WaveX, 0)) $Wave_c1
Make/O/N=(DimSize($WaveX, 0)) $Wave_c2
Make/O/N=(DimSize($WaveX, 0)) $Wave_c3
Make/O/N=(DimSize($WaveX, 0)) $Wave_c4
Make/O/N=(DimSize($WaveX, 0)) $Wave_c5
Make/O/N=(DimSize($WaveX, 0)) $Wave_f
//Make/O/N=(DimSize($WaveX, 0)) Wavesv
Make/O/N=(DimSize($WaveC_before, 0)) $WaveC
$WaveC = $WaveC_before
coefi = $WaveC
$Wave_BCK=$WaveC[18]+ $WaveC[19]*$WaveX + BackgroundDublet($WaveC[20], $WaveC[12], $WaveC[6], $WaveC[21], $WaveX)+BackgroundDublet($WaveC[22], $WaveC[8], $WaveC[5], $WaveC[23], $WaveX)
$Wave_c1=$Wave_BCK + DoubletVoigt2(abs($WaveC[0]), abs($WaveC[1]), abs($WaveC[4]), abs($WaveC[5]), abs($WaveC[7]), abs($WaveC[8]), abs($WaveC[9]), 0, $WaveX)
$Wave_c2=$Wave_BCK + DoubletVoigt2(abs($WaveC[0]), abs($WaveC[1]), abs($WaveC[4]), abs($WaveC[5]), abs($WaveC[7]), abs($WaveC[10]), abs($WaveC[11]), 0, $WaveX)
$Wave_c3=$Wave_BCK + DoubletVoigt2(abs($WaveC[2]), abs($WaveC[3]), abs($WaveC[4]), abs($WaveC[6]), abs($WaveC[7]), abs($WaveC[12]), abs($WaveC[13]), 0, $WaveX)
$Wave_c4=$Wave_BCK + DoubletVoigt2(abs($WaveC[2]), abs($WaveC[3]), abs($WaveC[4]), abs($WaveC[6]), abs($WaveC[7]), abs($WaveC[14]), abs($WaveC[15]), 0, $WaveX)
$Wave_c5=$Wave_BCK + DoubletVoigt2(abs($WaveC[0]), abs($WaveC[1]), abs($WaveC[4]), abs($WaveC[5]), abs($WaveC[7]), abs($WaveC[16]), abs($WaveC[17]), 0, $WaveX)
$Wave_f=FiveDoubletsWithBCK($WaveC, $WaveX)
Display $Wave_BCK $WaveY $Wave_c1 $Wave_c2 $Wave_c3 $Wave_c4 $Wave_c5 $Wave_f vs $WaveX
ModifyGraph rgb($Wave_c1)=(19675,39321,1),rgb($Wave_c2)=(1,12815,52428),rgb($Wave_c3)=(52428,1,41942),rgb($Wave_c4)=(39321,13101,1),rgb($Wave_c5)=(16385,16388,65535),rgb($Wave_f)=(0,0,0)
i+=1
while(i<=imax)
End Macro
[Click and drag to move]
I tried to find a solution in previous topics but unfortunately I didn't reach any conclusion.
I hope my problem is not (very) redundant on the forum and that I could find a solution.
Thank you!
The correction is likely to replace the $Wave designations on the left side of an = sign with actual waves.
wwaveC = $WaveC_before
// or better
Duplicate/O $WaveC_before, wwaveC
A few other pointers ...
* Prefer to create functions not macros.
* You use DimSize($WaveX,0) so often that you should instead create it as a variable npts = DimSize($WaveX,0)
* Replace the do-while loop with a for(ic=ico;ic<imax;i+=1) ... endfor loop
* The multiple Make/O/N=(npts) statements can be one Make/O/N=(npts) $WaveX, $WaveY, ...
* After the make statement, use explicit declaration statements wave wwaveX = $WaveX to remove all implicit $WaveX syntax in later coding (the same for all other letters)
August 20, 2024 at 06:57 am - Permalink
Thank you very much! I will implement the suggestions and I hope to come up with a solution!
August 20, 2024 at 07:03 am - Permalink
After a brief look, I think what you are trying to do here could be done much more conveniently and with much greater flexibility by using the automatic batch fitting functionality of the Multipeak Fit package. If you are interested, do the following: Within Igor go to Analysis => Packages => Multipeak Fitting. Then press the Help button in the appearing panel. In the help, you will find 'Automatic Multipeak Batch Fitting' in the table of contents. Have a look and see if this might be something for your project.
August 20, 2024 at 08:07 am - Permalink