예제 #1
0
int main(int argc, char *argv[]) {
    // Options
    std::vector<String> opt(3);
    opt[0] = "all";
    opt[1] = "bytes";
    opt[2] = "host";

    // Error if there are not 3 things on the command line
    if (argc != 3)
        { output_usage_and_exit(argv[0], opt); }

    // Open file, quit if open fails
    std::ifstream in(argv[2]);
    if (!in)
        { std::cerr << "Couldn't open " << argv[2] << "\n"; exit(2); }

    // Process the log file
    std::vector<LogEntry> log_entries = parse(in);

    // Close the in file
    in.close();

    // Handle the specified option
   
    String option(argv[1]);
   
    if (option == opt[0]) {
       
      // Output everything
        output_all(std::cout, log_entries);
    }
    else if (option == opt[1]) {
      
      // Output total number of bytes
        std::cout << "Total number of bytes sent: " 
                  << byte_count(log_entries) << std::endl;
    }
    else if (option == opt[2]) {
       
      // Host names will be out-putted here
        by_host(std::cout, log_entries);
    }
    else    {
       
        std::cerr << "Unrecognized option: " << option << std::endl;
        std::cerr << "Recognized options: " 
             << opt[0] << " "
             << opt[1] << " "
             << opt[2] << std::endl;
    }

    return 0;
}
static int pack_double   (grib_accessor* a, const double* val, size_t *len)
{
    grib_accessor_ibmfloat* self = (grib_accessor_ibmfloat*)a;
    int ret = 0;
    unsigned long i = 0;
    unsigned long rlen = *len;
    size_t buflen  = 0;
    unsigned char *buf = NULL;
    long off = 0;

    if(*len < 1)
    {
        grib_context_log(a->parent->h->context, GRIB_LOG_ERROR, " wrong size for %s it pack at least 1 values ", a->name , rlen );
        *len = 0;
        return GRIB_ARRAY_TOO_SMALL;
    }

    if (rlen == 1){
        /*
    double x = 0;
    grib_nearest_smaller_ibm_float(val[0],&x);
    double y = grib_long_to_ibm(grib_ibm_to_long(val[0]));
    printf("IBMFLOAT val=%.20f nearest_smaller_ibm_float=%.20f long_to_ibm=%.20f\n",val[0],x ,y);
         */
        off = byte_offset(a)*8;
        ret =  grib_encode_unsigned_long(a->parent->h->buffer->data,grib_ibm_to_long(val[0]), &off,  32);
        if (*len > 1)  grib_context_log(a->parent->h->context, GRIB_LOG_WARNING, "grib_accessor_unsigned : Trying to pack %d values in a scalar %s, packing first value",  *len, a->name  );
        if (ret == GRIB_SUCCESS) len[0] = 1;
        return ret;
    }

    buflen = rlen*4;

    buf = (unsigned char*)grib_context_malloc(a->parent->h->context,buflen);

    for(i=0; i < rlen;i++){
        grib_encode_unsigned_longb(buf,grib_ibm_to_long(val[i]), &off,  32);
    }
    ret = grib_set_long_internal(a->parent->h,grib_arguments_get_name(a->parent->h,self->arg,0),rlen);

    if(ret == GRIB_SUCCESS)
        grib_buffer_replace(a, buf, buflen,1,1);
    else
        *len = 0;

    grib_context_free(a->parent->h->context,buf);

    a->length = byte_count(a);

    return ret;
}
예제 #3
0
파일: rnd_base.cpp 프로젝트: ref2401/SPARKi
com_ptr<ID3D11Texture2D> make_texture_cube(ID3D11Device* p_device, const texture_data& td,
	D3D11_USAGE usage, UINT bind_flags, UINT misc_flags)
{
	assert(p_device);
	assert(td.type == texture_type::texture_cube);
	assert(td.array_size == 6);
	assert(is_valid_texture_data(td));

	D3D11_TEXTURE2D_DESC desc = {};
	desc.Width = td.size.x;
	desc.Height = td.size.y;
	desc.MipLevels = td.mipmap_count;
	desc.ArraySize = td.array_size;
	desc.Format = make_dxgi_format(td.format);
	desc.SampleDesc.Count = 1;
	desc.SampleDesc.Quality = 0;
	desc.Usage = usage;
	desc.BindFlags = bind_flags;
	desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
	if (misc_flags != 0)
		desc.MiscFlags |= misc_flags;

	const size_t fmt_byte_count = byte_count(td.format);
	const uint8_t* ptr = td.buffer.data();
	std::vector<D3D11_SUBRESOURCE_DATA> data_list(desc.ArraySize * desc.MipLevels);

	for (UINT a = 0; a < desc.ArraySize; ++a) {
		for (UINT m = 0; m < desc.MipLevels; ++m) {
			const UINT w = desc.Width >> m;
			const UINT h = desc.Height >> m;
			const UINT index = a * desc.MipLevels + m;

			data_list[index].pSysMem = ptr;
			data_list[index].SysMemPitch = UINT(w * fmt_byte_count);
			data_list[index].SysMemSlicePitch = 0;
			ptr += w * h * fmt_byte_count;
		}
	}

	com_ptr<ID3D11Texture2D> p_tex;
	HRESULT hr = p_device->CreateTexture2D(&desc, data_list.data(), &p_tex.ptr);
	assert(hr == S_OK);
	return p_tex;
}
예제 #4
0
void GenotypeTable2::initialize() {
    cout << "Initializing GenotypeTable2 ... " << endl;
    alphabet_size = ( int ) alphabet.length();
    possible_genotypes_size = pow( alphabet_size, ( double ) MAX_ALLELE_COUNT ) + 1;   // +1 for 0 -> "unknown" genotype

    cout << "Alphabet Size: " << alphabet_size << endl;
    cout << "Possible Genotype Size: " << possible_genotypes_size << endl;

    assert( possible_genotypes_size < 256 );

    bits_per_gt = ( int ) ceil( log(( double )possible_genotypes_size ) / log( 2.0 ) );

    cout << "Bits per Genotype: " << bits_per_gt << endl;

    local_genotype_count = ( int ) GENOTYPE_FORM_COUNT - 1; // -1 for common 0 across all local
    bits_per_data = ( int ) ceil( log(( double ) local_genotype_count ) / log( 2.0 ) );

    cout << "Bits per Data: " << bits_per_data << endl;

    bits_per_row = bits_per_data * max_column;
    bytes_per_row = byte_count( bits_per_row );

    cout << "Bits per Data Row: " << bits_per_row << endl;
    cout << "Bytes per Data Row: " << bytes_per_row << endl;

    header_bit_len = local_genotype_count * bits_per_gt;  // Each Genotype Record can have at most 3 unique encodings (AA, AB, BB) + 1 unknown (00)
    header_byte_len = local_genotype_count;

    if( data != NULL ) {
        delete [] data;
    }
    data_size = max_row * bytes_per_row;

    cout << "Total Table size: " << data_size << " (bytes)" << endl;

    data = new byte[ data_size ];
    memset( data, 0, data_size );

    if( headers != NULL ) {
        delete [] headers;
    }
    header_size = max_row * header_byte_len;

    cout << "Total Header size: " << header_size << " (bytes)" << endl;

    headers = new byte[ header_size ];
    memset( headers, 0, header_size );

    if( gt_lookup != NULL ) {
        delete [] gt_lookup;
    }

    gt_size =  MAX_ALLELE_COUNT + 1;
    int idx, offset;
    lookup_size = gt_size * possible_genotypes_size;

    gt_lookup = new char[ lookup_size ];    // allocate space for all possible genotypes as null-terminated character sequences
    memset( gt_lookup, ( char )0, lookup_size );
    for( int i = 0; i < possible_genotypes_size; ++i ) {
        if( i > 0 ) {
            idx = i - 1;
            for( int k = 0, l = MAX_ALLELE_COUNT - 1; k < MAX_ALLELE_COUNT; ++k, --l ) {
                offset = idx % alphabet_size;
                gt_lookup[ i *gt_size + l ] = alphabet[offset];
                idx -= offset;
                idx /= alphabet_size;
            }
        } else {
            for( int k = 0; k < MAX_ALLELE_COUNT; ++k ) {
                gt_lookup[ k ] = '0';
            }
        }

        cout << ( gt_lookup + i * gt_size ) << " -> " << i << endl;
    }
    cout << "Initialized Genotype Lookups: " << lookup_size << " (bytes)" << endl;

    setupAlphabetTranslation();
}
예제 #5
0
파일: rnd_base.cpp 프로젝트: ref2401/SPARKi
texture_data make_texture_data(ID3D11Device* p_device, ID3D11DeviceContext* p_ctx, 
	texture_type type, ID3D11Texture2D* p_tex)
{
	assert(p_device);
	assert(p_ctx);
	assert(type != texture_type::unknown);
	assert(p_tex);

	// create a staging texture & fill it with p_tex data.
	D3D11_TEXTURE2D_DESC desc;
	p_tex->GetDesc(&desc);
	desc.Usage = D3D11_USAGE_STAGING;
	desc.BindFlags = 0;
	desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
	desc.MiscFlags = desc.MiscFlags & (~D3D11_RESOURCE_MISC_GENERATE_MIPS);

	com_ptr<ID3D11Texture2D> p_tex_staging;
	HRESULT hr = p_device->CreateTexture2D(&desc, nullptr, &p_tex_staging.ptr);
	assert(hr == S_OK);
	p_ctx->CopyResource(p_tex_staging, p_tex);


#ifdef SPARKI_DEBUG
	if (type == texture_type::texture_cube) assert(desc.ArraySize == 6);
#endif // SPAKIR_DEBUG

	// create a texture_data object
	texture_data td(type, uint3(desc.Width, desc.Height, 1), 
		desc.MipLevels, desc.ArraySize, make_pixel_format(desc.Format));
	
	const size_t fmt_byte_count = byte_count(td.format);
	uint8_t* ptr = td.buffer.data();

	// for each array slice 
	// for each mipmap level of the slice
	// map p_tex_tmp[array_slice][mipmap_level] and copy its' contents into the texture_data object.
	for (UINT a = 0; a < desc.ArraySize; ++a) {
		for (UINT m = 0; m < desc.MipLevels; ++m) {
			const UINT index = D3D11CalcSubresource(m, a, desc.MipLevels);

			D3D11_MAPPED_SUBRESOURCE map;
			hr = p_ctx->Map(p_tex_staging, index, D3D11_MAP_READ, 0, &map);
			assert(hr == S_OK);

			const UINT w = desc.Width >> m;
			const UINT h = desc.Height >> m;
			const size_t mip_bc = w * h * fmt_byte_count;
			assert(mip_bc > 0);
			assert(mip_bc <= map.DepthPitch);

			if (mip_bc == map.DepthPitch) {
				std::memcpy(ptr, map.pData, mip_bc);
				ptr += mip_bc;
			}
			else {
				uint8_t* p_src = reinterpret_cast<uint8_t*>(map.pData);
				const size_t row_bc = w * fmt_byte_count;
				// Note(MSDN): The runtime might assign values to RowPitch and DepthPitch 
				// that are larger than anticipated because there might be padding between rows and depth.
				// https://msdn.microsoft.com/en-us/library/windows/desktop/ff476182(v=vs.85).aspx
				for (size_t row = 0; row < h; ++row) {
					std::memcpy(ptr, p_src, row_bc);
					p_src += map.RowPitch;
					ptr += row_bc;
				}
			}

			p_ctx->Unmap(p_tex_staging, index);
		}
	}

	return td;
}
static long next_offset(grib_accessor* a){
  return byte_offset(a)+byte_count(a);
}