JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for COMP-FORTRAN-90 Archives


COMP-FORTRAN-90 Archives

COMP-FORTRAN-90 Archives


COMP-FORTRAN-90@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

COMP-FORTRAN-90 Home

COMP-FORTRAN-90 Home

COMP-FORTRAN-90  September 2016

COMP-FORTRAN-90 September 2016

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: Pointer remapping: can not the Fortran 2003 facility of remapping to a rank-one array be extended to CHARACTER variables?

From:

Bill Long <[log in to unmask]>

Reply-To:

Fortran 90 List <[log in to unmask]>

Date:

Sun, 25 Sep 2016 16:46:57 +0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (168 lines)

On Sep 24, 2016, at 8:48 AM, Vipul Parekh <[log in to unmask]> wrote:

> A correction - in the beginning section of this note, I meant to write:
> 
> Is it then possible to introduce an added facility for coders involving CHARACTER variables and CHARACTER arrays in pointer assignment as following: 
> 
>   character(kind=CK,len=n*ell), target :: s                 ! n, ell are constants
>   character(kind=CK,len=ell), pointer :: t(1:n) => s      ! not allowed currently, but can it be?
> 
> That is, the type and kind of character data on both sides of the assignment are the same, only the rank is different.

More importantly, the length type parameters are different.   This is want causes this to be not allowed.

Cheer,
Bill

