Exemplo n.º 1
0
void ParseFiles()
{
	int offset = outfile.tellp();
	
	for(int i = 0; i < files.size(); i++)
	{
		ifstream infile(files[i].c_str(), ifstream::binary);
		int size = 0;
		
		infile.seekg(0, ios::end);
		size = infile.tellg();
		infile.seekg(0, ios::beg);
		
		if(size == 0)
			continue;
		
		cout << "[+] " << files[i] << " size[" << setw(8) << setfill('0') << size << "]" << endl;
		
		char *data = new char[size];
		infile.read(data,size);
		outfile.write(data,size);
		delete data;
		
		int curOffset = outfile.tellp();
		outfile.seekp(8*i);
		outfile.write((char*)&offset,4);
		outfile.write((char*)&size,4);
		outfile.seekp(curOffset);
		
		offset += size;
		infile.close();
	}
}
Exemplo n.º 2
0
static bool writeFile(const wstring &res, ofstream &fs, bkplong pos)
{
	static unsigned short magic = 0xFEFF;
	//write in Unicode16-LE
	if (!fs.good())
		return false;
	if (pos >= 0)
		fs.seekp(pos, ios_base::beg);
	else
		fs.seekp(pos + 1, ios_base::end);
	fs.write((const char *)&magic, 2);
	u16string result;
	bkplong s = res.size();
	bkplong s2 = s * sizeof(wchar_t) / sizeof(char16_t);
	result.resize(s2);
#ifdef HAVE_CODECVT
	auto& f = use_facet<codecvt<wchar_t, char16_t, mbstate_t>>(locale());
	mbstate_t mb = mbstate_t();
	char16_t* from_next;
	const wchar_t* to_next;
	f.out(mb, &res[0], &res[s], to_next, &result[0], &result[s2], from_next);
#else
	ucs4toutf16((uint16_t *)&result[0], (uint32_t *)&res[0], s);
#endif
	fs.write((const char *)result.c_str(), 2 * result.length());
	return true;
}
Exemplo n.º 3
0
void CQualLL::CreateFile(ofstream &fp){
	char *block;
  ifstream fileTemp;
	size_t IndexPos = 0, pos_input = 0, end_input = 0, aux = 0, inpos = 1;
	if(CQual.length() != 0){
		CQual = GZcompressString(CQual);
		SaveValue(fileQual, CQual.length());
		SaveValue(fileQual, (char *)CQual.c_str(), CQual.length());
		CQual = "";
	}
	fileQual.close();
	SaveValue(fp, LOSSLESS);
	cds_word Variables[2];
	Variables[0] = IndexRate;
	Variables[1] = numberOfLines;
	SaveValue(fp, Variables, 2);
	buffer = init_buffer();
	buffer_use = 0;
	if(IndexRate > 0){//this will be overwrite at the end
		IndexPos = fp.tellp();
		IndexLine = new cds_word[1 + (numberOfLines + IndexRate - 1)/IndexRate];
		for(cds_word w = 0; w < (1 + (numberOfLines + IndexRate - 1)/IndexRate); w++)
			IndexLine[w] = 0;
		SaveValue(fp, IndexLine, 1 + ((numberOfLines + IndexRate - 1)/IndexRate));
	}
	init_qual = fp.tellp();
	init_qual += 2 * sizeof(size_t);
	SaveValue(fp, init_qual);
	SaveValue(fp, end_qual);

	fileTemp.open(tmp_name.c_str());
	pos_input = fileTemp.tellg();
	fileTemp.seekg(0, std::ifstream::end);
	end_input = fileTemp.tellg();
	fileTemp.seekg(pos_input);
	if(IndexRate > 0)	
		IndexLine[0] = fp.tellp();
	while(pos_input < end_input){
		aux = LoadValue<size_t>(fileTemp);
		block = LoadValue<char>(fileTemp, aux);
		pos_input += aux + sizeof(size_t);
		SaveValue(fp, block, aux);
		if(IndexRate > 0){
			IndexLine[inpos] = fp.tellp();
			inpos ++;
		}
		delete [] block;
	}
	fileTemp.close();
	end_qual = fp.tellp();
	fp.seekp(IndexPos);
	if(IndexRate > 0)
		SaveValue(fp, IndexLine, (1 + (numberOfLines + IndexRate - 1)/IndexRate));
	delete [] buffer;
	fp.seekp(init_qual - sizeof(size_t));
	SaveValue(fp, end_qual);
	fp.seekp(end_qual);
	remove(tmp_name.c_str());
}
Exemplo n.º 4
0
size_t dami::getFileSize(ofstream& file)
{
  size_t size = 0;
  if (file.is_open())
  {
    streamoff curpos = file.tellp();
    file.seekp(0, ios::end);
    size = file.tellp();
    file.seekp(curpos);
  }
  return size;
}
Exemplo n.º 5
0
	void distance(){

		if(System::file().doesExist(_outputDir + "/mat_presenceAbsence_jaccard.bin")){
			_distanceMatrixJaccard.open((_outputDir + "/mat_presenceAbsence_jaccard.bin").c_str(), ios::binary | ios::in);
			_distanceMatrixBrayCurtis.open((_outputDir + "/mat_abundance_braycurtis.bin").c_str(), ios::binary | ios::in);
		}
		else{
			_distanceMatrixJaccard.open((_outputDir + "/mat_presenceAbsence_jaccard.bin").c_str(), ios::binary);
			_distanceMatrixBrayCurtis.open((_outputDir + "/mat_abundance_braycurtis.bin").c_str(), ios::binary);
		}

		bool isSymmetrical = false;
		if(_inputFilename1 == _inputFilename2 && _start_i == _start_j){
			computeDistanceSymetrical();
			isSymmetrical = true;
		}
		else{
			computeDistanceRectangle();
		}


		for(size_t i=0; i<_threads.size(); i++){
			_threads[i]->join();
			delete _threads[i];
			//cout << i << endl;
		}

		_progress->finish();

		//Fill diagonal with 0

		if(isSymmetrical){
			for(size_t i=_start_i; i<_start_i+_n_i; i++){
				size_t j=i;
				u_int64_t pos = i*_nbDataset1*sizeof(DistanceValueType) + (j*sizeof(DistanceValueType));
				_distanceMatrixJaccard.seekp(pos);
				_distanceMatrixBrayCurtis.seekp(pos);
				DistanceValueType nullDist = 0;
				_distanceMatrixJaccard.write((const char*)&nullDist, sizeof(nullDist));
				_distanceMatrixBrayCurtis.write((const char*)&nullDist, sizeof(nullDist));
			}
		}


		_distanceMatrixJaccard.close();
		_distanceMatrixBrayCurtis.close();

		//string command = "cp " + string(_inputFilename1+".ids") + " " + _outputDir + "/matrix_infos.ids ";
		//cout << command << endl;
		//system(command.c_str());
	}
