home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / fortran / 2828 < prev    next >
Encoding:
Text File  |  1992-07-25  |  2.4 KB  |  64 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!darwin.sura.net!jhunix.hcf.jhu.edu!psun
  3. From: psun@jhunix.hcf.jhu.edu (Peter Sun)
  4. Subject: Re: Variable repeat count specifier for FORMAT statments
  5. Message-ID: <1992Jul24.220222.27681@jhunix.hcf.jhu.edu>
  6. Organization: HAC - Johns Hopkins University, Baltimore
  7. References: <1992Jul23.215113.16531@jhunix.hcf.jhu.edu>
  8. Distribution: na
  9. Date: Fri, 24 Jul 1992 22:02:22 GMT
  10. Lines: 52
  11.  
  12. In article <1992Jul23.215113.16531@jhunix.hcf.jhu.edu> psun@jhunix.hcf.jhu.edu (Peter Sun) writes:
  13. >My apologies if this questions seems trivial, but I've tried to find the
  14. >answer in so many places.  I need to know how to give a variable as the
  15. >number of repeat counts to a format field descriptor statement.  For
  16. >example I know on VAX/VMS this can be done with something like:
  17. >
  18. >                   write (*, '(<n>(I8))')
  19. >
  20. >which will repeat the format descriptor I8 n number of times, but I haven't
  21. >found this portable to other compilers.  Namely, the MIPS Fortran 77
  22. >compiler for the SGI IRIS system.  Is there a standard for this?  Or is it
  23. >just compiler dependent.
  24. >
  25. >Thank you very much!  Any help will be greatly appreciate.  
  26. >
  27. >--Peter Sun
  28. >psun@jhunix.hcf.jhu.edu
  29.  
  30. ===============================================================================
  31.  
  32. Thanks to everyone who replied to my question.  I got a lot of great
  33. responses. 
  34.  
  35. The overwhelming solution I got to the problem involves first writing
  36. internally as a character string, and then calling that string as the
  37. format to do the actual output (explained better below).  This solution was
  38. provided to me by Myron Calhoun, Al Stangenberger, Melvin Klassen, John
  39. Aguirre, Kurt Hirchert, Jim Giles, and James Burley.  Thanks very much--you
  40. are all very helpful people.
  41.  
  42.  
  43. --Peter Sun
  44. psun@jhunix.hcf.jhu.edu
  45.  
  46. ----------------------------------------------------------------------------
  47.     CHARACTER*80 FMT           ! Declare the format as a char string.
  48.     INTEGER      N              !
  49.                       !
  50.     n = 7                  ! Specify repeat count.
  51.                       !  
  52.     fmt = '(xxx(I8))'          ! Init. the string w/o specifiy 
  53.                       ! repeat count.
  54.     write(fmt,(2:4),'(I3)') n     ! Write to the format and replace the
  55.                       ! xxx with the repeat count.
  56.     write(*,fmt) what_to_write    ! Write out, calling the string FMT
  57.                       ! as the format statement.
  58. ----------------------------------------------------------------------------
  59.  
  60.  
  61.  
  62.  
  63.  
  64.