1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| function [ floatCAP ] = uint48le_to_CAP( mots )
% récupération de 3 mots uint16 en little endian avec un mots=fread(fid,3,uint16) classique
% routine inspirée de ci dessous:
% UINT64LE_TO_VAXD Converts from IEEE-LE (UINT32) to VAXD (double)
% This function takes a raw 32bit unsigned integer (little endian)
% and converts it into the equivalent floating point number it represents
% in the VAXF file format for floating point numbers. The VAXF format is
% the single precision format used with both the VAXD and VAXG
% double precision formats and files.
% <a href="http://www.opengroup.org/onlinepubs/9629399/chap14.htm#tagfcjh_20" target="_blank">http://www.opengroup.org/onlinepubs/...htm#tagfcjh_20</a>
%
% See also UINT64LE_TO_VAXG, UINT64LE_TO_VAXD, FREADVAXD, FREADVAXG
%% Define floating value properties for VAX architecture
% The generic equation for a floating point number is:
% (-1)^double(S) * (F+C) * A^(double(E)-B);
% Different operating systems and file formats utilize different values
% for A, B, and C. F, E, and S are computed from the appropriate bits in
% the number as stored on disk.
A = 2 ;%exposant base 2
B = 128 ;%Complément à 2 de l'exposant
C = 0.5 ;%biais de normalisation de la mantisse
%% Convert raw unsigned number into right answer
% Flip the upper and lower bits (based on how Vax data storage format)
% CAP <-----mot1-----><-----mot2-----><-----mot3----->
% IEEE-LE <-----WORD3-----><-----WORD2-----><-----WORD1----->
mot1 = mots(3);%
mot2 = mots(2);%
mot3 = mots(1);%
CAPInt = bitor( bitshift(mot2, 16), bitshift(mot1, 0) );
CAPInt = bitor( bitshift(mot3, 32), bitshift(CAPInt,0));%reconstruction des 48 bits
% Pull out the sign, exponent, and fractional component
% VAX FLOAT BYTES <-----WORD3----><-----WORD2-----><-----WORD1----->
% VAX FLOAT BITS 0123456789ABCDEF 0123456789ABCDEF 0123456789ABCDEF
% Sign Exp Fract SFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFEEEEEEEE
S = bitshift(bitshift(CAPInt , 0), -47); %)signe
E = bitshift(bitshift(CAPInt , 40,48), -40);%)exposant
F = bitshift(bitshift(CAPInt , 1,48), -9); % mantisse
% Construct the floating point number from SEF (Sign, Exp, Fract)
% Formula valid for non-zero values only (zeros fixed in next step)
% <a href="http://www.codeproject.com/KB/applications/libnumber.aspx" target="_blank">http://www.codeproject.com/KB/applic...libnumber.aspx</a>
% <a href="http://www.opengroup.org/onlinepubs/9629399/chap14.htm#tagfcjh_20" target="_blank">http://www.opengroup.org/onlinepubs/...htm#tagfcjh_20</a>
M = C+double(F)./1.099511627776e+12;%DACS Specific 1099511627776=2^40 pour normalisation de la mantisse
floatCAP = (-1).^double(S) .* M .* A.^(double(E)-B);%Generic
% Add in zeros (if E and S are zero, doubleVAXF should be set to zero)
zerosIndex = (E == 0 & S == 0);%logical index of all zeros
floatCAP(zerosIndex) = 0;
zerosIndex = (E == 0 & S == 1);%cas non défini
floatCAP(zerosIndex) = NaN;
end |
Partager