Stringmatch a string with wave names in the root folder
Peeyush Khare
Hi,
I need to tell my code to take a 1D text wave that contains some names and search for waves in the root folder with the same name. So suppose my 1D wave has name1,name2 and name3 in its three rows, I want the program to look for numeric waves called name1,name2 and name3 in the root folder. If a match is found, I want to store the name in a new 1D wave. So basically this is something similar to stringmatch function. However, how can I stringmatch a string with the name of a wave in the root folder. Kindly advise.
Thanks,
Peeyush
String matchStr
DFREF dfr
DFREF savedDF = GetDataFolderDFR()
SetDataFolder dfr
String itemList = WaveList(matchStr,";", "")
SetDataFolder savedDF
return itemList
End
Usage:
Variable n = ItemsInList(list)
Make/T/N=(n) textWave = StringFromList(p,list)
May 3, 2021 at 05:56 pm - Permalink
Here is a version using wave reference waves for inspiration
// Creates the text wave with wave names
Make/T/O root:MyWaveNames={"Wave1", "Wave2", "Wave3", "Wave4", "Wave5"}
Wave/T MyWaveNames=root:MyWaveNames
// Creates three numerical waves and one text wave
Make/O/N=10 root:Wave1, root:Wave3, root:Wave4
Make/T/O/N=10 root:Wave2
// Converts the wave names to wave references (Wave5 will be invalid and Wave2 will be text)
Make/WAVE/O/N=(NumPnts(MyWaveNames)) MyWaves=root:$MyWaveNames[p]
Wave/WAVE MyWaves=root:MyWaves
// Extracts the valid numerical waves from MyWaves
Extract/O MyWaves, root:MyNumericalWaves, (WaveType(MyWaves[p], 1)==1)
Wave/WAVE MyNumericalWaves=root:MyNumericalWaves
// Creates a list with the names of the extracted waves and displays them in a table together with the original wave names
Make/T/O/N=(NumPnts(MyNumericalWaves)) MyNumericalWaveNames=NameOfWave(MyNumericalWaves[p])
Wave/T MyNumericalWaveNames=root:MyNumericalWaveNames
Edit MyWaveNames, MyNumericalWaveNames
end
May 4, 2021 at 12:52 am - Permalink
In reply to Function/S WaveListInDF… by JimProuty
Hi Jim,
Thanks a lot for the help! So in my situation, I have multiple strings (as different rows of one 1D text wave) that all need to be checked for being present as individual names of waves in the root folder. Whichever are true, those strings need to be stored in a new 1D text wave. So I suppose I need to run a for loop over your code. Kindly advise how to do this..
A few quick questions for my understanding:
- Does "dfr" have a significance as a term in IGOR programming?
- What do "savedDF" and "GetDataFolderDFR" mean?
Best regards,
Peeyush
May 4, 2021 at 09:23 am - Permalink
In reply to Function/S WaveListInDF… by JimProuty
.
May 4, 2021 at 09:24 am - Permalink
In reply to Here is a version using wave… by olelytken
Hi olelytken,
Thanks a lot for the advice! Very helpful.
Best regards,
Peeyush
May 4, 2021 at 09:27 am - Permalink
In reply to Hi Jim, Thanks a lot for… by Peeyush Khare
Jim used dfr and savedDFR as data folder references. A data folder reference works like a wave reference.
Execute DisplayHelpTopic "data folder references" for details.
GetDataFolderDFR is a function, that's why it's displayed with coloured text in the code.
Execute DisplayHelpTopic "GetDataFolderDFR" to see what it does.
May 4, 2021 at 09:59 am - Permalink
if you have the exact names of the waves in your text wave you can use extract:
extract allwaves, somewaves, waveexists($"root:" + allwaves)
May 4, 2021 at 10:09 am - Permalink
In reply to if you have the exact names… by tony
Hi Tony,
This is exactly what I needed.. however I'm running into a small issue. Some of my wave names have space in the middle e.g. isopropyl alcohol. Your code extracted singley worded wave names e.g. eugenol but it didn't pull out names with a space in the middle. Could you please advise how to fix this?
Thanks for all the help and tips!
Sincerely,
Peeyush
May 4, 2021 at 01:43 pm - Permalink
With all your advice, I think I've worked it out below. Thanks! Quick question: How to make the size of the wave "standardfound" variable ?
wave/T standardname_avg
killwaves/Z standardfound
variable n,i
make/T=(dimsize(standardname_avg,0))standardfound
n=0
for(i=0;i<dimsize(standardname_avg,0);i+=1)
wave w=$standardname_avg[i]
if(waveexists(w)==1)
standardfound[n]=standardname_avg[i]
n=n+1
endif
endfor
edit standardname_avg,standardfound
end
May 4, 2021 at 02:05 pm - Permalink
In reply to With all your advice, I… by Peeyush Khare
extract allwaves, somewaves, waveexists($"root:" + PossiblyQuoteName(allwaves))
May 4, 2021 at 02:13 pm - Permalink
In reply to extract allwaves, somewaves,… by tony
PossiblyQuoteName! wow fascinating! Thanks a ton, Tony!
May 4, 2021 at 02:50 pm - Permalink