[MITgcm-support] Question about .bin files

Martin Losch Martin.Losch at awi.de
Thu Mar 13 11:31:51 EDT 2008


Hi Elja,

Lucas's suggestions are very good. I might add, that you can specify  
both 32bin and 64bit input files. Just make sure the flags in the  
model are set appropriately. If you set readBinaryPrec=32, in  
namelist PARM01 in "data" (which is the default I think), then all  
your input files have to be 32-bit. If you set readBinaryPrec=64,  
then you'll have to specify 64bit input files. (there's also a  
writeBinaryPrec which works the same way. the *.meta files of the  
output will tell you what the precision of the output is, if you are  
not sure).

in Matlab this can look like this:
% reading topography (look at the value of readBinaryPrec in data, or  
just try it out)
nx=?; ny=? % you have to know those in advance, have a look at  
verifcation/${yourexample}/code/SIZE.h
if 32bit
fid=fopen('topography.bin','r','b'); topog=fread(fid,[nx  
ny],'real*4'); fclose(fid); % for 32bit
else
fid=fopen('topography.bin','r','b'); topog=fread(fid,[nx  
ny],'real*8'); fclose(fid); % for 64bit
end

% now create your topography (for an ocean in z-coordinates):
h = -1000*ones(nx,ny); % constant depth of 1000m meters without  
continents, substitute what you want here
% 32bit
fid=fopen('topography.32bit','w','b'); fwrite(fid,h,'real*4'); fclose 
(fid);
% 64bit
fid=fopen('topography.64bit','w','b'); fwrite(fid,h,'real*8'); fclose 
(fid);

Martin

BTW, I find it cool that you use this model for simulating the ocean  
on Europa; can you send me a figure about that (project logo or  
something like that), so that I can convince my bosses what a great  
universatile model the MITgcm is (o:

On 13 Mar 2008, at 15:53, Lucas Merckelbach wrote:

> 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
> _______________________________________________
> MITgcm-support mailing list
> MITgcm-support at mitgcm.org
> http://mitgcm.org/mailman/listinfo/mitgcm-support




More information about the MITgcm-support mailing list