Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Catastrophic compiler error

Adrian_F_1
Beginner
895 Views

The following code gives a catastrophic compiler error:

      CHARACTER(*) FUNCTION fmt(rr)
      IMPLICIT NONE
      REAL*8 :: rr
      CHARACTER(LEN=LEN(fmt)) :: cc
      WRITE(cc,'(4g13.5)') rr
      IF(cc == '      0.00000') cc = '  0.00000'
      fmt = cc
      RETURN
      END

D:\Devl.OLI\OLIEngines\src\asap>ifort a.for
Intel(R) Visual Fortran Compiler Professional for applications running on IA-32, Version 11.1    Build 20100414 Package ID: w_cprof_
p_11.1.065
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

a.for(4): catastrophic error: **Internal compiler error: internal abort** Please report this error along with the circumstances in w
hich it occurred in a Software Problem Report.  Note: File and line given may not be explicit cause of this error.
      CHARACTER(LEN=LEN(fmt)) :: cc
--------------------^
compilation aborted for a.for (code 3)

0 Kudos
6 Replies
Steven_L_Intel1
Employee
895 Views

I thought I had seen everything...  I don't think this usage is legal, but in any case an internal compiler error is the wrong response. I will let the developers know - thanks. The issue ID is DPD200244699.

Looking at what the standard allows in a specification expression, fmt is not a dummy argument, COMMON variable nor is it accessed by use or host association. So the only clause that might allow it is:

22 (9) a specification inquiry where each designator or function argument is
23 (a) a restricted expression or
24 (b) a variable whose properties inquired about are not
25 (i) dependent on the upper bound of the last dimension of an assumed-size array,
26 (ii) deferred, or
27 (iii) defined by an expression that is not a restricted expression,

I think LEN(fmt) fails all of these. The length is not "deferred" in the way the standard means it - that would mean LEN=:.

A CHARACTER(*) function is a deprecated feature and is often misunderstood. I recommend avoiding it.

0 Kudos
Adrian_F_1
Beginner
895 Views

Thanks Steve, just need to make one minor fix to the code (I can't edit it for some reason) - remove the "4" from the write statement.

0 Kudos
Steven_L_Intel1
Employee
895 Views

You can remove the whole WRITE statement and still get the error. It has to do with the use of LEN(FMT) when declaring cc.

0 Kudos
Adrian_F_1
Beginner
895 Views

How would you write this code without using a character(*) function?

0 Kudos
Steven_L_Intel1
Employee
895 Views

I am not completely certain what you want to do, but perhaps something like this:

[fortran]
module fmtmod
implicit none
contains
function fmt (rr)
character(:), allocatable :: fmt
real(8), intent(in) :: rr
! Initially allocate result to 13 characters for the write
allocate (character(13) :: fmt)
write (fmt,'(G13.5)') rr
fmt = trim(fmt)
end function fmt
end module fmtmod
[/fortran]

You would need to USE FMTMOD to make this accessible - I did this because an explicit interface is required and this is the easiest way.

0 Kudos
Steven_L_Intel1
Employee
895 Views

In a future release, the compiler will give a reasonable error message for this case.

0 Kudos
Reply