 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Tue Oct 06, 2009 12:26 pm Post subject: Allocatable variables and modules |
|
|
The question relates to a common variable defined by means of a module and alocatable variables.
In oder to save time we have several 2D data arrays defined in a module. This means we assign the data once and perform the desired operations. In short we experience the following: In some subroutines arrays are constructed from the module (or global) data, i.e. one column of a matrix. When using the debugger the assigned matrix display no valid data (but a print to the screen is correct). I prepared a small sample code which shows this: Code: | module pmsyn_mod
implicit none
save
real, allocatable,dimension(:,:) :: TF
end module pmsyn_mod
subroutine assign_TF(m,n)
use pmsyn_mod
implicit none
integer,intent(in) :: m,n
integer :: i,j
real :: random
allocate(TF(m,n))
do i=1,n
do j=1,m
TF(j,i) = random()*1000.0d0
enddo
enddo
return
end subroutine assign_TF
subroutine T_new(m,n)
use pmsyn_mod
real,dimension(m) :: T1
real,pointer,dimension(:) :: T2
T1 = TF(:,1)
write(*,'(5F8.2)') T1 !---------------------T1 has only invalid values in the debugger
T2 => TF(:,1)
write(*,'(5F8.2)') T2 !---------------------T2 has valid values in the debugger
return
end subroutine T_new
program alloc
use pmsyn_mod
implicit none
integer :: m=5,n=2
! Assign a 5x2 matrix
call assign_TF(m,n)
! Use
call T_new(m,n)
end program alloc |
My question: In the subroutine T_new the arrays T1 and T2 are defined as real,pointer,dimension( : ) respectively. Are both these definitions correct or is there something wrong in the debugger? |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Thu Oct 08, 2009 10:07 am Post subject: |
|
|
Unfortunately I cannot judge whether the above issue is the result of some bad programming by us or some poor behaviour (or bug) from the debugger. However, I did put in some effort to provide a working example which will reproduce what we experience.
I will appreciate an one line comment  |
|
Back to top |
|
 |
Robert

Joined: 29 Nov 2006 Posts: 457 Location: Manchester
|
Posted: Thu Oct 08, 2009 2:30 pm Post subject: |
|
|
Hi
I will take a look at your example. Without really looking ... I would blame the debugger  |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Fri Oct 09, 2009 12:15 am Post subject: |
|
|
I managed to reproduce your example, using FTN95 Ver 5.30.0
While SDBG Ver 5.30 shows T1 as undefined, the write statement gives the correct result. T2 has the correct values displayed in SDBG and also printed.
I can't see any explaination other than the values SDBG has for T1 are not being correctly updated.
I did change T1 to allocatable and that changed the performance of SDBG. Stepping through using F7 shows how SDBG is working or not working. Could it be that SDBG does not like automatic arrays ?
Code: | subroutine T_new(m,n)
use pmsyn_mod
integer*4 m,n,k
! real,dimension(m) :: T1
real, allocatable,dimension(:) :: T1
real,pointer,dimension(:) :: T2
!
k = size (TF,1) ! probably safer coding
allocate(T1(k))
T1 = TF(:,1)
write(*,'(5F8.2)') T1 !---------------------T1 has only invalid values in the debugger
!
T2 => TF(:,1)
write(*,'(5F8.2)') T2 !---------------------T2 has valid values in the debugger
return
end subroutine T_new
|
John |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Sat Oct 10, 2009 9:06 pm Post subject: |
|
|
I started using the numerical recipes in fortran 90. Here automatic arrays are often used in the code. Even though the results are correct, it is not possible to debug properly (or without printing to the screen). From this I conclude that this must be a bug in SDBG.
Furthermore, I checked FTN95 versions starting from Ver. 4.70. This means that automatic arrays were never correctly updated or displayed by SDBG. Maybe other programmers do such a good job the first time they do not need to bedug - I always do a lot of debugging
Perhaps someone at Silverfrost can comment on this issue. |
|
Back to top |
|
 |
Robert

Joined: 29 Nov 2006 Posts: 457 Location: Manchester
|
Posted: Mon Oct 12, 2009 12:42 am Post subject: |
|
|
The problem only happens when the size is passed in and the array has to be allocated from the heap rather than the stack (if it is fixed size). I cannot believe this has not been noticed before. |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Mon Oct 12, 2009 3:29 am Post subject: |
|
|
Robert,
These are automatic arrays. Maybe few programmers use automatic arrays, as allocate gives a bit more control.
I rarely use SDBG, as (nearly) every time I use it on a new program, it does not display on the screen. I start with "SDBG program.exe" in a cmd.exe box. I then either have to select sdbg from the taskbar, then close it and open again or I think you can delete sdbg.ini from \windows.
It can take a few restarts to get the child windows open in SDBG that I want.
Is there an explaination for this problem or can't sdbg.ini cope with a new program.exe ?
I just tried SDBG with another program and it started up fine, so I'm not sure what causes it to sometimes start and not display the window on the screen. Any ideas ?
John |
|
Back to top |
|
 |
