// Rascal, the Advanced Scientific CALculator // Copyright (C) 2001, Sebastian Ritterbusch (Rascal@Ritterbusch.de) // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more detauls. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #include #include #include #include string gnuplot_output_file=""; string set_gnuplot_output_file(string b) { return gnuplot_output_file=b; } #ifdef WEB_VERSION int web_plot_no=0; #endif string gnuplot(const valuematrix & a) { #ifdef STANDALONE_VALUE return "plotting not supported in standalone version"; #else if(!cell(a,1).isSYMREC()) { return "Usage: plot(,,,)"; } symrec *f((symrec*)cell(a,1).asSYMREC()); char buffer[1024]; char buffer2[1024]; tmpnam(buffer); // I know that I mustn't use this function :) tmpnam(buffer2); // but the man-pages don't tell me how I can avoid it! // I need to know the file name! Help is appreciated! ofstream out(buffer); value xstart(-5.),xend(5.),xstep(1/32.); if(a.N>1 || a.M>1) xstart=cell(a,2)*1.; if(a.N>2 || a.M>2) xend=cell(a,3); if(a.N>3 || a.M>3) xstep=cell(a,4); int lines=1; for(value x=xstart;x<=xend;x=x+xstep) { out << output(x).asSTRING(); value y=evaluate(f,x); if(y.isMATRIX()) { valuematrix Y(y.asMATRIX()); int i1,i2; lines=0; for(i1=0;i1name << "\" with lines" << endl; else if(lines>1) { int i; out2 << "plot \"" << buffer << "\" title \"" << f->name << " 1\" with lines"; for(i=1;iname << " " << i+1 << "\" with lines"; } out2 << endl; } out2.close(); char buffer3[1024]; sprintf(buffer3,"gnuplot -persist %s",buffer2); system(buffer3); #ifdef WEB_VERSION cout << endl << "" << endl; #endif unlink(buffer); unlink(buffer2); return "ok"; #endif } string gnupplot(const valuematrix & a) { #ifdef STANDALONE_VALUE return "plotting not supported in standalone version"; #else if(!cell(a,1).isSYMREC()) { return "Usage: pplot(<2dfunction>,,,,,,,)"; } symrec *f((symrec*)cell(a,1).asSYMREC()); char buffer[1024]; char buffer2[1024]; tmpnam(buffer); // I know that I mustn't use this function :) tmpnam(buffer2); // but the man-pages don't tell me how I can avoid it! // I need to know the file name! Help is appreciated! ofstream out(buffer); value tstart(0),tend(1),tstep(1/128.); value minx,maxx,miny,maxy; int dosx=0,dosy=0; if(a.N>1 || a.M>1) tstart=cell(a,2)*1.; if(a.N>2 || a.M>2) tend=cell(a,3); if(a.N>3 || a.M>3) tstep=cell(a,4); if(a.N>4 || a.M>4) { dosx=1;minx=maxx=cell(a,5); } if(a.N>5 || a.M>5) { dosx=1;maxx=cell(a,6); } if(a.N>6 || a.M>6) { dosy=1;miny=maxy=cell(a,7); } if(a.N>7 || a.M>7) { dosy=1;maxy=cell(a,8); } int lines=1; for(value t=tstart;t<=tend;t=t+tstep) { // out << output(x).asSTRING(); value y=evaluate(f,t); if(y.isMATRIX()) { valuematrix Y(y.asMATRIX()); int i1,i2; lines=0; for(i1=0;i1name << "\" with lines" << endl; } else if(lines>2) { int i; out2 << "plot "; if(dosx) { out2 << "["<name << " 1\" with lines"; for(i=2;iname << " " << i/2+1 << "\" with lines"; } out2 << endl; } out2.close(); char buffer3[1024]; sprintf(buffer3,"gnuplot -persist %s",buffer2); system(buffer3); #ifdef WEB_VERSION cout << endl << "" << endl; #endif unlink(buffer); unlink(buffer2); return "ok"; #endif } string gnusplot(const valuematrix & a) { #ifdef STANDALONE_VALUE return "plotting not supported in standalone version"; #else if(!cell(a,1).isSYMREC()) { return "Usage: splot(,,,,,,)"; } symrec *f((symrec*)cell(a,1).asSYMREC()); char buffer[1024]; char buffer2[1024]; tmpnam(buffer); // I know that I mustn't use this function :) tmpnam(buffer2); // but the man-pages don't tell me how I can avoid it! // I need to know the file name! Help is appreciated! ofstream out(buffer); value xstart(-5.),xend(5.),xstep(1/4.); value ystart(-5.),yend(5.),ystep(1/4.); if(a.N>1 || a.M>1) xstart=cell(a,2)*1.; if(a.N>2 || a.M>2) xend=cell(a,3)*1.; if(a.N>3 || a.M>3) ystart=cell(a,4)*1.; if(a.N>4 || a.M>4) yend=cell(a,5)*1.; if(a.N>5 || a.M>5) xstep=cell(a,6); if(a.N>6 || a.M>6) ystep=cell(a,7); int lines=1; for(value x=xstart;x<=xend;x=x+xstep) { for(value y=ystart;y<=yend;y=y+ystep) { out << output(x).asSTRING() << "\t" << output(y).asSTRING(); valuematrix X(2,1); X(0,0)=x; X(1,0)=y; value z=evaluate_n(f,X); if(z.isMATRIX()) { valuematrix Z(z.asMATRIX()); int i1,i2; lines=0; for(i1=0;i1name << "\" with lines" << endl; else if(lines>1) { int i; out2 << "splot \"" << buffer << "\" title \"" << f->name << " 1\" with lines"; for(i=1;iname << " " << i+1 << "\" with lines"; } out2 << endl; } out2.close(); char buffer3[1024]; sprintf(buffer3,"gnuplot -persist %s",buffer2); system(buffer3); #ifdef WEB_VERSION cout << endl << "" << endl; #endif unlink(buffer); unlink(buffer2); return "ok"; #endif }