Silverfrost Forums

Welcome to our forums

New Video

20 Jun 2020 10:06 #25717

Well I opened up my main application this morning in Plato and recompiled it with the aim of identifying other places where I need to make the adjustments outlined above. I succeeded in doing this, but I had to resort to using Notepad as the editor.

Today’s problem is that the new Plato closes without warning when scrolling through a long file of code using the scroll up/down buttons– around 5000 lines in this case.

PS autocompile was off, but highlight DO/END do was on. If both are off it appears to be OK.

20 Jun 2020 11:08 #25718

Ken

Is it possible to send me the code?

20 Jun 2020 1:47 #25719

I defined two additional functions as recommended by Paul/Ken to avoid direct call to SIMPLEPLOT_REDRAW@:

integer function new_data_cb()
CALL SELECT_GRAPHICS_OBJECT@(handle_pl)
call simpleplot_redraw@()
CALL select_font@('arial')
CALL bold_font@(1)
CALL size_in_points@(15,15)
CALL draw_characters@('Y_S-JTSK [m]',600,630,RGB@(255,0,255))
CALL rotate_font@(90.0d0)
CALL draw_characters@('X_S-JTSK [m]',90,400,RGB@(255,0,255)) 
CALL rotate_font@(0.0d0)
new_data_cb = 2
end function new_data_cb

Its contents was previously part of an integer call-back function within the %PL following the condition:

IF (cb_reason .eq. 'PLOT_ADJUST') THEN 
...
i = COPY_GRAPHICS_REGION@(handle_internal_gr, 1, 1, gw, gh, handle_pl, 1, 1, gw, gh, 13369376) 
END IF

Now, it looks as follows:

IF (cb_reason .eq. 'PLOT_ADJUST') THEN 
i = new_data_cb()
i = COPY_GRAPHICS_REGION@(handle_internal_gr, 1, 1, gw, gh, handle_pl, 1, 1, gw, gh, 13369376) 
END IF

Then, the 2nd new function to avoid direct SIMPLEPLOT_REDRAW@ call is:

integer function new_data_cb_simple_plot()

CALL SELECT_GRAPHICS_OBJECT@(handle_pl)
call simpleplot_redraw@()
new_data_cb_simple_plot = 2

end function new_data_cb_simple_plot

The above function replaces all direct SIMPLEPLOT_REDRAW@ calls (all those calls were removed) in the whole program.

When I zoom in/out the graph by pressing the corresponding buttons, it works, however as soon as I move the mouse cursor back over the graph, it automatically adjust the graph to its extents without pressing zoom in or zoom out button (what is not wanted).

Now, I do not know, whether this could be a problem with the new DLLs or the problem is embedded in my code?

And to be honest, I do not quite understand, what it is advantage of blocking direct calls to SIMPLEPLOT_REDRAW@ function (which worked problem free) and using an user defined function instead? At present, I have some problems with this approach.

Martin

20 Jun 2020 2:13 #25720

Ken

There is an alternative way for ClearWin+ to avoid re-entry and that is for it to block calls to simpleplot_redraw@ from the 'PLOT_ADJUST' callback.

We can try that if you wish.

20 Jun 2020 5:20 #25721

Martin,

If you look carefully at the examples I provided you with in the other thread, there are no calls to SIMPLEPLOT_REDRAW@ within the “PLOT_ADJUST” section, or any other section of the %pl call back.

If you did have call to SIMPLEPLOT_REDRAW@ in the %pl call back, then you will get into a recursive loop and it’s by sheer luck rather than design that your code was previously running.

The zoom/pan example I posted on Thu May 14, 2020 7:39 pm works without any modification with the new DLLs. As does the example from Fri May 29, 2020. Neither of these have calls to SIMPLEPLOT_REDRAW@() within the %pl callback.

The issue I raised above was that using the %gr drawing routines on the %pl region was only occurring on the first time the call back was called. Subsequent calls to SIMPLEPLOT_REDRAW@ do not now call the callback, and so I was missing some graphics information which is added to the %pl graphics region.

Based on the discussion in the other thread, you do not appear to be trying to do this – since your %gr calls are to a different graphics region.

Without seeing a simple example which demonstrates how you have adapted the samples I have provided you with and the nature of the problem there’s not much more I can say.

