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
Anfänger
787Aufrufe
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 Antworten
Steven_L_Intel1
Mitarbeiter
787Aufrufe
LEN is the standard intrinsic for this. What's the problem?
lklawrie
Einsteiger
787Aufrufe
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.
mecej4
Geehrter Beitragender III
787Aufrufe
> 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.
Steven_L_Intel1
Mitarbeiter
787Aufrufe
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.
Ralph_Nelson
Anfänger
787Aufrufe
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.
Antworten