Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with headers in fortran 1

Status
Not open for further replies.

anmorgan

Programmer
Mar 27, 2012
5
US
So I will start out this generically and explain my specific task if needed. In general if I have a .h file in fortran, how do I include it properly, assume f77.

Some background on environment:
Windows 7 using cygwin compiling with x86_64-w64-mingw32-gfortran.exe for 64-bit compilation.

thanks
 
First of all, I took on the practice of NOT giving the extension *.h to 'include' files for Fortran; instead, I have chosen the extension *.inc (for INClude file)...this way, if I have a program that includes Fortran as well as C files, I can still tell them apart. Also, I can programatically pick them, like from make files, etc.

In any case, including a file is simple:
include 'file.inc'


 
I am not so very sure, if the include-statement is part of FORTRAN 77 for my docs of the Compaq-Compiler do not show any reference to it in FORTRAN 77.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
I only know that include is part of the old g77 compiler and works with both forms: fixed-form and free-form.
 
Thanks for the responses. I'm specifically trying to use OpenMPI with fortran and they have a "mpif.h" header (in fortran), so the header is not in my control.

The error I'm getting is if I include or even past the content of the header at the top of my code, which also has an include, the compiler acts as if the code after the header is not correct, example:

MPI_FTest.F:3.72:

program MPI_FTest
1
Error: Unexpected PROGRAM statement at (1)

This is the type of error I get.

It could be as simple as:

include 'mpif.h'
program myprogram
print *, "Hello"
end program myprogram

And still gives error, Install for openMPI is located here: if you want to install and try it out. Its small so it wouldn't take long to download and install.
 
That's because a program can only have one program in it...

It looks like your *.h file is not quite a header file; instead, it seems to be a program in its own right with the 'program' keyword in it, that is used to test MPI.

Inspect the *.h file and make sure it has a lot more than the 'program' part..maybe you can delete that part altogether and leave the remaining part that actually only declares variables, functions, subroutines, but no 'program'
 
No that is not correct. I don't know why you would assume something like Open MPI would do something like that and I checked, it's only declarations.

I'm not sure why forums like to theorize about solutions. I appreciate the feedback, but please don't off of assumptions. I'm probably missing something, but I don't know fortran that well.
 
Dude, tone it down...keep it up and you will stop getting any kind of help.

Often, forums HAVE to theorize for various reasons...sometimes the OP does not even ask the right question or does not provide enough info or it's sooo totally clueless that he/she does not even ask the right question...and so the forum is left to theorize....this is not such a bad thing, it provides other things to at least rule them out, etc...

Good luck

Over and out from this thread.

 
That was not my intention. It just bugs me when someone starts theorizing the solution before they know the problem (its happened to me a lot on forums). If you were offended by comments I'm sorry. Everyone has the ability to improve, especially me :)

On that note, probing questions are better, rather then pointing fingers at what could be.
 
The PROGRAM statement is optional. Within a program unit, a PROGRAM statement can be preceded only by comment lines

So swap line 1 and 2 in your code and you should be fine.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
I only know that include is part of the old g77 compiler and works with both forms: fixed-form and free-form.

Yes, mikrom, you are right. I checked and I found that the g77 compiler shows many features, that the docs of my Compaq compiler does not show in its list of Fortran 77 statements.

And I checked in the fortran 77 standard and did not find any reference to an include statement neither. So g77 apparently shows some non-standard fortran 77 extensions. And as anmorgan expressed that he uses f77 then this might be a problem. But in his second post he did not say anything about his compiler complaining about the include, so his compiler seems to be advanced as well.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Thank you gummibaer, that was it, it should be in the format:

program myprogram
include 'mpif.h'

print *, "Hello"

end program myprogram

Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top