Turning a .txt file into a wave
s0585353
Fri, 11/18/2016 - 12:51 pm
NewPath/O dataFolder
String callist=ListFilesofType("dataFolder",1,".txt")
String timefile=StringFromList(0,callist)
LoadWave/G/M/D/A=wave/P=datafolder timefile
Thanks
Wave w = $name // Create a wave reference
Variable numRows = DimSize(w, 0)
Variable numColumns = DimSize(w, 1)
Variable numPoints = numRows * numColumns
Redimension/N=(numPoints) w
BTW, when you post Igor code, use <igor> and </igor> tags as explained at http://www.igorexchange.com/node/3221
November 18, 2016 at 03:16 pm - Permalink
Variable cwl
NewPath/O dataFolder //dialog box to get the data folder path
String callist=ListFilesofType("dataFolder",1,".txt")
String timefile=StringFromList(0,callist)
LoadWave/G/M/P=datafolder timefile
String name = StringFromList(0,timefile) // Get name of the wave created by LoadWave
Wave w = $name // Create a wave reference
Variable numRows = DimSize(w, 0)
Variable numColumns = DimSize(w, 1)
Variable numPoints = numRows * numColumns
Redimension/N=(numPoints) w
End
November 21, 2016 at 12:50 pm - Permalink
Although my web browser makes it look like your file contains numbers in columns, in fact, it contains one long row of number separated by tabs.
You can't use LoadWave/G for this data. To understand why, execute this:
You can use LoadWave/J (Load Delimited Text). Here is a function that may get you started in the right direction:
"Load Time File...", LoadTimeFile("", "")
End
Function LoadTimeFile(pathName, fileName)
String pathName // Name of an Igor symbolic path or ""
String fileName // Name of file or full path to file
// First get a valid reference to a file.
if ((strlen(pathName)==0) || (strlen(fileName)==0))
// Display dialog looking for file.
Variable refNum
String filters = "Text Files (*.txt):.txt;"
filters += "All Files:.*;"
Open/D/R/P=$pathName /F=filters refNum as fileName
fileName = S_fileName // S_fileName is set by Open/D
if (strlen(fileName) == 0) // User cancelled?
return -1
endif
endif
LoadWave/J/M/P=$pathName/Q fileName
String listOfWaves = S_waveNames // S_waveNames is set by LoadWave
String filePath = S_path + S_fileName // S_path and S_fileName are set by LoadWave
String name = StringFromList(0, listOfWaves)
Wave w = $name // Create a wave reference
// Redimension as 1D wave
Variable numRows = DimSize(w, 0)
Variable numColumns = DimSize(w, 1)
Variable numPoints = numRows * numColumns
Redimension/N=(numPoints) w
Printf "Loaded wave %s from \"%s\"\r", name, filePath
return 0 // Success
End
To clarify what a symbolic path is versus a data folder, execute these commands:
DisplayHelpTopic "Data Folders"
November 21, 2016 at 01:41 pm - Permalink