using mathgl on intel ifx (fortran) windows

15 views
Skip to first unread message

Haydar AKDAĞ

unread,
Apr 21, 2025, 1:54:43 PMApr 21
to MathGL

Hi everyone,

I have successfully downloaded MathGL's GPL binaries for Windows, which come with the necessary DLLs and utilities. However, I am trying to use MathGL with Intel Fortran (ifx) and need some guidance.

I understand that MathGL is primarily designed for C/C++ environments, but I am wondering how I can integrate it into an Intel Fortran project. Specifically, I would like to know how to link MathGL's functions (either through the static library or the DLL) in an Intel Fortran project.

Could someone provide insights or examples on how to do this?


I ran iup_mglplot.lib intel ifx (fortran) but some mathgl functions are missing like sphere tube. So how can I connect mathgl to fortran in windows and use it?

Any help would be greatly appreciated!

Thank you!

Alexey Balakin

unread,
Apr 23, 2025, 5:25:44 PMApr 23
to MathGL
Hi,

you can use MathGL as is if you switch on the AT&T standard for code linker. This is default for gfortran, and need to be enabled manually for MS VisualFortran. After that just and mgl library -- for gfortran the command line is "gfortran test.f90 -lmgl -fdefault-real-8". The sample code is below
===================================
! gfortran test.f90 -lmgl -fdefault-real-8
program test
integer(8) :: dat, gr, mgl_create_data_size, mgl_create_graph
real(8) :: v,x,y
dat = mgl_create_data_size(30,40,1) ! data to for plotting
do i=0,29
  do j=0, 39
    x = (i-15.)/15.
    y = (j-20.)/20.
!    v = 1./(1.+(i-15)*(i-15)/9.+(j-20)*(j-20)/16.)
    v = 1/(1+x*x*9+y*y*4)
    call mgl_data_set_value(dat, v,i,j,0)
  end do
end do
gr = mgl_create_graph(1800, 1200)      ! class for plot drawing
call mgl_dens(gr,dat,"","")          ! plot surface
call mgl_cont(gr,dat,"y","")         ! plot yellow contour lines
call mgl_box(gr)
call mgl_axis(gr,"","","")       ! draw axis
call mgl_puts(gr,1.,1.,1.2,"\i f = \dfrac{1}{1+(5x-5)^2+(5y-5)^2}","",-1.)
call mgl_write_frame(gr,"sample.jpg","") ! save it
call mgl_delete_data(dat)            ! free used memory
call mgl_delete_graph(gr)
end program
===================================
Alternatively, you can use C/Fortran interface to use C/C++ functions directly (this should work for Fortran90 or later, as I remember).

Unfortunately, I know nothing about ifx compiler to specify the exact linker options and command lines.

Kind regards,
Alexey Balakin

понедельник, 21 апреля 2025 г. в 20:54:43 UTC+3,

Haydar AKDAĞ

unread,
Apr 24, 2025, 3:30:54 AMApr 24
to mat...@googlegroups.com
Hi, thank you for your response. 
First of all, I am not a professional, but which header files do I need to bind to Fortran in order to use Mathgl with ifx? 
The following program worked  

Best regards,
Haydar Akdağ


ifx mathgl.f90 -I"C:\vcpkg\installed\x64-windows\include" "C:\vcpkg\installed\x64-windows\lib\freeglut.lib" "C:\vcpkg\installed\x64-windows\lib\opengl32.lib" "C:\vcpkg\installed\x64-windows\lib\glu32.lib" "C:\vcpkg\installed\x64-windows\lib\mgl.lib" -o mathgl.exe

Exported from Notepad++
program mathgl_example use iso_c_binding implicit none integer(c_int64_t) :: dat, gr real(c_double) :: x, y, v integer :: i, j interface function mgl_create_data_size(nx, ny, nz) bind(C, name="mgl_create_data_size") import :: c_int,c_int64_t integer(c_int), value :: nx, ny, nz integer(c_int64_t) :: mgl_create_data_size end function function mgl_create_graph(w, h) bind(C, name="mgl_create_graph") import :: c_int,c_int64_t integer(c_int), value :: w, h integer(c_int64_t) :: mgl_create_graph end function subroutine mgl_data_set_value(dat, val, i, j, k) bind(C, name="mgl_data_set_value") import :: c_int, c_double, c_int64_t integer(c_int64_t), value :: dat real(c_double), value :: val integer(c_int), value :: i, j, k end subroutine subroutine mgl_dens(gr, dat, sch, opt) bind(C, name="mgl_dens") import :: c_int64_t,c_char integer(c_int64_t), value :: gr, dat character(kind=c_char), dimension(*) :: sch, opt end subroutine subroutine mgl_cont(gr, dat, col, opt) bind(C, name="mgl_cont") import :: c_int64_t,c_char integer(c_int64_t), value :: gr, dat character(kind=c_char), dimension(*) :: col, opt end subroutine subroutine mgl_box(gr) bind(C, name="mgl_box") import :: c_int64_t integer(c_int64_t), value :: gr end subroutine subroutine mgl_axis(gr, ax1, ax2, opt) bind(C, name="mgl_axis") import :: c_int64_t,c_char integer(c_int64_t), value :: gr character(kind=c_char), dimension(*) :: ax1, ax2, opt end subroutine subroutine mgl_puts(gr, x, y, z, txt, font, size) bind(C, name="mgl_puts") import :: c_int64_t, c_double, c_int,c_char integer(c_int64_t), value :: gr real(c_double), value :: x, y, z character(kind=c_char), dimension(*) :: txt, font integer(c_int), value :: size end subroutine subroutine mgl_write_frame(gr, fname, opt) bind(C, name="mgl_write_frame") import :: c_int64_t,c_char integer(c_int64_t), value :: gr character(kind=c_char), dimension(*) :: fname, opt end subroutine subroutine mgl_delete_data(dat) bind(C, name="mgl_delete_data") import :: c_int64_t integer(c_int64_t), value :: dat end subroutine subroutine mgl_delete_graph(gr) bind(C, name="mgl_delete_graph") import :: c_int64_t integer(c_int64_t), value :: gr end subroutine end interface ! Veri seti oluştur dat = mgl_create_data_size(30, 40, 1) do i = 0, 29 do j = 0, 39 x = (i - 15.0) / 15.0 y = (j - 20.0) / 20.0 v = 1.0 / (1.0 + x*x*9 + y*y*4) call mgl_data_set_value(dat, v, i, j, 0) end do end do gr = mgl_create_graph(1800, 1200) call mgl_dens(gr, dat, "", "") call mgl_cont(gr, dat, "y", "") call mgl_box(gr) call mgl_axis(gr, "", "", "") call mgl_puts(gr, 1.0d0, 1.0d0, 1.2d0, "\i f = \dfrac{1}{1+(5x)^2+(5y)^2}", "", -1) call mgl_write_frame(gr, "mathgl_output.jpg", "") call mgl_delete_data(dat) call mgl_delete_graph(gr) end program mathgl_example






