home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / fortran / 4329 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.6 KB  |  62 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!ukma!asuvax!ncar!neit.cgd.ucar.edu!mai
  3. From: mai@neit.cgd.ucar.edu (Andrew Mai)
  4. Subject: Re: Print characters on one line without newline...???
  5. Message-ID: <1992Nov16.203156.1829@ncar.ucar.edu>
  6. Sender: news@ncar.ucar.edu (USENET Maintenance)
  7. Organization: Climate and Global Dynamics Division/NCAR, Boulder, CO
  8. References: <BxtnK6.23s@cs.uiuc.edu>
  9. Date: Mon, 16 Nov 1992 20:31:56 GMT
  10. Lines: 50
  11.  
  12. In article <BxtnK6.23s@cs.uiuc.edu> ctaylor@cs.uiuc.edu
  13. (Conrad W Taylor) writes:
  14. >
  15. >         I'm writting this PrintX routine that is to print
  16. > the letter X n times on one line without any spaces and
  17. > newline.
  18.  
  19. The following does what you want and is written in ANSI standard FORTRAN 77.
  20.  
  21.       program test
  22.       call printx(15)
  23.       call printx(80)
  24.       end
  25.       subroutine printx(xcount)
  26. c
  27. c  Print a space, then xcount X's with a newline at the end
  28. c
  29.       integer xcount,nd
  30.       character*16 form1,form2
  31.       write(form1,fmt='(a,i1,a)') '(a,i',nd(xcount),',a)'
  32.       write(form2,fmt=form1) '(1x,',xcount,'(''X''))'
  33.       write(6,form2)
  34.       return
  35.       end
  36.       function nd(k)
  37. c
  38. c  Returns the number of digits in k (plus one for the
  39. c  minus sign if k is negative)
  40. c
  41.       integer nd,k,l
  42.       nd=1
  43.       l=abs(k)
  44.     1 if (l.lt.10) goto 2
  45.       nd=nd+1
  46.       l=l/10
  47.       goto 1
  48.     2 if (k.lt.0) nd=nd+1
  49.       return
  50.       end
  51.  
  52. OUTPUT:
  53.  XXXXXXXXXXXXXXX
  54.  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  55.  
  56.  
  57. I don't know an easier way to do this in standard FORTRAN, but someone will
  58. probably show you.
  59.  
  60. Andy Mai
  61. mai@ncar.ucar.edu
  62.