Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"We don't have to protect the environment -- the Second Coming is at hand." -- James Watt


devel / comp.lang.fortran / Running print into file

SubjectAuthor
* Running print into fileDieter Britz
+* Re: Running print into fileThomas Koenig
|+* Re: Running print into fileArjen Markus
||`* Re: Running print into filegah4
|| `* Re: Running print into fileArjen Markus
||  +- Re: Running print into fileThomas Koenig
||  `- Re: Running print into fileNeil
|`* Re: Running print into fileDieter Britz
| `* Re: Running print into fileDieter Britz
|  +* Re: Running print into fileRon Shepard
|  |`* Re: Running print into fileJohn
|  | `- Re: Running print into fileJohn
|  `* Re: Running print into fileJCampbell
|   `* Re: Running print into fileRon Shepard
|    `* Re: Running print into fileJohn
|     +- Re: Running print into fileJohn
|     `* Re: Running print into fileGary Scott
|      `- Re: Running print into fileJCampbell
`- Re: Running print into fileLouis Krupp

1
Running print into file

<s9aktp$2gs$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=883&group=comp.lang.fortran#883

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dieterhansbritz@gmail.com (Dieter Britz)
Newsgroups: comp.lang.fortran
Subject: Running print into file
Date: Thu, 3 Jun 2021 13:19:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <s9aktp$2gs$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 3 Jun 2021 13:19:53 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="811476fa5de22d1dbb130ca9004ea5bb";
logging-data="2588"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ArARHNgWCWW8Az5w6QGrEfoYsXvmKHZ0="
User-Agent: Pan/0.144 (Time is the enemy; 28ab3ba git.gnome.org/pan2)
Cancel-Lock: sha1:D+aftnUiPmj378iOYFqUhHNj3cg=
 by: Dieter Britz - Thu, 3 Jun 2021 13:19 UTC

This might be a Linux question but I'm not sure.
When I run a Fortran program that prints a lot of stuff
as it runs, directly, it does that. But when I run it
offline, with the output going into a file, it only prints
right near the end of execution. So that file is empty for
the whole time.

I run it with a script with this order:

../<script> >& <output file name> &

Is there a way to run it so that it prints as it runs?
--
Dieter Britz

Re: Running print into file

<s9al5h$15d$1@newsreader4.netcologne.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=884&group=comp.lang.fortran#884

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!aioe.org!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd6-2e93-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoenig@netcologne.de (Thomas Koenig)
Newsgroups: comp.lang.fortran
Subject: Re: Running print into file
Date: Thu, 3 Jun 2021 13:24:01 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <s9al5h$15d$1@newsreader4.netcologne.de>
References: <s9aktp$2gs$1@dont-email.me>
Injection-Date: Thu, 3 Jun 2021 13:24:01 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd6-2e93-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd6:2e93:0:7285:c2ff:fe6c:992d";
logging-data="1197"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Thu, 3 Jun 2021 13:24 UTC

Dieter Britz <dieterhansbritz@gmail.com> schrieb:
> This might be a Linux question but I'm not sure.
> When I run a Fortran program that prints a lot of stuff
> as it runs, directly, it does that. But when I run it
> offline, with the output going into a file, it only prints
> right near the end of execution. So that file is empty for
> the whole time.

Often, terminal output is unbuffered, file output is.

Your compiler probably supports the FLUSH statement, as in

program main
use iso_fortran_env, only : output_unit
implicit none
write (*,'(A)') "Hello"
flush output_unit
! Do something that takes a long time
write (*,'(A)') "Goodbye"
end program main

Try that.

Re: Running print into file

<d15c7acc-495c-4a29-bad9-d629313ca629n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=885&group=comp.lang.fortran#885

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:622a:89:: with SMTP id o9mr215019qtw.339.1622731673609;
Thu, 03 Jun 2021 07:47:53 -0700 (PDT)
X-Received: by 2002:a25:16c2:: with SMTP id 185mr531510ybw.24.1622731673400;
Thu, 03 Jun 2021 07:47:53 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 3 Jun 2021 07:47:53 -0700 (PDT)
In-Reply-To: <s9al5h$15d$1@newsreader4.netcologne.de>
Injection-Info: google-groups.googlegroups.com; posting-host=62.194.62.207; posting-account=A91wAAoAAADgBUxBX6QqsrSD26GLhVp8
NNTP-Posting-Host: 62.194.62.207
References: <s9aktp$2gs$1@dont-email.me> <s9al5h$15d$1@newsreader4.netcologne.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d15c7acc-495c-4a29-bad9-d629313ca629n@googlegroups.com>
Subject: Re: Running print into file
From: arjen.markus895@gmail.com (Arjen Markus)
Injection-Date: Thu, 03 Jun 2021 14:47:53 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2235
 by: Arjen Markus - Thu, 3 Jun 2021 14:47 UTC

On Thursday, June 3, 2021 at 3:24:03 PM UTC+2, Thomas Koenig wrote:
> Dieter Britz schrieb:
> > This might be a Linux question but I'm not sure.
> > When I run a Fortran program that prints a lot of stuff
> > as it runs, directly, it does that. But when I run it
> > offline, with the output going into a file, it only prints
> > right near the end of execution. So that file is empty for
> > the whole time.
> Often, terminal output is unbuffered, file output is.
>
> Your compiler probably supports the FLUSH statement, as in
>
> program main
> use iso_fortran_env, only : output_unit
> implicit none
> write (*,'(A)') "Hello"
> flush output_unit
> ! Do something that takes a long time
> write (*,'(A)') "Goodbye"
> end program main
>
> Try that.
You may also get the effect you need using the tee program:

myprog | tee report.out

as tee reads standard input and writes it to standard output or a file. It may set things as if it was a terminal (one of those magic things that can happen). Note that I have not tried this myself, just a half-informed guess.

Regards,

Arjen

Re: Running print into file

<7198dece-4e90-4316-9d2f-41a05bcd8b57n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=886&group=comp.lang.fortran#886

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:1121:: with SMTP id p1mr2098761qkk.299.1622771029220;
Thu, 03 Jun 2021 18:43:49 -0700 (PDT)
X-Received: by 2002:a25:bec6:: with SMTP id k6mr2046738ybm.187.1622771028950;
Thu, 03 Jun 2021 18:43:48 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.snarked.org!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 3 Jun 2021 18:43:48 -0700 (PDT)
In-Reply-To: <d15c7acc-495c-4a29-bad9-d629313ca629n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=98.232.94.215; posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 98.232.94.215
References: <s9aktp$2gs$1@dont-email.me> <s9al5h$15d$1@newsreader4.netcologne.de>
<d15c7acc-495c-4a29-bad9-d629313ca629n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7198dece-4e90-4316-9d2f-41a05bcd8b57n@googlegroups.com>
Subject: Re: Running print into file
From: gah4@u.washington.edu (gah4)
Injection-Date: Fri, 04 Jun 2021 01:43:49 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 22
 by: gah4 - Fri, 4 Jun 2021 01:43 UTC

On Thursday, June 3, 2021 at 7:47:55 AM UTC-7, arjen.m...@gmail.com wrote:
> On Thursday, June 3, 2021 at 3:24:03 PM UTC+2, Thomas Koenig wrote:

(snip)

> > Often, terminal output is unbuffered, file output is.

> > Your compiler probably supports the FLUSH statement, as in

(snip)

> You may also get the effect you need using the tee program:

> myprog | tee report.out

I used to use tee a lot, less often now.
But I do remember that the output to it is buffered, so it doesn't help.
It might be that you can turn off buffering in the program that
writes to the pipe.

Now I more often use tail -f to follow the output written to the file, but again
(as the OP notes) it is buffered, so you won't see it for a while.

Re: Running print into file

<8837543c-d0fe-45f1-bfd2-6973a12ea9b9n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=887&group=comp.lang.fortran#887

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ac8:6c3a:: with SMTP id k26mr3291365qtu.146.1622786544912;
Thu, 03 Jun 2021 23:02:24 -0700 (PDT)
X-Received: by 2002:a25:99c1:: with SMTP id q1mr2750443ybo.517.1622786544657;
Thu, 03 Jun 2021 23:02:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 3 Jun 2021 23:02:24 -0700 (PDT)
In-Reply-To: <7198dece-4e90-4316-9d2f-41a05bcd8b57n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=62.194.62.207; posting-account=A91wAAoAAADgBUxBX6QqsrSD26GLhVp8
NNTP-Posting-Host: 62.194.62.207
References: <s9aktp$2gs$1@dont-email.me> <s9al5h$15d$1@newsreader4.netcologne.de>
<d15c7acc-495c-4a29-bad9-d629313ca629n@googlegroups.com> <7198dece-4e90-4316-9d2f-41a05bcd8b57n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8837543c-d0fe-45f1-bfd2-6973a12ea9b9n@googlegroups.com>
Subject: Re: Running print into file
From: arjen.markus895@gmail.com (Arjen Markus)
Injection-Date: Fri, 04 Jun 2021 06:02:24 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Arjen Markus - Fri, 4 Jun 2021 06:02 UTC

On Friday, June 4, 2021 at 3:43:50 AM UTC+2, gah4 wrote:
> On Thursday, June 3, 2021 at 7:47:55 AM UTC-7, arjen wrote:
> > On Thursday, June 3, 2021 at 3:24:03 PM UTC+2, Thomas Koenig wrote:
> (snip)
> > > Often, terminal output is unbuffered, file output is.
>
> > > Your compiler probably supports the FLUSH statement, as in
> (snip)
> > You may also get the effect you need using the tee program:
>
> > myprog | tee report.out
> I used to use tee a lot, less often now.
> But I do remember that the output to it is buffered, so it doesn't help.
> It might be that you can turn off buffering in the program that
> writes to the pipe.
>
> Now I more often use tail -f to follow the output written to the file, but again
> (as the OP notes) it is buffered, so you won't see it for a while.
Hm, so it is not as smart/magic as I thought. Well, in that case the simplest solution would indeed be to use flush explicitly.

Should that be impractical or impossible, I can think of one other possibility: use the "expect" tool to fool the program into thinking it is outputting to a terminal.

Regards,

Arjen

Re: Running print into file

<s9cg2l$9bq$1@newsreader4.netcologne.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=888&group=comp.lang.fortran#888

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd6-2e93-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoenig@netcologne.de (Thomas Koenig)
Newsgroups: comp.lang.fortran
Subject: Re: Running print into file
Date: Fri, 4 Jun 2021 06:09:25 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <s9cg2l$9bq$1@newsreader4.netcologne.de>
References: <s9aktp$2gs$1@dont-email.me>
<s9al5h$15d$1@newsreader4.netcologne.de>
<d15c7acc-495c-4a29-bad9-d629313ca629n@googlegroups.com>
<7198dece-4e90-4316-9d2f-41a05bcd8b57n@googlegroups.com>
<8837543c-d0fe-45f1-bfd2-6973a12ea9b9n@googlegroups.com>
Injection-Date: Fri, 4 Jun 2021 06:09:25 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd6-2e93-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd6:2e93:0:7285:c2ff:fe6c:992d";
logging-data="9594"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Fri, 4 Jun 2021 06:09 UTC

Arjen Markus <arjen.markus895@gmail.com> schrieb:
> On Friday, June 4, 2021 at 3:43:50 AM UTC+2, gah4 wrote:
>> On Thursday, June 3, 2021 at 7:47:55 AM UTC-7, arjen wrote:
>> > On Thursday, June 3, 2021 at 3:24:03 PM UTC+2, Thomas Koenig wrote:
>> (snip)
>> > > Often, terminal output is unbuffered, file output is.
>>
>> > > Your compiler probably supports the FLUSH statement, as in
>> (snip)
>> > You may also get the effect you need using the tee program:
>>
>> > myprog | tee report.out
>> I used to use tee a lot, less often now.
>> But I do remember that the output to it is buffered, so it doesn't help.
>> It might be that you can turn off buffering in the program that
>> writes to the pipe.
>>
>> Now I more often use tail -f to follow the output written to the file, but again
>> (as the OP notes) it is buffered, so you won't see it for a while.
> Hm, so it is not as smart/magic as I thought. Well, in that case the simplest solution would indeed be to use flush explicitly.
>
> Should that be impractical or impossible, I can think of one
> other possibility: use the "expect" tool to fool the program into
> thinking it is outputting to a terminal.

That may be a bit of overkill.

There is another method: Look into the compiler documentation
and see if there is anything there.

For example, gfortran supports the GFORTRAN_UNBUFFERED_PRECONNECTED
environment variable; if that is set to "y", then standard output
should also be unbuffered. I'm fairly certain other compilers also
support this kind of thing.

Re: Running print into file

<60ba1300$0$694$14726298@news.sunsite.dk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=889&group=comp.lang.fortran#889

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
Message-ID: <60ba1300$0$694$14726298@news.sunsite.dk>
From: nddtwentyone@gmail.com (Neil)
Subject: Re: Running print into file
Newsgroups: comp.lang.fortran
References: <s9aktp$2gs$1@dont-email.me> <s9al5h$15d$1@newsreader4.netcologne.de> <d15c7acc-495c-4a29-bad9-d629313ca629n@googlegroups.com> <7198dece-4e90-4316-9d2f-41a05bcd8b57n@googlegroups.com> <8837543c-d0fe-45f1-bfd2-6973a12ea9b9n@googlegroups.com>
User-Agent: tin/2.4.4-20191224 ("Millburn") (Linux/5.4.0-74-generic (x86_64))
Date: 04 Jun 2021 11:48:18 GMT
Lines: 34
Organization: SunSITE.dk - Supporting Open source
NNTP-Posting-Host: eb550237.news.sunsite.dk
X-Trace: 1622807298 news.sunsite.dk 694 nddtwentyone@gmail.com/78.148.228.62:34024
X-Complaints-To: staff@sunsite.dk
 by: Neil - Fri, 4 Jun 2021 11:48 UTC

Arjen Markus <arjen.markus895@gmail.com> wrote:
> On Friday, June 4, 2021 at 3:43:50 AM UTC+2, gah4 wrote:
>> On Thursday, June 3, 2021 at 7:47:55 AM UTC-7, arjen wrote:
>> > On Thursday, June 3, 2021 at 3:24:03 PM UTC+2, Thomas Koenig wrote:
>> (snip)
>> > > Often, terminal output is unbuffered, file output is.
>>
>> > > Your compiler probably supports the FLUSH statement, as in
>> (snip)
>> > You may also get the effect you need using the tee program:
>>
>> > myprog | tee report.out
>> I used to use tee a lot, less often now.
>> But I do remember that the output to it is buffered, so it doesn't help.
>> It might be that you can turn off buffering in the program that
>> writes to the pipe.
>>
>> Now I more often use tail -f to follow the output written to the file, but again
>> (as the OP notes) it is buffered, so you won't see it for a while.
> Hm, so it is not as smart/magic as I thought. Well, in that case the simplest solution would indeed be to use flush explicitly.
>
> Should that be impractical or impossible, I can think of one other possibility: use the "expect" tool to fool the program into thinking it is outputting to a terminal.

If the flush statement (Fortran 2003 and later) is unavailable and the
various flush extensions that existed before that are also
unavailable, one can often achieve the same effect by closing and
reopening the file, e.g.,

...
write(7,*)lots_of_stuff
close(7)
open(unit=7,file="whatever.txt",position="append")
write(7,*)lots_more_stuff
...

Re: Running print into file

<s9g5hc$bls$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=890&group=comp.lang.fortran#890

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dieterhansbritz@gmail.com (Dieter Britz)
Newsgroups: comp.lang.fortran
Subject: Re: Running print into file
Date: Sat, 5 Jun 2021 15:34:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <s9g5hc$bls$1@dont-email.me>
References: <s9aktp$2gs$1@dont-email.me>
<s9al5h$15d$1@newsreader4.netcologne.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 5 Jun 2021 15:34:04 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="af5d6f85b76bf92a80accae46848bc49";
logging-data="11964"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19UX1rqslKMyZXrdzVQvkqVkYbINtolYu8="
User-Agent: Pan/0.144 (Time is the enemy; 28ab3ba git.gnome.org/pan2)
Cancel-Lock: sha1:t0BV0YIYPzY4Og71TQzpjKon11A=
 by: Dieter Britz - Sat, 5 Jun 2021 15:34 UTC

On Thu, 03 Jun 2021 13:24:01 +0000, Thomas Koenig wrote:

> Dieter Britz <dieterhansbritz@gmail.com> schrieb:
>> This might be a Linux question but I'm not sure.
>> When I run a Fortran program that prints a lot of stuff as it runs,
>> directly, it does that. But when I run it offline, with the output
>> going into a file, it only prints right near the end of execution. So
>> that file is empty for the whole time.
>
> Often, terminal output is unbuffered, file output is.
>
> Your compiler probably supports the FLUSH statement, as in
>
> program main
> use iso_fortran_env, only : output_unit implicit none write (*,'(A)')
> "Hello"
> flush output_unit ! Do something that takes a long time write
> (*,'(A)') "Goodbye"
> end program main
>
> Try that.

I just did. But I'm using print instead of write, and flush seems
to want the LUN. What is the LUN for print? I tried 5 but that didn't
work.

--
Dieter Britz

Re: Running print into file

<s9g5si$kc8$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=891&group=comp.lang.fortran#891

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dieterhansbritz@gmail.com (Dieter Britz)
Newsgroups: comp.lang.fortran
Subject: Re: Running print into file
Date: Sat, 5 Jun 2021 15:40:02 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <s9g5si$kc8$1@dont-email.me>
References: <s9aktp$2gs$1@dont-email.me>
<s9al5h$15d$1@newsreader4.netcologne.de> <s9g5hc$bls$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 5 Jun 2021 15:40:02 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="af5d6f85b76bf92a80accae46848bc49";
logging-data="20872"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EmsU11ZfbX+JLVsuUSWmX5WqDWw+fGGo="
User-Agent: Pan/0.144 (Time is the enemy; 28ab3ba git.gnome.org/pan2)
Cancel-Lock: sha1:PH1qVDUw3nwQsyha3vrC+nZ9iGo=
 by: Dieter Britz - Sat, 5 Jun 2021 15:40 UTC

On Sat, 05 Jun 2021 15:34:04 +0000, Dieter Britz wrote:

> On Thu, 03 Jun 2021 13:24:01 +0000, Thomas Koenig wrote:
>
>> Dieter Britz <dieterhansbritz@gmail.com> schrieb:
>>> This might be a Linux question but I'm not sure.
>>> When I run a Fortran program that prints a lot of stuff as it runs,
>>> directly, it does that. But when I run it offline, with the output
>>> going into a file, it only prints right near the end of execution. So
>>> that file is empty for the whole time.
>>
>> Often, terminal output is unbuffered, file output is.
>>
>> Your compiler probably supports the FLUSH statement, as in
>>
>> program main
>> use iso_fortran_env, only : output_unit implicit none write (*,'(A)')
>> "Hello"
>> flush output_unit ! Do something that takes a long time write
>> (*,'(A)') "Goodbye"
>> end program main
>>
>> Try that.
>
> I just did. But I'm using print instead of write, and flush seems to
> want the LUN. What is the LUN for print? I tried 5 but that didn't work.

Sorry, my silly error, it should have been 6, and that works. Thanks
for the tip. I'm running programs that run for days on end and I would
like to see how much they do along the way, and this will let me do it.

--
Dieter Britz

Re: Running print into file

<_mNuI.32068$9a1.11208@fx38.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=892&group=comp.lang.fortran#892

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx38.iad.POSTED!not-for-mail
Subject: Re: Running print into file
Newsgroups: comp.lang.fortran
References: <s9aktp$2gs$1@dont-email.me>
<s9al5h$15d$1@newsreader4.netcologne.de> <s9g5hc$bls$1@dont-email.me>
<s9g5si$kc8$1@dont-email.me>
From: nospam@nowhere.org (Ron Shepard)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:78.0)
Gecko/20100101 Thunderbird/78.10.2
MIME-Version: 1.0
In-Reply-To: <s9g5si$kc8$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Lines: 43
Message-ID: <_mNuI.32068$9a1.11208@fx38.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sat, 5 Jun 2021 11:11:38 -0500
X-Received-Bytes: 2756
 by: Ron Shepard - Sat, 5 Jun 2021 16:11 UTC

On 6/5/21 10:40 AM, Dieter Britz wrote:
> On Sat, 05 Jun 2021 15:34:04 +0000, Dieter Britz wrote:
>
>> On Thu, 03 Jun 2021 13:24:01 +0000, Thomas Koenig wrote:
>>
>>> Dieter Britz <dieterhansbritz@gmail.com> schrieb:
>>>> This might be a Linux question but I'm not sure.
>>>> When I run a Fortran program that prints a lot of stuff as it runs,
>>>> directly, it does that. But when I run it offline, with the output
>>>> going into a file, it only prints right near the end of execution. So
>>>> that file is empty for the whole time.
>>>
>>> Often, terminal output is unbuffered, file output is.
>>>
>>> Your compiler probably supports the FLUSH statement, as in
>>>
>>> program main
>>> use iso_fortran_env, only : output_unit implicit none write (*,'(A)')
>>> "Hello"
>>> flush output_unit ! Do something that takes a long time write
>>> (*,'(A)') "Goodbye"
>>> end program main
>>>
>>> Try that.
>>
>> I just did. But I'm using print instead of write, and flush seems to
>> want the LUN. What is the LUN for print? I tried 5 but that didn't work.
>
> Sorry, my silly error, it should have been 6, and that works. Thanks
> for the tip. I'm running programs that run for days on end and I would
> like to see how much they do along the way, and this will let me do it.

Are you using a hardwired 6, or are you using output_unit as shown
above? I don't use "print" statements, but I think print and write will
both use the same output buffers and the output from each is properly
intermingled.

I use lots of old 40+ year old code still with hardwired 6 output units,
but I've been using iso_fortran_env for several years now with no
portability problems. That is what I would now recommend.

$.02 -Ron Shepard

Re: Running print into file

<ea74c460-bab3-4a19-b5ff-78c18871589bn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=896&group=comp.lang.fortran#896

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a0c:c709:: with SMTP id w9mr13800609qvi.37.1622990035735;
Sun, 06 Jun 2021 07:33:55 -0700 (PDT)
X-Received: by 2002:a25:16c2:: with SMTP id 185mr17925413ybw.24.1622990035607;
Sun, 06 Jun 2021 07:33:55 -0700 (PDT)
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sun, 6 Jun 2021 07:33:55 -0700 (PDT)
In-Reply-To: <_mNuI.32068$9a1.11208@fx38.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:546:300:4c20:a18a:310e:b261:fb88;
posting-account=7tVJUQoAAACymEG6aShD5R0lhHCm_A0r
NNTP-Posting-Host: 2601:546:300:4c20:a18a:310e:b261:fb88
References: <s9aktp$2gs$1@dont-email.me> <s9al5h$15d$1@newsreader4.netcologne.de>
<s9g5hc$bls$1@dont-email.me> <s9g5si$kc8$1@dont-email.me> <_mNuI.32068$9a1.11208@fx38.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ea74c460-bab3-4a19-b5ff-78c18871589bn@googlegroups.com>
Subject: Re: Running print into file
From: urbanjost@comcast.net (John)
Injection-Date: Sun, 06 Jun 2021 14:33:55 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: John - Sun, 6 Jun 2021 14:33 UTC

extensions on OPEN, compiler switches and environment variables, FLUSH in particular are good solutions, but note there is a command on most Linux platforms that does what it was hoped tee(1) did -- unbuffer(1). If the program happens to be something you cannot change the code for or is not Fortran you might find it handy. It is also part of the expect(1) package so depending on your system you might need to install it or ask for expect(1) to be installed.

Re: Running print into file

<e5602aee-4ee6-412e-8a96-c5f003314e0fn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=897&group=comp.lang.fortran#897

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a37:8245:: with SMTP id e66mr12374314qkd.439.1622990308476;
Sun, 06 Jun 2021 07:38:28 -0700 (PDT)
X-Received: by 2002:a25:99c1:: with SMTP id q1mr17204490ybo.517.1622990308315;
Sun, 06 Jun 2021 07:38:28 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sun, 6 Jun 2021 07:38:28 -0700 (PDT)
In-Reply-To: <ea74c460-bab3-4a19-b5ff-78c18871589bn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:546:300:4c20:a18a:310e:b261:fb88;
posting-account=7tVJUQoAAACymEG6aShD5R0lhHCm_A0r
NNTP-Posting-Host: 2601:546:300:4c20:a18a:310e:b261:fb88
References: <s9aktp$2gs$1@dont-email.me> <s9al5h$15d$1@newsreader4.netcologne.de>
<s9g5hc$bls$1@dont-email.me> <s9g5si$kc8$1@dont-email.me> <_mNuI.32068$9a1.11208@fx38.iad>
<ea74c460-bab3-4a19-b5ff-78c18871589bn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e5602aee-4ee6-412e-8a96-c5f003314e0fn@googlegroups.com>
Subject: Re: Running print into file
From: urbanjost@comcast.net (John)
Injection-Date: Sun, 06 Jun 2021 14:38:28 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: John - Sun, 6 Jun 2021 14:38 UTC

On Sunday, June 6, 2021 at 10:33:57 AM UTC-4, John wrote:
> extensions on OPEN, compiler switches and environment variables, FLUSH in particular are good solutions, but note there is a command on most Linux platforms that does what it was hoped tee(1) did -- unbuffer(1). If the program happens to be something you cannot change the code for or is not Fortran you might find it handy. It is also part of the expect(1) package so depending on your system you might need to install it or ask for expect(1) to be installed.

There is another command called stdbuf(1) that is similiar that also might be on your machine, although I prefer unbuffer.

Re: Running print into file

<9d1c3b9d-97bb-420a-a6e8-5a14f46e85f0n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=912&group=comp.lang.fortran#912

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ac8:7615:: with SMTP id t21mr4215558qtq.140.1623317796837;
Thu, 10 Jun 2021 02:36:36 -0700 (PDT)
X-Received: by 2002:a25:c547:: with SMTP id v68mr6064094ybe.361.1623317796660;
Thu, 10 Jun 2021 02:36:36 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 10 Jun 2021 02:36:36 -0700 (PDT)
In-Reply-To: <s9g5si$kc8$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:8003:2328:5a00:7cd1:5533:20fd:9b56;
posting-account=W6x0LgoAAADUV-yz4YE9o_6nxcvZvCmc
NNTP-Posting-Host: 2001:8003:2328:5a00:7cd1:5533:20fd:9b56
References: <s9aktp$2gs$1@dont-email.me> <s9al5h$15d$1@newsreader4.netcologne.de>
<s9g5hc$bls$1@dont-email.me> <s9g5si$kc8$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9d1c3b9d-97bb-420a-a6e8-5a14f46e85f0n@googlegroups.com>
Subject: Re: Running print into file
From: campbelljohnd01@gmail.com (JCampbell)
Injection-Date: Thu, 10 Jun 2021 09:36:36 +0000
Content-Type: text/plain; charset="UTF-8"
 by: JCampbell - Thu, 10 Jun 2021 09:36 UTC

On Sunday, June 6, 2021 at 1:40:05 AM UTC+10, Dieter Britz wrote:
> On Sat, 05 Jun 2021 15:34:04 +0000, Dieter Britz wrote:
>
> > On Thu, 03 Jun 2021 13:24:01 +0000, Thomas Koenig wrote:
> >
> >> Dieter Britz <dieterh...@gmail.com> schrieb:
> >>> This might be a Linux question but I'm not sure.
> >>> When I run a Fortran program that prints a lot of stuff as it runs,
> >>> directly, it does that. But when I run it offline, with the output
> >>> going into a file, it only prints right near the end of execution. So
> >>> that file is empty for the whole time.
> >>
> >> Often, terminal output is unbuffered, file output is.
> >>
> >> Your compiler probably supports the FLUSH statement, as in
> >>
> >> program main
> >> use iso_fortran_env, only : output_unit implicit none write (*,'(A)')
> >> "Hello"
> >> flush output_unit ! Do something that takes a long time write
> >> (*,'(A)') "Goodbye"
> >> end program main
> >>
> >> Try that.
> >
> > I just did. But I'm using print instead of write, and flush seems to
> > want the LUN. What is the LUN for print? I tried 5 but that didn't work.
> Sorry, my silly error, it should have been 6, and that works. Thanks
> for the tip. I'm running programs that run for days on end and I would
> like to see how much they do along the way, and this will let me do it.
>
> --
> Dieter Britz
My solution to this problem is to have a result update routine which packages the output in:

!$OMP CRITICAL
open (unit=111, file='run_hist.log', position='append')
! call write update routines
close (unit=111)
!$OMP END CRITICAL

I use this approach for analysis packets of about 30 minutes in a multi-threaded and repeated analysis.
It addresses my requirement for collecting results and reviewing a set of runs over days

Re: Running print into file

<fzpwI.34164$9a1.30930@fx38.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=913&group=comp.lang.fortran#913

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx38.iad.POSTED!not-for-mail
Subject: Re: Running print into file
Newsgroups: comp.lang.fortran
References: <s9aktp$2gs$1@dont-email.me>
<s9al5h$15d$1@newsreader4.netcologne.de> <s9g5hc$bls$1@dont-email.me>
<s9g5si$kc8$1@dont-email.me>
<9d1c3b9d-97bb-420a-a6e8-5a14f46e85f0n@googlegroups.com>
From: nospam@nowhere.org (Ron Shepard)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:78.0)
Gecko/20100101 Thunderbird/78.11.0
MIME-Version: 1.0
In-Reply-To: <9d1c3b9d-97bb-420a-a6e8-5a14f46e85f0n@googlegroups.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Lines: 57
Message-ID: <fzpwI.34164$9a1.30930@fx38.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Thu, 10 Jun 2021 09:44:27 -0500
X-Received-Bytes: 3693
 by: Ron Shepard - Thu, 10 Jun 2021 14:44 UTC

On 6/10/21 4:36 AM, JCampbell wrote:
> On Sunday, June 6, 2021 at 1:40:05 AM UTC+10, Dieter Britz wrote:
>> On Sat, 05 Jun 2021 15:34:04 +0000, Dieter Britz wrote:
>>
>>> On Thu, 03 Jun 2021 13:24:01 +0000, Thomas Koenig wrote:
>>>
>>>> Dieter Britz <dieterh...@gmail.com> schrieb:
>>>>> This might be a Linux question but I'm not sure.
>>>>> When I run a Fortran program that prints a lot of stuff as it runs,
>>>>> directly, it does that. But when I run it offline, with the output
>>>>> going into a file, it only prints right near the end of execution. So
>>>>> that file is empty for the whole time.
>>>>
>>>> Often, terminal output is unbuffered, file output is.
>>>>
>>>> Your compiler probably supports the FLUSH statement, as in
>>>>
>>>> program main
>>>> use iso_fortran_env, only : output_unit implicit none write (*,'(A)')
>>>> "Hello"
>>>> flush output_unit ! Do something that takes a long time write
>>>> (*,'(A)') "Goodbye"
>>>> end program main
>>>>
>>>> Try that.
>>>
>>> I just did. But I'm using print instead of write, and flush seems to
>>> want the LUN. What is the LUN for print? I tried 5 but that didn't work.
>> Sorry, my silly error, it should have been 6, and that works. Thanks
>> for the tip. I'm running programs that run for days on end and I would
>> like to see how much they do along the way, and this will let me do it.
>>
>> --
>> Dieter Britz
> My solution to this problem is to have a result update routine which packages the output in:
>
> !$OMP CRITICAL
> open (unit=111, file='run_hist.log', position='append')
> ! call write update routines
> close (unit=111)
> !$OMP END CRITICAL
>
> I use this approach for analysis packets of about 30 minutes in a multi-threaded and repeated analysis.
> It addresses my requirement for collecting results and reviewing a set of runs over days

This uses unit=111, so it does not work with print, right? What is the
difference in this and the simple "flush output_unit" statement
suggested previously? Does this work correctly but "flush" did not? The
reason I'm asking is that simply closing a file is no guarantee that the
output buffer will be immediately flushed. The program could wait until
final termination before the output buffers within the i/o library are
actually flushed into the external file system. There is no strict
guarantee that "flush" will do that either, but at least that is the
stated intention of the operation, unlike the situation with "close",
whose real purpose is to allow the lun to be reused within the i/o library.

$.02 -Ron Shepard

Re: Running print into file

<ea23c51f-fa43-49ec-a752-1e30ad6d35f4n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=917&group=comp.lang.fortran#917

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ac8:75c3:: with SMTP id z3mr1677424qtq.308.1623374385485;
Thu, 10 Jun 2021 18:19:45 -0700 (PDT)
X-Received: by 2002:a25:be09:: with SMTP id h9mr2335263ybk.239.1623374385300;
Thu, 10 Jun 2021 18:19:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 10 Jun 2021 18:19:45 -0700 (PDT)
In-Reply-To: <fzpwI.34164$9a1.30930@fx38.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:546:300:4c20:71ab:c458:def8:8a25;
posting-account=7tVJUQoAAACymEG6aShD5R0lhHCm_A0r
NNTP-Posting-Host: 2601:546:300:4c20:71ab:c458:def8:8a25
References: <s9aktp$2gs$1@dont-email.me> <s9al5h$15d$1@newsreader4.netcologne.de>
<s9g5hc$bls$1@dont-email.me> <s9g5si$kc8$1@dont-email.me> <9d1c3b9d-97bb-420a-a6e8-5a14f46e85f0n@googlegroups.com>
<fzpwI.34164$9a1.30930@fx38.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ea23c51f-fa43-49ec-a752-1e30ad6d35f4n@googlegroups.com>
Subject: Re: Running print into file
From: urbanjost@comcast.net (John)
Injection-Date: Fri, 11 Jun 2021 01:19:45 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: John - Fri, 11 Jun 2021 01:19 UTC

Unbuffered I/O can be very inefficient so I prefer not to use unconditional coding to force a flush, but prefer using commands like unbuffer(1) or environment variables when the extension is available, the drawback being that you cannot do it retroactively if you decide you want to peek at the output of a long running job long after you started it; but I do always do a flush after an error message as I have seen messages get lost if an abnormal termination follows but I don't think it even occurred to me to make it a critical region. I though a CLOSE did say it did an implicit flush but (without trying it) I would expect a CLOSE() /OPEN() to be (at least potentially) a very expensive method performance-wise so I would hesitate to do that except for critical rarely-encountered messages. I thought a CLOSE() did guarantee the file would be flushed but so far I do not see that in the standard, so I am starting to doubt that after all.

Re: Running print into file

<b6cd54cd-dd9b-40f6-9b08-772cd6ff7d6en@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=918&group=comp.lang.fortran#918

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ac8:5e46:: with SMTP id i6mr1706063qtx.366.1623374758342;
Thu, 10 Jun 2021 18:25:58 -0700 (PDT)
X-Received: by 2002:a25:d94a:: with SMTP id q71mr1252703ybg.49.1623374758235;
Thu, 10 Jun 2021 18:25:58 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!usenet.pasdenom.info!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 10 Jun 2021 18:25:57 -0700 (PDT)
In-Reply-To: <ea23c51f-fa43-49ec-a752-1e30ad6d35f4n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:546:300:4c20:71ab:c458:def8:8a25;
posting-account=7tVJUQoAAACymEG6aShD5R0lhHCm_A0r
NNTP-Posting-Host: 2601:546:300:4c20:71ab:c458:def8:8a25
References: <s9aktp$2gs$1@dont-email.me> <s9al5h$15d$1@newsreader4.netcologne.de>
<s9g5hc$bls$1@dont-email.me> <s9g5si$kc8$1@dont-email.me> <9d1c3b9d-97bb-420a-a6e8-5a14f46e85f0n@googlegroups.com>
<fzpwI.34164$9a1.30930@fx38.iad> <ea23c51f-fa43-49ec-a752-1e30ad6d35f4n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b6cd54cd-dd9b-40f6-9b08-772cd6ff7d6en@googlegroups.com>
Subject: Re: Running print into file
From: urbanjost@comcast.net (John)
Injection-Date: Fri, 11 Jun 2021 01:25:58 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: John - Fri, 11 Jun 2021 01:25 UTC

PS: I have noticed on certain platforms that some commands seem to cause files to flush, like strace(1) and suspending and resuming a process but it has varied wildly depending on the OS but thought it is worth mentioning in case someone knows of a system routine that causes a process to flush everything to disk that I have missed. If there is one and no command to go with it it would make a nice utility to make a program to do that, even if just on Linux or Unix.

Re: Running print into file

<sa1403$hlb$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=922&group=comp.lang.fortran#922

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: garylscott@sbcglobal.net (Gary Scott)
Newsgroups: comp.lang.fortran
Subject: Re: Running print into file
Date: Fri, 11 Jun 2021 20:52:04 -0500
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <sa1403$hlb$1@dont-email.me>
References: <s9aktp$2gs$1@dont-email.me>
<s9al5h$15d$1@newsreader4.netcologne.de> <s9g5hc$bls$1@dont-email.me>
<s9g5si$kc8$1@dont-email.me>
<9d1c3b9d-97bb-420a-a6e8-5a14f46e85f0n@googlegroups.com>
<fzpwI.34164$9a1.30930@fx38.iad>
<ea23c51f-fa43-49ec-a752-1e30ad6d35f4n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 12 Jun 2021 01:52:03 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="c9773248d932daeb4f814a2856192106";
logging-data="18091"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FC06Ns/n5xIPpOa3WYBkXQo4gx8WkOuw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:2c+304BR82FBDQiQWeNISJuoqf8=
In-Reply-To: <ea23c51f-fa43-49ec-a752-1e30ad6d35f4n@googlegroups.com>
Content-Language: en-US
 by: Gary Scott - Sat, 12 Jun 2021 01:52 UTC

On 6/10/2021 8:19 PM, John wrote:
> Unbuffered I/O can be very inefficient so I prefer not to use unconditional coding to force a flush, but prefer using commands like unbuffer(1) or environment variables when the extension is available, the drawback being that you cannot do it retroactively if you decide you want to peek at the output of a long running job long after you started it; but I do always do a flush after an error message as I have seen messages get lost if an abnormal termination follows but I don't think it even occurred to me to make it a critical region. I though a CLOSE did say it did an implicit flush but (without trying it) I would expect a CLOSE() /OPEN() to be (at least potentially) a very expensive method performance-wise so I would hesitate to do that except for critical rarely-encountered messages. I thought a CLOSE() did guarantee the file would be flushed but so far I do not see that in the standard, so I am starting to doubt that after all.
>
You could just read for a key press (peak, not a wait) and only flush
when the process is started (i.e. read for either key not pressed or
another key to stop)...

Re: Running print into file

<189cc11b-784f-419c-9bfa-d6e94830b4dfn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=924&group=comp.lang.fortran#924

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ac8:6885:: with SMTP id m5mr14886467qtq.268.1623639759948;
Sun, 13 Jun 2021 20:02:39 -0700 (PDT)
X-Received: by 2002:a25:d94a:: with SMTP id q71mr20186851ybg.49.1623639759752;
Sun, 13 Jun 2021 20:02:39 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sun, 13 Jun 2021 20:02:39 -0700 (PDT)
In-Reply-To: <sa1403$hlb$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:8003:2328:5a00:8185:191f:8238:eced;
posting-account=W6x0LgoAAADUV-yz4YE9o_6nxcvZvCmc
NNTP-Posting-Host: 2001:8003:2328:5a00:8185:191f:8238:eced
References: <s9aktp$2gs$1@dont-email.me> <s9al5h$15d$1@newsreader4.netcologne.de>
<s9g5hc$bls$1@dont-email.me> <s9g5si$kc8$1@dont-email.me> <9d1c3b9d-97bb-420a-a6e8-5a14f46e85f0n@googlegroups.com>
<fzpwI.34164$9a1.30930@fx38.iad> <ea23c51f-fa43-49ec-a752-1e30ad6d35f4n@googlegroups.com>
<sa1403$hlb$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <189cc11b-784f-419c-9bfa-d6e94830b4dfn@googlegroups.com>
Subject: Re: Running print into file
From: campbelljohnd01@gmail.com (JCampbell)
Injection-Date: Mon, 14 Jun 2021 03:02:39 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: JCampbell - Mon, 14 Jun 2021 03:02 UTC

On Saturday, June 12, 2021 at 11:52:06 AM UTC+10, Gary Scott wrote:
> On 6/10/2021 8:19 PM, John wrote:
> > Unbuffered I/O can be very inefficient so I prefer not to use unconditional coding to force a flush, but prefer using commands like unbuffer(1) or environment variables when the extension is available, the drawback being that you cannot do it retroactively if you decide you want to peek at the output of a long running job long after you started it; but I do always do a flush after an error message as I have seen messages get lost if an abnormal termination follows but I don't think it even occurred to me to make it a critical region. I though a CLOSE did say it did an implicit flush but (without trying it) I would expect a CLOSE() /OPEN() to be (at least potentially) a very expensive method performance-wise so I would hesitate to do that except for critical rarely-encountered messages. I thought a CLOSE() did guarantee the file would be flushed but so far I do not see that in the standard, so I am starting to doubt that after all.
> >
> You could just read for a key press (peak, not a wait) and only flush
> when the process is started (i.e. read for either key not pressed or
> another key to stop)..

While the use of CLOSE/OPEN might be considered expensive, if it is used once every 30 minutes (infrequently) this is not an issue. (There was an ifort/windows problem with repeated opening of the same file, but at the frequency I am using this approach, this problem has not been identified)
I used CRITICAL, to indicate I was using OpenMP and so sharing the unit 111 between all threads in a critical region appears to work effectively, overcoming any possible file buffer conflicts.
I also prefer a file output, rather than write (*.., managed via critical as it generates packets of reports that can be better understood and used as a run log. Write (* typically generates a mess and can easily overflow the screen buffer.
The way different O/S and compilers implement flush (I use gFortran on Windows), I would expect others to have different problems, but I suggested my approach as it has worked effectively for long mult-threaded runs.
If not addressed, my expoerience has been that gFortran does not flush text files which makes monitoring of long runs more difficult.

Re: Running print into file

<rLBxI.55349$431.27766@fx39.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=925&group=comp.lang.fortran#925

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!npeer.as286.net!npeer-ng0.as286.net!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx39.iad.POSTED!not-for-mail
Subject: Re: Running print into file
Newsgroups: comp.lang.fortran
References: <s9aktp$2gs$1@dont-email.me>
From: lkrupp@invalid.pssw.com.invalid (Louis Krupp)
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
MIME-Version: 1.0
In-Reply-To: <s9aktp$2gs$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Content-Language: en-US
Lines: 53
Message-ID: <rLBxI.55349$431.27766@fx39.iad>
X-Complaints-To: abuse(at)newshosting.com
NNTP-Posting-Date: Mon, 14 Jun 2021 05:25:43 UTC
Organization: Newshosting.com - Highest quality at a great price! www.newshosting.com
Date: Sun, 13 Jun 2021 23:25:42 -0600
X-Received-Bytes: 2112
 by: Louis Krupp - Mon, 14 Jun 2021 05:25 UTC

On 6/3/2021 7:19 AM, Dieter Britz wrote:
> This might be a Linux question but I'm not sure.
> When I run a Fortran program that prints a lot of stuff
> as it runs, directly, it does that. But when I run it
> offline, with the output going into a file, it only prints
> right near the end of execution. So that file is empty for
> the whole time.
>
> I run it with a script with this order:
>
> ./<script> >& <output file name> &
>
> Is there a way to run it so that it prints as it runs?

The 'script' command might work for you.

I compiled this program -- tsl.f90 (where "tsl" is short for "test
sleep" or something) -- as tsl:

===
program tsl
implicit none

integer n

do n = 1, 1000
    print *, n
    call sleep(5)
end do

end program
===

I ran it like this:

script -c ./tsl -f -O tsl.script

and it saved constantly flushed output in tsl.script.

Running it like this:

script -c ./tsl -f -O tsl.script > /dev/null

saved regularly flushed output in tsl.script but didn't send it to my
terminal window.

The saved script file has a header line "Script started on ..." and a
carriage return character after every output line.

I'm running Fedora 34. Your mileage may vary.

Louis


devel / comp.lang.fortran / Running print into file

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor