- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello everyone,
I'm having issues with this sample of code
subroutine tri_2D(vect) real(kind=DP), dimension(:,:),pointer :: vect integer :: n, n1, n2 real(kind=DP), dimension(:), allocatable :: STOCK1, STOCK2 real(kind=DP) :: temp1,temp2 integer :: j, jj, jcompt, flag, jk integer :: nn,nntemp integer :: k,w integer :: markeur real(kind=DP),dimension(:), pointer :: ptr_temp ! recuperation des dimensions de vect n1=size(vect,1) n2=size(vect,2) ! write(unit=*,fmt=*) "n1=",n1,"n2=",n2 ! pause if (n2/=2) then write(unit=*,fmt=*) "erreur de dimension de vect, tri 2D : dim non égale a 2" return endif nn=n1 allocate(stock1(nn),stock2(nn)) do k=1,nn STOCK1(k)=vect(k,1) STOCK2(k)=vect(k,2) enddo .........
Oddly, I declare these variables as "allocatable", so they should be allocated after the statement allocate, right ?
Except I get that "Undefined pointer/aray" (see attached picture). So I guess that it should crash when I affect a value in the "do loop" that follows ? But it doesn't. The debugger still goes through the code
Please advise. I can't figure out what's going on in my statements.
Regards,
Renaud Egal
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I declare these variables as "allocatable", so they should be allocated after the statement allocate, right ?Not necessarily. You can guard against failed allocation requests by including a STAT= clause in the ALLOCATE statement. If the ALLOCATE did fail, which could happen if nn is large, that would explain why the debugger shows the array as undefined.
You can also use the intrinsic function ALLOCATED to test whether an array has been properly allocated before using the array -- for example, to store information into it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, I'll try that as soon as I can.
But in this case nn value was 12, not so much large. And if it failed to allocate, wouln't it crash when work is done on it ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
And if it failed to allocate, wouln't it crash when work is done on it ?That's what I'd expect.
It would help if you could post a complete program source with instructions build and run, and provide information on the compiler version and options used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you need to show the declaration of vect in the calling routine also.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If an allocate statement without a STAT specifier encounters an error, then the program should terminate (see F2008 6.7.1.2p9).
This just looks like the debugger getting confused about where the variable being watched is actually kept in memory, or similar. This is not unusual. On its own it may not indicate a problem with the program (or may not be relevant to any other observed problems with the program).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Guys,
from what you said I figured that it was an abnormal functionning of VS, not fortran itself.
Then I reinstalled VS and the problem disappeared. Strange.
- Tags:
- Hi
- I did meet the same question as you under vs2013 and vs2019
- which version have you installed to solve the problem
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page