From: James Van Buskirk on
"Gordon Sande" <g.sande(a)worldnet.att.net> wrote in message
news:2010012609284916807-gsande(a)worldnetattnet...

> Nice does not include the use of transfer

Sigh.

C:\gfortran\clf\conv_char>type conv_char.f90
module convert
implicit none
interface conv_char
module procedure string2array
module procedure array2string
end interface conv_char
contains
pure function string2array(string)
character(*), intent(in) :: string
character string2array(len(string))

string2array = s2a(string,len(string))
end function string2array
pure function s2a(array,n)
integer, intent(in) :: n
character, intent(in) :: array(n)
character s2a(n)

s2a = array
end function s2a
pure function array2string(array)
character, intent(in) :: array(:)
character(size(array)) :: array2string

array2string = a2s(array,size(array))
end function array2string
pure function a2s(string,n)
integer, intent(in) :: n
character(n), intent(in) :: string(1)
character(n) a2s

a2s = string(1)
end function a2s
end module convert

program test
use convert
implicit none

write(*,'(a,i0)') 'LEN(''ABCDEFG'') = ', LEN('ABCDEFG')
write(*,'(a,i0)') 'LEN(conv_char(''ABCDEFG'')) = ', &
LEN(conv_char('ABCDEFG'))
write(*,'(a,i0)') 'SIZE(conv_char(''ABCDEFG'')) = ', &
SIZE(conv_char('ABCDEFG'))
write(*,'(a)') 'conv_char(''ABCDEGF'') = ', conv_char('ABCDEFG')

write(*,'()')
write(*,'(a,i0)') 'LEN([''A'',''B'',''C'',''D'',''E'',''F'',''G'']) = ',
&
LEN(['A','B','C','D','E','F','G'])
write(*,'(a,i0)') 'SIZE([''A'',''B'',''C'',''D'',''E'',''F'',''G'']) = ',
&
SIZE(['A','B','C','D','E','F','G'])
write(*,'(a,i0)') 'LEN(conv_char( &
&[''A'',''B'',''C'',''D'',''E'',''F'',''G''])) = ', &
LEN(conv_char(['A','B','C','D','E','F','G']))
write(*,'(a)') 'conv_char( &
&[''A'',''B'',''C'',''D'',''E'',''F'',''G'']) = ', &
conv_char(['A','B','C','D','E','F','G'])
end program test

C:\gfortran\clf\conv_char>gfortran -std=f2003 conv_char.f90 -oconv_char

C:\gfortran\clf\conv_char>conv_char
LEN('ABCDEFG') = 7
LEN(conv_char('ABCDEFG')) = 1
SIZE(conv_char('ABCDEFG')) = 7
conv_char('ABCDEGF') =
A
B
C
D
E
F
G

LEN(['A','B','C','D','E','F','G']) = 1
SIZE(['A','B','C','D','E','F','G']) = 7
LEN(conv_char( ['A','B','C','D','E','F','G'])) = 7
conv_char( ['A','B','C','D','E','F','G']) =
ABCDEFG

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


From: Gordon Sande on
On 2010-01-26 11:32:52 -0400, "e p chandler" <epc8(a)juno.com> said:

>
> "Gordon Sande" <g.sande(a)worldnet.att.net> wrote in message
> news:2010012609284916807-gsande(a)worldnetattnet...
>> On 2010-01-25 22:34:59 -0400, "e p chandler" <epc8(a)juno.com> said:
>>
>>>
>>> "Fortran_follower" <ezeepraveen4u(a)gmail.com> wrote in message
>>> news:dd63bcc5-aa09-411d-a44c-ff4815e2e10b(a)v25g2000yqk.googlegroups.com...
Dear

Richard
>>>
>>>> Maine,
>>>>
>>>> Thank you for your detailed reply to my query.
>>>> Please have a look at my declaration below:
>>>> character,allocatable,dimension(:,:) :: fname
>>>> character*100 :: outfile,infile,outfname
>>>> character*150 :: infpath,outfpath,line
>>>> integer :: num,i,j,col
>>>> c
>>>> col=50
>>>> i=1
>>>> j=1
>>>> c
>>>> write(*,*)'Enter no.of files to merge'
>>>> read(*,*)num
>>>> allocate(fname(num,col))
>>>> c
>>>>
>>>>> outfname = [fname(1,1:7), fname(num,1:6)]
>>>>
>>>> For the solution you have mentioned, I am getting the following error.
>>>> outfname = [fname(1,1:7), fname(num,1:6)]
>>>> 1
>>>> Error: Incompatible ranks 0 and 1 in assignment at (1)
>>>>
>>>> Can you please let me know...whether the problem is with the
>>>> declaration or with something else...!!
>>>>
>>>> Thanking you.
>>>>
>>>> Praveen.
>>>
>>> outfname is a character variable (string). fname(1,1:7) is an array
>>> slice. It is NOT a string of characters.
>>>
>>> outfname='ABCDEFG' is not the same as outfname = ['A','B','C','D','E','F','G']
>>
>> Is there a nice idiom for doing the conversion?
>
> Not AFAIK. It would be "nice" from the point of view of letting the OP
> do what he thinks he wants to do to have strings be the same as 1-D
> character vectors, as they are in APL, or have an APL like catenate
> function. But then what does catenate mean for a numeric array?
>
> A <- 1 2 3 4 5
> I <- ,A
> I
> 12345
>
> ?????
>
>> On the few occasions I have had
>> to do this I ended up with a loop assigninng single characters. There
>> are special
>> rules on the use of character arrays as formats in i/o that do the
>> conversion for
>> you. Either that is a slick feature for that case or an indication of a missing
>> ability elsewhere.
>
> Yes. But that is deceptive. It's an artifact of the output being
> serialized. So printing A$ is the same as printing B[1:7].

Read the fine print on run time formats. An array of characters will be
concatenated
to construct the format. Rather special case that has nothing to do with the
actual output the format produces. I would guess it is a legacy
requirement from
something F77 did.

>> Nice does not include the use of transfer or changing all the commas above to
>> concatenate symbols. (I tend to rate transfer as "too clever for words" and to
>> be avoided.)
>
> Well JVB does write some "nice" write only code with it. [smile]

And I thought it was compiler testing code! ;-)


>

From: Gordon Sande on
On 2010-01-26 12:50:25 -0400, "James Van Buskirk" <not_valid(a)comcast.net> said:

> "Gordon Sande" <g.sande(a)worldnet.att.net> wrote in message
> news:2010012609284916807-gsande(a)worldnetattnet...
>
>> Nice does not include the use of transfer
>
> Sigh.
>
> C:\gfortran\clf\conv_char>type conv_char.f90
> module convert
> implicit none
> interface conv_char
> module procedure string2array
> module procedure array2string
> end interface conv_char
> contains
> pure function string2array(string)
> character(*), intent(in) :: string
> character string2array(len(string))
>
> string2array = s2a(string,len(string))
> end function string2array
> pure function s2a(array,n)
> integer, intent(in) :: n
> character, intent(in) :: array(n)
> character s2a(n)
>
> s2a = array
> end function s2a
> pure function array2string(array)
> character, intent(in) :: array(:)
> character(size(array)) :: array2string
>
> array2string = a2s(array,size(array))
> end function array2string
> pure function a2s(string,n)
> integer, intent(in) :: n
> character(n), intent(in) :: string(1)
> character(n) a2s
>
> a2s = string(1)
> end function a2s
> end module convert
>
> program test
> use convert
> implicit none
>
> write(*,'(a,i0)') 'LEN(''ABCDEFG'') = ', LEN('ABCDEFG')
> write(*,'(a,i0)') 'LEN(conv_char(''ABCDEFG'')) = ', &
> LEN(conv_char('ABCDEFG'))
> write(*,'(a,i0)') 'SIZE(conv_char(''ABCDEFG'')) = ', &
> SIZE(conv_char('ABCDEFG'))
> write(*,'(a)') 'conv_char(''ABCDEGF'') = ', conv_char('ABCDEFG')
>
> write(*,'()')
> write(*,'(a,i0)') 'LEN([''A'',''B'',''C'',''D'',''E'',''F'',''G'']) = ',
> &
> LEN(['A','B','C','D','E','F','G'])
> write(*,'(a,i0)') 'SIZE([''A'',''B'',''C'',''D'',''E'',''F'',''G'']) = ',
> &
> SIZE(['A','B','C','D','E','F','G'])
> write(*,'(a,i0)') 'LEN(conv_char( &
> &[''A'',''B'',''C'',''D'',''E'',''F'',''G''])) = ', &
> LEN(conv_char(['A','B','C','D','E','F','G']))
> write(*,'(a)') 'conv_char( &
> &[''A'',''B'',''C'',''D'',''E'',''F'',''G'']) = ', &
> conv_char(['A','B','C','D','E','F','G'])
> end program test
>
> C:\gfortran\clf\conv_char>gfortran -std=f2003 conv_char.f90 -oconv_char
>
> C:\gfortran\clf\conv_char>conv_char
> LEN('ABCDEFG') = 7
> LEN(conv_char('ABCDEFG')) = 1
> SIZE(conv_char('ABCDEFG')) = 7
> conv_char('ABCDEGF') =
> A
> B
> C
> D
> E
> F
> G
>
> LEN(['A','B','C','D','E','F','G']) = 1
> SIZE(['A','B','C','D','E','F','G']) = 7
> LEN(conv_char( ['A','B','C','D','E','F','G'])) = 7
> conv_char( ['A','B','C','D','E','F','G']) =
> ABCDEFG

I appreciate the notion but it suffers from the fault of most object oriented
code that a naive reader can not determine what is going on without reading
in exhaustive detail large amounts of the surrounding code.

The opinion that I have formed, and been told by many others, is that unless
the abstraction is well designed, heavily used, fixed and imposed by others
it will cause much more harm than it cures. The obvious example is a wondowing
package which works nicely as it follows the requirements stated. The
next usefull
example has still not been provided!



From: e p chandler on
On Jan 26, 12:46 pm, Gordon Sande <g.sa...(a)worldnet.att.net> wrote:

re: array of characters versus a string in I/O

> Read the fine print on run time formats. An array of characters will be
> concatenated
> to construct the format. Rather special case that has nothing to do with the
> actual output the format produces. I would guess it is a legacy
> requirement from
> something F77 did.

Aha! Now I understand that you were referring to the format specifier.
I was talking about the items in the I/O list and did not get your
point at all.

-- e
e-mail: epc8 at juno dot com
sig: I'm at the office so I'm stuck with Google here.