View previous topic :: View next topic |
Author |
Message |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Thu Aug 12, 2021 10:26 am Post subject: |
|
|
FLOOR and CEILING have now been added for the next release of FTN95. |
|
Back to top |
|
|
simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Wed Feb 23, 2022 4:22 am Post subject: |
|
|
Hi Paul,
Would it be difficult to add SOURCE= as an optional argument to ALLOCATE? I believe it is a 2003 standard. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Wed Feb 23, 2022 8:30 am Post subject: |
|
|
Simon
I don't know off hand but I will add it to the list for investigation. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Mon Feb 28, 2022 5:38 pm Post subject: |
|
|
At first sight, implementing SOURCE= may not be very difficult but "allocate on assignment" is already provided. It is similar and more direct.
Code: | program main
integer a(10)
integer,allocatable::b(:)
a = 7
b = a
print*,b
end program main |
|
|
Back to top |
|
|
simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Tue Mar 01, 2022 4:50 am Post subject: |
|
|
Many thanks Paul. The allocate on assignment will work for most instances I need. |
|
Back to top |
|
|
simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Wed Jun 01, 2022 3:05 am Post subject: |
|
|
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.
Code: |
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"?)
Code: |
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:
Code: | Module p
Contains
Subroutine s
Character(Len=:), Allocatable, Save :: c
c = 'A'
Print*, c
End Subroutine s
End Module p
| [/code] |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2834 Location: South Pole, Antarctica
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Thu Jun 02, 2022 6:48 am Post subject: |
|
|
Simon
I will add Example 1 to the wish list and Example 2 demonstrates an omission that needs fixing. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Thu Jun 02, 2022 11:53 am Post subject: |
|
|
Dan
Thanks for the feedback. We will explore the possibility of adding to the wiki. |
|
Back to top |
|
|
simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Sat Jun 11, 2022 3:32 pm Post subject: |
|
|
Sorry to add more to the wish-list - it would be nice to get the 2008 intrinsic functions FindLoc, MaxLoc and MinLoc added. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Mon Jun 13, 2022 7:20 am Post subject: |
|
|
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. |
|
Back to top |
|
|
simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Tue Jun 14, 2022 4:20 pm Post subject: |
|
|
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! |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Wed Jun 15, 2022 7:15 am Post subject: |
|
|
Simon
For a quick work-around you could use MINLOC. For example, for a 1D array
Code: | 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. |
|
Back to top |
|
|
simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Thu Jun 16, 2022 9:11 pm Post subject: |
|
|
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).
Code: | 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
|
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7938 Location: Salford, UK
|
Posted: Fri Jun 17, 2022 7:03 am Post subject: |
|
|
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. |
|
Back to top |
|
|
|