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

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!wupost!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!hirchert
  3. From: hirchert@ncsa.uiuc.edu (Kurt Hirchert)
  4. Subject: Re: Variable repeat count specifier for FORMAT statments
  5. References: <1992Jul23.215113.16531@jhunix.hcf.jhu.edu>
  6. Message-ID: <1992Jul24.012058.21162@ncsa.uiuc.edu>
  7. Originator: hirchert@pluto.ncsa.uiuc.edu
  8. Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
  9. Organization: Nat'l Ctr for Supercomp App (NCSA) @ University of Illinois
  10. Distribution: na
  11. Date: Fri, 24 Jul 1992 01:20:58 GMT
  12. Lines: 32
  13.  
  14. In article <1992Jul23.215113.16531@jhunix.hcf.jhu.edu> psun@jhunix.hcf.jhu.edu (Peter Sun) writes:
  15. >My apologies if this questions seems trivial, but I've tried to find the
  16. >answer in so many places.  I need to know how to give a variable as the
  17. >number of repeat counts to a format field descriptor statement.  For
  18. >example I know on VAX/VMS this can be done with something like:
  19. >
  20. >                   write (*, '(<n>(I8))')
  21. >
  22. >which will repeat the format descriptor I8 n number of times, but I haven't
  23. >found this portable to other compilers.  Namely, the MIPS Fortran 77
  24. >compiler for the SGI IRIS system.  Is there a standard for this?  Or is it
  25. >just compiler dependent.
  26.  
  27. This is a VAX extension.  It is not standard, but in most cases there are
  28. standard replacements.
  29.  
  30. In this case, I would simply replace <n> with a large number; the format
  31. interpreter will ignore the excess repetitions of (I8).  In more complex
  32. situations, I would build the format on the fly:
  33.  
  34.               character*80 fmt
  35.               ...
  36.               write (fmt,'(a,i3,a)') '(',n,'(I8))'
  37.               write (*,fmt) whatever_it_is_you_wanted_to_write
  38.  
  39. The first write statement creates in the variable fmt a copy of your
  40. example format with the current value of n replacing <n>.  The second
  41. write then uses the variable fmt as the format to write whatever it was
  42. that you originally wanted to write.
  43. -- 
  44. Kurt W. Hirchert     hirchert@ncsa.uiuc.edu
  45. National Center for Supercomputing Applications
  46.