Processing Wave Names/Paths and Lists of waves in XOP functions

This is of interest to XOP function writers who have to parse string inputs.

If you have a function in an XOP that takes as a parameter a string containing a wave name or a full path to a wave (data folder path:wave name), the ParseWavePath function will help you parse the input into C strings containing wave name and data folder name.

The ParseWaveListPaths takes a a semicolon- or comma-separated list of wavenames or full paths to waves and returns an array of waveHandles.

Yes, in most cases you should use operations, not functions, for processing lists of waves, in which case you can use OperationHandler to parse inputs, but sometimes a function is appropriate.


<br />
// typedefs for paramater string for data folder paths and wave names. Put these in a header file<br />
typedef char DFPATH [MAXCMDLEN + 1];<br />
typedef char WVNAME [MAX_OBJ_NAME + 1];<br />
<br />
<br />
/*******************************************************************************************************<br />
Takes a handle to a string containing either the name of an Igor Wave in the current data folder or the full path <br />
to an Igor Wave and copies the data folder path (if one is given) and the wave name into the given strings<br />
Last Modified Mar 09 2010 by Jamie Boyd  */
<br />
void ParseWavePath (Handle fullPath, DFPATH dataFolderName, WVNAME waveName){<br />
    <br />
    // ignore leading and trailing spaces<br />
    long startPos, stopPos, pathLen= GetHandleSize(fullPath);<br />
    for (startPos = 0; (*(*fullPath + startPos) == ' ') && (startPos < pathLen); startPos++);<br />
    for (stopPos = pathLen -1; (*(*fullPath + stopPos) == ' ') && (stopPos > startPos); stopPos--);<br />
    pathLen = 1 + stopPos - startPos;<br />
    // Find last colon, the break between the dataFolder and the waveName<br />
    int waveNameBreak;<br />
    for (waveNameBreak = stopPos;((*(*fullPath + waveNameBreak) != ':') && (waveNameBreak >= startPos)); waveNameBreak--);<br />
        // If count down gets to startPos, then no colon, so no datafolder, just wavename   <br />
        if (waveNameBreak < startPos){<br />
            // copy wave name and teminate string<br />
            memcpy (waveName, *fullPath + startPos, pathLen);<br />
            waveName [pathLen] = 0;<br />
            // no data folder, so make path ":" for current folder and terminate dataFolderName<br />
            dataFolderName [0] = ':';<br />
            dataFolderName [1] = 0;<br />
        }else{ // there is a colon, so there is a datafolder <br />
            // copy data folder name and terminate string<br />
            memcpy (dataFolderName, *fullPath + startPos, (waveNameBreak + 1 - startPos));<br />
            dataFolderName [waveNameBreak + 1 - startPos] = 0;<br />
            //copy wavename<br />
            memcpy (waveName, *fullPath + waveNameBreak + 1, (pathLen - 1 - (waveNameBreak - startPos)));<br />
            waveName [pathLen -1 - (waveNameBreak - startPos)] = 0;<br />
        }<br />
}<br />
<br />
/*******************************************************************************************************<br />
Takes a handle to a string containing a semicolon- or comma-separated list of names of Igor waves in the current datafolder<br />
or full paths to Igor waves and returns a pointer to an array of Wave Handles corresponding to those waves.<br />
Also sets the variable pointed to by nWavesPtr to the number of waves in the list<br />
Last Modified Mar 09 2010 by Jamie Boyd  */
<br />
waveHndl* ParseWaveListPaths (Handle pathsList, int* nWavesPtr){<br />
    <br />
    int listLen = GetHandleSize (pathsList);<br />
    // Count semicolons/commas to see how many waves we have.<br />
    int nWaves = 1;<br />
    // ignore trailing semicolon/comma if present<br />
    if ((*(*pathsList + listLen -1) == ';')|| (*(*pathsList + listLen -1) == ','))<br />
        listLen--;<br />
    for (int iList =0; iList < listLen -1 ; iList++){<br />
        if ((*(*pathsList + iList) == ';') || (*(*pathsList + iList) == ',')) nWaves ++;<br />
    }<br />
    // make array of waveHandles<br />
    waveHndl* handleList = (waveHndl*)NewPtr (nWaves * sizeof(waveHndl));<br />
    // make a handle and 2 strings to pass to parseWavePath<br />
    Handle aPath=NewHandle ((MAXCMDLEN + 1) * sizeof (char));<br />
    DFPATH dataFolderPath;<br />
    DataFolderHandle pathDFHandle;<br />
    WVNAME nameOfWave;<br />
    int iWave =0;<br />
    int startPos=0;<br />
    int nameLen =0;<br />
    // find each wave name/path by looking for semicolons/commas and parse it<br />
    for (iWave =0, startPos=0; iWave < nWaves ; startPos += nameLen + 1, iWave++){<br />
        // find next semicolon/comma, or end of list<br />
        for (nameLen =0 ; (((*(*pathsList + startPos + nameLen) != ';') && (*(*pathsList + startPos + nameLen) != ',')) && (startPos + nameLen < listLen)) ; nameLen ++);<br />
        // copy the wave name/path into a handle and Parse it into datafolder path and wavename<br />
        SetHandleSize (aPath, (nameLen * sizeof (char)));<br />
        if (aPath == NULL){<br />
            handleList[iWave] = NULL; <br />
            continue;<br />
        }<br />
        memcpy ((void*)*aPath, (void*)(*pathsList + startPos), (nameLen * sizeof (char)));<br />
        ParseWavePath (aPath, dataFolderPath, nameOfWave);<br />
        // Make reference to dataFolder<br />
        GetNamedDataFolder (NULL, dataFolderPath, &pathDFHandle);<br />
        // get wave reference and add to handleList<br />
        handleList[iWave] = FetchWaveFromDataFolder(pathDFHandle, nameOfWave);<br />
    }<br />
    // free aPath handle<br />
    DisposeHandle (aPath);<br />
    *nWavesPtr = nWaves;<br />
    // return pointer to wave handles array<br />
    return handleList;<br />
}<br />
<br />

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More