67 offsetTimeMs_ = offsetTimeMs;
75 if (fpBegin_ != NULL) {
83 if (fpBegin_ != NULL) {
90 offsetTimeMs_ = offsetTimeMs;
97 offsetTimeMs_ = offsetTimeMs;
101 for (
int i=0; i<nNeur_; i++) {
102 spikesIt_.push_back(spikes_[i].begin());
106 void SpikeGeneratorFromFile::openFile() {
107 std::string funcName =
"openFile("+fileName_+
")";
108 fpBegin_ = fopen(fileName_.c_str(),
"rb");
115 szByteHeader_ = 4*
sizeof(int)+1*
sizeof(
float);
116 fseek(fp,
sizeof(
int)+
sizeof(
float), SEEK_SET);
121 for (
int i=1; i<=3; i++) {
122 size_t result = fread(&grid,
sizeof(
int), 1, fp);
131 void SpikeGeneratorFromFile::init() {
138 for (
int i=0; i<nNeur_; i++) {
139 spikes_.push_back(std::vector<int>());
144 fseek(fp, szByteHeader_, SEEK_SET);
146 std::string funcName =
"readFile("+fileName_+
")";
149 size_t result1, result2;
152 result1 = fread(&tmpTime,
sizeof(
int), 1, fp);
154 result2 = fread(&tmpNeurId,
sizeof(
int), 1, fp);
156 if (result1 + result2 == 2)
157 spikes_[tmpNeurId].push_back(tmpTime);
161 for (
int neurId=0; neurId<1; neurId++) {
162 printf(
"[%d]: ",neurId);
163 for (
int i=0; i<spikes_[neurId].size(); i++) {
164 printf(
"%d ",spikes_[neurId][i]);
176 assert(nid < nNeur_);
178 if (spikesIt_[nid] != spikes_[nid].end()) {
181 if (*(spikesIt_[nid])+offsetTimeMs_ < endOfTimeSlice) {
185 printf(
"[%d][%d]: currTime=%u, lastTime=%u, endOfTime=%u, offsetTimeMs=%u, nextSpike=%u\n", grpId, nid,
186 currentTime, lastScheduledSpikeTime, endOfTimeSlice, offsetTimeMs_,
187 (
unsigned int) (*(spikesIt_[nid])+offsetTimeMs_));
191 return (
unsigned int)(*(spikesIt_[nid]++)+offsetTimeMs_);
CARLsim User Interface This class provides a user interface to the public sections of CARLsimCore sou...
void loadFile(std::string fileName, int offsetTimeMs=0)
Loads a new spike file.
SpikeGeneratorFromFile(std::string fileName, int offsetTimeMs=0)
SpikeGeneratorFromFile constructor.
static void assertTrue(bool statement, errorType errorIfAssertionFails, std::string errorFunc, std::string errorMsgPrefix="", std::string errorMsgSuffix="")
simple wrapper for assert statement
int nextSpikeTime(CARLsim *sim, int grpId, int nid, int currentTime, int lastScheduledSpikeTime, int endOfTimeSlice)
schedules the next spike time
~SpikeGeneratorFromFile()
SpikeGeneratorFromFile destructor.
void rewind(int offsetTimeMs)
Rewinds the spike file to beginning of file.