ccmatrix1.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include "ccmatrix.h"
00003 
00004 
00005 class SciError {};
00006 
00007 // CMatrix A(name,job);
00008 
00009 extern "C" {
00010 #include <stdio.h>
00011 #undef _PARAMS
00012 #include "stack-c.h"
00013 int send_scilab_job(char *,long int);
00014 void cc_test();
00015 
00016 }
00017 
00018 static char buf[256];
00019 
00020 CMatrix::CMatrix(char *name1,char *job)
00021 {
00022   sprintf(buf,"%s=%s;",name1,job);
00023   if ( send_scilab_job(buf,strlen(buf)) != 0) 
00024     throw SciError();
00025   else 
00026     {
00027       int lp;
00028       C2F(cmatptr)(name1, &m, &n, &lp,strlen(name1));
00029       v = stk(lp);
00030     }
00031   name = new char[strlen(name1)+1];
00032   strcpy(name,name1);
00033 }
00034 
00035 
00036 void CMatrix::scijob(char *jobname)
00037 {
00038   sprintf(buf,jobname,name);
00039   if ( send_scilab_job(buf,strlen(buf)) != 0) 
00040     throw SciError();
00041 }
00042 
00043 CMatrix& CMatrix::plus(CMatrix &B)
00044 {
00045   sprintf(buf,"%s=%s+%s",this->name,this->name,B.name);
00046   if ( send_scilab_job(buf,strlen(buf)) != 0) 
00047     throw SciError();
00048   int lp;
00049   C2F(cmatptr)(name, &m, &n, &lp,strlen(name));
00050   v = stk(lp);
00051   return *this;
00052 }
00053 
00054 void CMatrix::print()
00055 {
00056   fprintf(stdout,"Matrix %s=\n",name);
00057   scijob("disp(%s)");
00058 }
00059 
00060 void CMatrix::inv()
00061 {
00062   sprintf(buf,"%s=inv(%s)",name,name);
00063   if ( send_scilab_job(buf,strlen(buf)) != 0) 
00064     throw SciError();
00065   int lp;
00066   C2F(cmatptr)(name, &m, &n, &lp,strlen(name));
00067   v = stk(lp);
00068 }
00069 
00070 
00071 void cc_test() 
00072 {
00073   CMatrix A("a","ones(2,2)");
00074   CMatrix B("b","8");
00075   A.plus(B);
00076   A.scijob("disp(%s);");
00077   A.scijob("%s=rand(2,2)");
00078   A.print();
00079   A.inv();
00080   A.print();
00081 }
00082 
00083 
00084 
00085 

Generated on Sun Mar 4 15:03:45 2007 for Scilab [trunk] by  doxygen 1.5.1