Save Wave as General Binary
hrodstein
// SaveWaveAsGeneralBinary(pathName, filePath, dataType, byteOrder, w)
// Saves the wave's raw data only. This is of use to export to another program.
// This works on numeric waves only, not on text waves, DFREF waves, etc.
// NOTE: This overwrites the file if it already exists.
// Example:
// Make/N=128/S jack = sin(x/8)
// SaveWaveAsGeneralBinary("", "jack.bin", 0, 0, jack)
// This writes 4 bytes per point of single-precision floating point data for a total of 512 bytes.
Function SaveWaveAsGeneralBinary(pathName, filePath, dataType, byteOrder, w)
String pathName // Name of Igor symbolic path or ""
String filePath // Full path, relative path or file name relative to symbolic path
Variable dataType // 0 for default; See FBinWrite documentation for other types
Variable byteOrder // 0 for default; See FBinWrite documentation for other types
Wave w // The wave to save
Variable refNum
// First get a valid reference to a file.
if ((strlen(pathName)==0) || (strlen(filePath)==0))
// Display dialog looking for file.
String fileFilters = "Binary File (*.bin):.bin;"
Open/D/P=$pathName/F=fileFilters/M="Save wave to file" refNum as filePath
filePath = S_fileName // S_fileName is set by Open/D
if (strlen(filePath) == 0) // User cancelled?
return -1
endif
endif
Open/P=$pathName refNum as filePath
FBinWrite /F=(dataType) /B=(byteOrder) refNum, w
Close refNum
return 0
End
// Saves the wave's raw data only. This is of use to export to another program.
// This works on numeric waves only, not on text waves, DFREF waves, etc.
// NOTE: This overwrites the file if it already exists.
// Example:
// Make/N=128/S jack = sin(x/8)
// SaveWaveAsGeneralBinary("", "jack.bin", 0, 0, jack)
// This writes 4 bytes per point of single-precision floating point data for a total of 512 bytes.
Function SaveWaveAsGeneralBinary(pathName, filePath, dataType, byteOrder, w)
String pathName // Name of Igor symbolic path or ""
String filePath // Full path, relative path or file name relative to symbolic path
Variable dataType // 0 for default; See FBinWrite documentation for other types
Variable byteOrder // 0 for default; See FBinWrite documentation for other types
Wave w // The wave to save
Variable refNum
// First get a valid reference to a file.
if ((strlen(pathName)==0) || (strlen(filePath)==0))
// Display dialog looking for file.
String fileFilters = "Binary File (*.bin):.bin;"
Open/D/P=$pathName/F=fileFilters/M="Save wave to file" refNum as filePath
filePath = S_fileName // S_fileName is set by Open/D
if (strlen(filePath) == 0) // User cancelled?
return -1
endif
endif
Open/P=$pathName refNum as filePath
FBinWrite /F=(dataType) /B=(byteOrder) refNum, w
Close refNum
return 0
End
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
Thanks,
Ryan
February 26, 2018 at 06:06 am - Permalink
It is helpful to enclose the code in <igor> and </igor> tags for clarity.
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
February 26, 2018 at 08:45 am - Permalink
Theh waves have been pasted in and are auto named wave0 etc, so I step through them that way.
Any help is appreciated.
variable filenumstart, filenumstop
string filepathstring
string pathstring
string wavestring
variable i = 0
for(i=filenumstart;i<filenumstop+1;i+=1)
pathstring = "root:wave"+num2str(i)
wavestring = "wave"+num2str(i)
filepathstring = "C:destination:"+wavestring+".bin"
wave datasave = $pathstring
SaveWaveAsGeneralBinary("",filepathstring,0,0, datasave)
endfor // Execute body code until continue test is FALSE
end
February 26, 2018 at 04:11 pm - Permalink
This bit:
is wrong when pathName ="" and filePath is a complete file path; the dialog is invoked when it is not necessary.
I suggest you try this, instead:
variable filenumstart, filenumstop
string filepathstring
string pathstring
string wavestring
variable i = 0
for(i=filenumstart;i<filenumstop+1;i+=1)
pathstring = "root:wave"+num2str(i)
wavestring = "wave"+num2str(i)
filepathstring = "C:destination:"+wavestring+".bin"
wave datasave = $pathstring
//SaveWaveAsGeneralBinary("",filepathstring,0,0, datasave)
Variable refNum
Open refNum as filepathstring
FBinWrite refNum, datasave
Close refNum
endfor // Execute body code until continue test is FALSE
end
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
February 26, 2018 at 07:56 pm - Permalink