LTFAT_API int LTFAT_NAME_COMPLEX(fftrealcircshift)( const LTFAT_COMPLEX* in, ltfat_int L, const double shift, LTFAT_COMPLEX* out) { ltfat_div_t domod; double shiftLoc; int status = LTFATERR_SUCCESS; CHECKNULL(in); CHECKNULL(out); CHECK(LTFATERR_BADSIZE, L > 0, "L must be positive"); domod = ltfat_idiv(L, 2); shiftLoc = remainder(shift, L); if (shiftLoc != 0) { LTFAT_COMPLEX phasefact = -I * (LTFAT_REAL)(2.0 * M_PI * shiftLoc) / (( LTFAT_REAL) L); out[0] = in[0]; for (int ii = 1; ii < domod.quot + 1; ii++) out[ii] = exp((LTFAT_REAL)ii * phasefact) * in[ii]; } else { if (in != out) memcpy(out, in, (domod.quot + 1) * sizeof * out); } error: return status; }
LTFAT_API int LTFAT_NAME_COMPLEX(dgtreal_phaseunlock)(const LTFAT_COMPLEX* cTimeinv, ltfat_int L, ltfat_int W, ltfat_int a, ltfat_int M, LTFAT_COMPLEX* cFreqinv) { ltfat_int N, M2; int status = LTFATERR_SUCCESS; CHECKNULL(cFreqinv); CHECKNULL(cTimeinv); CHECK(LTFATERR_NOTPOSARG, L > 0, "L must be positive"); CHECK(LTFATERR_NOTPOSARG, W > 0, "W must be positive"); CHECK(LTFATERR_NOTPOSARG, a > 0, "a must be positive"); CHECK(LTFATERR_NOTPOSARG, M > 0, "M must be positive"); N = L / a; M2 = M / 2 + 1; for (ltfat_int w = 0; w < W; w++) { for (ltfat_int n = 0; n < N; n++) { const LTFAT_COMPLEX* inCol = cTimeinv + n * M2 + w * M2 * N; LTFAT_COMPLEX* outCol = cFreqinv + n * M2 + w * M2 * N; LTFAT_NAME_COMPLEX(fftrealcircshift)( inCol, M, (double)(n * a), outCol); } } error: return status; }
static void make_png(void) { png_bytepp row_pointers=NULL; rgb_t * row_data=NULL; int i; int nfreqs = nfft/2+1; png_structp png_ptr=NULL; png_infop info_ptr=NULL; CHECKNULL( png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING,0,0,0) ); CHECKNULL( info_ptr = png_create_info_struct(png_ptr) ); png_init_io(png_ptr, fout ); png_set_IHDR(png_ptr, info_ptr ,nfreqs,nrows,8,PNG_COLOR_TYPE_RGB,PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT,PNG_FILTER_TYPE_DEFAULT ); row_data = (rgb_t*)malloc(sizeof(rgb_t) * nrows * nfreqs) ; cpx2pixels(row_data, vals, nfreqs*nrows ); row_pointers = realloc(row_pointers, nrows*sizeof(png_bytep)); for (i=0;i<nrows;++i) { row_pointers[i] = (png_bytep)(row_data + i*nfreqs); } png_set_rows(png_ptr, info_ptr, row_pointers); fprintf(stderr,"creating %dx%d png\n",nfreqs,nrows); fprintf(stderr,"bitdepth %d \n",png_get_bit_depth(png_ptr,info_ptr ) ); png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY , NULL); }
LTFAT_API int LTFAT_NAME_COMPLEX(dgt2dgtreal)(const LTFAT_COMPLEX* cdgt, ltfat_int M, ltfat_int N, LTFAT_COMPLEX* cdgtreal) { int status = LTFATERR_SUCCESS; int M2 = M / 2 + 1; CHECKNULL(cdgtreal); CHECKNULL(cdgt); CHECK(LTFATERR_BADSIZE, M > 0, "M must be positive"); CHECK(LTFATERR_BADSIZE, N > 0, "N must be positive"); if (cdgtreal == (const LTFAT_COMPLEX*) cdgt) { LTFAT_COMPLEX* cdgtrealFront = cdgtreal + M2; for (ltfat_int n = 1; n < N; n++) { const LTFAT_COMPLEX* cdgtCol = cdgt + n * M; for (ltfat_int m = 0; m < M2; m++) *cdgtrealFront++ = cdgtCol[m] ; } } else for (ltfat_int n = 0; n < N; n++) memcpy(cdgtreal + n * M2, cdgt + n * M, M2 * sizeof * cdgtreal); error: return status; }
LTFAT_API int LTFAT_NAME(real2complex_array)(const LTFAT_REAL* in, ltfat_int L, LTFAT_COMPLEX* out) { LTFAT_REAL (*outTmp)[2]; int status = LTFATERR_SUCCESS; CHECKNULL(in); CHECKNULL(out); CHECK(LTFATERR_BADSIZE, L > 0, "L must be positive"); outTmp = (LTFAT_REAL(*)[2]) out; if (in == (LTFAT_REAL*)out) { // Go from the back to avoid overwriting input for (ltfat_int ii = L - 1; ii >= 0; ii--) { outTmp[ii][0] = in[ii]; outTmp[ii][1] = 0.0; } } else { for (ltfat_int ii = 0; ii < L; ii++) { outTmp[ii][0] = in[ii]; outTmp[ii][1] = 0.0; } } error: return status; }
MgReader* MgSelectCommand::Execute() { FdoPtr<FdoIFeatureReader> reader; // Break up the filter into smaller chunks FdoPtr<MgFdoFilterCollection> subFilters = this->GetSubFilters(); CHECKNULL((FdoISelect*)m_command, L"MgSelectCommand.Execute"); // Execute queries using the smaller filters and collect the results of the queries into a reader collection. FdoPtr<MgFdoReaderCollection> frc = MgFdoReaderCollection::Create(); for (FdoInt32 filterIndex = 0; filterIndex < subFilters->GetCount(); filterIndex++) { FdoPtr<FdoFilter> filter = subFilters->GetItem(filterIndex); m_command->SetFilter(filter); reader = m_command->Execute(); frc->Add(reader); } FdoPtr<MgFdoFeatureReader> featureReader = new MgFdoFeatureReader(frc); CHECKNULL((FdoIFeatureReader*)featureReader, L"MgSelectCommand.Execute"); return new MgServerFeatureReader(m_connection, featureReader); }
LTFAT_API int LTFAT_NAME_COMPLEX(fftfftshift)(const LTFAT_COMPLEX* in, ltfat_int L, LTFAT_COMPLEX* out) { ltfat_div_t domod; int status = LTFATERR_SUCCESS; domod = ltfat_idiv(L, 2); if (domod.rem) { // There is no Nyquist sample, modulation is by (L-1/L)*pi status = LTFAT_NAME_COMPLEX(fftcircshift)(in, L, (double)domod.quot, out); } else { CHECKNULL(in); CHECKNULL(out); CHECK(LTFATERR_BADSIZE, L > 0, "L must be positive"); if (in != out) for (int ii = 0; ii < L; ii += 2) out[ii] = in[ii]; // There is Nyquist sample. Modulation is exactly by pi i.e. no complex // multiplication for (int ii = 1; ii < L; ii += 2) out[ii] = -in[ii]; } error: return status; }
////////////////////////////////////////////////////////////////// /// <summary> /// Gets the data type of the property with the specified name. /// </summary> /// <param name="propertyName">Input the property name.</param> /// <returns>Returns the type of the property.</returns> INT32 MgProxySqlDataReader::GetPropertyType(CREFSTRING propertyName) { CHECKNULL(m_propDefCol, L"MgProxySqlDataReader.GetPropertyType"); Ptr<MgPropertyDefinition> propDef = m_propDefCol->GetItem(propertyName); CHECKNULL((MgPropertyDefinition*)propDef, L"MgProxySqlDataReader.GetPropertyType"); return propDef->GetPropertyType(); }
////////////////////////////////////////////////////////////////// /// <summary> /// Gets the data type of the property at the specified index. /// </summary> /// <param name="index">Input the property index.</param> /// <returns>Returns the type of the property.</returns> INT32 MgProxySqlDataReader::GetPropertyType(INT32 index) { CHECKNULL(m_propDefCol, L"MgProxySqlDataReader.GetPropertyType"); Ptr<MgPropertyDefinition> propDef = m_propDefCol->GetItem(index); CHECKNULL((MgPropertyDefinition*)propDef, L"MgProxySqlDataReader.GetPropertyType"); return propDef->GetPropertyType(); }
////////////////////////////////////////////////////////////////// /// <summary> /// Gets the number of properties in the result set. /// </summary> /// <returns>Returns the number of properties.</returns> INT32 MgFeatureReader::GetPropertyCount() { Ptr<MgClassDefinition> classDef = this->GetClassDefinition(); CHECKNULL((MgClassDefinition*)classDef, L"MgFeatureReader.GetPropertyCount"); Ptr<MgPropertyDefinitionCollection> propDefCol = classDef->GetProperties(); CHECKNULL((MgPropertyDefinitionCollection*)propDefCol, L"MgFeatureReader.GetPropertyCount"); return propDefCol->GetCount(); }
LTFAT_API int LTFAT_NAME_COMPLEX(fftcircshift)( const LTFAT_COMPLEX* in, ltfat_int L, const double shift, LTFAT_COMPLEX* out) { double shiftLoc; int status = LTFATERR_SUCCESS; CHECKNULL(in); CHECKNULL(out); CHECK(LTFATERR_BADSIZE, L > 0, "L must be positive"); shiftLoc = remainder(shift, L); if (shiftLoc != 0) { const ltfat_div_t domod = ltfat_idiv(L, 2); double phasefact = -2.0 * M_PI * shiftLoc / L; out[0] = in[0]; // We do the complex multiplication explicitly, because we want the intermediate // results to be doubles until the very end. This function has problems with // numerical precision degradation. const LTFAT_REAL* inPtr = (const LTFAT_REAL*) in; LTFAT_REAL* outPtr = (LTFAT_REAL*) out; for (int ii = 1; ii < domod.quot + 1; ii++) { LTFAT_REAL ar = inPtr[2 * ii]; LTFAT_REAL ai = inPtr[2 * ii + 1]; double br = cos(ii * phasefact); double bi = sin(ii * phasefact); outPtr[2 * ii] = (LTFAT_REAL) ( ar * br - ai * bi ); outPtr[2 * ii + 1] = (LTFAT_REAL) (ar * bi + ai * br ); } for (int ii = 1; ii < domod.quot + domod.rem; ii++) { LTFAT_REAL ar = inPtr[2 * (L - ii)]; LTFAT_REAL ai = inPtr[2 * (L - ii) + 1]; double br = cos(-ii * phasefact); double bi = sin(-ii * phasefact); outPtr[2 * (L - ii)] = (LTFAT_REAL) ( ar * br - ai * bi ); outPtr[2 * (L - ii) + 1] = (LTFAT_REAL) ( ar * bi + ai * br ); } } else { if (in != out) memcpy(out, in, L * sizeof * out); } error: return status; }
MgFeatureManipulationCommand* MgFeatureManipulationCommand::CreateCommand(MgFeatureCommand* webCmd, MgServerFeatureConnection* connection, INT32 cmdId) { CHECKNULL(webCmd, L"MgFeatureManipulationCommand.CreateCommand") CHECKNULL(connection, L"MgFeatureManipulationCommand.CreateCommand") INT32 cmdType = webCmd->GetCommandType(); bool supports = false; Ptr<MgFeatureManipulationCommand> command; switch(cmdType) { case MgFeatureCommandType::InsertFeatures: { supports = connection->SupportsCommand(FdoCommandType_Insert); if (supports) { command = new MgServerInsertCommand(webCmd, connection, cmdId); } break; } case MgFeatureCommandType::UpdateFeatures: { supports = connection->SupportsCommand(FdoCommandType_Update); if (supports) { command = new MgServerUpdateCommand(webCmd, connection, cmdId); } break; } case MgFeatureCommandType::DeleteFeatures: { supports = connection->SupportsCommand(FdoCommandType_Delete); if (supports) { command = new MgServerDeleteCommand(webCmd, connection, cmdId); } break; } } if (!supports) { STRING message = MgServerFeatureUtil::GetMessage(L"MgCommandNotSupported"); MgStringCollection arguments; arguments.Add(message); throw new MgFeatureServiceException(L"MgFeatureManipulationCommand.CreateCommand", __LINE__, __WFILE__, &arguments, L"", NULL); } return command.Detach(); }
////////////////////////////////////////////////////////////////// /// <summary> /// Gets the name of the property at the given ordinal position. /// </summary> /// <param name="index">Input the position of the property.</param> /// <returns>Returns the property name</returns> STRING MgFeatureReader::GetPropertyName(INT32 index) { Ptr<MgClassDefinition> classDef = this->GetClassDefinition(); CHECKNULL((MgClassDefinition*)classDef, L"MgFeatureReader.GetPropertyName"); Ptr<MgPropertyDefinitionCollection> propDefCol = classDef->GetProperties(); CHECKNULL((MgPropertyDefinitionCollection*)propDefCol, L"MgFeatureReader.GetPropertyName"); Ptr<MgPropertyDefinition> propDef = propDefCol->GetItem(index); CHECKNULL((MgPropertyDefinition*)propDef, L"MgFeatureReader.GetPropertyName"); return propDef->GetName(); }
////////////////////////////////////////////////////////////////// /// <summary> /// Gets the data type of the property with the specified name. /// Please refer to MgPropertyType for list of values /// </summary> /// <param name="propertyName">Input the property name.</param> /// <returns>Returns the type of the property.</returns> INT32 MgFeatureReader::GetPropertyType(CREFSTRING propertyName) { Ptr<MgClassDefinition> classDef = this->GetClassDefinition(); CHECKNULL((MgClassDefinition*)classDef, L"MgFeatureReader.GetPropertyType"); Ptr<MgPropertyDefinitionCollection> propDefCol = classDef->GetProperties(); CHECKNULL((MgPropertyDefinitionCollection*)propDefCol, L"MgFeatureReader.GetPropertyType"); Ptr<MgPropertyDefinition> propDef = propDefCol->GetItem(propertyName); CHECKNULL((MgPropertyDefinition*)propDef, L"MgFeatureReader.GetPropertyType"); return GetMgPropertyType(propDef); }
// Get the property for the specified index MgProperty* MgProxyFeatureReader::GetProperty(INT32 index) { CHECKNULL(m_set, L"MgProxyFeatureReader.GetProperty"); CHECK_FEATURESET_COUNT(m_set, L"MgProxyFeatureReader.GetProperty"); Ptr<MgPropertyCollection> ptrCol = m_set->GetFeatureAt(m_currRecord-1); CHECKNULL(ptrCol, L"MgProxyFeatureReader.GetProperty"); Ptr<MgProperty> ptrProp = ptrCol->GetItem(index); CHECKNULL(ptrProp, L"MgProxyFeatureReader.GetProperty"); return SAFE_ADDREF(ptrProp.p); }
void MgFeatureNumericFunctions::Initialize(MgReader* reader, FdoFunction* customFunction, CREFSTRING propertyAlias) { CHECKNULL((MgReader*)reader, L"MgFeatureNumericFunctions.Initialize"); CHECKNULL((FdoFunction*)customFunction, L"MgFeatureNumericFunctions.Initialize"); if(1 == reader->GetPropertyCount()) { m_type = MgServerFeatureUtil::GetPropertyDefinition(reader, m_propertyName); } else { // Only get the property needed FdoPtr<FdoExpressionCollection> exprCol = customFunction->GetArguments(); FdoInt32 cnt = exprCol->GetCount(); FdoPtr<FdoExpression> expr; if(cnt == 1) { expr = exprCol->GetItem(0); FdoIdentifier* propName = dynamic_cast<FdoIdentifier*>(expr.p); CHECKNULL(propName, L"MgFeatureNumericFunctions.Initialize"); m_propertyName = propName->GetName(); m_type = reader->GetPropertyType(m_propertyName); } else { // Throw original exception m_type = MgServerFeatureUtil::GetPropertyDefinition(reader, m_propertyName); } } // TODO: Should we really check this, may be we can ignore ?? // because we can only come to here if property type is numeric this->CheckSupportedPropertyType(); // We must have an property alias // Though we can name a property with same name as function expression // But Fdo forces to have an alias. Therefore we implement this restriction. if (propertyAlias.empty()) { STRING message = MgServerFeatureUtil::GetMessage(L"MgMissingPropertyAlias"); MgStringCollection arguments; arguments.Add(message); throw new MgFeatureServiceException(L"MgFeatureDistribution.Initialize", __LINE__, __WFILE__, &arguments, L"", NULL); } m_reader = SAFE_ADDREF(reader); m_customFunction = FDO_SAFE_ADDREF(customFunction); m_propertyAlias = propertyAlias; }
PHASERET_API int PHASERET_NAME(pghi)(const LTFAT_REAL s[], ltfat_int L, ltfat_int W, ltfat_int a, ltfat_int M, double gamma, LTFAT_COMPLEX c[]) { PHASERET_NAME(pghi_plan)* p = NULL; int status = LTFATERR_SUCCESS; CHECKNULL(s); CHECKNULL(c); CHECKSTATUS( PHASERET_NAME(pghi_init)( L, W, a, M, 1e-1, 1e-10, gamma, &p)); PHASERET_NAME(pghi_execute)(p, s, c); // This cannot fail PHASERET_NAME(pghi_done)(&p); error: return status; }
void MgProxySqlDataReader::ToXml(string &str) { CHECKNULL((MgBatchPropertyCollection*)m_set, L"MgProxySqlDataReader.ToXml"); CHECKNULL((MgPropertyDefinitionCollection*)m_propDefCol, L"MgProxySqlDataReader.ToXml"); // this XML follows the SqlSelect-1.0.0.xsd schema ResponseStartUtf8(str); HeaderToStringUtf8(str); BodyStartUtf8(str); while ( this->ReadNext() ) { CurrentToStringUtf8(str); } BodyEndUtf8(str); ResponseEndUtf8(str); }
void MgSelectCommand::SetFilter(FdoFilter* value) { CHECKNULL((FdoISelect*)m_command, L"MgSelectCommand.SetFilter"); m_command->SetFilter(value); m_filter = FDO_SAFE_ADDREF(value); }
////////////////////////////////////////////////////////////////// /// <summary> /// Gets the name of the property at the given ordinal position. /// </summary> /// <param name="index">Input the position of the property.</param> /// <returns>Returns the property name</returns> STRING MgProxySqlDataReader::GetPropertyName(INT32 index) { CHECKNULL(m_propDefCol, L"MgProxySqlDataReader.GetPropertyName"); Ptr<MgPropertyDefinition> propDef = m_propDefCol->GetItem(index); return propDef->GetName(); }
INT16 MgFeatureReader::GetMgPropertyType(MgPropertyDefinition* propDef) { CHECKNULL((MgPropertyDefinition*)propDef, L"MgFeatureReader.GetMgPropertyType") INT32 mgPropType = 0; // Whether it is data,geometry,raster,object or association property INT16 type = propDef->GetPropertyType(); switch(type) { case MgFeaturePropertyType::DataProperty: { mgPropType = ((MgDataPropertyDefinition*)propDef)->GetDataType(); break; } case MgFeaturePropertyType::GeometricProperty: { mgPropType = MgPropertyType::Geometry; break; } case MgFeaturePropertyType::RasterProperty: { mgPropType = MgPropertyType::Raster; break; } case MgFeaturePropertyType::ObjectProperty: { break; } case MgFeaturePropertyType::AssociationProperty: { break; } } return ((INT16)mgPropType); }
void MgSelectCommand::SetGroupingFilter(FdoFilter* filter) { CHECKNULL((FdoISelect*)m_command, L"MgSelectCommand.SetGroupingFilter"); // This operation is not supported by FdoISelect // m_command->SetGroupingFilter(filter); // throw new MgInvalidOperationException(L"MgSelectCommand.SetGroupingFilter", __LINE__, __WFILE__, NULL, L"", NULL); }
void MgSelectCommand::SetDistinct(bool value) { CHECKNULL((FdoISelect*)m_command, L"MgSelectCommand.SetDistinct"); // This operation is not supported by FdoISelect // m_command->SetDistinct(value); // throw new MgInvalidOperationException(L"MgSelectCommand.SetDistinct", __LINE__, __WFILE__, NULL, L"", NULL); }
LTFAT_API int LTFAT_NAME(complex2real_array)(const LTFAT_COMPLEX* in, ltfat_int L, LTFAT_REAL* out) { const LTFAT_REAL (*inTmp)[2]; int status = LTFATERR_SUCCESS; CHECKNULL(in); CHECKNULL(out); CHECK(LTFATERR_BADSIZE, L > 0, "L must be positive"); inTmp = (const LTFAT_REAL(*)[2]) in; for (ltfat_int ii = 0; ii < L; ii++) out[ii] = inTmp[ii][0]; error: return status; }
void MgProxySqlDataReader::SetService(MgFeatureService* service) { CHECKNULL(service, L"MgProxySqlDataReader.SetService"); if (m_service == NULL) { m_service = SAFE_ADDREF(service); } }
FdoIdentifierCollection* MgSelectCommand::GetGrouping() { CHECKNULL((FdoISelect*)m_command, L"MgSelectCommand.GetGrouping"); // This operation is not supported by FdoISelect // return m_command->GetGrouping(); // throw new MgInvalidOperationException(L"MgSelectCommand.GetGrouping", __LINE__, __WFILE__, NULL, L"", NULL); return NULL; }
FdoFilter* MgSelectCommand::GetGroupingFilter() { CHECKNULL((FdoISelect*)m_command, L"MgSelectCommand.GetGroupingFilter"); // This operation is not supported by FdoISelect // return m_command->GetGroupingFilter(filter); // throw new MgInvalidOperationException(L"MgSelectCommand.GetGroupingFilter", __LINE__, __WFILE__, NULL, L"", NULL); return NULL; }
bool MgSelectCommand::GetDistinct() { CHECKNULL((FdoISelect*)m_command, L"MgSelectCommand.GetDistinct"); // This operation is not supported by FdoISelect // return m_command->GetDistinct(); // throw new MgInvalidOperationException(L"MgSelectCommand.GetDistinct", __LINE__, __WFILE__, NULL, L"", NULL); return false; }
MgSelectCommand::MgSelectCommand(MgResourceIdentifier* resource) { CHECKNULL((MgResourceIdentifier*)resource, L"MgSelectCommand.MgSelectCommand"); // Connect to provider m_connection = new MgServerFeatureConnection(resource); if ((NULL != m_connection.p) && ( m_connection->IsConnectionOpen() )) { m_providerName = m_connection->GetProviderName(); } else { throw new MgConnectionFailedException(L"MgSelectCommand.MgSelectCommand", __LINE__, __WFILE__, NULL, L"", NULL); } // Create FdoISelect command FdoPtr<FdoIConnection> fdoConn = m_connection->GetConnection(); m_command = (FdoISelect*)fdoConn->CreateCommand(FdoCommandType_Select); CHECKNULL((FdoISelect*)m_command, L"MgSelectCommand.MgSelectCommand"); }
MgServerGetFeatureProviders::MgServerGetFeatureProviders() { FdoPtr<IProviderRegistry> providerReg = FdoFeatureAccessManager::GetProviderRegistry(); CHECKNULL(providerReg, L"MgServerGetFeatureProviders.MgServerGetFeatureProviders()"); FdoPtr<IConnectionManager> connManager = FdoFeatureAccessManager::GetConnectionManager(); CHECKNULL(connManager, L"MgServerGetFeatureProviders.MgServerGetFeatureProviders()"); m_fdoProviderCol = providerReg->GetProviders(); CHECKNULL(m_fdoProviderCol, L"MgServerGetFeatureProviders.MgServerGetFeatureProviders()"); // this XML follows the FeatureProviderRegistry-1.0.0.xsd schema m_xmlUtil = new MgXmlUtil("FeatureProviderRegistry" /* NOXLATE */); CHECKNULL(m_xmlUtil, L"MgServerGetFeatureProviders.MgServerGetFeatureProviders()"); // no more risk of exceptions, so we can now assign these m_providerReg = providerReg.Detach(); m_connManager = connManager.Detach(); }