现在的位置: 首页 > 综合 > 正文

我得意地笑: 搞定了, 哈哈 如何读取Thermo Scientific Nicolet Omnic *.spa二进制格式的谱图文件中的数据

2013年10月12日 ⁄ 综合 ⁄ 共 1343字 ⁄ 字号 评论关闭

 

 

时间是, 2010年5月23日 16:08分, 星期天

 

用了两天时间, 这次主要是借助工具自己破解的.

 

上次搞Perkin Elmer的 *.sp 是借助了现成的matlab代码变成VBA的

 

哈哈

 

现在存在的问题主要是, 读取谱图时候的偏移量, 对于不同的*.spa谱图文件而言, 并不是一个固定值

 

比如, 三个谱图中, 就有两个不同的偏移量,

 

0x488h, 0x41ch

 

这说明, 跳转的过程中, 利用了某种逻辑规则, 让人稍微有些郁闷...

 

0x41ch是文件没有做过修改的原始谱图的偏移量

 

0x488h则不是一个固定的偏移, 是文件被修改之后, 修改的信息添加在谱图数据之前, 导致偏移量增加

 

因此, 只需考虑0x41c h的偏移就可以了

 

代码如下:

 

clc
filename='c:/Documents and Settings/User Name/My Documents/Spectral File.SPA';
fid=fopen(filename,'r');
% Find the points number
fseek(fid,hex2dec('234'),'bof');
Number_of_DataPoints=fread(fid,1,'int32');

%Find the maximum and minimum of Wavenumber (cm-1) range
fseek(fid,576,'bof');
Maximum_Wavenumber=fread(fid,1,'single');
Minimum_Wavenumber=fread(fid,1,'single');
Interval=(Maximum_Wavenumber-Minimum_Wavenumber)/(Number_of_DataPoints-1);
Wavenumber=linspace(Minimum_Wavenumber,Maximum_Wavenumber,Number_of_DataPoints).';
Wavenumber=flipud(Wavenumber);
%Find the Y-Axis data type: %Transmittance or Absorbance
fseek(fid,hex2dec('360'),'bof'); Y_Label=char(fread(fid,14,'uchar')');
% How to define the offset for spectral data still remains unresolved.
fseek(fid,hex2dec('41c'),'bof');
spectrum=fread(fid,Number_of_DataPoints,'single');%'double'); % float64, %real*8
figure(1),plot(Wavenumber,spectrum,'r'); set(gcf,'color','w');
set(gca,'xdir','rev','xcolor','b','ycolor','b','xlim',[round(Minimum_Wavenumber),round(Maximum_Wavenumber)]);
xlabel('Wavenumber /cm^{-1}'); ylabel(Y_Label);

抱歉!评论已关闭.