⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rec_observ.cpp

📁 PQDIF软件包(SDK,Software Development Kit),它能转换、生成并且显示PQDIF文件.对于开发电力系统的数据输出非常有用。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                pvectData->SetTag( tagSeriesValues );

                //  The vector is currently the only member of this collection.
                pcollOne->Add( pvectData );
            }

            //  Add it!
            pcolSI->Add( pcollOne );
        }
    }

    return idxNew;
}


bool CPQDIF_R_Observation::SetSeriesBaseQuantity
            (
            long        idxChannel,
            long        idxSeries,
            double      value
            )
{
    bool    status = false;

    CPQDIF_E_Collection *   pcol;
    CPQDIF_E_Scalar *       psc;

    //  Find the series
    pcol = GetOneSeries( idxChannel, idxSeries );
    if( pcol )
    {
        psc = FindScalarInCollection( pcol, tagSeriesBaseQuantity );
        if( !psc )
        {
            //  Create it !
            psc = (CPQDIF_E_Scalar *) theFactory.NewElement( ID_ELEMENT_TYPE_SCALAR );
            if( psc )
            {
                pcol->Add( psc );
            }
        }

        //  Init the scalar
        if( psc )
        {
            psc->SetTag( tagSeriesBaseQuantity );
            psc->SetValueREAL8( value );
            status = TRUE;
        }
    }

    return status;
}


bool CPQDIF_R_Observation::GetSeriesBaseQuantity
            (
            long        idxChannel,
            long        idxSeries,
            double&     value
            )
{
    bool    status = false;

    CPQDIF_E_Collection *   pcol;
    CPQDIF_E_Scalar *       psc;

    //  Find the series
    pcol = GetOneSeries( idxChannel, idxSeries );
    if( pcol )
    {
        psc = FindScalarInCollection( pcol, tagSeriesBaseQuantity );
        if( psc )
        {
            status = psc->GetValueREAL8( value );
        }
    }

    return status;
}


bool CPQDIF_R_Observation::SetTriggerInfo
            (
                    UINT4               idTriggerMethod,
                    long                countTriggers,
            const   UINT4 *             aidxTriggerChan,
            const   TIMESTAMPPQDIF&     timeTriggered
            )
{
    bool    status = false;

    CPQDIF_E_Scalar *   psc;
    CPQDIF_E_Vector *   pvect;

    //  Init
//    ASSERT( aidxTriggerChan );

    //  First, find (or create) the trigger method
    psc = FindOrCreateScalarInCollection( m_record->m_pcollMain, 
            tagTriggerMethodID, ID_PHYS_TYPE_UNS_INTEGER4 );
    //  Set its value
    if( psc )
    {
        status = psc->SetValueUINT4( idTriggerMethod );
    }

    //  Get triggered channels?
    if( status && idTriggerMethod == ID_TRIGGER_METH_CHANNEL )
    {
        status = false;
        pvect = FindOrCreateVectorInCollection( m_record->m_pcollMain, 
                    tagChannelTriggerIdx, ID_PHYS_TYPE_UNS_INTEGER4 );
        //  Set its value(s)
        if( pvect )
        {
            //  Validate physical type
            if( pvect->GetPhysicalType() == ID_PHYS_TYPE_UNS_INTEGER4 )
            {
                pvect->SetCount( countTriggers );
                for( long idx = 0; idx < countTriggers; idx++ )
                {
                    pvect->SetValueUINT4( idx, aidxTriggerChan[ idx ] );
                }
                status = TRUE;
            }
        }
    }

    //  Set the time it was triggered
    if( status )
    {
        status = false;
        psc = FindOrCreateScalarInCollection( m_record->m_pcollMain,
            tagTimeTriggered, ID_PHYS_TYPE_TIMESTAMPPQDIF );
        //  Set value
        if( psc )
        {
            status = psc->SetValueTimeStamp( timeTriggered );
        }
    }

    return status;
}


