Reorder Waves in Data Folder


// ReorderWavesInDataFolder(dRef, baseName, sortOptions)
// Reorders the waves in the data folder specified by dRef so that they are sorted.
//
// When you iterate through waves in a given data folder, Igor returns the waves
// in the order in which they were added to the data folder. Sometimes a procedures
// needs the waves to be in a certain order. This achieves that by temporarily moving
// the waves out of the original data folder to a temporary data folder and then moving
// them back to the original data folder in the desired order.
//
// All waves in the specified data folder whose names begin with the specified base name are reordered.
// Pass "" for baseName to reorder all waves in the data folder.
//
// See the SortList function for the meaning of the sortOptions parameter.
//
// Here is an example:
//	NewDataFolder/O/S root:TestDataFolder
//	Make/O xWave3, xWave7, xWave1, xWave0, xWave15, xWave11
//	Make/O yWave0, yWave7, yWave1, yWave3, yWave15, yWave11
//	ReorderWavesInDataFolder(dRef, "xWave", 16)
//	ReorderWavesInDataFolder(dRef, "yWave", 16)
Function ReorderWavesInDataFolder(dRef, baseName, sortOptions)
	DFREF dRef
	String baseName
	Variable sortOptions			// As for SortList function
 
 	String tempDFName = "%tempForReorderWavesInDF%"
	NewDataFolder /O dRef:$tempDFName
	DFREF tempDF = dRef:$tempDFName
 
	String waveNames = WaveList(baseName+"*", ";", "")
	String sortedWaveNames = SortList(waveNames, ";", sortOptions)
	
	// Move waves to temp data folder
	Variable numWaves = itemsInList(waveNames)
	String name
	Variable i
	for(i=0; i<numWaves; i+=1)
		name = StringFromList(i, sortedWaveNames)
		MoveWave dRef:$name, tempDF
	endfor
	
	// Move waves back to original data folder
	for(i=0; i<numWaves; i+=1)
		name = StringFromList(i, sortedWaveNames)
		MoveWave tempDF:$name, dRef
	endfor
 
	KillDataFolder tempDF
End

Forum

Support

Gallery

Igor Pro 10

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More