Automatically grouping waves

Hello everyone,

last but not least for today:

If i have waves present in the following format in one folder:

wave wave1_1_1
wave wave1_3_1
wave wave1_3_1
wave wave1_3_1
wave wave1_4_1
wave wave1_4_1


How can I automatically group them according to the changing number in the middle? The numbers in the middle are not the same all the time, otherwise I would have used some strigmatch of the last few digits...

So for the example above I expect to have three groups, one wave in group1, three in group 2 and 2 in group3.
I need this to automatically create subfolders containing the grouped waves.

Up to now I was manually doing this using the following function:

Function move_all()
    string prefix, list_all
    variable count, i
   
    prefix="*"
    prompt prefix, "prefix"
    doprompt "enter prefix of waves to be moved:", prefix
    if (V_Flag)
            Abort
    Endif
   
    DFREF dfr = GetDataFolderDFR()     
   
    NewDataFolder/O/S $prefix
    DFREF dfrM = GetDataFolderDFR()
    SetDataFolder dfr
   
    list_all = WaveList(prefix+"*",";","")
    count = ItemsInList(list_all)

        for (i = 0; i < count; i+=1)
            wave thisWave1 = $StringFromList(i, list_all)
        movewave thiswave1, dfrM       
    endfor
end
Have you looked in to using ListMatch or GrepList?

string strlist = "ab_1_1; ab_2_1; aa_2_1; aa_3_1; ab_1_3"
print ListMatch(strList,"*_1_*")
  ab_1_1; ab_1_3;
print ListMatch(strList,"*_2_*")
   ab_2_1; aa_2_1;


--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
Hi jjweimer,

Thanks for your response! I thought about using stringmatch or listmatch. The problem is that these middle numbers I want to identify and group waves accordingly are not always the same! Sometimes the first identifying middle number is 2, sometimes 3 etc. Not even the interval is always the same, another problem... So how can I introduce chronology into the Listmatch? So that the first waves are grouped according to any first middle number and more waves according to any second number and so on. Purpose is as stated above to say: "Any waves matching whatever number comes first after the constant pattern "wave1_", please group accordingly; any waves matching any different number from that, please group accordingly"

I think my problem more or less is that as I imagine it, Igor is supposed to find a constant pattern by itself that I can only roughly describe, f.i. by excluding the "wave"-part and the "_1"-part of the example in my first post.

Is that possible?

Best regards,

Martin
I would propose this below. Suppose you have MyWaveList with the list of wave names in the folder.

* Capture the first item from MyWaveList
* Use SplitString or GrepString to capture the required pattern from the first item (call it ... itemPatternStr)
* Use ListMatch to pull off all items from MyWaveList that match itemPatternStr (put them in WavesToMoveList)
* Move waves in WavesToMoveList OR build a text wave item-by-item meta-list that gets handled later (latter is my preference)
* Remove WavesToMoveList items from MyWaveList (using RemoveFromList ???)
* Repeat loop from step 1 until all items in MyWaveList are exhausted

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
It took me some time to work it out but it works in your way and exactly solves my problem. Thanks so much!