Stringmatch a string with wave names in the root folder

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 

Function/S WaveListInDF(matchStr, dfr)
    String matchStr
    DFREF dfr
 
    DFREF savedDF = GetDataFolderDFR()
    SetDataFolder dfr
    String itemList = WaveList(matchStr,";", "")

    SetDataFolder savedDF
    return itemList
End

Usage:

String list= WaveListInDF("name*",root:)
Variable n = ItemsInList(list)
Make/T/N=(n) textWave = StringFromList(p,list)

 

Here is a version using wave reference waves for inspiration

Function MyFunction()

    //  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

 

In reply to 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 

In reply to by Peeyush Khare

Peeyush Khare wrote:

- Does "dfr" have a significance as a term in IGOR programming? 

- What do "savedDF" and "GetDataFolderDFR" mean? 

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.

if you have the exact names of the waves in your text wave you can use extract:

extract allwaves, somewaves, waveexists($"root:" + allwaves)

 

In reply to 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

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 ?

Function run()
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