types::Function::ReturnValue sci_interp2d(types::typed_list &in, int _iRetCount, types::typed_list &out) { // input types::Double* pDblXp = NULL; types::Double* pDblYp = NULL; types::Double* pDblX = NULL; types::Double* pDblY = NULL; types::Double* pDblC = NULL; // output types::Double* pDblZp = NULL; types::Double* pDblDzpdx = NULL; types::Double* pDblDzpdy = NULL; types::Double* pDblD2zdx2p = NULL; types::Double* pDblD2zdxyp = NULL; types::Double* pDblD2zdy2p = NULL; int iType = 8; // default C0 int sizeOfX = 0; int sizeOfXp = 0; int sizeOfY = 0; int sizeOfC = 0; // *** check the minimal number of input args. *** if (in.size() < 5 || in.size() > 6) { Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "interp2d", 5, 6); return types::Function::Error; } // *** check number of output args according the methode. *** if (_iRetCount > 6) { Scierror(78, _("%s: Wrong number of output argument(s): %d to %d expected.\n"), "interp2d", 1, 6); return types::Function::Error; } // *** check type of input args and get it. *** // xp if (in[0]->isDouble() == false) { Scierror(999, _("%s: Wrong type for input argument #%d : A matrix expected.\n"), "interp2d", 1); return types::Function::Error; } pDblXp = in[0]->getAs<types::Double>(); sizeOfXp = pDblXp->getSize(); if (pDblXp->isComplex()) { Scierror(999, _("%s: Wrong type for argument #%d: Real matrix expected.\n"), "interp2d", 1); return types::Function::Error; } // yp if (in[1]->isDouble() == false) { Scierror(999, _("%s: Wrong type for input argument #%d : A matrix expected.\n"), "interp2d", 2); return types::Function::Error; } pDblYp = in[1]->getAs<types::Double>(); if (pDblXp->getRows() != pDblYp->getRows() || pDblXp->getCols() != pDblYp->getCols()) { Scierror(999, _("%s: Wrong size for input arguments #%d and #%d: Same size expected.\n"), "interp2d", 1, 2); return types::Function::Error; } if (pDblYp->isComplex()) { Scierror(999, _("%s: Wrong type for argument #%d: Real matrix expected.\n"), "interp2d", 2); return types::Function::Error; } // x if (in[2]->isDouble() == false) { Scierror(999, _("%s: Wrong type for input argument #%d : A matrix expected.\n"), "interp2d", 3); return types::Function::Error; } pDblX = in[2]->getAs<types::Double>(); sizeOfX = pDblX->getSize(); if (pDblX->getRows() != 1 || pDblX->getSize() < 2) { Scierror(999, _("%s: Wrong size for input arguments #%d: A row vector of size at least 2 expected.\n"), "interp2d", 3); return types::Function::Error; } if (pDblX->isComplex()) { Scierror(999, _("%s: Wrong type for argument #%d: Real matrix expected.\n"), "interp2d", 3); return types::Function::Error; } // y if (in[3]->isDouble() == false) { Scierror(999, _("%s: Wrong type for input argument #%d : A matrix expected.\n"), "interp2d", 4); return types::Function::Error; } pDblY = in[3]->getAs<types::Double>(); sizeOfY = pDblY->getSize(); if (pDblY->getRows() != 1 || pDblY->getSize() < 2) { Scierror(999, _("%s: Wrong size for input arguments #%d: A row vector of size at least 2 expected.\n"), "interp2d", 4); return types::Function::Error; } // c if (in[4]->isDouble() == false) { Scierror(999, _("%s: Wrong type for input argument #%d : A matrix expected.\n"), "interp2d", 5); return types::Function::Error; } pDblC = in[4]->getAs<types::Double>(); sizeOfC = 16 * (sizeOfX - 1) * (sizeOfY - 1); if (pDblC->getCols() != 1 || pDblC->getSize() != sizeOfC) { Scierror(999, _("%s: Wrong size for input arguments #%d: A colomn vector of size %d expected.\n"), "interp2d", 5, sizeOfC); return types::Function::Error; } // out mode if (in.size() == 6) { if (in[5]->isString() == false) { Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), "interp2d", 6); return types::Function::Error; } wchar_t* wcsType = in[5]->getAs<types::String>()->get(0); if (wcscmp(wcsType, L"C0") == 0) { iType = 8; } else if (wcscmp(wcsType, L"by_zero") == 0) { iType = 7; } else if (wcscmp(wcsType, L"natural") == 0) { iType = 1; } else if (wcscmp(wcsType, L"periodic") == 0) { iType = 3; } else if (wcscmp(wcsType, L"by_nan") == 0) { iType = 10; } else // undefined { Scierror(999, _("%s: Wrong values for input argument #%d : '%s' is a unknow '%s' type.\n"), "interp2d", 6, wcsType, "outmode"); return types::Function::Error; } } // *** Perform operation. *** pDblZp = new types::Double(pDblXp->getRows(), pDblXp->getCols()); if (_iRetCount == 1) { C2F(bicubicinterp)(pDblX->get(), pDblY->get(), pDblC->get(), &sizeOfX, &sizeOfY, pDblXp->get(), pDblYp->get(), pDblZp->get(), &sizeOfXp, &iType); } else // if(_iRetCount > 2) { pDblDzpdx = new types::Double(pDblXp->getRows(), pDblXp->getCols()); pDblDzpdy = new types::Double(pDblXp->getRows(), pDblXp->getCols()); if (_iRetCount == 3) { C2F(bicubicinterpwithgrad)(pDblX->get(), pDblY->get(), pDblC->get(), &sizeOfX, &sizeOfY, pDblXp->get(), pDblYp->get(), pDblZp->get(), pDblDzpdx->get(), pDblDzpdy->get(), &sizeOfXp, &iType); } else // == 6 { pDblD2zdx2p = new types::Double(pDblXp->getRows(), pDblXp->getCols()); pDblD2zdxyp = new types::Double(pDblXp->getRows(), pDblXp->getCols()); pDblD2zdy2p = new types::Double(pDblXp->getRows(), pDblXp->getCols()); C2F(bicubicinterpwithgradandhes)(pDblX->get(), pDblY->get(), pDblC->get(), &sizeOfX, &sizeOfY, pDblXp->get(), pDblYp->get(), pDblZp->get(), pDblDzpdx->get(), pDblDzpdy->get(), pDblD2zdx2p->get(), pDblD2zdxyp->get(), pDblD2zdy2p->get(), &sizeOfXp, &iType); } } // *** Return result in Scilab. *** switch (_iRetCount) { case 6 : out.insert(out.begin(), pDblD2zdy2p); case 5 : out.insert(out.begin(), pDblD2zdxyp); case 4 : out.insert(out.begin(), pDblD2zdx2p); case 3 : out.insert(out.begin(), pDblDzpdy); case 2 : out.insert(out.begin(), pDblDzpdx); default : break; } out.insert(out.begin(), pDblZp); return types::Function::OK; }
types::Function::ReturnValue sci_interp3d(types::typed_list &in, int _iRetCount, types::typed_list &out) { // input types::Double* pDblXYZ[3] = {NULL, NULL, NULL}; types::TList* pTList = NULL; types::Double* pDblX = NULL; types::Double* pDblY = NULL; types::Double* pDblZ = NULL; types::Double* pDblOrder = NULL; types::Double* pDblCoef = NULL; types::Double* pDblXyzminmax = NULL; // output types::Double* pDblFp = NULL; types::Double* pDblFpdx = NULL; types::Double* pDblFpdy = NULL; types::Double* pDblFpdz = NULL; int iType = 0; int order[3]; int sizeOfXp; // *** check the minimal number of input args. *** if ((in.size() < 4) || (5 < in.size())) { Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "interp3d", 4); return types::Function::Error; } // *** check number of output args according the methode. *** if (_iRetCount > 4) { Scierror(78, _("%s: Wrong number of output argument(s): %d to %d expected.\n"), "interp3d", 1, 4); return types::Function::Error; } // *** check type of input args and get it. *** // xp yp zp for (int i = 0; i < 3; i++) { if (in[i]->isDouble() == false) { Scierror(999, _("%s: Wrong type for input argument #%d : A matrix expected.\n"), "interp3d", i + 1); return types::Function::Error; } pDblXYZ[i] = in[i]->getAs<types::Double>(); if (pDblXYZ[0]->getRows() != pDblXYZ[i]->getRows() || pDblXYZ[0]->getCols() != pDblXYZ[i]->getCols()) { Scierror(999, _("%s: Wrong size for input argument #%d : Same size as argument %d expected.\n"), "interp3d", i + 1, 1); return types::Function::Error; } if (pDblXYZ[i]->isComplex()) { Scierror(999, _("%s: Wrong type for argument #%d: Real matrix expected.\n"), "interp3d", i + 1); return types::Function::Error; } } sizeOfXp = pDblXYZ[0]->getSize(); if (in[3]->isTList() == false) { Scierror(999, _("%s: Wrong type for input argument #%d : A tlist of type %s expected.\n"), "interp3d", 4, "tensbs3d"); } pTList = in[3]->getAs<types::TList>(); if (pTList->getTypeStr() != L"tensbs3d") { Scierror(999, _("%s: Wrong type for input argument #%d: A %s tlist expected.\n"), "interp3d", 4, "tensbs3d"); return types::Function::Error; } pDblX = pTList->getField(L"tx")->getAs<types::Double>(); pDblY = pTList->getField(L"ty")->getAs<types::Double>(); pDblZ = pTList->getField(L"tz")->getAs<types::Double>(); pDblOrder = pTList->getField(L"order")->getAs<types::Double>(); pDblCoef = pTList->getField(L"bcoef")->getAs<types::Double>(); pDblXyzminmax = pTList->getField(L"xyzminmax")->getAs<types::Double>(); if (in.size() == 5) { if (in[4]->isString() == false) { Scierror(999, _("%s: Wrong type for input argument #%d : string expected.\n"), "interp3d", 5); return types::Function::Error; } wchar_t* wcsType = in[4]->getAs<types::String>()->get(0); if (wcscmp(wcsType, L"C0") == 0) { iType = 8; } else if (wcscmp(wcsType, L"by_zero") == 0) { iType = 7; } else if (wcscmp(wcsType, L"periodic") == 0) { iType = 3; } else if (wcscmp(wcsType, L"by_nan") == 0) { iType = 10; } else // undefined { char* pstType = wide_string_to_UTF8(wcsType); Scierror(999, _("%s: Wrong values for input argument #%d : '%s' is an unknown '%s' type.\n"), "interp3d", 5, pstType, "outmode"); FREE(pstType); return types::Function::Error; } } else { //"C0" iType = 8; } // *** Perform operation. *** pDblFp = new types::Double(pDblXYZ[0]->getRows(), pDblXYZ[0]->getCols()); order[0] = static_cast<int>(pDblOrder->get(0)); order[1] = static_cast<int>(pDblOrder->get(1)); order[2] = static_cast<int>(pDblOrder->get(2)); int sizeOfX = pDblX->getRows() - order[0]; int sizeOfY = pDblY->getRows() - order[1]; int sizeOfZ = pDblZ->getRows() - order[2]; double* minmax = pDblXyzminmax->get(); int workSize = order[1] * order[2] + 3 * std::max(order[0], std::max(order[1], order[2])) + order[2]; double* work = new double[workSize]; if (_iRetCount == 1) { C2F(driverdb3val)(pDblXYZ[0]->get(), pDblXYZ[1]->get(), pDblXYZ[2]->get(), pDblFp->get(), &sizeOfXp, pDblX->get(), pDblY->get(), pDblZ->get(), &sizeOfX, &sizeOfY, &sizeOfZ, &order[0], &order[1], &order[2], pDblCoef->get(), work, &minmax[0], &minmax[1], &minmax[2], &minmax[3], &minmax[4], &minmax[5], &iType); } else // _iRetCount == 4 { pDblFpdx = new types::Double(pDblXYZ[0]->getRows(), pDblXYZ[0]->getCols()); pDblFpdy = new types::Double(pDblXYZ[0]->getRows(), pDblXYZ[0]->getCols()); pDblFpdz = new types::Double(pDblXYZ[0]->getRows(), pDblXYZ[0]->getCols()); C2F(driverdb3valwithgrad)(pDblXYZ[0]->get(), pDblXYZ[1]->get(), pDblXYZ[2]->get(), pDblFp->get(), pDblFpdx->get(), pDblFpdy->get(), pDblFpdz->get(), &sizeOfXp, pDblX->get(), pDblY->get(), pDblZ->get(), &sizeOfX, &sizeOfY, &sizeOfZ, &order[0], &order[1], &order[2], pDblCoef->get(), work, &minmax[0], &minmax[1], &minmax[2], &minmax[3], &minmax[4], &minmax[5], &iType); } delete[] work; // *** Return result in Scilab. *** switch (_iRetCount) { case 4 : out.insert(out.begin(), pDblFpdz); case 3 : out.insert(out.begin(), pDblFpdy); case 2 : out.insert(out.begin(), pDblFpdx); default : break; } out.insert(out.begin(), pDblFp); return types::Function::OK; }
types::Function::ReturnValue sci_rand(types::typed_list &in, int _iRetCount, types::typed_list &out) { types::Double* pOut = NULL; static int siRandType = 0; static int siRandSave = 0; static int iForceInit = 0; int iSizeIn = (int)in.size(); if (iSizeIn == 0 || iSizeIn == -1) { //rand or rand() double dblRand = getNextRandValue(siRandType, &siRandSave, 0); out.push_back(new types::Double(dblRand)); return types::Function::OK; } if (in[0]->isString()) { //rand("xxx") types::String* pS = in[0]->getAs<types::String>(); if (pS->getSize() != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), "rand", 1); return types::Function::Error; } wchar_t* pwstKey = pS->get(0); if (pwstKey[0] == g_pwstConfigInfo[0]) { //info if (iSizeIn > 1) { Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "rand", 1); return types::Function::Error; } if (siRandType == 0) { out.push_back(new types::String(g_pwstTypeUniform)); } else { out.push_back(new types::String(g_pwstTypeNormal)); } } else if (pwstKey[0] == g_pwstConfigSeed[0]) { //seed if (iSizeIn == 1) { //get out.push_back(new types::Double(siRandSave)); } else if (iSizeIn == 2) { if (in[1]->isDouble() == false || in[1]->getAs<types::Double>()->isScalar() == false) { Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), "rand", 2); return types::Function::Error; } siRandSave = (int)std::max(in[1]->getAs<types::Double>()->get(0), double(0)); iForceInit = 1; } else { Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "rand", 2); return types::Function::Error; } } else { siRandType = setRandType(pwstKey[0]); } } else { int iRandSave = siRandType; if (in[iSizeIn - 1]->isString()) { //uniform ou normal types::String* pS = in[iSizeIn - 1]->getAs<types::String>(); if (pS->getSize() != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), "rand", iSizeIn); return types::Function::Error; } //set randomize law iRandSave = siRandType; siRandType = setRandType(pS->get(0)[0]); iSizeIn--; } types::typed_list args; std::copy(in.begin(), in.begin() + iSizeIn, back_inserter(args)); int iDims = 0; int* piDims = NULL; bool alloc = false; bool ret = getDimsFromArguments(args, "rand", &iDims, &piDims, &alloc); if (ret == false) { switch (iDims) { case -1: Scierror(21, _("Invalid index.\n")); break; case 1: { //call overload return Overload::generateNameAndCall(L"rand", in, _iRetCount, out); } } return types::Function::Error; } //special case for complex unique complex argument bool complex = false; if (in.size() == 1 && in[0]->isGenericType()) { complex = in[0]->getAs<types::GenericType>()->isComplex(); } pOut = new types::Double(iDims, piDims, complex); if (alloc) { delete[] piDims; } double* pd = pOut->get(); for (int i = 0; i < pOut->getSize(); i++) { pd[i] = getNextRandValue(siRandType, &siRandSave, iForceInit); iForceInit = 0; } if (pOut->isComplex()) { double* pImg = pOut->getImg(); for (int i = 0; i < pOut->getSize(); i++) { pImg[i] = getNextRandValue(siRandType, &siRandSave, iForceInit); } } out.push_back(pOut); //retore previous law siRandType = iRandSave; } return types::Function::OK; }