int get_double_info(void* _pvCtx, int _iRhs, int* _piParent, int *_piAddr, int _iItemPos) { SciErr sciErr; int iRows = 0; int iCols = 0; double* pdblReal = NULL; double* pdblImg = NULL; if (_iItemPos == 0) { //not in list if (isVarComplex(_pvCtx, _piAddr)) { sciErr = getComplexMatrixOfDouble(_pvCtx, _piAddr, &iRows, &iCols, &pdblReal, &pdblImg); } else { sciErr = getMatrixOfDouble(_pvCtx, _piAddr, &iRows, &iCols, &pdblReal); } } else { if (isVarComplex(_pvCtx, _piAddr)) { sciErr = getComplexMatrixOfDoubleInList(_pvCtx, _piParent, _iItemPos, &iRows, &iCols, &pdblReal, &pdblImg); } else { sciErr = getMatrixOfDoubleInList(_pvCtx, _piParent, _iItemPos, &iRows, &iCols, &pdblReal); } } if (sciErr.iErr) { printError(&sciErr, 0); return 0; } insert_indent(); sciprint("Double (%d x %d)\n", iRows, iCols); return 0;; }
int getFixedSizeDoubleMatrixInList(int argNum, int itemPos, int rows, int cols, double **dest) { int *varAddress,inputMatrixRows,inputMatrixCols; SciErr sciErr; const char errMsg[]="Wrong type for input argument #%d: A matrix of double of size %d by %d is expected.\n"; const int errNum=999; //same steps as above sciErr = getVarAddressFromPosition(pvApiCtx, argNum, &varAddress); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } getMatrixOfDoubleInList(pvApiCtx, varAddress, itemPos, &rows, &cols, dest); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } return 0; }
/*--------------------------------------------------------------------------*/ SciErr getIntInPList(void* _pvCtx, int * _piAddress, const char * _pstLabel, int * _piValue, int * _piFound, int _iDefaultValue, int _iLog, enum type_check _eCheck, ...) { int pos_label = 0, i = 0; int m_tmp = 0, n_tmp = 0; double * tmp_dbl = NULL; SciErr _SciErr; _SciErr.iErr = 0; _SciErr.iMsgCount = 0; pos_label = commonFindLabel(_pvCtx, _piAddress, _pstLabel); *_piFound = pos_label; if (pos_label != -1) { _SciErr = getMatrixOfDoubleInList(_pvCtx, _piAddress, pos_label + 1, &m_tmp, &n_tmp, &tmp_dbl); if (!_SciErr.iErr) { *_piValue = (int)tmp_dbl[0]; } else { if (_iLog) { sciprint(_("%s: wrong parameter type. %s expected. Return default value %d.\n"), "getIntInPList", "int", _iDefaultValue); } *_piValue = _iDefaultValue; } } else { if (_iLog) { sciprint(_("%s: parameter not found. Return default value %d.\n"), "getIntInPList", _iDefaultValue); } *_piValue = _iDefaultValue; } /* Now check parameters */ if (_eCheck != CHECK_NONE) { va_list vl; int nb_value_to_check = 0; int value_to_check = 0; int check_res = 0; va_start(vl, _eCheck); switch (_eCheck) { case CHECK_MIN: value_to_check = va_arg(vl, int); va_end(vl); if (value_to_check > *_piValue) { if ((*_piFound != -1) && (_iLog)) { sciprint(_("%s: wrong min bound for parameter %s: min bound %d, value %d\n"), "getIntInPList", _pstLabel, value_to_check, *_piValue); } *_piValue = _iDefaultValue; addErrorMessage(&_SciErr, 999, _("%s: wrong min bound for parameter %s: min bound %d, value %d\n"), "getIntInPList", _pstLabel, value_to_check, *_piValue); return _SciErr; } break; case CHECK_MAX: value_to_check = va_arg(vl, int); va_end(vl); if (value_to_check < *_piValue) { if ((*_piFound != -1) && (_iLog)) { sciprint(_("%s: wrong max bound for parameter %s: max bound %d, value %d\n"), "getIntInPList", _pstLabel, value_to_check, *_piValue); } *_piValue = _iDefaultValue; addErrorMessage(&_SciErr, 999, _("%s: wrong max bound for parameter %s: max bound %d, value %d\n"), "getIntInPList", _pstLabel, value_to_check, *_piValue); return _SciErr; } break; case CHECK_BOTH: // First value is the min bound value_to_check = va_arg(vl, int); if (value_to_check > *_piValue) { if ((*_piFound != -1) && (_iLog)) { sciprint(_("%s: wrong min bound for parameter %s: min bound %d, value %d\n"), "getIntInPList", _pstLabel, value_to_check, *_piValue); } *_piValue = _iDefaultValue; va_end(vl); addErrorMessage(&_SciErr, 999, _("%s: wrong min bound for parameter %s: min bound %d, value %d\n"), "getIntInPList", _pstLabel, value_to_check, *_piValue); return _SciErr; } // Second value is the max bound value_to_check = va_arg(vl, int); va_end(vl); if (value_to_check < *_piValue) { if ((*_piFound != -1) && (_iLog)) { sciprint(_("%s: wrong max bound for parameter %s: max bound %d, value %d\n"), "getIntInPList", _pstLabel, value_to_check, *_piValue); } *_piValue = _iDefaultValue; addErrorMessage(&_SciErr, 999, _("%s: wrong max bound for parameter %s: max bound %d, value %d\n"), "getIntInPList", _pstLabel, value_to_check, *_piValue); return _SciErr; } break; case CHECK_VALUES: // First parameters is int and contains the number of values to check nb_value_to_check = va_arg(vl, int); check_res = 0; for (i = 0; i < nb_value_to_check; i++) { value_to_check = va_arg(vl, int); check_res = check_res || (value_to_check == *_piValue); } if (!check_res) { if ((*_piFound != -1) && (_iLog)) { sciprint(_("%s: wrong value for parameter %s: value %d\n"), "getIntInPList", _pstLabel, *_piValue); sciprint(_("%s: awaited parameters: "), "getIntInPList"); va_start(vl, _eCheck); nb_value_to_check = va_arg(vl, int); for (i = 0; i < nb_value_to_check; i++) { value_to_check = va_arg(vl, int); sciprint(" %d", value_to_check); } sciprint("\n"); } *_piValue = _iDefaultValue; va_end(vl); addErrorMessage(&_SciErr, 999, _("%s: wrong value for parameter %s: value %d\n"), "getIntInPList", _pstLabel, *_piValue); return _SciErr; } va_end(vl); break; }