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!

gfortran 4.8 vs. gfortran 4.3

Status
Not open for further replies.

kweemstra

Programmer
Apr 18, 2013
5
NL
Hi all,

Just new to the forum, but I think it's great that these forums exist!
I'm running MAC OS X 10.6 on a macbook pro. I just installed gfortran version 4.8 (which was probably the latest one, because it was chosen by default) through the homebrew 'package manager' on this macbook. I used to have gfortran version 4.3 on my older computer and was able to compile. I compile using a make-file, and most dependencies (modules) of the main program compile without complication. The following module, however, gives me an error:

Code:
module timers
implicit none
public
integer, private :: time_array(8)

contains
!----------------------------------------------------------------
  subroutine start_timer(time)
    real :: time
    call date_and_time(values=time_array)
    !time = time_array(5)*3600. + time_array(6)*60. + time_array(7) + 0.001*time_array(8)
    time=time_array(5)*3600+time_array(6)*60+time_array(7)+ 0.001*time_array(8)
    write(0,*)time_array(5)
    !write(0,*)time
  end subroutine start_timer
!----------------------------------------------------------------
  subroutine end_timer(ftime,stime)
    real :: ftime,stime
    call date_and_time(values=time_array)
    !ftime = (-1.*stime+(time_array (5)*3600. + time_array(6)*60. + time_array(7) + 0.001*time_array(8)))
    !write(0,*)ftime,stime
  end subroutine end_timer
!----------------------------------------------------------------
end module timers

where the error is:

gfortran -c SRC/Timers.F90 -g -Wall -fbounds-check -fbacktrace -J./MOD -o OBJ/Timers.o
f951: internal compiler error: Illegal instruction

f951: internal compiler error: Abort trap
gfortran: internal compiler error: Abort trap (program f951)
make: *** [OBJ/Timers.o] Abort trap


After some checking it turns out the compiles stumbles over the following snippet:

Code:
0.001*time_array(8)

Hence it seems like one is not allowed to use such floating point constructs in the code??
Anyone familiar with this problem? And how to fix it? Is there a flag I can set, such that it actually swallows this or do I need to change the code (and other modules/routines having similar constructs?).
Thanks in advance!

Cheers,
Kees

 
You specified time_array to be an integer. This is not compatibel to multiplication by 0.001
You might want to convert the variables to real before multiplication

Code:
time = float (time_array(5)) * 3600. + float (time_array(6)) * 60. + float (time_array(7)) +  0.001 * float (time_array(8))


Norbert



The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Hi Norbert,

Thanks for your post. I realize that this is sloppy, but that doesn't solve the problem.
It seems like it really has to do with the value of 0.001 ??
Is it not allowed to use floats in such a format (in version 4.8)?
Thanks anyway.

Kees
 
Unfortunately I am not using gfortran but an older f90/95 compiler.
I copied and pated your code and it compiled fine, without errormessage. So I thought your compiler might be especially picky in its diagnostics. Outside of this I could not recognise anything fishy in your code.

There could not be any restriction in using 0.001 in this format. This would kill most of fortran applications, I'd say.

If I were you, I would try the following:

