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

string length

Ralph_Nelson
Novice
786 Views
Rebuilding an old Cray F77 program that had the following:

integer lpref
character*(*) prefix
lpref = len(prefix)

where "len" was a fuction returning the length of "prefix"

Did a quick google but couldn't find an easiest way to find the lenght of a character string in intel fortran.

Could you suggest the easiest way? Surely there is one and it is just my search abitlities that are lacking.

Thanks
0 Kudos
5 Replies
Steven_L_Intel1
Employee
786 Views
LEN is the standard intrinsic for this. What's the problem?
0 Kudos
lklawrie
Beginner
786 Views
LEN(charvar) will give you the length of the character variable.

LEN_TRIM(charvar) will give you the length of the string (leading spaces included)

That's my understanding at least.
0 Kudos
mecej4
Honored Contributor III
786 Views
> LEN_TRIM(charvar) will give you the length of the string after removing trailing spaces (leading spaces included)

There is nothing specific to Cray Fortran here. Furthermore, len is a standard intrinsic function and its definition is not vendor-dependent.

Googling "Fortran len function" generated a number of pertinent links.
0 Kudos
Steven_L_Intel1
Employee
786 Views
And for completeness I should add that LEN_TRIM looks at trailing spaces only. It does not consider a NUL or a TAB to be a space.
0 Kudos
Ralph_Nelson
Novice
786 Views
Thanks for all the replies folks.

I had added "implicit none" to clear up the variables in the subroutines plus added several compiler attributes in the process. Doing some clean up and then recompilng, it disappeared so it could have been commenting of the variable itself or I didn't look closely enough.
0 Kudos
Reply