finding procedure version

Might it be possible to create an easy way to query the version number of a procedure from within a function in that procedure?

Here is how I have done it using existing functions:

// returns version number as integer, 100 = 1.00
static function GetThisProcVersion()
    int noversion = 0 // default value when no version is found
    string strStack = GetRTStackInfo(3)
    string strProc = StringFromList(ItemsInList(strStack, ",") - 2, strStack, ",")
    wave /T ProcText = ListToTextWave(ProcedureText("",0,strProc), "\r")
    variable versionVar
    Grep /Q/E="(?i)^#pragma[\s]*version[\s]*=" /LIST/Z ProcText
    s_value = LowerStr(TrimString(s_value, 1))
    sscanf s_value, "#pragma version = %f", versionVar
    if (V_flag!=1 || versionVar<=0)
        return noversion
    endif
    versionVar *= 100
    int version = versionVar
    return version
end

Why would I want to do this?

When a package is initialized and a control panel is created, save the procedure file version associated with that panel.

When a control procedure runs, check that the current procedure version matches the init version.

If an saved experiment contains an out-of-date control panel that was created with an earlier version of the package, the version check will allow me to avoid errors arising from mismatch between new code and old initialisation state.

There are other ways to do it, but it would be nice to have something like a GetProcedureVersion(winName) function where GetProcedureVersion("")  returns the version of the host file.

 

My usual method is to code the version number in a constant, and then save the version as userdata in the panel. Yes, that means being careful to match the #pragma and the version constant...

Yes, I thought about doing that. But it feels rather like setting a trap for myself. Hence the hack that I posted above - at least that way I can't forget to make the update.

Interesting idea ... store the version number in UserData for the panel. I have typically stored it as a global.

In some cases I sync the panel status, together with other package settings, with a structure, and put the whole thing either in the panel user data or in a package folder for quick retrieval. The version number would then sit in the structure.

A built-in ProcedureVersion function will be in Igor 9.01:

ProcedureVersion(<nameOfMacroOrFunctionStr> [,inProcTitleAndIndependentModuleNameStr])

The arguments are similar to ProcedureText.

 Variable version = ProcedureVersion("") returns the version number of procedure containing the currently running macro or function.

Super! Much appreciated.

I thought maybe it was tricky for Igor query compiler directives in straightforward way at run time. Maybe it is? At least ProcedureVersion("") will look less hacky than the snippet above.