Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Fortran application not writing output to one of the .out files

94 views
Skip to first unread message

Sushant Mehan

unread,
Nov 8, 2022, 1:28:39 PM11/8/22
to
Hi All,

I am beginners in FORTRAN and dealing with huge FORTRAN project. I apologize in the beginning if my question sounded lame. Here is the issue

Blocks of Code where file was introduced and initiated. There are 300+ fortran files in the project. That's why using only a few blocks if thats helpful
open (178,file="instreamP.out")
write (178,12224)
12224 format ('Year Day Rch flow solp-in solp-out orgp
-in orgp-out EPC benp solp_benp orgp_benp so
lp_orgp ')

write (178,78) curyr,iida,jrch,flow,solpcon,dsolp,orgpcon,dorgp,
* epc,sedp_benthos(jrch),solp_benp_flux, orgp_benp_flux,
* solp_orgp_flux

The code executed successfully, and I ran the project, and my output file with name "instreamP.out is produced with headers, but there is no data in it.

I would appreciate any help in this matter. Also, I would appreciate any guidance on learning FORTRAN.

Thanks,
Sushant


jfh

unread,
Nov 8, 2022, 3:54:06 PM11/8/22
to
Is the program in fixed or free source form? The * in the two last lines are valid only in fixed source form but the format statement makes me wonder. Are the ends of lines in what you posted (where format 12224 occupies 3 lines) at the ends of lines in the actual program? What is format 78 and how were the things written with it declared and evaluated? We could possibly give useful help if provided with a minimal complete program, together with any error messages and warnings it gave at compile time and run time. What compiler was used?

gah4

unread,
Nov 8, 2022, 5:24:50 PM11/8/22
to
On Tuesday, November 8, 2022 at 10:28:39 AM UTC-8, sushan...@gmail.com wrote:

(snip)

> write (178,78) curyr,iida,jrch,flow,solpcon,dsolp,orgpcon,dorgp,
> * epc,sedp_benthos(jrch),solp_benp_flux, orgp_benp_flux,
> * solp_orgp_flux

> The code executed successfully, and I ran the project, and my output file
> with name "instreamP.out is produced with headers, but there is no data in it.

Without non-advancing I/O, which yours doesn't have, the least a Fortran WRITE
statement can write is a blank line.

As noted previously, showing the FORMAT statement number 78 would be nice.

But, most likely, your program isn't exectuting this WRITE statement.

Easy test is to put a

STOP 78

statement after the WRITE statement.

(The 78 is a reminder of where it stopped.)

That also guarantees that the output buffer is written out.

If the STOP 78 statement is not executed, you know it didn't get there.


Robin Vowels

unread,
Nov 8, 2022, 9:06:10 PM11/8/22
to
On Wednesday, November 9, 2022 at 5:28:39 AM UTC+11, sushan...@gmail.com wrote:
> Hi All,
>
> I am beginners in FORTRAN and dealing with huge FORTRAN project. I apologize in the beginning if my question sounded lame. Here is the issue
>
> Blocks of Code where file was introduced and initiated. There are 300+ fortran files in the project. That's why using only a few blocks if thats helpful
> open (178,file="instreamP.out")
> write (178,12224)
> 12224 format ('Year Day Rch flow solp-in solp-out orgp
> -in orgp-out EPC benp solp_benp orgp_benp so
> lp_orgp ')
>
> write (178,78) curyr,iida,jrch,flow,solpcon,dsolp,orgpcon,dorgp,
> * epc,sedp_benthos(jrch),solp_benp_flux, orgp_benp_flux,
> * solp_orgp_flux
>
> The code executed successfully,

No it didn't.

> and I ran the project, and my output file with name "instreamP.out is produced with headers, but there is no data in it.
>
> I would appreciate any help in this matter. Also, I would appreciate any guidance on learning FORTRAN.

You need to show the FORMAT statement 78.
It would seem that the second WRITE statement is never executed.
Insert a simple PRINT statement (e,.g., PRINT *, 'GOT HERE')
just before the second WRITE.

Sushant Mehan

unread,
Nov 8, 2022, 11:04:02 PM11/8/22
to
That's the problem. I am not getting any error messages. Apologies for my ignorance. I am not aware if the program is fixed or free. Since it is open source, so many people use it, and the convention changes from time to time. Unfortunately, there is no option here to link the *.f files else I Would have shared the program.

But I will try it now by being more detailed
This is one chunk of code in one file
write (178,79) curyr,iida,jrch,flow,solpcon,dsolp,orgpcon,dorgp,
* epc,sedp_benthos(jrch),solp_benp_flux, orgp_benp_flux,
* solp_orgp_flux
!! end if
79 format(3i4,10f12.3)

The other chunk is
open (178,file="instreamP.out")
write (178,12224)
12224 format ('Year Day Rch flow solp-in solp-out orgp
-in orgp-out EPC benp solp_benp orgp_benp so
lp_orgp ')

These are the only two blocks where the code was called, and no other place it was mentioned. Note: I changed 78 to 79 because 78 was used in another file of the same project.

I am sorry I want to be more detailed with my problem. If this won't work, I will put my code on google drive and share the link.

Kindest regards,
Sushant

Sushant Mehan

unread,
Nov 8, 2022, 11:05:47 PM11/8/22
to
Robin,

It seems you picked something. I saw that format 78 was called in other file. So I made 78 to 79 in my code and called it as follows:
This is one chunk of code in one file
write (178,79) curyr,iida,jrch,flow,solpcon,dsolp,orgpcon,dorgp,
* epc,sedp_benthos(jrch),solp_benp_flux, orgp_benp_flux,
* solp_orgp_flux
!! end if
79 format(3i4,10f12.3)

The other chunk is
open (178,file="instreamP.out")
write (178,12224)
12224 format ('Year Day Rch flow solp-in solp-out orgp
-in orgp-out EPC benp solp_benp orgp_benp so
lp_orgp ')

Any more suggestions?

Kindest regards,
Sushant

Sushant Mehan

unread,
Nov 8, 2022, 11:08:00 PM11/8/22
to
Hi Gah,

I think you were right. 78 was called in another file of the project. I replaced my 78 with 79 and tried running the project. Again, no error while compiling but the application is still not writing data to the "instreamP.out" file

This is one chunk of code in one file
write (178,79) curyr,iida,jrch,flow,solpcon,dsolp,orgpcon,dorgp,
* epc,sedp_benthos(jrch),solp_benp_flux, orgp_benp_flux,
* solp_orgp_flux
!! end if
79 format(3i4,10f12.3)

The other chunk is
open (178,file="instreamP.out")
write (178,12224)
12224 format ('Year Day Rch flow solp-in solp-out orgp
-in orgp-out EPC benp solp_benp orgp_benp so
lp_orgp ')

Any recommendations?

Kindest regards,
Sushant

gah4

unread,
Nov 8, 2022, 11:58:20 PM11/8/22
to
On Tuesday, November 8, 2022 at 8:04:02 PM UTC-8, sushan...@gmail.com wrote:

(snip)

> That's the problem. I am not getting any error messages.
> Apologies for my ignorance. I am not aware if the program is fixed or free.
> Since it is open source, so many people use it, and the convention changes
> from time to time. Unfortunately, there is no option here to link the *.f files else
> I Would have shared the program.

*.f files usually mean fixed form.

Statements have to start in column 7 (or more), with blanks or statement
number before that. But posting software likes to remove blanks at
the beginning of lines.

> But I will try it now by being more detailed
> This is one chunk of code in one file
> write (178,79) curyr,iida,jrch,flow,solpcon,dsolp,orgpcon,dorgp,
> * epc,sedp_benthos(jrch),solp_benp_flux, orgp_benp_flux,
> * solp_orgp_flux
> !! end if
> 79 format(3i4,10f12.3)

(snip)

> These are the only two blocks where the code was called, and no other place
> it was mentioned. Note: I changed 78 to 79 because 78 was used in another
> file of the same project.

Statement numbers only need to be unique within the same subroutine,
function or main program. In most cases, that is within one file.

> I am sorry I want to be more detailed with my problem
> If this won't work, I will put my code on google drive and share the link.

Seems to be some version of SWAT:

https://swat.tamu.edu/software/archive/

If you say which one, we can download it from the original source.

Though it seems that they supply already compiled versions.


Thomas Koenig

unread,
Nov 9, 2022, 1:40:00 AM11/9/22
to
Sushant Mehan <sushan...@gmail.com> schrieb:
Which system and which compiler are you running?

Is file 178 already open? In this case, calling open just modifies
the existing connection (which can be confusing). What happens
if you put a close(178) in front of the open?

What happens if you put a

flush 178

after each write? There was a bug in a version of Darwin which
impacted gfortran so that it did not flush files at program end.

Robin Vowels

unread,
Nov 9, 2022, 5:17:02 AM11/9/22
to
.
The OPEN statement must be executed before the WRITE (178 .. statement.
If it is not, the output will be written to another file, possibly called FOR178.
.
I suggested inserting a simple PRINT statement, just before the WRITE statement.
You need to do this, in order to find out whether the WRITE statement is being executed.

FortranFan

unread,
Nov 9, 2022, 9:04:25 AM11/9/22
to
On Tuesday, November 8, 2022 at 1:28:39 PM UTC-5, sushan...@gmail.com wrote:
> ..
> I am beginners in FORTRAN and dealing with huge FORTRAN project. I apologize in the beginning if my question sounded lame. Here is the issue
> ..
> I would appreciate any help in this matter. Also, I would appreciate any guidance on learning FORTRAN.
>

Hello @sushan...@gmail.com,

You may also want to inquire at the relatively recent Fortran Discourse site where you can attach Fortran source code with your posts, provide links, include code snippets with syntax highlighting, etc.
https://fortran-lang.discourse.group/

Re: learning Fortran, please see this page at fortran-lang.org that provides links to a lot of resources:
https://fortran-lang.discourse.group/

Sushant Mehan

unread,
Nov 9, 2022, 11:28:50 AM11/9/22
to
Hi Gah,

The version I am working on is not public. You can access the code files from here https://drive.google.com/file/d/1fvXani_-iwfwcaabzFEFoFffaLKOZTY5/view?usp=share_link
The snips I shared were from file readfile.f (L 153- 155) and watqual3.f (L764-768). Since this project's source code files are customized, I must compile them every time I run the project.

Hope this helps to answer my issue of not writing the data to the output file.

Thanks,
Sushant

Sushant Mehan

unread,
Nov 9, 2022, 11:33:22 AM11/9/22
to
Thanks, Thomas, for your response. Greatly appreciated. I am compiling code using CodeBlocks 20.3 on Windows 10 machine. and compiler is gfortran. I do not think the 178 is open already.

Sushant Mehan

unread,
Nov 9, 2022, 11:38:42 AM11/9/22
to
I appreciate the link to the sources. Thanks!

Sushant Mehan

unread,
Nov 9, 2022, 11:41:05 AM11/9/22
to
This is a great suggestion. I will try this right now and will share how it goes.

James Van Buskirk

unread,
Nov 9, 2022, 4:11:40 PM11/9/22
to
"FortranFan" wrote in message
news:3f6ce8bd-d99c-4150...@googlegroups.com...

> You may also want to inquire at the relatively recent Fortran
> Discourse site where you can attach Fortran source code with
> your posts, provide links, include code snippets with syntax
> highlighting, etc.
> https://fortran-lang.discourse.group/

Why are you always trying to move users of this group to
that Fortran discourse group? I took a look at it and a couple
of threads I noticed was one where apparently the speed of
the sieve of Eratosthenes was compared with a C++
implementation, but there was no code visible on the
forum so you couldn't identify the mistakes in the Fortran
code. I wrote a sieve at one time that was pretty fast for
sizes less than about 1.0e12 and maybe posted it here
but I don't have time and energy right now to search for
it.
Another thread was an inquiry that amounted to being
about procedures with the BIND attribute. I have been
working on code what needs to pop up OpenGL windows
to display graphics, so it needs to do stuff like ask the OS
to initiate a new thread (_beginthreadex), establish thread
local storage, and set up an OpenGL canvas. OpenGL itself
needs to be called. How you are supposed to achieve all
this without the interface capabilities introduced in f2003
is beyond me, but you wouldn't have a hint of this from
reading the thread.
To me, the forum is overall disappointing.

FortranFan

unread,
Nov 9, 2022, 6:10:47 PM11/9/22
to
On Wednesday, November 9, 2022 at 4:11:40 PM UTC-5, James Van Buskirk wrote:
> "FortranFan" wrote in message

> news:3f6ce8bd-d99c-4150...@googlegroups.com...
> > You may also want to inquire at the relatively recent Fortran
> > Discourse site where you can attach Fortran source code with
> > your posts, provide links, include code snippets with syntax
> > highlighting, etc.
> > https://fortran-lang.discourse.group/
> Why are you always trying to move users of this group to
> that Fortran discourse group? ..

"You talkin' to me"?

> To me, the forum is overall disappointing.

I think the Fortran Discourse is really a good place for all Fortran-related discussions. It is a very useful site generally and I think it is especially the case for anyone who shares about themselves as "I am beginners in FORTRAN" and "I would appreciate any guidance on learning FORTRAN"

To each their own in terms which online groups they want to use. That's why I merely suggest the Fortran Discourse site to posters, as in "You may also want to inquire at the relatively recent Fortran Discourse site .." I expect the posters will note "may" and "also" and appreciate the obvious which is that it's entirely up to them, they can do as they wish .. hopefully they become aware there are more resources out there to help with Fortran.

I will continue pointing out the Fortran Discourse site to whoever appears to be a new poster on Fortran-related matters.
0 new messages