For example, in you first code fragment above why do you need to call simpleplot_redraw@ before labelling your axis? Is that really necessary?

Paul,

I was OK with the previous DLLs – what I was trying to do with box selection in a %pl to create a zoom function was pushing the library to its limits – so happy to back off on that one. In any case, the modifications I made yesterday to my code, will not cause the code to fail if the block in the new DLLs is removed – which would address Martin’s issue – for the time being anyway.

Having said that, I think the block is the best way forward for all users – but you are in a far better position to make the final call on this than I am.

Ken

20 Jun 2020 6:49 (Edited: 20 Jun 2020 8:46) #25722

Paul, Great overall improvement of %PL!

Looked at video, though had no chance to play with it yet, too many other programs are still loaded. But from just the video was surprised that 256 bytes buffer was enough to keep all the settings. Is it formally infinite to accommodate future additions?

Also as just the potential option to discuss, do you think it is doable to implement also what John Silver mentioned, i.e. additional option for saving settings into the file ? If this will be done in the form easily included after that into the Fortran source text without editing (i.e. complete lines of text like iz=winop@('link=lines') ) that probably would be great as the current settings character line looks totally cryptic. May be on this early stage at least adding short keywords in this settings line would make it human readable and editable

And the option (button or keyboard combination) for saving image into png/jpg?

As a matter of beautification of settings probably great would be to use property sheet %ps where related settings can be systematized under the specific tabs and also 'spiced' by small images clarifying what means link=lines or frame, or etched https://i.postimg.cc/HnSkqr0W/Image146.jpg

This was real breakthrough for %PL !

20 Jun 2020 7:08 #25723

Ken,

sorry, this was copied by mistake (the call to SIMPLEPLOT_REDRAW@ within the function I provided above)! I never used there the call to SIMPLEPLOT_REDRAW@. Nevertheless, the issue I described I still have, simply when I zoom in/out by pressing the corresponding buttons and then when I move with the cursor over the graph, it automatically adjust to its extents.

Now, I am investigating where could be the problem hidden.

20 Jun 2020 7:45 #25724

Martin,

OK, understood, but you can see how a single line of code can be misleading.

Using the terminology/definition of variables in of my post on Thu May 14, 2020 7:39 pm, maybe adding the following will fix the problem – before your call(s) to simpleplot_redraw@()

k = CHANGE_PLOT_DBL@(0, 'x_min', 0, x_min_now)
k = CHANGE_PLOT_DBL@(0, 'x_max', 0, x_max_now)
k = CHANGE_PLOT_DBL@(0, 'y_min', 0, y_min_now)
k = CHANGE_PLOT_DBL@(0, 'y_max', 0, y_max_now)

Ken

20 Jun 2020 8:08 #25725

Thanks Ken!

Today in the afternoon I already tested also your code you provided now again, with no positive effect (my problem remains)

Currently, it looks like follows (my handle_pl=0):

INTEGER FUNCTION update_PL_limits ()    ! call-back to update the graphs
    USE CLRWIN						
    IMPLICIT NONE
    INTEGER*4 
    
ag=CHANGE_PLOT_DBL@(handle_pl,'x_min',0,y_min_now);ag=CHANGE_PLOT_DBL@(handle_pl,'x_max',0,y_max_now)
ag=CHANGE_PLOT_DBL@(handle_pl,'y_min',0,x_min_now);ag=CHANGE_PLOT_DBL@(handle_pl,'y_max',0,x_max_now)
    	
!  CALL simpleplot_redraw@()
i = akt_graf ()  !contains calling to SELECT_GRAPHICS_OBJECT@(handle_pl) and SIMPLEPLOT_REDRAW@() functions
    
    update_PL_limits=1
END FUNCTION update_PL_limits

The axes are reversed in the code above due to the way how our national geodetical coordinate system is defined (but this is formal thing only) So, investigating further, although I have such feeling that the problem may really lie hidden here (based on graphs behaviour).

Martin

20 Jun 2020 8:30 #25726

I forgot to add the following:

It can be an interesting indicator, as soon as I zoom in by pressing the zoom in button, the X,Y captions dismiss (they re-appear only then, when I press zoom to extents). In any zooming in/out, they always disappear.

