manpagez: man pages & more
info mathgl
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.5 C/Fortran interface

The usage of pure C or Fortran or any similar interfaces (see section C interface) is practically identical to classes usage. But there are some differences. C functions must have argument HMGL (for graphics) and/or HMDT (for data arrays) which specifies the object for drawing or manipulating (changing). Fortran users may regard these variables as integer. So, firstly the user has to create this object by function mgl_create_*() and has to delete it after the using by function mgl_delete_*().

Also, all arguments of C function have to be defined. So there are several functions with practically identical names doing practically the same. But some of them have simplified interface for the quick plotting and some of them have access to all plotting parameters for manual tunning.

As an example of C function usage let me draw the plot from Plots for 2D data. The C code which does it is shown below:

    #include <mgl/mgl_c.h>
    int main()
        HMGL gr = mgl_create_graph_zb(600, 400);
        mgl_set_alpha(gr, true);
        mgl_set_light(gr, true);
        HMDT a = mgl_create_data_size(30,20,1);
        mgl_data_modify(a,"0.6*sin(2*pi*x)*sin(3*pi*y) + 0.4*cos(3*pi*(x*y))",0);

        mgl_subplot(gr, 2,2,0);
        mgl_rotate(gr, 40,60,0);
        mgl_box(gr, true);
        mgl_subplot(gr, 2,2,1);
        mgl_rotate(gr, 40,60,0);
        mgl_box(gr, true);
        mgl_subplot(gr, 2,2,2);
        mgl_rotate(gr, 40,60,0);
        mgl_box(gr, true);
        mgl_subplot(gr, 2,2,3);
        mgl_rotate(gr, 40,60,0);
        mgl_box(gr, true);

        /* don't forgot to save graphics */
        return 0;

Practically the same simple to create a window. For example let rewrite the code from for window creation (see section Using FLTK/Qt/GLUT window):

    int sample(HMGL gr, void *)
        return 0;
    int main(int argc,char **argv)
        mgl_create_graph_fltk(sample, "MathGL examples", NULL);
        return 0;

The Fortran code have some peculiarities. Exactly it not allow one to send arbitrary parameter (which was NULL in previous example) to function. This is limitation of Fortran language. So, the corresponding code will be NOT TESTED NOW!!!:

    program TEST
    integer x,f,func
        call mgl_create_graph_fltk(sample, 'MathGL examples');
        call mgl_fltk_run();
    end program TEST
    integer function sample(gr)
    integer*8 gr
        call mgl_rotate(gr,60,40,0);
        call mgl_box(gr,1);

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© 2000-2019
Individual documents may contain additional copyright information.