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

character allocatable

Intel_C_Intel
Employee
607 Views
One fast question.
How can I declare a charater string as ALLOCATABLE
e.g
character :: string*5000

I want to have
character, ALLOCATABLE :: string(:)
How to allocate this string for e.g 5000 characters ?
Using ALLOCATE (string(*5000)) does not work.
Using ALLOCATE (string(5000)) works but the I get error messages when compiling with code using this string.
0 Kudos
2 Replies
dave_frank
Beginner
607 Views
you undoubtedly are trying to use the string array
ie. allocate ( string(5000) )
as a string.
but its NOT a string despite you calling it one.

you cant allocate a character string in F95,
but you can in F2003..

what you can do is switch gears by using your "string"
as a subroutine argument and use the array as a string in the subroutine..
0 Kudos
Jugoslav_Dujic
Valued Contributor II
607 Views
Erm, you can't, at least not in F95 standard. It will be possible in next F2000 standard, but you'll have to wait for that loooong.

Second form, as you discovered, is usable in some contexts, but cannot be used everywhere where normal strings are required.

Also, you can google for ISO_VARYING_STRING module. This is an extension to standard which defines operations on a user-defined TYPE. One incarnation (allegedly without memory leaks, which are a pain with POINTERs within derived types) can be found here. (Didn't try it myself).

Jugoslav
0 Kudos
Reply