Loading multiple waves from multiple .txt files
dmichala
What I'd like to do is to be able to select multiple .text files and load in two waves from each (1st and 3rd columns). 'Open' lets me select multiple files but then once the for loop starts, it opnes 3 more windows for me to select files. I was hopeing LoadWave would load the first column in each file in 'loadedFiles' as t0, t1, t2, etc. and the third column as c0, c1, c2, etc.
On paper, I'd say this code would do that but LoadWave opens a new file selection window every time it loops. I thought StringFromList(i, loadedFiles) would load the full path name of the file of interest which would negate the need for a selection window. Where is my misunderstanding in this?
Thanks.
Function loadMult()
variable RefNum
String message = "Select one or more files"
String fileName
String fileFilters = "Data Files (*.txt,*.dat,*.csv):.txt,.dat,.csv;"
fileFilters += "All Files:.*;"
Open /D /R /MULT=1 /F=fileFilters /M=message refNum
Print "The RefNUM is: ", refNum
String loadedFiles = S_fileName
Print loadedFiles[1]
Print "The Selected Files are: ", loadedFiles
if (strlen(loadedFiles) == 0)
Print "File Contains No Data - Script was Cancelled!!"
else
Variable numFilesSelected = ItemsInList(loadedFiles, "\r")
Variable i
for(i=0; i<numFilesSelected; i+=1)
String columnInfoStr = ""
columnInfoStr += "N=t" + num2str(i) + ";"
columnInfoStr += "C=1,N='_skip_';" // Skip Column1
columnInfoStr += "N=c" + num2str(i) + ";"
LoadWave/J/D/O/L={0,1,0,0,3}/B=columnInfoStr StringFromList(i, loadedFiles) //This opens more dialog windows
endfor
endif
return 0
END
variable RefNum
String message = "Select one or more files"
String fileName
String fileFilters = "Data Files (*.txt,*.dat,*.csv):.txt,.dat,.csv;"
fileFilters += "All Files:.*;"
Open /D /R /MULT=1 /F=fileFilters /M=message refNum
Print "The RefNUM is: ", refNum
String loadedFiles = S_fileName
Print loadedFiles[1]
Print "The Selected Files are: ", loadedFiles
if (strlen(loadedFiles) == 0)
Print "File Contains No Data - Script was Cancelled!!"
else
Variable numFilesSelected = ItemsInList(loadedFiles, "\r")
Variable i
for(i=0; i<numFilesSelected; i+=1)
String columnInfoStr = ""
columnInfoStr += "N=t" + num2str(i) + ";"
columnInfoStr += "C=1,N='_skip_';" // Skip Column1
columnInfoStr += "N=c" + num2str(i) + ";"
LoadWave/J/D/O/L={0,1,0,0,3}/B=columnInfoStr StringFromList(i, loadedFiles) //This opens more dialog windows
endfor
endif
return 0
END
Add /A to your LoadWave command.
November 6, 2018 at 09:21 am - Permalink
In reply to Add /A to your LoadWave… by hrodstein
I don't think this is a wave naming problem. The loadwave fails to find the directory and filename somehow... Why is that happening?
May 13, 2020 at 04:25 am - Permalink
In reply to I don't think this is a wave… by Jakub
LoadWave needs to know the name of the file and the folder containing the file.
The use of "StringFromList(i, loadedFiles)" makes it difficult to debug this. Store the output from StringFromList in a local string variable and print it to the history or use the debugger to inspect it.
May 13, 2020 at 05:26 am - Permalink
loading 1st and 3rd columns sounds a bit like something I have had to do before. maybe this procedure contains something useful?
May 14, 2020 at 12:29 am - Permalink