Develop and Download Open Source Software

Browse CVS Repository

Contents of /satellite/neuromanager/neuromanager/SpikeData.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Tue Mar 14 13:17:47 2006 UTC (18 years, 1 month ago) by orrisroot
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +2 -3 lines
File MIME type: text/x-c++src
added template code for data type plugins.

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/04 13:38:16 orrisroot Exp $ */
23
24 // SpikeData.cpp : implementation of the CSpikeData class
25 //
26
27 #include "stdafx.h"
28 #include "SpikeData.h"
29
30 CSpikeData::CSpikeData()
31 {
32 m_pMCData = NULL;
33 m_iChannelNumber = -1;
34 m_uDataSize = 0;
35 m_nWidth = 0;
36 m_pqwDataPos = NULL;
37 m_pdData = NULL;
38 m_piComponent = NULL;
39 }
40
41 CSpikeData::~CSpikeData()
42 {
43 if ( m_uDataSize > 0 )
44 {
45 // free memory
46 delete [] m_pqwDataPos;
47 for ( UINT i = 0; i < m_uDataSize; i++ )
48 delete [] m_pdData[ i ];
49 delete [] m_pdData;
50 delete [] m_piComponent;
51 }
52 }
53
54 int CSpikeData::GetChannelNumber()
55 {
56 ASSERT( m_pMCData != NULL );
57 return m_iChannelNumber;
58 }
59
60 UINT CSpikeData::GetSize()
61 {
62 ASSERT( m_pMCData != NULL );
63 return m_uDataSize;
64 }
65
66 SIZE_T CSpikeData::GetWidth()
67 {
68 ASSERT( m_pMCData != NULL );
69 return m_nWidth;
70 }
71
72 QWORD CSpikeData::GetDataPos( UINT num )
73 {
74 ASSERT( m_pMCData != NULL );
75 ASSERT( m_uDataSize > num );
76 return m_pqwDataPos[ num ];
77 }
78
79 double **CSpikeData::GetParsedData()
80 {
81 ASSERT( m_pMCData != NULL );
82 ASSERT( m_uDataSize > 0 );
83 return m_pdData;
84 }
85
86 BOOL CSpikeData::Initialize( CMultiChannelData *pMCData, UINT ch )
87 {
88 ASSERT( pMCData != NULL );
89 ASSERT( pMCData->IsMapped() );
90 ASSERT( pMCData->GetChannelNumber() > ch );
91 m_pMCData = pMCData;
92 m_iChannelNumber = ch;
93 return TRUE;
94 }
95
96 BOOL CSpikeData::SetWidth( SIZE_T width )
97 {
98 ASSERT( m_pMCData != NULL );
99 ASSERT( m_pMCData->IsMapped() );
100 ASSERT( m_nWidth == 0 ); // must be zero
101 m_nWidth = width;
102 return TRUE;
103 }
104
105 BOOL CSpikeData::AddSpike( QWORD pos )
106 {
107 ASSERT( m_pMCData != NULL );
108 ASSERT( m_pMCData->IsMapped() );
109 ASSERT( m_nWidth != 0 ); // must be already initialized spike width
110 // allocate memory
111 double *data_mem = new double[ m_nWidth ];
112 double **data_array = new double * [ m_uDataSize + 1 ];
113 QWORD *data_pos = new QWORD[ m_uDataSize + 1 ];
114 int *comp_num = new int[ m_uDataSize + 1 ];
115 SIZE_T len = m_nWidth;
116 // get data from raw data file
117 m_pMCData->AttachData( m_iChannelNumber );
118 for ( SIZE_T i = 0; i < len; i++ )
119 data_mem[ i ] = m_pMCData->GetData( pos + i );
120 m_pMCData->DetachData();
121 // set new data array to allocated memory
122 for ( UINT i = 0; i < m_uDataSize; i++ )
123 {
124 data_array[ i ] = m_pdData[ i ];
125 data_pos[ i ] = m_pqwDataPos[ i ];
126 comp_num[ i ] = m_piComponent[ i ];
127 }
128 data_array[ m_uDataSize ] = data_mem;
129 // free old memory
130 if ( m_uDataSize > 0 )
131 {
132 delete [] m_pdData;
133 delete [] m_pqwDataPos;
134 delete [] m_piComponent;
135 }
136 // replace member variables
137 m_pdData = data_array;
138 m_pqwDataPos = data_pos;
139 m_piComponent = comp_num;
140 m_uDataSize++;
141 return TRUE;
142 }
143

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26