Data-folder awareness for WaveList()
chozo
Sat, 05/30/2020 - 04:57 am
WaveList() is only returning results from the current data folder and thus needs acrobatics with SetDataFolder to work on different DFs. It is one of the few functions I use frequently which is not able to take a data-folder string or DFREF input. I propose the addition of this functionality (a new function WaveListDFR()?) to have this convenient function work with DFREFs.
I agree. This would help eliminate the gymnastics that one must sometimes undertake with SetDataFolder to jump around in data folders.
May 30, 2020 at 06:57 am - Permalink
Yes, it would be great to have that. In the meantime I use this:
string matchStr, separatorStr, optionsStr; DFREF dfr
DFREF saveDFR = getDataFolderDFR()
SetDataFolder dfr
string s=wavelist(matchStr, separatorStr, optionsStr)
SetDataFolder saveDFR
return s
end
May 31, 2020 at 02:08 am - Permalink
I think that new function should return a wave reference wave. And you have to ensure what you don't bug out, so something like
string s
variable err
DFREF saveDFR = GetDataFolderDFR()
SetDataFolder dfr
try
err = GetRTError(1)
s = WaveList(matchStr, separatorStr, optionsStr); AbortOnRTE
catch
err = GetRTError(1)
SetDataFolder saveDFR
return $""
endtry
WAVE wv = ListToWaveRefWave(s)
SetDataFolder saveDFR
if(DimSize(wv, 0) == 0)
return $""
endif
return wv
End
based on tony's solution.
June 1, 2020 at 04:44 am - Permalink
Thomas,
thank you for your suggestion and the code example. To be honest, I rather would get a string list as before from the function instead of a wave reference wave. I think a string list is easier to chop down further (e.g., by using GrepList()) than to handle wave references right away. Also, I wonder if in the code the ListToWaveRefWave(s) should come before the SetDataFolder command, otherwise the correct waves cannot be referenced, no?
June 1, 2020 at 08:47 pm - Permalink
@chozo. Thanks for the comment. Yes indeed the SetDataFolder must come later. And also handle an empty wave specially.
June 2, 2020 at 02:20 am - Permalink
To create a wave reference wave you can already do something like below, but sometimes it's useful to create a stringlist directly, for instance if you need it for a popup menu.
// Counts the number of waves in MyFolder
Variable n=CountObjectsDFR(MyFolder, 1)
// Creates a list of all waves in the folder
Make/FREE/O/WAVE/N=(n) AllWaves=WaveRefIndexedDFR(MyFolder, p)
June 2, 2020 at 02:35 am - Permalink
Hi olelytken, great code example. I keep this in mind for later use.
June 5, 2020 at 05:34 am - Permalink
WaveRefIndexedDFR can be used to iterate through the waves in a particular data folder.
June 7, 2020 at 12:50 pm - Permalink