gfortran46: Error: Type of argument 'z' in call to 'dimag' at (1) should be COMPLEX(16), not COMPLEX(8)
Anton Shterenlikht
mexas at bris.ac.uk
Thu Jul 11 23:49:50 UTC 2013
>From sgk at troutmask.apl.washington.edu Thu Jul 11 18:32:18 2013
>>
>>The correct fixes are to properly declare the variables via Fortran's
>>kind type parameter and to use generic intrinsic functions.
>
>Please fix the quoting mechanism of your email client to
>NOT use tab characters. It leads to alot of wasted screen
>real estate.
>
>>$ cat dcargu.f
>> FUNCTION DCARGU(C)
>> IMPLICIT REAL*8 (A-H,O-Z)
>> REAL*8 DCARGU
>> COMPLEX*16 C
>
>> IF (DIMAG(C).GT.0.D0) THEN
>
>I suspect you are being hit by -fdefault-real-8 or
>similar option. If this is the case, you may want
>to ask the ASTER developers if they know what that
>option actually does.
(cc to thierry@ - the maintainer)
It's actually in the port's Makefile:
.if ${ARCH} == "i386"
FLAGARCH= -DP_LINUX -DLINUX
FFLAGARCH=
.else
FLAGARCH= -DLINUX64
FFLAGARCH= -fdefault-integer-8 -fdefault-real-8
.endif
Anyway, please correct my analysis if it's wrong.
complex*16 is the same as complex(kind=8), meaning
16 bytes total, or two 8-byte reals.
The effect of -fdefault-real-8 is to make DIMAG
expect not complex(8) but complex(16), but *only*
on platforms where complex(16) is supported.
And on ia64 is does not seem to be supported,
and -fdefault-real8 has no effect on ia64:
$ uname -a
FreeBSD mech-cluster241.men.bris.ac.uk 10.0-CURRENT FreeBSD 10.0-CURRENT #5 r252055: Fri Jun 21 15:57:18 BST 2013 root at mech-cluster241.men.bris.ac.uk:/usr/obj/usr/src/sys/TZAV ia64
$ cat z.f90
complex*16 :: z
z = (1,2)
write (*,*) dimag(z)
end
$ gfortran46 -Wall z.f90
$ ./a.out
2.0000000000000000
$ gfortran46 -Wall -fdefault-real-8 z.f90
$ ./a.out
2.0000000000000000
$
In contract, on amd64, -fdefault-real-8 makes
DIMAG expect complex(16), but complex(8) is given.
And changing the declaration to complex(16) makes
the code compile and work as expected, i.e. increase
the number of significant digits roughly by a factor of 2:
$ cat z.f90
complex*16 :: z
z = (1,2)
write (*,*) dimag(z)
end
$ gfortran46 z.f90
$ ./a.out
2.0000000000000000
$ gfortran46 -fdefault-real-8 z.f90
z.f90:3.18:
write (*,*) dimag(z)
1
Error: Type of argument 'z' in call to 'dimag' at (1) should be COMPLEX(16), not COMPLEX(8)
$ sed s/\*16/\(kind=16\)/g z.f90 > zz.f90
$ cat zz.f90
complex(kind=16) :: z
z = (1,2)
write (*,*) dimag(z)
end
$ gfortran46 zz.f90
zz.f90:3.18:
write (*,*) dimag(z)
1
Error: Type of argument 'z' in call to 'dimag' at (1) should be COMPLEX(8), not COMPLEX(16)
$ gfortran46 -fdefault-real-8 zz.f90
$ ./a.out
2.0000000000000000000000000000000000
$
Anyway, it is important to know that -fdefault-real-8
does not affect the complex declarations.
I agree with you that this routine from the
Aster code is not very well written, i.e.
is not written with portability in mind.
However, code_Aster is massive and I don't think
it likely the developers will want to fix
issues like this.
I'm not sure what to do about this.
Anton
More information about the freebsd-fortran
mailing list