Example #1
0
void ConfigVisitor::Visit(const json::Array& array) {
	if (array.empty()) {
		Error<OptionJsonValueArray>("Cannot infer the type of an empty array");
		return;
	}

	json::Object const& front = array.front();
	if (front.size() != 1) {
		Error<OptionJsonValueArray>("Invalid array member");
		return;
	}

	const std::string& array_type = front.begin()->first;

	if (array_type == "string")
		AddOptionValue(ReadArray(array, array_type, &OptionValueListString::SetListString));
	else if (array_type == "int")
		AddOptionValue(ReadArray(array, array_type, &OptionValueListInt::SetListInt));
	else if (array_type == "double")
		AddOptionValue(ReadArray(array, array_type, &OptionValueListDouble::SetListDouble));
	else if (array_type == "bool")
		AddOptionValue(ReadArray(array, array_type, &OptionValueListBool::SetListBool));
	else if (array_type == "color")
		AddOptionValue(ReadArray(array, array_type, &OptionValueListColor::SetListColor));
	else
		Error<OptionJsonValueArray>("Array type not handled");
}
Example #2
0
void WrapMatrixBasis (TomVM& vm) {
    ClearMatrix ();
    matrix [15] = 1;
    ReadArray (vm.Data (), vm.GetIntParam (3), vmValType (VTP_REAL, 1, 1, true), &matrix [0], 4);
    ReadArray (vm.Data (), vm.GetIntParam (2), vmValType (VTP_REAL, 1, 1, true), &matrix [4], 4);
    ReadArray (vm.Data (), vm.GetIntParam (1), vmValType (VTP_REAL, 1, 1, true), &matrix [8], 4);
    ReturnMatrix (vm);
}
Example #3
0
int main(void) {
	char s1[MAXVALUE];
	char s2[MAXVALUE];
	int val;
	ReadArray(s1, MAXVALUE);
	ReadArray(s2, MAXVALUE);
	val = any(s1, s2);
	printf("%d", val);
	return 0;
}
Example #4
0
bool AtomUUID::Read() {
	uint8_t buffer[16];
	if (!ReadArray(buffer, 16)) {
		FATAL("Unable to read UUID");
		return false;
	}
	_metadata["uuid"] = format("%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "-%02" PRIx8 "%02" PRIx8 "-%02" PRIx8 "%02" PRIx8 "-%02" PRIx8 "%02" PRIx8 "-%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "%02" PRIx8,
			buffer[0],
			buffer[1],
			buffer[2],
			buffer[3],
			buffer[4],
			buffer[5],
			buffer[6],
			buffer[7],
			buffer[8],
			buffer[9],
			buffer[10],
			buffer[11],
			buffer[12],
			buffer[13],
			buffer[14],
			buffer[15]
			);
	if (_metadata["uuid"] == "be7acfcb-97a9-42e8-9c71-999491e3afac") {
		//http://www.adobe.com/content/dam/Adobe/en/devnet/xmp/pdfs/XMPSpecificationPart3.pdf
		string payload;
		if (!ReadString(payload, _size - 16 - 8)) {
			FATAL("Unable to read XMP");
			return false;
		}
		_metadata["payload"] = payload;
	} else {
		if ((_size - 16 - 8) > 0) {
			uint32_t tempSize = (uint32_t) _size - 16 - 8;
			uint8_t *pTemp = new uint8_t[tempSize];
			if (!ReadArray(pTemp, tempSize)) {
				FATAL("Unable to read UUID raw content");
				delete[] pTemp;
				return false;
			}
			_metadata["payload"] = Variant(pTemp, tempSize);
			delete[] pTemp;
		} else {
			_metadata["payload"] = Variant();
		}
	}
	return true;
}
Example #5
0
bool JsonString::ReadValue()  
{  
	Token token;  
	ReadToken(token);  
	bool successful = true;  

	switch(token.type_)  
	{  
	case tokenObjectBegin:  
		objnum++;  
		successful = ReadObject(token);  
		break;  
	case tokenArrayBegin:  
		successful = ReadArray(token);  
		break;  
	case tokenNumber:  
	case tokenString:  
	case tokenTrue:  
	case tokenFalse:  
	case tokenNull:  
		break;  
	default:  
		return false;  
	}  
	return successful;  
}  
void XFileLoader::ReadData<glm::mat4>(istream& s, glm::mat4& d)
{
	float elems[16];
    ReadArray(s, elems, elems + 16);
    d = make_mat4(elems);
	SkipToken(s, XFileToken::Semicolon);
}
Example #7
0
/*****************************************************************************
 * DWORD CalculateCheckSum(DWORD addr, BYTE *buffer, DWORD range)
 *****************************************************************************/
DWORD CalculateCheckSum(DWORD addr, BYTE *buffer, DWORD range)
{
    DWORD   checksum = 0xFFFFFFFF;
    
    while(range > 0)
    {
        WORD arraySize = COMM_PKT_RX_MAX_SIZE;
        WORD    i;

        if(arraySize > range)
            arraySize = range;

        ReadArray(addr, buffer, arraySize);

        for(i = 0; i < arraySize; i++)
        {
            checksum += (DWORD)buffer[i]; 
        }

        range -= arraySize;
        addr += (DWORD)arraySize;
    }

    checksum *= -1;

    return checksum;

}
void
avtNETCDFReaderBase::GetTimes(std::vector<double> &times)
{
    int ncdim = -1, nts = 1;
    std::string name;
    float *times_array = 0;
    if(GetTimeDimension(fileObject, ncdim, nts, name))
    {
        // Read the times from the DB.
        times_array = ReadArray(name.c_str());
    }
    else
    {
        // Read the time attribute.
        times_array = ReadTimeAttribute();
        if (times_array != 0)
            nts = 1;
    }

    if(times_array != 0)
    {
        for(int i = 0; i < nts; ++i)
            times.push_back((double)times_array[i]);
        delete [] times_array;
    }
    else 
    {
        for(int i = 0; i < nts; ++i)
            times.push_back((double)i);
    }
}
Example #9
0
TEST_F(ParticleTest, InterpolationSecond) {
	// Read Fields
	unsigned int size = 0;
	double *uext = ReadArray("../test/data/uext_128.dat", &size);
	double *vext = ReadArray("../test/data/vext_128.dat", &size);
	double *wext = ReadArray("../test/data/wext_128.dat", &size);
	double *text = ReadArray("../test/data/text_128.dat", &size);
	double *qext = ReadArray("../test/data/qext_128.dat", &size);
	double *Z = ReadArray("../test/data/z_128.dat", &size);
	double *ZZ = ReadArray("../test/data/zz_128.dat", &size);

	// Create GPU
	params.LinearInterpolation = 1;
	GPU *gpu = NewGPU(1, 133, 133, 130, 0.251327, 0.125664, 0.040000, Z, ZZ, &params);

	// Setup Variables
	double dx = 0.0019634921875, dy = 0.00098175;

	// Setup Particle
	GPU *input = ParticleRead("../test/data/InterpolationSecondInput.dat");
	ParticleAdd(gpu, 0, &input->hParticles[0]);

	// Update Particle
	ParticleUpload(gpu);
	ParticleFieldSet(gpu, uext, vext, wext, text, qext);
	ParticleInterpolate(gpu, dx, dy);
	ParticleDownload(gpu);

	// Compare Results
	GPU *expected = ParticleRead("../test/data/InterpolationSecondExpected.dat");
	CompareParticle(&gpu->hParticles[0], &expected->hParticles[0]);

	// Free Data
	free(gpu);
}
Example #10
0
/*******************************************************************************
Function:       size_t JPEGfread(void *ptr, size_t size, size_t n, void* file)

Precondition:   None

Overview:       This function emulates file system's fread() on constant data
                in internal flash or external memory

Input:          Data buffer, size of data chunk, size of data type, file pointer

Output:         Number of bytes copied
*******************************************************************************/
size_t JPEGfread(void *ptr, size_t size, size_t n, void *file)
{
    size_t      index;
    FLASH_BYTE  *pFile;
    DWORD       address;

    SHORT type;

    type = *((GFX_RESOURCE *)file);

    if((type & 0x0FF0) != IMAGE_JPEG)
        return 0;

    switch(type & GFX_MEM_MASK)
    {
        #ifdef USE_JPEG_FLASH
		case FLASH:
            pFile = ((IMAGE_FLASH *)file)->address;

            BYTE    *bptr = (BYTE *)ptr;
            for(index = 0; index < size * n; index++)
            {
                bptr[index] = (BYTE) pFile[_jpegImageIndex];
                _jpegImageIndex++;
            }

            break;
        #endif
		
		#ifdef USE_JPEG_EXTERNAL
        case EXTERNAL:
            address = _jpegImageIndex + ((IMAGE_EXTERNAL *)file)->address;
            ReadArray(address, (BYTE *)ptr, size * n);  // macro calling the ReadArray function from the external memory driver

            // see JPEGImage.h
            index = size * n;
            _jpegImageIndex += index;
            break;
        #endif

		#if defined(USE_JPEG_EDS)
        case EDS_EPMP:
            address = _jpegImageIndex + (((GFX_IMAGE_HEADER*)file)->LOCATION.extAddress);
            index = size * n;
            memcpyeds2ram(ptr, address, index);
            _jpegImageIndex += index;
            break;
        #endif

        default:
            return (0);
    }

    return (index);
}
Example #11
0
void XFileLoader::ReadTexCoords(istream& s, vector<vec2>& texCoords)
{
	XFileToken t = XFileToken::NextToken(s);
	if (t.m_type == XFileToken::Identifier)
		t = XFileToken::NextToken(s);
    if (t.m_type != XFileToken::LeftBrace)
        THROW_EXCEPTION_T("Parsing error", ParsingException);
	int nElems;
	ReadMember(s, nElems);
	texCoords.resize(nElems);
	ReadArray(s, texCoords.begin(), texCoords.end());
	SkipToken(s, XFileToken::RightBrace);
}
Example #12
0
	JsonValue * JsonParser::ReadValue(JsonValue * parent)
	{
		if (*cur_ == '"')
		{
			return ReadString(parent);
		}
		else if (IsDigit(*cur_) || *cur_ == '-')
		{
			return ReadNumber(parent);
		}
		else if (IsAlpha(*cur_))
		{
			std::string keyword;
			ParseIdentifier(keyword);

			if (keyword == "null")
			{
				return 0;
			}
			if (keyword == "true")
			{
				return new JsonBooleanValue(parent, true);
			}
			else if (keyword == "false")
			{
				return new JsonBooleanValue(parent, false);
			}
			else
			{
				throw Error(
					row_,
					column_ - keyword.length(),
					FormatString("Invalid bareword \"%s\", while value expected", keyword.c_str())
				);
			}
		}
		else if (*cur_ == '[')
		{
			return ReadArray(parent);
		}
		else if (*cur_ == '{')
		{
			return ReadObject(parent);
		}
		else
		{
			RaiseError("Invalid symbol, while value expected");
			return 0;
		}
	}
