1

How could I find the size of a dynamically allocated object path in subroutine newcase?

  subroutine newcase(path)

  character(:, kind=c_char),
 &     allocatable                     :: path
  integer(kind=c_int)                  :: sizepath

  write(*,*) "Trim Path: ", path, ":"
  this% object = newcase_c(path, sizepath)

  end subroutine newcase

The object is allocated when the subroutine is called as shown below:

  character(256, kind=c_char)   :: cwd
  character(:, kind=c_char)
 & , allocatable                :: trimpath

  call GETCWD(cwd)
  trimpath = trim(cwd)

  call newcase(trimpath)
2
  • 2
    With the shown code, the variable 'path' has no size as it is unallocated. Commented Apr 16, 2019 at 2:24
  • 3
    What function do you use to find the length of character variables, even if they are not allocatable? Commented Apr 16, 2019 at 5:51

1 Answer 1

1

I used len to find the length of path. Documentation is here.

Sign up to request clarification or add additional context in comments.

1 Comment

len will give you the length of the string including trailing blanks. If you want the length excluding trailing blanks, then use len_trim.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.