variable repetition in formatted i/o 
Author Message
 variable repetition in formatted i/o

i remember something like this from my old f77 days.

integer :: i=3, a=11, b=12, c=13
write(*, '(<i>I4)') a, b, c
! write(*, '(3I4)') a, b, c      i want the above line to do this

apparently i remember wrong and this is not working. do we have anything for
this purpose in fortran 77/90 ?

thanks,
cuneyt



Sun, 31 Aug 2003 05:14:34 GMT  
 variable repetition in formatted i/o


Quote:
>i remember something like this from my old f77 days.

>integer :: i=3, a=11, b=12, c=13
>write(*, '(<i>I4)') a, b, c
>! write(*, '(3I4)') a, b, c      i want the above line to do this

>apparently i remember wrong and this is not working. do we have anything for
>this purpose in fortran 77/90 ?

You remember right, but this is an extension (invented by Digital in
the 1970s) called Variable Format Expressions.  It's implemented in
Digital/Compaq compilers and some others, but is not part of any
Fortran standard.  

There are standard-conforming ways to do a lot of what one does with
VFEs - the most straightforward is something like this:

character*(50) myfmt
...
write (myfmt,'(A,I0,A)') "(",i,"I4)"
write (*,myfmt) a,b,c

Depending on what you want to accomplish, you could also get the same
results with something like this:

write (*,'(100I4)') a,b,c

taking advantage of the fact that unused repetition counts are dropped
on the floor.


Fortran Engineering
Compaq Computer Corporation, Nashua NH

Compaq Fortran web site: http://www.compaq.com/fortran



Sun, 31 Aug 2003 05:57:22 GMT  
 variable repetition in formatted i/o

Quote:

> i remember something like this from my old f77 days.

> integer :: i=3, a=11, b=12, c=13
> write(*, '(<i>I4)') a, b, c
> ! write(*, '(3I4)') a, b, c      i want the above line to do this

> apparently i remember wrong and this is not working. do we have anything for
> this purpose in fortran 77/90 ?

I presume you want repitions because the number of variables output will change? I.e. it
won't always be 3?

why not do

  write( *, '( 10(i4,:) )' ) a, b, c

this will let you output 10 or less variables. Change 10 to whatever you need. The ":"
stops output once the output variable list is exhausted.

And there's always run-time formatting using the FMT= keyword isn't there?

cheers,

paulv

--
Paul van Delst           A little learning is a dangerous thing;

Ph: (301)763-8000 x7274  There shallow draughts intoxicate the brain,
Fax:(301)763-8545        And drinking largely sobers us again.



Sun, 31 Aug 2003 05:54:57 GMT  
 variable repetition in formatted i/o

Quote:
>   write( *, '( 10(i4,:) )' ) a, b, c
..
> The ":" stops output once the output variable list is exhausted.

Note that you don't need the colon in this kind of context.
Doesn't hurt anything, but it doesn't help anything either.
Output will stop anyway as soon as it hits a data edit descriptor
that has no data item with it.  The colon is useful when there
are other edit descriptors between the data ones and you want to
stop before those.  For example, if you wanted to output the 3
values with the word "and" between them, you could do

  write (*, '(10(i4,:," and "))') a, b, c

Here the colon will keep you from getting a trailing "and".

--
Richard Maine                       |  Good judgement comes from experience;
email: my last name at host.domain  |  experience comes from bad judgement.
host: altair, domain: dfrc.nasa.gov |        -- Mark Twain



Sun, 31 Aug 2003 06:36:18 GMT  
 variable repetition in formatted i/o

Quote:


> >   write( *, '( 10(i4,:) )' ) a, b, c
> ..
> > The ":" stops output once the output variable list is exhausted.

> Note that you don't need the colon in this kind of context.
> Doesn't hurt anything, but it doesn't help anything either.
> Output will stop anyway as soon as it hits a data edit descriptor
> that has no data item with it.  The colon is useful when there
> are other edit descriptors between the data ones and you want to
> stop before those.  For example, if you wanted to output the 3
> values with the word "and" between them, you could do

>   write (*, '(10(i4,:," and "))') a, b, c

> Here the colon will keep you from getting a trailing "and".

You're right of course. I use this form to print out progress indicators - usually 10
values (like every 100th loop iteration) a line followed by a CR. The ":" prevents the
last carriage return if the output values are not multiples of 100 (or whatever I choose).

cheers,

paulv

--
Paul van Delst           A little learning is a dangerous thing;

Ph: (301)763-8000 x7274  There shallow draughts intoxicate the brain,
Fax:(301)763-8545        And drinking largely sobers us again.



Sun, 31 Aug 2003 22:17:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Variable repetition count in FORMAT

2. repetition on format descriptor

3. variables in reg exp repetition

4. limited test-less loop-less call-full repetition

5. OCaml module type repetition in mli and ml files

6. LOGO-L> selection and pre-test repetition

7. Regexp: why does (re)* return only last repetition?

8. Concatination Repetition Multiplier

9. random url without repetition

10. Generating combinations with repetitions

11. On sequence repetition (*)

12. On sequence repetition (*)

 

 
Powered by phpBB® Forum Software