long     CPQDIF_R_Observation::GetCountResolvedSeries
            (
            long    idxChannel,
            long    idxSeries
            ) 
{
    bool    status = false;
    long    countPoints = 0;
    long    idxChannelDefn;
    UINT4   idQuantityUnits;
    GUID    idQuantityCharacteristic;
    GUID    idValueType;
    UINT4   idStorageMethod;

    CPQDIF_Element *        pel;
    CPQDIF_E_Collection *   pcol;
    CPQDIF_E_Vector *       pvectSeriesArray;

    //  Verify that we're in an observation record
    //  Requires a data source record
    if( m_record && m_pds && idxChannel >= 0 && idxSeries >= 0)
    {
        //  Find the channel defn index
        status = GetChannelDefnIdx( idxChannel, idxChannelDefn );

        //  Fail if we got a bogus index
        if( status && idxChannelDefn < 0 )
            status = false;
    }

    //  Gather information from the series definition
    if( status )
    {
        status = m_pds->GetSeriesDefnInfo( idxChannelDefn, idxSeries,
                    idQuantityUnits, idValueType, idQuantityCharacteristic, idStorageMethod );
    }

    if( status )
    {
        //  Find the series
        pcol = GetOneSeries( idxChannel, idxSeries );
        if( pcol )
        {
            pel = pcol->GetElement( tagSeriesValues );
            if( pel && pel->GetElementType() == ID_ELEMENT_TYPE_VECTOR )
            {
                pvectSeriesArray = (CPQDIF_E_Vector *) pel;
                countPoints = _GenerateSeriesCount( idStorageMethod, pvectSeriesArray );
            }
        }
    }

    return countPoints;
}

double * CPQDIF_R_Observation::NewResolvedSeries
            (
            long    idxChannel,
            long    idxSeries,
            long&   countPoints,
            bool    noShare
            )
{
    bool        status = false;
    int         idx;
    double *    arValues = NULL;

    CPQDIF_Element *        pel;
    CPQDIF_E_Collection *   pcol;
    CPQDIF_E_Scalar *       psc;
    CPQDIF_E_Vector *       pvectSeriesArray;

    long        typePhysical;
    PQDIFValue  value;
    double      valueReal;

    double      rBaseValue = 1.0;
    double      rScale = 1.0;
    double      rOffset = 0.0;

    long        idxChannelDefn = 0;

    string      name;
    UINT4       idPhase;
    GUID        idQuantityType;
    UINT4       idQuantityMeasured;
    UINT4       idQuantityUnits;
    GUID        idQuantityCharacteristic;
    GUID        idValueType;
    UINT4       idStorageMethod;

    bool        gotShareChannel = false;
    bool        gotShareSeries  = false;
    bool        isShared = false;
    UINT4       idxShareChannelIdx = 0;
    UINT4       idxShareSeriesIdx = 0;

    //  Verify that we're in an observation record
    //  Requires a data source record
    if( m_record && m_pds && idxChannel >= 0 && idxSeries >= 0)
    {
        //  Find the channel defn index
        status = GetChannelDefnIdx( idxChannel, idxChannelDefn );

        //  Fail if we got a bogus index
        if( status && idxChannelDefn < 0 )
            status = false;
    }

    //  Gather information from the channel & series definitions
    if( status )
    {
        status = m_pds->GetChannelDefnInfo( idxChannelDefn, name, idPhase, idQuantityType, idQuantityMeasured );
    }
    if( status )
    {
        status = m_pds->GetSeriesDefnInfo( idxChannelDefn, idxSeries,
                    idQuantityUnits, idValueType, idQuantityCharacteristic, idStorageMethod );
    }

    if( status )
    {
        status = false;

        //  Find the series
        pcol = GetOneSeries( idxChannel, idxSeries );
        if( pcol )
        {
            status = TRUE;

            //  Loop through all elements in the series collection
            for( idx = 0; idx < pcol->GetCount(); idx++ )
            {
                pel = pcol->GetElement( idx );
                if( pel )
                {
                    if( pel->GetElementType() == ID_ELEMENT_TYPE_SCALAR )
                    {
                        psc = (CPQDIF_E_Scalar *) pel;

                        //  If it's REAL4 or REAL8, go ahead and pull it out
                        valueReal = 0.0;
                        psc->GetValue( typePhysical, value );
                        if( typePhysical == ID_PHYS_TYPE_REAL4 )
                        {
                            valueReal = value.real4;
                        }
                        if( typePhysical == ID_PHYS_TYPE_REAL8 )
                        {
                            valueReal = value.real8;
                        }

                        if( PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesBaseQuantity ) )
                        {
                            rBaseValue = valueReal;
                        }

                        if( PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesScale ) )
                        {
                            rScale = valueReal;
                        }

                        if( PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesOffset ) )
                        {
                            rOffset = valueReal;
                        }

                        if( PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesShareChannelIdx ) )
                        {
                            gotShareChannel = TRUE;
                            psc->GetValueUINT4( idxShareChannelIdx );
                        }

                        if( PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesShareSeriesIdx ) )
                        {
                            gotShareSeries = TRUE;
                            psc->GetValueUINT4( idxShareSeriesIdx );
                        }
                    }

                    if( pel->GetElementType() == ID_ELEMENT_TYPE_VECTOR
                        && PQDIF_IsEqualGUID( pel->GetTag(), tagSeriesValues ) )
                    {
                        pvectSeriesArray = (CPQDIF_E_Vector *) pel;
                    }

                }   //  if( pel )
            }
        }
    }

    //  Generate the series data
    if( status )
    {
        if( gotShareChannel && gotShareSeries )
        {
            //  We're sharing the series from somwhere else --
            //  generate it from the shared indices
            if( !noShare )
            {
                arValues = NewResolvedSeries( 
                    (long) idxShareChannelIdx, 
                    (long) idxShareSeriesIdx, 
                           countPoints, true );
            }
            else
            {
                //  Can't generate! The file is trying to share a series
                //  from another shared series. This is not legal.
                arValues = NULL;
            }
        }
        else if( pvectSeriesArray )
        {
            //  Generate the new series array
            arValues = _GenerateSeriesData( idxChannelDefn, idStorageMethod, 
                rBaseValue, rScale, rOffset, pvectSeriesArray, countPoints );
        }
        else
        {
            //  Can't generate!
            arValues = NULL;
        }
    }

    return arValues;
}


