From: Jovan Cormac on
fj wrote:

>> This instruction is not legal : all the strings must have the same
>> length ! Your compiler has accepted it (extension) in padding the
>> shortest strings with spaces.
>
> Correction : not legal in FORTRAN-95

Ok, thank you. Any possiblilty of a workaround then?

--
-- jovan
From: James Van Buskirk on
"Jovan Cormac" <limulus(a)gmx.net> wrote in message
news:hudn9s$i9n$1(a)news.albasani.net...

> fj wrote:

>>> This instruction is not legal : all the strings must have the same
>>> length ! Your compiler has accepted it (extension) in padding the
>>> shortest strings with spaces.

>> Correction : not legal in FORTRAN-95

> Ok, thank you. Any possiblilty of a workaround then?

C:\gfortran\clf\char_array>type char_array.f90
module mymod
contains
SUBROUTINE routine1(strings)
IMPLICIT NONE

CHARACTER (LEN = *), INTENT(IN) :: strings(:)
INTEGER :: i

WRITE(*,*) (strings(i), i = 1, SIZE(strings))

RETURN
END SUBROUTINE routine1
end module mymod

program start
use mymod
implicit none
CALL routine1( (/character(len=6) :: 'Hello', ' ', 'World!' /) )
end

C:\gfortran\clf\char_array>gfortran -Wall char_array.f90 -ochar_array

C:\gfortran\clf\char_array>char_array
Hello World!

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


From: dpb on
Jovan Cormac wrote:
> fj wrote:
>
>>> This instruction is not legal : all the strings must have the same
>>> length ! Your compiler has accepted it (extension) in padding the
>>> shortest strings with spaces.
>>
>> Correction : not legal in FORTRAN-95
>
> Ok, thank you. Any possiblilty of a workaround then?

If the question is how to write legal (consistent w/ F95 Standard) array
constructor for CHARACTER data, sure...pad all strings in the
constructor to the same length.

Otherwise, do you mean to ask something different?

--


From: mecej4 on
James Van Buskirk wrote:

> "Jovan Cormac" <limulus(a)gmx.net> wrote in message
> news:hudn9s$i9n$1(a)news.albasani.net...
>
>> fj wrote:
>
>>>> This instruction is not legal : all the strings must have the same
>>>> length ! Your compiler has accepted it (extension) in padding the
>>>> shortest strings with spaces.
>
>>> Correction : not legal in FORTRAN-95
>
>> Ok, thank you. Any possiblilty of a workaround then?
>
> C:\gfortran\clf\char_array>type char_array.f90
> module mymod
> contains
> SUBROUTINE routine1(strings)
> IMPLICIT NONE
>
> CHARACTER (LEN = *), INTENT(IN) :: strings(:)
> INTEGER :: i
>
> WRITE(*,*) (strings(i), i = 1, SIZE(strings))
>
> RETURN
> END SUBROUTINE routine1
> end module mymod
>
> program start
> use mymod
> implicit none
> CALL routine1( (/character(len=6) :: 'Hello', ' ', 'World!' /) )
> end
>
> C:\gfortran\clf\char_array>gfortran -Wall char_array.f90 -ochar_array
>
> C:\gfortran\clf\char_array>char_array
> Hello World!
>
If I am not mistaken, this is not quite what the OP wanted: he wants each
item in the constructor to be printed without extra padding or truncation.

-- mecej4
From: Jovan Cormac on
dpb wrote:

> If the question is how to write legal (consistent w/ F95 Standard) array
> constructor for CHARACTER data, sure...pad all strings in the
> constructor to the same length.
>
> Otherwise, do you mean to ask something different?
>
> --
>
>


Well, truth be told the standard doesn't concern me much, since my code
compiles with the compiler we use (Intel).

What I meant is, is there a way to achieve what I originally described:
Passing several strings (variable number) of variable length and then
outputting them all WITHOUT them being either truncated (TRIM) or blown
up (padded), i.e.: Is there a way to emulate the behavior of WRITE in a
user-written function? After all,

WRITE(*,*) 'Hello', ' ', 'world'

will do just what I described (without any additional processing, of
course), so technically, it is certainly possible.


--
-- jovan
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7
Prev: many runs in one directory
Next: pressure and fortran