Code covered by the BSD License  

Highlights from
GSTools

4.88889

4.9 | 10 ratings Rate this file 17 Downloads (last 30 days) File Size: 223 KB File ID: #9938

GSTools

by Kris De Gussem

 

09 Feb 2006 (Updated 19 Aug 2009)

A set of matlab functions to read, write and deal with .spc spectra and spectral descriptions

| Watch this File

File Information
Description

GSTools v0.4.3

This toolbox is an implementation to open and save SPC-spectra in matlab.

Additional routines are supplied as well: e.g.:
- GSImportspec: loads all SPC-files in a map
- GSDendrogram: this is to be used as a supplement to the matlab's toolbox function Dendrogram. GSDendrogram allows the user to put coloured labels with the samples names under the dendrogram. properly are added.
- BTree class: a binary tree implementation, which offers the user to easily inspect the different items in a list, as well as the positions of these different items. This combined approach makes it easy to work with numeric arrays and stringlists, such as spectral descriptions.

A PDF with detailed information on the usage (including some sample code) is supplied in the zip-archive.

GSTools is also included in the Biodata toolbox (doi: 10.1016/j.chemolab.2008.08.003).

Required Products Statistics Toolbox
MATLAB release MATLAB 6.5 (R13)
Other requirements Statistics toolbox is only required in order to make dendrograms.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (14)
18 Jul 2012 Uur

I tried this:

x = 1:0.1:100;
y = sin(x);
file = [x ; y]';
xlswrite('file.xls', file);

fread = xlsread('file.xls');
fX = fread(:,1); fY = fread(:,2);

GSSpcWrite ('newFile.spc', y, x) -> Works!

GSSpcWrite ('newFile.spc', fY, fX)
??? Error using ==> GSSpcWrite>CreateSPCFileFromMatrices at 217
Length of axis and number of spectral channels do not correspond.

Error in ==> GSSpcWrite at 189
CreateSPCFileFromMatrices (f, spectra, axis, logtxt, logbin, options);

How can I overcome this?

17 Jul 2012 Uur

Hi, very useful tool for spectroscopists.

However I could not use it properly, I think.

When I generate x and y axis randomly, I can write to SPC well. But When I try to read from XLS and write to SPC, I get the error "Length of axis and number of spectral channels do not correspond." eventhough the size of my data are the same.

My input was GSSpcWrite ('spec.spc', y,x)

So where do I make wrong?

greetings.

22 May 2012 Chun Cai

First thanks for the great work. After using this toolbox for a while, I have found 3 bugs and have fixes.

- Problem: (GSSpcRead v0.4.3), For a multifile SPC file when using this option:
[data,xaxis,auditlog]=GSSpcRead('c:\tmp\test.spc',0);
Error using zeros Out of memory. Type HELP MEMORY for your options.error.

Solution: Change line 437 from
data = zeros (l,Specdata.spectra(1).data); %preallocation for speed
to
data = zeros (l,length(Specdata.spectra(1).data)); %preallocation for speed

- Problem: (GSSpcRead v0.4.3) For Horiba .spc file, the log information (last line is empty, error)

Solution: change line 403 from
if (~isempty(T{1}))
to
if (~isempty(S)) && (~isempty(T{1}))

- Problem (GSSpcWrite v0.4.3)
Uneven spaced x-axis is ignored, and generated SPC is even spaced.
Line 320 range function - if input is row vector, then no range (just 0s)

Solution: change
if range(diff) > 1E-8
to
if range(diff(:)) > 1E-8

28 Apr 2011 Larry Weber

I found an error in GSSpcWrite.m . It outputs the xtype, ytype, and ztype to the header as a string instead of the correct single byte binary format. This is especially bad if the string has more than one byte since the rest of the header will get messed up.

The fix is to change lines 578 through 592 to the following code which simply converts the string to a single binary byte.

Thanks to Kris for making this very helpful set of routines available to us.