Exemplo n.º 6
0
    /**
     * @brief writeHeader Write the header out to a file
     * @param file
     */
    void writeHeader(ofstream &file)
    {
        // Write out the header information
        file.seekp(0, ios::beg);

        file.write((char*)&this->header, sizeof(this->header));
    }
Exemplo n.º 7
0
int Towers_sm(int disks, int arr1[], int arr2[], int count, bool &ppart, ofstream &fout, ofstream &outfile)
{
	int split;
   	int split_res;
   	int remaining;
 	int remaining_res;
 	int result;
 	int diskssofar;
 	int smallest_so_far;

	for(diskssofar = 1; diskssofar < count; diskssofar++)
	{
		arr2[diskssofar - 1] = 2*(diskssofar) - 1;
		ppart = true;
	}
		
 	if(diskssofar >= count)
 	{
 		for(int a = diskssofar; a <= disks; a++)
		{
			//Resetting "smallest_so_far"
			smallest_so_far = INT_MAX;

			for(split = 1; split < diskssofar; split++)
			{
				remaining = diskssofar - split;
				split_res = arr2[split - 1];

				remaining_res = arr1[remaining - 1];
				result = 2*(split_res) + remaining_res;

				//Only update "smallest_so_far" if "result" is lower
				if(result <= smallest_so_far)
					smallest_so_far = result;
			}
			//Setting the used array to "smallest_so_far"
			arr1[a-1] = smallest_so_far;
			ppart = false;
		}
 	}

 	cout << "The array is: ";
	outfile << "The array is: ";
 	for (int g = 0; g < disks; g++)
 	{
		cout << arr2[g] << " ";
		fout << arr2[g] << " ";
		outfile << arr2[g] << " ";
	}
	cout << endl;
	outfile << endl;

	//Setting the writting stream cursor back to the beginning
	fout.clear();
	fout.seekp(0);

	return arr2[disks - 1];
}
Exemplo n.º 8
0
void Picture::WriteFileHeader(ofstream& fout)const
{
	fout.seekp(0);
	fout.write(fileHeader.fileType,2);
	fout.write((char*)&fileHeader.bfSize,4);
	fout.write((char*)&fileHeader.bfReserved1,2);
	fout.write((char*)&fileHeader.bfReserved2,2);
	fout.write((char*)&fileHeader.bfOffBits,4);
}
Exemplo n.º 9
0
//Modify file content function
bool modelA::modifyContFile(ofstream mdfos,unsigned int startPos,unsigned int endPos,string newContent)
{
	if(endPos<startPos)
		return false;
	else
	{
		//Move ofstream pointer to end position 
		mdfos.seekp(endPos,ios_base::beg);
		//Delete old content
		for(int i=0;i<int(endPos-startPos);i++)
			mdfos.put(char(8));
		//Write new content
		mdfos<<newContent<<flush;
		//Exit and go to begin
		mdfos.clear();
		mdfos.seekp(0,ios_base::beg);
	}

	return true;
}
Exemplo n.º 10
0
    /**
     * @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++;
    }
Exemplo n.º 11
0
    // Called from the consumer since this class is a registered MessageListener.
    virtual void onMessage( const Message* message ) {
        try
        {
            const TextMessage* textMessage =
                dynamic_cast< const TextMessage* >( message );
            string text = "";

            if( textMessage != NULL ) {
                text = textMessage->getText();
                const Topic* destination = dynamic_cast<const Topic*>(textMessage->getCMSDestination());
                destination->getTopicName();

                // Do something with the text, like:
                printf("Number of received message is %d\n",numMessage);
				printf( "Message Received, messageType: %s, message content: %s\n",destination->getTopicName().c_str(), text.c_str() );
				
				// output message into log file

				//open the log file
oFile.open("log_PAS.txt",ios::app);

	//move point to the end of the file, append information at the  end of the log file
	oFile.seekp(0,ios::end);

vector<string> logStr3;
logStr3.push_back("\nMessage Received, messageType: ");
logStr3.push_back(destination->getTopicName().c_str());
logStr3.push_back("\n message content: ");
logStr3.push_back(text.c_str());
logStr3.push_back("\n Number of received Message are : ");
std::stringstream strNum;
strNum << numMessage;
logStr3.push_back(strNum.str());
	copy(logStr3.begin(),logStr3.end(),ostream_iterator<string>(oFile));
//close the log file
	oFile.close();
	numMessage++;



            } else {
                // Log the error
                cerr << "Received a non-text message" << endl;
            }

        } catch (CMSException& e) {
            // Log the error
            cerr << "Opps! B exception happened: " << e.getMessage() << endl;
        }
    }
Exemplo n.º 12
0
void MakeImage::WriteSector(ofstream &stream, int sectorNum, char *data) {

    int writePos = sectorNum * SECTOR_SIZE;

    // get end of file pos
    stream.seekp(0, ios::end);
    int endPos = stream.tellp();

    if(endPos <= writePos) {

        do {
            stream.put(0);
            endPos = stream.tellp();
        }
        while(endPos <= writePos);
    }


    stream.seekp(writePos);
    stream.seekp(0, ios_base::cur);

    stream.write(data, SECTOR_SIZE);

}
Exemplo n.º 13
0
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);
}
Exemplo n.º 14
0
void Picture::WriteInfoHeader(ofstream& fout) const
{
	fout.seekp(14);
	fout.write((char*)&infoHeader.biSize,4);
	fout.write((char*)&infoHeader.biWidth,4);
	fout.write((char*)&infoHeader.biHeight,4);
	fout.write((char*)&infoHeader.biPlanes,2);
	fout.write((char*)&infoHeader.biBitCount,2);
	fout.write((char*)&infoHeader.biCompression,4);
	fout.write((char*)&infoHeader.biSizeImage,4);
	fout.write((char*)&infoHeader.biXPixelsPerMeter,4);
	fout.write((char*)&infoHeader.biYPixelsPerMeter,4);
	fout.write((char*)&infoHeader.biClrUsed,4);
	fout.write((char*)&infoHeader.biClrImportant,4);
}
Exemplo n.º 15
0
//jump to line n in functions
bool MapBuilder::jumpToLine(int n, ifstream &lookFile, ofstream &putFile){ 
   bool newLine = false;   
   
   lookFile.seekg(ios_base::beg); //set cursor to the beginning
   int counter = 0;
   while((n < counter) && (!file.eof())){ //search for n new lines
      if(findsNLChar(lookFile)){ //if you find a new line
         counter++;         //count that
      }
   }
   
   if(!lookFile.eof()){ //if we got to the end before making n lines
      return false; //we never made it
   }
   
   putFile.seekp(lookFile.tellg()); //put the putting pointer to where looking pointer is
   return true;     //successfully got to line n
}
Exemplo n.º 16
0
void __stdcall vcamOpenLog(int verbosity, char* message)
{
#ifdef _DEBUG
	{
		CAutoLock l(&debugLock);
		if (numUsers == 0) {
			BOOL ok = CreateDirectory(VCAM_DEBUG_DIRNAME, NULL);
			if (!ok && GetLastError() == ERROR_ALREADY_EXISTS)
			{
				ok = TRUE;
			}
			if (ok) {
				try {
					debugOut.exceptions(ios::failbit);
					debugOut.open(VCAM_DEBUG_FNAME, ios_base::app);
					// Truncate log if it's too big
					debugOut.seekp(0, ios_base::end);
					if (debugOut.tellp() > 1024 * 256) {
						debugOut.close();
						debugOut.open(VCAM_DEBUG_FNAME, ios_base::trunc);
					}
					openedOK = TRUE;
				}
				catch (...)
				{
					openedOK = FALSE;
				}
			}
			else 
			{
				openedOK = FALSE;
			}
			if (!openedOK && !showedLogWarning)
			{
				Msg("Couldn't open multicam log file,\r\nso no logging will be performed");
				showedLogWarning = TRUE;
			}
		}
		numUsers++;
	}
	vcamLog(verbosity, "%s opened log, numUsers = %d", message, numUsers);
#endif
}
Exemplo n.º 17
0
int main() {
	ifs.open("MTK.txt", ios::in);
	ofs.open("DSC.txt", ios::out);
	int n; // so dinh
	int a[MAX][MAX];
	ifs >> n;
	for( int i = 1; i<=n; i++ ) {
		for( int j = 1; j<=n; j++ ) {
			ifs >> a[i][j];
		}
	}
	ifs.close();
	int count = 0;
	ofs << n << " " << endl << endl << endl;
	for( int i = 1; i<=n; i++ ) {
		for( int j = i+1; j<=n; j++ ) {
			if( a[i][j] ) {
				ofs << i << " " << j << endl;
				count++;
			} 
		}
	}
	ofs.seekp(2);
	ofs << count;
	ofs.close();
	ofs.open("DSK.txt", ios::out);
	ofs << n << endl;
	for( int i = 1; i<=n; i++ ) {
		for( int j = 1; j<=n; j++ ) {
			if( a[i][j] ) {
				ofs << j << " ";
			}
		}
		ofs << endl;
	}
	ofs.close();
	return 0;
}
Exemplo n.º 18
0
void write_data_w_pos(ofstream& out_stream, Word* write_data, int pos){
    out_stream.seekp(pos);
    out_stream.write((char*)&write_data, sizeof(Word));
}
Exemplo n.º 19
0
int main(int argc, char** argv)
{
  ros::init(argc , argv , "qrcode_multi");

  pthread_t thread_getPosition;
  pthread_create(&thread_getPosition,NULL,GetPosition,NULL);

  sleep(5);

  boost::posix_time::ptime now = ros::Time::now().toBoost();
  boost::gregorian::date now_date(now.date());                       //格林尼治时间
  boost::posix_time::time_duration now_time(now.time_of_day().hours(), now.time_of_day().minutes(), now.time_of_day().seconds(), 0);

  out.open("/home/peng/robocup/RC2014_SEU-Jolly_Prelim4_qr.csv");
  out.seekp(0, ios::end); //每次从文件结尾处输入
  out<<"\"qr codes\""<<endl<<"\"1.0\""<<endl<<"\"SEU-Jolly\""<<endl<<"\"China\""<<endl<<"\""<<now_date<<"\""<<endl<<"\""<<now_time<<"\""<<endl<<"\"Prelim4\""<<endl<<endl<<"id,time,text,x,y,z"<<endl;

  long imageNo = 0;
  string infilename;                       //存放图片的名字,序列号.bmp,如1.bmp
  string infilename1;                      //存放图片序列号,如1
  char ch_imageNo[100];
  bool flag_navigation=false;
  char ch_subimg[50];
  string temp_subimg;

  infilename="1.bmp";
  Image image;

  string directory = "/home/peng/robocup/bmp";
  string fullpath;
  int fd , watch;
  bool isCreated = false;
  
    fd = inotify_init();
    char buf[100 * (sizeof(inotify_event) + 0)];
//    cout<<"sizeof inotify_event:"<<sizeof(inotify_event)<<endl;
    ssize_t length;	

	try
	{
	    while(1)
	    {		
			isCreated = false;
			fullpath = directory + "/" + infilename;
		        watch = inotify_add_watch(fd , directory.c_str() , IN_CREATE |IN_MOVED_TO );

	    		infilename1=infilename.substr(0,infilename.length()-4);

			if(access(fullpath.c_str(), F_OK) ==0)
			{
				//cout<<infilename<<" exists"<<endl;
				isCreated = true;
			}

			while(!isCreated)
			{
				//cout<<"waiting for "<<infilename<<endl;
				length = read(fd , buf , sizeof(buf));
				//cout<<"length:"<<length<<endl;	
				if(length < 0)
					break;
				inotify_event *event;
				for (size_t i = 0; i < static_cast<size_t>(length);i += sizeof(inotify_event) + event->len)
				{
		    			event = reinterpret_cast<inotify_event *>(&buf[i]);
				        if (event->len > 0 && infilename == event->name) 
					{
		                		//printf("The file %s was created.\n", event->name);
			        		isCreated = true;
			                        break;
					}
		                }
			
			}
			//cout<<"reading file.."<<endl;
			usleep(200000);
			if(isCreated)
				image.read(fullpath); 
			else
				break;
			
			//cout<<"finish reading .."<<endl;
	//		string expected;
	//		expected = get_expected(infilename);

			  int gresult = 1;
			  int hresult = 1;
			  hresult = test_image_multi_hybrid(image);
			  if(res==0)
			  {
			    cout << "#" <<infilename1 << "  " << "hybrid" <<"  "<<cell_result<<endl;
			    for(size_t i = 0; i < cell_results.size(); i++)
			    {
			    	cout << "#"<<infilename1<<"  "<<cell_results[i]<<endl;
			    }
			  }
			  else
			  {
			    cout << "#"<<infilename1<<"  "<<cell_result<<endl;
			  }
			  cell_results.clear(); //清除每次的结果,然后从新开始

			  if(hresult!=0)
			  {
				  cout<<"     hybrid failed..."<<endl;
				  gresult = test_image_multi_global(image);
				  if(res==0)
				  {
					cout << "#" <<infilename1 << "  " << "globle"  <<"  "<<cell_result<<endl;
					for(size_t i = 0; i < cell_results.size(); i++)
			   		{
			    			cout << "#"<<infilename1<<"  "<<cell_results[i]<<endl;
			    		}
				  }
				  else
				  {
					cout << "#"<<infilename1<<"  "<<cell_result<<endl;
				  }
				  cell_results.clear(); //清除每次的结果,然后从新开始

				  if(gresult!=0)
				  {
					  cout<<"     global failed..."<<endl;
				  }
			  }

			strcpy(ch_imageNo,infilename1.c_str());
			imageNo = atoi(ch_imageNo);
			imageNo++;
			sprintf(ch_imageNo,"%ld.bmp",imageNo);
			infilename=ch_imageNo;

			inotify_rm_watch(fd, watch);
			if(remove(fullpath.c_str()))
			{
				cout<<"Could not remove "<<fullpath<<endl;
			}
	    }
	}
	catch(...)
	{
		cout<<"error occured"<<endl;
	}

  out.close();
  close(fd);
  return 0;

}
Exemplo n.º 20
0
int Towers_lg(int disks, int count, int arr2[], int arr3[], bool &ppart, ifstream &infile, ofstream & outfile, ofstream &fout)
{
	int even = count%2;
	int totres;
	int split;
   	int split_res;
   	int remaining;
 	int remaining_res;
 	int result;
 	int smallest_so_far;
 	int disks1;

	//Setting in reading stream cursor back to the beginning
	infile.clear();
	infile.seekg(0);


	for(disks1 = 1; disks1 < count; disks1++)
 	{
 		arr2[disks1 - 1] = 2*(disks1) - 1;
 		arr3[disks1 - 1] = 2*(disks1) - 1;
 	}

	//If the number of disks is equal to or less than the number of pegs, then calculate based on 2n-1
	if(disks < count)
	{
		cout << "The array is: ";
		outfile << "The array is: ";
		if(even == 0)
		{
			for (int g = 0; g < disks; g++)
			{
				cout << arr2[g] << " ";
				outfile << arr2[g] << " ";
				fout << arr2[g] << " ";
			}
			cout << endl;
			outfile << endl;
			//Setting the writting stream cursor back to the beginning
			fout.clear();
			fout.seekp(0);
			//Making sure the reading stream is at the beginning of the file
			infile.clear();
			infile.seekg(0);

			ppart = true;
			return totres = arr2[disks - 1];
		}
		else
		{
			cout << "The array is: ";
			outfile << "The array is: ";
			for (int r = 0; r < disks; r++)
			{
				cout << arr3[r] << " ";
				outfile << arr3[r] << " ";
				fout << arr3[r] << " ";
			}
			cout << endl;
			outfile << endl;

			//Setting the writting stream cursor back to the beginning
			fout.clear();
			fout.seekp(0);

			//Making sure the reading stream is at the beginning of the file
			infile.clear();
			infile.seekg(0);

			ppart = true;
			return totres = arr3[disks - 1];
		}
	}
	else
	{
		while(!infile.eof())
		{
			for(int z = 0; z < disks; z++)
			{
				infile >> arr2[z];
			}
		}
		//Resetting the reading cursor back to the beginning
		infile.clear();
		infile.seekg(0);

		//Setting the first position in the next array
		arr3[0] = 1;
		
		for(int j = 4; j <= count; j++)
		{
			//Resetting "smallest_so_far"
			smallest_so_far = INT_MAX;

			for(split = 1; split < disks1; split++)
			{
				remaining = disks1 - split;
				split_res = arr3[split - 1];

				remaining_res = arr3[remaining - 1];
				result = 2*(split_res) + remaining_res;

				//Only update "smallest_so_far" if "result" is lower
				if(result <= smallest_so_far)
					smallest_so_far = result;
			}
			//Setting the used array to "smallest_so_far"
			arr2[j - 1] = smallest_so_far;
		}
	
		cout << "The array is: ";
		outfile << "The array is: ";
		for (int g = 0; g < disks; g++)
		{
			cout << arr2[g] << " ";
			outfile << arr2[g] << " ";
			fout << arr2[g] << " ";
		}
		cout << endl;
		outfile << endl;

		//Setting the writting stream cursor back to the beginning
		fout.clear();
		fout.seekp(0);

		//Making sure the reading stream is at the beginning of the file
		infile.clear();
		infile.seekg(0);
		
		ppart = false;
	}
	return totres = arr3[disks - 1];
}
Exemplo n.º 21
0
int main(int argc, char* argv[]) {
	bool quiet = false;

	if (argc < 6) {
		printf("Usage : rsem-parse-alignments refName imdName statName alignFType('s' for sam, 'b' for bam) alignF [-t Type] [-l fn_list] [-tag tagName] [-q]\n");
		exit(-1);
	}

	strcpy(fn_list, "");
	read_type = 0;
	if (argc > 6) {
		for (int i = 6; i < argc; i++) {
			if (!strcmp(argv[i], "-t")) {
				read_type = atoi(argv[i + 1]);
			}
			if (!strcmp(argv[i], "-l")) {
				strcpy(fn_list, argv[i + 1]);
			}
			if (!strcmp(argv[i], "-tag")) {
				SamParser::setReadTypeTag(argv[i + 1]);
			}
			if (!strcmp(argv[i], "-q")) { quiet = true; }
		}
	}

	verbose = !quiet;

	sprintf(groupF, "%s.grp", argv[1]);
	gi.load(groupF);
	sprintf(tiF, "%s.ti", argv[1]);
	transcripts.readFrom(tiF);

	sprintf(datF, "%s.dat", argv[2]);
	sprintf(cntF, "%s.cnt", argv[3]);

	init(argv[2], argv[4][0], argv[5]);

	hit_out.open(datF);

	string firstLine(99, ' ');
	firstLine.append(1, '\n');		//May be dangerous!
	hit_out<<firstLine;

	switch(read_type) {
	case 0 : parseIt<SingleRead, SingleHit>(parser); break;
	case 1 : parseIt<SingleReadQ, SingleHit>(parser); break;
	case 2 : parseIt<PairedEndRead, PairedEndHit>(parser); break;
	case 3 : parseIt<PairedEndReadQ, PairedEndHit>(parser); break;
	}

	hit_out.seekp(0, ios_base::beg);
	hit_out<<N[1]<<" "<<nHits<<" "<<read_type;

	hit_out.close();

	//cntF for statistics of alignments file
	ofstream fout(cntF);
	fout<<N[0]<<" "<<N[1]<<" "<<N[2]<<" "<<(N[0] + N[1] + N[2])<<endl;
	fout<<nUnique<<" "<<nMulti<<" "<<nIsoMulti<<endl;
	fout<<nHits<<" "<<read_type<<endl;
	fout<<"0\t"<<N[0]<<endl;
	for (iter = counter.begin(); iter != counter.end(); iter++) {
		fout<<iter->first<<'\t'<<iter->second<<endl;
	}
	fout<<"Inf\t"<<N[2]<<endl;
	fout.close();

	release();

	if (verbose) { printf("Done!\n"); }

	return 0;
}
Exemplo n.º 22
0
void fseekp(ofstream &fout, streampos offset, ios_base::seekdir way) {
  fout.seekp(offset, way);
}
Exemplo n.º 23
0
//Takes a height array height array of variable length and turns it into an STL file
void writeSTLfromArray(){
	out.open(savefile.c_str(),ios_base::binary);

	uint32_t triangleCount = (width-1)*(height-1)*2;	//number of facets in a void-free surface
	triangleCount += 4*(width-1);	//triangle counts for the walls of the model
	triangleCount += 4*(height-1);
	triangleCount += 2; 			//base triangles
	float planarScale = 40/width;
	float xScale = (float)cos(globalLat);

	if(out.good()){
		for(int i = 0; i < 80; i++){
			out.write("t",1);
		}
		//write a placeholder number
		out.write((char *)&triangleCount,4);
		for(int c = 1; c < width; c++){
			if((int)hList.at(c)>-50 & (int)hList.at(c-1)>-50 & (int)hList.at(c+width-1)>-50 ){
				vertex a = createVertex(c*xScale, 0,hList.at(c));
				vertex b = createVertex((c-1)*xScale, 0,hList.at(c-1));
				vertex d = createVertex((c-1)*xScale, 1,hList.at(c+width-1));
				
				vertex w = createVertex(c*xScale,0,0);				//used in model walls
				vertex z = createVertex((c-1)*xScale,0,0);
				
				addTriangle(createTriangle(a,d,b));
				addTriangle(createTriangle(b,z,a));			//model walls
				addTriangle(createTriangle(w,a,z));
			}else{
				triangleCount-=3;
			}
		}
		for(int y = 1; y < height-1; y++){
			for(int x = 1; x < width; x++){
				if((int)hList.at(y*width+x)>-50 & (int)hList.at((y-1)*width+x)>-50 & (int)hList.at(y*width+x-1)>-50 ){
					vertex a = createVertex(x*xScale,y,hList.at(y*width+x));
					vertex b = createVertex(x*xScale,y-1,hList.at((y-1)*width+x));
					vertex c = createVertex((x-1)*xScale,y,hList.at(y*width+x-1));
					addTriangle(createTriangle(a,c,b));
				}else{
					triangleCount--;
				}
			}
			for(int x = 1; x < width; x++){
				if((int)hList.at(y*width+x)>-50 & (int)hList.at(y*width+x-1)>-50 & (int)hList.at((y+1)*width+x-1)>-50 ){
					vertex a = createVertex(x*xScale,y,hList.at(y*width+x));		//same
					vertex b = createVertex((x-1)*xScale,y,hList.at(y*width+x-1));
					vertex c = createVertex((x-1)*xScale,y+1,hList.at((y+1)*width+x-1));
					addTriangle(createTriangle(a,c,b));
				}else{
					triangleCount--;
				}
			}
		}
		for(int x = 1; x < width; x++){
			if((int)hList.at((height-1)*width+x)>-50 & (int)hList.at((height-2)*width+x)>-50 & (int)hList.at((height-1)*width+x-1)>-50){
				vertex a = createVertex(x*xScale,height-1,hList.at((height-1)*width+x));		//same
				vertex b = createVertex(x*xScale,height-2,hList.at((height-2)*width+x));
				vertex c = createVertex((x-1)*xScale,height-1,hList.at((height-1)*width+x-1));
				
				vertex w = createVertex(x*xScale,height-1,0);		//used in model walls
				vertex z = createVertex((x-1)*xScale,height-1,0);
				
				addTriangle(createTriangle(a,c,b));
				addTriangle(createTriangle(c,a,z));			//model walls
				addTriangle(createTriangle(w,z,a));
			}else{
				triangleCount-=3;
			}
		}
		
		vertex st;
		vertex sb;
		vertex bt;
		vertex bb;
		for(int y = 1; y < width; y++){						//adds walls in the y direction for
			if((int)hList.at(y*width)>-50 & (int)hList.at((y-1)*width)>-50){
				st = createVertex(0,y,hList.at(y*width));			//for x=0 first
				sb = createVertex(0,y-1,hList.at((y-1)*width));
				bt = createVertex(0,y,0);
				bb = createVertex(0,y-1,0);
				
				addTriangle(createTriangle(bb,sb,st));
				addTriangle(createTriangle(st,bt,bb));
			}else{
				triangleCount-=2;
			}
			if((int)hList.at(y*width+width-1)>-50 & (int)hList.at(y*width-1)>-50){
				st = createVertex((width-1)*xScale,y,hList.at(y*width+width-1));		//for x=width next
				sb = createVertex((width-1)*xScale,y-1,hList.at(y*width-1));
				bt = createVertex((width-1)*xScale,y,0);
				bb = createVertex((width-1)*xScale,y-1,0);
				
				addTriangle(createTriangle(sb,bb,st));
				addTriangle(createTriangle(bt,st,bb));
			}else{
				triangleCount-=2;
			}
		}
		
		vertex origin = createVertex(0,0,0);					//create bottom surface
		vertex bottomright = createVertex((width-1)*xScale,0,0);
		vertex topleft = createVertex(0,height-1,0);
		vertex topright = createVertex((width-1)*xScale,height-1,0);
		addTriangle(createTriangle(origin,topright,bottomright));
		addTriangle(createTriangle(origin,topleft,topright));
		//triangleCount-=2;
		
		out.seekp(80);
		out.write((char *)&triangleCount,4);
	}
	cout << triangleCount << "\n";
}
Exemplo n.º 24
0
void write_w_pos(ofstream& out, WORD* write_value, const int pos){
    out.seekp(pos*sizeof(WORD));
    out.write(reinterpret_cast<char*>(write_value), sizeof(WORD));
}
Exemplo n.º 25
0
int Logger::lengthFileLog() {
	fileLog.seekp(0, ios::end);
	int fileLogSize = static_cast<int>(fileLog.tellp());
	return fileLogSize;
}
void ImageType::copyHeaderInBinary(ofstream& imageDestination, ifstream& imageSource)
{
	imageDestination.seekp(0);
	imageSource.seekg(0);
	unsigned char line[COMMENT_LENGTH];

	imageSource.read((char*)line, 3);
	imageDestination.write((char*)line, 3);
	if (width < 10)
	{
		imageSource.read((char*)line, 1);
		imageDestination.write((char*)line, 1);
	}
	else if (width < 100)
	{
		imageSource.read((char*)line, 2);
		imageDestination.write((char*)line, 2);
	}
	else
	{
		imageSource.read((char*)line, 3);
		imageDestination.write((char*)line, 3);
	}
	imageSource.read((char*)line, 1);
	imageDestination.write((char*)line, 1);
	if (height < 10)
	{
		imageSource.read((char*)line, 1);
		imageDestination.write((char*)line, 1);
	}
	else if (height < 100)
	{
		imageSource.read((char*)line, 2);
		imageDestination.write((char*)line, 2);
	}
	else
	{
		imageSource.read((char*)line, 3);
		imageDestination.write((char*)line, 3);
	}
	imageSource.read((char*)line, 1);
	imageDestination.write((char*)line, 1);
	if (maxValue < 10)
	{
		imageSource.read((char*)line, 1);
		imageDestination.write((char*)line, 1);
	}
	else if (maxValue < 100)
	{
		imageSource.read((char*)line, 2);
		imageDestination.write((char*)line, 2);
	}
	else
	{
		imageSource.read((char*)line, 3);
		imageDestination.write((char*)line, 3);
	}
	imageSource.read((char*)line, 1);
	imageDestination.write((char*)line, 1);

}
Exemplo n.º 27
0
void CRPSPreMF::CreateFile(ifstream &SamFile, ofstream &fp, int SamOrRps, vector<cds_word>* IndexClusterToLines){
	cds_word *index;
	size_t index_pos = 0;
	getValuesPreSeq(posWin, WINSIZE); // get for last time the values from winSeq
	for(cds_word j = 0; j < WINSIZE; j++) //free winSeq
		delete [] WinSeq[j];
	delete [] WinSeq;
	if(tmp_file_string.length() > 0){
		fileSeq << tmp_file_string;  //write to fileQual (it must exist)
		tmp_file_string = "";
	}
	ClusterIndex[ClusterIndex.size() - 1] = ClusterReads;
	if(overlapcluster){ //add extra block if there is at least one read overlap with the next block
		ClusterIndex.push_back((cds_word)-1);
		if(IndexClusterToLines != NULL)
			IndexClusterToLines->push_back(numberOfLines);
		ClusterOverlap.push_back(overlapcluster);
	}
	fileSeq.close();
	huffA = new Huffman(occ_notA, 249, true);
	huffC = new Huffman(occ_notC, 249, true);
	huffG = new Huffman(occ_notG, 249, true);
	huffT = new Huffman(occ_notT, 249, true);
	SaveValue(fp, ROW);
	cout << "ClusterSize: " << ClusterOverlap.size() << endl;
	cds_word novacio = 0;
	for(cds_word i = 0; i < ClusterIndex.size()  ; i++){
		if(ClusterIndex[i] != (cds_word)-1)
			novacio++;
	}
	cout << "No vacio: " << novacio << endl;		
	index = &ClusterIndex[0]; //Index data
	if(ClusterIndex.size() != ClusterOverlap.size())
		cout << "Error: Number of blocks created is not correct" << endl;
	SaveValue(fp, (cds_word)ClusterIndex.size());
	index_pos = fp.tellp();
	SaveValue(fp, index, ClusterIndex.size());
	SaveValue(fp, variableSize);
	//if(variableSize){
		index = &ClusterOverlap[0];
		SaveValue(fp, index, ClusterOverlap.size());
	//}	
	cds_word Variables[6];
	Variables[0] = numberOfLinesNR;	Variables[1] = numberOfLines;	Variables[2] = sizeLine.size();
	Variables[3] = preSeqLength;	Variables[4] = (cds_word)(RNames.size()); Variables[5] = IndexRate;
	SaveValue(fp, Variables, 6);
	SaveValue(fp, &sizeLine[0], sizeLine.size());
	for(cds_word i = 0; i < RNames.size(); i++){
		SaveValue(fp, (cds_word)(RNames[i].length()));
		SaveValue(fp, (char *)(RNames[i].c_str()), RNames[i].length());
		SaveValue(fp, RNamesCluster[i]);
	}
	huffA->Save(fp); huffC->Save(fp); huffG->Save(fp); huffT->Save(fp);
	init_preseq = fp.tellp();
	init_preseq += 3 * sizeof(size_t);
	SaveValue(fp, init_preseq);
	SaveValue(fp, init_seq);
	SaveValue(fp, end_seq);
	buffer = init_buffer();
	buffer_use = 0;
	CompressPressumeSeq(fp, &buffer, &buffer_use);
	init_seq = fp.tellp();
	//RE-READ SAM FILE AND CREATE NEW FILE
	ComputeCSeq(SamFile, fp, SamOrRps);
	end_seq = fp.tellp();
	fp.seekp(index_pos);
	index = &ClusterIndex[0];
	SaveValue(fp, index, ClusterIndex.size());
	fp.seekp(init_preseq - 2 * sizeof(size_t));
	SaveValue(fp, init_seq);
	SaveValue(fp, end_seq);
	remove(tmp_name.c_str());
	fp.seekp(end_seq);
}