Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: fopen(machineformat=vaxd)
Date: Mon, 20 Oct 2008 01:11:01 +0000 (UTC)
Organization: Boeing
Lines: 55
Message-ID: <gdglr5$jb1$1@fred.mathworks.com>
References: <gdcld5$2jj$1@fred.mathworks.com> <gdd73e$71t$1@fred.mathworks.com> <gddq4p$k2t$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1224465061 19809 172.30.248.38 (20 Oct 2008 01:11:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 20 Oct 2008 01:11:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: news.mathworks.com comp.soft-sys.matlab:496135


"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <gddq4p$k2t$1@fred.mathworks.com>...
> Thanks James!
>  
> > I may be able to write some custom code for you ... I just did something similar on another newsgroup thread recently. Is the file just a pure binary file with only D-FLOAT numbers? How many per record? What system are you reading these on? Do you know if your system is big-endian or little-endian?
> 
> It would be a big hack!

I don't think so. At least not based on what you have written so far. Like I wrote earlier, I have already done something very similar quite recently.

> I'm working with C3D files, which contain a section with mixed CHAR, INT8, UINT16, FLOAT32.
> Afterwards a big block of binary records is following and finally **any** kind of supplemental data are allowed.
> 

The only problem you seem to have is the D-FLOAT stuff. 
All of the other variables I assume you can still read 
in OK, as long as you get the endian convention OK. 
The strategy I am proposing is to pick the appropriate 
endian for fopen, then read in the data using fread. 
The D-FLOAT stuff will of course read incorrectly as 
an IEEE double, but I can write a function to manipulate 
the bits after you read in the value to convert them 
from a D-FLOAT format to an IEEE double format. I am 
quite familiar with both and this should not be too 
difficult. D-FLOAT only has 8 bits for exponent and 
55 bits for mantissa, whereas IEEE double has 11 bits 
for exponent and 52 bits for mantissa. The range of 
a D-FLOAT is less than a IEEE double, so the only tricky 
part will be the rounding from 55 bit mantissa down 
to a 52 bit mantissa. If MATLAB somehow screws up the 
floating point bits on the fread operation so you don't 
get the exact bit pattern on the fread, you could always 
read them in as int64 or uint64 and then do the bit 
conversion on that instead. 

Alternatively, you could read in the file in native format, and then use swapbytes to do the endian stuff manually.

Just to be clear, D-FLOAT is a 64-bit double precision floating point format, whereas F-FLOAT is a 32-bit single precision floating point format. You wrote FLOAT32 above. Was this what you are assuming is D-FLOAT?

> I have about trial 20.000 files and assume 20% of them use the VaxD format.
> 
> I'm enormously surprised that Matlab has removed this important feature from FOPEN! It worked since Matlab 4 (or even earlier), you find the VAXD-Format in Octave and Scilab. Unfortunately, I cannot find any documentation for this loss of features on the Mathworks web docs.

Yes, this is a bit surprising. Since they already had this capability, why give it up? I am not familiar with Octave or Scilab. Are they easy to install & run so I can generate some test files on my own?

> By the way, where do I find the documentation for former releases?
>

I don't think they maintain documentation for past releases on their website.
 
> So the best solution for me would be a conversion in 6.5.1: Read in VAXD and develop a function to write in little-endian. That's no fun.
> 

The endian part is the easy part.

James Tursa