TIMESTAMPPQDIF * CPQDIF_R_Observation::NewResolvedSeriesTimeStamp
            (
            long    idxChannel,
            long    idxSeries,
            long&   countPoints,
            bool    noShare
            )
{
    TIMESTAMPPQDIF *        result = NULL;

    CPQDIF_E_Collection *   pcol;
    CPQDIF_Element *        pel;
    CPQDIF_E_Scalar *       psc;
    CPQDIF_E_Vector *       pvectSeriesArray;

    //  Shared?
    BOOL    gotShareChannel = FALSE;
    BOOL    gotShareSeries = FALSE;
    UINT4   idxShareChannelIdx = 0;
    UINT4   idxShareSeriesIdx = 0;

    pcol = GetOneSeries( idxChannel, idxSeries );
    if( pcol )
    {
        //  Is this sucker shared?
        pel = pcol->GetElement( tagSeriesShareChannelIdx );
        if( pel && pel->GetElementType() == ID_ELEMENT_TYPE_SCALAR )
        {
            gotShareChannel = TRUE;
            psc = dynamic_cast<CPQDIF_E_Scalar *>( pel );
            psc->GetValueUINT4( idxShareChannelIdx );
        }

        pel = pcol->GetElement( tagSeriesShareSeriesIdx );
        if( pel && pel->GetElementType() == ID_ELEMENT_TYPE_SCALAR )
        {
            gotShareSeries = TRUE;
            psc = dynamic_cast<CPQDIF_E_Scalar *>( pel );
            psc->GetValueUINT4( idxShareSeriesIdx );
        }


        if( gotShareSeries && gotShareSeries && !noShare )
        {
            //  SHARED.
            //  Allow ONE level of recursion -- no more.
            result = NewResolvedSeriesTimeStamp( idxShareChannelIdx, 
                        idxShareSeriesIdx, countPoints, true );
        }
        else
        {
            //  NOT SHARED.
            //  Try to decode it the normal way.
            pel = pcol->GetElement( tagSeriesValues );
            if( pel->GetElementType() == ID_ELEMENT_TYPE_VECTOR )
            {
                pvectSeriesArray = dynamic_cast<CPQDIF_E_Vector *>( pel );


                //  Determine size/allocate space for the timestamp array
                if( pvectSeriesArray->GetCount( countPoints ) )
                {
                    result = new TIMESTAMPPQDIF[ countPoints ];
                    if( result )
                    {
                        //  Is it already in timestamp form?
                        if( pvectSeriesArray->GetPhysicalType() == ID_PHYS_TYPE_TIMESTAMPPQDIF )
                        {
                            //  We're done!
                            countPoints = pvectSeriesArray->GetValuesTimeStamp ( result, countPoints );
                        }
                        else
                        {
                            //  Fabricate it from starting time stamp and second offsets
                            double * seconds = NewResolvedSeries( idxChannel, idxSeries, countPoints, true );
                            if( seconds )
                            {
                                _GenerateTimeStampArray( result, seconds, countPoints );
                                delete [] seconds;
                            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -