Merging Procedures/Functions?

Hi there,

I have a set of individual procedures that I use for the analysis of my data. This worked fine for the initial stages of my project. It is however,getting pretty tedious to go through each individual procedure for the large data sets I have now so I'd like to automate this process even further. I would like to create a single function that uses these procedures to get me to the final product. I was looking into "Accessing Waves in Functions" and "Wave References" but I'm unsure how to implement it.

I'm showing two of the procedures that I use as part of the process. The first one "BLAll" creates a new set of waves that have undergone a baseline subtraction as specified by the procedure "Baseline Subtraction".

Function BaselineSubtraction(w1)    //This function finds the minimum value over a specified range and subtracts it from the parent wave.
                            // The baseline corrected wave is then smoothed out.
    WAVE w1                 // w1 is the initial wave to be baselined
   
    Variable leftmark=300               // leftmark is the leftmost "x" value of the range, rightmark is the rightmost "x" value of the range
    Variable rightmark=629              //rangetype should be a point in the wave that is within the specified range
    Variable rangetype=300
   
    String outputName= NameOfWave(w1) +"_bl"            //Renames the original wave
   
    if (rangetype<300 || rangetype>629)                 //if the value of for rangetype is outside the specified range, return null result
        return -1                                   //The range is setup b/n 300 and 629 because that is the corresponding ev/nm range that I care about in the
    endif                                           // new waves
   
    Duplicate/o w1 $outputName                      //Duplicates original wave and renames it according to the outputName function
    Wave output = $outputName
   
    if (rangetype==0)                               //Determines the various wave statistics over the specified range
        WaveStats/Q output
    endif
   
    if (rangetype==300)
        WaveStats/Q/R=[leftmark,rightmark] output
    endif
   
    if (rangetype==629)
        WaveStats/Q/R=(leftmark,rightmark) output
    endif
   
    output= output - V_min                      //Carry out baseline subtraction by utlizing V_min determined from previous loops
    DeletePoints/M=0 0,6,output                 //Remove irrelevant/uninteresting points from polished data
    DeletePoints/M=0 624,1000,output
    //Smooth 10,output                          //Smoothes out the baseline corrected wave.
    //print V_min                               //Prints the minimum value used to carry out the baseline subtraction
End

FUNCTION BLAll(wname, fnum)     //When calling the wave for this function, do not include the profile number!

    STRING wname
    VARIABLE fnum
   
    VARIABLE i
    STRING w1
   
    for(i=0; i<=fnum; i=i+1)
        w1 = wname+num2str(i)
            BaselineSubtraction($(w1))
    endfor
End


The second one "SpanoFitAll" fits a function I defined in another procedure to the waves I created using "BLAll".

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

Function SpanoFit(w1,xwave,cwave)

    Wave w1,xwave,cwave
    String outputName="Spano_" + NameOfWave(w1)
    String cwaveName="Cs_" +NameOfWave(w1)
   
    Variable/G V_FitTol=0.00001
    Variable/G V_FitMxIters=100
   
    Make/D/O/N=7 EpsilonSpano
    EpsilonSpano[0]={0,10^-6,0,10^-6,10^-6,10^-6,10^-6}
   
    Make/D/O/T/N=7 T_ConstraintsSpano
    T_ConstraintsSpano[0]={"K1 > 0.01","K1 < 1","K3 > 1.85","K3 < 2.1","K4 > 0.02","K4 < 0.1","K6 > 0.001","K6 < 10"}
   
    Duplicate /O w1 $(outputName)
    Wave output=$(outputName)
   
    FuncFit/N=1 /L=624 /H="1010010"  Spano cwave w1[256,376] /X=xwave /D/E=EpsilonSpano/C=T_ConstraintsSpano/F={0.95,7}/R   //[600,775] for S-Flame [1000,1225] for T-Flame
        output= Spano(cwave,xwave)
   
    Duplicate/O cwave $(cwaveName)
    Wave output1=$(cwaveName)
End

Function SpanoFitAll(w1,xwave,cwave,fnum)

    String w1
    Wave xwave,cwave
    Variable fnum
    Variable i
    String neww1
   
    for(i=0; i<=fnum; i=i+1)
        neww1 = w1+num2str(i) +"_bl_smth"
            SpanoFit($(neww1),xwave,cwave)
    endfor
End


Could someone provide me with an example or tip as to how I'd create a function that creates the baseline subtracted waves and uses them to create the fits? I have additional procedures that I'd like to implement into this process, but an example on how to do it with these two would help me a lot.

Thank you very much!
Your code is too long to examine in detail. It would be better if you could boil it down to the simplest possible, self-contained function that we could run and debug.

That said, it is better to write this:
w1 = wname+num2str(i)
BaselineSubtraction($(w1))


like this:
w1 = wname+num2str(i)
Wave w = $w1    // Create wave reference
BaselineSubtraction(w)


This is easier to debug and avoids dependency on the rtGlobals mode in effect.

This applies any time you use $. I recommend creating an explicit wave reference.
Figured it out. All I needed to do was apply the wave references as you mentioned. Thank you!