Topic: Translate CVF graphics to Simply Fortran

I am using CVF66 for many years and creates a lot of programs. CVF is no more working with windows > XP and it became Intel Visual Fortran; but IVF is no option for me for many reasons.
I am lucky to have Simply Fortran with AppGraphics now but there is a little problem: AppGraphis is using pixel coordinates with the origin left up and my programs in CVF are using so called "world" coordinates with the origin left down. Further CVF routines, of course, looks different from Appgraphics (as well from any other graphic lib).
I decided (and just started) to build a module which is calling AppGraphics routines by the (nearly) unchanged old CVF graphics routines.  I am sure that it will avoid a lot of work translating all the CVF graphics in stead of rewriting statement by statement!
Are there more (ex-)CVF-users with the same problem?

Re: Translate CVF graphics to Simply Fortran

Hello Jeff,
I made a translate interface between CVF graphics so called  "world "ordinates and pixel ordinates as used in AppGraphics. So for me there is no need to make it also in Appgraphics now.The interface makes it possible to use the same  calls to graphics as in CVF:
Subroutine Moveto_w(xw,yw,wxy) ! Name and arguments same as CVF
!   Use W_ords_to_pixels
!    Use AppGraphics
    Integer x,y 
    Real*8 xw,yw
    TYPE (wxycoord)wxy
    wxy%x = xw
    wxy%y = yw
    x= int((xw)*scale_x) + x_offset
    y= int((ywtot- yw)*scale_y) - y_offset
    Call moveto (x, y)
    Call settextxy (x, y)       ! this is because CVF has no different textpos for outgtext
  end subroutine Moveto_w

I am sure that it will save much time to convert all my software to Simply Fortran from CVF!
Still to do: a lot of other procedures like circles, arcs, ellipse, rectangles  and so on.
But due to other activities a have to stop after some weeks with SF and may be I can restart end of august if there comes no other job....
Klaus

Re: Translate CVF graphics to Simply Fortran

Klaus,

That's a great bit of code!  Having to do it for all the shapes might be hard, but perhaps you could have some functions to handle such things:

! Translate x coordinates
pure function tr_x(wxy) result x
   implicit none
   type(wxycoord), intent(in)::wxy
   integer::x
   x = int(wxy%x*scale_x)+x_offset
end function tr_x

! Translate y coordinates
pure function tr_y(wxy) result y
   implicit none
   type(wxycoord), intent(in)::wxy
   integer::y
   y = int(wxy%y*scale_y)+y_offset
end function tr_y

I apologize if there's a syntax error above. I didn't actually test the functions.

With the above, though, you could do something like:

call line(tr_x(p1), tr_y(p1), tr_x(p2), tr_y(p2))

And it might allow you to avoid having to write a new wrapper subroutine for each and every drawing operation.

Jeff Armstrong
Approximatrix, LLC

Re: Translate CVF graphics to Simply Fortran

Hello Jeff,
Thanks for your code to translate dimensions to pixels prior to use graphics. It's a good idea to use it for all new code. My proposed solution only is applicable to let CVF source work asap without many changes.
However..... my impression is that GNU Fortran accepts less language variation than Compac Fortran. In general it's better to use the exact standard instead of a individual programming style!
It's a great benefit that Simply Fortran is helping already while typing the code!
And from this there rises a new question regarding your above mentioned call line which contains the functions as arguments
In the following example
Do i = 1,3
    xw = p(i,1); yw = p(i,2)
    Call  Moveto_w(xw,yw,wxy)   !(dble(p(i,1)),dble(p(i,2))), wxy)
    ii = lineto_w(dble(p(i+5,1)),dble(p(i+5,2)))
end do
Moveto_w does not accept functions but lineto_w does accept! It was directly shown by typing the statement.
Why? Wat happend?
By the way, the CVF combination Moveto prior to lineto is because CVF is missing the line between two points

I'll be from tomorrow some days out of office,
Regards Klaus

Re: Translate CVF graphics to Simply Fortran

Klaus,

I'm not sure I understand you question exactly. Could you also post the code used to implement the lineto_w function so I could compare it to the moveto_w subroutine.

Jeff Armstrong
Approximatrix, LLC

