Batch Process. Use one wave to perform mathematical operation on the rest in data folder.

Hello!

So I'm sure there is a way to do this but I'm not sure where in the manual to look.
I want to use one wave to divide all other waves in the data folder and produce a new wave. This is what I've got so far.

Function RemoveBavkgroundFTIR()
    Wave w          //define data wave
    Variable datafolder
    String/G list = Wavelist("*",";","") // creates a list of all waves in current "datafolder" separated by a ;
           
           
    Variable/G numItems = ItemsInList(list), i // counts how and indices the items(graph) broken by ;
    for (i = 0; i<numItems; i+=1) // starts a loop to go through each wave data
        String/G data   //creates a string of ith data
       
        data = StringFromList(i,list,";") //goes through list and extracts ith string
        wave w=$data

    String newName = NameOfWave(w) + "_AuRemove"    // gives output wave new name
    Duplicate/O w, $newName
    Wave wminAu = $newname
        wnminAu= (w/refWave)
    endfor
End


So in my last line of code I want variable refwave to be a wave that I can select from a list of IGOR waves. I feel like I need to define a new variable and somehow open up a dialogue to select it. Or should I just write in the name of the wave that I want to use? I hope what I'm trying to do makes sense! You guys of IGOR are usually great at helping out newby programmers like me out!!

Thanks in advance,
N
Let's see:
You neither need the first "wave" statement nor the "datafolder variable" (which should be a datafolder reference 'DFRef' or at least a string btw.)
I assume you use the /G flag for the strings and variables for some debugging after the function has executed (making them "Global").
It is sufficient if you declare the "data" and "newName" strings outside the loop. Pure assignments inside the loop are much faster (remember this for later:-) )
You do not need NameOfWave since it is stored already in "data" and you can solely assign it via NewName=Data+ "_AuR" (note: I shortened the name; probably you want to do further steps and add more suffixes. In order to avoid 'liberal names', i.e., to stay below 31 characters, keep these extensions short -- my colleagues had this habit; If you have more experience you probably want to sort your data treatment steps in 'data folders').
The overwrite flag "/O" is only necessary is you run your code again.
The last line of code seems to contain a typo: "wminAu" vs. "wnminAu".
A possible way would be to pass the reference wave as a function argument
Function RemoveBavkgroundFTIR(refWave)
Wave refWave

or by a string and usage the '$' operator.
You probably want to check whether the processed wave is identical to the reference wave and exclude the division it his case (or it is always located in a different data folder).
HJ
PS: Buzzwords, worth to be read in the manual, are given in single quotes.

PPS: I was wondering if division is the right operation? You mention remove, which I would correlate with subtraction, while division goes together normalization.
Thanks HJ!

That was really helpful. Those tips are well noted and will be remembered!

Using the function argument to pass waves like that solved my problem very nicely. However, I left the "String newName" where it was in the code otherwise it wouldn't produce a new named wave to operate on... I think. Anyway the way I have it below works.

Anyway here is the completed code in case an other new IGOR enthusiasts stumble upon similar problems!
Function RemoveBackgroundFTIRbulk(refWave)
    Wave refWave
    String/G list = Wavelist("*",";","") // creates a list of all waves in current "datafolder" separated by a ;
    String/G data   //creates a string of ith data
   
 
    Variable/G numItems = ItemsInList(list), i // counts how and indices the items(graph) broken by ;
    for (i = 0; i<numItems; i+=1) // starts a loop to go through each wave data
       
        data = StringFromList(i,list,";") //goes through list and extracts ith string
        wave w=$data
    String newName = data + "_AuR"  // gives output wave new name
    Duplicate/O w, $newName
    Wave wminAu = $newname
        wminAu= (w/refWave)
    endfor
   
End


Function RemoveBackgroundFTIR(refWave)
    Wave refWave
    RemoveBackgroundFTIRbulk(refWave)
End


Thanks again HJ! This is some useful stuff that can easily be modified to do different batch processing.
Best,N

PS: The reason I had the variable "datafolder" was because I hoped to one day automate it that every new set of data could be collected in different data folders. but I haven't had time to write a piece of code to do that successfully yet. I manually make a new one and select and drag all my brand new waves into it.

PPS It's a division because it's a reflectance measurement and I'm trying to remove the light source signal which is convoluted into my data signal. For absorbance measurements a subtraction is correct! =)
Regarding the position of the string statement, one would write
    String newName  
    for (i = 0; i<numItems; i+=1) // starts a loop to go through each wave data
 
        data = StringFromList(i,list,";") //goes through list and extracts ith string
        wave w=$data
        newName = data + "_AuR"     // gives output wave new name
        Duplicate/O w, $newName
        ...
    endfor

which creates the variable outside the loop and only does the assignment inside.
HJ