--------------------------------------------------------------------------


Alexey Balakin <mathgl....@gmail.com>, 24 Nis 2025 Per, 00:25 tarihinde şunu yazdı:
--
You received this message because you are subscribed to the Google Groups "MathGL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathgl+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mathgl/b1cbaaef-5d46-407a-af96-9a8917e1b158n%40googlegroups.com.
mathgl_output.jpg

Haydar AKDAĞ

unread,
Apr 24, 2025, 9:39:29 AMApr 24
to mat...@googlegroups.com
Hi, again 
I downloaded (mathgl-8.0.3-ucrt64) the GPL binaries for MS Visual Studio, 64-bit build, with all utilities and required DLLs in the bin folder. Why are there .a files in the lib folder instead of .lib files? Also, if this is correct, do I need to convert the .a files to .lib? Would the following command work for conversion: lib /MACHINE:X64 /DEF:C:\path\to\your\libmgl.a /OUT:C:\path\to\your\libmgl.lib?  
Best regards,
Haydar Akdağ
--------------------------------------------------------------------------


Haydar AKDAĞ <hhayda...@gmail.com>, 24 Nis 2025 Per, 10:30 tarihinde şunu yazdı:

mathgl....@gmail.com

unread,
Apr 24, 2025, 10:45:10 AMApr 24
to mat...@googlegroups.com
Hi,

чт, 24 апр. 2025 г. в 16:39, Haydar AKDAĞ <hhayda...@gmail.com>:
Hi, again 
I downloaded (mathgl-8.0.3-ucrt64) the GPL binaries for MS Visual Studio, 64-bit build, with all utilities and required DLLs in the bin folder. Why are there .a files in the lib folder instead of .lib files? Also, if this is correct, do I need to convert the .a files to .lib? Would the following command work for conversion: lib /MACHINE:X64 /DEF:C:\path\to\your\libmgl.a /OUT:C:\path\to\your\libmgl.lib?  
 
MinGW uses unix notation for file extensions, i.e. *.o for object files, *.a for library files, *.so for DLL files and so on. Since MinGW and VisualStudio (which prefer *.lib files, and etc) are binary incompatible for C/C++ code in general, then I provide binary files for 2 most common compilers under Windows: MinGW and VisualStudio. Also, I don't know the simple way to convert *.a to *.lib files. However *.dll files should be compatible for C-only and Fortran-only interface and for C++ classes from files mgl.h, data.h, datac.h.
 
Best regards,
Haydar Akdağ
--------------------------------------------------------------------------


Haydar AKDAĞ <hhayda...@gmail.com>, 24 Nis 2025 Per, 10:30 tarihinde şunu yazdı:
Hi, thank you for your response. 
First of all, I am not a professional, but which header files do I need to bind to Fortran in order to use Mathgl with ifx? 
The following program worked  

Generally you don't need header files for Fortran. Because most functions return "void", ie are subroutines in Fortran. The only exceptions are functions returning a pointer, which should be the integers (line "integer(8) :: dat, gr, mgl_create_data_size, mgl_create_graph"in my example, see https://mathgl.sourceforge.net/doc_en/C-interface.html ). At this, all C functions (except one with a variable list of arguments, ie ones having "..." in declarations) have the same C and Fortran interface.The only limitation is to use "double" (ie real-8) for real numbers. So, I manually specify this flag in the example.

Formally, the interface you wrote ask to link the C-function instead of Fortran ones, and this interface is not needed for compilers, which understand the AT&T standard: see https://gcc.gnu.org/onlinedocs/gfortran/Naming-conventions.htmlhttps://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html . The unix-like compilers (gcc, gfortran, clang, mingw) support it by default and no one needs such interfaces. The MS VisualFortran (and probably ifx) need special compiler flags to switch it on.

 
--
Kind regards,
Alexey Balakin
Reply all
Reply to author
Forward
0 new messages