bool IO_UncertSimResults::ReadUncertResults(DC_UncertSimResults& results) { try { ReadFileHeader(results, true); ReadNextRecord(); ReadInt(); // skip next rec SC_IntArray runStartRecs; ReadIntArray(runStartRecs); results.AllocAndSetSize(runStartRecs.Size()); for (int i = 0; i < results.Size(); i++) { ReadAbsolute(runStartRecs[i]); ReadOneRun(results[i]); } CloseFile(); return true; } catch (BufFileC::BufferFileError& err) { GenAppErrorMsg("ReadUncertResults", err.errMsg); CloseFile(); } return false; }
uint64 FastqParser::ParseFrom(const FastqDataChunk& chunk_, std::vector<FastqRecord>& records_, uint64& rec_count_) { ASSERT(buffer == NULL); memory = (byte*)chunk_.data.Pointer(); memoryPos = 0; memorySize = chunk_.size; rec_count_ = 0; while (memoryPos < memorySize && ReadNextRecord(records_[rec_count_])) { rec_count_++; if (records_.size() < rec_count_ + 1) records_.resize(records_.size() + REC_EXTENSION_FACTOR(records_.size())); } ASSERT(rec_count_ > 0); return chunk_.size - skippedBytes; }
void IO_ProfileSimResults::ReadOneRun(ProfileSimRunResults& runRes) { ReadString(runRes.runID, ProfileSimRunResults::runIDLen); ReadStringArray(runRes.caseValDesc); ReadStringArray(runRes.caseValShortDesc); ReadStringArray(runRes.caseSeqData.sequenceIDs); ReadDoubleArray(runRes.caseSeqData.sequenceStartTimes); // next record contains case start records ReadNextRecord(); SC_IntArray caseStartRecs; ReadIntArray(caseStartRecs); runRes.AllocAndSetSize(caseStartRecs.Size()); // individual case results for (int i = 0; i < runRes.Size(); i++) { ReadAbsolute(caseStartRecs[i]); ReadOneCase(runRes[i]); } }
uint64 FastqParserExt::ParseFrom(const FastqDataChunk &chunk_, std::vector<FastqRecord> &records_, uint64 &rec_count_, uint64 tagPreserveFlags_) { ASSERT(buffer == NULL); ASSERT(tagPreserveFlags_ != 0); uchar tagBuffer[MaxTagBufferSize]; totalBytesCut = 0; memory = (byte*)chunk_.data.Pointer(); memoryPos = 0; memorySize = chunk_.size; rec_count_ = 0; while (memoryPos < memorySize && ReadNextRecord(records_[rec_count_], tagBuffer, tagPreserveFlags_)) { rec_count_++; if (records_.size() < rec_count_ + 1) records_.resize(records_.size() + REC_EXTENSION_FACTOR(records_.size())); } ASSERT(rec_count_ > 0); ASSERT(chunk_.size >= totalBytesCut + skippedBytes); return chunk_.size - totalBytesCut - skippedBytes; }
bool IO_UncertSimResults::AddUncertRun(const DC_UncertSimResults& resultHeader, const UncertRunResults& results, bool addExisting) { GenAppClearMsgs(); bool openExisting = addExisting && ConvFileC::CFfileExists(fileName); DC_UncertSimResults currHeader; if (openExisting) { if (!ReadFileHeader(currHeader, false)) { GenAppErrorMsg("UncertSimResults", "File contents incompatible"); return false; } if ((currHeader.IsMultiple() && (!resultHeader.IsMultiple())) || ((!currHeader.IsMultiple()) && resultHeader.IsMultiple())) { GenAppErrorMsg("UncertSimResults", "Cannot combine multiple & not multiple"); return false; } if (currHeader.IsMultiple()) { if (currHeader.multipleRunVariableIDs.Size() != resultHeader.multipleRunVariableIDs.Size()) GenAppErrorMsg("UncertSimResults", "Multiple run results different size??"); } } try { SC_IntArray runStartRecs; runStartRecs.SetResizable(); int nextRec, runIndexRecord; if (openExisting) { ReadFileHeader(currHeader, true); ReadNextRecord(); runIndexRecord = GetCurrentRec(); nextRec = ReadInt(); ReadIntArray(runStartRecs); } else { OpenFile(fileName, false); // set up initial header info nRuns = 0; WriteFileHeader(resultHeader); FlushBuffer(nextRec); runIndexRecord = nextRec; // initial header BufferReset(nextRec); WriteInt(0); FlushBuffer(nextRec); // backup and set nextRec BufferReset(runIndexRecord); WriteInt(nextRec); // reflush FlushBuffer(); } int runStart = nextRec; // set to next avail BufferReset(nextRec); // add the run to the end WriteOneRun(results, nextRec); nRuns++; // update header BufferReset(0); WriteFileHeader(resultHeader); FlushBuffer(); // update next avail record BufferReset(runIndexRecord); WriteInt(nextRec); // update run start records runStartRecs += runStart; WriteIntArray(runStartRecs); FlushBuffer(); CloseFile(); return true; } catch (BufFileC::BufferFileError& err) { GenAppErrorMsg("WriteUncertResults", err.errMsg); } CloseFile(); return false; }
/*=========================================================================== * ReadContinuousLogData *--------------------------------------------------------------------------- * Description: Puts the node in continuous mode, reads the sensor data and * prints to the screen and logs data to user file until the user * interrupts. * * Return: HANDLE - handle to the opened comport *===========================================================================*/ void ReadContinuousLogData(int portNum) { int iCount = 0; BOOL bStopContinuous = FALSE; DWORD dwcharsRead = 0; I3dmgx3Set Record; BYTE cmd_return; int Curs_posY = 0; int Curs_posX = 0; int status = 0; int error_record = 0; int valid_check = 0; int valid_count = 0; char consoleBuff[60] = {0}; long valid_rec = 0; unsigned char error_cmd; char ComLogFile[256]; FILE *m_logFile; int LogFlag = 0; int error_count = 0; int errorCode =0, i=0; char fw[20] = {0}; char sn[20] = {0}; char mListSep[4]; char mDecSep[4]; LANGID langId; char szLanguage[256]; /*MAX_PATH]; */ char idchar[] = {'\x02', '\x00', '\x01', '\x03', '\x04'}; int m_timerconst = 62500; unsigned long AA_Time_Stamp=0; unsigned long AA_s_prev =0; float AA_convert = 0.0; float AA_prev = 0.0; struct __timeb64 timebuffer; char *timeline; _ftime64( &timebuffer ); timeline = _ctime64( & ( timebuffer.time ) ); while (LogFlag != 1){ printf("Enter Name of LogFile to use:"); scanf("%s", &ComLogFile); // 255); printf("logFile %s\n", ComLogFile); if ( ( m_logFile= fopen( ComLogFile, "w")) == NULL){ printf("File: %s not opened\n", ComLogFile); if(++error_count > 2) return; }else LogFlag = 1; } fprintf(m_logFile, "[SESSION START TAG]\n"); fprintf(m_logFile, "Session Start Time:%.19s.%hu \n", timeline, timebuffer.millitm ); fprintf(m_logFile, "Time Source: HOST\n"); GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SLIST,mListSep,4); fprintf(m_logFile, "List Separator: %s\n", mListSep); GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SDECIMAL,mDecSep,4); fprintf(m_logFile, "Decimal Separator: %s\n", mDecSep); langId = GetSystemDefaultLangID (); i = VerLanguageName (langId, szLanguage, 256); //dwSize = MAX_PATH; fprintf(m_logFile, "Language: %s\n", szLanguage); while(valid_check == 0) { errorCode = i3dmgx3_getFirmwareVersion(portNum, &fw[0]); if (errorCode < 0){ purge_port(portNum); printf("Firmware Error %d\n",errorCode); if (valid_count++ > 6) { printf("Please Halt Current Data Display and Retry, count %d\n", valid_count); return; } }else if (errorCode >= 0){ valid_check = 1; } } /*------------------------------------------------------------------ * 0xEA get serial information number, model and options (as string) *-----------------------------------------------------------------*/ valid_count =0; for ( i=0; i<4; i++){ //cycles through the valid device options errorCode = i3dmgx3_getDeviceIdentiy(portNum, idchar[i], &sn[0]); if (errorCode < 0){ purge_port(portNum); i--; if (valid_count++ >6){ printf("Error Read Device Identity: %s\n", explainError(errorCode)); } } else{ switch( i ) { case 0: fprintf(m_logFile, "Device Name: %s\n",sn); break; case 1: fprintf(m_logFile, "Device Model: %s\n",sn); break; case 2: fprintf(m_logFile, "Device FirmWare Version: %s\n", fw); fprintf(m_logFile, "Device Serial Number: %s\n", sn); break; case 3: fprintf(m_logFile, "Device Options: %s\n", sn); break; case 4: default: break; } } } fprintf(m_logFile, "Command C2\n[DATA START TAG]\n\t Time%s Accel X%s Accel Y%s Accel Z%s AngRate X%s AngRate Y%s AngRate Z%s Ticks\n", mListSep, mListSep, mListSep, mListSep, mListSep, mListSep, mListSep); //put the node in continuous mode status =SetContinuousMode(portNum, 0xC2); printf("setcontinuous is %d", status); //set up the output for the data printf("\n\n"); printf("Reading streaming data (hit s to Stop streaming).\n"); printf("C2___________________________Acceleration_______________________________\n"); printf(" X Y Z \n"); /* acceleration values go here */ printf("\n\n\n"); printf("C2____________________________Angular_Rate______________________________\n"); printf(" X Y Z \n"); /* angle rate values go here */ getConXY(&Curs_posX, &Curs_posY); printf("\n\n\n\n"); //continue until the user hits the <s>top key while(!bStopContinuous) { if(ReadNextRecord(portNum, &Record, &cmd_return) != SUCCESS) error_record++; if (cmd_return == 0xC2){ if (AA_s_prev == 0){ fprintf(m_logFile, "\t 0.00"); AA_s_prev = Record.timer; //AA_Time_Stamp; } else { AA_convert = ((float)(Record.timer - AA_s_prev)/m_timerconst); //19660800); AA_s_prev = Record.timer; //AA_Time_Stamp; AA_prev = AA_prev + AA_convert; fprintf(m_logFile, "\t%6.2f", AA_prev); } //move to the acceleration position and print the data sprintf(consoleBuff, "\t%2.6f\t\t%2.6f\t\t%2.6f", Record.setA[0], Record.setA[1], Record.setA[2]); fprintf(m_logFile, "%s %2.6f%s %2.6f%s %2.6f%s ", mListSep, Record.setA[0],mListSep, Record.setA[1], mListSep, Record.setA[2], mListSep); setConXY(Curs_posX, Curs_posY -5, &consoleBuff[0]); sprintf(consoleBuff, "\t%2.6f\t\t%2.6f\t\t%2.6f", Record.setB[0], Record.setB[1], Record.setB[2]); fprintf(m_logFile, "%2.6f%s %2.6f%s %2.6f%s %u\n", Record.setB[0], mListSep, Record.setB[1], mListSep, Record.setB[2], mListSep, Record.timer); setConXY(Curs_posX, Curs_posY, &consoleBuff[0]); valid_rec++; }else if (cmd_return != 0xc4){ if((cmd_return == 0xCB || cmd_return == 0xD3) && error_record == 0) error_cmd = cmd_return; else error_record++; } //check for a key every 50 iterations if(iCount++ > 50) { int ch = 0; if(ReadCharNoReturn(&ch)){ bStopContinuous = (ch == 's' || ch == 'S'); } //reset the counter iCount = 0; } } printf("\n\n\nStopping Continuous Mode..."); StopContinuousMode(portNum); printf("stopped.\n"); fclose(m_logFile); if (error_record > 0) printf("Number of records received in error were %d and received successfully %d\n", error_record, valid_rec); else printf("All %d records read successfully.\n", valid_rec); }
/*=========================================================================== * ReadContinuousData *--------------------------------------------------------------------------- * Description: Puts the node in continuous mode, reads the sensor data and * prints to the screen until the user interrupts. * * Return: HANDLE - handle to the opened comport *===========================================================================*/ void ReadContinuousData(int portNum) { int iCount = 0; BOOL bStopContinuous = FALSE; DWORD dwcharsRead = 0; I3dmgx3Set Record; BYTE cmd_return; int Curs_posY = 0; int Curs_posX = 0; int status = 0; int error_record = 0; char consoleBuff[60] = {0}; long valid_rec = 0; unsigned char error_cmd; //put the node in continuous mode status =SetContinuousMode(portNum, 0xC2); printf("setcontinuous is %d", status); //set up the output for the data printf("\n\n"); printf("Reading streaming data (hit s to Stop streaming).\n"); printf("C2___________________________Acceleration_______________________________\n"); printf(" X Y Z \n"); /* acceleration values go here, save the position */ printf("\n\n\n"); printf("C2____________________________Angular_Rate______________________________\n"); printf(" X Y Z \n"); /* angle rate values go here, save the position */ getConXY(&Curs_posX, &Curs_posY); printf("\n\n\n\n"); //continue until the user hits the s key while(!bStopContinuous) { if(ReadNextRecord(portNum, &Record, &cmd_return) != SUCCESS) error_record++; if (cmd_return == 0xC2){ //move to the acceleration position and print the data sprintf(consoleBuff, "\t%2.6f\t\t%2.6f\t\t%2.6f", Record.setA[0], Record.setA[1], Record.setA[2]); setConXY(Curs_posX, Curs_posY -5, &consoleBuff[0]); sprintf(consoleBuff, "\t%2.6f\t\t%2.6f\t\t%2.6f", Record.setB[0], Record.setB[1], Record.setB[2]); setConXY(Curs_posX, Curs_posY, &consoleBuff[0]); valid_rec++; }else if (cmd_return != 0xC4){ if((cmd_return == 0xCB || cmd_return == 0xD3) && error_record == 0) error_cmd = cmd_return; else error_record++; } //check for a key every 50 iterations if(iCount++ > 50) { int ch = 0; if(ReadCharNoReturn(&ch)){ bStopContinuous = (ch == 's' || ch == 'S'); } //reset the counter iCount = 0; } } printf("\n\n\nStopping Continuous Mode..."); StopContinuousMode(portNum); printf("stopped.\n"); if (error_record > 0) printf("Number of records received in error were %d and received successfully %d\n", error_record, valid_rec); else printf("All %d records read successfully.\n", valid_rec); }
bool IO_ProfileSimResults::AddSimRun(const ProfileSimRunResults& results, bool addExisting) { GenAppClearMsgs(); bool fileOK = addExisting && ReadFileHeader(false); try { SC_IntArray runStartRecs; runStartRecs.SetResizable(); int nextRec, runIndexRecord; if (fileOK) { ReadFileHeader(true); ReadNextRecord(); runIndexRecord = GetCurrentRec(); nextRec = ReadInt(); ReadIntArray(runStartRecs); } else { OpenFile(fileName, false); WriteStdFileHeader(fileHeader, StringLength(fileHeader) + 1, writeVersion, 0); WriteInt(0); // 0 runs FlushBuffer(nextRec); runIndexRecord = nextRec; // initial header BufferReset(nextRec); WriteInt(0); WriteInt(0); WriteInt(0); FlushBuffer(nextRec); // backup and set nextRec BufferReset(runIndexRecord); WriteInt(nextRec); WriteInt(0); WriteInt(0); // reflush FlushBuffer(); } int runStart = nextRec; // set to next avail BufferReset(nextRec); // add the run to the end WriteOneRun(results, nextRec); nRuns++; // update header BufferReset(0); WriteStdFileHeader(fileHeader, StringLength(fileHeader) + 1, writeVersion, 0); WriteInt(nRuns); FlushBuffer(); // update next avail record BufferReset(runIndexRecord); WriteInt(nextRec); // update run start records runStartRecs += runStart; WriteIntArray(runStartRecs); FlushBuffer(); CloseFile(); return true; } catch (BufFileC::BufferFileError& err) { GenAppErrorMsg("WriteSimResults", err.errMsg); } CloseFile(); return false; }
void DnaPacker::UnpackFromBin(const BinaryBinBlock& binBin_, DnaBin& dnaBin_, uint32 minimizerId_, DataChunk& dnaChunk_, bool append_) { // calculate global bin properties // uint64 recordsCount = 0; for (uint32 i = 0; i < binBin_.descriptors.size(); ++i) { const BinaryBinDescriptor& desc = binBin_.descriptors[i]; recordsCount += desc.recordsCount; } ASSERT(recordsCount < (1 << 28)); // initialize // uint64 recId = 0; if (append_) { recId = dnaBin_.Size(); recordsCount += recId; ASSERT(dnaChunk_.data.Size() >= dnaChunk_.size + binBin_.rawDnaSize); } else { dnaBin_.Clear(); dnaChunk_.size = 0; if (dnaChunk_.data.Size() < binBin_.rawDnaSize) dnaChunk_.data.Extend(binBin_.rawDnaSize); } dnaBin_.Resize(recordsCount); if (recordsCount == 0) return; // configure settings // BinPackSettings settings; char minString[64] = {0}; if (minimizerId_ != params.TotalMinimizersCount()) // N bin? { settings.suffixLen = params.signatureSuffixLen; params.GenerateMinimizer(minimizerId_, minString); } else { settings.suffixLen = 0; } BitMemoryReader metaReader(binBin_.metaData, binBin_.metaSize); BitMemoryReader dnaReader(binBin_.dnaData, binBin_.dnaSize); char* dnaBufferPtr = (char*)dnaChunk_.data.Pointer(); for (uint32 i = 0; i < binBin_.descriptors.size(); ++i) { const BinaryBinDescriptor& desc = binBin_.descriptors[i]; const uint64 initialMetaPos = metaReader.Position(); const uint64 initialDnaPos = dnaReader.Position(); // read bin header // settings.minLen = metaReader.GetBits(LenBits); settings.maxLen = metaReader.GetBits(LenBits); ASSERT(settings.minLen > 0); ASSERT(settings.maxLen >= settings.minLen); settings.hasConstLen = (settings.minLen == settings.maxLen); if (!settings.hasConstLen) { settings.bitsPerLen = bit_length(settings.maxLen - settings.minLen); ASSERT(settings.bitsPerLen > 0); } // read bin records // if (settings.suffixLen > 0) { for (uint32 j = 0; j < desc.recordsCount; ++j) { DnaRecord& rec = dnaBin_[recId++]; rec.dna = dnaBufferPtr + dnaChunk_.size; bool b = ReadNextRecord(metaReader, dnaReader, rec, settings); ASSERT(b); ASSERT(dnaChunk_.size + rec.len <= dnaChunk_.data.Size()); std::copy(minString, minString + params.signatureSuffixLen, rec.dna + rec.minimizerPos); dnaChunk_.size += rec.len; } } else { for (uint32 j = 0; j < desc.recordsCount; ++j) { DnaRecord& rec = dnaBin_[recId++]; rec.dna = dnaBufferPtr + dnaChunk_.size; bool b = ReadNextRecord(metaReader, dnaReader, rec, settings); ASSERT(b); ASSERT(dnaChunk_.size + rec.len <= dnaChunk_.data.Size()); dnaChunk_.size += rec.len; } } metaReader.FlushInputWordBuffer(); dnaReader.FlushInputWordBuffer(); dnaBin_.SetStats(MIN(settings.minLen, dnaBin_.GetStats().minLen), MAX(settings.maxLen, dnaBin_.GetStats().maxLen)); ASSERT(metaReader.Position() - initialMetaPos == desc.metaSize); ASSERT(dnaReader.Position() - initialDnaPos == desc.dnaSize); } }
void DnaPacker::UnpackFromBin(const BinaryBinDescriptor& desc_, DnaBin &dnaBin_, DataChunk& dnaChunk_, BitMemoryReader& metaReader_, BitMemoryReader& dnaReader_, uint32 minimizerId_) { const uint64 recordsCount = desc_.recordsCount; const uint64 initialMetaPos = metaReader_.Position(); const uint64 initialDnaPos = dnaReader_.Position(); ASSERT(recordsCount < (1 << 28)); dnaBin_.Resize(recordsCount); // initialize settings // BinPackSettings settings; settings.minLen = metaReader_.GetBits(LenBits); settings.maxLen = metaReader_.GetBits(LenBits); settings.hasConstLen = (settings.minLen == settings.maxLen); ASSERT(settings.maxLen > 0); ASSERT(settings.maxLen >= settings.minLen); if (minimizerId_ != params.TotalMinimizersCount()) settings.suffixLen = params.signatureSuffixLen; else settings.suffixLen = 0; if (!settings.hasConstLen) { settings.bitsPerLen = bit_length(settings.maxLen - settings.minLen); ASSERT(settings.bitsPerLen > 0); } char* dnaBufferPtr = (char*)dnaChunk_.data.Pointer(); uint64 dnaBufferPos = 0; // unpack records // if (settings.suffixLen > 0) { char minString[64] = {0}; params.GenerateMinimizer(minimizerId_, minString); for (uint32 r = 0; r < recordsCount; ++r) { DnaRecord& rec = dnaBin_[r]; rec.dna = dnaBufferPtr + dnaChunk_.size + dnaBufferPos; bool b = ReadNextRecord(metaReader_, dnaReader_, rec, settings); ASSERT(b); ASSERT(dnaBufferPos + rec.len <= desc_.rawDnaSize); std::copy(minString, minString + params.signatureSuffixLen, rec.dna + rec.minimizerPos); dnaBufferPos += rec.len; } } else { for (uint32 r = 0; r < recordsCount; ++r) { DnaRecord& rec = dnaBin_[r]; rec.dna = dnaBufferPtr + dnaChunk_.size + dnaBufferPos; bool b = ReadNextRecord(metaReader_, dnaReader_, rec, settings); ASSERT(b); ASSERT(dnaBufferPos + rec.len <= desc_.rawDnaSize); dnaBufferPos += rec.len; } } dnaChunk_.size += dnaBufferPos; dnaBin_.SetStats(settings.minLen, settings.maxLen); metaReader_.FlushInputWordBuffer(); dnaReader_.FlushInputWordBuffer(); ASSERT(metaReader_.Position() - initialMetaPos == desc_.metaSize); ASSERT(dnaReader_.Position() - initialDnaPos == desc_.dnaSize); }