Shouldn't this throw an error?

I have a text wave that holds numeric and string variables, such as:

make/O/T/N=(1,2) M_Param
SetDimLabel 1,0,sVARIABLE, M_Param
SetDimLabel 1,1,numVARIABLE, M_Param
M_Param[0][%numVariable] = num2Str(99)
M_Param[0][%sVariable] = "OFF"
Edit M_Param.ld


What I wanted to do was:
function ReadParam(w)
    wave/T w
   
    variable var =  str2num(w[0][%numVARIABLE])
    print var
        // do something with var
end


But what I did was

function ReadParam(w)
    wave w
   
    variable var =  w[0][%numVARIABLE]
    print var
         // do something with var
end


This executed without problem, but gave wrong results. Ok, w is incorrectly declared to be numeric, but shouldn't the assignment of var fail?

I would have expected it to fail also.

And igor knows that it is a text wave
function ReadParam(w)
    wave w

    // prints 2 for text waves
    print WaveType(w,1)
end
At compile time the compiler doesn't know that you are going to feed it a text wave, so it compiles numeric code. At runtime that code does strange things with the text wave.

I suppose you could argue that there should be a run-time check. I think we tend to leave out such checks because they can slow down critical operations. You can add the check, of course, but if the problem is caused by an error it's hard to see why you would add the check!

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:
At compile time the compiler doesn't know that you are going to feed it a text wave, so it compiles numeric code.

Maybe a future rtGlobals=4 could force the user to say either "Wave/D" or "Wave/T" in order to make it clearer what is expected as wave type. Or maybe introduce a new wave flag which says numeric type.

I would be the first user for rtglobals=4 :)