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

Problem with required data type

h-faber
Beginner
2,081 Views
Hi,
I am going slightly mad trying to fix the following error message:

"A CHARACTER data type is required in this context"

The code I got looks like

CHARACTER*(*) VAR1
.
.
.
VAR1 = SCHAUM()
.
.
.
CHARACTER*(*) FUNCTION SCHAUM ()
SCHAUM = 'SCHAUMSCHLAEGER'
RETURN
END FUNCTION SCHAUM

It does not help if I replace the *(*) figures by (len=80) or so. Besides I have no idea about the meaning of CHARACTER*(*) VAR1, haven't found any documentation about it.

Anyone here knowing more about this issue?

TIA

H.
0 Kudos
4 Replies
wkramer
Beginner
2,081 Views
You probably need an explicit interface to function SCHAUM(), so the compiler knows that SCHAUM returns with a character variable.
Add something like:
Interface
CHARACTER*(*) FUNCTION SCHAUM ()
SCHAUM = 'SCHAUMSCHLAEGER'
RETURN
END FUNCTION SCHAUM
End interface
to your declarations.
Walter
0 Kudos
h-faber
Beginner
2,081 Views
Hello Walter,
adding your two interface lines unfortunately does not change a thing, still the same error message. What might be of interest is that this code is contained in a file which begins with
SUBROUTINE MyFunc(Var1, Var2, Var3)
Maybe this plays a role in this issue?
0 Kudos
wkramer
Beginner
2,081 Views
Sorry, I have been a bit messy in my reply.
The following code for a complete program shows what I mean.
A charcacter*(*) function return value is not accepted in an interface block, so I changed it into character(len=15).
Walter
Code:
    program CharString
      implicit none
    ! Variables
      CHARACTER(len=80) VAR1
    ! Body of CharString
      CALL MyFunc(Var1)
    end program CharString

    SUBROUTINE MyFunc(Var1)
      implicit none
      CHARACTER*(*) VAR1
      Interface
        CHARACTER(len=15) FUNCTION SCHAUM ()
        END FUNCTION SCHAUM
      End interface
      VAR1 = SCHAUM()
    END SUBROUTINE
    
    CHARACTER(len=15) FUNCTION SCHAUM ()
      implicit none
      SCHAUM = 'SCHAUMSCHLAEGER'
      RETURN
    END FUNCTION SCHAUM

Message Edited by wkramer on 03-18-2005 04:57 AM

0 Kudos
h-faber
Beginner
2,081 Views
Hello Walter,
thx a bunch, I got it working now. :)
0 Kudos
Reply