Working out if a string list of IGOR commands is syntactically correct (i.e. would they work from the command line)

Sometimes one has a list of IGOR commands that one wants to issue in a batch manner from the command line. How does one know if they are syntactically correct (i.e. have the correct parameters, etc)? The following two functions determine that.

One provides a textwave containing the list of IGOR commands. These are then written to a procedure file, with text to make it look like they are enclosed in a function. This procedure file is then INSERTINCLUDEd and a COMPILEPROCEDURES is attempted. If the commands are fine then the procedure file compiles and no error messages are produced. If one or more of the commands is syntactically wrong then an IGOR compilation error window pops up and says that there is a problem. It will also list where the first problem is.

After this the procedure file is DELETEINCLUDEd and recompiled (COMPILEPROCEDURES). It is necessary for the procedure to be in an Independent Module because it can continue processing if there is a problem.

#pragma IndependentModule=batchChecker

Function checkBatchFile(listWave)
    Wave/t listWave

    pathinfo IGOR
    newpath/o/q/z User_PROCEDURES, S_Path+"User Procedures"
    //first part is to write the listWave to a procedure file
    duplicate/o/t listwave, batchFileChecker
    redimension/n=(-1,0)  batchfileChecker
    insertpoints 0,2,batchfilechecker
    batchfileChecker[0] = "#pragma rtGlobals=1    // Use modern global access method."
    batchfileChecker[1] = "Function test()"
    redimension/n=(numpnts(batchfileChecker)+1) batchFileChecker
    batchfileChecker[inf] = "End"

    Save/o/g/P=User_Procedures batchfileChecker as "batchFileChecker.ipf"
    killwaves/z batchFileChecker

    //now do the checking
    string/g diditcompile = ""
    execute/p/z "INSERTINCLUDE \"batchFileChecker\""
    execute/p/z/q "COMPILEPROCEDURES "
    execute/p/z/q "didItcompile = Functionlist(\"\",\";\",\"\")"

    execute/p/q/z "DELETEINCLUDE \"batchFileChecker\""
    execute/p/z/q "COMPILEPROCEDURES "
    execute/p/z/q "Deletefile/P=User_Procedures \"batchFileChecker.ipf\""
    execute/p/q/z "batchChecker#compResult(didItCompile)"

End

Function compresult(val)
    string val
    Variable/g V_flag
   
    if(stringmatch(val,"Procedures Not Compiled;"))
        print "There seems to be something wrong with your list of commands"
        V_flag = 1
    else
        print "Your batch list of commands seems to be syntactically correct"
        V_flag=0
    Endif
end

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More