Home > Archive > Fortran > March 2004 > Re: Is there any standered function which converts a character array
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Is there any standered function which converts a character array
|
|
| Tom McGlynn 2004-03-27, 12:18 am |
| Noby wrote:
> Is there any standered function which converts a character array to a
> character string?
>
> (I use G77 compiler)
You might try an internal write.
E.g.,
character*3 array(10)/'abc',9*'def'/
character*30 glom
write(glom,'(999a)') array
print *,array
end
gives
abcdefdefdefdefdefdefdefdef
This write assumes that array is shorter 999 elements but allows
the elements of array to be any length. There may be restrictions
on the maximum repeat count in the format element.
Regards,
Tom McGlynn
| |
| meek@skyway.usask.ca 2004-03-27, 12:18 am |
| In a previous article, Tom McGlynn <tam@lheapop.gsfc.nasa.gov> wrote:
>Noby wrote:
>
>
>You might try an internal write.
>
>E.g.,
>
> character*3 array(10)/'abc',9*'def'/
> character*30 glom
> write(glom,'(999a)') array
> print *,array
> end
>
>gives
>
> abcdefdefdefdefdefdefdefdef
>
>This write assumes that array is shorter 999 elements but allows
>the elements of array to be any length. There may be restrictions
>on the maximum repeat count in the format element.
>
>
> Regards,
> Tom McGlynn
I usually use equivalence -if the problem is specific., e.g.
character*100 string
character*1 char1(100)
equivalence (char1(1),string)
or maybe you could write to substring
do i=1,n
write(string(i:i),'(a1)')char1(i)
enddo
(Caveat!: looks reasonable- but I haven't tried it - some
compilers may not like!),
Chris
|
|
|
|
|