/*--------------------------------------------------------------------------*/ int sci_xchange( char * fname, unsigned long fname_len ) { int m1,n1,l1,m2,n2,l2,m3,n3,l3,l4,l5; int four = VIEWING_RECT_SIZE ; int one = 1 ; int * xPixCoords; int * yPixCoords; double * xCoords; double * yCoords; int viewingRect[VIEWING_RECT_SIZE]; CheckRhs(3,3); CheckLhs(1,3); GetRhsVar(3,STRING_DATATYPE,&m3,&n3,&l3); /* Convert coordinates */ if ( strcmp(cstk(l3),"i2f") == 0) { GetRhsVar(1,MATRIX_OF_INTEGER_DATATYPE,&m1,&n1,&l1); GetRhsVar(2,MATRIX_OF_INTEGER_DATATYPE,&m2,&n2,&l2); CheckSameDims(1,2,m1,n1,m2,n2); CreateVar(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE,&m1,&n1,&l3); CreateVar(Rhs+2,MATRIX_OF_DOUBLE_DATATYPE,&m1,&n1,&l4); /* Get rectangle */ CreateVar(Rhs+3,MATRIX_OF_DOUBLE_DATATYPE,&one,&four,&l5); xPixCoords = istk(l1); yPixCoords = istk(l2); xCoords = stk(l3); yCoords = stk(l4); convertPixelCoordsToUserCoords(xPixCoords, yPixCoords, xCoords, yCoords, m1 * n1, viewingRect ); } else { GetRhsVar(1,MATRIX_OF_DOUBLE_DATATYPE,&m1,&n1,&l1); GetRhsVar(2,MATRIX_OF_DOUBLE_DATATYPE,&m2,&n2,&l2); CheckSameDims(1,2,m1,n1,m2,n2); CreateVar(Rhs+1,MATRIX_OF_INTEGER_DATATYPE,&m1,&n1,&l3); CreateVar(Rhs+2,MATRIX_OF_INTEGER_DATATYPE,&m1,&n1,&l4); /* Get rectangle */ CreateVar(Rhs+3,MATRIX_OF_DOUBLE_DATATYPE,&one,&four,&l5); xCoords = stk(l1); yCoords = stk(l2); xPixCoords = istk(l3); yPixCoords = istk(l4); convertUserCoordToPixelCoords(xCoords, yCoords, xPixCoords, yPixCoords, m1 * n1, viewingRect); } *stk(l5) = viewingRect[0]; *stk(l5 + 1) = viewingRect[1]; *stk(l5 + 2) = viewingRect[2]; *stk(l5 + 3) = viewingRect[3]; LhsVar(1)=Rhs+1; LhsVar(2)=Rhs+2; LhsVar(3)=Rhs+3; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_xchange(char * fname, unsigned long fname_len) { SciErr sciErr; int* piAddrl3 = NULL; int* piAddr1 = NULL; int* piAddr2 = NULL; int* piAddrl1 = NULL; int* piAddrl2 = NULL; char* l3Input = NULL; double* l5 = NULL; int m1 = 0, n1 = 0, m2 = 0, n2 = 0; int four = VIEWING_RECT_SIZE; int one = 1; int * xPixCoords = NULL; int * yPixCoords = NULL; double* xCoords = NULL; double* yCoords = NULL; int viewingRect[VIEWING_RECT_SIZE]; CheckInputArgument(pvApiCtx, 3, 3); CheckOutputArgument(pvApiCtx, 1, 3); sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrl3); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 3. if (getAllocatedSingleString(pvApiCtx, piAddrl3, &l3Input)) { Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 3); return 1; } /* Convert coordinates */ if (strcmp(l3Input, "i2f") == 0) { int* l1 = NULL; int* l2 = NULL; double* l3 = NULL; double* l4 = NULL; 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, &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, &piAddr2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr2, &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; } sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &l3); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, m1, n1, &l4); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } /* Get rectangle */ sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, one, four, &l5); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } xPixCoords = (int*)(l1); yPixCoords = (int*)(l2); xCoords = (l3); yCoords = (l4); convertPixelCoordsToUserCoords(xPixCoords, yPixCoords, xCoords, yCoords, m1 * n1, viewingRect); } else { double* l1 = NULL; double* l2 = NULL; int* l3 = NULL; int* l4 = NULL; 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; } sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &l3); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, nbInputArgument(pvApiCtx) + 2, m1, n1, &l4); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } /* Get rectangle */ sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, one, four, &l5); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } xCoords = (l1); yCoords = (l2); xPixCoords = (int*)(l3); yPixCoords = (int*)(l4); convertUserCoordToPixelCoords(xCoords, yCoords, xPixCoords, yPixCoords, m1 * n1, viewingRect); } l5[0] = viewingRect[0]; l5[1] = viewingRect[1]; l5[2] = viewingRect[2]; l5[3] = viewingRect[3]; freeAllocatedSingleString(l3Input); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2; AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3; ReturnArguments(pvApiCtx); return 0; }