/*! * \file octave/Test.cpp * \brief this file implements the Test MaterialLaw. * File generated by tfel version 0.1 * \author Helfer Thomas * \date 18 / 11 / 08 * Example for octave users */ #include #include #include #include #include #ifdef __cplusplus extern "C"{ #endif /* __cplusplus */ static double get_scalar_value(const octave_value& value,const int,const int){ return value.scalar_value(); } // end of get_scalar_value static double get_matrix_value(const octave_value& value,const int i,const int j){ return (value.matrix_value())(i,j); } // end of get_matrix_value static double Test_compute(const double T,const double p) { using namespace std; typedef double real; double f; f = T * p; return f; } // end of Test_compute DEFUN_DLD(Test,args,nargout, "this function implements the Test material law.\n" "* Example for octave users \n") { typedef double (*PtrGetFunction)(const octave_value&,const int,const int); PtrGetFunction getfunction[2]; int i,j; int row,col; bool areAllVarMatrices; bool areAllVarScalars; octave_value retval; if(args.length()!=2){ error("Test : 2 arguments and only 2 arguments required"); return retval; } areAllVarMatrices = true; areAllVarScalars = true; row=-1; col=-1; for(i=0;i!=2;++i){ if(args(i).is_real_scalar()){ areAllVarMatrices = false; getfunction[i] = &get_scalar_value; } else if(args(i).is_real_matrix()){ areAllVarScalars = false; getfunction[i] = &get_matrix_value; if(row==-1){ row = args(i).matrix_value().rows(); col = args(i).matrix_value().cols(); } else { if((row!=args(i).matrix_value().rows())|| (col!=args(i).matrix_value().cols())){ error("Test : all arguments shall have the same size"); return retval; } } } else { error("Test : arguments must be either a matrix or scalar"); return retval; } } if(areAllVarScalars){ retval = Test_compute(args(0).scalar_value(),args(1).scalar_value()); } else if(areAllVarMatrices){ Matrix xin0(args(0).matrix_value()); Matrix xin1(args(1).matrix_value()); Matrix xout(row,col); for(i=0;i!=row;++i){ for(j=0;j!=col;++j){ xout(i,j) = Test_compute(xin0(i,j),xin1(i,j)); } } retval = xout; } else { Matrix xout(row,col); for(i=0;i!=row;++i){ for(j=0;j!=col;++j){ xout(i,j) = Test_compute((*(getfunction[0]))(args(0),i,j), (*(getfunction[1]))(args(1),i,j)); } } retval = xout; } return retval; } // end of Test #ifdef __cplusplus } // end of extern "C" #endif /* __cplusplus */