bool rab::BuildDiffFile( Options const& options, Config const& config, DiffEncoders const& diffEncoders, Path_t const& relativePath, PackageOutput_t& package, LogOutput_t& out, FileInfo& fileInfo ) { Path_t fullNew = options.pathToNew / relativePath / fileInfo.name; Path_t fullOld = options.pathToOld / relativePath / fileInfo.name; Path_t relativeTemp = relativePath / DiffFileName(fileInfo.name, config); dung::MemoryBlock oldFile; if( !ReadWholeFile( fullOld.wstring(), oldFile ) ) { out << "Can't read file " << FileString(fullOld) << std::endl; return false; } dung::SHA1Compute( oldFile.pBlock, oldFile.size, fileInfo.oldSha1 ); fileInfo.oldSize = oldFile.size; if( MatchName( config.oldSkipChanged_regex, fileInfo.name ) ) return true; dung::MemoryBlock newFile; if( !ReadWholeFile( fullNew.wstring(), newFile ) ) { out << "Can't read file " << FileString(fullNew) << std::endl; return false; } dung::SHA1Compute( newFile.pBlock, newFile.size, fileInfo.newSha1 ); fileInfo.newSize = newFile.size; bool result = true; if( fileInfo.newSha1 != fileInfo.oldSha1 ) { fileInfo.isDifferent = true; result &= CreateDiffFile( options, diffEncoders, fileInfo, fullNew, fullOld, relativeTemp, newFile, oldFile, package, out ); } else fileInfo.isDifferent = false; return result; }
bool Open(const char* path){ char* buffer; if(ReadWholeFile(buffer, path) == 0) return false; GLDEBUG(mID = OpenGL::CreateShader(GL_VERTEX_SHADER_ARB)); GLDEBUG(OpenGL::ShaderSource(mID, 1, (const GLchar**)&buffer, NULL)); GLDEBUG(OpenGL::CompileShader(mID)); delete [] buffer; return true; }
int main(int argc, char *argv[]) { try { eavlExecutor::SetExecutionMode(eavlExecutor::PreferGPU); eavlInitializeGPU(); if (argc != 3 && argc != 4) THROW(eavlException,"Incorrect number of arguments"); // Read the input eavlDataSet *data = ReadWholeFile(argv[1]); eavlField *f = data->GetField(argv[2]); if (f->GetAssociation() != eavlField::ASSOC_CELL_SET) THROW(eavlException, "Wanted a cell-centered field."); string cellsetname = f->GetAssocCellSet(); int cellsetindex = data->GetCellSetIndex(cellsetname); eavlCellToNodeRecenterMutator *cell2node = new eavlCellToNodeRecenterMutator; cell2node->SetDataSet(data); cell2node->SetField(argv[2]); cell2node->SetCellSet(data->GetCellSet(cellsetindex)->GetName()); cell2node->Execute(); if (argc == 4) { cerr << "\n\n-- done with surface normal, writing to file --\n"; WriteToVTKFile(data, argv[3], cellsetindex); } else { cerr << "No output filename given; not writing result\n"; } cout << "\n\n-- summary of data set result --\n"; data->PrintSummary(cout); } catch (const eavlException &e) { cerr << e.GetErrorText() << endl; cerr << "\nUsage: "<<argv[0]<<" <infile.vtk> <fieldname> [<outfile.vtk>]\n"; return 1; } return 0; }
bool rab::CreateDiffFile( Options const& options, DiffEncoders const &diffEncoders, FileInfo& fileInfo, Path_t const& fullNew, Path_t const& fullOld, Path_t const& relativeTemp, dung::MemoryBlock const& newFile, dung::MemoryBlock const& oldFile, PackageOutput_t &package, LogOutput_t& out ) { Path_t fullTemp = relativeTemp.filename(); if( options.produceTemp ) { fullTemp = options.pathToTemp / relativeTemp; fs::create_directories( fullTemp.parent_path() ); } dung::DiffEncoder_i* pEncoder = diffEncoders.FindEncoder( fileInfo.name, fileInfo.diffMethod ); if( pEncoder != NULL ) { out << "Encoding " << fileInfo.diffMethod << " diff file " << GenericString( relativeTemp ) << std::endl; dung::MemoryBlock deltaFile; if( !pEncoder->EncodeDiffMemoryBlock( newFile.pBlock, newFile.size, oldFile.pBlock, oldFile.size, deltaFile.pBlock, deltaFile.size ) ) { _tstring errorMessage; pEncoder->GetErrorMessage( errorMessage ); out << "Encoding error: " << errorMessage << std::endl; return false; } if( options.produceTemp ) { if( !WriteWholeFile( fullTemp.wstring(), deltaFile ) ) { out << "Can't write file " << GenericString( fullTemp ) << std::endl; return false; } } if( !package.WriteFile( GenericString( relativeTemp ), deltaFile.pBlock, deltaFile.size ) ) { out << "Can't write file " << GenericString( relativeTemp ) << " to package. Size=" << deltaFile.size << std::endl; return false; } } else { dung::DiffEncoderExternal_i* pExternalEncoder = diffEncoders.FindExternalEncoder( fileInfo.name, fileInfo.diffMethod ); if( pExternalEncoder != NULL ) { out << "Encoding " << fileInfo.diffMethod << " diff file " << GenericString( relativeTemp ) << std::endl; if( !pExternalEncoder->EncodeDiffFile( GenericString(fullNew).c_str(), GenericString(fullOld).c_str(), GenericString(fullTemp).c_str() ) ) { _tstring errorMessage; pExternalEncoder->GetErrorMessage( errorMessage ); out << "Encoding error: " << errorMessage << std::endl; return false; } dung::MemoryBlock deltaFile; if( !ReadWholeFile( fullTemp.generic_string(), deltaFile ) ) { out << "Can't read file " << GenericString(fullTemp) << std::endl; return false; } if( !options.produceTemp ) fs::remove( fullTemp ); if( !package.WriteFile( GenericString(relativeTemp), deltaFile.pBlock, deltaFile.size ) ) { out << "Can't write file " << GenericString(relativeTemp) << " to package. Size=" << deltaFile.size << std::endl; return false; } } else { out << "Can't file encoder for file " << fileInfo.name << std::endl; return false; } } return true; }
void CFile::TryConvertIncbin() { std::string idents[6] = { "INCBIN_S8", "INCBIN_U8", "INCBIN_S16", "INCBIN_U16", "INCBIN_S32", "INCBIN_U32" }; int incbinType = -1; for (int i = 0; i < 6; i++) { if (CheckIdentifier(idents[i])) { incbinType = i; break; } } if (incbinType == -1) return; int size = 1 << (incbinType / 2); bool isSigned = ((incbinType % 2) == 0); long oldPos = m_pos; long oldLineNum = m_lineNum; m_pos += idents[incbinType].length(); SkipWhitespace(); if (m_buffer[m_pos] != '(') { m_pos = oldPos; m_lineNum = oldLineNum; return; } m_pos++; SkipWhitespace(); if (m_buffer[m_pos] != '"') RaiseError("expected double quote"); m_pos++; int startPos = m_pos; while (m_buffer[m_pos] != '"') { if (m_buffer[m_pos] == 0) { if (m_pos >= m_size) RaiseError("unexpected EOF in path string"); else RaiseError("unexpected null character in path string"); } if (m_buffer[m_pos] == '\r' || m_buffer[m_pos] == '\n') RaiseError("unexpected end of line character in path string"); if (m_buffer[m_pos] == '\\') RaiseError("unexpected escape in path string"); m_pos++; } std::string path(&m_buffer[startPos], m_pos - startPos); m_pos++; SkipWhitespace(); if (m_buffer[m_pos] != ')') RaiseError("expected ')'"); m_pos++; std::printf("{"); int fileSize; std::unique_ptr<unsigned char[]> buffer = ReadWholeFile(path, fileSize); if ((fileSize % size) != 0) RaiseError("Size %d doesn't evenly divide file size %d.\n", size, fileSize); int count = fileSize / size; int offset = 0; for (int i = 0; i < count; i++) { int data = ExtractData(buffer, offset, size); offset += size; if (isSigned) std::printf("%d,", data); else std::printf("%uu,", data); } std::printf("}"); }
int main(int argc, char *argv[]) { try { eavlExecutor::SetExecutionMode(eavlExecutor::PreferGPU); eavlInitializeGPU(); if (argc != 4 && argc != 5) THROW(eavlException,"Incorrect number of arguments"); // Read the input eavlDataSet *data = ReadWholeFile(argv[1]); eavlBinaryMathMutator *math = new eavlBinaryMathMutator(); math->SetDataSet(data); math->SetField1(argv[2]); math->SetField2(argv[3]); math->SetOperation(eavlBinaryMathMutator::Add); math->SetResultName(string(argv[2]) + "_plus_" + argv[3]); math->Execute(); math->SetOperation(eavlBinaryMathMutator::Subtract); math->SetResultName(string(argv[2]) + "_minus_" + argv[3]); math->Execute(); math->SetOperation(eavlBinaryMathMutator::Multiply); math->SetResultName(string(argv[2]) + "_times_" + argv[3]); math->Execute(); eavlUnaryMathMutator *umath = new eavlUnaryMathMutator(); umath->SetDataSet(data); umath->SetOperation(eavlUnaryMathMutator::Negate); umath->SetField(argv[2]); umath->SetResultName(string("neg_") + argv[2]); umath->Execute(); umath->SetField(argv[3]); umath->SetResultName(string("neg_") + argv[3]); umath->Execute(); if (argc == 5) { cerr << "\n\n-- done with operations, writing to file --\n"; WriteToVTKFile(data, argv[4]); } else { cerr << "No output filename given; not writing result\n"; } cout << "\n\n-- summary of data set result --\n"; data->PrintSummary(cout); } catch (const eavlException &e) { cerr << e.GetErrorText() << endl; cerr << "\nUsage: "<<argv[0]<<" <infile.vtk> <field1name> <field2name> [<outfile.vtk>]\n"; return 1; } return 0; }
void ReadReads(const Option & opt, const CReference * refGenome, const CHashTable * hashTable) { FILE * fout = fopen(opt.outputFile.c_str(), "wb"); CRead * reads, *reads_rev; CRegion * region; char * strReads; MEMORY_ALLOCATE_CHECK( reads = (CRead *) malloc(MAX_MAPPING_READS * sizeof(CRead))); MEMORY_ALLOCATE_CHECK( reads_rev = (CRead *) malloc(MAX_MAPPING_READS * sizeof(CRead))); MEMORY_ALLOCATE_CHECK( region = (CRegion *) malloc( MAX_MAPPING_READS * TOTAL_SHIFT_rev * sizeof(CRegion))); /* read reads from the file*/ INFO("read reads from", opt.readsFile); SIZE_T readsLen = ReadWholeFile(opt.readsFile, &strReads); char strRead[MAX_LINE_LEN]; SIZE_T nReadsNum = 0; SIZE_T readID = 0; map < SIZE_T, SIZE_T > mapPosCount; for (SIZE_T i = 0; i < readsLen; i++) { SIZE_T len = GetLineFromString(&strReads[i], strRead); i += len; if (strRead[0] != '>' && len != 0) { CHECK_READ_LEN(len, nReadsNum); strcpy(reads[nReadsNum].readInStr, strRead); reads[nReadsNum].readLen = len; nReadsNum++; } if (nReadsNum == MAX_MAPPING_READS || (nReadsNum > 0 && i >= readsLen - 1)) { Reverse_Kernel(reads, reads_rev, nReadsNum); SIZE_T NUM = TOTAL_SHIFT_rev * nReadsNum; TIME_INFO( Match_Kernel(refGenome, hashTable, reads, reads_rev, region, NUM), "match time"); for (SIZE_T i = 0; i < NUM; i++) { for (SIZE_T j = region[i].lower; j <= region[i].upper; j++) { mapPosCount[hashTable->index[j] - i % TOTAL_SHIFT]++; } if ((i + 1) % TOTAL_SHIFT == 0) { for (map<SIZE_T, SIZE_T>::iterator it = mapPosCount.begin(); it != mapPosCount.end(); it++) { if (it->second > 1) { fprintf(fout, "read %d: %d %d\n", i / TOTAL_SHIFT_rev, it->first, it->second); } } mapPosCount.clear(); } } readID += nReadsNum; nReadsNum = 0; } } fclose(fout); free(strReads); free(reads); free(region); }
static LoadedSound LoadWaveFile( char* filePath, Stack* allocater ) { #define RIFF_CODE( a, b, c, d ) ( ( (uint32)(a) << 0 ) | ( (uint32)(b) << 8 ) | ( (uint32)(c) << 16 ) | ( (uint32)(d) << 24 ) ) enum { WAVE_ChunkID_fmt = RIFF_CODE( 'f', 'm', 't', ' ' ), WAVE_ChunkID_data = RIFF_CODE( 'd', 'a', 't', 'a' ), WAVE_ChunkID_RIFF = RIFF_CODE( 'R', 'I', 'F', 'F' ), WAVE_ChunkID_WAVE = RIFF_CODE( 'W', 'A', 'V', 'E' ) }; #pragma pack( push, 1 ) struct WaveHeader{ uint32 RIFFID; uint32 size; uint32 WAVEID; }; struct WaveChunk { uint32 ID; uint32 size; }; struct Wave_fmt { uint16 wFormatTag; uint16 nChannels; uint32 nSamplesPerSec; uint32 nAvgBytesPerSec; uint16 nBlockAlign; uint16 wBitsPerSample; uint16 cbSize; uint16 wValidBitsPerSample; uint32 dwChannelMask; uint8 SubFormat [8]; }; #pragma pack( pop ) LoadedSound result = { }; void* fileData = ReadWholeFile( filePath, allocater, NULL ); if( fileData != NULL ) { struct RiffIterator { uint8* currentByte; uint8* stop; }; auto ParseChunkAt = []( WaveHeader* header, void* stop ) -> RiffIterator { return { (uint8*)header, (uint8*)stop }; }; auto IsValid = []( RiffIterator iter ) -> bool { return iter.currentByte < iter.stop; }; auto NextChunk = []( RiffIterator iter ) -> RiffIterator { WaveChunk* chunk = (WaveChunk*)iter.currentByte; //This is for alignment: ( ptr + ( targetalignment - 1 ) & ~( targetalignment - 1)) aligns ptr with the correct bit padding uint32 size = ( chunk->size + 1 ) & ~1; iter.currentByte += sizeof( WaveChunk ) + size; return iter; }; auto GetChunkData = []( RiffIterator iter ) -> void* { void* result = ( iter.currentByte + sizeof( WaveChunk ) ); return result; }; auto GetType = []( RiffIterator iter ) -> uint32 { WaveChunk* chunk = (WaveChunk*)iter.currentByte; uint32 result = chunk->ID; return result; }; auto GetChunkSize = []( RiffIterator iter) -> uint32 { WaveChunk* chunk = (WaveChunk*)iter.currentByte; uint32 result = chunk->size; return result; }; WaveHeader* header = (WaveHeader*)fileData; assert( header->RIFFID == WAVE_ChunkID_RIFF ); assert( header->WAVEID == WAVE_ChunkID_WAVE ); uint32 channelCount = 0; uint32 sampleDataSize = 0; void* sampleData = 0; for( RiffIterator iter = ParseChunkAt( header + 1, (uint8*)( header + 1 ) + header->size - 4 ); IsValid( iter ); iter = NextChunk( iter ) ) { switch( GetType( iter ) ) { case WAVE_ChunkID_fmt: { Wave_fmt* fmt = (Wave_fmt*)GetChunkData( iter ); assert( fmt->wFormatTag == 1 ); //NOTE: only supporting PCM assert( fmt->nSamplesPerSec == 48000 ); assert( fmt->wBitsPerSample == 16 ); channelCount = fmt->nChannels; }break; case WAVE_ChunkID_data: { sampleData = GetChunkData( iter ); sampleDataSize = GetChunkSize( iter ); }break; } } assert( sampleData != 0 ); result.sampleCount = sampleDataSize / ( channelCount * sizeof( uint16 ) ); result.channelCount = channelCount; if( channelCount == 1 ) { result.samples[0] = (int16*)sampleData; result.samples[1] = 0; } else if( channelCount == 2 ) { } else { assert(false); } } return result; }