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

access violation for a non-positive array

anishtain4
Beginner
344 Views
[bash]SUBROUTINE GRID_GEN(GRID,L,H)
  USE VARIABLES
  TYPE(ND),INTENT(INOUT)      ::GRID(-IM/2:IM/2-1,-JM/2:JM/2-1)
  REAL          ::L,H,DX,DY
  INTEGER       ::I,J
  
  DX  = L/IM
  DY  = H/JM
  DO I=-IM/2,IM/2-1
    DO J=-JM/2,JM/2-1
      GRID(I,J).X  = I*DX
      GRID(I,J).Y  = J*DY
      GRID(I,J).K1 = I*2*Pi/L
      GRID(I,J).K2 = J*2*Pi/H
      GRID(I,J).KK =(GRID(I,J).K1**2+GRID(I,J).K2**2)
      IF (I==IM/2+1.AND.J==JM/2+1) GRID(I,J).KK=1
    END DO
  END DO
  RETURN
END SUBROUTINE[/bash]
This subroutine was working fine while the dimensions of grid was defined like: GRID(:,:) but I want to change the indexes for all the program like this to be easier with fourier series, when I run this program it hits a access violation and stops running once it get to the loop. When I checked it in debug the value has been assigned but program stops proceeding. IM and JM are defined as public variables in the VARIABLES module.

When I define another varibale like:
TYPE(ND)::G(-im/2:im/2-1,-jm/2:jm/2-1),GRID(:,:)
and replace it with GRID on entire subroutine it works, and finally I replace them by GRID=G.
Am I doing something against the standards here? in the main program dimensions of GRID has negative values too!
0 Kudos
4 Replies
mecej4
Honored Contributor III
344 Views
Am I doing something against the standards here?

Indeed, you are. See Section 12.3.1.1 Explicit interface in the Fortran 2003 Standard. Assumed shape array arguments need an explicit interface. If you give the compiler a proper interface but then change the function without changing the interface, the compiler is unable to produce correct code.

In effect, you gave false information to the compiler, even if inadvertently.
0 Kudos
anishtain4
Beginner
344 Views
yesssss, that`s it, I corrected the interface and it`s done. Working with the compact has spoiled me, can I ask you to introduce me a good guide to learn the fortran 2003 by a deep understanding? I already have a basic knowledge of it but I need to learn more about the memory access and compiling options.

Thanks greately
0 Kudos
mecej4
Honored Contributor III
344 Views
A concise guide is the book by Metcalf, Reid and Cohen, Fortran 95/2003 Explained, OUP, 2005. There is a link to a draft version of the Fortran 2003 standard at the top of this forum, which is more useful as a reference than a guide. Then, there are the Intel compiler documents, as well.
0 Kudos
anishtain4
Beginner
344 Views
Thanks, I got the book of Metcalf, of course explained one not simplified, but for the standard I'm having some problem with the j3-fortran.org, connection times out and it cannot be downloaded,
thanks anyway
0 Kudos
Reply