您的位置:首页 > 其它

读*.spa文件,比较靠谱的方法似乎还是,直接用UltraEditor打开二进制文件,找相关的位置并猜测...

2010-05-23 11:32 441 查看
首先 , filename = 'c:/Documents and Settings/User Name/My Documents/Spectral Sample.SPA' %包括路径名的文件名

然后 , fid = fopen(filename,'r'); %二进制格式打开, 并准备读取



同时, 用ultraEditor打开同一个谱图文件:



首先, 第1~18个字节代表了18个标识性字符, 'Spectral Data File', 可以用来作为判断该文件是否Nicolet *.spa格式的标识

其次, 第0x360H, 到0x36dH个字节, 也就是第864~877字节, 14个字节, 共14个字符代表'%Transmittance',即数据是透过率方式表达的.



当前的发现是:



1. fseek(fid,hex2dec('41c'),'bof'); spectrum=fread(fid,1868,'float32'); %在偏移量0x41c处读取1868个单精度浮点数, 得到谱图.

其中数据点数1868来自后面的搜索.



2. fseek(fid,576,'bof'); fread(fid,1,'single')

ans =

3.999639892578125e+003, 找到的是最大波数



3. fseek(fid,580,'bof'); fread(fid,1,'single')

ans =

3.991925964355469e+002, 找到的是最小波数



在找这两个关键波数的位置的时候, 用到了下面的scripts:



clc
filename='c:/Documents and Settings/User Name/My Documents/051109 sample B.SPA';

fid=fopen(filename,'r');
fseek(fid,hex2dec('484'),'bof');
spectrum=fread(fid,934,'double'); % 只是确认找到的谱图数据的位置而已
plot(spectrum,'r'); %此处的934, 不能再大, 但是却可以更小... 不见得是934个数据点...
frewind(fid);
data=0;
position=0;
flags=1;
counts=0;
loops=0;
Number_to_be_found=3999.63989;
%580=position, find: 3999.63989;
%584=poistion, find: 399.192596;% 1.928467;
data_format= 'single';

while flags

while ~feof(fid)
data=fread(fid,1,data_format);
%if ~isempty(data)
position=position+4;
%end
loops=loops+1;
if ~isempty(data)
if abs(data-Number_to_be_found)<0.005
'find'
data
position
loops
break
end
end
end

counts=counts+1;
if counts<=8
frewind(fid);
header=char(fread(fid,counts,'uchar')')
%fseek(fid,counts,'cof');
position=counts;
else
flags=0;
end
end
data
position
loops



其它,



4. 谱图文件名的位置: fseek(fid,hex2dec('23eb'),'bof'); fullfiname=char(fread(fid,260,'uchar')')可以得到



5. 关于谱图的波数和精度, 奇怪怎么是用文字的形式交代的

谱图的背景扫描的时间方面, 星期几: fseek(fid,hex2dec('32a'),'bof'); fullfiname=char(fread(fid,3,'uchar')')

月份: fseek(fid,hex2dec('32e'),'bof'); fullfiname=char(fread(fid,3,'uchar')')

日期: fseek(fid,hex2dec('332'),'bof'); fullfiname=char(fread(fid,2,'uchar')')

时刻: fseek(fid,hex2dec('335'),'bof'); fullfiname=char(fread(fid,8,'uchar')')

年份: fseek(fid,hex2dec('324'),'bof'); fullfiname=char(fread(fid,4,'uchar')')

时区: fseek(fid,hex2dec('343'),'bof'); fullfiname=char(fread(fid,11,'uchar')')





相邻两个数据点的 波数间隔

fseek(fid,hex2dec('37e'),'bof'); str2num(char(fread(fid,6,'uchar')'))



数据点的个数

fseek(fid,hex2dec('234'),'4c79'); fread(fid,1,'int32')



波数的最大值 和 最小值 之差 , 绝对值之后, 除以 波数间隔, 取四舍五入的结果, 再加1,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: