Reading Header and Data From The Same File
Posted February 13th, 2009 by hrodstein
// 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
