Пример #1
0
int hivpopulation::write_genotypes(ostream &out, int sample_size, string gt_label, int start, int length){
	if (HIVPOP_VERBOSE) cerr<<"hivpopulation::write_genotypes()...";
	if (HIVPOP_VERBOSE) cerr<<"start = "<<start<<"...";
	if (HIVPOP_VERBOSE) cerr<<"length = "<<length<<"...";

	if (out.bad()){
		cerr<<"hivpopulation::write_genotypes(): BAD OUTPUT FILE!"<<endl;
		return HIVPOP_BADARG;
	}else{
		int gti;
		string temp;
		if (length <= 0)
			length = number_of_loci - start;

		produce_random_sample(sample_size);
		if (sample_size>get_population_size()){
			cerr<<"hivpopulation::write_genotypes(): requested sample size exceeds population size"<<endl;
			return HIVPOP_BADARG;
		}else{
			for (int s=0; s<sample_size; s++){
				gti=random_clone();
				out <<">GT-"<<gt_label<<"_"<<gti<<'\n';
				for (int i =start; i<start+length; i++ ){
					if (population[gti].genotype[i]) out <<'1';
					else out <<'0';
				}
				out<<'\n';
			}
		}
		if (HIVPOP_VERBOSE) cerr<<"...done."<<endl;
		return 0;
	}
}
Пример #2
0
//write coeff to a stream. This will write pairs of bistrings and values to the stream
int hypercube_lowd::write_coeff(ostream &out, bool label)
{
	int i,k;
	if (out.bad())
	{
		cerr <<"hypercube_lowd::write_coeff: bad stream\n";
		return HC_BADARG;
	}
	i=0;
	while(out.good() && i<(1<<dim))
	{
		if (label)
		{
			for (k=0; k<dim; k++)
			{
				if (i&(1<<k)) out <<'1';
				else out <<'0';
			}
			out <<"  ";
		}
		out <<coeff[i]<<endl;
		i++;
	}
	if (i<(1<<dim))
	{
		cerr <<"hypercube_lowd::write_coeff: error while writing!\n";
		return HC_BADARG;
	}
	return 0;

}
Пример #3
0
//--------------------------------------------------
bool ofBuffer::writeTo(ostream & stream) const {
	if(stream.bad()){
		return false;
	}
	stream.write(&(buffer[0]), buffer.size() - 1);
	return true;
}
Пример #4
0
//=============================================================================
// Function: DumpSymbols
//
// Parameters:
//      LPTSTR lpszLibPathName    - The library file path name
//      CStdioFile* pFile         - Address of the file in which to dump the symbols
//
// Description:
//
// Given a library file path name, the function dumps the symbol info into the file
// pointed to by pFile.
//=============================================================================
BOOL CLibSymbolInfo::DumpSymbols(LPTSTR lpszLibPathName, ostream& pFile)
{
  if(lpszLibPathName == NULL || pFile.bad() ) {
    assert(lpszLibPathName != NULL);
    assert(pFile.good());
    m_strErrorMsg.assign("NULL <lpszLibPathName> or Invalid file handle.");
    return FALSE;
  }

  if(!Dump(lpszLibPathName, pFile))  return FALSE;
  return TRUE;
}
Пример #5
0
//write func to a stream
int hypercube_lowd::write_func(ostream &out)
{
	int i;
	if (out.bad())
	{
		cerr <<"hypercube_lowd::write_func: bad stream\n";
		return HC_BADARG;
	}
	i=0;
	while(out.good() && i<(1<<dim))
	{
		out <<func[i]<<endl;
		i++;
	}
	if (i<(1<<dim))
	{
		cerr <<"hypercube_lowd::write_func: error while writing!\n";
		return HC_BADARG;
	}
	return 0;

}
Пример #6
0
uint64_t PackUtils::Unpack(istream& in, uint64_t size, ostream& out)
{
	uint64_t result = 0;
	int ret;
	uint64_t remaining = size;
	uint64_t have;
	z_stream strm;

	char readBuf[PackUtils::CHUNK];
	char writeBuf[PackUtils::CHUNK];

	/* allocate inflate state */
	strm.zalloc = Z_NULL;
	strm.zfree = Z_NULL;
	strm.opaque = Z_NULL;
	strm.avail_in = 0;
	strm.next_in = Z_NULL;

	ret = inflateInit(&strm);
	
	if (ret != Z_OK)
		return 0;

	/* decompress until deflate stream ends or end of file */
	do 
	{
		strm.avail_in = PackUtils::CHUNK;
		if(remaining < PackUtils::CHUNK)
		{
			strm.avail_in = (uInt)remaining;
		}
		remaining -= strm.avail_in;

		if(!in.read(readBuf, strm.avail_in))
		{
			strm.avail_in = (uInt)in.gcount();
		}

		if (in.bad()) 
		{
			(void)inflateEnd(&strm);
			return 0;
		}

		if (strm.avail_in == 0)
			break;

		strm.next_in = (Bytef*) readBuf;

		/* run inflate() on input until output buffer not full */
		do 
		{
			strm.avail_out = CHUNK;
			strm.next_out = (Bytef*) writeBuf;
			ret = inflate(&strm, Z_NO_FLUSH);
			
			switch (ret) 
			{
				case Z_NEED_DICT:
					ret = Z_DATA_ERROR;     /* and fall through */
				case Z_DATA_ERROR:
				case Z_MEM_ERROR:
					(void)inflateEnd(&strm);
					return 0;
			}

			have = CHUNK - strm.avail_out;

			result += have;
			
			out.write(writeBuf, have);

			if (out.bad()) 
			{
				(void)inflateEnd(&strm);
				return 0;
			}

		} while (strm.avail_out == 0);

		/* done when inflate() says it's done */
	} while (ret != Z_STREAM_END);

	/* clean up and return */
	(void)inflateEnd(&strm);
	return ret == Z_STREAM_END ? result : 0;
}
Пример #7
0
uint64_t PackUtils::Pack(istream& in, ostream& out)
{
	uint64_t result = 0;

	char readBuf[PackUtils::CHUNK];
	char writeBuf[PackUtils::CHUNK];

	int ret, flush;
	uint64_t have;
	z_stream strm;

	/* allocate deflate state */
	strm.zalloc = Z_NULL;
	strm.zfree = Z_NULL;
	strm.opaque = Z_NULL;
	ret = deflateInit(&strm, Z_DEFAULT_COMPRESSION);

	// Couldn't init deflate
	if (ret != Z_OK)
	{
		return 0;
	}

	do
	{
		strm.avail_in = PackUtils::CHUNK;

		if(!in.read(readBuf, PackUtils::CHUNK))
		{
			strm.avail_in = (uInt)in.gcount();
		}

		if(in.bad())
		{
			(void)deflateEnd(&strm);
			return 0;
		}
		flush = (in.eof() || strm.avail_in == 0) ? Z_FINISH : Z_NO_FLUSH;
		strm.next_in = (Bytef*) readBuf;

		/* run deflate() on input until output buffer not full, finish
		compression if all of source has been read in */
		do 
		{
			strm.avail_out = CHUNK;
			strm.next_out = (Bytef*) writeBuf;
			ret = deflate(&strm, flush);    /* no bad return value */

			have = CHUNK - strm.avail_out;

			result += have;
			out.write(writeBuf, have);

			if (out.bad()) 
			{
				(void) deflateEnd(&strm);
				return 0;
			}
		} while (strm.avail_out == 0);

		/* done when last data in file processed */
	} while (flush != Z_FINISH);

	/* clean up and return */
	(void)deflateEnd(&strm);

	in.clear();

	return result;
}