#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Location
    Washington, D.C.
    Posts
    5
    Rep Power
    0

    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

IMN logo majestic logo threadwatch logo seochat tools logo