Currently, the code in the %PL call-back after the condition PLOT_ADJUST looks like this:

IF (cb_reason .eq. 'PLOT_ADJUST') THEN 
 
        
 !       CALL SELECT_GRAPHICS_OBJECT@(handle_pl)   !výber grafu 
      	CALL select_font@('arial')                                   ! nový font 
        CALL bold_font@(1)                                           ! bold aktivovaný       
!        CALL size_in_pixels@(15,15)                          ! výška fontu v pixeloch 
        CALL size_in_points@(15,15)                          ! výška fontu v bodoch
        CALL draw_characters@('Y_S-JTSK [m]',600,630,RGB@(255,0,255))  ! napisanie textu Y_S-JTSK [m] horizontálna os - nadpis
        CALL rotate_font@(90.0d0) ! Otocenie textu (pre zvislu os (v S-JTSK je to os X a napise X_S-JTSK [m] do vertikálnej polohy)
        CALL draw_characters@('X_S-JTSK [m]',90,400,RGB@(255,0,255)) vertikalna os - nadpis
        CALL rotate_font@(0.0d0) ! spat do horizontalnej roviny


i = COPY_GRAPHICS_REGION@(handle_internal_gr, 1, 1, gw, gh, handle_pl, 1, 1, gw, gh, 13369376)    ! kópia do pamäte
 END IF

All the codes above worked problem free with previous versions of DLLs.

20 Jun 2020 9:56 #25728

Martin,

The %pl call back will only be called once by the pl part of the code and that is when the %pl region is initially created. This is indicated by the presence of the PLOT_ADJUST string. The captions will therefore be drawn initially correctly. Subsequent calls to SIMPLEPLOT_REDRAW@ will now no longer call the %pl call back, so the actions that previously were there triggered by the PLOT_ADJUST string have to be placed elsewhere.

Move everything that was within the

 IF (cb_reason .eq. 'PLOT_ADJUST') THEN  ;;;;;; END IF

to a new subroutine

Call this new subroutine from within the IF (cb_reason .eq. 'PLOT_ADJUST') THEN control block in the pl_cb, and also after your calls to SIMPLEPLOT_REDRAW@. With the previous DLLs the call to SIMPLEPLOT_REDRAW@ would call the pl_cb – now it does not.

If you do this it should fix your axes problem.

No changes should be necessary to any other parts of the pl_cb associated with mouse moves etc.

Paul, may have an idea why the previous limits set for the pl region now appear to get forgotten – which is a change to the way the program operated before.

I did a quick test on my previous code – the one with the buttons to pan and zoom. I added another button, the call back of which only calls simpleplot_redraw@ and the currently selected limits, after a zoom operation are not “lost”. Added another button which changes the data to be plotted, - again the call to SIMPLEPLOT_REDRAW@ associated with this does not change the plot limits. This code is below.

If you comment out all the code in the pl_cb associated with a mouse move and drawing the yellow box of coordinates does the zoom function still fail?

Ken

20 Jun 2020 9:58 #25729
implicit none
integer, parameter :: dp = kind(1.d0), n = 1000
real(kind=dp), parameter :: pi = 3.14159265359d0, dt = 1.d-4, omega = 50.d0*2.d0*pi, ta = 0.040d0
real(kind=dp) t1(1:n), ac(1:n), dc(1:n), inst(1:n), xmin_data, xmax_data, ymin_data, ymax_data, xstep, ystep
real(kind=dp) x_min_now, x_max_now, y_min_now, y_max_now
contains
  integer function generate_data()
  integer i
  real(kind=dp) ran
  ran=random@()
    do i = 1, n, 1
      if (i .gt. 1) then
        t1(i) = t1(i-1) + dt
      else
        t1(i) = 0.d0
      end if
      ac(i) = ran*sqrt(2.d0)*cos(omega*t1(i)-pi)  ;  dc(i) = -ac(1)*exp(-t1(i)/ta) ; inst(i)=ac(i)+dc(i)
    end do
    generate_data = 1
  end function generate_data
  integer function plot()
  include<windows.ins>
  integer, save :: iw
    xmin_data = minval(t1)  ; xmax_data = maxval(t1)
    ymin_data = min(minval(ac), minval(dc), minval(inst)) ; ymax_data = max(maxval(ac), maxval(dc), maxval(inst))
    xstep = (xmax_data - xmin_data)/10.d0 ; ystep = (ymax_data - ymin_data)/10.d0
    x_min_now = xmin_data ; x_max_now = xmax_data ; y_min_now = ymin_data ; y_max_now = ymax_data
    call winop@('%pl[native,x_array,gridlines,n_graphs=3,width=2,frame,etched,colour=blue,colour=red,colour=black]')
    iw = winio@('%pl[full_mouse_input]&',700,600,n,t1,ac,dc,inst)
    iw = winio@('%ob[scored]&')
    iw = winio@('%2nl%cn%^tt[Zoom in]&',              zoom_in_cb)
    iw = winio@('%2nl%cn%^tt[Zoom out]&',             zoom_out_cb)
    iw = winio@('%2nl%cn%^tt[Full extents]%2nl&',     zoom_out_full_cb)
    iw = winio@('%2nl%cn%^tt[Pan pos X]&',            pan_positive_x_cb)
    iw = winio@('%2nl%cn%^tt[Pan neg X]&',            pan_negative_x_cb)
    iw = winio@('%2nl%cn%^tt[Pan pos Y]&',            pan_positive_y_cb)
    iw = winio@('%2nl%cn%^tt[Pan neg Y]&',            pan_negative_y_cb)
    iw = winio@('%2nl%cn%^tt[Simpleplot Redraw]&',    spr_cb)
    iw = winio@('%2nl%cn%^tt[New data]&',             new_data_cb)
    iw = winio@('%cb%ff%2nl%cn%tt[Close]&')
    iw = winio@(' ') ; plot = 1
  end function plot
  integer function spr_cb()
  include<windows.ins>
    call simpleplot_redraw@()
    spr_cb = 1
  end function spr_cb
  integer function new_data_cb()
  include<windows.ins> 
  integer i
    i = generate_data()
    call simpleplot_redraw@()
    new_data_cb = 1
  end function new_data_cb
  integer function update_pl_limits()
  include<windows.ins>
  integer k
    k = CHANGE_PLOT_DBL@(0, 'x_min', 0, x_min_now) ; k = CHANGE_PLOT_DBL@(0, 'x_max', 0, x_max_now)
    k = CHANGE_PLOT_DBL@(0, 'y_min', 0, y_min_now) ; k = CHANGE_PLOT_DBL@(0, 'y_max', 0, y_max_now)
    call simpleplot_redraw@()           
    update_pl_limits = 1
  end function update_pl_limits
  subroutine swap_real_dp(r1,r2)
  real(kind=dp), intent(inout) :: r1, r2
  real(kind=dp) temp
    temp = r2 ; r2 = r1 ; r1 = temp
  end subroutine swap_real_dp
20 Jun 2020 9:58 #25730
  integer function zoom_out_cb()
  include<windows.ins>
  integer i
    x_min_now = x_min_now - xstep ; x_max_now = x_max_now + xstep ; y_min_now = y_min_now - ystep ; y_max_now = y_max_now + ystep
    i = update_pl_limits() ; zoom_out_cb = 1
  end function zoom_out_cb
  integer function zoom_in_cb()
  real(kind=dp) x_min_now_save, x_max_now_save, y_min_now_save, y_max_now_save
  integer i
  integer, save :: iw
    x_min_now_save = x_min_now ; x_max_now_save = x_max_now  ; y_min_now_save = y_min_now ; y_max_now_save = y_max_now
    x_min_now = x_min_now + xstep ; x_max_now = x_max_now - xstep ; y_min_now = y_min_now + ystep ; y_max_now = y_max_now - ystep
    if ( ( x_max_now - x_min_now .gt. xstep ) .and. ( y_max_now - y_min_now .gt. xstep ) ) then
      i = update_pl_limits()
    else
      x_min_now = x_min_now_save ; x_max_now = x_max_now_save ; y_min_now = y_min_now_save ; y_max_now = y_max_now_save
      iw = winio@('%ws%2nl%cn%tt[Continue]','Max zoom level with this control.') 
    end if
   zoom_in_cb = 1
  end function zoom_in_cb
  integer function zoom_out_full_cb()
  integer i
!    x_min_now = xmin_data ; y_min_now = ymin_data ; x_max_now = xmax_data ; y_max_now = ymax_data
!   Copied from function plot() - since the extent of the data may have changed following a call to new_data 
    xmin_data = minval(t1)  ; xmax_data = maxval(t1)
    ymin_data = min(minval(ac), minval(dc), minval(inst)) ; ymax_data = max(maxval(ac), maxval(dc), maxval(inst))
    xstep = (xmax_data - xmin_data)/10.d0 ; ystep = (ymax_data - ymin_data)/10.d0
    x_min_now = xmin_data ; x_max_now = xmax_data ; y_min_now = ymin_data ; y_max_now = ymax_data
    i = update_pl_limits()
    zoom_out_full_cb = 1
  end function zoom_out_full_cb
  integer function pan_positive_x_cb()
  integer i
    x_min_now = x_min_now + xstep ; x_max_now = x_max_now + xstep ; i = update_pl_limits() ; pan_positive_x_cb = 1
  end function pan_positive_x_cb
  integer function pan_negative_x_cb()
  integer i
    x_min_now = x_min_now - xstep ; x_max_now = x_max_now - xstep ; i = update_pl_limits() ; pan_negative_x_cb = 1
  end function pan_negative_x_cb
  integer function pan_positive_y_cb()
  integer i
    y_min_now = y_min_now + ystep ; y_max_now = y_max_now + ystep ; i = update_pl_limits() ; pan_positive_y_cb = 1
  end function pan_positive_y_cb 
  integer function pan_negative_y_cb()
  integer i
    y_min_now = y_min_now - ystep ; y_max_now = y_max_now - ystep ; i = update_pl_limits() ; pan_negative_y_cb = 1
  end function pan_negative_y_cb
end module example
program main
use example
implicit none
integer i
i = generate_data() ; i = plot()
end program main
21 Jun 2020 10:22 #25742

Ken,

profound thanks for your help! Today, I had another family program so I was not able to seat in front of my PC. I will do it within next week.

BUT, I already did what you suggest practically immediately after your advise (your post of Friday, June 19, 3.46pm)!

I was struggling with this change a while and my best result was that I achieved that the axes captions were always present (even after zooming in/out), BUT the problem with automatic zoom to extents, when I moved with mouse cursor over graphs, remained unsolved with these changes! It means, as soon as I move the cursor over the graphs after some zooming in/out, the program automatically re-draws whole graphs to their extents.

I have to mention that I created a FUNCTION called within the block IF (cb_reason.eq. 'PLOT_ADJUST') THEN ... END IF, which contained everything, NOT SUBROUTINE! I suppose it should make no difference.

It looked as follows:

!integer function new_dll_cb()

!        CALL SELECT_GRAPHICS_OBJECT@(handle_pl)
!		call simpleplot_redraw@()
        
!		CALL select_font@('arial') 
!        CALL bold_font@(1) 
!!        CALL size_in_pixels@(15,15) 
!        CALL size_in_points@(15,15) 
!        CALL draw_characters@('Y_S-JTSK [m]',600,630,RGB@(255,0,255)) 
!        CALL rotate_font@(90.0d0) 
!        CALL draw_characters@('X_S-JTSK [m]',90,400,RGB@(255,0,255)) 
!        CALL rotate_font@(0.0d0) 
!	i = COPY_GRAPHICS_REGION@(handle_internal_gr, 1, 1, gw, gh, handle_pl, 1, 1, gw, gh, 13369376)

!new_data_cb = 2
!end function new_dll_cb
....
....
IF (cb_reason .eq. 'PLOT_ADJUST') THEN 

i = new_dll_cb()

END IF

In next days I will create a subroutine (instead of function), if it should help to solve my problem. I will give a feedback as soon as I get something new. At the moment I am quite sceptic, since there are some additional issues (the switching on/off of graphs does not work correctly). Since I am already under time pressure to present the results of the whole graphics in a seminar, probably I will downgrade the DLL´s back to the previous ones, where everything worked problem free and later, after seminar, I will try to adapt whole program to the latest DLLs, since now - the %PL command offers very exciting features and flexibility (it would be for us as surveyors worthful, when it would be added to the %PL still the option SCALE)!.

However, my program has about 1300 lines of code in 5 different subroutines/modules, so it will not be a easy work.

Martin

22 Jun 2020 3:05 #25743

Paul, Tried this new feature and my immediate wish was to set parameters in the file. If user often doing changes (adjusting minimum and maximum x and y, changing step etc) he will be forced to recompile the code every time he adjusts the plot for new variants. There exist tasks where you set the plot just ones for all future cases but in vast other life situations you need permanently change something in the plot.

Parameters are automatically saved in the filename which user provides for this specific plot, and they will be automatically loaded from same file when user next time opens this specific plot. No further intervention is needed, all done in background. This is how all my plots are set in all programs, no recompilation needed. There was no single plot ever which I set ones and never changed something in it again! Besides it is easy quickly clone old plot to new plot using existing plot settings if needed

May be there exist situations where current way of save setting could be the only practical method but I can not quickly imagine one. I understand that this was just the demo, and your route for the final product lie in different way

22 Jun 2020 7:01 #25745

Dan

At the moment I don't understand what you are asking for.

Do you want ClearWin+ to offer to save the data to a file and prompt for a file name?

As it is, your program can save the data to a file and read it back on the next run. You will have to do the reading back anyway even if ClearWin+ saves to a file for you.

22 Jun 2020 9:16 #25746

The mechanism within ClearWin+ that is used to block re-entry to a %pl callback from a call to simpleplot_redraw@ has been modified. With this change, calling simpleplot_redraw@ will lead to a call to the callback but a call to simpleplot_redraw@ from the %pl callback will be blocked.

New DLLs that incorporate this change can be downloaded via the link given here https://forums.silverfrost.com/Forum/Topic/3780.

22 Jun 2020 11:01 #25749

Martin,

your old code may well work with today's DLLs - which implement the change that was made but in a different way. I don't have time to download and test myself until this evening.

Ken

22 Jun 2020 12:17 #25750

Paul I meant to offer an option that settings data saved to the harddrive automatically at the exit of settings process. In this case next time you run this program it starts not with basic plot like it does for first time but already using created settings. For that additional filename has to be provided like

Call Winop@('AutoSetfile=PLplotMain01.set')

and that's basically it

Of course user can save settings by himself and read them next time program runs but that is an additional programming by the user. With above mentioned addition the user will be able to use both options for saving settings to harddrive if he wants plus use the existing saving to the clipboard with recompilation. The automatic saving settings to the disk with similarly automatic reading next time program runs the plot will be the most used I predict

22 Jun 2020 2:27 #25751

Dan

I will see what can be done.

John

The order is coded using the following list but you will need to remove some items particularly those like line colour that vary from one line to another. Line attributes are added one line at a time at the end of the first two lists each of which is terminated by a semi-colons.

enum
{
  pl_title_ix,
  pl_title_iy,
  pl_xcap_ix,
  pl_xcap_iy,
  pl_ycap_ix,
  pl_ycap_iy,
  pl_tick_value_ix,
  pl_tick_value_iy,
  pl_xmin_supplied,
  pl_ymin_supplied,
  pl_xmax_supplied,
  pl_ymax_supplied,
  pl_x_sigfigs,
  pl_y_sigfigs,
  pl_width,
  pl_depth,
  pl_link,
  pl_pen_style,
  pl_line_width,
  pl_symbol,
  pl_symbol_size,
  pl_axes_pen,
  pl_frame_pen,
  pl_tick_len,
  pl_gridlines,
  pl_frame,
  pl_framed,
  pl_etched,
  pl_external_ticks,
  pl_fixed_aspect,
  pl_title_height,
  pl_caption_height,
  pl_tick_value_height,
  pl_back_colour,
  pl_font_colour,
  pl_margin_left,
  pl_margin_top,
  pl_margin_right,
  pl_margin_bottom,
  pl_smoothing,
  pl_idata_end
};

enum
{
  pl_xmin,
  pl_ymin,
  pl_xmax,
  pl_ymax,
  pl_ddx,
  pl_ddy,
  pl_fdata_end
};
Please login to reply.