Robert

Joined: 29 Nov 2006 Posts: 457 Location: Manchester
|
Posted: Mon Oct 12, 2009 11:49 am Post subject: |
|
|
The sdbg window positions are the same for any debugged program. If you change them that will be reflected in future debugging sessions. In other words the program you are debugging has no effect on the window location. Do you have a current example that causes sdbg to not show its windows? If so can yo run it and then after termination send the sdbg.ini file to ftn95@silverfrost.com so I can take a look at it. |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Tue Oct 13, 2009 5:56 am Post subject: |
|
|
Robert,
I emailed the .ini files, but the difference appears to be in the coordinates.
I saved then tried the sdbg.ini file on my notebook. The before does not display on my screen, but the one after does.
The "before" one is from the last use in May, and the "ok" one is after saving the file when exiting sdbg.
When starting sdbg for the first time; to get sdbg to display, I select the sdbg logo on the taskbar, then maximise.
This produces a screen with areas that are not updated.
I then exit sdbg, saving the status.
Restarting sdbg then works.
It is off-putting that when I first start SDBG, nothing happens. (This occurs fairly regularly)
I'm not sure why this occurs, being invalid info in the sdbg file or other processes that conflict.
If it is invalid data, I don't remember how it was created, as if I save the status when exiting, it is ok.
May be it is when I don't save the info, but why would it update the file with corrupt info.
I'm at a loss to explain this, although the only obvious change in the files is that the before file has:
Desktop-X=67639555
Desktop-Y=1230127955
while the ok has:
Desktop-X=-4
Desktop-Y=-4
I did try exiting sdbg without saving, and it changed the file to (savepositiononexit=0)
How can the desktop-X in the bad file be apparently so wrong ??
I do sometimes use 2 screens with my notebook (at home), but I don't think I did that with SDBG. The bad file is stamped 1:47pm, which means I probably did not have 2 screens at the time.
Could the fix be to check for invalid locations in the .ini file ?
The before file is:-
Code: | [Debugger-Win32]
LastCommandLine=C:\junk\test\lgotemp@.exe
ShowTips=0
NextTip=2
SavePositionOnExit=1
VariablesWindow-X=111
VariablesWindow-Y=14
VariablesWindow-W=47
VariablesWindow-H=26
SourceWindow-X=12
SourceWindow-Y=11
SourceWindow-W=92
SourceWindow-H=38
StackWindow-X=112
StackWindow-Y=2
StackWindow-W=45
StackWindow-H=8
Desktop-X=67639555
Desktop-Y=1230127955
DesktopMaximised=0
Desktop-W=0
Desktop-H=0
DesktopPlacement=2,3,-1,-1,-1,-1,0,0,1408,1062
ArrayWindow-X=111
ArrayWindow-Y=15
ArrayWindow-W=41
ArrayWindow-H=29
ExpressionWindow-X=31
ExpressionWindow-Y=21
ExpressionWindow-W=30
ExpressionWindow-H=1
|
I have now tried the _before file on my other computer, and sdbg again does not display on the screen. I am at a loss to explain when these bad values for Desktop-X and Desktop-Y get created, as typically once sdbg starts working it is ok for the next few times I start it up. Could something else be initialising sdbg.ini ?
John |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Tue Oct 13, 2009 1:53 pm Post subject: |
|
|
I think that the sdbg.ini file was created when I compiled using:-
ftn95 program /check /lgo
If the program crashes, it goes to the error pop-up, but could also then initialise sdbg, but not via sdbg startup. |
|
Back to top |
|
 |
Robert

Joined: 29 Nov 2006 Posts: 457 Location: Manchester
|
Posted: Tue Oct 13, 2009 9:53 pm Post subject: |
|
|
I have uploaded a new debugger into http://www.ftn95.co.uk/ftn95/debugger.zip. It fixes the problem with non constant, non allocatable, local arrays. In addition I have added some code to mitigate this strange window placement problem. It detects odd coordinates and reset them -- so at least the window will be visible. Has anyone else seen JohnCampbell's problem where the debugger disappears and the sdbg.ini file has to be deleted?
Robert |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Tue Oct 13, 2009 11:56 pm Post subject: |
|
|
Robert,
I have tested the new version of sdbg, with my corrupt .ini file and the original example of jjgermis and both now work correctly.
thanks for your assistance
John |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Wed Oct 14, 2009 3:48 pm Post subject: |
|
|
Hi John and Robert,
I successfully tested the new version as well. It works as expected
Thank you! |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|