[MITgcm-support] Question about .bin files

Lucas Merckelbach lmm at noc.soton.ac.uk
Thu Mar 13 10:53:48 EDT 2008


Hi Elja,

> Therefore, I would like to adapt the topography-file (topog.bin) 
> -and the other .bin files- to the situation on this moon. Unfortunately, 
> I do not know how to proceed. From the manual (page 151), I learned that 
> the files are 'assumed to contain 64-bit binary numbers'. However, when 
> I try to load the file in Matlab, it does not work, properly.

Two things that can cause trouble: the size: 32 or 64 bit and the order of 
bits: little or bigendian. When reading a binary, you have to make sure 
that file and hardware agree on this as the endian issue is hardware 
dependent. When reading a binary (and writing is similar) with matlab you 
can specify the size and also the endianess. I suggest to have a look at 
any of the examples that come with the code and look for a file gendata.m. 
This will contain something like

ieee='b'
fid=fopen('Qbot.bin','w',ieee); fwrite(fid,Qbot,'real*8'); fclose(fid);

ieee can be 'l' or 'b', meaning little endian or big endian respectively. 
If not specified, it uses the machine native endianess, which may be not 
the one your file is in. Also make sure that if you create your own 
binaries, you make them for the machine you are going to run the model on, 
as the model should also be able to read the file...

I don't use matlab myself, but you should be able to recreate the binary 
files using the corresponding gendata.m script. These prescribe the 
endianess.

Good luck,
lucas



More information about the MITgcm-support mailing list