Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26758 Discussions

Problem with alocation of character deferred length string in defined type

dajum
Novice
204 Views

I have defined a type in a module as:


    TYPE::CHARARRAY
        sequence
        CHARACTER*32 NAME
        CHARACTER(LEN=:),ALLOCATABLE :: CA(:)
        INTEGER VTYPE
        INTEGER NLEN
    END TYPE
    TYPE(CHARARRAY),ALLOCATABLE:: UDCA(:)

 

I then allocate the array as:
    ALLOCATE(UDCA(NUDCASIZE),STAT=ERR)

THen the string CA as:
    ALLOCATE(CHARACTER(LEN=CLEN)::UDCA(NUMUDCA+1)%CA(NSIZE),STAT=ERR)

Where CLEN, NUMUDCA, and NSIZE are all integers defined at runtime.

Looking at this in the debugger shows CA as an udefined pointer, but ERR=0 and checking ALLOCATED(UDCA(NUMUDCA+1)%CA) don't show any errors. The code seems to be able to set the string and print it out again.  But using it as an argument to a subroutine crashes:


        CALL SAVUDCA(NREC,UDCA(I)%CA,UDCA(I)%NLEN,NFILE)

Any idea why?

RUnning with PSXE2016

 

0 Kudos
6 Replies
IanH
Black Belt
204 Views

The debugger is probably telling fibs.  It does that, more often than not.

More code is required to diagnose the crash - ideally something runnable.  Obvious questions - is `i` in the range of 1:NUDCASIZE, has the CA component of element `i` been allocated (you say "the string..." in a few places, but there are actually NUDCASIZE deferred length strings), what's the interface of SAVUDCA, ...

(Why a sequence type?)

mecej4
Black Belt
204 Views

To expand on what IanH asked, let us suppose for a moment that NUDCASIZE = 5 and NUMUDCA = 4. You allocate UDCA as an array with  5 elements. Then, you allocate "the" string array component CA of UDCA(5) as an array of NSIZE elements, each of which is a character(len=CLEN) variable. That would leave UDCA(1)%CA, UDCA(2)%CA, UDCA(3)%CA and UDCA(4)%CA undefined. 

Along the same lines, without seeing the declarations of the argument list of your subroutine, it is impossible to state why the call caused a crash.

As you can see, you need to provide more details and be more precise in your description.

dajum
Novice
204 Views

The attached program exhibits the same failure. Thanks for the help!

IanH
Black Belt
204 Views

The value of I in the main program in the code in #4 is undefined. 

One of the dummy arguments in the subroutine is assumed shape.  An explicit interface is required for an assumed shape array, there is no such interface.

 

dajum
Novice
204 Views

Thanks!  Is the an option to get the compiler to warn about such things?

mecej4
Black Belt
204 Views
s:\lang>ifort /warn:all /check:all uam.f alloc.f
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.1.143 Build 20161005
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

alloc.f(15): warning #6717: This name has not been given an explicit type.   
        CALL SAVUDCA(NREC,UDCA(I)%CA,UDCA(I)%NLEN,NFILE)
-------------------------------^
alloc.f(15): error #7978: Required interface for passing assumed shape array is missing from original source.   [CA]
        CALL SAVUDCA(NREC,UDCA(I)%CA,UDCA(I)%NLEN,NFILE)
----------------------------------^
compilation aborted for alloc.f (code 1)

 

Reply