[MITgcm-support] Error in reading the input files

Martin Losch Martin.Losch at awi.de
Tue Mar 2 07:40:16 EST 2010


Hi,
I might add that the I/O format of the MITgcm is _ALWAYS_ ieee big endian. (unless you use netcdf output)

David is right and you should use a compiler flag that does the conversion on a little-endian machine (most likely your case). If your compiler does not provide such a flag (e.g. g77), there is CPP-FLAG that you can use in the build options file, see e.g. tools/build_options/linux_ia32_g77, in particular the line
DEFINES='-D_BYTESWAPIO -DWORDLENGTH=4'

The first flag makes the code compile a byte-swapping routine, the second defines the length of a "word", so a number in your fields.
for exf_iprec = 32 in data.exf, you should do this in matlab (as an example)
fld = ones(nx,ny,nt); % forcing field
fid = fopen('myfile.bin','w','ieee-be');
fwrite(fid,fid,'real*4');
fclose(fid);

For more help you need to provide more details about your computer, compiler, etc.

Martin

On Mar 1, 2010, at 11:17 PM, David Hebert wrote:

> Akur,
> 
> I believe most (if not all) MITgcm build scripts default to big endian. Thus, usually when MITgcm is compiled on a little-endian machine some form of byteswapio flag is used (i.e., pgf90 -byteswapio ... for Portland group compilers). When you build MITgcm is this flag in your build script? If so than it will not read your little endian file correctly. Also, it will write a big endian file regardless of what the input file endian type.
> 
> Also, along those lines, your external Fortran code to test your binary file will not read big endian correctly unless you have a byteswapio compiler flag.  Are you using byteswapio flag for your external Fortran code? If not give that a try with big endian binary file and see if it works.
> 
> David
> 
> 
> 
> On 03/01/10 16:03, ankur gupta wrote:
>> Hello, 
>> 
>> I am trying to use Large&Yeager bulk formulation EXF package for computing heat and momentum fluxes at the surface of a 1X1 resolution ocean model. I have written my input files using matlab in single precision and little-endian. 
>> 
>> To check if the written data is in correct format, I used a simple fortran code to read the input files before providing it to MITgcm. Using unformatted, direct access, recl=N*4 (N is number of data points=nx_in*ny_in) I was able to read the input files correctly. Please note if I use big-endian to write my files the fortran code doesn't read it properly. I am using a linux machine and initially thought that big-endian should have worked. 
>> 
>> However when I run MITgcm and write the data (read by subroutine exf_interp_read) to a separate file I again get incorrectly formatted data. The exf_iprec is set to 32 in data.exf. 
>> 
>> Can anyone see where is the error, let me know if I should specify more of the configuration parameters I am using to help you trace the error. 
>> 
>> Regards,
>> Ankur
>> 
>> _______________________________________________
>> MITgcm-support mailing list
>> 
>> MITgcm-support at mitgcm.org
>> http://mitgcm.org/mailman/listinfo/mitgcm-support
>> 
>> 
>> 
> 
> -- 
> David A. Hebert
> Naval Research Lab
> Stennis Space Center, MS 39529
> david.hebert at nrlssc.navy.mil
> Phone: (228) 688-5846
> _______________________________________________
> MITgcm-support mailing list
> MITgcm-support at mitgcm.org
> http://mitgcm.org/mailman/listinfo/mitgcm-support




More information about the MITgcm-support mailing list