Determine the version of a procedure file

//**
// Determine the version of a compiled procedure window
// named procedureWinTitleStr.
// The version is defined using the #pragma version
// compiler directive.  For example,
// #pragma version=1.05.
//
// As stated in the Igor documentation, the line must
// start flush with the left of the window (that is, there
// can be no leading whitespace).  Spaces
// and tabs within the directive are ignored.
//
// Returns NaN if procedure window doesn't exist,
// 1.00 if no version is defined in the procedure window,
// or the version that is defined in the procedure window.
//*
Function GetProcedureVersion(procedureWinTitleStr)
    String procedureWinTitleStr
   
    // By default, all procedures are version 1.00 unless
    // otherwise specified.
    Variable version = 1.00
    Variable versionIfError = NaN
   
    String procText = ProcedureText("", 0, procedureWinTitleStr)
    if (strlen(procText) <= 0)
        return versionIfError       // Procedure window doesn't exist.
    endif
   
    String regExp = "(?i)(?:^#pragma|\\r#pragma)(?:[ \\t]+)version(?:[\ \t]*)=(?:[\ \t]*)([\\d.]*)"
   
    String versionFoundStr
    SplitString/E=regExp procText, versionFoundStr
    if (V_flag == 1)
        version = str2num(versionFoundStr)
    endif
    return version 
End
Perhaps a better return for a procedure file with no #pragma version information should be 0.00 instead of 1.00. That would allow also for distinguishing from procedure files that are version 1.00.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
I thought about that, but Igor allows you to declare the version of your procedure as 0 or even a negative number, if you wish. I assume that it also allows you to declare the version to be NaN, but that is less likely to be an issue, I suspect.
Oh! Odd but understandable.

Having a return of 0.00 (since NaN is used as a No Procedure File Error flag) still seems a better "no pragma defined" return value than 1.00. While Igor allows procedure files of version = 0.00, I suspect the number of users who purposely code a procedure file with such a version number is far, far smaller than the number who actually use no version pragma in their procedure file.

This is BTW a good standard piece of code to have around to help oversee code development.

Thanks!

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More