From: "G. Hugh SONG" <ghsong@\"Spamspoiler\"kjist.ac.kr>
Subject: Internal IO bug in g77? (was Re: g77's 8-byte record descriptor)
Date: 1998/10/18 [thread overview]
Message-ID: <70cf6o$4co$2@news.kjist.ac.kr> (raw)
In-Reply-To: y6hfx4pgwh.fsf@tweedledumb.cygnus.com
Craig Burley wrote:
> Toon Moene <toon@moene.indiv.nluug.nl> writes:
>
> > What I can clarify is that "decision" is the wrong word to use here - we
> > detected the incompatibility (not being able to read unformatted files
> > produced by a Dec Fortran compiled program in a g77 compiled one (on
> > Alpha/DEC Unix) and vice versa) far too late to do anything on it.
>
> Some background info might be appropriate here. Most questions about
> g77 and I/O facilities are really questions about libf2c, since g77
> just uses that. (But it's nice to see that so many questions about
> libf2c on c.l.f are phrased as questions about g77, anyway; there
> was a time, even while g77 was available, that that wasn't true.)
>
> libf2c "happened" to pick a type for the record header that became
> 8 bytes, not 4, on some (or all) OSes on the Alpha, and probably
> on other machines as well.
>
> It's true we're loathe to make gratuitous incompatible changes to
> g77, from one version to the next, for the same machine/OS combo,
> especially in a case where the only problems resulting from the
> current situation occur when moving unformatted files between
> different systems -- something users should not be depending upon
> anyway.
>
> However, while I haven't investigated this fully myself, I believe
> there might be some good reasons to use the 8-byte header, or at
> least something more than 4 bytes.
>
> In particular, if, as I suspect is the case, the header counts bytes,
> not words, and given that the canonical Alpha configuration for
> programming uses 4-byte integers (and thus 4-byte array indexes)
> but 8-byte pointers (and thus vastly more than a 2GB limit on array
> size), it seems to me that there are arrays one could reasonably
> declare and use on an Alpha, but not be able to write to a file
> if that file's format limited record sizes to byte counts represented
> as 4-byte integers.
>
> Whether a particular version of *g77* can take advantage of these
> implications for normal, non-I/O code anyway, I don't know offhand,
> but the kind of thing I'm thinking of is this:
>
> PARAMETER (IMAX=2147483647)
> DOUBLE PRECISION A(IMAX)
>
> The array is definitely not too big for an Alpha, although the compiler
> has to be careful to multiply out byte offsets in the 8-byte integer
> type instead of the 4-byte (so A(IMAX) itself can be addressed without
> overflowing a register).
>
> However, I believe the array A could not be properly written to an
> unformatted file if g77 defaulted to the 4-byte record headers, as
> people are recommending be done. (I don't know what the failure
> mode would be -- perhaps a small amount of the array would be written,
> with no diagnostic or other evidence of a problem.)
>
> Even if g77 can't currently handle the above even for non-I/O stuff,
> it *should* be able to (I think, speaking offhand), and other compilers
> on Alphas might well be able to (and, if so, they should be defaulting
> to 8-byte headers as well). Getting code generation perfectly right
> is an ongoing battle, but as Toon suggested with his post, it is
> much harder to "fix" file-format problems after releasing products
> that ensconse those problems into peoples' files.
> --
>
> "Practice random senselessness and act kind of beautiful."
> James Craig Burley, Software Craftsperson burley@gnu.org
We now have our James here.
Thank you James.
I now can understand your preferrence to 8-byte.
Anyway, right after I posted the first article in this thread,
With a help of my friend here, I wrote a small C buffer, which must be
very useful for any one. What it does is to forget Fortran
record-oriented IO all together and to rely on generating a C-style binary
file.
In the course of the development of this small buffer, I think
I found a compiler bug of g77.
The internal IO cannot take
write(label(1),'(''This is the '',i1,''st string.\0'')') 1
The code compiles OK with the above line. But the execution will halt
at the above "\0". Putting "\\0" does not make sense because
we do not actually want a string of "\0" to be save for some
printing.
BTW, I guess I spent total of 10 hours to develop the C buffer.
I don't know much about C myself.
-------------test.f--------------------------------
program test
implicit none
integer i, Fbinout, IDUM1, LSTR
parameter(LSTR = 72)
integer i4(3)
real*4 r4(20)
character label(3)*72, TERM0*2
parameter(TERM0 = '\0')
i4(1) = 4
i4(2) = 5
i4(3) = 1
do i = 1, 20
r4(i) = i
end do
write(label(1),'(''This is the '',i1,''st string.'',a2)') 1, TERM0
label(2) = 'That\0'
label(3) = 'That and this\0'
IDUM1 = fbinout('r4.un\0', 3, LSTR, label, 3, i4, 20, r4)
153 format(5(1x,1pe15.7e3))
stop
end
---------------------fbinout.c--------------------------
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <time.h>
int fbinout_(char *fname, int *ms, int *lstr, char strings[], int *mi, int
I4[], int *md, float r4[])
{
short size, csize;
int j;
long timev;
FILE *fout;
char *ctimep;
time(&timev);
ctimep = ctime(&timev);
csize = strlen(ctimep);
/*
for(j=0; j<*ms; ++j)
fprintf(stdout, "string[%d] = %s\n", j, strings+j*(*lstr));
for(j = 0; j < *mi; j++)
fprintf(stdout, "I4[%d] = %d\n", j, I4[j]);
for(j = 0; j < *md; j++)
fprintf(stdout, "r4[%d] = %f\n", j, r4[j]);
fprintf(stdout, "%s\n", ctimep);
*/
/* binary write */
fout = fopen(fname, "wb");
fwrite(ms, sizeof(int), 1L, fout);
for(j = 0; j < *ms; j++) {
size = strlen(strings+j*(*lstr));
fwrite(&size, sizeof(short), 1L, fout);
fwrite(strings+j*(*lstr), sizeof(char), (size_t)size, fout);
}
fwrite(mi, sizeof(int), 1L, fout);
fwrite(I4, sizeof(int), (size_t)*mi, fout);
fwrite(md, sizeof(int), 1L, fout);
fwrite(r4, sizeof(float), (size_t)*md, fout);
fwrite(ctimep, sizeof(char), (size_t)csize, fout);
fclose(fout);
return 0;
}
-------------------Makefile---------------
SHELL=/bin/sh
CFLAGS =-g
FFLAGS =-g
test.x: test.o fbinout.o
$(FC) -o test.x $^
clean:
rm *.o
------------------------------------------
Finally, I would like to use the opportunity of talking to James directly.
When would the optimization with double precision complex
be working?
Thank you very much for all.
--
G. Hugh Song
PS: Please remove "Spamspoiler" when replying
next prev parent reply other threads:[~1998-10-18 4:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-10-15 4:00 g77's 8-byte record descriptor G. Hugh SONG
1998-10-15 4:00 ` Toon Moene
1998-10-15 4:00 ` Greg Lindahl
1998-10-16 4:00 ` Feng Liu
1998-10-18 4:00 ` Toon Moene
1998-10-18 4:00 ` Craig Burley
1998-10-16 4:00 ` Craig Burley
1998-10-18 4:00 ` G. Hugh SONG [this message]
1998-10-16 4:00 ` Robert Corbett
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox