Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!mcsun!unido!rwthinf!rwthi3!ricki From: ricki@john.informatik.rwth-aachen.de (Richard Breuer) Newsgroups: comp.lang.fortran Subject: Re: Left justify of integers. Message-ID: Date: 4 Jun 91 11:41:50 GMT References: Sender: news@rwthinf.UUCP Distribution: comp Lines: 46 quan@sol.surv.utas.edu.au (Stephen Quan) writes: >I'm having a slight, almost trivial problem, I cannot write >integers without them being right justified. >eg write (*,*) 5 > gives > ......5 (. are leading spaces) >Is there some format statement (i1.1 or something) that will >solve this problem? I want a general solution, not just : > write (*,'(i1)') 5 >-- >quan@sol.surv.utas.edu.au (Stephen Quan) >Department of Surveying (I'm actually a computer scientist.) >University of Tasmania. >-- >quan@sol.surv.utas.edu.au (Stephen Quan) Well, there is no FORTRAN format that will do this. You can however 'create' your own format by using an internal WRITE: ... character*5 fmt fmt = '(i )' write(fmt(3:4),'(i2)') intlen(myint) write(*,fmt) myint ... So you just need a function 'intlen' that computes the length of an integer value in decimal digits, e.g. intlen(5) = 1 intlen(-5) = 2 intlen(1234) = 4 ... I wrote such a function some years ago. If you want it, let me know and I will look for it. Hope this help, Ricki.