THE SPECTRUM VIEWER FILE FORMAT (.svf)
Spectrum Viewer can read a lot of files. Text, binary, you name it. Still I felt the need to create yet another proprietary file format. Why? When SV exits, it saves its state (including all loaded data sets) into the LastSession.svf file. When the program is restarted, it loads this file and the program comes back exactly the way you left it. As demands grew, so did the svf format, and finally it is mature enough to make its specs public. You can even use the svf format to store your own data, and not use Spectrum Viewer at all, but use your own programs to read it. In my opinion the format is very versatile. The general specs are:
The file can contain multiple data sets, all with x, y and z data (at present z data is ignored by Spectrum Viewer, it is read and saved, however). The data format is binary 32-bit float. Binary, so it reads fast (no need to convert strings to floats). I chose float over double because it halves the file size and memory usage, speeds up reading time and for most applications the double precision isn't needed anyway.
Each data set can have its own file path, axis names, graph name, data set name.
Each data set can have a text block with info about the data set (e.g. measure parameters). This text block can be seen (and edited) in the data set style window, in the info text box.
Each data set can have an own data block which will be ignored by SV. This data block can contain anything, raw data, measure parameters, whatever you want to put in there. It won't affect the display of the file in SV. The only thing you have to specify is the size of the data block. SV reads the data block, attaches it to the data set and saves it again when the data set is saved in svf format (so you won't lose the data block when saving to another file). Of course, this data block is only useful if you have written another program which knows what to do with it, like a calibration program.
The exact structure of the SVF file is described below. If you decide to use the format yourself, I have included SVF.h and SVF.c as well so you can get started right away.
The exact structure of a .svf file is as follows. First, there are the file parameters.
File version number, 4 chars. currently 0 0 0 1
Number of bytes to skip, unsigned int (4 bytes). Must be zero, unles you have a custom data block, then you have to put its size in bytes here.
Custom data block. Can be anything, as long as you give its correct size in the above parameter. SV will ignore this block and skip over it. This is the FILE data block, each data set can have its own custom data block as well.
XReverse, char, 1 byte, may be 1 or 0. If this is 1 the X-axis display will be mirrored.
YReverse, char, 1 byte, may be 1 or 0.
YRReverse, char, 1 byte, may be 1 or 0.
NrOfDataSets, int, 4 bytes.
Then, for each data set the following block:
Number of bytes to skip, unsigned int (4 bytes). Must be zero, unles you have a custom data block, then you have to put its size in bytes here.
Custom data block. Can be anything, as long as you give its correct size in the above parameter. SV will ignore this block and skip over it. This is the DATA SET data block.
DataPath, null-terminated string, max 255. If not required one 0 byte (which in fact is a string with zero length). Can be longer than 255, SV won't crash, but SV will chop off the string at 255 chars. DataPath is the physical path of the file name of the data set. It is used in the "Delete file from disk" menu command, and with the DDE "DSDelete"command. When 0, SV will fill in the name of the file opened. When specified, SV will use the specified name. This name can be different from the actual .svf file name this data set is in. This is used for example in the LastSession.svf file, where the data path will not point to the LastSession.svf file, but to its original file. When not sure what to put in this field, make it 0 and everything will be allright.
DataSetName, string, max 252. If not required one 0 byte. Can be longer than 252, but will be chopped off. This is the name that will appear in the name window. When 0, SV will put the file name in the name window
GraphTitle, max 255. If not required one 0 byte. Can be longer, etc.
XName, max 255. If not required one 0 byte. This is the name that will be given to the X-axis (like "Energy (eV)"). When a .svf file is opened, SV will look at the axis names of the first data set, and put them in place. When afterwards a data set is selected SV will automatically read the axis names and put them in place. This way you can display different data sets simultaneously, and always have the correct description on the axes. When 0, SV will leave the axes names as they were.
YName, max 255.
ZName, max 255. At present Z data is ignored by SV, it is read and saved, however. I've put Z data in here for future use.
DSInfo, max 1023. This is a text block which can be viewed (and edited) in the data set style window, in the info text block. Here you can put measure parameters which you need to be able to see when displaying the file in SV.
Hidden, char, 1 byte, may be 1 or 0. If this is 1, the file will be already hidden when opened.
Selected, char, 1 byte, may be 1 or 0.
RightYAxis, char, 1 byte, may be 1 or 0.
ZDataPresent, char, 1 byte, may be 1 or 0
NrOfDataPoints, int, 4 bytes
X[0], float, 4 bytes
Y[0], float, 4 bytes
if (ZDataPresent) Z[0], float 4 bytes
X[1], Y[1], Z[1], X[2], ...., Z[NrOfDataPoints-1].
If you're interested to use this format in your own programs, take a look at the SVF.h file and the SVF.c file.
If you are programming to write .svf files, you can debug your files in SV with the svf test mode. Set in the specview.ini file the value of "Show SVF file info when reading" to 1.