The following code has been puzzling me for a few days.
In the program below, a file is initially written. There are four lines each containing four random numbers.
After this a simple plot is generated using %pl. There is a call back function attached to the %pl.
If the call back reason is “plot_adjust”, set_plot_mode is called with argument (1) and the call back reads the data in the file, treating each of the four numbers in each line as two pairs of (x,y,) coordinates. A line is drawn between the two pairs of points using draw_line_betweenD@
A DO loop is used to read the file. Since the number of lines in the file is unknown, IOSTAT is used in the read statement to detect the EOF condition, which exits the DO loop. At this point, set_plot_mode@(0) is called.
The resulting graphic plot is as expected. However, with the 64 bit compiler the %mn items become unresponsive after the plot is updated by the call back function. This does not occur with the 32 bit compiler.
Can anyone else reproduce this, or identify what I am doing wrong here?
program demo
use clrwin
implicit none
integer iw, i,j
real*8 cord(4)
integer pl_cb ; external pl_cb
integer another_cb ; external another_cb
open(unit=10,file='cord.txt',status='unknown')
! Write four lines each containing four random numbers to the file cord.txt
do i = 1, 4
call random_number(cord)
write(10,*) (cord(j),j=1,4)
end do
! Create a simple pl plot
iw = winio@('%mn[Exit]&','Exit')
iw = winio@('%mn[Do something]&',another_cb)
call winop@('%pl[native,x_array,frame,gridlines]')
call winop@('%pl[link=user,dx=0.1,dy=0.1]')
iw = winio@('%^pl&',500,500,2,[0.d0,1.d0],[0.d0,1.d0],pl_cb)
iw = winio@('')
end program demo
integer function pl_cb()
use clrwin
implicit none
real*8 x1,y1,x2,y2
integer stat
print*, 'Beginning pl_cb'
if (CLEARWIN_STRING@('CALLBACK_REASON') .eq. 'PLOT_ADJUST') then
print*, 'Plot_adjust'
call SET_PLOT_MODE@(1)
! Read each line of file on unit 10, treating the values as two sets of (x,y) pairs
! Since we don't necessarily know the number of lines in the file exit the do loop using
! IOSTAT value
rewind 10
do
read(10,*,IOSTAT=stat) x1,y1,x2,y2
if (stat .eq. 0) then
call draw_line_betweenD@(x1,y1,x2,y2,rgb@(255,0,0))
write(*,'(A,2F8.4,A,2F8.4)') 'Line between ', x1, y1, ' and ', x2, y2
else if (stat .eq. -1) then
print*, 'EOF' ; exit
else if (stat .eq. -2) then
print*, 'EOR' ; exit
end if
end do
print*, 'Loop terminated'
call SET_PLOT_MODE@(0)
end if
pl_cb = 2
end function pl_cb
integer function another_cb()
print*, 'another_cb'
another_cb = 2
end function another_cb