Save Wave as General Binary

// 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

I am trying to utilize this code snippet to save a large number of binary files in a routine. I tried going through the IGor binary as well, but I get the same problem, I want to auto name the files and skip dialog. In this routine even when I name the file explicitly I still get the save dialog box, which doesn't help when trying to work on several thousand spectra to save... How would I go about using this (or any of the other save functions).

Thanks,
Ryan
Please post the code that you're using so we can help you.

It is helpful to enclose the code in <igor> and </igor> tags for clarity.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
Hi sorry for not putting the code in in the first place. I have tried variations where I put the igor symbolic path (root:wave etc) in the right place, but that doesn't seem to help.
Theh waves have been pasted in and are auto named wave0 etc, so I step through them that way.
Any help is appreciated.

Function SaveBinaryBlueSpectra(filenumstart,filenumstop)
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
I think you're encountering a bug in the code snippet.

This bit:
    if ((strlen(pathName)==0) || (strlen(filePath)==0))


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:

Function SaveBinaryBlueSpectra(filenumstart,filenumstop)
    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.

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More