| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
9.7.11 Parser sample
C++ code
float a[100]; // let a_i = sin(4*pi*x), x=0...1
for(int i=0;i<100;i++) a[i]=sin(4*M_PI*i/99);
mglParse *parser = new mglParse;
mglData &d = (parser->AddVar("dat"))->d;
d.Set(a,100); // set data to variable
parser->Execute(gr, "plot dat; xrange 0 1\nbox\naxis");
// you may break script at any line do something
// and continue after that
parser->Execute(gr, "xlabel 'x'\nylabel 'y'\nbox");
// also you may use cycles or conditions in script
parser->Execute(gr, "for $0 -1 1 0.1\nline 0 0 -1 $0 'r'\nnext");
MGL code
NOT AVAILABLE
Pure C code
float a[100]; /* let a_i = sin(4*pi*x), x=0...1 */ int i; for(i=0;i<100;i++) a[i]=sin(4*M_PI*i/99); HMPR parser = mgl_create_parser(); HMDT d = mgl_add_var(parser, "dat"); mgl_data_set_float(d,a,100,1,1); /* set data to variable */ mgl_parse_text(gr, parser, "plot dat; xrange 0 1\nbox\naxis"); /* you may break script at any line do something and continue after that */ mgl_parse_text(gr, parser, "xlabel 'x'\nylabel 'y'"); /* also you may use cycles or conditions in script */ mgl_parse_text(gr, parser, "for $0 -1 1 0.1\nline 0 0 -1 $0 'r'\nnext");
Fortran code
integer i,parser,d, mgl_create_data_size, mgl_create_parser
real a(100)
! let a_i = sin(4*pi*x), x=0...1
do i = 1,100
a(i)=sin(4*3.1415926*(i-1)/99)
end do
parser = mgl_create_parser()
d = mgl_add_var(parser, "dat")
call mgl_data_set_real(d,a,100,1,1) ! set data to variable
! I don't know how put new line ('\n') into fortran string
! So call mgl_parse_text() for each string :(
call mgl_parse_text(gr, parser, "plot dat; xrange 0 1")
call mgl_parse_text(gr, parser, "box")
call mgl_parse_text(gr, parser, "axis")
! you may break script at any line do something
! and continue after that
call mgl_parse_text(gr, parser, "xlabel 'x'")
call mgl_parse_text(gr, parser, "ylabel 'y'")
! there is now conditions because I don't know
! how to send several string into parser at once :(
!! also you may use cycles or conditions in script
!call mgl_parse_text(gr, parser, "for $0 -1 1 0.1\nline 0 0 -1 $0 'r'\nnext")
Python
You may need to use from numpy import * for defining functions like sin().
parser = mglParse();
dat = parser.AddVar("dat");
dat.Create(100);
for i in range(100):
dat[i] = sin(4*pi*i/99);
parser.Execute(gr, "plot dat; xrange 0 1\nbox\naxis");
# you may break script at any line do something
# and continue after that
parser.Execute(gr, "xlabel 'x'\nylabel 'y'");
# also you may use cycles or conditions in script
parser.Execute(gr, "for $0 -1 1 0.1\nline 0 0 -1 $0 'r'\nnext");
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
