Re: fbinrecread' and f77 'write'

From: David Ian Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Mon, 5 Feb 2007 17:46:08 -0700

Clarification:

NCL's fbinrecread cannot read files produced by a Fortran binary write
using g77-compiled code on (we believe) any 64-bit architecture machine.
The problem is that g77 uses 8-byte control words (that both precede and
follow Fortran binary records). There is no compiler option to modify
this
behavior of g77. Currently, regardless of byte-order, NCL always
expects Fortran
binary data to use 4-byte control words. Also the files that NCL writes
always
have 4-byte control words regardless of the bit size of the OS or the
compiler used
to build it.

Other Fortran compilers on 64-bit operating systems that we have tested
so far
do use 4 byte control words and thus are compatible with NCL's binary
reading
and writing routines. These include the Portland Group Compiler on
Linux 64-bit,
xlf90 on IBM/AIX and f90 on IRIX 64-bit.

We are currently in the process of testing gfortran and g95 on Linux
64-bit.

Bottom line: NCL cannot read binary files produced by g77-compiled code
on 64-bit
systems and files written by NCL could not be read by such code. There
is no
workaround at present other than to use a different compiler or a
32-bit OS if
using g77. We intend to introduce options for specifying the number of
bytes in the control word on read and on write.

  -dave

On Feb 5, 2007, at 4:17 PM, Mary Haley wrote:

>
> FYI to all: we are looking into this problem. It involves in the way
> the "g77" compiler behaves on a 64-bit Linux system when it comes to
> reading and writing Fortran binary files. This behavior is different
> than how other compilers and g77 on other systems behaves.
>
> The work-around is to read the file from the same system it was
> written on. Meanwhile, we will probably add an option to the
> "setfileoption" procedure to account for this difference.
>
> I may post back here once this is finished.
>
> --Mary
>
> On Tue, 23 Jan 2007, Richard Neale wrote:
>
>> I am having trouble getting the expected behavior between
>> a f77 write and an ncl fbinrecread.
>>
>> For example the two following snippets of code (a WRAPIT'ed
>> f77 routine writing unformatted output and an ncl routine reading it)
>> gives the output at the bottom. Basically fbinrecread seems to insert
>> a
>> spurious zero at the start of the record and is not even able to read
>> any of
>> the two successive records??
>>
>> The problems have broken diagnostic code that was fine probably 2
>> ncl versions ago.
>>
>> Any help/ideas?
>>
>> Thanks
>> Rich
>>
>>
>> **f77 code**
>>
>> C NCLFORTSTART
>> SUBROUTINE EX_RBN (DIMS1)
>> CHARACTER*256 filename
>> INTEGER DIMS1(3)
>> C NCLEND
>> filename = "dims.bin"
>> open (11,file=filename,form="unformatted")
>> print*,'dims fortran ',DIMS1
>> write (11) DIMS1 ! dimensions
>> write (11) DIMS1 ! dimensions
>> write (11) DIMS1 ! dimensions
>>
>> RETURN
>> END
>>
>> ** NCL code **
>>
>> external EX_RBN "./ex_rbn.so"
>>
>> begin
>> dims = (/100,144,192/)
>> print("before dims = "+ dims)
>> EX_RBN:: ex_rbn(dims)
>> dims_out = fbinrecread("dims.bin",0,3,"integer")
>> print("after dims = " + dims_out)
>> dims_out = fbinrecread("dims.bin",1,3,"integer")
>> print("after dims = " + dims_out)
>> dims_out = fbinrecread("dims.bin",2,3,"integer")
>> print("after dims = " + dims_out)
>>
>> end
>>
>>
>> *Output
>>
>> mineral:diag/var_code/fortran>ncl < ex_rbn.ncl
>> Copyright (C) 1995-2006 - All Rights Reserved
>> University Corporation for Atmospheric Research
>> NCAR Command Language Version 4.2.0.a034
>> The use of this software is governed by a License Agreement.
>> See http://www.ncl.ucar.edu/ for more details.
>> (0) before dims = 100
>> (1) before dims = 144
>> (2) before dims = 192
>> dims fortran 100 144 192
>> (0) after dims = 0
>> (1) after dims = 100
>> (2) after dims = 144
>> fatal:fbinrecread: an error occurred reading the record control
>> words. Something is wrong with the FORTRAN binary file.
>> fatal:Execute: Error occurred at or near line 9
>>
>> --
>> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>> Richard Neale - Rm 304 - rneale_at_ucar.edu
>> http://www.cgd.ucar.edu/cms/rneale Climate Modelling Section, CGD,
>> NCAR
>> P.O. Box 3000, Boulder, CO 80307-3000
>> Tel (303) 497-1380 Fax (303) 497-1324
>> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk_at_ucar.edu
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Feb 05 2007 - 17:46:08 MST

This archive was generated by hypermail 2.2.0 : Tue Feb 06 2007 - 15:01:55 MST