Why won't this Fortran90 program compile?

MarkLoveExEx
MarkLoveExEx used Ask the Experts™
on
What's wrong with this Fortran90 program? I can't get it to compile...
HEtoGrib2.f90.txt
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I get this error:
HEtoGrib2.f90_error.txt
JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018

Commented:
It has been a very long time since I have used Fortran, but the error says you have not linked in the modules you need to successfully compile. When you compile any program, there is an opportunity to link in canned (pre-programmed) routines. Have you done this?
Developer
Fellow 2017
Most Valuable Expert 2018
Commented:
What commands are you using to compile it and/or link it with the necessary libraries to generate an executable? For example, to compile it, you'll use something like this:

gfortran -c HEtoGrib2.f90

To create an executable, you'll use something like this:

gfortran -o ExecutableName object1.o object2.o object3.o

You'll have as many objectN.o libraries as necessary — that's where your functions and subroutines called by HEtoGrib2 will be located (lenstr, stoi, rdxmrg, baopenw, gribcreate, addgrid, addfield, gribend, wryte). Regards, Joe
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I compiled the HEtoGrib2.f90 program using the following command:

gfortran -c HEtoGrib2.f90

which seemed to compile without error. It produced a file called HEtoGrib2.o

I then ran the following:

HEtoGrib2.o /home/oper/practice3/ serfc_xmrg1119201506z /home/oper/practice3/ mygrib.grb

but I got the following error:

HEtoGrib2.o: HEtoGrib2.o: cannot execute [Exec format error]

Do you know what I'm doing wrong? Maybe my input file is not compatible...
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
I'm not knowledgeable in Unix/Linux, but my guess is that your command line needs to include the object code files (object1.o, object2.o, etc.) that have all the functions and subroutines that you're calling (lenstr, stoi, rdxmrg, baopenw, gribcreate, addgrid, addfield, gribend, wryte). It makes sense that the compile is successful — it is the linking into an executable that is failing because it can't find the object code files needed. Regards, Joe
>> I then ran the following:
>>  HEtoGrib2.o /home/oper/practice3/ serfc_xmrg1119201506z /home/oper/practice3/ mygrib.grb
HEtoGrib2.o is an object module, not an executable, so you cannot run it.

>> gfortran -c HEtoGrib2.f90
I think the -c option means to create an object module and do not continue to create an executable.

>> call baopenw(lunout,trim(filename),ierr)
>> HEtoGrib2.f90:(.text+0x337e): undefined reference to `baopenw_'
There is a subroutine baopenw that must be defined somewhere. In what file did you define it?
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
> I think the -c option means to create an object module and do not continue to create an executable.

Yes, that's correct. You need to use the -o option to create the executable. See my earlier post that discusses it:
http:#a41288845

Regards, Joe

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial