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 

Sum and MaxVal returning incorrect values

 
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: 268

PostPosted: Sun Aug 08, 2021 5:32 am    Post subject: Sum and MaxVal returning incorrect values Reply with quote

The following code defines a derived type, t2, in terms of another derived type, t1. If an array of type t2 is allocated and values assigned, the intrinsic functions Sum and MaxVal return incorrect values (and my guess is that MinVal and possibly some other functions will have similar problems).

Code:
Module m
   Type t1
      Integer :: n
      Real :: r
   End Type t1
   Type t2
      Type(t1) :: tt
   End Type t2
!
   Type(t2), Dimension(:), Allocatable :: at2
End Module m


Program p
   Use m, Only: at2
   Integer :: n = 5
   Integer :: i
!
   Allocate (at2(n))
   Do i = 1, n
      at2(i)%tt%r = 99.0
      at2(i)%tt%n = 2
   End Do
   Print*, at2(:)%tt%n
   Print*, MaxVal(at2(:)%tt%n)
   Print*, Sum(at2(:)%tt%n)
End Program p
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sun Aug 08, 2021 9:30 am    Post subject: Reply with quote

One of the truly wonderful things about being an old dog (i.e. unable to learn new tricks) is that one rarely gets caught out by such things!

I'm a firm believer that everything should work as it is supposed to, or there ought to be documentation to the effect that something doesn't work, so no doubt one of Paul's 'I have made a note of this' remarks means that it will soon be fixed. I hope so, as there's zero chance of it going into the help file!

Eddie
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Aug 09, 2021 9:51 am    Post subject: Reply with quote

Simon

Thank you for the feedback. This appears to be an orginal bug. I have logged it for investigation.
Back to top
View user's profile Send private message AIM Address
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Thu Aug 12, 2021 2:35 am    Post subject: Reply with quote

Perhaps I am suffering from too much lockdown (now predicted to go to November!!), but why use the following structure ?

at2(i)%tt%r = 99.0

I know it is possible in Fortran syntax, but doesn't the following approach achieve the same result ?

at2_tt(i)%r = 99.0

I do not appreciate the need for heiracthical derived types.
I do have extensive use of derived types for data structures to define problems, but then tend to use multi-dimension arrays and vectors for the compute intense phase. Then again, most FE calculations are simply F = K . X.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Thu Aug 12, 2021 12:10 pm    Post subject: Reply with quote

John, in Simon's example Type t2 contains only one member, namely, tt, which is what you probably see as rather pointless. On the other hand, the test code shown may have been obtained by paring down production code. For example, the production code could well have had the declaration

Code:
   Type t2
      Type(t1) :: tt
      Character(len=2) :: cc  ! 2-character country code
   End Type t2
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Thu Aug 12, 2021 12:53 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
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Thu Aug 12, 2021 1:05 pm    Post subject: Reply with quote

As always, Paul has responded quickly and completely to an error report, which is at least one of the reasons why FTN95 is so valued by its users. I'm always impressed by that, even if I will never use the facility.

E
Back to top
View user's profile Send private message
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Sat Aug 14, 2021 3:16 am    Post subject: Reply with quote

Yes, thanks very much Paul.
And mecej4 is correct - I have paired the code down to the minimum required to reproduce the error. There is no attempt to make the example look like a worthwhile use of derived types; the intent was only to make Paul's job as simple as possible. For what it's worth, the original code is something like the following, with Type(area) defining an area bounded by latitude and longitude limits, and Type(domain) containing additional information to define the size of the area and locate it in a larger field:

Code:
! - area -
   Public :: area
   Type area
      Sequence
      Real(Kind=rp) :: rltn ! - northern area limit -
      Real(Kind=rp) :: rlts ! - southern area limit -
      Real(Kind=rp) :: rlgw ! - western area limit -
      Real(Kind=rp) :: rlge ! - eastern area limit -
   End Type area
!
! - domain -
   Public :: domain
   Type domain
      Sequence
      Integer :: nlts    ! - number of latitudes in domain -
      Integer :: nlgs    ! - number of longitudes in domain -
      Integer :: ilt1    ! - northern latitude domain limit index -
      Integer :: ilt2    ! - southern latitude domain limit index -
      Integer :: ilg1    ! - western longitude domain limit index -
      Integer :: ilg2    ! - eastern longitude domain limit index -
      Type(area) :: alim ! - area limits -
   End Type domain
Back to top
View user's profile Send private message
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