Character

Suppouse I don’t know exactly the length of my CHARACTER variable, or that I want to use a different length in different subroutines of the same variable.
Is there any way to work around the fact that you have to define the length of a CHARACTER explicitely?

example: CHARACTER(len=10) dummy

is there a way for me to omit the “len=10” so that my “dummy” variable could be long 10 characters, or 8 characters or 12 characters in the same subroutine or in different subroutines of the same program?

thank you

Hi jx8,


You could use an assumed-size character array as the dummy argument.

Example:

     program test

       call stringlen('String1')
       call stringlen('A longer string')
       call stringlen('A even longer string')
  
     end program test

     subroutine stringlen (str) 
      
       character (*) :: str

       WRITE(*,*), '\'', str, '\' is length ', LEN(str)
       
     end subroutine stringlen

Hope this helps,
Mat