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!

How do I print a real number using GNU gfortran

Status
Not open for further replies.

rdflg

Instructor
Aug 21, 2024
2
Hi,
I am new to Fortran...but not programming. Why won't this program work? I can print integers but not reals.

PROGRAM print_real
IMPLICIT NONE
REAL :: x
x=3.14
PRINT *,x
END PROGRAM print_real

It compiles fine with gfortran (v12.3.0) but when run gives the following...

"Program received signal SIGILL: Illegal instruction.
Backtrace for this error."

The above program runs using a Fortran77 compiler, though. I installed gcc-12.3.0-32.exe and am running Windows Vista on a 32-bit machine.
I've downloaded kindfinder.F90, and have tried all sorts of KINDs (2,4,8,16) and different precisions and ranges (using SELECTED_REAL_KIND).
I BET the solution is blindingly simple. MANY thanks.

Rdflg
 
Is that version compatible with your 32 bit machine? You may have installed the 64 bit version.
 
Hi rdflg,

I tried what you posted and it works for me:

rdflg.f95
Code:
PROGRAM print_real
  IMPLICIT NONE
  REAL :: x
  x=3.14
  PRINT *,x
END PROGRAM print_real

I compiled it with gfortran and it runs without error:
Code:
$ gfortran rdflg.f95 -o rdflg
$ ./rdflg
   3.14000010

I have this gfortran version on Linux
Code:
$ gfortran --version
GNU Fortran (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Maybe something is wrong with your gfortran compiler installation
 
Is that version compatible with your 32 bit machine? You may have installed the 64 bit version.
Hi,
Could I sincerely thank ALL of you who replied - it would take too long to thank everyone individually - for your useful suggestions. I never did find the problem, but suspect, as some people suggested, it was a compiler problem. So, I gave up with the GNU gfortran compiler and found an old copy of obsolete Silverfrost Fortran (version 7 - the latest version is probably version 157 now!) on the interent, which solved the problem. Running an ancient copy of Windows Vista, probably meant I was on a hiding to nothing right from the beginning. Hey ho. Live and learn?

Thanks again, guys (and guyesses!)

Simon (AKA rdflg)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top