Multiple Return Syntax Error

Dear all,

I would like a general idea about the syntax for multiple returns and whether it's possible to return multiple waves from a function, but I'm finding myself stuck returning multiple variables and strings.  I'm using Igor Pro 9.01.

Firstly, I understand from reading the documentation that if one wants a function to return one wave, one must use the /WAVE flag in the function declaration:

function /WAVE exampleReturn(a)

      variable a
      Make /O /N=3 exampleWave = {a, 2, 3}

      return exampleWave

end

which can then be called from a subroutine:

function exampleReturnUse(b)

    variable b
    wave waveReturn = exampleReturn(b)

    print  waveReturn

end

Which works well. 

Likewise, multiple variable or string returns can in principle be performed by using inline syntax (defining all parameters in a single function declaration line). However I cannot get the example to run from:

DisplayHelpTopic "Multiple Return Syntax" 

If I call the following compiled function from the command line (using Subroutine(10) for example):

Function [ Variable v, String s ] Subroutine( Variable a )
    return [1+a, "hello"]
End

I just get a generic 'syntax error' message. 

Likewise, I get the same outcome if I try an example I came up with:

function [variable c, variable d] exampleMultipleReturn(variable a, variable b)

          c = a + b
          d = a - b
         
          return [c , d]
         
end

Again, calling exampleMultipleReturn(3,5) for example returns a 'syntax error' message; both the examples above compile in the procedure window however. 

I'm trying to work my way up to returning multiple waves from a function, but I'm assuming there's something fundamentally flawed about my understanding.  

Provided I can correct the error of my ways, what would be the correct syntax for returning multiple waves. Must I still use the /WAVE flag? For example, if I follow the above examples, is this redundancy necessary?

Function /WAVE [ wave v, wave s ] Subroutine(variable a )

All the best,

Ryan 

 

 

 

Have you tries to call your MRS function from the commandline only?

 

The following works here with 9.01 r39200.

 

Function [ Variable v, String s ] Subroutine( Variable a )
    return [1+a, "hello"]
End

Function CallSubroutine()

    variable v_result
    string s_result
   
    [v_result, s_result] = SubRoutine(1)
   
    print V_result, S_result
End

 

•Callsubroutine()
  2  hello

 

What do you mean with 'being useful'? This depends on your use case, no?

By the way, here is an example with multiple-wave return, you asked for:

function [wave v, wave s] exampleReturn(variable a)
    Make/O/N=3 exampleWave1 = {a, 2, 3}
    Make/O/N=3 exampleWave2 = {2*a, 6, 7}
    return [exampleWave1, exampleWave2]
end

Function test(Variable a)
    Wave v,s
    [v, s] = exampleReturn(a)
    print v, s
    return 0
End

 

> I was commenting on the idea that if I can't call a function from the command line, it doesn't appear incredibly useful.

That depends on your usage of Igor I guess. There are a lot of specialities (free waves, multiple return syntax, pass-by-reference parameters, functions returning waves/dfrs, ...) which only work in function code where function A calls function B. But if you require that it is always callable from the command line, well you can't use these specialities.