Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!mp.cs.niu.edu!ux1.cso.uiuc.edu!hirchert From: hirchert@ncsa.uiuc.edu (Kurt Hirchert) Newsgroups: comp.lang.fortran Subject: Re: Left justify of integers. Message-ID: <1991Jun12.163531.3683@ncsa.uiuc.edu> Date: 12 Jun 91 16:35:31 GMT References: <676362067.43@egsgate.FidoNet.Org> Sender: usenet@ux1.cso.uiuc.edu (News) Organization: Nat'l Ctr for Supercomp App (NCSA) @ University of Illinois Lines: 53 Originator: hirchert@harriett.ncsa.uiuc.edu Summary: 1. FORTRAN 77 provides no guaranteed facility for directly writing left- justified integers (although list-directed output may work this way in some implementations). 2. There are two common ways to "roll your own": a. Construct the format dynamically. A function such as INTEGER FUNCTION WIDTH(INTEGR) INTEGER MAXWID PARAMETER (MAXWID=10) * 10 is the right value for 32-bit integers, since 2**31 has 10 digits. * 5 is the right value for 16-bit integers, since 2**15 has 5 digits. * When porting to a new machine, redefine MAXWID accordingly. DO 10 WIDTH=1,MAXWID-1 IF (10**WIDTH .GT. ABS(INTEGR)) GO TO 20 10 CONTINUE 20 IF (INTEGR .LT 0) WIDTH=WIDTH+1 END will usually be both faster and more accurate in determining the correct width. b. Write the integer to an internal file, and then use character manipulation to locate the relevant characters that you want to put out. 3. Fortran 90 didn't significantly change the situation, except that some of the new intrinsic functions make 2b easier to do. 4. Apparently, several people suggested to X3J3 that the I edit descriptor without a width should work this way (analogous to the A edit descriptor without a width). a. A without a width is also well defined on input. I without a width does not appear to be. b. While X3J3 was relatively amenable to changes of this small magnitude early in the revision cycle, by the time of the formal public reviews, X3J3 was so busy dealing with major issues that unless it was "intuitively obvious" that this kind of small change was the right thing to do, there usually wasn't time to fully debate the merits of this kind of proposal, and such proposals were sent back to subcommittee. Because of that, subcommittees rarely even tried to bring such proposals before the full committee unless there was reason to believe that it would be passed with little or no opposition. I think that 4a is sufficient reason to believe that there would have been opposition, and to the best of my knowledge, these suggestions were never brought out of subcommittee. -- Kurt W. Hirchert hirchert@ncsa.uiuc.edu National Center for Supercomputing Applications