SPC File Format
SPC File Format
and
Using GSPCIO
NOTE: This document describes the "new" SPC file format. The "old" format that was used in
SpectraCalc and LabCalc does not support multifiles or the Audit Log and has a 256 byte Main
header. However, GRAMS and the file I/O utilities must be capable of reading both formats.
A more detailed description of the SPC file format is available in the document "Galactic
Universal Data Format Specification." This document provides a guide for programmers to
implement data reading or data writing routines for files in Thermo Galactic SPC data file
format. The "official" description of the SPC file format is contained in the file SPC.H. These
documents are included in the Thermo Galactic SPC File Developer's Kit which can be
downloaded from the Thermo Galactic website
(www.thermogalactic.com/instruments/spcdata/spc_sdk.zip).
Table of Contents
SPC File Format.............................................................................................................1
Single Files and Multifiles .........................................................................................................................1
SPC File Sections .....................................................................................................................................1
Main Header Block .................................................................................................................................2
Data Block ..............................................................................................................................................3
XY Data Block.................................................................................................................................3
Subheader Block.............................................................................................................................3
Directory Block................................................................................................................................4
Log Block................................................................................................................................................4
Log Header Block ...........................................................................................................................4
Log Data Block................................................................................................................................5
ASCII Log Text Block......................................................................................................................5
Using GSPCIO................................................................................................................6
Defining GSPCIO for Use in Programs ....................................................................................................6
Reading File Properties ............................................................................................................................6
File Type.................................................................................................................................................6
X and Y Values.......................................................................................................................................6
X Axis Limits...........................................................................................................................................7
Axis Labels .............................................................................................................................................7
Subfiles...................................................................................................................................................7
Audit Log ................................................................................................................................................7
Creating SPC Files ...................................................................................................................................8
Y-only Single Files..................................................................................................................................8
XY Single Files .......................................................................................................................................8
Y-Only Multifiles .....................................................................................................................................9
XYY Multifiles .........................................................................................................................................9
XYXY Multifiles.....................................................................................................................................10
Disk Files..............................................................................................................................................10
Reading from Disk ........................................................................................................................10
Writing to Disk...............................................................................................................................11
Thermo
The Y-only file is the standard format. Y-only files have X values that are equally spaced. A Yonly file stores only the Y data, with the starting and ending X-axis limits stored in the header.
(With this information, GRAMS and other Thermo Galactic products can calculate the X value
of any data point in the file "on-the-fly.") The X-axis limits are called the Frequency First Point
(ffp) and Frequency Last Point (flp).
The XY file has X values that are not equally spaced. In this case, the X and Y values are both
stored (two arrays of data points, one array for the Y values and a second array for the
corresponding X values). The ffp/flp limits are ignored.
A multifile is simply a file with more than one spectrum (subfile) stored in it. There are three basic
types of multifiles:
Y-Only All of the subfiles have the same evenly spaced X values. Only the Y values are
stored.
XYY
All of the subfiles have the same unevenly spaced X values. The X values are stored
once and the Y values are stored for each subfile.
XYXY
Thermo
page 1
Data Type
Description
byte
byte
byte
char
long
double
First X coordinate
15
double
Last X coordinate
23
long
Number of subfiles
27
byte
28
byte
29
byte
30
byte
31
long
Compressed Date:
minutes= 6 bits
hour= 5 bits
day= 5 bits
month= 4 bits
year=12 bits
35
char * 9
43
char * 9
52
word
54
float * 8
Spare
86
char * 130
Memo
216
char * 30
Thermo
page 2
246
long
250
long
254
byte
255
byte
Calibration level + 1
256
word
258
float
262
char * 48
Method file
310
float
314
long
Number of W planes
318
float
W plane increment
322
byte
324
char * 187
Reserved
Data Block
The Data Block is the body of the file containing the actual trace data.
1. For each subfile, a 32 byte subheader
2. All of the X coordinates of the subfiles, if appropriate
3. All of the Y values
XY Data Block
For XY type single files and XYY Multifiles, the X axis data are stored in a block following the Main
Header block and before the Subheader Block as single precision floats.
Subheader Block
Each subfile has a 32 byte subheader block. This block exists even for single files.
Byte #
Data Type
Description
byte
char
word
float
float
13
float
17
long
21
long
25
float
W axis value
29
char * 4
Reserved
Thermo
page 3
For XY single files and XYY Multifiles, the Y data are stored after each subfile header. They can
be stored in one of two formats:
q
q
For XYXY Multifiles, the data for each subfile is stored with all of the X coordinates (as singles)
followed by all of the Y values in one of the above formats.
The SPC file format allows for the handling of 4-dimensional data. This is done using the W axis,
which is tracked as follows:
1.
In the Main header block are parameters specifying the number of W planes, the W increment,
and the W axis units.
2.
The subfile headers then have a parameter setting the W value for that subfile.
3.
The total number of subfiles are then divided by the number of W planes and consecutive
subfiles are "bundled" in each W plane. This means that the total number of subfiles must be
an even multiple of the number of W planes.
For example, if there are 5 W planes and 20 subfiles, each block of 4 subfiles will belong to a W
plane and will each have the same W value.
Directory Block
For XYXY Multifiles, this block contains the offset pointers for each subfile.
Log Block
The Log Block consists of three parts:
q
q
q
Data Type
Description
Long
Long
Size of the memory block occupied by the Log block = the Log
block size rounded-up to the nearest even multiple of 4096
Long
11
Long
15
Long
19
Char * 44
Reserved
Thermo
page 4
Main Header
[XYY X Coordinates]
Subfile Header
[XYXY Subfile X Values]
Subfile Y values
..........
Subfile Header
[XYXY Subfile X Values]
Subfile Y Values
[Subfile Directory Block]
Log Block Header
[Binary Log Block]
Audit Log Block
Figure 1. Diagram of SPC File Structure.
Thermo
page 5
Using GSPCIO
This tutorial gives basic information and tips on using the utility in applications. All of the code
examples are in Visual Basic. They assume that suitable variables have been declared and set to
valid values. The methods, properties, and events of GSPCIO are described in detail in the Help
file GSPCIO.CHM.
Note that index variables for the numbers of points and subfiles should be declared as Long to
handle the largest allowed values.
X and Y Values
The Y values are acquired using the call SPCIO.YPoints. Getting the X values is more complicated
since the call used depends on whether the file is Y-only or XY. Therefore, the following code must
be used:
pts = SPCIO.NumPoints
If SPCIO.FileType = spcFileTypeEven then
FFP = SPCIO.FirstX
FLP = SPCIO.LastX
For i = 0 to pts - 1
X(i) = FFP + i * (FLP FFP) / (pts-1)
next I
else
X = SPCIO.XPoints
FFP = X(0)
FLP = X(pts-1)
end if
Note that the X and Y arrays must be dimensioned from 0 to the number of points1.
Thermo
page 6
X Axis Limits
The starting and ending X-axis limits of a spectrum are read using the SPCIO.FirstX (= ffp) and the
SPCIO.LastX (= flp) methods.
Note that for XY files, these values do not necessarily correspond to the actual X-axis limits. In this
case, you can get the actual limits by reading the file's X array (using SPCIO.XPoints) and reading
th
the values of the 0 and last elements of the X-axis array. For XYXY Multifiles, it is necessary to
scan through all of the subfiles and get the outermost X limits (when doing so, be sure to handle the
data running from both low to high and high to low).
Axis Labels
There are two basic types of axis labels in an SPC file: a "standard" label defined by a numerical
code in the Main file header, and a "custom" label defined by a string in the Main header block.
Because the two values can be set independently, you cannot count on the one not being used to
be null. The following code gets the X-axis type code and label:
If SPCIO.XLabel <> SPCIO.XCustomLabel then
XType = SPCIO.XType
XCustomLabel =""
Else
XType = 0
XCustomLabel = SPCIO.XCustomLabel
End If
Subfiles
GSPCIO numbers the subfiles in a Multifile from 0 to the number of subfiles 1. Each subfile
actually has two Z values: a starting "time" and an ending "time". This was to allow for a scan taking
a finite period. The subfiles are accessed as follows:
NumSubs = SPCIO.NumSubfiles
For i = 0 to NumSubs-1
SPCIO.SubfileIndex = i
ZStart = SPCIO.ZStart
ZEnd = SPCIO.ZEnd
Next i
Audit Log
The Audit Log section of the SPC file serves two functions:
1.
To record instrument and data acquisition information for use in processing the data
2.
Because GSPCIO does not have a call to return the number of lines in the Audit Log, you need to
acquire the information in a loop until an error condition occurs. When reading the Log text, you
need to specify the line number being read.
i = 0
Do While SPCIO.GetLogLine(i, Text(i)) <> -1
LineLen = SPCIO.GetLogLine(i, Text(i))
i = i + 1
Loop
The Log text can also be read-in all at once and then parsed by looking for the <CR><LF> line
delimiters. Note that you have to check on both characters because it is possible for them to be in
reversed order in the file.
Thermo
page 7
NumChars = SPCIO.LogTextSize
LogString = SPCIO.LogText
i = 0
j = 0
Do While i <= NumChars
i = i+1
Char = Mid$(LogString,i,1)
If (Char<>vbCr and Char<>vbLf) then
Text(j) = Text(j) & Char
Else
j = j+1
End If
Loop
To write to the Audit Log, you just keep adding lines. GSPCIO automatically updates the pointer
information in the Log block header.
For i = 0 to NumLines
SPCIO.AppendLogLine LogText(i)
Next i
XY Single Files
For XY files, the X axis values must be explicitly passed. To facilitate future use of the file, it is
recommended that the First and Last X values be set to the corresponding values in the X axis
array.
SPCIO.CreateSPC spcFileTypeXYY
SPCIO.FirstX = X(0)
SPCIO.LastX = X(pts-1)
SPCIO.AddPoints Y,X
Thermo
page 8
Y-Only Multifiles
To create Multifiles, you successively add each subfile. You must also set the Z order type and Z
values. The Z axis type can be one of the following:
q
q
q
ZTypeEven: The subfile Z values are evenly spaced. Only the first Z value and Z Increment
are used.
ZTypeOrdered: The subfile Z values are either all ascending or descending, but do not have to
be even.
ZType Random: Any Z values are allowed for any subfile.
Note that the subfile numbers are indexed starting at 0. Also, a null placeholder is passed in the X
axis field of the GSPCIO call.
SPCIO.CreateSPC spcFileTypeEven
SPCIO.FirstX = FFP
SPCIO.LastX = FLP
SPCIO.ZIncrementTypeDefault = ZType
ReDim Y(0 to NumPoints-1)
For i = 0 to NumSubfiles-1
RS.AbsolutePosition = i+1
SPCIO.OpenBlob RS.Fields("Trace").Value
Y = SPCIO.YPoints
SPCIO.AddSubfile Y, vbNull, ZValues(i), ZValues(i)
Next i
XYY Multifiles
To generate an XYY Multifile, you must explicitly pass the (global) X axis array. In the sample
below, the X axis array must be the same for each source file. It is re-read in each pass of the loop
for convenience.
SPCIO.CreateSPC spcFileTypeXYY
SPCIO.ZIncrementTypeDefault = ZType
ReDim Y(0 to NumPoints-1)
ReDim X(0 to NumPoints-1)
For i = 0 to NumSubfiles-1
RS.AbsolutePosition = i+1
SPCIO.OpenBlob RS.Fields("Trace").Value
Y = SPCIO.YPoints
X = SPCIO.XPoints
SPCIO.AddSubfile Y, X, ZValues(i), ZValues(i)
Next I
SPCIO.FirstX = X(0)
SPCIO.LastX = X(NumPoints-1)
Thermo
page 9
XYXY Multifiles
For XYXY Multifiles, the X data is different for each subfile, but must always be in the same
orientation. This means that the data arrays must be re-dimensioned for each source file. The
outermost points must be determined when scanning through the loop. This is incorporated into the
file generation loop here, but it could also be made a separate scan through the data.
SPCIO.CreateSPC spcFileTypeXYXY
SPCIO.ZIncrementTypeDefault = Ztype
For i = 0 to NumSubfiles-1
RS.AbsolutePosition = i+1
SPCIO.OpenBlob RS.Fields("Trace").Value
NumPoints = SPCIO.NumPoints
ReDim Y(0 to NumPoints-1)
ReDim X(0 to NumPoints-1)
Y = SPCIO.YPoints
X = SPCIO.XPoints
SPCIO.AddSubfile Y, X, ZValues(i), ZValues(i)
If i = 0 Then
FFP = SPCIO.X(0)
FLP = SPCIO.X(NumPoints-1)
End If
Disk Files
Reading from Disk
GSPCIO can also be used to read an SPC file directly from disk. In this case, it is necessary to
validate that the file is in SPC format. An error code is returned if it is not.
On Error Resume Next
SPCIO.OpenFile FileName
ecode = Err.Number
On Error GoTo 0
Select Case ecode
case 0
MsgBox "This is a valid SPC file. You may proceed."
case 1
MsgBox "Unable to open file. File does not exist or" _
& " you do not have rights to it."
case 3
MsgBox "This file is not in SPC format, but is a recognized" _
& " spectrum file that can be converted."
End Select
Thermo
page 10
Writing to Disk
Either a single (sub)file or an entire Multifile can be saved to disk:
SPCIO.SaveFile FileName, SubfileIndex
If the subfile index = -1, then the entire Multifile is saved.
Thermo
page 11