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

Inverse function of LEN_TRIM

madsplinter
Beginner
496 Views

Hi there,

I'm writing a subroutine that accepts a string of variable lenght as input. The maximum lenght of the string is 128 characters and so that's the lenght I've defined for it in the subroutine.

Now, this isthe problem: when I pass to the subroutine a string shorter than 128 characters I get an errorof "Character length argument mismatch". I thought that I could solve the problem using a function that does the inverse job of LEN_TRIM, that is, adds at the end of the input string a series of blank spaces in order to arrive at a desired lenght.

Is there a function like this already implemented in fortran?

Or maybe youhave another way to solve the problem?


0 Kudos
2 Replies
TimP
Honored Contributor III
496 Views
How about simple assignment?

character(len=128) padded128_string

padded128_string = trimmed_string


0 Kudos
Steven_L_Intel1
Employee
496 Views
Is there a specific reason you defined the length as 128 in the subroutine? Using :LEN=*, where the length is taken from that of the argument, is the more usual approach and avoids this problem.

There is no intrinsic to pad a string out to a given length, but you could write a function to do this easily enough:

function pad (string, length)
character(len=length) :: pad
character(len=*, intent=in) :: string
integer, intent=in :: length

pad = string
return
end function pad
0 Kudos
Reply