int sci_fann_create(char * fname) { int * pi_command_addr = NULL; int m_layers, n_layers, * pi_layers_addr = NULL; int * pi_conn_addr = NULL; char * Command = NULL; double * layers = NULL, conn = 0.0; unsigned int * ui_layers = NULL; int res, numLayers, i; struct fann * result_ann = NULL; SciErr _sciErr; if (Rhs<2) { Scierror(999,"%s usage: ann = %s(command,[layers ...])", fname, fname); return 0; } _sciErr = getVarAddressFromPosition(pvApiCtx, 1, &pi_command_addr); if (_sciErr.iErr) { printError(&_sciErr, 0); return 0; } getAllocatedSingleString(pvApiCtx, pi_command_addr, &Command); _sciErr = getVarAddressFromPosition(pvApiCtx, 2, &pi_layers_addr); if (_sciErr.iErr) { printError(&_sciErr, 0); return 0; } _sciErr = getMatrixOfDouble(pvApiCtx, pi_layers_addr, &m_layers, &n_layers, &layers); if ((n_layers != 1) & (m_layers !=1)) { Scierror(999,"%s: Layers must be a vector!",fname); return 0; } numLayers = m_layers * n_layers; ui_layers = (unsigned int *)MALLOC(numLayers*sizeof(unsigned int)); for(i=0; i<numLayers; i++) ui_layers[i] = layers[i]; if (strcmp(Command,"standard") == 0) { freeAllocatedSingleString(Command); // fann_create_standard_array Just like fann_create_standard, but with an array of layer sizes instead of individual parameters. result_ann = fann_create_standard_array(numLayers,ui_layers); FREE(ui_layers); if (result_ann==NULL) { Scierror(999,"%s: not able to create standard network\n",fname); return 0; } } if (strcmp(Command,"sparse") == 0) { freeAllocatedSingleString(Command); // fann_create_sparse_array Just like fann_create_sparse, but with an array of layer sizes instead of individual parameters. _sciErr = getVarAddressFromPosition(pvApiCtx, 3, &pi_conn_addr); if (_sciErr.iErr) { printError(&_sciErr, 0); return 0; } getScalarDouble(pvApiCtx, pi_conn_addr, &conn); result_ann = fann_create_sparse_array(conn,numLayers,ui_layers); FREE(ui_layers); if (result_ann==NULL) { Scierror(999,"%s: not able to create sparse network\n",fname); return 0; } } if (strcmp(Command,"shortcut") == 0) { freeAllocatedSingleString(Command); // fann_create_shortcut_array Just like fann_create_shortcut, but with an array of layer sizes instead of individual parameters. result_ann = fann_create_shortcut_array(numLayers,ui_layers); FREE(ui_layers); if (result_ann==NULL) { Scierror(999,"%s: not able to create shortcut network\n",fname); return 0; } } //Create the struct representing this ann in scilab res = createScilabFannStructFromCFannStruct(result_ann, Rhs + 1); if (res==-1) return 0; LhsVar(1) = Rhs + 1; return 0; }
/*--------------------------------------------------------------------------*/ int sci_dseupd(char *fname, void *pvApiCtx) { SciErr sciErr; int* piAddrpRVEC = NULL; int* pRVEC = NULL; int* piAddrpHOWMANY = NULL; char* pHOWMANY = NULL; int* piAddrpSELECT = NULL; int* pSELECT = NULL; int* piAddrpD = NULL; double* pD = NULL; int* piAddrpZ = NULL; double* pZ = NULL; int* piAddrpSIGMA = NULL; double* pSIGMA = NULL; int* piAddrpBMAT = NULL; char* pBMAT = NULL; int* piAddrpN = NULL; int* pN = NULL; int* piAddrpWHICH = NULL; char* pWHICH = NULL; int* piAddrpNEV = NULL; int* pNEV = NULL; int* piAddrpTOL = NULL; double* pTOL = NULL; int* piAddrpRESID = NULL; double* pRESID = NULL; int* piAddrpNCV = NULL; int* pNCV = NULL; int* piAddrpV = NULL; double* pV = NULL; int* piAddrpIPARAM = NULL; int* pIPARAM = NULL; int* piAddrpIPNTR = NULL; int* pIPNTR = NULL; int* piAddrpWORKD = NULL; double* pWORKD = NULL; int* piAddrpWORKL = NULL; double* pWORKL = NULL; int* piAddrpINFO = NULL; int* pINFO = NULL; int mRVEC, nRVEC; int mSELECT, nSELECT; int D, mD, nD; int Z, mZ, nZ; int mSIGMA, nSIGMA; int mN, nN; int mNEV, nNEV; int mTOL, nTOL; int RESID, mRESID, nRESID; int mNCV, nNCV; int V, mV, nV; int IPARAM, mIPARAM, nIPARAM; int IPNTR, mIPNTR, nIPNTR; int WORKD, mWORKD, nWORKD; int WORKL, mWORKL, nWORKL; int INFO, mINFO, nINFO; int minlhs = 1, minrhs = 19, maxlhs = 9, maxrhs = 19; int LDZ, LDV, LWORKL; int sizeWORKL = 0; /* [D,Z,RESID,V,IPARAM,IPNTR,WORKD,WORKL,INFO]=dseupd... (RVEC,HOWMANY,SELECT,D,Z,SIGMA,BMAT,N,WHICH,NEV,TOL,RESID,NCV,V,IPARAM,IPNTR,WORKD,WORKL,INFO) */ CheckInputArgument(pvApiCtx, minrhs, maxrhs); CheckOutputArgument(pvApiCtx, minlhs, maxlhs); /* VARIABLE = NUMBER */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrpRVEC); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpRVEC, &mRVEC, &nRVEC, &pRVEC); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrpSELECT); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 3. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpSELECT, &mSELECT, &nSELECT, &pSELECT); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrpD); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 4. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpD, &mD, &nD, &pD); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 4); return 1; } D = 4; sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddrpZ); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 5. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpZ, &mZ, &nZ, &pZ); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 5); return 1; } Z = 5; sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddrpSIGMA); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 6. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpSIGMA, &mSIGMA, &nSIGMA, &pSIGMA); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 6); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 8, &piAddrpN); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 8. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpN, &mN, &nN, &pN); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 8); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 10, &piAddrpNEV); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 10. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpNEV, &mNEV, &nNEV, &pNEV); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 10); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 11, &piAddrpTOL); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 11. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpTOL, &mTOL, &nTOL, &pTOL); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 11); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 12, &piAddrpRESID); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 12. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpRESID, &mRESID, &nRESID, &pRESID); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 12); return 1; } RESID = 12; sciErr = getVarAddressFromPosition(pvApiCtx, 13, &piAddrpNCV); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 13. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpNCV, &mNCV, &nNCV, &pNCV); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 13); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 14, &piAddrpV); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 14. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpV, &mV, &nV, &pV); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 14); return 1; } V = 14; sciErr = getVarAddressFromPosition(pvApiCtx, 15, &piAddrpIPARAM); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 15. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpIPARAM, &mIPARAM, &nIPARAM, &pIPARAM); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 15); return 1; } IPARAM = 15; sciErr = getVarAddressFromPosition(pvApiCtx, 16, &piAddrpIPNTR); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 16. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpIPNTR, &mIPNTR, &nIPNTR, &pIPNTR); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 16); return 1; } IPNTR = 16; sciErr = getVarAddressFromPosition(pvApiCtx, 17, &piAddrpWORKD); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 17. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpWORKD, &mWORKD, &nWORKD, &pWORKD); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 17); return 1; } WORKD = 17; sciErr = getVarAddressFromPosition(pvApiCtx, 18, &piAddrpWORKL); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 18. sciErr = getMatrixOfDouble(pvApiCtx, piAddrpWORKL, &mWORKL, &nWORKL, &pWORKL); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 18); return 1; } WORKL = 18; sciErr = getVarAddressFromPosition(pvApiCtx, 19, &piAddrpINFO); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 19. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpINFO, &mINFO, &nINFO, &pINFO); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 19); return 1; } INFO = 19; LWORKL = mWORKL * nWORKL; LDV = Max(1, pN[0]); LDZ = LDV; /* Check some sizes */ if (mIPARAM*nIPARAM != 11) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "IPARAM", 11); return 1; } if (mIPNTR*nIPNTR != 14) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "IPNTR", 14); return 1; } if (mRESID*nRESID != pN[0]) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "RESID", pN[0]); return 1; } if (mWORKD * nWORKD < 3 * pN[0]) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "WORKD", 3 * pN[0]); return 1; } if (mSELECT*nSELECT != pNCV[0]) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "SELECT", pNCV[0]); return 1; } if (mD*nD != (pNEV[0])) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "D", pNEV[0]); return 1; } if ((mZ != pN[0]) || (nZ != pNEV[0])) { Scierror(999, _("%s: Wrong size for input argument %s: A matrix of size %dx%d expected.\n"), fname, "Z", pN[0], pNEV[0]); return 1; } if ((mV != pN[0]) || (nV != pNCV[0])) { Scierror(999, _("%s: Wrong size for input argument %s: A matrix of size %dx%d expected.\n"), fname, "V", pN[0], pNCV[0]); return 1; } sizeWORKL = pNCV[0] * pNCV[0] + 8 * pNCV[0]; if ((mWORKL * nWORKL < sizeWORKL)) { Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "WORKL", sizeWORKL); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrpHOWMANY); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrpHOWMANY, &pHOWMANY)) { Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 2); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 7, &piAddrpBMAT); if (sciErr.iErr) { freeAllocatedSingleString(pHOWMANY); printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 7. if (getAllocatedSingleString(pvApiCtx, piAddrpBMAT, &pBMAT)) { freeAllocatedSingleString(pHOWMANY); Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 7); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 9, &piAddrpWHICH); if (sciErr.iErr) { freeAllocatedSingleString(pBMAT); freeAllocatedSingleString(pHOWMANY); printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 9. if (getAllocatedSingleString(pvApiCtx, piAddrpWHICH, &pWHICH)) { freeAllocatedSingleString(pBMAT); freeAllocatedSingleString(pHOWMANY); Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 9); return 1; } C2F(dseupd)(pRVEC, pHOWMANY, pSELECT, pD, pZ, &LDZ, pSIGMA, pBMAT, pN, pWHICH, pNEV, pTOL, pRESID, pNCV, pV, &LDV, pIPARAM, pIPNTR, pWORKD, pWORKL, &LWORKL, pINFO, 1L, 1L, 1L, 2L); freeAllocatedSingleString(pHOWMANY); freeAllocatedSingleString(pBMAT); if (pINFO[0] < 0) { Scierror(998, _("%s: internal error, info=%d.\n"), fname, *pINFO); return 0; } AssignOutputVariable(pvApiCtx, 1) = D; AssignOutputVariable(pvApiCtx, 2) = Z; AssignOutputVariable(pvApiCtx, 3) = RESID; AssignOutputVariable(pvApiCtx, 4) = V; AssignOutputVariable(pvApiCtx, 5) = IPARAM; AssignOutputVariable(pvApiCtx, 6) = IPNTR; AssignOutputVariable(pvApiCtx, 7) = WORKD; AssignOutputVariable(pvApiCtx, 8) = WORKL; AssignOutputVariable(pvApiCtx, 9) = INFO; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_messagebox(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddrmessageAdr = NULL; int* piAddrtitleAdr = NULL; int* piAddriconAdr = NULL; int* piAddrbuttonsTextAdr = NULL; int* piAddrmodalOptionAdr = NULL; double* buttonNumberAdr = NULL; int messageBoxID = 0; /* Used to read input arguments */ int nbRow = 0, nbCol = 0; int nbRowButtons = 0, nbColButtons = 0; int nbRowMessage = 0, nbColMessage = 0; char **buttonsTextAdr = 0; char **messageAdr = 0; char **titleAdr = 0; char **modalOptionAdr = 0; char **iconAdr = 0; /* Used to write output argument */ int buttonNumber = 0; CheckInputArgument(pvApiCtx, 1, 5); CheckOutputArgument(pvApiCtx, 0, 1); /* Message to be displayed */ if ((checkInputArgumentType(pvApiCtx, 1, sci_strings))) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrmessageAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 1. if (getAllocatedMatrixOfString(pvApiCtx, piAddrmessageAdr, &nbRowMessage, &nbColMessage, &messageAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 1); return 1; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1); return FALSE; } /* Title to be displayed */ if (nbInputArgument(pvApiCtx) >= 2) { if (checkInputArgumentType(pvApiCtx, 2, sci_strings)) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrtitleAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 2. if (getAllocatedMatrixOfString(pvApiCtx, piAddrtitleAdr, &nbRow, &nbCol, &titleAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2); return 1; } if (nbRow*nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2); return FALSE; } /* The title argument can be used to give the modal option */ if (isModalOption(titleAdr[0])) { modalOptionAdr = titleAdr; titleAdr = NULL; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2); return FALSE; } } /* Icon to be displayed */ if (nbInputArgument(pvApiCtx) >= 3) { if ((checkInputArgumentType(pvApiCtx, 3, sci_strings))) { sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddriconAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 3. if (getAllocatedMatrixOfString(pvApiCtx, piAddriconAdr, &nbRow, &nbCol, &iconAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 3); return 1; } if (nbRow*nbCol == 1) { /* The icon argument can be used to give the modal option or the buttons names */ if (isModalOption(iconAdr[0])) { modalOptionAdr = (char **)iconAdr; iconAdr = NULL; } else if (!isIconName(iconAdr[0])) { buttonsTextAdr = (char **)iconAdr; nbRowButtons = nbRow; nbColButtons = nbCol; iconAdr = NULL; } } else /* More than one string --> buttons names */ { buttonsTextAdr = (char **)iconAdr; nbRowButtons = nbRow; nbColButtons = nbCol; iconAdr = NULL; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A string or a string vector expected.\n"), fname, 3); return FALSE; } } /* Buttons names */ if (nbInputArgument(pvApiCtx) >= 4) { if ((checkInputArgumentType(pvApiCtx, 4, sci_strings))) { sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrbuttonsTextAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 4. if (getAllocatedMatrixOfString(pvApiCtx, piAddrbuttonsTextAdr, &nbRowButtons, &nbColButtons, &buttonsTextAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 4); return 1; } if (nbRow*nbCol == 1) { /* The buttons names argument can be used to give the modal option */ if (isModalOption(buttonsTextAdr[0])) { modalOptionAdr = buttonsTextAdr; buttonsTextAdr = NULL; } } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A string or a string vector expected.\n"), fname, 3); return FALSE; } } /* Modal option */ if (nbInputArgument(pvApiCtx) == 5) { if ((checkInputArgumentType(pvApiCtx, 5, sci_strings))) { sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddrmodalOptionAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 5. if (getAllocatedMatrixOfString(pvApiCtx, piAddrmodalOptionAdr, &nbRow, &nbCol, &modalOptionAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 5); return 1; } if (nbRow*nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 5); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 5); return FALSE; } } /* Create the Java Object */ messageBoxID = createMessageBox(); /* Message */ setMessageBoxMultiLineMessage(messageBoxID, messageAdr, nbColMessage * nbRowMessage); freeAllocatedMatrixOfString(nbRowMessage, nbColMessage, messageAdr); /* Title */ if (titleAdr != NULL) { setMessageBoxTitle(messageBoxID, titleAdr[0]); freeAllocatedMatrixOfString(nbRow, nbCol, titleAdr); } else { setMessageBoxTitle(messageBoxID, _("Scilab Message")); } /* Icon */ if (iconAdr != NULL) { setMessageBoxIcon(messageBoxID, iconAdr[0]); freeAllocatedMatrixOfString(nbRow, nbCol, iconAdr); } /* Buttons */ if (buttonsTextAdr != NULL) { setMessageBoxButtonsLabels(messageBoxID, buttonsTextAdr, nbColButtons * nbRowButtons); freeAllocatedMatrixOfString(nbRowButtons, nbColButtons, buttonsTextAdr); } /* Modal ? */ if (modalOptionAdr != NULL) { setMessageBoxModal(messageBoxID, !stricmp(modalOptionAdr[0], "modal")); freeAllocatedMatrixOfString(nbRow, nbCol, modalOptionAdr); } else { setMessageBoxModal(messageBoxID, FALSE); } /* Display it and wait for a user input */ messageBoxDisplayAndWait(messageBoxID); /* Return the index of the button selected */ if (nbOutputArgument(pvApiCtx) == 1) { /* Read the user answer */ buttonNumber = getMessageBoxSelectedButton(messageBoxID); nbRow = 1; nbCol = 1; sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &buttonNumberAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } buttonNumberAdr[0] = buttonNumber; AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; } else { AssignOutputVariable(pvApiCtx, 1) = 0; } ReturnArguments(pvApiCtx); return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_prod(char *fname, void* pvApiCtx) { SciErr sciErr; int iRows = 0; int iCols = 0; int*piAddr = NULL; double* pdblReal = NULL; double* pdblImg = NULL; int iRowsRet = 0; int iColsRet = 0; double* pdblRealRet = NULL; double* pdblImgRet = NULL; int iMode = 0; CheckRhs(1, 2); CheckLhs(1, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (Rhs == 2) { sciErr = getProcessMode(pvApiCtx, 2, piAddr, &iMode); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } } sciErr = getVarDimension(pvApiCtx, piAddr, &iRows, &iCols); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (iRows * iCols == 0) { double dblVal = 0; if (iMode == 0) { iRows = 1; iCols = 1; dblVal = 1; } else { iRows = 0; iCols = 0; } sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, 1, 1, &dblVal); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; } switch (iMode) { case BY_ROWS : iRowsRet = 1; iColsRet = iCols; break; case BY_COLS : iRowsRet = iRows; iColsRet = 1; break; default : //BY_ALL iRowsRet = 1; iColsRet = 1; break; } if (isVarComplex(pvApiCtx, piAddr)) { sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal, &pdblImg); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = allocComplexMatrixOfDouble(pvApiCtx, Rhs + 1, iRowsRet, iColsRet, &pdblRealRet, &pdblImgRet); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } vWDmProd(iMode, pdblReal, pdblImg, iRows, iRows, iCols, pdblRealRet, pdblImgRet, 1); } else { sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = allocMatrixOfDouble(pvApiCtx, Rhs + 1, iRowsRet, iColsRet, &pdblRealRet); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } vDmProd(iMode, pdblReal, iRows, iRows, iCols, pdblRealRet, 1); } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_mputl(char *fname, unsigned long fname_len) { SciErr sciErr; int *piAddressVarOne = NULL; int *piAddressVarTwo = NULL; char **pStVarOne = NULL; int *lenStVarOne = NULL; int mOne = 0, nOne = 0; int mnOne = 0; char *filename = NULL; int fileDescriptor = -1; BOOL bCloseFile = FALSE; int i = 0; int mputlErr = MPUTL_ERROR; if (Rhs != 2) { Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), fname, 2); return 0; } if (Lhs != 1) { Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), fname, 1); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if ( isDoubleType(pvApiCtx, piAddressVarTwo) ) { double dValue = 0.; if (!isScalar(pvApiCtx, piAddressVarTwo)) { Scierror(999, _("%s: Wrong size for input argument #%d: Integer expected.\n"), fname, 2); return 0; } if ( getScalarDouble(pvApiCtx, piAddressVarTwo, &dValue) == 0) { fileDescriptor = (int)dValue; } else { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else if ( isStringType(pvApiCtx, piAddressVarTwo) ) { if (!isScalar(pvApiCtx, piAddressVarTwo)) { Scierror(999, _("%s: Wrong size for input argument #%d: String expected.\n"), fname, 2); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarTwo, &filename) == 0) { #define WRITE_ONLY_TEXT_MODE "wt" int f_swap = 0; double res = 0.0; int ierr = 0; char *expandedFileName = expandPathVariable(filename); C2F(mopen)(&fileDescriptor, expandedFileName, WRITE_ONLY_TEXT_MODE, &f_swap, &res, &ierr); if (expandedFileName) { FREE(expandedFileName); expandedFileName = NULL; } switch (ierr) { case MOPEN_NO_ERROR: break; case MOPEN_NO_MORE_LOGICAL_UNIT: { freeAllocatedSingleString(filename); Scierror(66, _("%s: Too many files opened!\n"), fname); return 0; } break; case MOPEN_CAN_NOT_OPEN_FILE: { Scierror(999, _("%s: Cannot open file %s.\n"), fname, filename); freeAllocatedSingleString(filename); return 0; } break; case MOPEN_NO_MORE_MEMORY: { freeAllocatedSingleString(filename); Scierror(999, _("%s: No more memory.\n"), fname); return 0; } break; case MOPEN_INVALID_FILENAME: { if (filename) { Scierror(999, _("%s: invalid filename %s.\n"), fname, filename); } else { freeAllocatedSingleString(filename); Scierror(999, _("%s: invalid filename.\n"), fname); } return 0; } break; case MOPEN_INVALID_STATUS: default: { freeAllocatedSingleString(filename); Scierror(999, _("%s: invalid status.\n"), fname); return 0; } break; } bCloseFile = TRUE; freeAllocatedSingleString(filename); } else { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: a String or Integer expected.\n"), fname, 2); } sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (!isStringType(pvApiCtx, piAddressVarOne)) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1); return 0; } sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &mOne, &nOne, NULL, NULL); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if ( !((mOne == 1) || (nOne == 1)) ) { Scierror(999, _("%s: Wrong size for input argument #%d: A 1-by-n or m-by-1 array expected.\n"), fname, 1); return 0; } mnOne = mOne * nOne; lenStVarOne = (int*)MALLOC(sizeof(int) * mnOne); if (lenStVarOne == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &mOne, &nOne, lenStVarOne, NULL); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } pStVarOne = (char**) MALLOC(sizeof(char*) * mnOne); if (pStVarOne == NULL) { FREE(lenStVarOne); lenStVarOne = NULL; Scierror(999, _("%s: No more memory.\n"), fname); return 0; } for (i = 0; i < mnOne; i++) { pStVarOne[i] = (char*)MALLOC(sizeof(char) * (lenStVarOne[i] + 1)); if (pStVarOne[i] == NULL) { freeArrayOfString(pStVarOne, i); if (lenStVarOne) { FREE(lenStVarOne); lenStVarOne = NULL; } Scierror(999, _("%s: No more memory.\n"), fname); return 0; } } sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &mOne, &nOne, lenStVarOne, pStVarOne); if (lenStVarOne) { FREE(lenStVarOne); lenStVarOne = NULL; } if (sciErr.iErr) { freeArrayOfString(pStVarOne, mnOne); printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } mputlErr = mputl(fileDescriptor, pStVarOne, mnOne); freeArrayOfString(pStVarOne, mnOne); if (bCloseFile) { double dErrClose = 0.; C2F(mclose)(&fileDescriptor, &dErrClose); } switch (mputlErr) { case MPUTL_NO_ERROR: createScalarBoolean(pvApiCtx, Rhs + 1, TRUE); LhsVar(1) = Rhs + 1; PutLhsVar(); break; case MPUTL_INVALID_FILE_DESCRIPTOR: // commented for compatiblity // Scierror(999, _("%s: invalid file descriptor.\n"), fname); // break; case MPUTL_ERROR: case MPUTL_NO_WRITE_RIGHT: default: createScalarBoolean(pvApiCtx, Rhs + 1, FALSE); LhsVar(1) = Rhs + 1; PutLhsVar(); break; } return 0; }
/* ==================================================================== */ int sci_edf_set_patientname(char *fname) { SciErr sciErr; int m1 = 0, n1 = 0; int *piAddressVarOne = NULL; int* piLenVarOne = NULL; double *pdVarOne = NULL; int iType1 = 0; int m2 = 0, n2 = 0; int *piAddressVarTwo = NULL; int* piLenVarTwo = NULL; char **stringData = NULL; int iType2 = 0; int m_out = 0, n_out = 0; double *dOut = NULL; int i; int handle; /* --> result = csum(3,8) /* check that we have only 2 parameters input */ /* check that we have only 1 parameters output */ CheckInputArgument(pvApiCtx,2,2) ; CheckOutputArgument(pvApiCtx,1,1) ; /* get Address of inputs */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } /* check input type */ sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } if ( iType1 != sci_matrix ) { Scierror(999,"%s: Wrong type for input argument #%d: A integer expected.\n",fname,1); return 0; } sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } if ( iType2 != sci_strings ) { Scierror(999,"%s: Wrong type for input argument #%d: A string expected.\n",fname,2); return 0; } sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarOne,&m1,&n1,&pdVarOne); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } /* get string */ sciErr = getMatrixOfString(pvApiCtx, piAddressVarTwo,&m2, &n2, NULL, NULL); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } piLenVarTwo = (int*)malloc(sizeof(int) * m2 * n2); sciErr = getMatrixOfString(pvApiCtx, piAddressVarTwo, &m2, &n2, piLenVarTwo, NULL); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } stringData = (char**)malloc(sizeof(char*) * m2 * n2); for(i = 0 ; i < n2 * m2 ; i++) { stringData[i] = (char*)malloc(sizeof(char) * (piLenVarTwo[i] + 1));//+ 1 for null termination } sciErr = getMatrixOfString(pvApiCtx, piAddressVarTwo, &m2, &n2, piLenVarTwo, stringData); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } /* check size */ if ( (m1 != 1) || (n1 != 1) ) { Scierror(999,"%s: Wrong size for input argument #%d: A scalar expected.\n",fname,1); return 0; } if ( (m2 !=1) || (n2 !=1) ) { Scierror(999,"%s: Wrong size for input argument #%d: A single stringr expected.\n",fname,2); return 0; } /* call c function csum */ // csum(&pdVarOne[0],&pdVarTwo[0],&dOut); if ( edf_set_patientname(pdVarOne[0], stringData[0]) <0) { Scierror(999,"Could not write string\n"); return 0; } m_out = 1; n_out = 1; dOut = (double*)malloc(sizeof(double) * m_out*n_out); // CreateVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m_out, &n_out, &dout); dOut[0]=0; /* create result on stack */ createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m_out, n_out, dOut); free(dOut); AssignOutputVariable(pvApiCtx,1) = nbInputArgument(pvApiCtx) + 1; /* This function put on scilab stack, the lhs variable which are at the position lhs(i) on calling stack */ /* You need to add PutLhsVar here because WITHOUT_ADD_PUTLHSVAR was defined and equal to %t */ /* without this, you do not need to add PutLhsVar here */ ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_getcallbackobject(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddrpObjUID = NULL; int nbRow = 0; int nbCol = 0; char** pObjUID = NULL; unsigned long graphicHandle = 0; CheckInputArgument(pvApiCtx, 1, 1); CheckOutputArgument(pvApiCtx, 0, 1); if ((checkInputArgumentType(pvApiCtx, 1, sci_strings))) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrpObjUID); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 1. if (getAllocatedMatrixOfString(pvApiCtx, piAddrpObjUID, &nbRow, &nbCol, &pObjUID)) { Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 1); return 1; } if (nbCol != 1 || nbRow == 0) { Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1); return FALSE; } graphicHandle = getHandle(pObjUID[0]); freeAllocatedMatrixOfString(nbRow, nbCol, pObjUID); /* Create return variable */ if (graphicHandle == 0) /* Non-existing object --> return [] */ { double* stkAdr = NULL; nbRow = 0; nbCol = 0; sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &stkAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } } else /* Return the handle */ { long long* stkAdr = NULL; nbRow = 1; nbCol = 1; sciErr = allocMatrixOfHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &stkAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } *stkAdr = (long long)graphicHandle; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_scinotes(char * fname, void* pvApiCtx) { SciErr sciErr; CheckRhs(0, 3); CheckLhs(0, 1); if (Rhs == 0) { try { callSciNotesW(NULL, 0); } catch (GiwsException::JniCallMethodException exception) { Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str()); } catch (GiwsException::JniException exception) { Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str()); } } else { int m1 = 0, n1 = 0; int *piAddressVarOne = NULL; wchar_t **pStVarOne = NULL; int *lenStVarOne = NULL; int i = 0; int iType1 = 0; char *functionName = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (iType1 != sci_strings) { Scierror(999, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1); return 0; } /* get dimensions */ sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, NULL); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } lenStVarOne = (int *)MALLOC(sizeof(int) * (m1 * n1)); if (lenStVarOne == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } /* get lengths */ sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); FREE(lenStVarOne); return 0; } pStVarOne = (wchar_t **) MALLOC(sizeof(wchar_t *) * (m1 * n1)); if (pStVarOne == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); FREE(lenStVarOne); return 0; } for (i = 0; i < m1 * n1; i++) { pStVarOne[i] = (wchar_t *) MALLOC(sizeof(wchar_t) * (lenStVarOne[i] + 1)); if (pStVarOne[i] == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); for (; i >= 0; i--) { FREE(pStVarOne[i]); } FREE(pStVarOne); FREE(lenStVarOne); return 0; } } /* get strings */ sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } if (Rhs >= 2) //get line numbers { int *piAddressVarTwo = NULL; int m2 = 0, n2 = 0; double *pdblVarTwo = NULL; int iType2 = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } if (iType2 != sci_matrix && iType2 != sci_strings) { Scierror(999, _("%s: Wrong type for argument #%d: Real matrix or \'readonly\' expected.\n"), fname, 2); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } if (iType2 == sci_strings) { /* get dimensions */ wchar_t **pStVarTwo = NULL; int *lenStVarTwo = NULL; sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarTwo, &m2, &n2, lenStVarTwo, NULL); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } lenStVarTwo = (int *)MALLOC(sizeof(int) * m2 * n2); if (lenStVarTwo == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } /* get lengths */ sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarTwo, &m2, &n2, lenStVarTwo, pStVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); FREE(lenStVarTwo); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } pStVarTwo = (wchar_t **) MALLOC(sizeof(wchar_t *) * m2 * n2); if (pStVarTwo == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); FREE(lenStVarTwo); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } for (int i = 0; i < m2 * n2; i++) { pStVarTwo[i] = (wchar_t *) MALLOC(sizeof(wchar_t) * (lenStVarTwo[i] + 1)); if (pStVarTwo[i] == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); freeArrayOfWideString(pStVarTwo, i); FREE(lenStVarTwo); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } } /* get strings */ sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarTwo, &m2, &n2, lenStVarTwo, pStVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); FREE(pStVarTwo); FREE(lenStVarTwo); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } try { callSciNotesWWithOption(pStVarOne, pStVarTwo, m2 * n2, m1 * n1); } catch (GiwsException::JniCallMethodException exception) { Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str()); freeArrayOfWideString(pStVarTwo, m2 * n2); FREE(lenStVarTwo); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } catch (GiwsException::JniException exception) { Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str()); freeArrayOfWideString(pStVarTwo, m2 * n2); FREE(lenStVarTwo); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } freeArrayOfWideString(pStVarTwo, m2 * n2); FREE(lenStVarTwo); } else { if (isVarComplex(pvApiCtx, piAddressVarTwo) == 1) { Scierror(999, _("%s: Wrong type for argument #%d: Real matrix expected.\n"), fname, 2); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarTwo, &m2, &n2, &pdblVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } if (m2 * n2 != m1 * n1) { Scierror(999, _("%s: Wrong size for input arguments #%d and #%d: Same dimensions expected.\n"), fname, 1, 2); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } if (Rhs == 3) { int *piAddressVarThree = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3); return 0; } if (!isStringType(pvApiCtx, piAddressVarThree)) { Scierror(999, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 3); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } int ret = getAllocatedSingleString(pvApiCtx, piAddressVarThree, &functionName); if (ret) { Scierror(999, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 3); freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); return 0; } } try { callSciNotesWWithLineNumberAndFunction(pStVarOne, pdblVarTwo, functionName, m1 * n1); } catch (GiwsException::JniCallMethodException exception) { Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str()); } catch (GiwsException::JniException exception) { Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str()); } } } else { try { callSciNotesW(pStVarOne, m1 * n1); } catch (GiwsException::JniCallMethodException exception) { Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str()); } catch (GiwsException::JniException exception) { Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str()); } } freeArrayOfWideString(pStVarOne, m1 * n1); FREE(lenStVarOne); if (functionName) { freeAllocatedSingleString(functionName); } } LhsVar(1) = 0; PutLhsVar(); return 0; }
int sci_umfpack(char* fname, void* pvApiCtx) { SciErr sciErr; int mb = 0; int nb = 0; int i = 0; int num_A = 0; int num_b = 0; int mW = 0; int Case = 0; int stat = 0; SciSparse AA; CcsSparse A; int* piAddrA = NULL; int* piAddr2 = NULL; int* piAddrB = NULL; double* pdblBR = NULL; double* pdblBI = NULL; double* pdblXR = NULL; double* pdblXI = NULL; int iComplex = 0; int mA = 0; // rows int nA = 0; // cols int iNbItem = 0; int* piNbItemRow = NULL; int* piColPos = NULL; double* pdblSpReal = NULL; double* pdblSpImg = NULL; /* umfpack stuff */ double Info[UMFPACK_INFO]; double* Control = NULL; void* Symbolic = NULL; void* Numeric = NULL; int* Wi = NULL; double* W = NULL; char* pStr = NULL; int iType2 = 0; int iTypeA = 0; int iTypeB = 0; /* Check numbers of input/output arguments */ CheckInputArgument(pvApiCtx, 3, 3); CheckOutputArgument(pvApiCtx, 1, 1); /* First get arg #2 : a string of length 1 */ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getVarType(pvApiCtx, piAddr2, &iType2); if (sciErr.iErr || iType2 != sci_strings) { printError(&sciErr, 0); Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2); return 1; } getAllocatedSingleString(pvApiCtx, piAddr2, &pStr); /* select Case 1 or 2 depending (of the first char of) the string ... */ if (pStr[0] == '\\') // compare pStr[0] with '\' { Case = 1; num_A = 1; num_b = 3; } else if (pStr[0] == '/') { Case = 2; num_A = 3; num_b = 1; } else { Scierror(999, _("%s: Wrong input argument #%d: '%s' or '%s' expected.\n"), fname, 2, "\\", "/"); FREE(pStr); return 1; } FREE(pStr); /* get A */ sciErr = getVarAddressFromPosition(pvApiCtx, num_A, &piAddrA); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getVarType(pvApiCtx, piAddrA, &iTypeA); if (sciErr.iErr || iTypeA != sci_sparse) { printError(&sciErr, 0); Scierror(999, _("%s: Wrong type for input argument #%d: A sparse matrix expected.\n"), fname, 1); return 1; } if (isVarComplex(pvApiCtx, piAddrA)) { AA.it = 1; iComplex = 1; sciErr = getComplexSparseMatrix(pvApiCtx, piAddrA, &mA, &nA, &iNbItem, &piNbItemRow, &piColPos, &pdblSpReal, &pdblSpImg); } else { AA.it = 0; sciErr = getSparseMatrix(pvApiCtx, piAddrA, &mA, &nA, &iNbItem, &piNbItemRow, &piColPos, &pdblSpReal); } if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // fill struct sparse AA.m = mA; AA.n = nA; AA.nel = iNbItem; AA.mnel = piNbItemRow; AA.icol = piColPos; AA.R = pdblSpReal; AA.I = pdblSpImg; if ( mA != nA || mA < 1 ) { Scierror(999, _("%s: Wrong size for input argument #%d.\n"), fname, num_A); return 1; } /* get B*/ sciErr = getVarAddressFromPosition(pvApiCtx, num_b, &piAddrB); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getVarType(pvApiCtx, piAddrB, &iTypeB); if (sciErr.iErr || iTypeB != sci_matrix) { printError(&sciErr, 0); Scierror(999, _("%s: Wrong type for input argument #%d: A matrix expected.\n"), fname, 3); return 1; } if (isVarComplex(pvApiCtx, piAddrB)) { iComplex = 1; sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddrB, &mb, &nb, &pdblBR, &pdblBI); } else { sciErr = getMatrixOfDouble(pvApiCtx, piAddrB, &mb, &nb, &pdblBR); } if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if ( (Case == 1 && ( mb != mA || nb < 1 )) || (Case == 2 && ( nb != mA || mb < 1 )) ) { Scierror(999, _("%s: Wrong size for input argument #%d.\n"), fname, num_b); return 1; } SciSparseToCcsSparse(&AA, &A); /* allocate memory for the solution x */ if (iComplex) { sciErr = allocComplexMatrixOfDouble(pvApiCtx, 4, mb, nb, &pdblXR, &pdblXI); } else { sciErr = allocMatrixOfDouble(pvApiCtx, 4, mb, nb, &pdblXR); } if (sciErr.iErr) { freeCcsSparse(A); printError(&sciErr, 0); return 1; } /* allocate memory for umfpack_di_wsolve usage or umfpack_zi_wsolve usage*/ Wi = (int*)MALLOC(mA * sizeof(int)); if (A.it == 1) { mW = 10 * mA; } else { mW = 5 * mA; } W = (double*)MALLOC(mW * sizeof(double)); if (A.it == 1 && pdblBI == NULL) { int iSize = mb * nb * sizeof(double); pdblBI = (double*)MALLOC(iSize); memset(pdblBI, 0x00, iSize); } /* Now calling umfpack routines */ if (A.it == 1) { stat = umfpack_zi_symbolic(mA, nA, A.p, A.irow, A.R, A.I, &Symbolic, Control, Info); } else { stat = umfpack_di_symbolic(mA, nA, A.p, A.irow, A.R, &Symbolic, Control, Info); } if ( stat != UMFPACK_OK ) { freeCcsSparse(A); Scierror(999, _("%s: An error occurred: %s: %s\n"), fname, _("symbolic factorization"), UmfErrorMes(stat)); return 1; } if (A.it == 1) { stat = umfpack_zi_numeric(A.p, A.irow, A.R, A.I, Symbolic, &Numeric, Control, Info); } else { stat = umfpack_di_numeric(A.p, A.irow, A.R, Symbolic, &Numeric, Control, Info); } if (A.it == 1) { umfpack_zi_free_symbolic(&Symbolic); } else { umfpack_di_free_symbolic(&Symbolic); } if ( stat != UMFPACK_OK ) { if (A.it == 1) { umfpack_zi_free_numeric(&Numeric); } else { umfpack_di_free_numeric(&Numeric); } freeCcsSparse(A); Scierror(999, _("%s: An error occurred: %s: %s\n"), fname, _("numeric factorization"), UmfErrorMes(stat)); return 1; } if ( Case == 1 ) /* x = A\b <=> Ax = b */ { if (A.it == 0) { for ( i = 0 ; i < nb ; i++ ) { umfpack_di_wsolve(UMFPACK_A, A.p, A.irow, A.R, &pdblXR[i * mb], &pdblBR[i * mb], Numeric, Control, Info, Wi, W); } if (isVarComplex(pvApiCtx, piAddrB)) { for ( i = 0 ; i < nb ; i++ ) { umfpack_di_wsolve(UMFPACK_A, A.p, A.irow, A.R, &pdblXI[i * mb], &pdblBI[i * mb], Numeric, Control, Info, Wi, W); } } } else /* A.it == 1 */ { for ( i = 0 ; i < nb ; i++ ) { umfpack_zi_wsolve(UMFPACK_A, A.p, A.irow, A.R, A.I, &pdblXR[i * mb], &pdblXI[i * mb], &pdblBR[i * mb], &pdblBI[i * mb], Numeric, Control, Info, Wi, W); } } } else /* Case == 2, x = b/A <=> x A = b <=> A.'x.' = b.' */ { if (A.it == 0) { TransposeMatrix(pdblBR, mb, nb, pdblXR); /* put b in x (with transposition) */ for ( i = 0 ; i < mb ; i++ ) { umfpack_di_wsolve(UMFPACK_At, A.p, A.irow, A.R, &pdblBR[i * nb], &pdblXR[i * nb], Numeric, Control, Info, Wi, W); /* the solutions are in br */ } TransposeMatrix(pdblBR, nb, mb, pdblXR); /* put now br in xr with transposition */ if (isVarComplex(pvApiCtx, piAddrB)) { TransposeMatrix(pdblBI, mb, nb, pdblXI); /* put b in x (with transposition) */ for ( i = 0 ; i < mb ; i++ ) { umfpack_di_wsolve(UMFPACK_At, A.p, A.irow, A.R, &pdblBI[i * nb], &pdblXI[i * nb], Numeric, Control, Info, Wi, W); /* the solutions are in bi */ } TransposeMatrix(pdblBI, nb, mb, pdblXI); /* put now bi in xi with transposition */ } } else /* A.it==1 */ { TransposeMatrix(pdblBR, mb, nb, pdblXR); TransposeMatrix(pdblBI, mb, nb, pdblXI); for ( i = 0 ; i < mb ; i++ ) { umfpack_zi_wsolve(UMFPACK_Aat, A.p, A.irow, A.R, A.I, &pdblBR[i * nb], &pdblBI[i * nb], &pdblXR[i * nb], &pdblXI[i * nb], Numeric, Control, Info, Wi, W); } TransposeMatrix(pdblBR, nb, mb, pdblXR); TransposeMatrix(pdblBI, nb, mb, pdblXI); } } if (A.it == 1) { umfpack_zi_free_numeric(&Numeric); } else { umfpack_di_free_numeric(&Numeric); } if (piNbItemRow != NULL) { FREE(piNbItemRow); } if (piColPos != NULL) { FREE(piColPos); } if (pdblSpReal != NULL) { FREE(pdblSpReal); } if (pdblSpImg != NULL) { FREE(pdblSpImg); } FREE(W); FREE(Wi); freeCcsSparse(A); AssignOutputVariable(pvApiCtx, 1) = 4; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_xstring(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddrStr = NULL; int* piAddrl1 = NULL; double* l1 = NULL; int* piAddrl2 = NULL; double* l2 = NULL; int* piAddrl4 = NULL; double* l4 = NULL; int* piAddrl5 = NULL; double* l5 = NULL; double rect[4]; double x = 0., y = 0., angle = 0.0; int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0, m4 = 0, n4 = 0, m5 = 0, n5 = 0; char **Str = NULL; char **sendStr = NULL; int sendm3 = 0, sendn3 = 0; long hdlstr = 0; int nbElement = 0, i = 0; BOOL isboxed = FALSE; CheckInputArgument(pvApiCtx, 3, 5); sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrStr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 3. if (getAllocatedMatrixOfString(pvApiCtx, piAddrStr, &m3, &n3, &Str)) { Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 3); return 1; } if (m3 * n3 == 0) { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 1); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 2); return 1; } if (m1 * n1 == 1 || m2 * n2 == 1) { nbElement = m1 * n1 * m2 * n2; } else if (m1 * n1 == m2 * n2) { nbElement = m1 * n1; } else { Scierror(999, _("%s: Incompatible input arguments #%d and #%d: Same element number expected.\n"), fname, 1, 2); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } if (nbElement == 0) { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } if (nbInputArgument(pvApiCtx) >= 4) { sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrl4); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 4. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl4, &m4, &n4, &l4); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 4); return 1; } if (m4 * n4 != 1 && m4 * n4 != nbElement) { Scierror(999, _("%s: Wrong size for input argument #%d: %d or %d elements expected.\n"), fname, 4, 1, nbElement); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } } if (nbInputArgument(pvApiCtx) >= 5) { sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddrl5); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 5. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl5, &m5, &n5, &l5); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 5); return 1; } if (m5 * n5 != 1 && m5 * n5 != nbElement) { Scierror(999, _("%s: Wrong size for input argument #%d: %d or %d elements expected.\n"), fname, 5, 1, nbElement); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } } x = *l1; y = *l2; sendStr = Str; sendm3 = m3; sendn3 = n3; if (nbInputArgument(pvApiCtx) >= 4) { angle = DEG2RAD(*l4); } if (nbInputArgument(pvApiCtx) >= 5) { isboxed = (*l5 != 0); } getOrCreateDefaultSubwin(); if (nbElement == 1) { Objstring(sendStr, sendm3, sendn3, x, y, &angle, rect, TRUE, NULL, &hdlstr, 0, NULL, NULL, isboxed && (angle == 0), TRUE, FALSE, ALIGN_LEFT); } else { for (i = 0; i < nbElement; i++) { if (m1 * n1 == nbElement) { x = *((l1) + i); } if (m2 * n2 == nbElement) { y = *((l2) + i); } if (m3 * n3 == nbElement) { sendStr = Str + i; sendm3 = sendn3 = 1; } if (nbInputArgument(pvApiCtx) >= 4 && m4 * n4 == nbElement) { angle = DEG2RAD(*((l4) + i)); } if (nbInputArgument(pvApiCtx) >= 5 && m5 * n5 == nbElement) { isboxed = ((l5) != 0); } Objstring(sendStr, sendm3, sendn3, x, y, &angle, rect, TRUE, NULL, &hdlstr, 0, NULL, NULL, isboxed && (angle == 0), TRUE, FALSE, ALIGN_LEFT); } /* * If one of the string creation calls fails, * the compound build call will crash. * To be modified */ { char * o = ConstructCompoundSeq(nbElement); releaseGraphicObjectProperty(__GO_PARENT__, o, jni_string, 1); } } /* we must free Str memory */ freeArrayOfString(Str, m3 * n3); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_ClipBoard(char *fname, void* pvApiCtx) { SciErr sciErr; int* piAddr1 = NULL; int* piAddrl1 = NULL; int* piAddrStr = NULL; double* pdbll1 = NULL; int* pil1 = NULL; static int n1 = 0, m1 = 0; char* param1 = NULL; char* param2 = NULL; nbInputArgument(pvApiCtx) = Max(0, nbInputArgument(pvApiCtx)); CheckInputArgument(pvApiCtx, 0, 2); CheckOutputArgument(pvApiCtx, 0, 1); if ( getScilabMode() != SCILAB_NWNI ) { /*--------------------*/ /* clipboard("paste") */ /*--------------------*/ if (nbInputArgument(pvApiCtx) == 1) { if (checkInputArgumentType(pvApiCtx, 1, sci_strings)) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrl1, ¶m1)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1); return 1; } if ( ( strcmp(param1, "paste") == 0 ) || ( strcmp(param1, "pastespecial") == 0 ) ) { /* Use the Java clipboard (CallScilabBridge.java returns "" if clipboard could not be read) */ char *output = getClipboardContents(); m1 = (int)strlen(output); n1 = 1; if (createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, output)) { freeAllocatedSingleString(param1); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } /* TO DO a delete [] and not a FREE */ FREE(output); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; freeAllocatedSingleString(param1); ReturnArguments(pvApiCtx); return TRUE; } else { freeAllocatedSingleString(param1); Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 1, "paste", "pastespecial"); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return FALSE; } } else if (nbInputArgument(pvApiCtx) == 2) { if (checkInputArgumentType(pvApiCtx, 1, sci_strings)) { /* Get the first argument: should be "copy" or "do" */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrl1, ¶m1)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1); return 1; } if (( strcmp(param1, "do") != 0 ) && ( strcmp(param1, "copy") != 0 )) { freeAllocatedSingleString(param1); Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 1, "do", "copy"); return FALSE; } if (checkInputArgumentType(pvApiCtx, 2, sci_strings)) { /*-------------------------------------------*/ /* clipboard("do", {"paste","copy","empty"}) */ /*-------------------------------------------*/ /* @TODO : should be remplaced by an enum */ if ( strcmp(param1, "do") == 0 ) { freeAllocatedSingleString(param1); sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrl1, ¶m2)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } if ( strcmp(param2, "paste") == 0 ) { /* Call Java to do the job */ pasteClipboardIntoConsole(); } else if ( strcmp(param2, "copy") == 0 ) { /* Call Java to do the job */ copyConsoleSelection(); } else if ( strcmp(param2, "empty") == 0 ) { /* Call Java to do the job */ emptyClipboard(); } else { freeAllocatedSingleString(param2); Scierror(999, _("%s: Wrong value for input argument #%d: '%s', '%s' or '%s' expected.\n"), fname, 2, "copy", "paste", "empty"); return FALSE; } m1 = 0; n1 = 0; freeAllocatedSingleString(param2); sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &pdbll1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; } /*-------------------------*/ /* clipboard("copy", data) */ /*-------------------------*/ else if ( strcmp(param1, "copy") == 0 ) { char *TextToPutInClipboard = NULL; char **Str = NULL; int m2 = 0, n2 = 0; freeAllocatedSingleString(param1); sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrStr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 2. if (getAllocatedMatrixOfString(pvApiCtx, piAddrStr, &m2, &n2, &Str)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } if (m2 * n2 == 1) /* Single line copy */ { TextToPutInClipboard = Str[0]; /* Call Java to do the job */ setClipboardContents(TextToPutInClipboard); } else /* Multi-line copy */ { int i = 0, j = 0, l2 = 0; char *TextToSendInClipboard = NULL; int SizeofTextToSendInClipboard = 0; char **buffer = (char**)MALLOC( (m2 * n2) * sizeof(char *) ); if (buffer == NULL) { freeAllocatedMatrixOfString(m2, n2, Str); Scierror(999, _("%s: No more memory.\n"), fname); return FALSE; } for (i = 0; i < m2; i++) { for (j = 0; j < n2; j++) { SizeofTextToSendInClipboard = SizeofTextToSendInClipboard + (int)strlen(Str[j * m2 + i]) + (int)strlen("\n") + (int)strlen(" "); buffer[i * n2 + j] = os_strdup(Str[j * m2 + i]); } } TextToSendInClipboard = (char*)MALLOC( (SizeofTextToSendInClipboard) * sizeof(char) ); if (TextToSendInClipboard == NULL) { freeAllocatedMatrixOfString(m2, n2, Str); Scierror(999, _("%s: No more memory.\n"), fname); freeArrayOfString(buffer, m2 * n2); return FALSE; } strcpy(TextToSendInClipboard, ""); for (i = 0; i < m2; i++) { for (j = 0; j < n2; j++) { strcat(TextToSendInClipboard, buffer[l2++]); strcat(TextToSendInClipboard, " "); } if ( i != (m2 - 1) ) { strcat(TextToSendInClipboard, "\n"); } } /* Call Java to do the job */ setClipboardContents(TextToSendInClipboard); FREE(buffer); buffer = NULL; freeArrayOfString(buffer, m2 * n2); FREE(TextToSendInClipboard); TextToSendInClipboard = NULL; } freeAllocatedMatrixOfString(m2, n2, Str); m1 = 0; n1 = 0; sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &pdbll1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; } } else { freeAllocatedSingleString(param1); Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2); return FALSE; } } /*----------------------------------*/ /* clipboard(fignum, {"EMF","DIB"}) */ /*----------------------------------*/ else if (checkInputArgumentType(pvApiCtx, 1, sci_matrix)) { int num_win = -2; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr1, &m1, &n1, &pil1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } num_win = pil1[0]; if (m1 * n1 != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 1); return FALSE; } if (checkInputArgumentType(pvApiCtx, 2, sci_strings)) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrl1, ¶m2)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } if ( ( strcmp(param2, "EMF") == 0 ) || ( strcmp(param2, "DIB") == 0 ) ) { if (num_win >= 0) { /* Call Java */ if ( strcmp(param2, "EMF") == 0) { /* @TODO create EMF */ copyFigureToClipBoard(getFigureFromIndex(num_win)); } else { /* @TODO create DIB */ copyFigureToClipBoard(getFigureFromIndex(num_win)); } m1 = 0; n1 = 0; freeAllocatedSingleString(param2); sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &pdbll1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; } else { freeAllocatedSingleString(param2); Scierror(999, _("%s: Wrong value for input argument #%d: Must be >= %d expected.\n"), fname, 1, 0); return FALSE; } } else { freeAllocatedSingleString(param2); Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 2, "EMF", "DIB"); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: string or real expected.\n"), fname, 1); return FALSE; } } } else { Scierror(999, _("%s: Function not available in NWNI mode.\n"), fname); return FALSE; } return FALSE; }
/*--------------------------------------------------------------------------*/ int sci_stringbox(char * fname, unsigned long fname_len) { SciErr sciErr; int* piAddrstackPointer = NULL; long long* stackPointer = NULL; char** strStackPointer = NULL; double* pdblStackPointer = NULL; int type = -1; int *piType = &type; char* parentAxes = NULL; double* textCorners = NULL; int two = 2; int four = 4; double corners[4][2]; /* the four edges of the boundingRect */ /* The function should be called with stringbox(handle) */ CheckInputArgument(pvApiCtx, 1, 6); CheckOutputArgument(pvApiCtx, 0, 1); if (nbInputArgument(pvApiCtx) == 1) { int m; int n; /* A text handle should be specified */ char * pTextUID = NULL; if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles))) { Scierror(999, _("%s: Wrong type for input argument #%d: A 'Text' handle expected.\n"), fname, 1); return 0; } /* get the handle */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrstackPointer); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of handle at position 1. sciErr = getMatrixOfHandle(pvApiCtx, piAddrstackPointer, &m, &n, &stackPointer); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } if (m * n != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A 'Text' handle expected.\n"), fname, 1); return 0; } /* Get the handle and check that this is a text handle */ pTextUID = (char*)getObjectFromHandle((long int) * stackPointer); if (pTextUID == NULL) { Scierror(999, _("%s: The handle is not valid.\n"), fname); return 0; } getGraphicObjectProperty(pTextUID, __GO_TYPE__, jni_int, (void **)&piType); if (type != __GO_LABEL__ && type != __GO_TEXT__) { Scierror(999, _("%s: Wrong type for input argument #%d: A 'Text' handle expected.\n"), fname, 1); return 0; } getGraphicObjectProperty(pTextUID, __GO_PARENT_AXES__, jni_string, (void **)&parentAxes); updateTextBounds(pTextUID); /* * To do: performs a projection/unprojection to obtain the bounding box in object coordinates * but using a rotation matrix corresponding to the default rotation angles (view == 2d) */ getGraphicObjectProperty(pTextUID, __GO_CORNERS__, jni_double_vector, (void **)&textCorners); corners[1][0] = textCorners[0]; corners[1][1] = textCorners[1]; corners[0][0] = textCorners[3]; corners[0][1] = textCorners[4]; corners[3][0] = textCorners[6]; corners[3][1] = textCorners[7]; corners[2][0] = textCorners[9]; corners[2][1] = textCorners[10]; } else if (nbInputArgument(pvApiCtx) == 2) { Scierror(999, _("%s: Wrong number of input arguments: %d or %d to %d expected.\n"), fname, 1, 3, 6); return 0; } else { char * parentSubwinUID = (char*)getOrCreateDefaultSubwin(); char ** text = NULL; int textNbRow; int textNbCol; double xPos; double yPos; double angle = DEFAULT_ANGLE; int fontId; int *pfontId = &fontId; double fontSize; double *pfontSize = &fontSize; getGraphicObjectProperty(parentSubwinUID, __GO_FONT_STYLE__, jni_int, (void**)&pfontId); getGraphicObjectProperty(parentSubwinUID, __GO_FONT_SIZE__, jni_double, (void **)&pfontSize); /* Check that first argument is a string */ if ((!checkInputArgumentType(pvApiCtx, 1, sci_strings))) { Scierror(999, _("%s: Wrong type for input argument #%d: 2D array of strings expected.\n"), fname, 1); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrstackPointer); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 1. if (getAllocatedMatrixOfString(pvApiCtx, piAddrstackPointer, &textNbRow, &textNbCol, &strStackPointer)) { Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 1); return 1; } /* retrieve it */ text = strStackPointer; /* Second and third arguments should be scalars */ if (getScalarFromStack(2, fname, &xPos) < 0) { freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer); return 0; } if (getScalarFromStack(3, fname, &yPos) < 0) { freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer); return 0; } if (nbInputArgument(pvApiCtx) >= 4) { /* angle is defined */ if (getScalarFromStack(4, fname, &angle) < 0) { freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer); return 0; } } if (nbInputArgument(pvApiCtx) >= 5) { double fontIdD; /* font style is defined */ if (getScalarFromStack(5, fname, &fontIdD) < 0) { freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer); return 0; } fontId = (int) fontIdD; } if (nbInputArgument(pvApiCtx) >= 6) { /* font size is defined */ if (getScalarFromStack(6, fname, &fontSize) < 0) { freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer); return 0; } } /* compute the box */ getTextBoundingBox(text, textNbRow, textNbCol, xPos, yPos, angle, fontId, fontSize, corners); freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer); } /* copy everything into the lhs */ sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, two, four, &pdblStackPointer); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } pdblStackPointer[0] = corners[1][0]; pdblStackPointer[1] = corners[1][1]; pdblStackPointer[2] = corners[0][0]; pdblStackPointer[3] = corners[0][1]; pdblStackPointer[4] = corners[3][0]; pdblStackPointer[5] = corners[3][1]; pdblStackPointer[6] = corners[2][0]; pdblStackPointer[7] = corners[2][1]; AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int C2F(sci_errclear)(char *fname,unsigned long fname_len) { Rhs = Max(0,Rhs); CheckRhs(0,2); CheckLhs(1,1); if (Rhs == 1) { SciErr sciErr; int *piAddressVarOne = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isDoubleType(pvApiCtx, piAddressVarOne)) { double dValue = 0.; int iValue = 0; int iLastErrorValue = getInternalLastErrorValue(); if (!isScalar(pvApiCtx, piAddressVarOne)) { Scierror(999,_("%s: Wrong size for input argument #%d: A scalar expected.\n"), fname, 1); return 0; } getScalarDouble(pvApiCtx, piAddressVarOne, &dValue); iValue = (int)dValue; if ((double)iValue != dValue) { Scierror(999,_("%s: Wrong value for input argument #%d: An integer value expected.\n"), fname, 1); return 0; } if ((iValue == iLastErrorValue) || (iValue <= 0)) { /* clear fortran common error */ C2F(errgst).err2 = 0; /* clear last error buffer (C) */ clearInternalLastError(); } } else { Scierror(999,_("%s: Wrong type for input argument #%d: An integer value expected.\n"), fname, 1); return 0; } } else { /* clear fortran common error */ C2F(errgst).err2 = 0; /* clear last error buffer (C) */ clearInternalLastError(); } LhsVar(1) = 0; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_xgraduate(char *fname, void *pvApiCtx) { SciErr sciErr; int* piAddrl1 = NULL; double* l1 = NULL; int* piAddrl2 = NULL; double* l2 = NULL; double* lr = NULL; double xa = 0., xi = 0.; int m1 = 0, n1 = 0, m2 = 0, n2 = 0, i = 0; int kMinr = 0, kMaxr = 0, ar = 0, np1 = 0, np2 = 0, un = 1; CheckInputArgument(pvApiCtx, 2, 2); CheckOutputArgument(pvApiCtx, 2, 7); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } //CheckScalar if (m1 != 1 || n1 != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, 1); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2); return 1; } //CheckScalar if (m2 != 1 || n2 != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, 2); return 1; } C2F(graduate)((l1), (l2), &xi, &xa, &np1, &np2, &kMinr, &kMaxr, &ar); *l1 = xi; *l2 = xa; if (nbOutputArgument(pvApiCtx) >= 3) { sciErr = allocMatrixOfDouble(pvApiCtx, 3, un, un, &lr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } lr[0] = (double) np1; } if (nbOutputArgument(pvApiCtx) >= 4) { sciErr = allocMatrixOfDouble(pvApiCtx, 4, un, un, &lr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } lr[0] = (double) np2; } if (nbOutputArgument(pvApiCtx) >= 5) { sciErr = allocMatrixOfDouble(pvApiCtx, 5, un, un, &lr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } lr[0] = (double) kMinr; } if (nbOutputArgument(pvApiCtx) >= 6) { sciErr = allocMatrixOfDouble(pvApiCtx, 6, un, un, &lr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } lr[0] = (double) kMaxr; } if (nbOutputArgument(pvApiCtx) >= 7) { sciErr = allocMatrixOfDouble(pvApiCtx, 7, un, un, &lr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } lr[0] = (double) ar; } for (i = 1; i <= nbOutputArgument(pvApiCtx) ; i++) { AssignOutputVariable(pvApiCtx, i) = i; } ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_x_mdialog(char *fname, void* pvApiCtx) { SciErr sciErr; int* piAddrlabelsAdr = NULL; int* piAddrlineLabelsAdr = NULL; int* piAddrdefaultValuesAdr = NULL; int* piAddrcolumnLabelsAdr = NULL; double* emptyMatrixAdr = NULL; int nbRow = 0, nbCol = 0; int nbRowDefaultValues = 0, nbColDefaultValues = 0; int nbRowLineLabels = 0, nbColLineLabels = 0; int nbRowColumnLabels = 0, nbColColumnLabels = 0; int messageBoxID = 0; char **labelsAdr = NULL; char **lineLabelsAdr = NULL; char **columnLabelsAdr = NULL; char **defaultValuesAdr = NULL; int userValueSize = 0; char **userValue = NULL; CheckInputArgument(pvApiCtx, 3, 4); CheckOutputArgument(pvApiCtx, 0, 1); /* READ THE LABELS */ if ((checkInputArgumentType(pvApiCtx, 1, sci_strings))) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrlabelsAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 1. if (getAllocatedMatrixOfString(pvApiCtx, piAddrlabelsAdr, &nbRow, &nbCol, &labelsAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1); return 1; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 1); return FALSE; } /* Create the Java Object */ messageBoxID = createMessageBox(); /* Title is a default title */ setMessageBoxTitle(messageBoxID, _("Scilab Multiple Values Request")); /* Message */ setMessageBoxMultiLineMessage(messageBoxID, labelsAdr, nbCol * nbRow); freeAllocatedMatrixOfString(nbRow, nbCol, labelsAdr); /* READ THE LINE LABELS */ if (checkInputArgumentType(pvApiCtx, 2, sci_strings)) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrlineLabelsAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 2. if (getAllocatedMatrixOfString(pvApiCtx, piAddrlineLabelsAdr, &nbRowLineLabels, &nbColLineLabels, &lineLabelsAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } if (nbRowLineLabels != 1 && nbColLineLabels != 1) { freeAllocatedMatrixOfString(nbRowLineLabels, nbColLineLabels, lineLabelsAdr); Scierror(999, _("%s: Wrong size for input argument #%d: Vector of strings expected.\n"), fname, 2); return FALSE; } setMessageBoxLineLabels(messageBoxID, lineLabelsAdr, nbColLineLabels * nbRowLineLabels); freeAllocatedMatrixOfString(nbRowLineLabels, nbColLineLabels, lineLabelsAdr); } else { Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 2); return FALSE; } /* READ THE COLUMN LABELS or DEFAULT VALUES */ if (checkInputArgumentType(pvApiCtx, 3, sci_strings)) { if (nbInputArgument(pvApiCtx) == 3) { sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrdefaultValuesAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 3. if (getAllocatedMatrixOfString(pvApiCtx, piAddrdefaultValuesAdr, &nbRowDefaultValues, &nbColDefaultValues, &defaultValuesAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 3); return 1; } if ((nbRowDefaultValues != nbRowLineLabels) || (nbColDefaultValues != nbColLineLabels)) { freeAllocatedMatrixOfString(nbRowDefaultValues, nbColDefaultValues, defaultValuesAdr); Scierror(999, _("%s: Wrong size for input argument #%d: It must have same dimensions as argument #%d.\n"), fname, 3, 2); return FALSE; } setMessageBoxDefaultInput(messageBoxID, defaultValuesAdr, nbColDefaultValues * nbRowDefaultValues); freeAllocatedMatrixOfString(nbRowDefaultValues, nbColDefaultValues, defaultValuesAdr); } else { sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrcolumnLabelsAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 3. if (getAllocatedMatrixOfString(pvApiCtx, piAddrcolumnLabelsAdr, &nbRowColumnLabels, &nbColColumnLabels, &columnLabelsAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 3); return 1; } if (nbRowColumnLabels != 1 && nbColColumnLabels != 1) { freeAllocatedMatrixOfString(nbRowColumnLabels, nbColColumnLabels, columnLabelsAdr); Scierror(999, _("%s: Wrong size for input argument #%d: Vector of strings expected.\n"), fname, 3); return FALSE; } setMessageBoxColumnLabels(messageBoxID, columnLabelsAdr, nbColColumnLabels * nbRowColumnLabels); freeAllocatedMatrixOfString(nbRowColumnLabels, nbColColumnLabels, columnLabelsAdr); } } else { Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 3); return FALSE; } if (nbInputArgument(pvApiCtx) == 4) { /* READ DEFAULT VALUES */ if (checkInputArgumentType(pvApiCtx, 4, sci_strings)) { sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrdefaultValuesAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 4. // DO NOT FORGET TO RELEASE MEMORY via freeAllocatedMatrixOfString(nbRowDefaultValues, nbColDefaultValues, defaultValuesAdr). if (getAllocatedMatrixOfString(pvApiCtx, piAddrdefaultValuesAdr, &nbRowDefaultValues, &nbColDefaultValues, &defaultValuesAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 4); return 1; } if ((nbRowDefaultValues != nbRowLineLabels * nbColLineLabels) || (nbColDefaultValues != nbRowColumnLabels * nbColColumnLabels)) { Scierror(999, _("%s: Wrong size for input argument #%d: %d x %d matrix of strings expected.\n"), fname, 4, nbRowLineLabels * nbColLineLabels, nbRowColumnLabels * nbColColumnLabels); freeArrayOfString(defaultValuesAdr, nbColDefaultValues * nbRowDefaultValues); return FALSE; } setMessageBoxDefaultInput(messageBoxID, defaultValuesAdr, nbColDefaultValues * nbRowDefaultValues); freeArrayOfString(defaultValuesAdr, nbColDefaultValues * nbRowDefaultValues); } else { Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of strings expected.\n"), fname, 4); return FALSE; } } /* Display it and wait for a user input */ messageBoxDisplayAndWait(messageBoxID); /* Read the user answer */ userValueSize = getMessageBoxValueSize(messageBoxID); if (userValueSize == 0) { nbRow = 0; nbCol = 0; // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int emptyMatrixAdr". sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &emptyMatrixAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } } else { userValue = getMessageBoxValue(messageBoxID); nbCol = 1; nbRowDefaultValues = nbColLineLabels * nbRowLineLabels; nbColDefaultValues = 1; if (nbInputArgument(pvApiCtx) == 4) { nbColDefaultValues = nbColColumnLabels * nbRowColumnLabels; } createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRowDefaultValues, nbColDefaultValues, userValue); delete[] userValue; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_gsort(char *fname, unsigned long fname_len) { char iord[2]; char typex[10]; SciIntMat Im; int Type = 0; char **S = NULL; int m1 = 0, n1 = 0, l1 = 0; int m2 = 0, n2 = 0, l2 = 0; int m3 = 0, n3 = 0, l3 = 0; int ind_m1 = 0, ind_n1 = 0; int *indices = NULL; int iflag = 0; int i; iord[0] = DECREASE_COMMAND; iord[1] = '\0'; typex[0] = GLOBAL_SORT; typex[1] = '\0'; Rhs = Max(0, Rhs); CheckRhs(1, 3); CheckLhs(1, 2); if (Rhs >= 1) { Type = VarType(1); switch (Type) { case sci_strings: GetRhsVar(1, MATRIX_OF_STRING_DATATYPE, &m1, &n1, &S); break; case sci_matrix: { #define COMPLEX 1 int *header = NULL; int Cmplx = 0; header = (int *)GetData(1); Cmplx = header[3]; if (Cmplx == COMPLEX) { return gsort_complex(fname, typex, iord); } else { GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1); if ((m1 * n1) == 0) /* [] returns [] */ { int m = 0, n = 0, l = 0; CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &m, &n, &l); LhsVar(1) = Rhs + 1; if (Lhs == 2) { CreateVar(Rhs + 2, MATRIX_OF_DOUBLE_DATATYPE, &m, &n, &l); LhsVar(2) = Rhs + 2; } PutLhsVar(); return 0; } } } break; case sci_ints: GetRhsVar(1, MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE, &m1, &n1, &Im); break; case sci_sparse: default: OverLoad(1); return 0; break; } } if (Rhs == 3) { int* piAddr = NULL; char* pstData = NULL; SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &pstData)) { return 1; } if (strcmp(pstData, "i") && strcmp(pstData, "d")) { if (getWarningMode()) { sciprint(_("WARNING: %s\n"), _("This usage of the third argument of gsort is obsolete.")); sciprint(_("WARNING: %s\n"), _("It will no more be available in Scilab 6.")); sciprint(_("WARNING: %s\n"), _("Please use 'd' or 'i' instead.")); } } iord[0] = pstData[0]; freeAllocatedSingleString(pstData); } if (Rhs >= 2) { int* piAddr = NULL; char* pstData = NULL; SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &pstData)) { return 1; } if ((pstData[0] != ROW_SORT) && (pstData[0] != COLUMN_SORT) && (pstData[0] != GLOBAL_SORT) && (pstData[0] != LIST_SORT)) { Scierror(999, _("%s: Wrong value for input argument #%d: '%s', '%s', '%s', '%s' or '%s' expected.\n"), fname, 2, "r", "c", "g", "lr", "lc"); return 1; } if (strcmp(pstData, "c") && strcmp(pstData, "r") && strcmp(pstData, "g") && strcmp(pstData, "lc") && strcmp(pstData, "lr")) { if (getWarningMode()) { sciprint(_("WARNING: %s\n"), _("This usage of the second argument of gsort is obsolete.")); sciprint(_("WARNING: %s\n"), _("It will no more be available in Scilab 6.")); sciprint(_("WARNING: %s\n"), _("Please use 'r', 'c', 'g', 'lr' or 'lc' instead.")); } } strcpy(typex, pstData); freeAllocatedSingleString(pstData); } if (typex[0] == LIST_SORT) { if (typex[1] == ROW_SORT) { ind_m1 = m1; ind_n1 = 1; if (ind_m1 != 0) { indices = (int *)MALLOC(sizeof(int) * (ind_m1)); /* Only return in row */ } } else if (typex[1] == COLUMN_SORT) { ind_m1 = 1; ind_n1 = n1; if (ind_n1 != 0) { indices = (int *)MALLOC(sizeof(int) * (ind_n1)); /*Only return in col */ } } else { Scierror(999, _("%s: Wrong value for input argument #%d.\n"), fname, 2); return 0; } } else { ind_m1 = m1; ind_n1 = n1; if (ind_m1 * ind_n1 != 0) { indices = (int *)MALLOC(sizeof(int) * (ind_m1 * ind_n1)); /* return a matrix */ } } if (Lhs == 2) { iflag = 1; } else { iflag = 0; } switch (Type) { case sci_matrix: { if (m1 * n1 != 0) { int lr; double *matrix = stk(l1); double *tmp_matrix = NULL; /* next CreateVar and corresponding copy not needed if arg1 is not passed by reference */ if (!CreateVarNoCheck(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &lr)) { if (indices) { FREE(indices); indices = NULL; } return 0; } tmp_matrix = stk(lr); for (i = 0; i < m1 * n1; i++) { tmp_matrix[i] = matrix[i]; } C2F(gsortd) (tmp_matrix, indices, &iflag, &m1, &n1, typex, iord); LhsVar(1) = Rhs + 1; if (Lhs == 2) { if (!CreateVarFromPtrNoCheck(Rhs + 2, MATRIX_OF_INTEGER_DATATYPE, &ind_m1, &ind_n1, &indices)) { if (indices) { FREE(indices); indices = NULL; } return 0; } LhsVar(2) = Rhs + 2; } if (indices) { FREE(indices); indices = NULL; } PutLhsVar(); } } break; case sci_ints: { int lr; lr = Im.it; /* next CreateVar and corresponding copy not needed if arg1 is not passed by reference */ if (!CreateVarNoCheck(Rhs + 1, MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE, &m1, &n1, &lr)) { if (indices) { FREE(indices); indices = NULL; } return 0; } switch (Im.it) /* Type defined in stack-c.h */ { case I_CHAR: { char *matrix = Im.D; char *tmp_matrix = (char *)istk(lr); for (i = 0; i < m1 * n1; i++) { tmp_matrix[i] = matrix[i]; } C2F(gsortchar) (tmp_matrix, indices, &iflag, &m1, &n1, typex, iord); } break; case I_INT32: { int *matrix = Im.D; int *tmp_matrix = istk(lr); for (i = 0; i < m1 * n1; i++) { tmp_matrix[i] = matrix[i]; } C2F(gsortint) (tmp_matrix, indices, &iflag, &m1, &n1, typex, iord); } break; case I_UCHAR: { unsigned char *matrix = Im.D; unsigned char *tmp_matrix = (unsigned char *)istk(lr); for (i = 0; i < m1 * n1; i++) { tmp_matrix[i] = matrix[i]; } C2F(gsortuchar) (tmp_matrix, indices, &iflag, &m1, &n1, typex, iord); } break; case I_INT16: { short *matrix = Im.D; short *tmp_matrix = (short *)istk(lr); for (i = 0; i < m1 * n1; i++) { tmp_matrix[i] = matrix[i]; } C2F(gsortshort) (tmp_matrix, indices, &iflag, &m1, &n1, typex, iord); } break; case I_UINT16: { unsigned short *matrix = Im.D; unsigned short *tmp_matrix = (short *)istk(lr); for (i = 0; i < m1 * n1; i++) { tmp_matrix[i] = matrix[i]; } C2F(gsortushort) (tmp_matrix, indices, &iflag, &m1, &n1, typex, iord); } break; case I_UINT32: { unsigned int *matrix = Im.D; unsigned int *tmp_matrix = (unsigned int *)istk(lr); for (i = 0; i < m1 * n1; i++) { tmp_matrix[i] = matrix[i]; } C2F(gsortuint) (tmp_matrix, indices, &iflag, &m1, &n1, typex, iord); } break; default: if (indices) { FREE(indices); indices = NULL; } Scierror(999, _("%s: Wrong type for input argument #%d: Unknown type.\n"), fname, 1); return 0; } LhsVar(1) = Rhs + 1; if (Lhs == 2) { if (!CreateVarFromPtrNoCheck(Rhs + 2, MATRIX_OF_INTEGER_DATATYPE, &ind_m1, &ind_n1, &indices)) { if (indices) { FREE(indices); indices = NULL; } return 0; } LhsVar(2) = Rhs + 2; } if (indices) { FREE(indices); indices = NULL; } PutLhsVar(); } break; case sci_strings: { C2F(gsorts) (S, indices, &iflag, &m1, &n1, typex, iord); if (!CreateVarFromPtrNoCheck(Rhs + 1, MATRIX_OF_STRING_DATATYPE, &m1, &n1, S)) { if (indices) { FREE(indices); indices = NULL; } return 0; } LhsVar(1) = Rhs + 1; if (Lhs == 2) { if (!CreateVarFromPtrNoCheck(Rhs + 2, MATRIX_OF_INTEGER_DATATYPE, &ind_m1, &ind_n1, &indices)) { if (indices) { FREE(indices); indices = NULL; } return 0; } LhsVar(2) = Rhs + 2; } if (indices) { FREE(indices); indices = NULL; } freeArrayOfString(S, m1 * n1); PutLhsVar(); } break; default: if (indices) { FREE(indices); indices = NULL; } Scierror(999, _("%s: Wrong type for input argument #%d.\n"), fname, 1); return 0; break; } return 0; }
int hypermatExample(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddr = NULL; int iType = 0; int iRet = 0; CheckInputArgument(pvApiCtx, 1, 1); CheckOutputArgument(pvApiCtx, 0, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (isEmptyMatrix(pvApiCtx, piAddr)) { iRet = createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1); if (iRet) { return iRet; } AssignOutputVariable(pvApiCtx, 1) = 0; } else if (isHypermatType(pvApiCtx, piAddr)) { int * dims = NULL; int ndims; double* pdblReal = NULL; double* pdblImg = NULL; if (isHypermatComplex(pvApiCtx, piAddr)) { sciErr = getComplexHypermatOfDouble(pvApiCtx, piAddr, &dims, &ndims, &pdblReal, &pdblImg); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } sciErr = createComplexHypermatOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, pdblReal, pdblImg); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } } else { sciErr = getHypermatOfDouble(pvApiCtx, piAddr, &dims, &ndims, &pdblReal); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } sciErr = createHypermatOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dims, ndims, pdblReal); if (sciErr.iErr) { printError(&sciErr, 0); return sciErr.iErr; } } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; } return 0; }
/*--------------------------------------------------------------------------*/ int sci_plot3d(char * fname, void *pvApiCtx) { SciErr sciErr; static double ebox_def [6] = { 0, 1, 0, 1, 0, 1}; double *ebox = ebox_def; static int iflag_def[3] = {2, 2, 4}; int *iflag = iflag_def; double alpha_def = 35.0 , theta_def = 45.0; double *alpha = &alpha_def, *theta = &theta_def; int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0; int m3n = 0, n3n = 0, m3l = 0; int izcol = 0, isfac = 0; double *zcol = NULL; int mustFree = 0; static rhs_opts opts[] = { { -1, "alpha", -1, 0, 0, NULL}, { -1, "ebox", -1, 0, 0, NULL}, { -1, "flag", -1, 0, 0, NULL}, { -1, "leg", -1, 0, 0, NULL}, { -1, "theta", -1, 0, 0, NULL}, { -1, NULL, -1, 0, 0, NULL} }; char * legend = NULL; int* piAddr1 = NULL; int* piAddr2 = NULL; int* piAddr3 = NULL; int* piAddr31 = NULL; int* piAddr32 = NULL; double* l1 = NULL; double* l2 = NULL; double* l3 = NULL; double* l3n = NULL; /* ** This overload the function to call demo script ** the demo script is called %_<fname> */ if (nbInputArgument(pvApiCtx) <= 0) { sci_demo(fname, pvApiCtx); return 0; } if (nbInputArgument(pvApiCtx) == 2) { Scierror(77, _("%s: Wrong number of input argument(s).\n"), fname); return -1; } CheckInputArgument(pvApiCtx, 1, 8); if (getOptionals(pvApiCtx, fname, opts) == 0) { ReturnArguments(pvApiCtx); return 0; } if (nbInputArgument(pvApiCtx) != 1 && FirstOpt(pvApiCtx) < 4) { Scierror(999, _("%s: Misplaced optional argument: #%d must be at position %d.\n"), fname, 1, 4); return -1; } //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &m1, &n1, &l1); if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); printError(&sciErr, 0); return 1; } if (nbInputArgument(pvApiCtx) == 1) { int i; if (m1 * n1 == 0) { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } if (m1 == 1 || n1 == 1) { Scierror(999, _("%s: Wrong size for input argument #%d.\n"), fname, 1); return 1; } l3 = l1; m3 = m1; n3 = n1; m1 = 1; n1 = m3; m2 = 1; n2 = n3; l1 = (double *)MALLOC(sizeof(double) * n1); for (i = 0; i < n1; ++i) { l1[i] = i + 1; } l2 = (double *)MALLOC(sizeof(double) * n2); for (i = 0; i < n2; ++i) { l2[i] = i + 1; } mustFree = 1; } if (nbInputArgument(pvApiCtx) >= 3) { //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &m2, &n2, &l2); if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2); printError(&sciErr, 0); return 1; } if (m1 * n1 == 0) { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } /* third argument can be a matrix z or a list list(z,zcol) */ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } switch (getInputArgumentType(pvApiCtx, 3)) { case sci_matrix : //get variable address sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 3. sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &m3, &n3, &l3); if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); printError(&sciErr, 0); return 1; } izcol = 0; break; case sci_list : izcol = 1; /* z = list(z,colors) */ sciErr = getListItemNumber(pvApiCtx, piAddr3, &m3l); if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); printError(&sciErr, 0); return 1; } if (m3l != 2) { Scierror(999, _("%s: Wrong size for input argument #%d: List of size %d expected.\n"), fname, 2, m3l, 2); return 1; } sciErr = getListItemAddress(pvApiCtx, piAddr3, 1, &piAddr31); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getMatrixOfDouble(pvApiCtx, piAddr31, &m3, &n3, &l3); /* z */ if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); printError(&sciErr, 0); return 1; } sciErr = getListItemAddress(pvApiCtx, piAddr3, 2, &piAddr32); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getMatrixOfDouble(pvApiCtx, piAddr32, &m3n, &n3n, &l3n); /* z */ if (sciErr.iErr) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); printError(&sciErr, 0); return 1; } zcol = (l3n); if (m3n * n3n != n3 && m3n * n3n != m3 * n3) { Scierror(999, _("%s: Wrong size for input argument #%d: %d or %d expected.\n"), fname, 3, n3, m3 * n3); return 1; } /* * Added by E Segre 4/5/2000. In the case where zcol is a * matrix of the same size as z, we set izcol to 2. This * value is later transmitted to the C2F(fac3dg) routine, * which has been modified to do the interpolated shading * (see the file SCI/modules/graphics/src/c/Plo3d.c */ if (m3n * n3n == m3 * n3) { izcol = 2 ; } break; default : OverLoad(3); return 0; } } if (m1 * n1 == m3 * n3 && m1 * n1 == m2 * n2 && m1 * n1 != 1) { if (! (m1 == m2 && m2 == m3 && n1 == n2 && n2 == n3)) { Scierror(999, _("%s: Wrong value for input arguments #%d, #%d and #%d: Incompatible length.\n"), fname, 1, 2, 3); return 1; } } else { if (m2 * n2 != n3) { Scierror(999, _("%s: Wrong value for input arguments #%d and #%d: Incompatible length.\n"), fname, 2, 3); return 1; } if (m1 * n1 != m3) { Scierror(999, _("%s: Wrong value for input arguments #%d and #%d: Incompatible length.\n"), fname, 1, 3); return 1; } if (m1 * n1 <= 1 || m2 * n2 <= 1) { Scierror(999, _("%s: Wrong size for input arguments #%d and #%d: %s expected.\n"), fname, 2, 3, ">= 2"); return 1; } } if (m1 * n1 == 0 || m2 * n2 == 0 || m3 * n3 == 0) { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } iflag_def[1] = 8; GetOptionalDoubleArg(pvApiCtx, fname, 4, "theta", &theta, 1, opts); GetOptionalDoubleArg(pvApiCtx, fname, 5, "alpha", &alpha, 1, opts); GetLabels(pvApiCtx, fname, 6, opts, &legend); GetOptionalIntArg(pvApiCtx, fname, 7, "flag", &iflag, 3, opts); GetOptionalDoubleArg(pvApiCtx, fname, 8, "ebox", &ebox, 6, opts); getOrCreateDefaultSubwin(); /******************** 24/05/2002 ********************/ if (m1 * n1 == m3 * n3 && m1 * n1 == m2 * n2 && m1 * n1 != 1) /* NG beg */ { isfac = 1; } else { isfac = 0; } Objplot3d (fname, &isfac, &izcol, (l1), (l2), (l3), zcol, &m3, &n3, theta, alpha, legend, iflag, ebox, &m1, &n1, &m2, &n2, &m3, &n3, &m3n, &n3n); /*Adding F.Leray 12.03.04 and 19.03.04*/ if (mustFree) { FREE(l1); FREE(l2); } AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_fscanfMat(char *fname, void* pvApiCtx) { SciErr sciErr; int *piAddressVarOne = NULL; int m1 = 0, n1 = 0; int iType1 = 0; char *filename = NULL; char *expandedFilename = NULL; char *Format = NULL; char *separator = NULL; BOOL bIsDefaultSeparator = TRUE; fscanfMatResult *results = NULL; CheckRhs(1, 3); CheckLhs(1, 2); if (Rhs == 3) { int *piAddressVarThree = NULL; int m3 = 0, n3 = 0; int iType3 = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3); return 0; } if (isStringType(pvApiCtx, piAddressVarThree) == 0 || isScalar(pvApiCtx, piAddressVarThree) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 3); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarThree, &separator)) { freeVar(&filename, &expandedFilename, &Format, &separator); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } bIsDefaultSeparator = FALSE; } if (Rhs >= 2) { int *piAddressVarTwo = NULL; int m2 = 0, n2 = 0; int iType2 = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if (sciErr.iErr) { freeVar(&filename, &expandedFilename, &Format, &separator); printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2); if (sciErr.iErr) { freeVar(&filename, &expandedFilename, &Format, &separator); printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if (isStringType(pvApiCtx, piAddressVarTwo) == 0 || isScalar(pvApiCtx, piAddressVarTwo) == 0) { freeVar(&filename, &expandedFilename, &Format, &separator); Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarTwo, &Format)) { freeVar(&filename, &expandedFilename, &Format, &separator); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { Format = os_strdup(DEFAULT_FSCANFMAT_FORMAT); } sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if (sciErr.iErr) { freeVar(&filename, &expandedFilename, &Format, &separator); printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isStringType(pvApiCtx, piAddressVarOne) == 0 || isScalar(pvApiCtx, piAddressVarOne) == 0) { freeVar(&filename, &expandedFilename, &Format, &separator); Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &filename)) { freeVar(&filename, &expandedFilename, &Format, &separator); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } expandedFilename = expandPathVariable(filename); if (bIsDefaultSeparator) { #define NB_DEFAULT_SUPPORTED_SEPARATORS 2 /* bug 8148 */ /* default separator can be a space or a tabulation */ char *supportedSeparators[NB_DEFAULT_SUPPORTED_SEPARATORS] = {DEFAULT_FSCANFMAT_SEPARATOR, "\t"}; int i = 0; for (i = 0; i < NB_DEFAULT_SUPPORTED_SEPARATORS; i++) { results = fscanfMat(expandedFilename, Format, supportedSeparators[i]); if (results && results->err == FSCANFMAT_NO_ERROR) { break; } freeFscanfMatResult(results); } } else { results = fscanfMat(expandedFilename, Format, separator); } if (results == NULL) { freeVar(&filename, &expandedFilename, &Format, &separator); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } freeVar(NULL, &expandedFilename, &Format, &separator); switch (results->err) { case FSCANFMAT_NO_ERROR: { if ( (results->values) && (results->m > 0) && (results->n > 0)) { sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, results->m, results->n, results->values); if (sciErr.iErr) { FREE(filename); freeFscanfMatResult(results); printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { if (createEmptyMatrix(pvApiCtx, Rhs + 1)) { FREE(filename); freeFscanfMatResult(results); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } LhsVar(1) = Rhs + 1; if (Lhs == 2) { if (results->text) { sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, results->sizeText, 1, (char const * const*) results->text); if (sciErr.iErr) { FREE(filename); freeFscanfMatResult(results); printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { if (createSingleString(pvApiCtx, Rhs + 2, "")) { FREE(filename); freeFscanfMatResult(results); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } LhsVar(2) = Rhs + 2; } freeFscanfMatResult(results); FREE(filename); PutLhsVar(); return 0; } case FSCANFMAT_MOPEN_ERROR: { Scierror(999, _("%s: can not open file %s.\n"), fname, filename); FREE(filename); return 0; } case FSCANFMAT_READLINES_ERROR: { Scierror(999, _("%s: can not read file %s.\n"), fname, filename); FREE(filename); return 0; } case FSCANFMAT_FORMAT_ERROR: { Scierror(999, _("%s: Invalid format.\n"), fname); FREE(filename); return 0; } case FSCANFMAT_MEMORY_ALLOCATION: { Scierror(999, _("%s: Memory allocation error.\n"), fname); FREE(filename); return 0; } default: case FSCANFMAT_ERROR: { Scierror(999, _("%s: error.\n"), fname); FREE(filename); return 0; } } FREE(filename); freeFscanfMatResult(results); return 0; }
int sci_umf_lusolve(char* fname, unsigned long l) { SciErr sciErr; int mb = 0; int nb = 0; int it_flag = 0; int i = 0; int j = 0; int NoTranspose = 0; int NoRaffinement = 0; SciSparse AA; CcsSparse A; /* umfpack stuff */ double Info[UMFPACK_INFO]; // double *Info = (double *) NULL; double Control[UMFPACK_CONTROL]; void* Numeric = NULL; int lnz = 0, unz = 0, n = 0, n_col = 0, nz_udiag = 0, umf_flag = 0; int* Wi = NULL; int mW = 0; double *W = NULL; int iComplex = 0; int* piAddr1 = NULL; int* piAddr2 = NULL; int* piAddr3 = NULL; int* piAddr4 = NULL; double* pdblBR = NULL; double* pdblBI = NULL; double* pdblXR = NULL; double* pdblXI = NULL; int mA = 0; // rows int nA = 0; // cols int iNbItem = 0; int* piNbItemRow = NULL; int* piColPos = NULL; double* pdblSpReal = NULL; double* pdblSpImg = NULL; /* Check numbers of input/output arguments */ CheckInputArgument(pvApiCtx, 2, 4); CheckOutputArgument(pvApiCtx, 1, 1); /* First get arg #1 : the pointer to the LU factors */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getPointer(pvApiCtx, piAddr1, &Numeric); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } /* Check if this pointer is a valid ref to a umfpack LU numeric object */ if ( ! IsAdrInList(Numeric, ListNumeric, &it_flag) ) { Scierror(999, _("%s: Wrong value for input argument #%d: Must be a valid reference to (umf) LU factors.\n"), fname, 1); return 1; } /* get some parameters of the factorization (for some checking) */ if ( it_flag == 0 ) { umfpack_di_get_lunz(&lnz, &unz, &n, &n_col, &nz_udiag, Numeric); } else { iComplex = 1; umfpack_zi_get_lunz(&lnz, &unz, &n, &n_col, &nz_udiag, Numeric); } if ( n != n_col ) { Scierror(999, _("%s: An error occurred: %s.\n"), fname, _("This is not a factorization of a square matrix")); return 1; } if ( nz_udiag < n ) { Scierror(999, _("%s: An error occurred: %s.\n"), fname, _("This is a factorization of a singular matrix")); return 1; } /* Get now arg #2 : the vector b */ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isVarComplex(pvApiCtx, piAddr2)) { iComplex = 1; sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr2, &mb, &nb, &pdblBR, &pdblBI); } else { sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &mb, &nb, &pdblBR); } if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (mb != n || nb < 1) /* test if the right hand side is compatible */ { Scierror(999, _("%s: Wrong size for input argument #%d.\n"), fname, 2); return 1; } /* allocate memory for the solution x */ if (iComplex) { sciErr = allocComplexMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, mb, nb, &pdblXR, &pdblXI); } else { sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, mb, nb, &pdblXR); } if (sciErr.iErr) { printError(&sciErr, 0); return 1; } /* selection between the different options : * -- solving Ax=b or A'x=b (Note: we could add A.'x=b) * -- with or without raffinement */ if (nbInputArgument(pvApiCtx) == 2) { NoTranspose = 1; NoRaffinement = 1; } else /* 3 or 4 input arguments but the third must be a string */ { char* pStr = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } getAllocatedSingleString(pvApiCtx, piAddr3, &pStr); if (strcmp(pStr, "Ax=b") == 0) { NoTranspose = 1; } else if ( strcmp(pStr, "A'x=b") == 0 ) { NoTranspose = 0; } else { Scierror(999, _("%s: Wrong input argument #%d: '%s' or '%s' expected.\n"), fname, 3, "Ax=b", "A'x=b"); return 1; } if (nbInputArgument(pvApiCtx) == 4) { sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isVarComplex(pvApiCtx, piAddr4)) { AA.it = 1; sciErr = getComplexSparseMatrix(pvApiCtx, piAddr4, &mA, &nA, &iNbItem, &piNbItemRow, &piColPos, &pdblSpReal, &pdblSpImg); } else { AA.it = 0; sciErr = getSparseMatrix(pvApiCtx, piAddr4, &mA, &nA, &iNbItem, &piNbItemRow, &piColPos, &pdblSpReal); } if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // fill struct sparse AA.m = mA; AA.n = nA; AA.nel = iNbItem; AA.mnel = piNbItemRow; AA.icol = piColPos; AA.R = pdblSpReal; AA.I = pdblSpImg; /* some check... but we can't be sure that the matrix corresponds to the LU factors */ if ( mA != nA || mA != n || AA.it != it_flag ) { Scierror(999, _("%s: Wrong size for input argument #%d: %s.\n"), fname, 4, _("Matrix is not compatible with the given LU factors")); return 1; } NoRaffinement = 0; } else { NoRaffinement = 1; /* only 3 input var => no raffinement */ } } /* allocate memory for umfpack_di_wsolve usage or umfpack_zi_wsolve usage*/ Wi = (int*)MALLOC(n * sizeof(int)); if (it_flag == 1) { if (NoRaffinement) { mW = 4 * n; } else { mW = 10 * n; } } else { if (NoRaffinement) { mW = n; } else { mW = 5 * n; } } W = (double*)MALLOC(mW * sizeof(double)); if (NoRaffinement == 0) { SciSparseToCcsSparse(&AA, &A); } else { A.p = NULL; A.irow = NULL; A.R = NULL; A.I = NULL; } /* get the pointer for b */ if (it_flag == 1 && pdblBI == NULL) { int iSize = mb * nb * sizeof(double); pdblBI = (double*)MALLOC(iSize); memset(pdblBI, 0x00, iSize); } /* init Control */ if (it_flag == 0) { umfpack_di_defaults(Control); } else { umfpack_zi_defaults(Control); } if (NoRaffinement) { Control[UMFPACK_IRSTEP] = 0; } if (NoTranspose) { umf_flag = UMFPACK_A; } else { umf_flag = UMFPACK_At; } if (it_flag == 0) { for (j = 0; j < nb ; j++) { umfpack_di_wsolve(umf_flag, A.p, A.irow, A.R, &pdblXR[j * mb], &pdblBR[j * mb], Numeric, Control, Info, Wi, W); } if (iComplex == 1) { for (j = 0; j < nb ; j++) { umfpack_di_wsolve(umf_flag, A.p, A.irow, A.R, &pdblXI[j * mb], &pdblBI[j * mb], Numeric, Control, Info, Wi, W); } } } else { for (j = 0; j < nb ; j++) { umfpack_zi_wsolve(umf_flag, A.p, A.irow, A.R, A.I, &pdblXR[j * mb], &pdblXI[j * mb], &pdblBR[j * mb], &pdblBI[j * mb], Numeric, Control, Info, Wi, W); } } if (isVarComplex(pvApiCtx, piAddr2) == 0) { FREE(pdblBI); } freeCcsSparse(A); FREE(W); FREE(Wi); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; }
int sci_tbx_sum(char *fname, void* pvApiCtx) { SciErr sciErr; int *piAddressVarOne = NULL; double dVarOne = 0.0; int *piAddressVarTwo = NULL; double dVarTwo = 0.0; double dOut = 0.0; /* check that we have only 2 input arguments */ /* check that we have only 1 output argument */ CheckInputArgument(pvApiCtx, 2, 2); CheckOutputArgument(pvApiCtx, 1, 1); /* get Address of inputs */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } /* check input type */ if ( !isDoubleType(pvApiCtx, piAddressVarOne) ) { Scierror(999, "%s: Wrong type for input argument #%d: A scalar expected.\n", fname, 1); return 0; } if ( !isDoubleType(pvApiCtx, piAddressVarTwo) ) { Scierror(999, "%s: Wrong type for input argument #%d: A scalar expected.\n", fname, 2); return 0; } if ( getScalarDouble(pvApiCtx, piAddressVarOne, &dVarOne) ) { Scierror(999, "%s: Wrong size for input argument #%d: A scalar expected.\n", fname, 1); return 0; } if ( getScalarDouble(pvApiCtx, piAddressVarTwo, &dVarTwo) ) { Scierror(999, "%s: Wrong size for input argument #%d: A scalar expected.\n", fname, 2); return 0; } /* call c business function */ dOut = business_sum(dVarOne, dVarTwo); createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dOut); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; }
int sci_hdf5_load_v2(char *fn, int* pvApiCtx) { SciErr sciErr; int* piAddr = NULL; char* pstFilename = NULL; char* pstExpandedFilename = NULL; bool bImport = true; const int nbIn = nbInputArgument(pvApiCtx); int iSelectedVar = nbIn - 1; CheckInputArgumentAtLeast(pvApiCtx , 1); CheckOutputArgument(pvApiCtx, 1, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &pstFilename)) { if (pstFilename) { freeAllocatedSingleString(pstFilename); } Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname.data(), 2); return 1; } //open hdf5 file pstExpandedFilename = expandPathVariable(pstFilename); int iFile = openHDF5File(pstExpandedFilename, 0); if (iFile < 0) { Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), pstFilename); FREE(pstExpandedFilename); FREE(pstFilename); return 1; } FREE(pstExpandedFilename); FREE(pstFilename); //manage version information int iVersion = getSODFormatAttribute(iFile); if (iVersion != SOD_FILE_VERSION) { if (iVersion > SOD_FILE_VERSION) { //can't read file with version newer that me ! Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname.data(), SOD_FILE_VERSION, iVersion); return 1; } else { //call older import functions and exit or ... EXIT ! if (iVersion == 1 || iVersion == -1) { return sci_hdf5_load_v1(fn, pvApiCtx); } } } std::vector<wchar_t*> varList; if (iSelectedVar) { //selected variable char* pstVarName = NULL; for (int i = 0 ; i < iSelectedVar ; i++) { sciErr = getVarAddressFromPosition(pvApiCtx, i + 2, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &pstVarName)) { if (pstVarName) { freeAllocatedSingleString(pstVarName); } Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname.data(), i + 1); return 1; } if (import_variable(pvApiCtx, iFile, pstVarName) == false) { FREE(pstVarName); bImport = false; break; } varList.push_back(to_wide_string(pstVarName)); FREE(pstVarName); pstVarName = NULL; } } else { //all variables int iNbItem = 0; iNbItem = getVariableNames(iFile, NULL); if (iNbItem != 0) { char **pstVarNameList = (char **)MALLOC(sizeof(char *) * iNbItem); iNbItem = getVariableNames(iFile, pstVarNameList); //import all data for (int i = 0; i < iNbItem; i++) { if (import_variable(pvApiCtx, iFile, pstVarNameList[i]) == false) { bImport = false; break; } varList.push_back(to_wide_string(pstVarNameList[i])); } freeArrayOfString(pstVarNameList, iNbItem); } } //close the file closeHDF5File(iFile); if (bImport == true && varList.size() != 0) { createMatrixOfWideString(pvApiCtx, nbIn + 1, 1, static_cast<int>(varList.size()), varList.data()); } else { createEmptyMatrix(pvApiCtx, nbIn + 1); } for (auto & i : varList) { FREE(i); } AssignOutputVariable(pvApiCtx, 1) = nbIn + 1; ReturnArguments(pvApiCtx); // printf("End gateway !!!\n"); return 0; }
int sci_mpi_recv(char *fname, unsigned long fname_len) { SciErr sciErr; int iRet = 0; int *piBuffer = NULL; int iBufferSize = 0; int *piAddr1 = NULL; int *piAddr2 = NULL; double Tag = 0; double Rank = 0; MPI_Status status; CheckInputArgument(pvApiCtx, 2, 2); CheckOutputArgument(pvApiCtx, 1, 1); //Rank sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (getScalarDouble(pvApiCtx, piAddr1, &Rank)) { Scierror(999, _("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 1); return 0; } //Tag sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if (getScalarDouble(pvApiCtx, piAddr2, &Tag)) { Scierror(999, _("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 2); return 0; } //wait message "Rank" node iRet = MPI_Probe((int)Rank, (int)Tag, MPI_COMM_WORLD, &status); if (iRet != MPI_SUCCESS) { char error_string[MPI_MAX_ERROR_STRING]; int length_of_error_string; MPI_Error_string(iRet, error_string, &length_of_error_string); Scierror(999, _("%s: MPI_Probe failed. Rank %d / Tag %d: %s\n"), fname, Rank, Tag, error_string); return 0; } //get data size iRet = MPI_Get_count(&status, MPI_INT, &iBufferSize); if (iRet != MPI_SUCCESS) { char error_string[MPI_MAX_ERROR_STRING]; int length_of_error_string; MPI_Error_string(iRet, error_string, &length_of_error_string); Scierror(999, _("%s: MPI_Get_count failed. Rank %d / Tag %d: %s\n"), fname, Rank, Tag, error_string); return 0; } //alloc memory to receive data piBuffer = (int *)MALLOC(sizeof(int) * iBufferSize); if (piBuffer == NULL) { Scierror(999, _("%s: Could not create the received variable.\n"), fname); return 0; } //receive data iRet = MPI_Recv(piBuffer, iBufferSize, MPI_INT, (int)Rank, (int)Tag, MPI_COMM_WORLD, &status); if (iRet != MPI_SUCCESS) { char error_string[MPI_MAX_ERROR_STRING]; int length_of_error_string; MPI_Error_string(iRet, error_string, &length_of_error_string); Scierror(999, _("%s: MPI_Recv failed. Rank %d / Tag %d: %s\n"), fname, Rank, Tag, error_string); return 0; } //convert data from MPI to Scilab iRet = deserialize_from_mpi(pvApiCtx, piBuffer, iBufferSize); FREE(piBuffer); if (iRet) { Scierror(999, _("%s: Unable to deserialize data !\n"), fname); return 0; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_legendre(char *fname, void* pvApiCtx) { /* * Interface onto the (Slatec) dxleg.f code. * Scilab syntax: * * p = legendre(n, m, x [, norm_flag] ) * * x is a vector with mnx elements (it is better to * have a row vector but this is not forced) * * n : a non negative int scalar (or a vector of such * int regularly speced with an increment of 1) * m : same constraints than for n * * n and m may not be both vectors * * norm_flag : optional. When it is present and equal to "norm" * it is a normalized version which is computed * AUTHOR * Bruno Pincon <*****@*****.**> */ int it = 0, lc = 0, mM = 0, nM = 0, m1 = 0, m2 = 0, mN = 0, nN = 0; int n1 = 0, n2 = 0, mx = 0, nx = 0, mnx = 0, ms = 0, ns = 0; int M_is_scalar = 0, N_is_scalar = 0, normalized = 0, MNp1 = 0, *ipqa = NULL; double xx = 0., dnu1 = 0.; int id = 0, ierror = 0, i = 0, j = 0, nudiff = 0; SciErr sciErr; int* piAddr1 = NULL; int* piAddr2 = NULL; int* piAddr3 = NULL; int* piAddr4 = NULL; int nbInputArg = nbInputArgument(pvApiCtx); double* pdblN = NULL; double* pdblM = NULL; double* pdblX = NULL; double* pdblPQA = NULL; int* piPQA = NULL; int iType1 = 0; int iType2 = 0; int iType3 = 0; CheckInputArgument(pvApiCtx, 3, 4); CheckOutputArgument(pvApiCtx, 1, 1); /* get N */ //get variable address of the input argument sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getVarType(pvApiCtx, piAddr1, &iType1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (iType1 != sci_matrix) { Scierror(999, _("%s: Wrong type for input argument #%d: Integer or vector of integers expected.\n"), fname, 1); return 1; } sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &mN, &nN, &pdblN); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (verify_cstr(pdblN, mN * nN, &n1, &n2) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: Integer >= %d expected.\n"), fname, 1, 0); return 1; } if ( mN == 1 && nN == 1) { N_is_scalar = 1; } /* get M */ //get variable address of the input argument sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getVarType(pvApiCtx, piAddr2, &iType2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (iType2 != sci_matrix) { Scierror(999, _("%s: Wrong type for input argument #%d: Integer or vector of integers expected.\n"), fname, 2); return 1; } sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &mM, &nM, &pdblM); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (verify_cstr(pdblM, mM * nM, &m1, &m2) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: Integer >= %d expected.\n"), fname, 2, 0); return 1; } if ( mM == 1 && nM == 1) { M_is_scalar = 1; } if ( ! M_is_scalar && ! N_is_scalar ) { Scierror(999, _("%s: Only one of arg1 and arg2 may be a vector.\n"), fname); return 1; } /* get X */ //get variable address of the input argument sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } sciErr = getVarType(pvApiCtx, piAddr3, &iType3); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (iType3 != sci_matrix || isVarComplex(pvApiCtx, piAddr3)) { Scierror(999, _("%s: Wrong type for input argument #%d: Real matrix expected.\n"), fname, 3); return 1; } sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &mx, &nx, &pdblX); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } mnx = mx * nx; for ( i = 0 ; i < mnx ; i++ ) { if ((fabs(pdblX[i]) <= 1.0) == 0) { Scierror(999, _("%s: Wrong value for input argument #%d: Matrix with elements in [%d,%d] expected.\n"), fname, 3, -1, 1); return 1; } } if ( nbInputArg == 4 ) { //get variable address int iRet = 0; char* lschar = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a single string at position 4 iRet = getAllocatedSingleString(pvApiCtx, piAddr4, &lschar); if (iRet) { return iRet; } if ( strcmp(lschar, "norm") == 0) { normalized = 1; } else { normalized = 0; } freeAllocatedSingleString(lschar); } else { normalized = 0; } MNp1 = Max (n2 - n1, m2 - m1) + 1; allocMatrixOfDouble(pvApiCtx, nbInputArg + 1, MNp1, mnx, &pdblPQA); piPQA = (int*)MALLOC(MNp1 * mnx * sizeof(int)); if ( normalized ) { id = 4; } else { id = 3; } nudiff = n2 - n1; dnu1 = (double) n1; for ( i = 0 ; i < mnx ; i++ ) { xx = fabs(pdblX[i]); /* manage the case where xx = 1 with n scalar*/ if (N_is_scalar && xx == 1) { if (m1 == 0) { pdblPQA[i * MNp1] = 1; } else { pdblPQA[i * MNp1] = 0; } if (normalized) { pdblPQA[i * MNp1] = pdblPQA[i * MNp1] * sqrt(dnu1 + 0.5); } piPQA[i * MNp1] = 0; for (j = 1; j < MNp1; j++) { pdblPQA[i * MNp1 + j] = 0; piPQA[i * MNp1 + j] = 0; } } else { /* dxleg computes only for x in [0,1] */ C2F(dxlegf) (&dnu1, &nudiff, &m1, &m2, &xx, &id, pdblPQA + i * MNp1, piPQA + i * MNp1, &ierror); if ( ierror != 0 ) { if ( ierror == 207 ) /* @TODO what is 207 ? */ { Scierror(999, _("%s: overflow or underflow of an extended range number\n"), fname); } else { Scierror(999, _("%s: error number %d\n"), fname, ierror); } return 0; } } } /* dxlegf returns the result under a form (pqa,ipqa) (to * compute internaly with an extended exponent range) * When the "exponent" part (ipqa) is 0 then the number is exactly * given by pqa else it leads to an overflow or an underflow. */ for ( i = 0 ; i < mnx * MNp1 ; i++ ) { if ( piPQA[i] < 0 ) { pdblPQA[i] = 0.0; } if ( piPQA[i] > 0 ) { pdblPQA[i] = pdblPQA[i] * return_an_inf(); /* pqa[i] * Inf to have the sign */ } } FREE(piPQA); /* complete the result by odd/even symmetry for negative x */ for ( i = 0 ; i < mnx ; i++ ) { if ( pdblX[i] < 0.0 ) { if ( (n1 + m1) % 2 == 1 ) { for ( j = 0 ; j < MNp1 ; j += 2 ) { pdblPQA[i * MNp1 + j] = -pdblPQA[i * MNp1 + j]; } } else { for ( j = 1 ; j < MNp1 ; j += 2 ) { pdblPQA[i * MNp1 + j] = -pdblPQA[i * MNp1 + j]; } } } } AssignOutputVariable(pvApiCtx, 1) = nbInputArg + 1; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_xpolys(char *fname, void *pvApiCtx) { SciErr sciErr; int* piAddrl1 = NULL; double* l1 = NULL; int* piAddrl2 = NULL; double* l2 = NULL; int* piAddr3 = NULL; int* l3 = NULL; int m1 = 0, n1 = 0; int m2 = 0, n2 = 0; int m3 = 0, n3 = 0; int i = 0; long hdl = 0; int iFigureUID = 0; int iSubWinUID = 0; int iCompoundUID = 0; int iFalse = 0; int iVisible = 0; int *piVisible = &iVisible; CheckInputArgument(pvApiCtx, 2, 3); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2); return 1; } //CheckSameDims if (m1 != m2 || n1 != n2) { Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1); return 1; } if (m1 * n1 == 0 || m2 * n2 == 0) { /* dimension 0, 0 polyline to draw */ AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } iSubWinUID = getOrCreateDefaultSubwin(); iFigureUID = getCurrentFigure(); // Create compound. iCompoundUID = createGraphicObject(__GO_COMPOUND__); setGraphicObjectProperty(iCompoundUID, __GO_VISIBLE__, &iFalse, jni_bool, 1); /* Sets the parent-child relationship for the Compound */ setGraphicObjectRelationship(iSubWinUID, iCompoundUID); if (nbInputArgument(pvApiCtx) == 3) { sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 3. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr3, &m3, &n3, &l3); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); return 1; } //CheckVector if (m3 != 1 && n3 != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: Vector expected.\n"), fname, 3); return 1; } //CheckDimProp if (m3 * n3 < n1) { Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname); return 1; } /* Construct the polylines */ for (i = 0; i < n1; ++i) { Objpoly((l1 + (i * m1)), (l2 + (i * m2)), m1, 0, *(int*)(l3 + i), &hdl); // Add newly created object to Compound setGraphicObjectRelationship(iCompoundUID, getObjectFromHandle(hdl)); } } else { for (i = 0; i < n1; ++i) { Objpoly((l1 + (i * m1)), (l2 + (i * m2)), m1, 0, 1, &hdl); // Add newly created object to Compound setGraphicObjectRelationship(iCompoundUID, getObjectFromHandle(hdl)); } } getGraphicObjectProperty(iFigureUID, __GO_VISIBLE__, jni_bool, (void **)&piVisible); setGraphicObjectProperty(iCompoundUID, __GO_VISIBLE__, &iVisible, jni_bool, 1); setCurrentObject(iCompoundUID); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }