| 1 |
/* --------------------------------------------------------------------- */ |
| 2 |
/* NeuroManager - A spike train analysis tool */ |
| 3 |
/* Copyright (c) 2005-2006 RIKEN, Japan. All rights reserved. */ |
| 4 |
/* http://satellite.sourceforge.jp/ */ |
| 5 |
/* --------------------------------------------------------------------- */ |
| 6 |
/* This program is free software; you can redistribute it and/or */ |
| 7 |
/* modify it under the terms of the GNU General Public License */ |
| 8 |
/* as published by the Free Software Foundation; either version 2 */ |
| 9 |
/* of the License, or (at your option) any later version. */ |
| 10 |
/* */ |
| 11 |
/* This program is distributed in the hope that it will be useful, */ |
| 12 |
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 13 |
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
| 14 |
/* GNU General Public License for more details. */ |
| 15 |
/* */ |
| 16 |
/* You should have received a copy of the GNU General Public License */ |
| 17 |
/* along with this program; see the file COPYING.txt. If not, write */ |
| 18 |
/* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth */ |
| 19 |
/* Floor, Boston, MA 02110-1301, USA. */ |
| 20 |
/* --------------------------------------------------------------------- */ |
| 21 |
|
| 22 |
/* $Id: SpikeData.cpp,v 1.1 2006/02/02 07:33:27 orrisroot Exp $ */ |
| 23 |
|
| 24 |
// SpikeData.cpp : implementation of the CSpikeData class |
| 25 |
// |
| 26 |
|
| 27 |
#include "stdafx.h" |
| 28 |
#include "MultiChannelData.h" |
| 29 |
#include "SpikeData.h" |
| 30 |
|
| 31 |
CSpikeData::CSpikeData() |
| 32 |
{ |
| 33 |
m_pMCData = NULL; |
| 34 |
m_iChannelNumber = -1; |
| 35 |
m_uDataSize = 0; |
| 36 |
m_nWidth = 0; |
| 37 |
m_pqwDataPos = NULL; |
| 38 |
m_pdData = NULL; |
| 39 |
m_piComponent = NULL; |
| 40 |
} |
| 41 |
|
| 42 |
CSpikeData::~CSpikeData() |
| 43 |
{ |
| 44 |
if ( m_uDataSize > 0 ) |
| 45 |
{ |
| 46 |
// free memory |
| 47 |
delete [] m_pqwDataPos; |
| 48 |
for ( UINT i = 0; i < m_uDataSize; i++ ) |
| 49 |
delete [] m_pdData[ i ]; |
| 50 |
delete [] m_pdData; |
| 51 |
delete [] m_piComponent; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
int CSpikeData::GetChannelNumber() |
| 56 |
{ |
| 57 |
ASSERT( m_pMCData != NULL ); |
| 58 |
return m_iChannelNumber; |
| 59 |
} |
| 60 |
|
| 61 |
UINT CSpikeData::GetSize() |
| 62 |
{ |
| 63 |
ASSERT( m_pMCData != NULL ); |
| 64 |
return m_uDataSize; |
| 65 |
} |
| 66 |
|
| 67 |
SIZE_T CSpikeData::GetWidth() |
| 68 |
{ |
| 69 |
ASSERT( m_pMCData != NULL ); |
| 70 |
return m_nWidth; |
| 71 |
} |
| 72 |
|
| 73 |
QWORD CSpikeData::GetDataPos( UINT num ) |
| 74 |
{ |
| 75 |
ASSERT( m_pMCData != NULL ); |
| 76 |
ASSERT( m_uDataSize > num ); |
| 77 |
return m_pqwDataPos[ num ]; |
| 78 |
} |
| 79 |
|
| 80 |
double **CSpikeData::GetParsedData() |
| 81 |
{ |
| 82 |
ASSERT( m_pMCData != NULL ); |
| 83 |
ASSERT( m_uDataSize > 0 ); |
| 84 |
return m_pdData; |
| 85 |
} |
| 86 |
|
| 87 |
BOOL CSpikeData::Initialize( CMultiChannelData *pMCData, UINT ch ) |
| 88 |
{ |
| 89 |
ASSERT( pMCData != NULL ); |
| 90 |
ASSERT( pMCData->IsMapped() ); |
| 91 |
ASSERT( pMCData->GetChannelNumber() > ch ); |
| 92 |
m_pMCData = pMCData; |
| 93 |
m_iChannelNumber = ch; |
| 94 |
return TRUE; |
| 95 |
} |
| 96 |
|
| 97 |
BOOL CSpikeData::SetWidth( SIZE_T width ) |
| 98 |
{ |
| 99 |
ASSERT( m_pMCData != NULL ); |
| 100 |
ASSERT( m_pMCData->IsMapped() ); |
| 101 |
ASSERT( m_nWidth == 0 ); // must be zero |
| 102 |
m_nWidth = width; |
| 103 |
return TRUE; |
| 104 |
} |
| 105 |
|
| 106 |
BOOL CSpikeData::AddSpike( QWORD pos ) |
| 107 |
{ |
| 108 |
ASSERT( m_pMCData != NULL ); |
| 109 |
ASSERT( m_pMCData->IsMapped() ); |
| 110 |
ASSERT( m_nWidth != 0 ); // must be already initialized spike width |
| 111 |
// allocate memory |
| 112 |
double *data_mem = new double[ m_nWidth ]; |
| 113 |
double **data_array = new double*[ m_uDataSize + 1 ]; |
| 114 |
QWORD *data_pos = new QWORD[ m_uDataSize + 1 ]; |
| 115 |
int *comp_num = new int[ m_uDataSize + 1 ]; |
| 116 |
SIZE_T len = m_nWidth; |
| 117 |
// get data from raw data file |
| 118 |
m_pMCData->AttachData( m_iChannelNumber ); |
| 119 |
for ( SIZE_T i = 0; i < len; i++ ) |
| 120 |
data_mem[ i ] = m_pMCData->GetData( pos + i ); |
| 121 |
m_pMCData->DetachData(); |
| 122 |
// set new data array to allocated memory |
| 123 |
for ( UINT i = 0; i < m_uDataSize; i++ ) |
| 124 |
{ |
| 125 |
data_array[ i ] = m_pdData[ i ]; |
| 126 |
data_pos[ i ] = m_pqwDataPos[ i ]; |
| 127 |
comp_num[ i ] = m_piComponent[ i ]; |
| 128 |
} |
| 129 |
data_array[ m_uDataSize ] = data_mem; |
| 130 |
// free old memory |
| 131 |
if ( m_uDataSize > 0 ) |
| 132 |
{ |
| 133 |
delete [] m_pdData; |
| 134 |
delete [] m_pqwDataPos; |
| 135 |
delete [] m_piComponent; |
| 136 |
} |
| 137 |
// replace member variables |
| 138 |
m_pdData = data_array; |
| 139 |
m_pqwDataPos = data_pos; |
| 140 |
m_piComponent = comp_num; |
| 141 |
m_uDataSize++; |
| 142 |
return TRUE; |
| 143 |
} |
| 144 |
|