Load waves from multiple files and rename

temasi
Posts: 5
Joined: 2012-04-24
Location: Australia

Hi all,

I have to load several waves from different files, and I want to keep the original name of the wave and add the file name to the name of the wave. That way Igor won't show any error for loading waves with the same name.

For example, I have 4 txt files:
File1.txt
File2.txt
File3.txt
File4.txt
Each of them containing the same number of waves with the same name, e.g. Element1, Element2, Element3, Element4, Element5

I need to load the waves and rename them:

Element1_File1 Element1_File2 Element1_File3 Element1_File4
Element2_File1 Element2_File2 Element2_File3 Element2_File4
Element3_File1 Element3_File2 Element3_File3 Element3_File4
Element4_File1 Element4_File2 Element4_File3 Element4_File4
Element5_File1 Element5_File2 Element5_File3 Element5_File4

So far I've managed to load the waves from multiple files and rename them after the file name using the functions below:
DoOpenMultiFileDialog()
FilePathToWaveName(path)

I am new new to programming and I've been creating some useful "Frankenstein" procedures by using extracts from old posts. I guess I'll hang to it until I understand how everything really works.

Thanks.


Posts: 911
Joined: 2007-06-21
Location: United States

First, you may be better off loading the columns from a given file into a data folder named after that file. To learn about data folders, execute:

DisplayHelpTopic "Data Folders"

Assuming you want to go with your original plan . . .

To control the names of the waves being loaded by LoadWave you need to use the /B flag.

There is an example of this at http://www.igorexchange.com/node/2819. See the second post.

In your case it will look something like this:

	String fileName = ParseFilePath(3, filePath, ":", 0, 0)		// Get last element of path with extension removed
 
	String columnInfoStr = ""
	columnInfoStr += "N=Element1_" + fileName + ";"
	columnInfoStr += "N=Element2_" + fileName + ";"
 
	LoadWave /J /O /A /Q /B=columnInfoStr /P=$pathName filePath


temasi
Posts: 5
Joined: 2012-04-24
Location: Australia

Hi,
Thanks for the answer. I haven't figured out yet how to make it work for multiple files. I forgot to mention that I have more than 100 files and each have more than 50 waves, and their names are totally different... not as in my previous example.

I'm using:

#pragma rtGlobals=1		// Use modern global access method.
 
Function/S OpenMultiFileDialog()
	Variable refNum
	String message = "Select one or more files"
	String outputPaths
	String fileFilters = "All Files:.*;"
 
	Open /D /R /MULT=1 /F=fileFilters /M=message refNum 
	outputPaths = S_fileName
 
	if (strlen(outputPaths) == 0)
		Print "Cancelled"
	else
 
		Variable numFilesSelected = ItemsInList(outputPaths, "\r") 
		Variable i
 
 
		for(i=0; i<numFilesSelected; i+=1)
			String path = StringFromList(i, outputPaths, "\r")
 
			// Get just the fileName but with the extension remove.
			String name = ParseFilePath(3, path, ":", 0, 0)
			name = CleanupName(name, 0)
 
			// Get string to pass to LoadWave /B flag to set wave name
			String columnInfo
 
			columnInfo = "N='%s';" + name +";"	
 
			Printf "%d: %s\r", i, path	
 
			LoadWave/J/D/B=columnInfo/E=1/K=0/L={0,1,0,0,0} path
 
		endfor
 
	endif
 
	return outputPaths // Will be empty if user canceled 
 
End
<igor>
 
... but there is something wrong with the /B flag... 


Back to top