swamy2667
09-19-2008, 06:05 AM
Dear Members,
It is given that Character*(*) is a character constant
followed by Parameter synyax.
But I have seen as below in a Subroutine
Can you please expalin this:
Character*(*) Chaine
What is the meaning?
Thanks in Advance
Regards
Dr.K.Thiruvenkatasamy
davekw7x
09-19-2008, 11:49 AM
Character*(*) Chaine
Used as the declaration of a dummy argument in a subprogram: a string whose length is passed implicitly (transparently).
Check out something like http://www.ibiblio.org/pub/languages/fortran/ch2-13.html
Example (compiled with GNU g77 and GNU gfortran):
!
! Example of a subprogram that can take an argument
! that is a string of arbitrary length
!
program teststrlen
integer strlen
character s1*10
character s2*20
integer lll
s1 = '1234'
lll = len(s1)
write(*,'("In main: len(s1) = ", I2)') lll
lll = strlen(s1)
write(*,'("In main: strlen(s1) = ", I2/)') lll
s2 = '11223344'
lll = len(s2)
write(*,'("In main: len(s2) = ", I2)') lll
lll = strlen(s2)
write(*,'("In main: strlen(s2) = ", I2)') lll
end program teststrlen
integer function strlen(st)
integer i
character st*(*)
i = len(st)
write(*,'(" In strlen: len(st) = ", I2)') i
do while (st(i:i) .eq. ' ')
i = i - 1
enddo
strlen = i
return
end
Output
In main: len(s1) = 10
In strlen: len(st) = 10
In main: strlen(s1) = 4
In main: len(s2) = 20
In strlen: len(st) = 20
In main: strlen(s2) = 8
Regards,
Dave