//}}}
//{{{  ReadHuffmanTables
// //////////////////////////////////////////////////////////////////////////////////////////////////
//
//      Private - Read the huffman encoding tables
//
FrameParserStatus_t   FrameParser_VideoMjpeg_c::ReadHuffmanTables( void )
{
    int                 DataSize;
    unsigned int        TableSize;

    DataSize            = (int)GetShort() - 2;

    for (int Index=0; (DataSize >= (SIZEOF_HUFFMAN_BITS_FIELD+1)); Index++)
    {
        if (Index >= MAX_SUPPORTED_HUFFMAN_TABLES)
        {
            FRAME_ERROR("%s - Found more than supported number of Huffman tables (%d)\n", __FUNCTION__, Index );
            BufferPointer      += DataSize;
            return FrameParserError;
        }

        HuffmanTables[Index].Id         = GetByte();
        ReadArray( HuffmanTables[Index].BitsTable, SIZEOF_HUFFMAN_BITS_FIELD );
        DataSize                       -= SIZEOF_HUFFMAN_BITS_FIELD;

        TableSize                       = 0;
        for (int i=0; i<SIZEOF_HUFFMAN_BITS_FIELD; i++)
            TableSize                  += HuffmanTables[Index].BitsTable[i];

        HuffmanTables[Index].DataSize   = TableSize;
        ReadArray( HuffmanTables[Index].DataTable, TableSize );
        DataSize                       -= TableSize;
    }

#ifdef DUMP_HEADERS
        FRAME_TRACE( "    MJPEG_DHT  (Huffman tables)\n" );
        for (int i=0; i<MAX_SUPPORTED_HUFFMAN_TABLES; i++)
            FRAME_TRACE( "        Id = %d, DataSize = %d\n", HuffmanTables[i].Id, HuffmanTables[i].DataSize );
#endif

    return FrameParserNoError;
}
Example #14
0
bool ReadMatrix (TomVM& vm, int index, vmReal *m) {
    assert (m != NULL);

    // Read 3D matrix.
    // Matrix must be 4x4
    if (ArrayDimensionSize (vm.Data (), index, 0) != 4
    ||  ArrayDimensionSize (vm.Data (), index, 1) != 4) {
        vm.FunctionError ("Matrix must be a 4x4 matrix (e.g 'dim matrix#(3)(3)' )");
        return false;
    }

    // Read in matrix
    ReadArray (vm.Data (), index, vmValType (VTP_REAL, 2, 1, true), m, 16);
    return true;
}
Example #15
0
bool VersionedAtom::Read() {
	if (!ReadUInt8(_version)) {
		FATAL("Unable to read version");
		return false;
	}
	//FINEST("_version: %"PRIu8, _version);

	if (!ReadArray(_flags, 3)) {
		FATAL("Unable to read flags");
		return false;
	}
	//FINEST("_flags: %"PRIx8"%"PRIx8"%"PRIx8, _flags[0], _flags[1], _flags[2]);

	return ReadData();
}
Example #16
0
TEST_F(ParticleTest, InterpolationMulti) {
	// Read Fields
	unsigned int size = 0;
	double *uext = ReadArray("../test/data/uext16-real.dat", &size);
	double *vext = ReadArray("../test/data/vext16-real.dat", &size);
	double *wext = ReadArray("../test/data/wext16-real.dat", &size);
	double *text = ReadArray("../test/data/text16-real.dat", &size);
	double *qext = ReadArray("../test/data/qext16-real.dat", &size);
	double *Z = ReadArray("../test/data/Z16-real.dat", &size);
	double *ZZ = ReadArray("../test/data/ZZ16-real.dat", &size);

	// Create GPU
	params.LinearInterpolation = 0;
	GPU *gpu = NewGPU(2, 21, 21, 18, 0.5, 1.0, 0.0, Z, ZZ, &params);

	// Setup Variables
	double xl = 0.251327, yl = 0.251327;
	double dx = xl / 16.0, dy = yl / 16.0;

	// Setup Particle
	Particle input2 = {
		2, 0, {0.0, 0.0, 0.0}, {2 * dx, 2 * dx, 0.021}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
	ParticleAdd(gpu, 1, &input2);

	Particle input = {
		1, 0, {0.0, 0.0, 0.0}, {dx, dy, 0.021}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
	ParticleAdd(gpu, 0, &input);

	// Update Particle
	ParticleUpload(gpu);
	ParticleFieldSet(gpu, uext, vext, wext, text, qext);
	ParticleInterpolate(gpu, dx, dy);
	ParticleDownload(gpu);

	// Compare Results
	GPU *expected = ParticleRead("../test/data/InterpolationMulti.dat");
	ASSERT_EQ(gpu->pCount, expected->pCount);

	for(int i = 0; i < gpu->pCount; i++) {
		for(int j = 0; j < gpu->pCount; j++) {
			if(gpu->hParticles[i].pidx == expected->hParticles[j].pidx) {
				CompareParticle(&gpu->hParticles[i], &expected->hParticles[j]);
			}
		}
	}

	// Free Data
	free(gpu);
}
Example #17
0
int XFileLoader::ReadMesh(istream& s)
{
    vector<vec3> positions;
    vector<vec2> texCoords;
	vector<unsigned short> indices;
    vector<vec3> normals;
	vector<unsigned short> nindices;
	XFileToken t = XFileToken::NextToken(s);
	if (t.m_type == XFileToken::Identifier)
	{
		//m_meshes[meshIdx].m_name = t.m_content;
		t = XFileToken::NextToken(s);
	}
    if (t.m_type != XFileToken::LeftBrace)
        THROW_EXCEPTION_T("Parsing error", ParsingException);
	int nElems;
	ReadMember(s, nElems);
	positions.resize(nElems);
	ReadArray(s, positions.begin(), positions.end());
	ReadFaceArray(s, indices);
	int materialIdx = -1;
	while (true)
	{
		t = XFileToken::NextToken(s);
		if (t.m_type == XFileToken::Identifier)
		{
			if (t.m_content == "MeshNormals")
				ReadMeshNormals(s, normals, nindices);
			else if(t.m_content == "MeshMaterialList")
				materialIdx = ReadMeshMaterials(s);
			else if(t.m_content == "MeshTextureCoords")
				ReadTexCoords(s, texCoords);
			else
				SkipDataObject(s);
		}
		else if (t.m_type == XFileToken::LeftBrace)
			SkipDataReference(s);
		else if (t.m_type == XFileToken::RightBrace)
			break;
        else
            THROW_EXCEPTION_T("Parsing error", ParsingException);
	}
    if (!texCoords.empty() && texCoords.size() != positions.size())
        THROW_EXCEPTION_T("Parsing error", ParsingException);
	return CreateMesh(positions, texCoords, indices, normals, nindices, materialIdx);
}
Example #18
0
void XFileLoader::ReadMeshNormals(istream&s, vector<vec3>& normals, vector<unsigned short>& nindices)
{
	XFileToken t = XFileToken::NextToken(s);
	if (t.m_type == XFileToken::Identifier)
	{
        //m_meshes[meshIdx].m_name = t.m_content;
		t = XFileToken::NextToken(s);
	}
    if (t.m_type != XFileToken::LeftBrace)
        THROW_EXCEPTION_T("Parsing error", ParsingException);
	int nElems;
	ReadMember(s, nElems);
	normals.resize(nElems);
	ReadArray(s, normals.begin(), normals.end());
	ReadFaceArray(s, nindices);
	SkipToken(s, XFileToken::RightBrace);
}
Example #19
0
bool VersionedBoxAtom::Read() {
	if (!ReadUInt8(_version)) {
		FATAL("Unable to read version");
		return false;
	}

	if (!ReadArray(_flags, 3)) {
		FATAL("Unable to read flags");
		return false;
	}

	if (!ReadData()) {
		FATAL("Unable to read data");
		return false;
	}

	return BoxAtom::Read();
}
Example #20
0
TEST_F(ParticleTest, StatisticCountEveryOther) {
	// Read Fields
	unsigned int size = 0;
	double *uext = ReadArray("../test/data/uext.dat", &size);
	double *vext = ReadArray("../test/data/vext.dat", &size);
	double *wext = ReadArray("../test/data/wext.dat", &size);
	double *text = ReadArray("../test/data/text.dat", &size);
	double *qext = ReadArray("../test/data/qext.dat", &size);
	double *Z = ReadArray("../test/data/Z.dat", &size);
	double *ZZ = ReadArray("../test/data/ZZ.dat", &size);

	// Create GPU
	GPU *gpu = NewGPU(8, 11, 11, 8, 0.5, 1.0, 0.0, Z, ZZ, &params);

	// Setup Variables
	double xl = 0.251327, yl = 0.251327;
	double dx = xl / 6.0, dy = yl / 6.0;

	// Setup Particle
	int j = 0;
	for(int i = 0; i < size; i++) {
		if(i != 0 && i % 2 == 0) {
			j += 2;
		}
		Particle p = {0, 0, {0.0, 0.0, 0.0}, {xl / 2.0, yl / 2.0, Z[j]}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
		ParticleAdd(gpu, i, &p);
	}

	// Update Particle
	ParticleUpload(gpu);
	ParticleFieldSet(gpu, uext, vext, wext, text, qext);
	ParticleCalculateStatistics(gpu, dx, dy);

	// Compare Results
	for(int i = 0; i < size; i++) {
		if(i % 2 == 0) {
			ASSERT_EQ(gpu->hPartCount[i], 2);
		} else {
			ASSERT_EQ(gpu->hPartCount[i], 0);
		}
	}

	// Free Data
	free(gpu);
}
Example #21
0
int ReadVec (TomVM& vm, int index, vmReal *v) {
    assert (v != NULL);

    // Read a 3D vector.
    // This can be a 2, 3 or 4 element vector, but will always be returned as a 4
    // element vector. (z = 0 & w = 1 if not specified.)
    int size = ArrayDimensionSize (vm.Data (), index, 0);
    if (size < 2 || size > 4) {
        vm.FunctionError ("Vector must be 2, 3 or 4 element vector");
        return -1;                  // -1 = error
    }

    // Read in vector and convert to 4 element format
    v [2] = 0;
    v [3] = 1;
    ReadArray (vm.Data (), index, vmValType (VTP_REAL, 1, 1, true), v, size);

    // Return original size
    return size;
}
Example #22
0
    static bool Process(ParseParam<Iter>& param) {
      Shape::ptr shape = boost::dynamic_pointer_cast<Shape>(param.currentNode);
      if (!shape) {
        throw ParseError("CurrenNode is not Shape.");
      }
      if (*++param.iter != "{") {
        throw ParseError("TextureCoordinate: '{' not found.");
      }
      if (*++param.iter != "point") {
        throw ParseError("TextureCoordinate: 'point' not found.");
      }
      ++param.iter; 
      ReadArray(param, shape->geometory.textureCoord);

      while (*param.iter != "}" && param.iter != param.end) ++param.iter;
      if (param.iter == param.end) {
        throw ParseError("TextureCoordinate:: '}' not found.");
      }
      return true;
    }
Example #23
0
void XFileLoader::ReadFaceArray(istream& s, vector<unsigned short>& indices)
{
	int nFaces;
	ReadMember(s, nFaces);
	indices.reserve(nFaces * 3);
	for (int i = 0; i < nFaces; ++i)
	{
		if (i != 0)
			SkipToken(s, XFileToken::Comma);
		int nIndices;
		ReadMember(s, nIndices);
		vector<int> faceIndices(nIndices);
		ReadArray(s, faceIndices.begin(), faceIndices.end());
		for (int i = 1; i < nIndices - 1; ++i)
		{
			indices.push_back(faceIndices[0]);
			indices.push_back(faceIndices[i]);
			indices.push_back(faceIndices[i + 1]);
		}
	}
	SkipToken(s, XFileToken::Semicolon);
}
Example #24
0
int XFileLoader::ReadMeshMaterials(istream& s)
{
	vector<int> materialIndices;
	int nMaterialIndices;
	int nMaterials;
	XFileToken t = XFileToken::NextToken(s);
	if (t.m_type == XFileToken::Identifier)
	{
		//m_meshes[meshIdx].m_name = t.m_content;
		t = XFileToken::NextToken(s);
	}
    if (t.m_type != XFileToken::LeftBrace)
        THROW_EXCEPTION_T("Parsing error", ParsingException);
	ReadMember(s, nMaterials);
	ReadMember(s, nMaterialIndices);
	materialIndices.resize(nMaterialIndices);
	ReadArray(s, materialIndices.begin(), materialIndices.end());
	SkipToken(s, XFileToken::Semicolon);
	unsigned int materialIdx = UINT_MAX;
	while (true)
	{
		t = XFileToken::NextToken(s);
		if (t.m_type == XFileToken::Identifier)
		{
			if (t.m_content == "Material" && materialIdx == UINT_MAX)
				materialIdx = ReadMaterial(s);
			else
				SkipDataObject(s);
		}
		else if (t.m_type == XFileToken::LeftBrace)
			SkipDataReference(s);
		else if (t.m_type == XFileToken::RightBrace)
			break;
        else
            THROW_EXCEPTION_T("Parsing error", ParsingException);
	}
	return materialIdx;
}
Example #25
0
TEST_F(ParticleTest, StatisticVPSum) {
	// Read Fields
	unsigned int size = 0;
	double *uext = ReadArray("../test/data/uext.dat", &size);
	double *vext = ReadArray("../test/data/vext.dat", &size);
	double *wext = ReadArray("../test/data/wext.dat", &size);
	double *text = ReadArray("../test/data/text.dat", &size);
	double *qext = ReadArray("../test/data/qext.dat", &size);
	double *Z = ReadArray("../test/data/Z.dat", &size);
	double *ZZ = ReadArray("../test/data/ZZ.dat", &size);

	// Create GPU
	GPU *gpu = NewGPU(8, 11, 11, 8, 0.5, 1.0, 0.0, Z, ZZ, &params);

	// Setup Variables
	double xl = 0.251327, yl = 0.251327;
	double dx = xl / 6.0, dy = yl / 6.0;

	// Setup Particle
	for(int i = 0; i < size; i++) {
		Particle p = {0, 0, {1.0, 0.0, 0.0}, {xl / 2.0, yl / 2.0, Z[i]}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
		ParticleAdd(gpu, i, &p);
	}

	// Update Particle
	ParticleUpload(gpu);
	ParticleFieldSet(gpu, uext, vext, wext, text, qext);
	ParticleCalculateStatistics(gpu, dx, dy);

	// Compare Results
	double expected[] = {1.0, 0.0, 0.0};
	for(int i = 0; i < size; i++) {
		ASSERT_EQ(gpu->hVPSum[i * 3 + 0], expected[0]);
	}

	// Free Data
	free(gpu);
}
Example #26
0
TEST_F(ParticleTest, InterpolationZELSE16) {
	// Read Fields
	unsigned int size = 0;
	double *uext = ReadArray("../test/data/uext16.dat", &size);
	double *vext = ReadArray("../test/data/vext16.dat", &size);
	double *wext = ReadArray("../test/data/wext16.dat", &size);
	double *text = ReadArray("../test/data/text16.dat", &size);
	double *qext = ReadArray("../test/data/qext16.dat", &size);
	double *Z = ReadArray("../test/data/Z16.dat", &size);
	double *ZZ = ReadArray("../test/data/ZZ16.dat", &size);

	// Create GPU
	params.LinearInterpolation = 0;
	GPU *gpu = NewGPU(1, 21, 21, 18, 0.5, 1.0, 0.0, Z, ZZ, &params);

	// Setup Variables
	double xl = 0.251327, yl = 0.251327;
	double dx = xl / 16.0, dy = yl / 16.0;

	// Setup Particle
	Particle input = {
		0, 0, {0.0, 0.0, 0.0}, {xl / 16.0, yl / 16.0, 0.021}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
	ParticleAdd(gpu, 0, &input);

	// Update Particle
	ParticleUpload(gpu);
	ParticleFieldSet(gpu, uext, vext, wext, text, qext);
	ParticleInterpolate(gpu, dx, dy);
	ParticleDownload(gpu);

	// Compare Results
	GPU *expected = ParticleRead("../test/data/InterpolationZELSE16.dat");
	CompareParticle(&gpu->hParticles[0], &expected->hParticles[0]);

	// Free Data
	free(gpu);
}
Example #27
0
/*****************************************************************************
 * BOOL BinaryHandlePacket(void)
 *****************************************************************************/
BOOL BinaryHandlePacket(void)
{
    BYTE *packet;
    BYTE *payload;
    COMM_PKT_HDR *hdr;
    BYTE ack_nack;
    BOOL result = FALSE;

    if(COMM_PKT_RxPacketAvailable() == FALSE)
        return result; 

    packet = COMM_PKT_GetRxPacket();
    
    if(COMM_PKT_IsPacketValid(packet) == FALSE)
        return result;

    hdr = (COMM_PKT_HDR *)packet;
    payload = packet + sizeof(COMM_PKT_HDR);

    ack_nack = COMM_PKT_ACK;
    
    switch(hdr->cmd)
    {

    case COMM_PKT_ECHO:
        break;

    case COMM_PKT_MAX_PAYLOAD_SIZE:
        *((WORD *)payload) = COMM_PKT_RX_MAX_SIZE;
        hdr->length = 2;
        break;

    case COMM_PKT_MEMORY_ERASE:
    	ChipErase();
        break;

    case COMM_PKT_MEMORY_WRITE:
        {    
            COMM_PKT_MEMORY_PAYLOAD *memPayload = (COMM_PKT_MEMORY_PAYLOAD *)payload;

            if(!WriteMemory(memPayload->addr, (BYTE *)&memPayload->data, hdr->length - 4))
                ack_nack = COMM_PKT_NACK;

            hdr->length = 4;
        }
        break;

    case COMM_PKT_MEMORY_READ:
        {
            COMM_PKT_MEMORY_PAYLOAD *memPayload = (COMM_PKT_MEMORY_PAYLOAD *)payload;

            hdr->length = *((WORD *)(payload + 4));
            ReadArray(memPayload->addr, (BYTE *)&memPayload->data, hdr->length);
            hdr->length += 4;
        }
        break;

    case COMM_PKT_MEMORY_VERIFY:
        {
            COMM_PKT_VERIFY_PAYLOAD *verifyPayload = (COMM_PKT_VERIFY_PAYLOAD *)payload;

            *((DWORD *)payload) = CalculateCheckSum(verifyPayload->addr, payload, verifyPayload->range);
            hdr->length = 4;
        }
        break;

    case COMM_PKT_MEMORY_DONE:
        result = TRUE;
        break;

    default:
        ack_nack = COMM_PKT_NACK;
        break;
    }

    COMM_PKT_SendReply( FLASH_PROGRAMMER_COMMUNICATION_MEDIUM,
                        hdr->cmd,
                        ack_nack,
                        payload,
                        hdr->length);

    return result;
}
tTJSVariant* tTJSBinarySerializer::ReadBasicType( const tjs_uint8* buff, const tjs_uint size, tjs_uint& index ) {
	if( index > size ) return NULL;
	tjs_uint8 type = buff[index];
	index++;
	switch( type  ) {
	case TYPE_NIL:
		return new tTJSVariant((iTJSDispatch2*)NULL);
	case TYPE_VOID:
		return new tTJSVariant();
	case TYPE_TRUE:
		return new tTJSVariant((tjs_int)1);
	case TYPE_FALSE:
		return new tTJSVariant((tjs_int)0);
	case TYPE_STRING8: {
		if( (index+sizeof(tjs_uint8)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint8 len = buff[index]; index++;
		if( (index+(len*sizeof(tjs_char))) > size ) TJS_eTJSError( TJSReadError );
		return ReadStringVarint( buff, len, index );
	}
	case TYPE_STRING16: {
		if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint16 len = Read16( buff, index );
		if( (index+(len*sizeof(tjs_char))) > size ) TJS_eTJSError( TJSReadError );
		return ReadStringVarint( buff, len, index );
	}
	case TYPE_STRING32: {
		if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint32 len = Read32( buff, index );
		if( (index+(len*sizeof(tjs_char))) > size ) TJS_eTJSError( TJSReadError );
		return ReadStringVarint( buff, len, index );
	}
	case TYPE_FLOAT: {
			if( (index+sizeof(float)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint32 t = Read32( buff, index );
			return new tTJSVariant(*(float*)&t);
		}
	case TYPE_DOUBLE: {
			if( (index+sizeof(double)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint64 t = Read64( buff, index );
			return new tTJSVariant(*(double*)&t);
		}
	case TYPE_UINT8: {
			if( (index+sizeof(tjs_uint8)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint8 t = buff[index]; index++;
			return new tTJSVariant( t );
		}
	case TYPE_UINT16: {
			if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint16 t = Read16( buff, index );
			return new tTJSVariant( t );
		}
	case TYPE_UINT32: {
			if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint32 t = Read32( buff, index );
			return new tTJSVariant( (tjs_int64)t );
		}
	case TYPE_UINT64: {
			if( (index+sizeof(tjs_uint64)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint64 t = Read64( buff, index );
			return new tTJSVariant( (tjs_int64)t );
		}
	case TYPE_INT8: {
			if( (index+sizeof(tjs_uint8)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint8 t = buff[index]; index++;
			return new tTJSVariant( (tjs_int8)t );
		}
	case TYPE_INT16: {
			if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint16 t = Read16( buff, index );
			return new tTJSVariant( (tjs_int16)t );
		}
	case TYPE_INT32: {
			if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint32 t = Read32( buff, index );
			return new tTJSVariant( (tjs_int32)t );
		}
	case TYPE_INT64: {
			if( (index+sizeof(tjs_uint64)) > size ) TJS_eTJSError( TJSReadError );
			tjs_uint64 t = Read64( buff, index );
			return new tTJSVariant( (tjs_int64)t );
		}
	case TYPE_RAW16: {
		if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint16 len = Read16( buff, index );
		if( (index+len) > size ) TJS_eTJSError( TJSReadError );
		return ReadOctetVarint( buff, len, index );
	}
	case TYPE_RAW32: {
		if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint32 len = Read32( buff, index );
		if( (index+len) > size ) TJS_eTJSError( TJSReadError );
		return ReadOctetVarint( buff, len, index );
	}
	case TYPE_ARRAY16: {
		if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint16 count = Read16( buff, index );
		return ReadArray( buff, size, count, index );
	}
	case TYPE_ARRAY32: {
		if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint32 count = Read32( buff, index );
		return ReadArray( buff, size, count, index );
	}
	case TYPE_MAP16: {
		if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint16 count = Read16( buff, index );
		return ReadDictionary( buff, size, count, index );
	}
	case TYPE_MAP32: {
		if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
		tjs_uint32 count = Read32( buff, index );
		return ReadDictionary( buff, size, count, index );
	}
	default: {
		if( type >= TYPE_POSITIVE_FIX_NUM_MIN && type <= TYPE_POSITIVE_FIX_NUM_MAX ) {
			tjs_int value = type;
			return new tTJSVariant(value);
		} else if( type >= TYPE_NEGATIVE_FIX_NUM_MIN && type <= TYPE_NEGATIVE_FIX_NUM_MAX ) {
			tjs_int value = type;
			return new tTJSVariant(value);
		} else if( type >= TYPE_FIX_RAW_MIN && type <= TYPE_FIX_RAW_MAX ) { // octet
			tjs_int len = type - TYPE_FIX_RAW_MIN;
			if( (len*sizeof(tjs_uint8)+index) > size ) TJS_eTJSError( TJSReadError );
			return ReadOctetVarint( buff, len, index );
		} else if( type >= TYPE_FIX_STRING_MIN && type <= TYPE_FIX_STRING_MAX ) {
			tjs_int len = type - TYPE_FIX_STRING_MIN;
			if( (len*sizeof(tjs_char)+index) > size ) TJS_eTJSError( TJSReadError );
			return ReadStringVarint( buff, len, index );
		} else if( type >= TYPE_FIX_ARRAY_MIN && type <= TYPE_FIX_ARRAY_MAX ) {
			tjs_int count = type - TYPE_FIX_ARRAY_MIN;
			return ReadArray( buff, size, count, index );
		} else if( type >= TYPE_FIX_MAP_MIN && type <= TYPE_FIX_MAP_MAX ) {
			tjs_int count = type - TYPE_FIX_MAP_MIN;
			return ReadDictionary( buff, size, count, index );
		} else {
			TJS_eTJSError( TJSReadError );
			return NULL;
		}
	}
	}
}
Example #29
0
struct ATTRIBUTE* Disasm::ReadData(uint8 byte) {
	struct ATTRIBUTE attr(0, byte);
	uint32 length;
	switch (byte) {
		case  HP_UByteData:
			if (!fStream->ReadUByte(attr.val.ubyte)) return NULL;
			break;
		case  HP_UInt16Data:
			if (!fStream->ReadUInt16(attr.val.uint16)) return NULL;
			break;
		case  HP_UInt32Data:
			if (!fStream->ReadUInt32(attr.val.uint32)) return NULL;
			break;
		case  HP_SInt16Data:
			if (!fStream->ReadSInt16(attr.val.sint16)) return NULL;
			break;
		case  HP_SInt32Data:
			if (!fStream->ReadSInt32(attr.val.sint32)) return NULL;
			break;
		case  HP_Real32Data:
			if (!fStream->ReadReal32(attr.val.real32)) return NULL;
			break;

		case  HP_String: fprintf(stderr, "HP_String not implemented!\n"); return NULL;
			break;
		case  HP_UByteArray:
		case  HP_UInt16Array:
		case  HP_UInt32Array:
		case  HP_SInt16Array:
		case  HP_SInt32Array:
		case  HP_Real32Array:			
			if (!ReadArrayLength(length) || !ReadArray(byte, length, &attr)) return NULL; 
			break;

		case  HP_UByteXy:
			if (!fStream->ReadUByte(attr.val.UByte_XY.x) || !fStream->ReadUByte(attr.val.UByte_XY.y)) return NULL;
			break;
		case  HP_UInt16Xy:
			if (!fStream->ReadUInt16(attr.val.UInt16_XY.x) || !fStream->ReadUInt16(attr.val.UInt16_XY.y)) return NULL;
			break;
		case  HP_UInt32Xy:
			if (!fStream->ReadUInt32(attr.val.UInt32_XY.x) || !fStream->ReadUInt32(attr.val.UInt32_XY.y)) return NULL;
			break;
		case  HP_SInt16Xy:
			if (!fStream->ReadSInt16(attr.val.SInt16_XY.x) || !fStream->ReadSInt16(attr.val.SInt16_XY.y)) return NULL;
			break;
		case  HP_SInt32Xy:
			if (!fStream->ReadSInt32(attr.val.SInt32_XY.x) || !fStream->ReadSInt32(attr.val.SInt32_XY.y)) return NULL;
			break;
		case  HP_Real32Xy:
			if (!fStream->ReadReal32(attr.val.Real32_XY.x) || !fStream->ReadReal32(attr.val.Real32_XY.y)) return NULL;
			break;

		case  HP_UByteBox:
			if (!fStream->ReadUByte(attr.val.UByte_BOX.x1) || !fStream->ReadUByte(attr.val.UByte_BOX.y1) ||
				!fStream->ReadUByte(attr.val.UByte_BOX.x2) || !fStream->ReadUByte(attr.val.UByte_BOX.y2)) return NULL;
			break;
		case  HP_UInt16Box:
			if (!fStream->ReadUInt16(attr.val.UInt16_BOX.x1) || !fStream->ReadUInt16(attr.val.UInt16_BOX.y1) ||
				!fStream->ReadUInt16(attr.val.UInt16_BOX.x2) || !fStream->ReadUInt16(attr.val.UInt16_BOX.y2)) return NULL;
			break;
		case  HP_UInt32Box:
			if (!fStream->ReadUInt32(attr.val.UInt32_BOX.x1) || !fStream->ReadUInt32(attr.val.UInt32_BOX.y1) ||
				!fStream->ReadUInt32(attr.val.UInt32_BOX.x2) || !fStream->ReadUInt32(attr.val.UInt32_BOX.y2)) return NULL;
			break;
		case  HP_SInt16Box:
			if (!fStream->ReadSInt16(attr.val.SInt16_BOX.x1) || !fStream->ReadSInt16(attr.val.SInt16_BOX.y1) ||
				!fStream->ReadSInt16(attr.val.SInt16_BOX.x2) || !fStream->ReadSInt16(attr.val.SInt16_BOX.y2)) return NULL;
			break;
		case  HP_SInt32Box:
			if (!fStream->ReadSInt32(attr.val.SInt32_BOX.x1) || !fStream->ReadSInt32(attr.val.SInt32_BOX.y1) ||
				!fStream->ReadSInt32(attr.val.SInt32_BOX.x2) || !fStream->ReadSInt32(attr.val.SInt32_BOX.y2)) return NULL;
			break;
		case  HP_Real32Box:
			if (!fStream->ReadReal32(attr.val.Real32_BOX.x1) || !fStream->ReadReal32(attr.val.Real32_BOX.y1) ||
				!fStream->ReadReal32(attr.val.Real32_BOX.x2) || !fStream->ReadReal32(attr.val.Real32_BOX.y2)) return NULL;
			break;
		default:
			fprintf(stderr, "Unknown data tag %d %x\n", (int)byte, (int)byte);
			return NULL;
	}
	struct ATTRIBUTE* pAttr = new struct ATTRIBUTE(0, 0);
	*pAttr = attr;
	return pAttr;
}
Example #30
0
/***************************************************************
 * void CheckExternalFlashHex(void)
 ***************************************************************/
void CheckExternalFlashHex(void)
{
    typedef struct 
    {
        UINT32 mchpSignature;
        UINT32 mchpCRCData;
    } CRC_CHECK; 

    CRC_CHECK externalCRC, expectedCRC;   
    WORD textHeight;
    void *pFont;
    XCHAR *pStr = NULL;
    BOOL  setProgram = FALSE;
    
    XCHAR   msgStr1[] = {'P','r','o','g','r','a','m',' ','E','x','t','e','r','n','a','l',' ','D','a','t','a',0};
    XCHAR   msgStr2[] = {'E','x','t','e','r','n','a','l',' ','d','a','t','a',' ','i','n','v','a','l','i','d','.',0};
    XCHAR   msgStr3[] = {'P','l','e','a','s','e',' ','s','e','n','d',' ','d','a','t','a',' ','u','s','i','n','g',0};
    XCHAR   msgStr4[] = {'"','E','x','t','e','r','n','a','l',' ','M','e','m','o','r','y',0};
    XCHAR   msgStr5[] = {'P','r','o','g','r','a','m','m','e','r','"',' ','u','t','i','l','i','t','y',0};
    XCHAR   msgStr6[] = {'N','o','w',' ','w','a','i','t','i','n','g',' ','f','o','r',' ','d','a','t','a',0};
    XCHAR   msgStr7[] = {'v','i','a',' ','U','A','R','T','.','.','.',0};

    pFont = (void*) &FONTDEFAULT;
    SetFont(pFont);
    textHeight = GetTextHeight(pFont);

    // check if the CRC matches the data stored in the external flash memory
    expectedCRC.mchpCRCData = GRC_CRC32_EXTERNAL_MARKER;
    expectedCRC.mchpSignature = 0x5048434D;                // this is "MCHP"

    // check if programming is prompted     
    if(btnS2 == HW_BUTTON_PRESS)
    {
        pStr = msgStr1;
        setProgram = TRUE;
	} 

    if (setProgram == FALSE)
    {
        ReadArray(GRC_CRC32_EXTERNAL_ADDR, (BYTE *)&externalCRC, 8);
    
        if  ((expectedCRC.mchpCRCData != externalCRC.mchpCRCData) || \
             (expectedCRC.mchpSignature != externalCRC.mchpSignature))
        {
            // expected and read CRC does not match, proceed to programming flash first
            // run the flash programming 
            pStr = msgStr2;
            setProgram = TRUE;
        }
    }
    
    if (setProgram == TRUE)
    {
        SetColor(WHITE);
        ClearDevice();
        SetColor(BLACK);
        OutTextXY(10,10                 , pStr);
        OutTextXY(10,10 + (textHeight*2), msgStr3);
        OutTextXY(10,10 + (textHeight*3), msgStr4);
        OutTextXY(10,10 + (textHeight*4), msgStr5);
        OutTextXY(10,10 + (textHeight*5), msgStr6);
        OutTextXY(10,10 + (textHeight*6), msgStr7);

#ifndef USE_BISTABLE_DISPLAY_GOL_AUTO_REFRESH
	#if defined( ONE_CYCLE_DRAWING	) 
		// The screen drawing starts and completes during one while(1) cycle loop in main().
		// This Demo is one cycle drawing application.
        if ( GFX_DRIVER_IsUpdateRequested() || (g_UPDATE_FLAGS == GFX_UPDATE_AS_IT_DRAWS) )
        {
	    	GFX_DRIVER_UpdateEpd( g_UPDATE_FLAGS, 0, 0, GetMaxX(), GetMaxY() ); 
	    	g_UPDATE_FLAGS = GFX_UPDATE_NO_FLASH | GFX_WAIT_IMAGE_DISPLAYED;   
	    }
	#else
		// This way can be used when drawing may take few or more cycles of while(1) loop in main().
		// See "tick.c" file for details.
        if ( g_UpdateNow || (g_UPDATE_FLAGS == GFX_UPDATE_AS_IT_DRAWS) )
        {
	        g_UpdateNow = 0;
	    	GFX_DRIVER_UpdateEpd( g_UPDATE_FLAGS, 0, 0, GetMaxX(), GetMaxY() ); 
	    	g_UPDATE_FLAGS = GFX_UPDATE_NO_FLASH | GFX_WAIT_IMAGE_DISPLAYED;   
	    }	
	#endif
#endif		 
        // Call the external flash programming routine
        ProgramFlash();

        // check if UART is still busy sending replies to the host
        while(U2STAbits.TRMT);
        DelayMs(10);

        // Force Reset to force the checking of the flash memory if programming was a success
        Reset();
    }
}