Eamorr
Eamorr

Reputation: 10012

Fortran pointer error: "Invalid character in name "

I have a file called m_mixing.F90.

Inside this file, there's a function which is giving a compile error:

function getstackval(mix,sidx,hidx) result(d1)
    type(tMixer), intent(in) :: mix
    integer, intent(in) :: sidx
    integer, intent(in), optional :: hidx

    real(dp), pointer, contiguous :: d1(:)   !!This line is causing problems!

    type(dData1D), pointer :: dD1

    if ( present(hidx) ) then
       dD1 => get_pointer(mix%stack(sidx),hidx)
    else
       dD1 => get_pointer(mix%stack(sidx), &
            n_items(mix%stack(sidx)))
    end if

    d1 => val(dD1)

  end function getstackval

I compile as follows:

mpiifort -c -g -DMPI -DFC_HAVE_FLUSH -DFC_HAVE_ABORT m_mixing.F90

Here is the error:

/opt/apps/siesta/siesta-trunk-r561/Src/m_mixing.F90:2533.13:

real(dp), pointer, contiguous :: d1(:)

.............1

1 Error: Invalid character in name at (1)

It doesn't seem to like the "pointer" key word?

Can anyone give me some tips? I'm a Fortran novice.

Upvotes: 0

Views: 628

Answers (1)

jlokimlin
jlokimlin

Reputation: 593

@francescalus is right. Your version of ifort doesn't support the perfectly legalcontiguous attribute for function results yet. For any new Fortraners out there, the contiguous attribute was introduced in Fortran 2008 for array pointers and assumed-shape dummy arrays. Examples of non-contiguous arrays are:

foo(::2) ! odd-numbered elements
bar%re   ! real part of a complex array

Telling the compiler that an array is contiguous simplifies memory traversal and element address calculations, potentially improving performance.

Contiguity can be tested with the inquiry function is_contiguous(x) where x is an array of any type. This returns a default logical scalar with the value .true. if x is contiguous and .false. otherwise. If x is a pointer, it must be associated with a target.

Arrays in the C-language are always contiguous, so c_loc in ISO_C_binding was not permitted in Fortran 2003 for an array pointer or assumed-shape array. In Fortran 2008+, c_loc is permitted for any target that is contiguous (at execution time). For array pointers, the contiguous attribute has a runtime requirement that it be associated only with a contiguous target (via pointer assignment).

ptr => some_target

However, it is the programmer’s responsibility to ensure that the pointer will never become associated with a non-contiguous section; hence, checking is_continuous(ptr) after each pointer assignment is a must.

Upvotes: 2

Related Questions