home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!darwin.sura.net!jhunix.hcf.jhu.edu!psun
- From: psun@jhunix.hcf.jhu.edu (Peter Sun)
- Subject: Re: Variable repeat count specifier for FORMAT statments
- Message-ID: <1992Jul24.220222.27681@jhunix.hcf.jhu.edu>
- Organization: HAC - Johns Hopkins University, Baltimore
- References: <1992Jul23.215113.16531@jhunix.hcf.jhu.edu>
- Distribution: na
- Date: Fri, 24 Jul 1992 22:02:22 GMT
- Lines: 52
-
- In article <1992Jul23.215113.16531@jhunix.hcf.jhu.edu> psun@jhunix.hcf.jhu.edu (Peter Sun) writes:
- >My apologies if this questions seems trivial, but I've tried to find the
- >answer in so many places. I need to know how to give a variable as the
- >number of repeat counts to a format field descriptor statement. For
- >example I know on VAX/VMS this can be done with something like:
- >
- > write (*, '(<n>(I8))')
- >
- >which will repeat the format descriptor I8 n number of times, but I haven't
- >found this portable to other compilers. Namely, the MIPS Fortran 77
- >compiler for the SGI IRIS system. Is there a standard for this? Or is it
- >just compiler dependent.
- >
- >Thank you very much! Any help will be greatly appreciate.
- >
- >--Peter Sun
- >psun@jhunix.hcf.jhu.edu
-
- ===============================================================================
-
- Thanks to everyone who replied to my question. I got a lot of great
- responses.
-
- The overwhelming solution I got to the problem involves first writing
- internally as a character string, and then calling that string as the
- format to do the actual output (explained better below). This solution was
- provided to me by Myron Calhoun, Al Stangenberger, Melvin Klassen, John
- Aguirre, Kurt Hirchert, Jim Giles, and James Burley. Thanks very much--you
- are all very helpful people.
-
-
- --Peter Sun
- psun@jhunix.hcf.jhu.edu
-
- ----------------------------------------------------------------------------
- CHARACTER*80 FMT ! Declare the format as a char string.
- INTEGER N !
- !
- n = 7 ! Specify repeat count.
- !
- fmt = '(xxx(I8))' ! Init. the string w/o specifiy
- ! repeat count.
- write(fmt,(2:4),'(I3)') n ! Write to the format and replace the
- ! xxx with the repeat count.
- write(*,fmt) what_to_write ! Write out, calling the string FMT
- ! as the format statement.
- ----------------------------------------------------------------------------
-
-
-
-
-
-