(1) perform the transformation stepwise to see if it is really this multiplication by 0.001 that causes the errormessages like
Code:
time = float (time_array(5) * 3600.0
time = time + float (time_array(6)) * 60.0
time = time + float (time_array(7))
time = time + float (time_array(8)) * 0.001  ! or / 1000.0

(2) just define a variable and multiply by this
Code:
...
real a3600, a60, a001
a3600 = 3600.
a60 = 60.
a001 = 0.001
...
time = float (time_array(5) * a3600
time = time + float (time_array(6)) * a60
time = time + float (time_array(7))
time = time + float (time_array(8)) * a001

All of this is code that should work - like yours.

Good Luck.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Sorry, but I don't understand this
Code:
...
public
integer, private :: time_array(8)
...
What is then public and what is private?
 
public (without a list) specifies that all entities within the module - unless pecified otherwise - could be accessed from outward routines that use this module (where this module is specified in a use-statement). This statement is not necessary as this is the default status.

integer, private :: time_array(8) specifies, that this array cannot be accessed from outside but only from the routines pecified within the module.

This would not work with the above module and should create a compiler error:

Code:
subroutine garbage()
implicit none

use timers

time_array = 0
return

Of course, the two lines seem to be a little awkward with timers having time_array as the only entity, but this is legal programming, for a module may contain generally public items with only a few privates.

Norbert

The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Ok. Thanks again for your help Norbert. It's appreciated.
All right, seems to me something weird is going on here. This is the updated code:

Code:
module timers
implicit none
public
integer, private :: time_array(8)
real, private :: a3600, a60, a001
a3600 = 3600.
a60 = 60.
a001 = 0.001

contains
!----------------------------------------------------------------
  subroutine start_timer(time)
    real :: time
    call date_and_time(values=time_array)
    !time = time_array(5)*3600. + time_array(6)*60. + time_array(7) + 0.001*float(time_array(8))
    time = float (time_array(5) * a3600
    time = time + float (time_array(6)) * a60
    time = time + float (time_array(7))
    time = time + float (time_array(8)) * a001
    !write(0,*)time
  end subroutine start_timer
!----------------------------------------------------------------
  subroutine end_timer(ftime,stime)
    real :: ftime,stime
    call date_and_time(values=time_array)
    !ftime = (-1.*stime+(time_array (5)*3600. + time_array(6)*60. + time_array(7) + 0.001*(float(time_array(8))))
    ftime = -1.*stime
    ftime = ftime+ float(time_array(5) * a3600
    ftime = ftime + float(time_array(6)) * a60
    ftime = ftime + float(time_array(7))
    ftime = ftime + float(time_array(8)) * a001
    !write(0,*)ftime,stime
  end subroutine end_timer
!----------------------------------------------------------------
end module timers

Sadly, this is the new error message:

gfortran -c SRC/Timers.F90 -g -Wall -fbounds-check -fbacktrace -J./MOD -o OBJ/Timers.o
SRC/Timers.F90:6.13:

a3600 = 3600.
1
Error: Unexpected assignment statement in MODULE at (1)
SRC/Timers.F90:7.9:

a60 = 60.
1
Error: Unexpected assignment statement in MODULE at (1)
f951: internal compiler error: Illegal instruction

f951: internal compiler error: Abort trap
gfortran: internal compiler error: Abort trap (program f951)
make: *** [OBJ/Timers.o] Abort trap


I really don't get what's going on here! It is also weird that the compiler doesn't complain about the
Code:
a001 = 0.001
statement.
This is proper code if you would ask me...
I'm thinking about falling back to gfortran 4.3, but it shouldn't be necessary.
What do you think?

Regards,
Kees
 
As far as I know, you cannot put any assignment-statements like a3600 = .... into a module's body. To assign values, then you should do it during initialising:

Code:
real, private :: a3600 = 3600.0
real, private :: a60 = 60.0
real, private :: a001 = 0.001

But still we have this 'illegal instruction' message.
I very much doubt that the problem is in the statement referencing the constant 0.001.

Just for testing:

J1) What does happen if you do not declare time-array and the others as private?
(2) Does your code compile when you do comment off the calls to date_and_time?

Just wondering...

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Yeah. Ok. I see.
So I've brought it down to the following:

Code:
module timers
implicit none
public
!integer, private :: time_array(8)
!real, private :: a3600, a60, a001

integer,private :: time_array(8)
real,private :: a3600=3600.
real,private :: a60=60.
!real,private :: a001=0.001

!a3600=3600.
!a60=60.
!001=0.001

contains
!----------------------------------------------------------------
!  subroutine start_timer(time)
!    real :: time
!    call date_and_time(values=time_array)
!    time = time_array(5)*3600. + time_array(6)*60. + time_array(7) + 0.001*float(time_array(8))
!    time = float (time_array(5) * a3600
!    time = time + float (time_array(6)) * a60
!    time = time + float (time_array(7))
!    time = time + float (time_array(8)) * a001 
!    !write(0,*)time
!  end subroutine start_timer
!!----------------------------------------------------------------
!  subroutine end_timer(ftime,stime)
!    real :: ftime,stime
!    call date_and_time(values=time_array)
!    !ftime = (-1.*stime+(time_array (5)*3600. + time_array(6)*60. + time_array(7) + 0.001*(float(time_array(8))))
!    ftime = -1.*stime
!    ftime = ftime+ float(time_array(5) * a3600
!    ftime = ftime + float(time_array(6)) * a60
!    ftime = ftime + float(time_array(7))
!    ftime = ftime + float(time_array(8)) * a001 
!    !write(0,*)ftime,stime
!  end subroutine end_timer
!----------------------------------------------------------------
end module

The code above compiles, which makes sense, because pretty much everything is commented out. If I now uncomment the declaration of a001, it doesn't compile anymore and I end up with the same notorious error. (illegal instruction..).
It's so weird... We must be overlooking something here.

regards,
Kees
 
All right. I just fell back on an older version of gfortran and it compiles now. Conclusion: Don't install gfortran 4.8 on a mac running snow leopard. Although I still don't understand why it doesn't work at this moment. Thanks again Norbert!

Cheers,
kees

 
Well, yes, this sounds pretty weird - and your conclusion seems to be the only proper reaction.

Have fun
Norbert

The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top