Reading Header and Data From The Same File

//  ReadHeaderAndData(pathName, fileName, extension)
//  Demonstrates how to open a data file to read header information using FReadLine
//  and then to load data from the file using LoadWave.
//  If pathName and fileName are not empty, they are expected to point to the data
//  file which will be loaded without any dialog.
//  If either pathName or fileName is empty (""), an Open File dialog is displayed.
//  If you are not familiar with symbolic paths, execute this:
//      DisplayHelpTopic "Symbolic Paths"
Function ReadHeaderAndData(pathName, fileName, extension)
    String pathName     // Name of symbolic path or "" to display dialog.
    String fileName         // Name of file or "" to display dialog. Can also be full or partial path relative to symbolic path.
    String extension            // e.g., ".dat" for .dat files. "????" for all files.
   
    Variable refNum
   
    // Possibly display Open File dialog.
    if ((strlen(pathName)==0) || (strlen(fileName)==0))
        Open /D /R /P=$pathName /T=(extension) refNum as fileName
        fileName = S_fileName           // S_fileName is set by Open/D
        if (strlen(fileName) == 0)      // User cancelled?
            return -1
        endif
        // fileName is now a full path to the file.
    endif
   
    // Read the header lines
    Open /P=$pathName /R refNum as fileName
    // Read header here using FReadLine
    Close refNum
   
    LoadWave/J/P=$pathName fileName
   
    return 0
End


For a fleshed-out example see http://www.igorexchange.com/node/5842#comment-9728

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More