Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 25th, 2004, 08:30 PM
DSanborn3 DSanborn3 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Washington, D.C.
Posts: 5 DSanborn3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to DSanborn3 Send a message via Yahoo to DSanborn3
VB6: How To Read Data from Binary File in IEEE Floating Point, Little-Endian Format?

I have a proprietary binary file here that contains a variable called 'Hydroxyl #', seven sample titles (2, 5, 9, 12, 20, 23, 31 - these titles could just as easily be text, so they are probably stored as strings), and the associated float values for the variable (44.94, 46.17, 51.93, 54.08, 61.62, 63.75, 84.77). I have attached the zipped data file in 'Polyvl.zip'.

Below, I have also pasted a Matlab script that a long-since departed member of our company wrote to read the file. The script uses the 'fopen' command with the 'ieee-le' option (IEEE Float-Point, Little-Endian, bits not explicity specified).

My question is, how do I properly read (and also, display) this data properly in Visual Basic 6? I am currently using the 'Open ... For Binary Access Read ...' statement and the 'Input' statement to read the data into a Variant type variable. I am able to grab some of the data (Hydroxl #), but the rest looks like garbage.

Contact me at DSanborn3@hotmail, or DSanborn3 (at AIM, MSN, Yahoo) with additional questions or comments. TIA!

Regards,

Daniel

//-----Begin Matlab Script (read_da.m)---------------

function [a,spl_name]=read_da(fn);
% READ_DA -- read NIR NSAS data files.
%
% [a,spl_name]=read_da('filename');
% or
% [a,spl_name]=read_da;
%
% Will not work for full Vis/NIR range.
% Works for spectra transferred from pc to rs/6000 via binary ftp.
%
% See read_fda for reading full Vis/NIR range.

if nargin==0,
[fn,pt]=uigetfile('*.da','Select NSAS *.da file');
fn = fullfile(pt,fn);
end

inp=fopen(fn,'r','ieee-le');

nspec=0;
k=fread(inp,128,'char');

fseek(inp,2944,-1);
%
% loop for reading sample names
%
while ~feof(inp)
nspec=nspec+1;
da=k(65)+k(66)*256;
mo=k(67)+k(68)*256;
yr=k(69)+k(70)*256;
hr=k(71)+k(72)*256;
mi=k(73)+k(74)*256;
se=k(75)+k(76)*256;
spl_name(nspec,1:30)=[setstr(k(5:14))' sprintf(' %2g:%2g:%2g %2g-%2g-%4g',hr,mi,se,mo,da,yr)];
k=fread(inp,128,'char');
fseek(inp,(nspec+1)*2944,-1);
end;

frewind(inp);
a=zeros(nspec,700);
for i=1:nspec
k=fread(inp,2944./4,'float');

a(i,=k(33:732)';
end;
fclose(inp);

//-----End Matlab Script (read_da.m)-----------------
Attached Files
File Type: zip Polyvl.zip (174 Bytes, 130 views)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > VB6: How To Read Data from Binary File in IEEE Floating Point, Little-Endian Format?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap