For Programmers: Free Programming Magazines  


Home > Archive > Fortran > March 2004 > [ifc] print iterations only on one line...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author [ifc] print iterations only on one line...
fred

2004-03-27, 12:17 am


Hi,

Basically, in Fortran, if you want do display iterations on a screen,
you get

t = 1
t = 2
t = 3
....

with a new line each time.

I only want to display the last iteration, which erases all before,
without newlines.

I know how to do that in C:

for (i=0; i<5; i++)
{printf("%d\r", i); fflush(stdout);}
printf("\n");

I want to do the same in Fortran90 (ifc 7.1).

So I tried

do i=0,4
write(6,'(I1)') i
call flush(6)
end do

but it does not work.

How one can do that in Fortran ?

I don't find any hint in the ifc docs.


Thanks in advance.

--
Fred.
Tim Prince

2004-03-27, 12:17 am

Xref: kermit comp.lang.fortran:80967


"fred" <fredantispam@free.fr> wrote in message
news:tb1xnnitdb.fsf@free.fr...
>
> Hi,
>
> Basically, in Fortran, if you want do display iterations on a screen,
> you get
>
> t = 1
> t = 2
> t = 3
> ...
>
> with a new line each time.
>
> I only want to display the last iteration, which erases all before,
> without newlines.
>
> I know how to do that in C:
>
> for (i=0; i<5; i++)
> {printf("%d\r", i); fflush(stdout);}
> printf("\n");
>
> I want to do the same in Fortran90 (ifc 7.1).
>
> So I tried
>
> do i=0,4
> write(6,'(I1)') i
> call flush(6)
> end do
>
> but it does not work.
>
> How one can do that in Fortran ?

flush() is not standard Fortran. I don't know from your post whether that
is the part which "does not work" or which version of ifc you have. There
was a new update of ifc 7.1 this w.
advance=no (which I don't see in your code) is standard Fortran. I think
it would not be portable whether you could tab back. I don't see a tab in
your format. I'm not surprised that what you left out "doesn't work."

In the bad old days, this was done by using a format beginning with '+' in
column 1, and depended on a screen driver which waited for a \n character to
go down to the next line. Various common filters could interpret the old
1st column controls, like fpr and asa. So, if necessary, you piped your
Fortran stdout e.g.
yourexe|fpr. That's an earlier version the same scheme you appear to have
used in C. No doubt, you could find the C source code for fpr with a Google
search.


Douglas Cox

2004-03-27, 12:17 am

In article <tb1xnnitdb.fsf@free.fr>, fred wrote:

>
> Hi,
>
> Basically, in Fortran, if you want do display iterations on a screen,
> you get
>
> t = 1
> t = 2
> t = 3
> ...
>
> with a new line each time.
>
> I only want to display the last iteration, which erases all before,
> without newlines.
>
> I know how to do that in C:
>
> for (i=0; i<5; i++)
> {printf("%d\r", i); fflush(stdout);}
> printf("\n");
>
> I want to do the same in Fortran90 (ifc 7.1).
>
> So I tried
>
> do i=0,4
> write(6,'(I1)') i
> call flush(6)
> end do
>
> but it does not work.
>
> How one can do that in Fortran ?


do i=0,4
write(6,'(t1,i1)',advance="no") i
end do
write (*,*)
end

Works in ifc and ifort.
Doug

>
> I don't find any hint in the ifc docs.
>
>
> Thanks in advance.
>


jan van oosterwijk

2004-03-27, 12:17 am

Douglas Cox <tcc@sentex.net> wrote in message news:<405c5ef9@news.sentex.net>...
> In article <tb1xnnitdb.fsf@free.fr>, fred wrote:
>
>
> do i=0,4
> write(6,'(t1,i1)',advance="no") i
> end do
> write (*,*)
> end
>
> Works in ifc and ifort.
> Doug


If this is true, they are not standfard conforming.
The T1 refers to the actual file position, NOT position 1 of the record :-|

Anyway, the following works with my compilers (not Intel):

do i = 0, 4
write(unit = * , fmt = "(a1, t4, 't =', i3, )" &
& , advance = "NO" ) char(13), i
end do
! [a]char(13) is the "Carriage Return"

Jan van Oosterwijk

mailto: jan dot vanoosterwijk at wanadoo dot nl
Richard Maine

2004-03-27, 12:17 am

Xref: kermit comp.lang.fortran:81006

jvo_36@hotmail.com (jan van oosterwijk) writes:

>
> If this is true, they are not standfard conforming.
> The T1 refers to the actual file position, NOT position 1 of the record :-|


You don't mean file position. (Anyway, I assume you don't mean that;
if you did, you'd be wrong, but I'm assuming it is just your wording
that has the problem).