if isfield (spectra, 'xtype')
ThisSpcHdr.fxtype = uint8(str2double(LocateItem (spectra.xtype, Types.X, 2))); %%std%%%BYTE: Type of X units
else
ThisSpcHdr.fxtype = 13; %%std%%%BYTE: Type of X units
end
if isfield (spectra, 'ytype')
ThisSpcHdr.fytype = uint8(str2double(LocateItem (spectra.ytype, Types.Y, 2))); %%std%%%BYTE: Type of Y units
else
ThisSpcHdr.fytype = 0; %%std%%%BYTE: Type of Y units
end
if isfield (spectra, 'ztype')
ThisSpcHdr.fztype = uint8(str2double(LocateItem (spectra.ztype, Types.X, 2))); %%std%%%BYTE: Type of z units
else
ThisSpcHdr.fztype = 0; %%std%%%BYTE: Type of Z units
end

15 Dec 2010 Joseph

Oops, I'm sorry. I was inputting the wrong compatibility. Never mind.

15 Dec 2010 Joseph

This is exactly what I was looking for! Unfortunately, when I try to import multiple files, I get the following error:

EDU>> GSImportspec()
Warning: Multifile flag is set. But SPC-file does not contain multiple spectra.
> In GSSpcRead at 236
In GSImportspec at 245
??? Subscripted assignment between dissimilar structures.

Error in ==> GSImportspec at 245
spectra(i) = GSSpcRead (spcfiles(i).name, -1, 0);

26 Oct 2009 Cameron Bowles

I found an error for opening multifiles using GSSpcRead.m.

line 437 is;
data = zeros (l,Specdata.spectra(1).data);

and it should be;
data = zeros (l,length(Specdata.spectra(1).data));

Other then that I have had no problems, a great piece of code, good work Kris

26 Oct 2009 Cameron Bowles

fixed-point signed fractions,

I ran into one last problem, the exponent values in the headers/subheaders are in char form, meaning that if they are between 129 - 255, then they are actually between -127 to -1, or at least they are in the files I am reading in.

this causes the Y-axis to be incorrectly scaled, the fix I put in for this is in GSSpcRead; line 689, I inserted the following check loop at 689;

if YScalingExp > 128
YScalingExp = YScalingExp-256;
end
then the file should continue
CurrSpec = ........

I assume the process would be the same for the 16 bit input integers, in which case you would have to also put that check into line 675.

20 Jun 2008 matt o'brien

fantastic bit of code, works better than the old GRAMS converter ive been using until now!

03 Feb 2008 Pall Thordarson

Just downloaded it to convert SPC Raman data and it works perfectly! Noted a small error in the manual on page 2: plot (SData.xaxis, data);
doesn't work, just change to:
plot (SData.xaxis, Sdata.data); and it works fine.

05 Sep 2007 Gerbe van Dreumel

Use it for importing multi-dimensional spectra: and it works perfect!

13 Nov 2006 Dominique Bertrand

I needed to import SPC files and it works immediately.

06 Sep 2006 Rich Williams

Haven't used it for .spc files, but it includes an easy to use BTree class. Note that the @BTree\private\DoCompare.m method will fail upon unsigned types unless you replace the line

tmp = item - value;

with

tmp = (item > value) - (item < value);

12 Apr 2006 Rachel Rohde

I have only used this for reading in an .spc file. It worked great. It even plots the spectra so you know it was loaded properly.

Updates
13 Feb 2006

license added in zip-file

15 May 2006

Important bugs in GSSpcRead and GSSpcWrite are fixed. Functions now correctly interprete flags in the headers of the SPC-files.

20 Jun 2006

bug fixes, code optimisation and support for old SPC-file format

10 Jul 2006

User can now set the axis types in GSSpcWrite

19 Sep 2006

fixed a small bug in BTree when using unsigned data types (thanks to Richard Williams)

11 Oct 2006

code cleaning

30 Jul 2007

Support for multi-dimensional spectra

06 Aug 2007

minor update / code improvement

19 Aug 2009

dual licensed: added BSD license

Contact us