Load Space-Delimited Text File and Process Each Column
hrodstein
// This is an answer to the questions:
// How do I load a space-delimited file?
// How do I do a histogram of each loaded wave and create a graph showing the histogram?
Menu "Load Waves"
"Load Spaced Delimited File...", LoadSpaceDelimitedFile("", "")
End
Function ProcessWave(w)
Wave w
Variable numHistBins = 10 // Desired number of bins
String destWaveName = NameOfWave(w) + "_hist"
Make /O /N=(numHistBins) $destWaveName
Histogram /B=1 w, $destWaveName
Wave dest = $destWaveName
Display dest
End
// LoadSpaceDelimitedFile(pathName, fileName)
// Returns number of waves loaded or -1 if cancel.
Function LoadSpaceDelimitedFile(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
Open/D/R/P=$pathName refNum as fileName
fileName = S_fileName // S_fileName is set by Open/D
if (strlen(fileName) == 0) // User cancelled?
return -1
endif
endif
// Now load the data. The /V flag specifies space as delimiter.
// Add the /A flag if you don't want the "Loading Delimited Text" dialog.
// Add the /O flag if you want to overwrite existing waves with the same names.
LoadWave /J /D /E=1 /K=0 /W /V={" ","",0,0} /P=$pathName fileName
Variable numWavesLoaded = V_flag // V_flag is set by LoadWave
if (numWavesLoaded == 0)
return 0
endif
String listOfWavesLoaded = S_waveNames // S_waveNames is set by LoadWave
Variable i
for(i=0; i<numWavesLoaded; i+=1)
String name = StringFromList(i, listOfWavesLoaded)
Wave w = $name // Create wave list
ProcessWave(w)
endfor
return numWavesLoaded
End
// How do I load a space-delimited file?
// How do I do a histogram of each loaded wave and create a graph showing the histogram?
Menu "Load Waves"
"Load Spaced Delimited File...", LoadSpaceDelimitedFile("", "")
End
Function ProcessWave(w)
Wave w
Variable numHistBins = 10 // Desired number of bins
String destWaveName = NameOfWave(w) + "_hist"
Make /O /N=(numHistBins) $destWaveName
Histogram /B=1 w, $destWaveName
Wave dest = $destWaveName
Display dest
End
// LoadSpaceDelimitedFile(pathName, fileName)
// Returns number of waves loaded or -1 if cancel.
Function LoadSpaceDelimitedFile(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
Open/D/R/P=$pathName refNum as fileName
fileName = S_fileName // S_fileName is set by Open/D
if (strlen(fileName) == 0) // User cancelled?
return -1
endif
endif
// Now load the data. The /V flag specifies space as delimiter.
// Add the /A flag if you don't want the "Loading Delimited Text" dialog.
// Add the /O flag if you want to overwrite existing waves with the same names.
LoadWave /J /D /E=1 /K=0 /W /V={" ","",0,0} /P=$pathName fileName
Variable numWavesLoaded = V_flag // V_flag is set by LoadWave
if (numWavesLoaded == 0)
return 0
endif
String listOfWavesLoaded = S_waveNames // S_waveNames is set by LoadWave
Variable i
for(i=0; i<numWavesLoaded; i+=1)
String name = StringFromList(i, listOfWavesLoaded)
Wave w = $name // Create wave list
ProcessWave(w)
endfor
return numWavesLoaded
End
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More