Shorting values from different folders

Hi everyone,

I have loaded my data in igor using a loader that saves each spectrum (saved as a wave) separately together with some variables (Current, etc.) by creating individual folder. Now I would like to average/do some mathematics with the spectrum only with those folders having the value of a particular variable same (lets say when Current=15). How can I short those folders and do this? Thanks in advance.

Regards,
Somnath
Hi Somnath,

Maybe this function I wrote to do similar stuff helps you:

function/s getDataFolderList([sort])
// Returns a list of the full paths to sub data folders.
// Sorts the list by default. Set sort=0 to cancel.
    variable sort
    string dl = removeEnding(DataFolderDir(1)[8,inf],";\r")
    if (!strlen(dl))
        return ""
    endif
    dl = "'" + replaceString(",",dl,"','") + "'"    // single-quote everything to make all names legal
    dl = getDataFolder(1) + replaceString(",", dl, ":;"+getDataFolder(1)) + ":;"
    if (ParamIsDefault(sort))
        dl = sortList(dl)
    endif
    return dl
end


You would use it in a for loop like this:

string allSubFolders = getDataFolderList()
variable i, n=itemsInList(allSubFolders)
for (i=0; i<n; i+=1)
    string thisFolder = stringFromList(i, allSubFolders)
    if GrepString(thisFolder, "spectrum") // only use folders called "*spectrum*", this would be useful to avoid using folders like "root:Packages"
        setdatafolder $thisFolder
        // check for the existance & value of a given variable
        NVAR /Z Current
        if (NVAR_Exists(Current) && Current==15)
            print Current
        endif
        setdatafolder ::
    endif
endfor


(I haven't tested this example loop.)

I also have another function which lets you do execute_code_in_all_subfolders("print 0") but I think it's less useful in this context.

By the way, Igor's trace name feature is extremely useful when you use functions like this. For example, if you do Display and AppendToGraph Spectrum /TN=$thisFolder in the above loop, you will be able to see from the graph legend which wave is which. Otherwise, you would just get Spectrum, Spectrum#1, Spectrum#2, ...