ccmatrix1.cc

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

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