Plot diagrams in C/C++[SOLVED]

Karaoulis Marios marios_hellas_23 at yahoo.gr
Tue Nov 22 21:58:23 EET 2005


Ena mini-HOWTO

Osoi grafoun kodika, kai KATA thn diarkeia ekteleshs 8eloun na blepoun kapoio 
diagramma, (osodhpote poluploko) mporoun na xrhsimopoihsoun kapoio apo ta 
interface tou gnuplot.

Gia C --> http://ndevilla.free.fr/gnuplot/
Gia C++-->http://jijo.cjb.net/code/cc++
Gia Fortran -->http://gnuplotfortran.sourceforge.net/

Ti xreiazetai.
A) Katebaste to antoistoixo interface gia thn glossa pou xrhsimopoieite
B) Ena PC pou na trexei gnuplot

Gia to logou tou alh8es
Gia glossa C

Mesa ston fakelo src tou axeiou pou katebhke yparxoun duo arxeia
gnuplot_i.h
gnuplot_i.c
Balte afta ta duo arxeia ston fakelo pou brhsketai o kodikas sas

Dhmiourgeiste ena arxeio me ton kodika sas px test.c

-----------------------------------------------------
#include <stdio.h>
#include <stdlib.h>

#include "gnuplot_i.h"


#define NPOINTS     50

int main(int argc, char *argv[]) 
{
    gnuplot_ctrl    *   h1,
                    *   h2   ;/*Edo dhmiourgoume duo grafhmata tou   
                               gnuplot kai to onomazoume h1 kai h2*/

/*Dhmiourgo 2 pinakes x kai y me 50 8eseis*/
    double              x[NPOINTS] ;
    double              y[NPOINTS] ;
    int                 i ;


	printf("*** Bazo dedomena stous duo pinakes\n");
    for (i=0 ; i<NPOINTS ; i++) {
        x[i] = (double)i ;
        y[i] = (double)i * (double)i ;
    }
    
    h1 = gnuplot_init() ;/*Aparaithto*/
    gnuplot_resetplot(h1) ;/*Aparaithto*/
    gnuplot_setstyle(h1, "lines") ;/*Edo dhlono ti stul 8a exei h           
                                    kampulh mou, px lines, points*/
    gnuplot_plot_xy(h1, x, y, NPOINTS, "Edo bazo ti keimeno na fainetai    
                                        sthn kampulh mou") ;
    sleep(5) ;/*Dhlose poso xrono 8eleis to grafhma na fainetai. Einai 
              se deuterolepta, dhladh 5*/

    

    /*Edo plottaro to sin(x)*/
    h2 = gnuplot_init() ;
    gnuplot_setstyle(h2, "points") ;/*Prosoxh allakse to lines me points   
                                      gia na deikso ta diafora stul*/
    gnuplot_plot_equation(h2, "sin(x)", "sine") ;
    sleep(5);

   gnuplot_close(h1) ;/*Kleise to grafhma*/
   gnuplot_close(h2) ;
   return 0 ;

}
------------------------------------------------------------------

kante compile px 
gcc *.c
kai trekse to




Anolaga eukolo einai kai gia fortan.
__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 




More information about the Linux-greek-users mailing list