Silverfrost Forums

Welcome to our forums

Fortran 2003 and 2008 features

23 Feb 2022 7:30 #28810

Simon

I don't know off hand but I will add it to the list for investigation.

28 Feb 2022 4:38 #28811

At first sight, implementing SOURCE= may not be very difficult but 'allocate on assignment' is already provided. It is similar and more direct.

program main
 integer a(10)
 integer,allocatable::b(:)
 a = 7
 b = a
 print*,b 
end program main
1 Mar 2022 3:50 #28812

Many thanks Paul. The allocate on assignment will work for most instances I need.

1 Jun 2022 2:05 #29005

I noticed a couple of character-handling features at fortranwiki.org that do not work in FTN95. Would it be possible to get these implemented?

Example 1: initialization of elements of a character array without having to provide padding to make all the elements the same length. This code generates a compile-time error.

Program p
   Character(Len=8), Dimension(4) :: c = &
      [Character(Len=8) :: 'A', 'AB', 'ABC', 'ABCD']
End Program p

Example 2: Allocatable characters. This code does not print the correct value. (There is a similar post from StamK on 12 Oct 2016 in the 64-bit forum, and a response from Paul indicating that allocatable characters have been implemented. Perhaps this example does not work because it is using 'allocate on assignment'?)

Program p
   Character(Len=:), Allocatable :: c
   c = 'A'
   Print*, c
End Program p

Note that if c is declared with the Save attribute, a compilation error is returned. For example:

Module p
Contains
 Subroutine s
   Character(Len=:), Allocatable, Save :: c
   c = 'A'
   Print*, c
 End Subroutine s
End Module p

[/code]

2 Jun 2022 1:43 #29007

As to Fortranwiki, would be good to see FTN95 in this table https://fortranwiki.org/fortran/show/Fortran+2003+status

Though the major addition to FTN95 would be probably parallelization with MPI. And optimization on Polyhedron tests

2 Jun 2022 5:48 #29008

Simon

I will add Example 1 to the wish list and Example 2 demonstrates an omission that needs fixing.

2 Jun 2022 10:53 #29009

Dan

Thanks for the feedback. We will explore the possibility of adding to the wiki.

11 Jun 2022 2:32 #29038

Sorry to add more to the wish-list - it would be nice to get the 2008 intrinsic functions FindLoc, MaxLoc and MinLoc added.

13 Jun 2022 6:20 #29044

Simon

MAXLOC and MINLOC are in the Fortran 90/95 standard (unless you need the extra KIND or BACK arguments) so they are already provided.

I could add FINDLOC to the wish list but it will be of limited use for real arrays where a test for equality usually needs a tollerance value.

14 Jun 2022 3:20 #29046

Thanks Paul - I was only interested in FindLoc for integer arrays. I'd forgotten that MaxLoc and MinLoc were already available - sorry, but that's at least something less for you to do!

15 Jun 2022 6:15 #29048

Simon

For a quick work-around you could use MINLOC. For example, for a 1D array

integer a(10),b(1),val
...
b = MINLOC(a, abs(a-val) == 0)

At first sight it looks like FINDLOC could be defined in terms of MINLOC but with the extra mask abs(a-val) == 0.

16 Jun 2022 8:11 #29058

Hi Paul, That's a nice work around for now. But I'm curious as to why the following code does not allow line 8 (the second instance of MinLoc), but does allow line 7 (the first instance).

Program p
   Integer, Parameter :: n1 = 5
   Integer, Dimension(n1) :: ia1 = [2,4,3,5,1]
   Integer, Dimension(n1) :: ia2
   Integer :: i = 5
   Integer :: j
   j      = MinLoc(ia1(:), (Abs(ia1(:)-i) == 0))
   ia2(1) = MinLoc(ia1(:), (Abs(ia1(:)-i) == 0))
End Program p
17 Jun 2022 6:03 #29059

Simon

The Standard defines the result as being a vector (in this context) so the compiler should complain when you assign a vector to a scalar.

Note also that, in general, (:) is not helpful because FTN95 does not always distinguish this from an array section which generates in a temporary copy.

21 Jun 2022 3:27 #29073

Hi Paul, Since j is a scalar, should not the compiler complain at line 7? Simon

21 Jun 2022 4:51 #29075

Simon

Yes. I may need to take a closer look at this.

Is it important? Can you get it to work?

21 Jun 2022 4:58 #29076

Hi Paul, Not important. I have worked around this. In this case I'm simply working from the attitude that all bug reports may be potentially useful. Thanks, Simon

8 Jul 2022 7:39 #29151

FINDLOC has now been added to FTN95 and the associated DLLs but without the KIND and BACK arguments at the momnent.

8 Jul 2022 12:47 #29153

Excellent! Thank you. On another 2008 topic, are there any plans for submodules? Again not urgent from my side. I would simply use them to break up some large files, so their absence is not a big issue.

8 Jul 2022 2:29 #29154

Simon

The subject of SUBMODULEs has been raised recently elsewhere on this forum and I did briefly look at its definition.

A SUBMODULE is not a simple extension of the concept of a MODULE. Also a MODULE is already extremely complex from point of view of the compiler. You can have modules within modules and at each level components can be private to the module. Then there is the complexity of USE ONLY.

So my initial impression is that to add SUBMODULEs would involve a very large investment of time.

8 Jul 2022 8:47 #29155

Understood. I can certainly manage without submodules high on the priority list fo rnow.

Please login to reply.