If I recall the standard-speak correctly, T1 is relative to the
left tab limit.

The left tab limit is supposed to get reset to the position at the
beginning of each write, which means, I'd agree, that the above is
not suppose to work. I'd advise against writing code that
explicitly depends on things that can be called compiler bugs, as
this could be. I've seen people do it before and then be upset
when the bug was fixed in a later release. Beware.

At the very least, if you do something like this, isolate and
document it so that you can change it when the compiler bug is
fixed.

--
Richard Maine
email: my last name at domain
domain: sumertriangle dot net
fred

2004-03-27, 12:17 am

Douglas Cox <tcc@sentex.net> a écrit :

> do i=0,4
> write(6,'(t1,i1)',advance="no") i
> end do
> write (*,*)
> end

This only displays "4" at the end of the loop, not at each iteration.
(Jan's answer too).

Any idea ?

call flush(6) after "write(6,..." changes nothing.

Thanks.

--
Fred.
Michael Metcalf

2004-03-27, 12:17 am

> > write(6,'(t1,i1)',advance="no") i

t1 tabulates to column one ("Fortran 90/95 Explained", p. 211). Try tr1.

Regards,

Mike Metcalf


fred

2004-03-27, 12:17 am

"Michael Metcalf" <metcalfm@acm.org> a écrit :

>
> t1 tabulates to column one ("Fortran 90/95 Explained", p. 211). Try tr1.

This is what I want. Not trN.

--
Fred.
jan van oosterwijk

2004-03-27, 12:17 am

fred <fredantispam@free.fr> wrote in message news:<tbu10hgnhp.fsf@free.fr>...
> Douglas Cox <tcc@sentex.net> a écrit :
>
> This only displays "4" at the end of the loop, not at each iteration.
> (Jan's answer too).
>
> Any idea ?

Yes, if taken litterally as above, the eye wouldn't catch the preceding
numbers, so to see the effect, you must also put a time consuming
statement in the loop, like (NON standard) call sleep( ... or
call date_and_time(values = kv)
do
k = kv(7)
call date_and_time(values = kv)
if (k /= kv(7) ) exit
end do

> call flush(6) after "write(6,..." changes nothing.


Jan van Oosterwijk
Jan dot vanOosterwijk at wanadoo dot NL
fred

2004-03-27, 12:17 am

jvo_36@hotmail.com (jan van oosterwijk) a écrit :

> Yes, if taken litterally as above, the eye wouldn't catch the preceding
> numbers, so to see the effect, you must also put a time consuming
> statement in the loop, like (NON standard) call sleep( ... or

I don't think so.
_because_ I use sleep()

Here is my code :

write(*,*) 'Begin here'

do i=1,5

! that's what I want
! write(6,'(t1,A4,F8.2,A5,F6.2,A3)',advance="no") 't = ', ((i*dt)*1e12), &
! & ' ps (', (i*100./N),' %)'
! many lines of FDTD code...
!

! more simpler
write(6,'(t1,i1)',advance='no') i

call flush(6)
call sleep(1)
end do
write(*,*)
write(*,*) 'End here'

"5" is displayed only at the end of the loop and only "5" is displayed :
despite call sleep(1), no one of 1 to 4 numbers are displayed.

--
Fred.
jan van oosterwijk

2004-03-27, 12:17 am

fred <fredantispam@free.fr> wrote in message news:<tblllshgwg.fsf@free.fr>...
> jvo_36@hotmail.com (jan van oosterwijk) a écrit :
>
> I don't think so.
> _because_ I use sleep()
>
> Here is my code :
>
> write(*,*) 'Begin here'
>
> do i=1,5
>
> ! that's what I want
> ! write(6,'(t1,A4,F8.2,A5,F6.2,A3)',advance="no") 't = ', ((i*dt)*1e12), &
> ! & ' ps (', (i*100./N),' %)'
> ! many lines of FDTD code...
> !
>
> ! more simpler
> write(6,'(t1,i1)',advance='no') i
>
> call flush(6)
> call sleep(1)


Are you sure sleep counts seconds and not milliseconds?

> end do
> write(*,*)
> write(*,*) 'End here'
>
> "5" is displayed only at the end of the loop and only "5" is displayed :
> despite call sleep(1), no one of 1 to 4 numbers are displayed.


Like this it works for me:

write(*,'(A1,t4,i0)',advance='no') char(13), i
! [JvO] jan dot vanoosterwijk at wanadoo dot nl
fred

2004-03-29, 12:34 pm

jvo_36@hotmail.com (jan van oosterwijk) a écrit :

> Are you sure sleep counts seconds and not milliseconds?

Yes.

> Like this it works for me:
>
> write(*,'(A1,t4,i0)',advance='no') char(13), i

Argh ! Not for me. :-(((

--
Fred.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com