void rollCells(char &cellsResultChar, int &cellsResult)
{
//    char cellsResult;
    int cellFaceResult;
    
//    int cells[8] = {1, 2, 3, 4, 5, 6, 7, 8};
//    int cellFaces [6] = {1, 2, 3, 4, 5, 6};
    tesseractCells roll;
    
    //std::cout << roll.cells[3] << std::endl;

    cellsResult = rand() % roll.cells [7];
    cellFaceResult = rand() % roll.cellFaces [5];
    
    while (cellsResult == 0)
    {
        cellsResult = rand() % roll.cells [7];
    }
    while (cellFaceResult == 0)
    {
        cellFaceResult = rand() % roll.cellFaces [5];
    }
    
    numToChar(cellsResultChar, cellsResult);

    std::cout << "Your roll is: " << cellFaceResult << "(" << cellsResultChar << ")" << std::endl;
    
    return;
}
Esempio n. 2
0
static
void printAlignment(FILE *fptr, int *sites, int span, double *scorePerSite, Dataset *data ) {
	int extra = 5; //extra to view on left and right
	char upToLow = 'a' - 'A'; //offset to convert uppercase to lowercase
	for(int i = 0; i < data->numseqs; i++) {
		if(sites[i] >= 0) {
			fprintf(fptr, "%3d   ", i);
			for(int j = -extra; j < span + extra; j++) {
				//print site index
				if(j == 0) {
					fprintf(fptr, " %6d ", abs(getConcat2DoubleStrandPos(data, i, sites[i])) );
				}
				if( j == span) { 
					fprintf(fptr, " %-6d ", abs(getConcat2DoubleStrandPos(data, i, sites[i] + span - 1)) );
				}


				//print alignment chars
				int pos = j + sites[i];
				if(pos < 0 || pos >= data->seqlen[i] 
						|| (isForwardStrand(data, i, sites[i]) && !isForwardStrand(data,i, pos)) 
						|| (!isForwardStrand(data, i, sites[i]) && isForwardStrand(data,i, pos)) 
				  )
				{
					fprintf(fptr, " "); //out of sequence range
				}
				else if(sites[i] <= pos && pos < sites[i] + span) {
					fprintf(fptr, "%c", numToChar(data->seqs[i][pos])); //upper case
				}
				else {
					//lower case
					fprintf(fptr, "%c", numToChar(data->seqs[i][pos]) + upToLow); 
				}
			}
			fprintf(fptr, "  (%c)", isForwardStrand(data, i, sites[i]) ? '+' : '-' );

			fprintf(fptr, " Score=%8.3lf", scorePerSite[i]);

			//not safe - does not prevent buffer overflow
			//but the header has capacity from dataset.h
			fprintf(fptr, "  %s", data->headers[i]);

			fprintf(fptr, "\n");
		}
	}
}
Esempio n. 3
0
int numToString(int num) {

	int result;
	int numToChar(int num);

	if ( (num / 10) != 0)
	{
		numToString( num / 10);
		printf(" ");
		numToChar(num % 10);
	}
	else 
	{
		result = num %10;
		numToChar(result);
	}
	return 0;
}
Esempio n. 4
0
void cmdIndexed(u08 cmdInput)
{
    switch (cpState)
    {
        case INDEX:
            //
            // Validate index parameter (0-9,a-z)
            //
            if (-1 == (input[INDEX] = charToNum(cmdInput)))
            {
                cmdInit();
                return;
            }
            cpState =  PARAM1;
            break;

        case PARAM1:
            input[PARAM1] = cmdInput;
            cpState = PARAM2;
            break;

        case PARAM2:
            if (input[INDEX] > 1)
            {
                uart_send_buffered(input[COMMAND]);
                uart_send_buffered(numToChar(input[INDEX] - 2));
                uart_send_buffered(input[PARAM1]);
                uart_send_buffered(cmdInput);
            }
            else
            {
                switch (input[COMMAND])
                {
                    case CMD_PIXEL_ON:
                    case CMD_PIXEL_OFF:
                        dm_pixel(input[INDEX],
                                (input[COMMAND] == CMD_PIXEL_ON ? 1 : 0),
                                input[PARAM1] - '0',
                                cmdInput - '0');
                        break;
                }
            }
            cmdInit();
            break;
    }
}
Esempio n. 5
0
void cmdSetBits(u08 cmdInput)
{
    char length;
    if (LENGTH == cpState)
    {
        //
        // Validate length parameter (0-9,a-z)
        //
        if (-1 == (length = charToNum(cmdInput)))
        {
            cmdInit();
            return;
        }
        //
        // if length > 2 then subtract 2 and pass this command on to the
        // next controller in the chain
        //
        input[REMAINING] = length * 5;
        length -= 2;
        if (length > 0)
        {
            uart_send_buffered(input[COMMAND]);
            uart_send_buffered(numToChar(length));
        }
        input[INDEX] = 0;
        cpState = PARAM1;
        return;
    }
    if (input[INDEX] < 10)
    {
        dm_progColumn(input[INDEX] / 5, input[INDEX] % 5, cmdInput);
    }
    else
    {
        uart_send_buffered(cmdInput);
    }
    input[INDEX]++;
    input[REMAINING]--;
    if (0 == input[REMAINING])
    {
        cmdInit();
    }
}
Esempio n. 6
0
static
void printFlankingRegionProfile(FILE *fptr, int *sites, int span, Dataset *data) {
	double left[FLANKING_LEN][NUMCHARS];
	double right[FLANKING_LEN][NUMCHARS];

	for(int m = 0; m < FLANKING_LEN; m++) {
		for(int a = 0; a < NUMCHARS; a++) {
			left[m][a] = 0.0;
			right[m][a] = 0.0;
		}
	}

	for(int i = 0; i < data->numseqs; i++) {
		if(sites[i] >= 0) { //non-empty site under ZOOPS
			for(int m = 0; m < FLANKING_LEN; m++) {
				int lpos = sites[i] - m - 1;
				int rpos = sites[i] + span + m;

				if(lpos < 0 //out-of-bound on the left
					|| (isForwardStrand(data, i, sites[i]) && !isForwardStrand(data,i, lpos)) 
					|| (!isForwardStrand(data, i, sites[i]) && isForwardStrand(data,i, lpos))
				  )
				{
					left[m][GAP_CHAR] += 1.0; //out of range are counted as 'X'
				}
				else {
					left[m][data->seqs[i][lpos]] += 1.0;
				}

				if(rpos >= data->seqlen[i] //not out-of-bound on the right
					|| (isForwardStrand(data, i, sites[i]) && !isForwardStrand(data,i, rpos)) 
					|| (!isForwardStrand(data, i, sites[i]) && isForwardStrand(data,i, rpos))
				  )
				{
					right[m][GAP_CHAR] += 1.0; //out of range are counted as 'X'
				}
				else {
					right[m][data->seqs[i][rpos]] += 1.0;
				}
			}
		}
	}

	//normalize (including gap-chars)
	for(int m = 0; m < FLANKING_LEN; m++) {
		double lsum = 0.0; 
		double rsum = 0.0; 
		for(int a = 0; a < NUMCHARS; a++) {
			lsum += left[m][a];
			rsum += right[m][a];
		}
		for(int a = 0; a < NUMCHARS; a++) {
			left[m][a] /= lsum;
			right[m][a] /= rsum;
		}
	}

	fprintf(fptr, "Pos ");
	for(int x = -FLANKING_LEN; x <= -1; x++) {
		fprintf(fptr, " [%2d] ", x);
	}
	fprintf(fptr, "  ||  ");
	for(int x=0; x< FLANKING_LEN; x++) {
		fprintf(fptr, " [%2d] ", x + span);
	}
	fprintf(fptr, "\n");

	for(int y=0; y< NUMCHARS;  y++)
	{
		fprintf(fptr, "%c   ", numToChar(y));

		//print left flank
		for(int x = FLANKING_LEN - 1; x >= 0; x--) {
			fprintf(fptr, "%5.2lf ", left[x][y]);
		}

		fprintf(fptr, "  ||  ");

		//print right flank
		for(int x=0; x< FLANKING_LEN; x++) {
			fprintf(fptr, "%5.2lf ", right[x][y]);
		}
		fprintf(fptr, "\n");
	}
	fprintf(fptr, "\n");
}
Esempio n. 7
0
int main()
{

	IOWR_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,0,0);// Inititialize IP core
	IOWR_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,0,1);// load GRAM command


	int i;

	for(i=1; i<=100; i++)
	{
		IOWR_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,8,i);
	}

	while((IORD_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,4) & 4) != 4); // wait for GRAM to finish loading

	IOWR_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,0,0);// Inititialize IP core
	IOWR_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,0,2);// load P matrix data to upper bank

	alt_printf("DIN:");
	for(i=1; i<=100; i++)
	{
		IOWR_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,8,i);
		DIN[i-1] = IORD_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,8);
		alt_printf("%s,", numToChar(DIN[i-1]));
	}


	while((IORD_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,4) & 4) != 4); // wait for BRAM to finish loading

	IOWR_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,0,0);//Inititialize IP core
	//delay(10);
	IOWR_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,0,12);// send P * G command

	while((IORD_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,4) & 8) != 8); // wait for operation to complete

	IOWR_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,0,0);//Inititialize IP core
	alt_printf("\n");
	IOWR_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,0,3);// offload data from lower bank. set change value to 11 to offload from upper bank
	alt_printf("DOUT:\n");


	char cnt = 0;
	char j=0;
	char offset=0;
	for(i=0; i<=100; i++)
		{

			if (i == 0)
				{IORD_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,12);}
			else
			{
				while((IORD_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,4) & 32) != 32); //wait until data is ready

				DOUT[i-1] = IORD_32DIRECT(MATRIX_MUL_IP_S_INT_0_BASE,12);
					if(cnt == 9)
						{cnt = 0;
							for(j=9;j>=0;j--)
							{
								alt_printf("%s,", numToChar(DOUT[j+offset]));
							}
							alt_printf("\n\r");
							offset = offset + 10;
						}
					else
						cnt++;
			}
			//delay(10);
		}


	alt_printf("\n");
	return 0;
}
Esempio n. 8
0
int main (int argc, char** argv) {
	if (argc < 2) {
		std::cout << "Usage: main <datafile>\n";
		return 1;
	}
	
	std::ifstream data;
	data.open(argv[1]);
	if (data.fail()) {
		std::cout << "Could not open" << argv[1] << "\n";
		return 2;
	}
	
	int mSize;
	// Размер матриц
	data >> mSize;
	// Создаем матрицу C
	int** cMatrix = new int* [mSize];
	for (int i = 0; i < mSize; ++i)
		cMatrix[i] = new int [mSize];

	for (int i = 0; i < mSize; ++i)
		for (int j = 0; j < mSize; ++j)
			data >> cMatrix[i][j];
	
	// Создаем матрицу D
	int** dMatrix = new int* [mSize];
	for (int i = 0; i < mSize; ++i)
		dMatrix[i] = new int [mSize];

	for (int i = 0; i < mSize; ++i)
		for (int j = 0; j < mSize; ++j)
			data >> dMatrix[i][j];

	// Вывод
	std::cout << "=== C matrix ===\n";
	for (int i = 0; i < mSize; ++i) std::cout << "\t" << i; std::cout << "\n";
	for (int i = 0; i < mSize; ++i) std::cout << "\t---"; std::cout << "\n";
	for (int i = 0; i < mSize; ++i) {
		std::cout << i << "|\t";
		for (int j = 0; j < mSize; ++j) {
			if (cMatrix[i][j] < 0) std::cout << "X\t";
			else std::cout << cMatrix[i][j] << "\t";
		}
		std::cout << std::endl;
	}
	std::cout << std::endl;
	std::cout << "=== D matrix ===\n";
	for (int i = 0; i < mSize; ++i) std::cout << "\t" << numToChar(i); std::cout << "\n";
	for (int i = 0; i < mSize; ++i) std::cout << "\t---"; std::cout << "\n";
	for (int i = 0; i < mSize; ++i) {
		std::cout << numToChar(i) << "|\t";
		for (int j = 0; j < mSize; ++j) {
			if (dMatrix[i][j] < 0) std::cout << "X\t";
			else std::cout << dMatrix[i][j] << "\t";
		}
		std::cout << std::endl;
	}
	
	// Решение
	std::string solution = solve (cMatrix, dMatrix, mSize);
	std::cout << "\n=== Solution ===\n" << solution;
	
	for (int i = 0; i < mSize; ++i)
		delete [] cMatrix[i];
	delete [] cMatrix;
	for (int i = 0; i < mSize; ++i)
		delete [] dMatrix[i];
	delete [] dMatrix;
	
	return 0;
}