Re: Translate CVF graphics to Simply Fortran

Hello Jeff,
The problem is allready solved, but I don't know which code was not correct and after many alterations I cannot trace it back. may be I had some bad declarations....

Below is the code of my (prelininary) translater from CVF to SF containing move_to and line_to for your info.

The call to move _to and line_to as described before is done in several routines; for instance in the following:

Subroutine draw3D_cube(p, maxpnts)
use appgraphics
Use W_ords_to_pixels
Dimension p(maxpnts,3)
!.....
.....
In the first versions I wrote:
Call  Moveto_w(dble(p(i,1)),dble(p(i,2))), wxy)
It did not work and I used:
Call  Moveto_w(xw,yw,wxy)
......
Now in a new test the first statement works - so the problem is solved.
I am more and more contented with SF2 and will recommend it anywhere!
Regards, Klaus


PS
For your info the translate module
Module W_ords_to_pixels
    Use AppGraphics
Real*8 xw,xwtot, scale_x
Real*8 yw,ywtot, scale_y
Integer dx,dy, x_offset, y_offset
TYPE wxycoord
      Real*8 x
      Real*8 y
end type wxycoord
TYPE (wxycoord)wxy

contains

!!!!! ===================== warning ==============================!!!!! a
! The pixel window to show graphics has to be opened prior to apply this function !!!!!
Function setwindow (origin , x_left, y_up, x_rght, y_bot)    ! same as CVF but little changed functionallity!!
! i2   = setwindow (.TRUE.   , x_left, y_up, x_rght, y_bot)  ! make this work in module
        ! make returnvalue =1 if OK, otherwise 0
! In this this function a world coordinate system y from top down is not defined and has to return zero (diff from CVF)
integer setwindow
logical origin     ! to be true for lower left corner and y up warts
Real*8 x_left, y_up, x_rght, y_bot !virtual world corners of the viewport
                    ! If negative lower left corner there is an offset to the origin xw,yw = 0.,0.
Real*8 dxw, dyw    ! absolute "world"dimensions in xy direction
integer dx, dy
setwindow = 0

! the window size in world ordinates is defined by the arguments of this routine!!!!!!!!!!!!!!!!!!
dxw = x_rght - x_left
dyw = y_up - y_bot
If(dwx == 0. .or. dwy == 0.)return
If( .not. origin) return

! get the pre-defiened window size of the CURRENT window in pixels x,y may be the max screen or lower defined
dx = getmaxx()
dy = getmaxy()


IF(dx > 0 .and. dy > 0 )then
    ! only works in a predefined actual window!
     xwtot = dxw           !  May ..tot should be replaced by  ..w !!!
     scale_x = dble(dx)/dxw
     x_offset= -int(x_left*scale_x)
     
     ywtot = dyw
     scale_y = dble(dy)/dyw
     y_offset= -int(y_bot*scale_y)
!  End subroutine init_world_window
setwindow =1 ! does not work with origin in top left
End if
End function setwindow


  Subroutine Moveto_w(xw,yw,wxy)
!   Use W_ords_to_pixels
!    Use AppGraphics
    Integer x,y 
    Real*8 xw,yw
    TYPE (wxycoord)wxy
    wxy%x = xw
    wxy%y = yw
    x= int((xw)*scale_x) + x_offset
    y= int((ywtot- yw)*scale_y) - y_offset
    Call moveto (x, y)
    Call settextxy (x, y)       ! this is because CVF has no different textpos for outgtext
  end subroutine Moveto_w
   
   
  Function lineto_w(xw,yw)
  !  Use W_ords_to_pixels
    Integer x,y
    Real*8 xw,yw
!    TYPE (wxycoord)wxy ! neccessary to keep the end point in wxy?? Don't thinck so !!!
!    wxy%x = xw
!    wxy%y = yw
    lineto_w = 0   
    x= int((xw)*scale_x)  + x_offset
    y= int((ywtot- yw)*scale_y) - y_offset
    Call lineto (x, y)
    lineto_w = 1   
  End function lineto_w
 
!++++++++++++++++++++++++++++++++++++++++++++++++++++=
! still to do:
! Add procedures for all other used graphic function using world coordinates also for graph. text
   
End module W_ords_to_pixels