returning several waves from a function

Hi,

As an Igor newbie, I was trying to write a function that does some simple processing of an input wave, which ends up generating two processed waves of the same length and x-scaling. Since I use rtGlobals=3, and prefer to keep using it, there is the problem of somehow returning these 2 waves to the outside world. What is the advised way to do this in Igor? Package them into a matrix of waves? Or is there something else?

And since we are at it, how does one use optional arguments to functions?

Thanks.
You could use a wave wave as a parameter:

Function Subroutine(ww)
    Wave/WAVE ww                // Output waves returned here
   
    Make/O jack = sin(x/8)
    ww[0] = jack                    // Return to caller
   
    Make/O fred = cos(x/8)
    ww[1] = fred                    // Return to caller
End

Function Test()
    Make/FREE/N=2/WAVE theWaves
    Subroutine(theWaves)
    Wave first = theWaves[0]
    Wave second = theWaves[1]
    Display first, second
End


You could also use a structure:
Structure Structure2
    Wave first
    Wave second
EndStructure

Function Subroutine2(s)
    STRUCT Structure2 &s            // Output waves returned here
   
    Make/O jack = sin(x/8)
    Wave s.first = jack             // Return to caller
   
    Make/O fred = cos(x/8)
    Wave s.second = fred            // Return to caller
End

Function Test2()
    STRUCT Structure2 theWaves
    Subroutine2(theWaves)
    Wave first = theWaves.first
    Wave second = theWaves.second
    Display first, second
End


Quote:
how does one use optional arguments to functions?


Execute this for details:
DisplayHelpTopic "Optional Parameters"

Thanks a lot, especially for make me aware of the existence of the 'structure' data structure. That seems the most elegant solution.