Example of scanfile for reading ’named’ data.
MGL code:
subplot 1 1 0 '<_':title 'Save and scanfile sample' list a 1 -1 0 save 'This is test: 0 -> ',a(0),' q' 'test.txt' 'w' save 'This is test: 1 -> ',a(1),' q' 'test.txt' save 'This is test: 2 -> ',a(2),' q' 'test.txt' scanfile a 'test.txt' 'This is test: %g -> %g' ranges a(0) a(1):axis:plot a(0) a(1) 'o'
C++ code:
void smgl_scanfile(mglGraph *gr) { gr->SubPlot(1,1,0,"<_"); if(big!=3) gr->Title("Save and scanfile sample"); FILE *fp=fopen("test.txt","w"); fprintf(fp,"This is test: 0 -> 1 q\n"); fprintf(fp,"This is test: 1 -> -1 q\n"); fprintf(fp,"This is test: 2 -> 0 q\n"); fclose(fp); mglData a; a.ScanFile("test.txt","This is test: %g -> %g"); gr->SetRanges(a.SubData(0), a.SubData(1)); gr->Axis(); gr->Plot(a.SubData(0),a.SubData(1),"o"); }