读*.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,
然后 , 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,
相关文章推荐
- ie无法直接打开xml 文件的解决方法:
- 关于创建Excel表格问题(保存至指定文件/弹出直接打开还是下载,并可以选择保存路径的对话框)
- android webview页面中的文件(apk,mp3或mp4,以及文本等)链接,选择被打开还是直接下载
- 绿色版PS关联psd文件直接打开方法
- Eclipse打开文件的时候会报Error opening the editor. 的解决方法 。
- 在Python常用模块I如何打开相关文件的方法
- python打开文件并获取文件相关属性的方法
- 让TXT文本等其他任意格式的文件,不在IE中打开,而直接下载的方法
- Eclipse打开Java文件,默认是否折叠相关位置的代码
- 双击扩展名为.EML的文件无法用OutLook Express直接默认打开的解决方法
- 在Python常用模块I如何打开相关文件的方法
- 文件下载 浏览器直接打开文件而不是保存 相关问题
- vi设置 打开文件直接跳到文件关闭时光标的位置
- JAVA文件下载,IE不提示下载,直接打开的解决方法
- 用C#编程从数据库中读取图片数据导进Excel文件的方法(如何从数据库中读取保存的文件,直接打开,中间不保存到本地)
- 文件使用二进制模式打开情况下的换行的方法
- 打开模拟器上app的文件位置方法
- MyEclipse中直接打开class文件的方法
- MyEclipse中直接打开class文件的方法
- 在matlab中把矩阵保存为二进制文件,在c中打开的方法