void write(int count) { // append the data to the file file.write((const char*)&data[0], count * sizeof(T)); typename vector<T>::iterator i; for(i=data.begin();i!=data.end();i++) { txtfile << *i << endl; } data.clear(); // erase the data }
bool succintCode::write(ofstream& fout) { if(fout) { fout.write((char*)&_size,sizeof(_size)); fout.write((char*)&z,sizeof(z)); fout.write((char*)&w,sizeof(w)); if(rt->write(fout) && qt->write(fout)) { return true; } else { return false; } } else { return false; } }
int save_file_integralg3(double** integral_data, int anzahl_sets) { for(int ii = 0; ii < (anzahl_sets * anzahl_sets); ii++){ for(int jj = 0; jj < 8; jj++){ filek_groundstate.write((char*) &integral_data[ii][jj], sizeof(double)); } } return(0); }
int StatRandomVibrationSimulation::sampletofile(int nstep, ofstream& record) { long streampos=record.tellp(); //nt sz=U->Size(); // record.write(reinterpret_cast<const char*>(&time), sizeof(time)); // double val; for( int i=0 ; i<nstep; i++) { val=(*samplExc)(i); record.write( reinterpret_cast<const char*>(&val), sizeof( val)); } for(int i=0 ; i<nstep; i++) { val=(*samplResp)(i); record.write( reinterpret_cast<const char*>(&val), sizeof( val)); } record.flush(); return streampos; }
void WriteHeader() { // set up the header before we write the data so it's easier to put in the // correct values for(int i = 0; i < files.size(); i++) { int o = 0; outfile.write((char*)&o, 4); // offset outfile.write((char*)&o, 4); // size } }
/** * @brief writeSample Write a sample out to a file * @param sample * @param file */ void writeSample(short sample, ofstream &file) { // Calculate sample offset int sampleOffset = 44 + (this->samplesWritten * 2); // Seek to location of next sample and write file.seekp(sampleOffset); file.write((char*)&sample, sizeof(sample)); // Increment number samples written this->samplesWritten++; }
void MachLin::WriteData(ofstream &outf) { int s=odim*idim + odim; outf.write((char*) &s,sizeof(int)); s=sizeof(REAL); outf.write((char*) &s,sizeof(int)); #ifdef BLAS_CUDA cudaSetDevice(cuda_dev); REAL *local_mem=new REAL[odim*idim]; cublasGetVector(odim*idim,CUDA_SIZE,w,1,local_mem,1); cuda_check_error("transfer of weight matrix from GPU memory"); outf.write((char*)local_mem,odim*idim*sizeof(REAL)); delete [] local_mem; local_mem=new REAL[odim]; cublasGetVector(odim,CUDA_SIZE,b,1,local_mem,1); cuda_check_error("transfer of bias vector from GPU memory"); outf.write((char*)local_mem,odim*sizeof(REAL)); delete [] local_mem; #else outf.write((char*) w,odim*idim*sizeof(REAL)); outf.write((char*) b,odim*sizeof(REAL)); #endif }
static bool write_coltable() { rgb_color white,black; white.blue=255; white.red=255; white.green=255; black.blue=0; black.red=0; black.green=0; fout.write((char *) &(white.blue), sizeof(char)); if (!fout.good()) return 0; fout.write((char *) &(white.green), sizeof(char)); if (!fout.good()) return 0; fout.write((char *) &(white.red), sizeof(char)); if (!fout.good()) return 0; fout.write((char *) &(black.blue), sizeof(char)); if (!fout.good()) return 0; fout.write((char *) &(black.green), sizeof(char)); if (!fout.good()) return 0; fout.write((char *) &(black.red), sizeof(char)); if (!fout.good()) return 0; //fout.write((char *) &(black.alpha), sizeof(char)); //if (!fout.good()) return 0; return 1; }
void DistanceMatrix::writeHorizontalFirstLine( vector<ProteinSequence> p, ofstream& oFile, string tab ) { ScoreMatrix convert; vector<string> SeqNumber; int countSeq = 0; //oFile.write( tab.c_str(), tab.size()); for( size_t i = 0; i < p.size(); i++ ) { oFile.write( tab.c_str(), tab.size()); if ( i > 0) { oFile.write( tab.c_str(), tab.size()); } countSeq++; string s = "S"; string seqNum = convert.number_to_string(countSeq); s = s + seqNum; SeqNumber.push_back(s); oFile.write( s.c_str(), s.size() ); } }
// Called when an audio frame arrives virtual bool WriteFrame() { if (!started) return false; size_t frameSize = GetDataSize(); if (!frameSize) return true; if (!buf) buf = new char[frameSize]; GetData(buf, frameSize); f.write(buf, frameSize); return true; }
static void _PutRecord(ofstream& os, Array<String>& fields) { for (Uint32 i = 0, n = fields.size(); i < n; i++) { // Calling getCString to ensure utf-8 goes to the file // Calling write to ensure no data conversion by the stream CString buffer = _Escape(fields[i]).getCString(); os.write((const char *)buffer, static_cast<streamsize>(strlen((const char *)buffer))); os << endl; } os << endl; }
bool store_snaps_direct(ofstream& ofs, vector<snapshot_t>& vecSnaps, Source_Props& properties){ properties.scomSnap.clear(); for (uint32_t i = 0; i < vecSnaps.size(); ++i){ vector < U32 > scom; for (uint32_t j = 0; j < vecSnaps[i].size(); ++j){ ofs.write((char *)&*vecSnaps[i][j].begin(), sizeof(U32)*vecSnaps[i][j].size()); scom.push_back(vecSnaps[i][j].size()); } properties.scomSnap.push_back(scom); scom.clear(); } return 1; }
/** Creates the FAT Table @internalComponent @released @param ofstream */ void CFat16FileSystem::CreateFatTable(ofstream& aOutPutStream) { int FATSizeInBytes = (iFAT16BootSector.FatSectors()) * (iFAT16BootSector.BytesPerSector()); // Each FAT16 entries occupies 2 bytes, hence divided by 2 unsigned int totalFatEntries = FATSizeInBytes / 2; unsigned short *FatTable = new unsigned short[totalFatEntries]; unsigned short int clusterCounter = 1; int previousCluster; FatTable[0] = KFat16FirstEntry; /**Say cluster 5 starts at 5 and occupies clusters 7 and 9. The FAT table should have the value 7 at cluster location 5, the value 9 at cluster 7 and 'eof' value at cluster 9. Below algorithm serves this algorithm */ Iterator itr = iClustersPerEntry->begin(); while(itr != iClustersPerEntry->end()) { previousCluster = itr->second; if(iClustersPerEntry->count(itr->first) > 1) { for(unsigned int i = 1; i < iClustersPerEntry->count(itr->first); i++) { FatTable[previousCluster] = (unsigned short)(++itr)->second; previousCluster = itr->second; ++clusterCounter; } } FatTable[previousCluster] = EOF16; itr++; ++clusterCounter; } // Each FAT16 entries occupies 2 bytes, hence multiply by 2 std::string aFatString(reinterpret_cast<char*>(FatTable),clusterCounter*2); delete[] FatTable; if(clusterCounter < totalFatEntries) { // Each FAT16 entries occupies 2 bytes, hence multiply by 2 aFatString.append((totalFatEntries - clusterCounter)*2, 0); } MessageHandler::ReportMessage (INFORMATION,FATTABLEWRITEMSG,"FAT16"); // Write FAT table multiple times depending upon the No of FATS set. unsigned int noOfFats = iFAT16BootSector.NumberOfFats(); for(unsigned int i=0; i<noOfFats; i++) { aOutPutStream.write(aFatString.c_str(),aFatString.length()); } aFatString.erase(); aOutPutStream.flush(); }
//============================================================================= void CLM::Write(ofstream &s, bool binary) { if(!binary){ s << IO::CLM << " " << _patch.size() << " "; _pdm.Write(s); IO::WriteMat(s,_refs); for(size_t i = 0; i < _cent.size(); i++) IO::WriteMat(s,_cent[i]); for(size_t i = 0; i < _visi.size(); i++) IO::WriteMat(s,_visi[i]); for(size_t i = 0; i < _patch.size(); i++){ for(int j = 0; j < _pdm.nPoints(); j++) _patch[i][j].Write(s, binary); } } else{ int t = IOBinary::CLM; s.write(reinterpret_cast<char*>(&t), sizeof(t)); t = _patch.size(); s.write(reinterpret_cast<char*>(&t), sizeof(t)); _pdm.Write(s, binary); IOBinary::WriteMat(s,_refs); for(size_t i = 0; i < _cent.size(); i++) IOBinary::WriteMat(s,_cent[i]); for(size_t i = 0; i < _visi.size(); i++) IOBinary::WriteMat(s,_visi[i]); for(size_t i = 0; i < _patch.size(); i++){ for(int j = 0; j < _pdm.nPoints(); j++){ _patch[i][j].Write(s, binary); // if(j%46==0 && _patch[i][j]._p.size()){ // std::cout << i << " " <<j << std::endl; // std::cout << _patch[i][j]._p[0]._W << std::endl; // } } } } return; }
void Transaction::write(ofstream &fp, LINT cid, LINT incrtid) { if (nitems == 0) return; sort(); tid++; if (cid == 0) // no customer-id; set cust-id to trans-id cid = tid; if (print_cid) fp.write((char *) &cid, sizeof(LINT)); if (incrtid == -1) fp.write((char *) &tid, sizeof(LINT)); else fp.write((char *) &incrtid, sizeof(LINT)); fp.write((char *) &nitems, sizeof(LINT)); fp.write((char *) items, nitems * sizeof(LINT)); //cout << "TTT " << cid << " " << tid << " " << incrtid << " " //<< nitems << endl; }
int HTTPRequest::copyToFile(ofstream& ofs) { size_t contentLength = atoi(getHTTPHeader("Content-Length").c_str()); if (ofs.good()) { ofs.write(m_requestBody.c_str(), contentLength); } if (ofs.bad()) return -1; return 0; }
int addIncludes(ifstream& fin_toModify,ifstream& fin_refMain,ofstream& fout){ string planeText; if(!readFullText2string(fin_toModify,planeText)){ cout<< "read file error"<<endl; return -1; } string refText; readFullText2string(fin_refMain,refText); planeText = refText+planeText; fout.write(planeText.c_str(),planeText.length()); return 0; }
// Writes a line in a binary file // Format: word_id, doc_id, freq_in_doc, position void InvertedIndex::write_line(vector<int> values, ofstream& file, vector<int>::size_type min){ vector<int> aux; if (values.size() > min){ std::copy(values.begin(), min+values.begin(), std::back_inserter(aux)); } else { aux = values; } for (int value : aux){ file.write((char*) &value, sizeof(value)); } }
//Writes a triangle into the STL file void addTriangle(triangle t){ //normal vector1 out.write((char *)&t.normal.x,sizeof(float)); out.write((char *)&t.normal.y,sizeof(float)); out.write((char *)&t.normal.z,sizeof(float)); //vertices out.write((char *)&t.a.x,sizeof(float)); out.write((char *)&t.a.y,sizeof(float)); out.write((char *)&t.a.z,sizeof(float)); out.write((char *)&t.b.x,sizeof(float)); out.write((char *)&t.b.y,sizeof(float)); out.write((char *)&t.b.z,sizeof(float)); out.write((char *)&t.c.x,sizeof(float)); out.write((char *)&t.c.y,sizeof(float)); out.write((char *)&t.c.z,sizeof(float)); out.write(endTag,2); }
void ihexcallback(const uint8_t *ptr, size_t offset, size_t len) { //printf("callback: offset %#zx, len %zu\n", offset, len); // apply the file offset if (fileoffset > offset) { fprintf(stderr, "error: offset in hex file out of range of file offset, o %#zx to %#zx\n", offset, fileoffset); exit(1); } offset -= fileoffset; out.seekp(offset); out.write((const char *)ptr, len); }
static void WriteFinalKeyPart(LineItem *item, ofstream &file) { // Cache key const char *key = item->CaseKey(); int len = item->Length(); // Search for final part of key int ii = len - 1; while (ii >= 0 && IsAlphanumeric(key[ii])) --ii; // Write it int write_count = len - ii - 1; if (write_count > 0) file.write(key + ii + 1, write_count); }
AMI_err operate(const rectangle &in, AMI_SCAN_FLAG *sfin) { if (*sfin) { if (in.xlo < mbr.xlo) mbr.xlo = in.xlo; if (in.ylo < mbr.ylo) mbr.ylo = in.ylo; if (in.xhi > mbr.xhi) mbr.xhi = in.xhi; if (in.yhi > mbr.yhi) mbr.yhi = in.yhi; } else { out.write((char *) &mbr, sizeof(mbr)); cout << mbr.xlo << " " << mbr.ylo << " " << mbr.xhi << " " << mbr.yhi << endl; return AMI_SCAN_DONE; } return AMI_SCAN_CONTINUE; }
void Write(ofstream &out) { // Say how many elements to write. OutputSampleListMap::iterator mapIt; int setSize = listMap.size(); out.write((char*) &setSize, sizeof(int)); int keySize = 0; // Say how large each element is. if (listMap.size() > 0) { keySize = listMap.begin()->first.size(); } out.write((char*)&keySize, sizeof(int)); for (mapIt = listMap.begin(); mapIt != listMap.end(); ++mapIt) { string mapItKey = mapIt->first; out.write((char*) mapItKey.c_str(), sizeof(char) * mapItKey.size()); mapIt->second.Write(out); } int numLengths = lengths.size(); out.write((char*) &numLengths, sizeof(int)); int i; for ( i = 0; i < lengths.size(); i++) { out.write((char*) &lengths[i], sizeof(int)); } }
void invert_image(ifstream &infile, ofstream &outfile, BITMAPFILEHEADER &file_header, BITMAPINFOHEADER &info_header) { RGBQUAD pixel = { 0, 0, 0}; long size; //Size of the file //Getting the size of the stream infile.seekg(0, infile.end); size = infile.tellg(); //Outputting the file headers outfile.write(reinterpret_cast<char*>(&file_header), sizeof(file_header)); outfile.write(reinterpret_cast<char*>(&info_header), sizeof(info_header)); infile.seekg(54, infile.beg); //Moving stream to location 54 to avoid file header values for (int i = 54; i < size; i++) //Loop through all of the pixel data { pixel.rgbBlue = infile.get(); //Read in pixel value pixel.rgbGreen = infile.get(); pixel.rgbRed = infile.get(); pixel.rgbBlue = 255 - pixel.rgbBlue; //Inverts the colour pixel.rgbGreen = 255 - pixel.rgbGreen; pixel.rgbRed = 255 - pixel.rgbRed; outfile.write(reinterpret_cast<char*>(&pixel), 3); } /*Closing the io streams and ending the program*/ infile.close(); outfile.close(); cout << "\nThe operation is completed\nThe file has been closed...\n"; }
void flag_orbits::write_file(ofstream &fp, int verbose_level) { int f_v = (verbose_level >= 1); int i; if (f_v) { cout << "flag_orbits::write_file" << endl; } fp.write((char *) &nb_primary_orbits_lower, sizeof(int)); fp.write((char *) &nb_primary_orbits_upper, sizeof(int)); fp.write((char *) &nb_flag_orbits, sizeof(int)); fp.write((char *) &pt_representation_sz, sizeof(int)); for (i = 0; i < nb_flag_orbits * pt_representation_sz; i++) { fp.write((char *) &Pt[i], sizeof(int)); } for (i = 0; i < nb_flag_orbits; i++) { Flag_orbit_node[i].write_file(fp, 0 /*verbose_level*/); } if (f_v) { cout << "flag_orbits::write_file finished" << endl; } }
void write_to_bin(Datapack *pack, int size, ofstream &outb) { uint8 FSIZE = 28; //1 + 8 + 4 + 2 + 2 + 2 + 8 + 1 for (int i = 0; i < size; ++i) { outb.write((const char *) &(HEADER), 2); outb.write((const char *) &(FSIZE), 1); outb.write((const char *) &(pack[i].packnum), 1); //sizeof(pack[i].packnum) outb.write((const char *) &(pack[i].time), 8); //sizeof(pack[i].time) outb.write((const char *) &(pack[i].freq), 4); //sizeof(pack[i].freq) outb.write((const char *) &(pack[i].sign1), 2); //sizeof(pack[i].sign1) outb.write((const char *) &(pack[i].sign2), 2); //sizeof(pack[i].sign2) outb.write((const char *) &(pack[i].temp1), 2); //sizeof(pack[i].temp1) outb.write((const char *) &(pack[i].temp2), 8); //sizeof(pack[i].temp2) outb.write((const char *) &(pack[i].flags), 1); //sizeof(pack[i].flags) outb.write((const char *) &(pack[i].crc), 1); //sizeof(pack[i].crc) } }
void GDTextureObject::Write(ofstream &fout) const { unsigned int namelen = (unsigned int)name.length(); fout.write( (char*)&namelen, sizeof(namelen) ); fout.write( name.c_str(), namelen ); fout.write( (char*)&dimension, sizeof(dimension) ); fout.write( (char*)&textureFunc, sizeof(textureFunc) ); fout.write( (char*)wrapMode, sizeof(wrapMode) ); fout.write( (char*)borderColor, sizeof(borderColor) ); size_t count = textureFileNames.size(); for( size_t i = 0; i < count; ++i ) { namelen = (unsigned int)textureFileNames[i].length(); fout.write( (char*)&namelen, sizeof(namelen) ); fout.write( textureFileNames[i].c_str(), namelen ); } }
bool store_pairs_direct(ofstream& ofs, vector<pairs_t>& vecPairs, Source_Props& properties){ properties.nMax = 0; properties.nSnap.clear(); properties.mSnap.clear(); vector<U32> nodes; for (uint32_t i = 0; i < vecPairs.size(); ++i){ pairsToNodes(vecPairs[i], nodes); properties.nMax = max(properties.nMax, *max_element(nodes.begin(), nodes.end())); pairsToUniqueNodes(vecPairs[i], nodes); properties.nSnap.push_back(nodes.size()); properties.mSnap.push_back(vecPairs[i].size()); // fill ofs.write((char *)&vecPairs[i].front(), sizeof(pair_t)*vecPairs[i].size()); } return 1; }
bool Serializer::writeInt(ofstream &outfile, int write) { char *buf = new char[4]; bool negative = write < 0; buf[3] = (char)(write / ONE_SHIFT_ZERO); buf[2] = (char)(write / ONE_SHIFT_ONE); buf[1] = (char)(write / ONE_SHIFT_TWO); buf[0] = (char)(write / ONE_SHIFT_THREE); if (negative) buf[0] &= (char)0x80; outfile.write(buf, 4); if (!outfile.good()) return false; return true; }
void cameraBufferFull(uint8_t * buffer) { printf("cam buffer full\n"); //#ifdef USE_SD file.write( (char*) buffer, camera.BUFFER_SIZE); //#endif /*#ifdef USE_TFT uint8_t x = 0; for (uint16_t i = 0; i<camera.BUFFER_SIZE; i+=3) { screen.drawPixel(x++, linesRead, screen.newColor(buffer[i], buffer[i+1], buffer[i+2])); } linesRead++; #else for (uint16_t i = 0; i<camera.BUFFER_SIZE; i+=3) { Serial << _BYTE(buffer[i]) << _BYTE(buffer[i+1]) << _BYTE(buffer[i+2]); } #endif*/ }