- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i am trying to modify a very complex existing code. but I am getting this error. I am updating this to use dynamic memory allocation. I can not share the whole code. but I am attaching a dummy code made in the same way as the things are being done origianally. during building process, I am getting the error #6416.
Operating syste: Win 7 (enterprise edition)
Interface: Visual Studio 2010
Compiler: Intel(R) Visual Fortran Composer XE 2011 Update 8
Intel Form.zip contains the complete project.
Any help in this topic will be highly appreciated.
Thank you very much in advance.
Regards,
Vinod
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use fixed form too, the following uses .f90 format:
[fortran]
! RXN.F90
module RXN
INTEGER :: NCOMP
CHARACTER*30, ALLOCATABLE:: COMPID(:)
contains
integer function AllocateCOMPID(n)
integer :: n
ALLOCATE(COMPID(NCOMP), STAT = AllocateCOMPID
if(AllocateCOMPID .eq. 0) NCOMP = n
end function AllocateCOMPID
end module RXN
================================
! yourProgram.f90
PROGRAM MAIN
use RXN
INTEGER NCOMP,I, iError
OPEN (UNIT=5, FILE="input.txt")
READ (5,*) I
iError = AllocateCOMPID(I)
if(iError .ne. 0) STOP "Allocation Error"
READ (5,*) (COMPID(I),I=1,NCOMP)
CLOSE(5)
CALL DISPLAY()
END
SUBROUTINE DISPLAY()
use RXN
WRITE(*,*) (COMPID(I),I=1,NCOMP)
END SUBROUTINE
[/fortran]
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You cannot put an allocatable array in COMMON. The typical solution to this would be to make COMPID a module variable in a module that was USEd by all the procedures that needed to reference it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
jimdempseyatthecove wrote:
You can use fixed form too, the following uses .f90 format:
! RXN.F90 module RXN INTEGER :: NCOMP CHARACTER*30, ALLOCATABLE:: COMPID(:) contains integer function AllocateCOMPID(n) integer :: n ALLOCATE(COMPID(NCOMP), STAT = AllocateCOMPID if(AllocateCOMPID .eq. 0) NCOMP = n end function AllocateCOMPID end module RXN ================================ ! yourProgram.f90 PROGRAM MAIN use RXN INTEGER NCOMP,I, iError OPEN (UNIT=5, FILE="input.txt") READ (5,*) I iError = AllocateCOMPID(I) if(iError .ne. 0) STOP "Allocation Error" READ (5,*) (COMPID(I),I=1,NCOMP) CLOSE(5) CALL DISPLAY() END SUBROUTINE DISPLAY() use RXN WRITE(*,*) (COMPID(I),I=1,NCOMP) END SUBROUTINE
Jim Dempsey
Dear Jim,
Thank you very much for your input. I tried the code sent by you. I could build the application successfully. But, now I am getting a run-time error, which is not clear to me. It allocated 5 array elements to COMPID (i assume this as there is no error display during the execution) as per the input file. now after the allocation, it should read 5 elements from the next row of input file. But it gives the following error:
forrt1: sever(408): fort(2): subscript #1 of the array COMPID has value 1 which is greater than the upper bound of 0.
I tried to see COMPID (1) in watch window, and it says "Compid(1) - Subscript out of range".
This seems that the allocation was not successful. But I didnot get any error displayed on the screen. Could you please help me further, as I am new to this module thing.
Thank you very much in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
jimdempseyatthecove wrote:
You can use fixed form too, the following uses .f90 format:
! RXN.F90 module RXN INTEGER :: NCOMP CHARACTER*30, ALLOCATABLE:: COMPID(:) contains integer function AllocateCOMPID(n) integer :: n ALLOCATE(COMPID(NCOMP), STAT = AllocateCOMPID if(AllocateCOMPID .eq. 0) NCOMP = n end function AllocateCOMPID end module RXN ================================ ! yourProgram.f90 PROGRAM MAIN use RXN INTEGER NCOMP,I, iError OPEN (UNIT=5, FILE="input.txt") READ (5,*) I iError = AllocateCOMPID(I) if(iError .ne. 0) STOP "Allocation Error" READ (5,*) (COMPID(I),I=1,NCOMP) CLOSE(5) CALL DISPLAY() END SUBROUTINE DISPLAY() use RXN WRITE(*,*) (COMPID(I),I=1,NCOMP) END SUBROUTINE
Jim Dempsey
Dear Jim,
Thank you very much for your time and valuable comment. I tried this code and I could build successfully. But this time I am getting a runtime error. While reading second line from the input file, it says:
forrt1: severe(408): fort: (2): subscript #1 of the array COMPID has value 1 which is greater than the upper of 0.
I don't understand why the code is giving this error, as I did not get any allocation error.
Could you please help me out of this?
Thank you very much.
Regards,
Vinod
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve Lionel (Intel) wrote:
You cannot put an allocatable array in COMMON. The typical solution to this would be to make COMPID a module variable in a module that was USEd by all the procedures that needed to reference it.
Dear Steve,
Thank you for your input. I am trying this. Hopefully the problem will be resolved soon.
Regards,
Vinod
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Jim & Steve,
The problem has been resolved. Thank you very much for your help.
With best regards,
Vinod
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
jimdempseyatthecove wrote:
You can use fixed form too, the following uses .f90 format:
! RXN.F90 module RXN INTEGER :: NCOMP CHARACTER*30, ALLOCATABLE:: COMPID(:) contains integer function AllocateCOMPID(n) integer :: n ALLOCATE(COMPID(NCOMP), STAT = AllocateCOMPID if(AllocateCOMPID .eq. 0) NCOMP = n end function AllocateCOMPID end module RXN ================================ ! yourProgram.f90 PROGRAM MAIN use RXN INTEGER NCOMP,I, iError OPEN (UNIT=5, FILE="input.txt") READ (5,*) I iError = AllocateCOMPID(I) if(iError .ne. 0) STOP "Allocation Error" READ (5,*) (COMPID(I),I=1,NCOMP) CLOSE(5) CALL DISPLAY() END SUBROUTINE DISPLAY() use RXN WRITE(*,*) (COMPID(I),I=1,NCOMP) END SUBROUTINE
Jim Dempsey
Dear Jim & Steve,
Thank you very much for your inputs. The problem has been resolved.
Regards,
Vinod
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page