📄 rec_observ.cpp
字号:
}
}
}
}
}
}
return result;
}
bool CPQDIF_R_Observation::GetChannelDefnIdx
(
long idxChannel,
long& idxChannelDefn
)
{
bool status = false;
CPQDIF_E_Collection * pcollOneChannel;
CPQDIF_E_Scalar * psc;
UINT4 idx;
// Init
status = false;
idxChannelDefn = 0;
// Find the channel
pcollOneChannel = GetOneChannel( idxChannel );
if( pcollOneChannel )
{
// This is where the index should be
psc = m_record->FindScalarInCollection( pcollOneChannel, tagChannelDefnIdx );
if( psc )
{
status = psc->GetValueUINT4( idx );
idxChannelDefn = (long) idx;
status = TRUE;
}
}
return status;
}
CPQDIF_E_Collection * CPQDIF_R_Observation::GetChannelInstances( void )
{
CPQDIF_E_Collection * pcollChannels;
// Create the collection if it does not yet exist.
pcollChannels = m_record->FindCollectionInCollection( m_record->m_pcollMain, tagChannelInstances );
if( !pcollChannels )
{
pcollChannels = (CPQDIF_E_Collection *) theFactory.NewElement( ID_ELEMENT_TYPE_COLLECTION );
if( pcollChannels )
{
pcollChannels->SetTag( tagChannelInstances );
m_record->m_pcollMain->Add( pcollChannels );
}
}
return pcollChannels;
}
CPQDIF_E_Collection * CPQDIF_R_Observation::GetOneChannel( long idxChannel )
{
CPQDIF_E_Collection * pcolReturn = NULL;
CPQDIF_E_Collection * pcolInstances = GetChannelInstances();
CPQDIF_Element * pel;
if( pcolInstances )
{
pel = pcolInstances->GetElement( idxChannel );
if( pel )
{
if( pel->GetElementType() == ID_ELEMENT_TYPE_COLLECTION
&& PQDIF_IsEqualGUID( pel->GetTag(), tagOneChannelInst ) )
{
pcolReturn = (CPQDIF_E_Collection *) pel;
}
}
}
return pcolReturn;
}
CPQDIF_E_Collection * CPQDIF_R_Observation::GetSeriesInstances
(
CPQDIF_E_Collection * pcolChannel
)
{
return m_record->FindCollectionInCollection( pcolChannel, tagSeriesInstances );
}
CPQDIF_E_Collection * CPQDIF_R_Observation::GetOneSeries
(
CPQDIF_E_Collection * pcolChannel,
long idxSeries
)
{
CPQDIF_E_Collection * pcolReturn = NULL;
CPQDIF_E_Collection * pcolSeriesInstances = NULL;
CPQDIF_Element * pel;
if( pcolChannel )
{
// Get the series instances for this channel instance
pcolSeriesInstances = GetSeriesInstances( pcolChannel );
if( pcolSeriesInstances )
{
// Find the specific series instance
pel = pcolSeriesInstances->GetElement( idxSeries );
if( pel )
{
if( pel->GetElementType() == ID_ELEMENT_TYPE_COLLECTION
&& PQDIF_IsEqualGUID( pel->GetTag(), tagOneSeriesInstance ) )
{
// Return it!
pcolReturn = (CPQDIF_E_Collection *) pel;
}
}
}
}
return pcolReturn;
}
CPQDIF_E_Collection * CPQDIF_R_Observation::GetOneSeries
(
long idxChannel,
long idxSeries
)
{
CPQDIF_E_Collection * pcolReturn = NULL;
CPQDIF_E_Collection * pcolOneChannel = NULL;
pcolOneChannel = GetOneChannel( idxChannel );
pcolReturn = GetOneSeries( pcolOneChannel, idxSeries );
return pcolReturn;
}
long CPQDIF_R_Observation::_GenerateSeriesCount
(
UINT4 idStorageMethod,
CPQDIF_E_Vector * pvectSeriesArray
)
{
long countPoints = 0;
if( idStorageMethod & ID_SERIES_METHOD_VALUES )
{
// Straight vector.
pvectSeriesArray->GetCount( countPoints );
}
else if( idStorageMethod & ID_SERIES_METHOD_INCREMENT )
{
// Incremental storage method ... some assembly required.
long countValues;
long idxValue;
double rCount;
// Read in the rate change list
pvectSeriesArray->GetCount( countValues );
if( countValues > 0 )
{
// Grab only the point counts at indices 1, 3, 5, ...
for( idxValue = 1; idxValue < countValues; idxValue += 2 )
{
pvectSeriesArray->GetValue( idxValue, rCount );
countPoints += (long) rCount;
}
}
}
else
{
// No third option!
}
return countPoints;
}
double * CPQDIF_R_Observation::_GenerateSeriesData
(
int idxChannelDefn,
UINT4 idStorageMethod,
double rBaseValue,
double rScale,
double rOffset,
CPQDIF_E_Vector * pvectSeriesArray,
long& countPoints
)
{
double * arValues = NULL;
double * prTempValues;
long idxPoint;
long countValues;
long idxValue;
bool useScale = false;
bool useCal = false;
// Unused parameter
rBaseValue = rBaseValue;
// Get raw number of values in the vector. This may be the actual
// number of points.
pvectSeriesArray->GetCount( countValues );
// Determine how many total points
countPoints = _GenerateSeriesCount( idStorageMethod, pvectSeriesArray );
if( idStorageMethod & ID_SERIES_METHOD_VALUES )
{
// Straight vector. No assembly necessary.
// The two counts must be identical.
if( countPoints > 0 && countPoints == countValues )
{
// We already have the number of points...
arValues = new double[ countPoints ];
prTempValues = arValues;
for( idxPoint = 0; idxPoint < countPoints; idxPoint++, prTempValues++ )
{
pvectSeriesArray->GetValue( idxPoint, *prTempValues );
}
}
}
else if( idStorageMethod & ID_SERIES_METHOD_INCREMENT )
{
// Incremental storage method ... some assembly required.
double valueNext;
double rCount;
double rRate ;
long countChanges;
long idxChange;
long countPointsThisChange;
// Go through the rate change list and generate the array.
if( countPoints > 0 )
{
arValues = new double[ countPoints ];
if( arValues )
{
// Init -- get ready for loops
prTempValues = arValues;
valueNext = 0.0; // First item will be zero
// Determine total number of rate changes [0]
pvectSeriesArray->GetValue( 0, rCount );
countChanges = (long) rCount;
// Get counts and rate changes ...
for( idxChange = 0; idxChange < countChanges; idxChange++ )
{
// Calculate index into value array ...
idxValue = ( idxChange * 2 ) + 1;
// Get data ...
pvectSeriesArray->GetValue( idxValue + 0, rCount ); // Count @ rate
pvectSeriesArray->GetValue( idxValue + 1, rRate ); // Rate
countPointsThisChange = (long) rCount;
// Generate points from the data ...
for( idxPoint = 0; idxPoint < countPointsThisChange; idxPoint++, prTempValues++ )
{
// Store current point.
*prTempValues = valueNext;
// Calculate next point.
valueNext += rRate;
} // for( points );
} // for( changes )
}
}
}
else
{
// No third option!
arValues = NULL;
}
// Scale & offset?
if( idStorageMethod & ID_SERIES_METHOD_SCALED )
{
// Scale/offset should already be set.
useScale = true;
}
else
{
// Default values for scale/offset
rScale = 1.0;
rOffset = 0.0;
useScale = false;
}
// CT/PT ratios?
useCal = _GetCalibrationRatio( idxChannelDefn, rScale );
if( useCal )
{
// The scale has now been adjusted to apply
// the calibration ratio.
useScale = true;
}
// Adjust, if necessary.
if( useScale )
{
if( arValues && countPoints > 0 )
{
prTempValues = arValues;
for( idxPoint = 0; idxPoint < countPoints; idxPoint++, prTempValues++ )
{
// Apply scale first, then offset
*prTempValues *= rScale;
*prTempValues += rOffset;
} // for( points );
}
}
return arValues;
}
bool CPQDIF_R_Observation::_GenerateTimeStampArray
(
TIMESTAMPPQDIF * result,
double * seconds,
long countPoints
)
{
bool status = false;
TIMESTAMPPQDIF tsStart;
TIMESTAMPPQDIF tsTemp;
string name;
TIMESTAMPPQDIF * resTempCurrent = result;
TIMESTAMPPQDIF * resTempPrevious = result;
double * secTemp = seconds;
// Get start time for the entire observation
status = GetInfo( tsStart, tsTemp, name );
if( status )
{
// Note that we start at 1, since we already
// have the timestamp for
for( long idx = 0; idx < countPoints; idx++,
resTempCurrent++, resTempPrevious++, secTemp++ )
{
if( idx == 0 )
{
// Get starting time
*resTempCurrent = tsStart;
// Back up one so the next one gets the correct
// previous time.
resTempPrevious--;
}
else
{
// Get previous time
*resTempCurrent = *resTempPrevious;
}
// Add seconds to it
resTempCurrent->sec += *secTemp;
// Wrap over day?
while( resTempCurrent->sec >= (double) SECONDS_PER_DAY )
{
resTempCurrent->day++;
resTempCurrent->sec -= (double) SECONDS_PER_DAY;
}
} // for( stamps )
}
return status;
}
bool CPQDIF_R_Observation::_GetCalibrationRatio
(
int idxChannelDefn,
double& rScale
)
{
bool status = false;
bool gotInfo;
TIMESTAMPPQDIF tsTemp;
bool useCal = false;
bool useTrans = false; // Not used
long countChannels;
long idxChannel;
UINT4 idxChannelDefnCurrent;
UINT4 triggerTypeID;
REAL8 fullScale;
REAL8 noiseFloor;
REAL8 triggerLow;
REAL8 triggerHigh;
REAL8 triggerRate;
CPQDIF_E_Vector triggerShapeParam;
UINT4 xdTransformerTypeID;
REAL8 xdSystemSideRatio;
REAL8 xdMonitorSideRatio;
CPQDIF_E_Vector xdFrequencyResponse;
if( m_psett )
{
gotInfo = m_psett->GetInfo( tsTemp, tsTemp, tsTemp, useCal, useTrans );
if( gotInfo && useCal )
{
countChannels = m_psett->GetCountChannels();
for( idxChannel = 0; idxChannel < countChannels; idxChannel++ )
{
gotInfo = m_psett->GetChannelInfo( idxChannel, idxChannelDefnCurrent,
triggerTypeID, fullScale, noiseFloor,
triggerLow, triggerHigh, triggerRate, triggerShapeParam );
if( gotInfo )
{
// Is this the information for the correct channel defn?
if( idxChannelDefn == (int) idxChannelDefnCurrent )
{
gotInfo = m_psett->GetChanTrans( idxChannel,
xdTransformerTypeID,
xdSystemSideRatio, xdMonitorSideRatio,
xdFrequencyResponse );
if( gotInfo )
{
// Looks like we got it...
rScale *= xdMonitorSideRatio;
rScale /= xdSystemSideRatio;
status = true;
break;
}
}
}
}
}
}
return status;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -