Load & Plot multiple .txt to Common Graph
ggm877
I'm looking to load and display multiple 2 column .txt files to one graph. So far I've figured out a procedure of my own that easily loads .txt files to a wave using LoadWave and have found another procedure by Drhodstein that does the same in a nicer fashion. However I haven't been able to append these multiple waves to a single graph. It seems this should be an easy thing but I can seem to find a way to make it work primarily because each iteration of LoadWave overwrites the previous.
My code:
Function RamanGraph()
Variable refNum, k
String message = "Select one or more files"
String outputPaths
String fileFilters = "Delimited Text (*.txt):.txt;"
fileFilters += "All Files:.*;"
Open /R/D/F=fileFilters /MULT=1 /M=message refNum
outputPaths = S_fileName // Stores the full file names + directories in outputPaths
Variable/G numberOfImages = ItemsInList(outputPaths, "\r") // Finds the number of images being opened
If(StrLen(outputPaths)==0)
Print "User Cancelled"
return -1
Endif
String columnInfoStr = " "
columnInfoStr +="N=Shift;"
columnInfoStr +="N=Intensity;"
For(k=0;k<NumberOfImages;k+=1)
String path = StringFromList(k, outputPaths, "\r")
LoadWave/Q/J/D/A/K=0/E=1/W/O path
Wave /T imageList // Stores force curve names in ordered list
Make /O/T/N=(numberOfImages) imageList
imageList[k] = path
EndFor
End
Variable refNum, k
String message = "Select one or more files"
String outputPaths
String fileFilters = "Delimited Text (*.txt):.txt;"
fileFilters += "All Files:.*;"
Open /R/D/F=fileFilters /MULT=1 /M=message refNum
outputPaths = S_fileName // Stores the full file names + directories in outputPaths
Variable/G numberOfImages = ItemsInList(outputPaths, "\r") // Finds the number of images being opened
If(StrLen(outputPaths)==0)
Print "User Cancelled"
return -1
Endif
String columnInfoStr = " "
columnInfoStr +="N=Shift;"
columnInfoStr +="N=Intensity;"
For(k=0;k<NumberOfImages;k+=1)
String path = StringFromList(k, outputPaths, "\r")
LoadWave/Q/J/D/A/K=0/E=1/W/O path
Wave /T imageList // Stores force curve names in ordered list
Make /O/T/N=(numberOfImages) imageList
imageList[k] = path
EndFor
End
DrHodstein's Code:
Function LoadOneFile(pathName, filePath)
String pathName // Name of Igor symbolic path or ""
String filePath // File name, partial path relative to symbolic path, or full path
String fileName = ParseFilePath(3, filePath, ":", 0, 0) // Get file name without extension
String baseShiftName = "Shift"
String baseIntensityName = "Intensity"
Variable baseMaxNameLength = max(strlen(baseShiftName),strlen(baseIntensityName))
Variable maxIgorNameLength = 31
// This is to make sure that your wave names don't wind up being too long for Igor to handle
Variable clippedFileNameLength = maxIgorNameLength - baseMaxNameLength
String clippedFileName = fileName[0,clippedFileNameLength-1]
// Print clippedFileName // For debugging only
String columnInfoStr = ""
columnInfoStr += "N='" + baseShiftName + clippedFileName + "';"
columnInfoStr += "N='" + baseIntensityName + clippedFileName + "';"
// Print columnInfoStr // For debugging only
LoadWave/A/G/D/B=columnInfoStr/K=0/P=$pathName filePath // You may need to tweak this
End
Function/S LoadFiles()
Variable refNum
String message = "Select one or more files"
String outputPaths
String fileFilters = "Data Files (*.txt,*.dat,*.csv):.txt,.dat,.csv;"
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")
Printf "%d: %s\r", i, path
LoadOneFile("", path)
endfor
endif
return outputPaths // Will be empty if user canceled
End
String pathName // Name of Igor symbolic path or ""
String filePath // File name, partial path relative to symbolic path, or full path
String fileName = ParseFilePath(3, filePath, ":", 0, 0) // Get file name without extension
String baseShiftName = "Shift"
String baseIntensityName = "Intensity"
Variable baseMaxNameLength = max(strlen(baseShiftName),strlen(baseIntensityName))
Variable maxIgorNameLength = 31
// This is to make sure that your wave names don't wind up being too long for Igor to handle
Variable clippedFileNameLength = maxIgorNameLength - baseMaxNameLength
String clippedFileName = fileName[0,clippedFileNameLength-1]
// Print clippedFileName // For debugging only
String columnInfoStr = ""
columnInfoStr += "N='" + baseShiftName + clippedFileName + "';"
columnInfoStr += "N='" + baseIntensityName + clippedFileName + "';"
// Print columnInfoStr // For debugging only
LoadWave/A/G/D/B=columnInfoStr/K=0/P=$pathName filePath // You may need to tweak this
End
Function/S LoadFiles()
Variable refNum
String message = "Select one or more files"
String outputPaths
String fileFilters = "Data Files (*.txt,*.dat,*.csv):.txt,.dat,.csv;"
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")
Printf "%d: %s\r", i, path
LoadOneFile("", path)
endfor
endif
return outputPaths // Will be empty if user canceled
End
Any help would be appreciated, I feel that it should be a relatively easy step so save the waves in an iterative manner and then use AppendToGraph to plot them all together.
Thanks!
Garrett
To determine the names of the waves loaded, after LoadWave, execute this:
String firstName = StringFromList(0, wavesLoadedList)
Wave firstWave = $firstName
String secondName = StringFromList(0, wavesLoadedList)
Wave secondWave = $secondName
If the graph already exists, you can then use AppendToGraph.
For another example, execute:
DisplayHelpTopic "Loading Waves Using Igor Procedures"
December 11, 2017 at 01:08 pm - Permalink
December 12, 2017 at 09:00 am - Permalink