soccer jersey forums.silverfrost.com :: View topic - Lbound with derived-type arrays
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Lbound with derived-type arrays

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
simon



Joined: 05 Jul 2006
Posts: 270

PostPosted: Tue Jan 31, 2023 11:32 pm    Post subject: Lbound with derived-type arrays Reply with quote

I would have expected the following program to print 0 and 2, but FTN95 and at least two other compilers return 1 and 3. The program is trying to print the lower bound of an array within a derived type, when the lower bound is explicitly defined as 0. Please advise how my understanding is incorrect.

Code:
Module m
   Type t
      Integer, Dimension(0:2) :: i
   End Type t
   Type(t), Dimension(3) :: at
End Module m
!
Program p
   Use m
   Print*, lbound(at(1)%i(:)), ubound(at(1)%i(:))
End Program p
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1897

PostPosted: Tue Jan 31, 2023 11:40 pm    Post subject: Reply with quote

You may find the answer if you replace (0:2) by (-2:0) in the definition of t%i and see how that changes the results.

Changing the Print statement to
Code:
Print*, lbound(at(1)%i), ubound(at(1)%i)

and seeing the effect on the output may throw more light on the issue.
Back to top
View user's profile Send private message
simon



Joined: 05 Jul 2006
Posts: 270

PostPosted: Wed Feb 01, 2023 5:00 am    Post subject: Reply with quote

Thanks for the response. Indeed, the same output. The lower bound becomes 1 regardless of the definition. So effectively, you cannot use different bounds in a derived-type array?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8037
Location: Salford, UK

PostPosted: Wed Feb 01, 2023 7:45 am    Post subject: Reply with quote

Use the whole array...

Code:
   Print*, lbound(at(1)%i), ubound(at(1)%i)
Back to top
View user's profile Send private message AIM Address
simon



Joined: 05 Jul 2006
Posts: 270

PostPosted: Wed Feb 01, 2023 3:04 pm    Post subject: Reply with quote

Hmm, that is curious. What actually is the difference between at(1)%i and at(1)%(:), or, for that matter, between, say, iarray and iarray(:)?

Last edited by simon on Mon Feb 06, 2023 4:04 am; edited 1 time in total
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8037
Location: Salford, UK

PostPosted: Wed Feb 01, 2023 3:59 pm    Post subject: Reply with quote

The colon usually denotes an array section, a sub-array which is a copy of part of the whole. Presumably the copy can be of the whole but is a different object with, in this context, different properties.
Back to top
View user's profile Send private message AIM Address
simon



Joined: 05 Jul 2006
Posts: 270

PostPosted: Mon Feb 06, 2023 3:53 am    Post subject: Reply with quote

I think I get that. But what about the following? Surely this code should return 2 rather than 3. And it returns 3 even if you delete (:) in the Print statement

Code:
Module m
   Type t1
      Integer, Dimension(3) :: i
   End Type t1
   Type t2
      Type(t1) :: t
   End Type t2
   Type(t2), Dimension(2) :: at2
End Module m
!
Program p
   Use m
   Print*, Size(at2(:)%t%i(1))
End Program p
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8037
Location: Salford, UK

PostPosted: Mon Feb 06, 2023 9:15 am    Post subject: Reply with quote

Simon

It looks like FTN95 is giving an incorrect result in this context. I will log this for investigation.
Back to top
View user's profile Send private message AIM Address
simon



Joined: 05 Jul 2006
Posts: 270

PostPosted: Tue Nov 07, 2023 11:19 pm    Post subject: Reply with quote

Hi Paul,
Any progress on this one? I have work-arounds, but I have quite a few instances that I think are equivalent, where I am passing an array of a derived type, and the routine does not get what I would expect. For example,
Code:
Call s ( at2(:)%t%i(1) )
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8037
Location: Salford, UK

PostPosted: Wed Nov 08, 2023 9:02 am    Post subject: Reply with quote

Simon

This failure has not yet been fixed. An initial investigation located the point of failure but not the fix.

At first sight it's not obvious to me what you are asking for in the call to s(at2(:)%t%i(1)), which is some kind of "copy-in" of components extracted from the data structure.

Sometimes it is better to simplify the logic of the coding.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8037
Location: Salford, UK

PostPosted: Wed Nov 08, 2023 3:09 pm    Post subject: Reply with quote

Simon

If Call s(at2(:)%t%i(1)) does not do what you expect then can you provide sample code that illustrates what you get and what you expect.

It could easily be a different issue.
Back to top
View user's profile Send private message AIM Address
simon



Joined: 05 Jul 2006
Posts: 270

PostPosted: Wed Nov 08, 2023 7:40 pm    Post subject: Reply with quote

Hi Paul,
The following example does not quite reproduce the error I have in mind, but it is outputting a surplus value (which is presumably because the size of ia in subroutine s is still in error):

Code:
Module m
   Type t1
      Integer, Dimension(3) :: i
   End Type t1
   Type t2
      Type(t1) :: t
   End Type t2
   Type(t2), Dimension(2) :: at2
 Contains
  Subroutine s (ia)
   Integer, Dimension(:), Intent(In) :: ia
   Print *, ia
  End Subroutine s
End Module m
!
Program p
   Use m
   at2(1)%t%i(:) = [ 11, 12, 13 ]
   at2(2)%t%i(:) = [ 21, 22, 23 ]
   Call s ( at2(:)%t%i(2) )
End Program p
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8037
Location: Salford, UK

PostPosted: Thu Nov 09, 2023 8:33 am    Post subject: Reply with quote

Simon

Thanks. I have logged this for investigation.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8037
Location: Salford, UK

PostPosted: Thu Nov 23, 2023 3:40 pm    Post subject: Reply with quote

This failure has now been fixed for the next release of FTN95.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group