> 
> Apologies for any confusion,
> Vipul
> 
> On Sat, Sep 24, 2016 at 9:43 AM, Vipul Parekh <[log in to unmask]> wrote:
> Starting with Fortran 2003, the remapping of the elements of a rank-one array is permitted in pointer assignment.  Hence one can do: 
>   .. 
>   integer, target  :: a(m*m)  ! say m is a constant 
>   integer, pointer :: p(:,:) 
>   .. 
>   p(1:m,1:m) => a(1:m*m) 
> 
> Is it then possible to introduce an added facility for coders involving CHARACTER variables and CHARACTER arrays in pointer assignment as following: 
> 
>   character(kind=CK,len=n*ell), target :: s     ! n, ell are constants
>   character(len=ell), pointer :: t(1:n) => s       ! not allowed currently, but can it be?
> 
> In my simple-minded thinking, I tend to view both of above as just involving association with length-type of information of the objects on either side of the assignment.  But one is allowed by the standard while the other is not.  What is it about character type in Fortran that might make the above remapping not possible?
> 
> Because one combine the facility of argument association with pointer assignment to mimic the above, so why can't then the language offer an abstraction which does such an action 'behind the scenes' and thus offers a compact option for the coder? 
> 
> -- begin code -- 
> module m 
> 
>    use, intrinsic :: iso_fortran_env, only : character_kinds 
>    use, intrinsic :: iso_c_binding, only : c_loc, c_intptr_t 
> 
>    implicit none 
> 
>    integer, parameter :: CK = character_kinds(2) 
>    integer, parameter :: n = 3 
>    integer, parameter :: ell = 4 
> 
>    character(kind=CK, len=n*ell), target :: s 
>    character(kind=CK, len=ell), pointer  :: t(:) => null() 
> 
>    private :: set 
> 
> contains 
> 
>    subroutine set_t() 
> 
>       call set(s,t) 
> 
>    end subroutine set_t 
> 
>    subroutine set(string, pstring) 
> 
>       character(kind=CK,len=ell), intent(in), target   :: string(n) 
>       character(kind=CK,len=ell), intent(out), pointer :: pstring(:) 
> 
>       pstring(1:n) => string(1:n) 
> 
>    end subroutine set 
> 
>    subroutine output_addresses( x, s1, s2 ) 
> 
>       integer, intent(in)                           :: x 
>       character(kind=CK, len=*), intent(in), target :: s1 
>       character(kind=CK, len=*), intent(in), target :: s2 
> 
>       integer(c_intptr_t) :: add_1 
>       integer(c_intptr_t) :: add_2 
> 
>       add_1 = transfer( c_loc(s1), mold=add_1) 
>       add_2 = transfer( c_loc(s2), mold=add_2) 
>       print "(1x,i0,3x,z0,24x,z0)", x, add_1, add_2 
> 
>       return 
> 
>    end subroutine output_addresses 
> 
> end module m 
> program p 
> 
>    use m, only : s, t, output_addresses, n, ell, set_t 
> 
>    implicit none 
> 
>    integer :: i 
>    integer :: j 
>    integer :: k 
> 
>    call set_t() 
> 
>    do i = 1, n*ell 
>       s(i:i) = achar(96+i, kind=kind(S)) 
>    end do 
> 
>    print *, "Values" 
>    print *, "i   j   k   s(k:k)   t(i)(j:j)" 
>    do i = 1, n 
>       do j = 1, ell 
>          k = (i-1)*ell + j 
>          print "(1x,i0,3x,i0,3x,i0,3x,g0,7x,g0)", i, j, k, s(k:k), t(i)(j:j) 
>       end do 
>    end do 
> 
>    print *, "Addresses in memory" 
>    print *, "i   s((i-1)*ell+1:(i-1)*ell+1)    t(i)" 
>    do i = 1, n 
>       call output_addresses( i, s((i-1)*ell+1:(i-1)*ell+1), t(i) ) 
>    end do 
> 
>    stop 
> 
> end program p 
> -- end code -- 
> 
> Upon execution with gfortran which supports a second character kind, 
> 
> -- begin output -- 
>  Values 
>  i   j   k   s(k:k)   t(i)(j:j) 
>  1   1   1   a       a 
>  1   2   2   b       b 
>  1   3   3   c       c 
>  1   4   4   d       d 
>  2   1   5   e       e 
>  2   2   6   f       f 
>  2   3   7   g       g 
>  2   4   8   h       h 
>  3   1   9   i       i 
>  3   2   10   j       j 
>  3   3   11   k       k 
>  3   4   12   l       l 
>  Addresses in memory ** 
>  i   s((i-1)*ell+1:(i-1)*ell+1)    t(i) 
>  1   448020                        448020 
>  2   448030                        448030 
>  3   448040                        448040 
> 
> -- end output -- 
> 
> ** the use of c_loc is questionable but I figure it's handy here. 
> 
> So to summarize, are there rules or constraints or some flexilibility offered to implementations involving non-default and non-c_char character kinds that make the following compact representation not possible?
> 
>    character(kind=CK, len=n*ell), target :: s 
>    character(kind=CK, len=ell), pointer  :: t(1:n) => s 
> 
> The language has type, kind, and rank (TKR) restrictions on pointer remapping and I would expect any potential enhancement to character variables and arrays will retain the same.  So I would expect whatever an implementation might be doing for a non-default character kind would be immaterial, especially when the remapping that is permitted is to a rank-one array as is the case currently in the standard.  John Reid writes in "The New Features of Fortran 2003", "The limitation to rank-one arrays is because pointer arrays need not occupy contiguous storage: .. but all the gaps have the same length in the rank-one case." 
> 
> Thanks much in advance,
> Vipul Parekh
> 

Bill Long                                                                       [log in to unmask]
Fortran Technical Support  &                                  voice:  651-605-9024
Bioinformatics Software Development                     fax:  651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

December 2023
February 2023
November 2022
September 2022
February 2022
January 2022
June 2021
November 2020
September 2020
June 2020
May 2020
April 2020
December 2019
October 2019
September 2019
March 2019
February 2019
January 2019
November 2018
October 2018
September 2018
August 2018
July 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
December 2015
November 2015
October 2015
September 2015
August 2015
June 2015
April 2015
March 2015
January 2015
December 2014
November 2014
October 2014
August 2014
July 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
July 2013
June 2013
May 2013
April 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
August 2010
July 2010
June 2010
March 2010
February 2010
January 2010
December 2009
October 2009
August 2009
July 2009
June 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998
1997


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager