Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with array 2

Status
Not open for further replies.

manoslev

Technical User
Dec 7, 2004
12
GR
Hi,

I have a strange problem.
I am trying to write some values in an array that is
located in a subroutine in a different file from the file tha t contains the main program.When the program tries to access the array I am getting an access violation error.If I move the subroutine in the same file with the main program I have no problem but I really need to run it separatelly.
Any ideas will be helpful
 
Could it be the size of the array or the element type of the array? Check if this works on your compiler

Prog 1
Code:
program main
   integer, parameter:: jammax = 10
   integer, dimension(jammax):: jam
   integer:: jj

   call fill (jam, jammax)
   print *, (jam(jj), jj = 1, jammax)
   stop
end
Prog 2
Code:
subroutine fill (kelp, kelpmax)
   integer, dimension (:), intent(inout):: kelp
   integer, intent(in):: kelpmax
   integer:: kk
   do kk = 1, kelpmax
      kelp(kk) = kk * 2
   end do
   return
end subroutine
If that doesn't work, then there may be a problem with your linking. If it works, then the problem is with your program, in which case could you post how you are calling the external routine and how the subroutine is declared, including all the parameters.

 
Hey,
Thanks for your answer.
I tried your code and it gives me the same ''access violation'' error as my program.It seems is a compiler error after all. Is there any way I can fix it ?
 
Hello manoslev

Why do you "really need to run it separatelly"???
Why not fix this problem by include the subroutine in the main program file, if that works fine. I also think that the "access violation" error has something to do with the programming, rather than it is a compiler error. Is the array defined in the subroutine call or do you use an equivalence-statement?. You are not "reading/writing" from the array elements past the array end, is it??

Good luck
gullipe
 
Hello gullipe,

I need to run it separatelly because the subroutine I need calls other subroutines from the same file. Is a bit complicated program and I don't want to mess it up. The array is defined in the subroutine call and the access violation error comes when I try to read or write from the first element of the array.
 
1) Which compiler/os are you using
2) What does your compile line look like
3) What does your link line look like
 
Hello again
In my previous reply I wrote accidentally "equivalence-statement" but I meant "common-statement" of course! But anyway, as the array is defined in the subroutine call (but not through a "common"-statement), this is a strange error. Apart from the three questions by "xwb", please also show:

1) How the array is defined in the main program
2) How the array is defined in the subroutine
3) The CALL statement to the subroutine
4) The SUBROUTINE statement in the subroutine


 
Hello again,

I run Fortran 90 through Microsoft Developer Studio 97 and my OS is Windows XP Professional.
Now for the question of gullipe

1) COMMON/FFT/ fc(50000)
2) dimension f(nref)
3) call SFP (BUF,LBUF,nx,ny,nz,scr,IC,ihh,ikk,ill,fc)
4) SUBROUTINE SFP (x,lbuf,nx,ny,nz,scale,nref,ih,ik,il,f)

the nref argument which shows in 2) is about 5000
I don't know if there is a problem with BUF and LBUF. BUF is an array which has a dimension of LBUF. But I have assigned a constant value to LBUF in the main program with the command : PARAMETER LBUF=40000
 
Ok guys,

The problem is solved !!!
I figured it out as I was writing the previous post.
The problem was that the main program had the same name as the COMMON statement FFT.
I guess that's why it couldn't access the array.Changing the name of the program made the program to run with no errors.
Strange the compiler hadn't warn me for that.
Anyway the conversation with both of you was very helpful !
Thank you very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top