Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28383 Discussions

[allocate] Dynamic array indices

bucaioni__thomas
New Contributor I
1,031 Views

Is there any caveat in using custom indices for allocatables? For example

 

real, dimension (:,:), allocatable :: T
allocate ( T(0:2,5:7) )
T = 0
T(0,5) = 1
T(2,7) = 9
print *, T

 

works great, but it would be to be sure there is no side effects

 

0 Kudos
5 Replies
bucaioni__thomas
New Contributor I
1,002 Views

When I posted the first thread, an error occurred and I clicked the submit button two other times... Maybe you can delete two of the three posts

0 Kudos
JohnNichols
Valued Contributor III
979 Views

In 1957. Backus stood on the top of the highest mountain, God spoke to Backus, I give thee Fortran and all its quirks.  Backus set off down the mountain to IBM HQ to report on his success, about half way down the mountain, the bag got heavy, so he looked at God's code and decided we do not need that part about Implicit None, he wandered on and the bag was heavier, so he looked again and thought - no one will ever need that part about dynamic arrays, so he tossed away more. 

Finally he reached the holy place called the Watson Lab and held out the code,  in 54 pages. 

The leader looked at Backus and said - what is a PDF file? 

!****************************************************************************
!
!  PROGRAM: Console15
!
!  PURPOSE:  Entry point for the console application.
!
!****************************************************************************

    program Console15

    implicit none

    ! Variables

    ! Body of Console15
    integer A(10), BigA, N,I
    
    A(1) = 100
    A(2) = 20
    A(3) = 35
    A(4) = 400
    A(5) = 200
    A(6) = 100
    A(7) = 2
    A(8) = -1
    A(9) = 13
    A(10) = 20
    N = 10
    write(*,*)"The earliest known Fortran Program - 1956"
    
    BigA = A(1) 
    DO 20 I = 1, N
    if(BigA - A(i)) 10,20,20 
10   BigA = A(i)
20  Continue

    write(*,*)bigA
    

    end program Console15

 

The program is on Page 7 of the first manual - I merely declared the numbers.  It runs on the latest compiler without change. 

In anthropology they call these creation myths. 

JohnNichols
Valued Contributor III
976 Views

We will never know if the programmer in 1956 had a sense of humour in naming the variable BigA - I like to think she did. 

JohnNichols
Valued Contributor III
971 Views

The debugger was five sense lights - command

SENSE LIGHT 1  

Does not work in modern Fortran 

Reply