Exemple #1
0
int main(int argc, char** argv[]) {
    NLSystemContext ctx;
    bool inBounds;
    uint32 i;

    //Set default precision for GNU MP:
    mpf_set_default_prec(256);

    //Initialize our bigFloat arrays:
    initArray(state, in_systemVars, 39);
    initArray(minBounds, in_minBounds, 39);
    initArray(maxBounds, in_maxBounds, 39);

    //Initialize our NLSystemContext:
    initNLSystemContext(&ctx, state, minBounds, maxBounds, 39);

    //Run the main non-linear function:
    Jianmin(&ctx);

    //Check to make sure the system stayed within constraints:
    inBounds = checkBounds(&ctx, 39);

    if(inBounds == false) {
        printf("\nThe system strayed outside of its constraints! Please check your math.\n");
    }
    
    //free up the memory GNU MP allocated behind the scenes:
    clearArray(state, 39);
    clearArray(minBounds, 39);
    clearArray(maxBounds, 39);

    return 0;
}
Exemple #2
0
void resetListening() {
	clearArray(startbit, 4);
	clearArray(addressbit, 8);
	clearArray(cmdbit, 4);
	isLoadingStartArray = 1;
	zero_cross = 0;
	isListening = 0;
	
	sendReadyCommand();
}
Exemple #3
0
/*
 * At the moment, the main() function is primarily used for testing and
 * debugging. 
 */
int main() {
    clearArray(moving);
    clearArray(fixed);

    srand(0);   /* Initialize random seed */
    

    /* Debugging info */
    int j;
    for (j = 0; j < 10; j++) {
        fixed[10][j] = 1;
    }

    printf("Initial board:\n");
    printArray(&fixed, 24, 10);
    printf("Checking array\n");
    checkBoard();
    printArray(&fixed, 24, 10);
    printf("Points: %d \n", points);
    
    
    /* More debugging info */
    printf("Printing moving board:\n");
    printArray(&moving, 24, 10);
    printf("Adding random tile:\n");

    int k;
    for (k = 0; k < 7; k++) {
        setRandomTile();
        printArray(&moving, 24, 10);
        printf("\n\n\n");
        clearArray(moving);
    }

	/*  trying to move left */
	setRandomTile();
	printArray(&moving,24,10);
	printf("\n\n\n");
	moveLeft();
	printArray(&moving,24,10);
	
	/*move right*/
	printf("\n\n\n");
	moveRight();
	printArray(&moving,24,10);
	

    getchar();
    return 0;
}
void item_rectangles::drawMatrix(QGraphicsScene *scene, QRect bigRect, QSize smallRect)
{
    clearArray();

    long x = bigRect.x();
    long y = bigRect.y();
    long width = bigRect.width();
    long height = bigRect.height();
    int repWidth = width/smallRect.width();
    int repHeight = height/smallRect.height();
    QBrush brush = QBrush(Qt::darkYellow);

    for(int i = 0; i < repWidth; i++){
        for(int j = 0; j < repHeight; j++){
            long x1 = x + i * smallRect.width();
            long y1 = y + j * smallRect.height();
            rectArray.push_back(scene->addRect(1, 1, smallRect.width()-2, smallRect.height()-2,
                                               QPen(Qt::yellow, 1),
                                               brush));
            rectArray.last()->setPos(x1, y1);
            rectArray.last()->setData(0, "YellowRectangle");
            rectArray.last()->setOpacity(0.7);
            rectArray.last()->setZValue(10000);
        }
    }
}
Exemple #5
0
int fileLoadSHD(const char *filename,Shader_t *shader,void *unused)
{
  lxFSFile_t * fSHD;
  char buf[1024];

  fSHD = FS_open(filename);
  l_SHDData.file = fSHD;
  l_SHDData.shader = shader;
  lprintf("Shader: \t%s\n",filename);

  if(fSHD == NULL)
  {
    lprintf("ERROR shdload: ");
    lnofile(filename);
    return LUX_FALSE;
  }

  lxFS_gets(buf, 255, fSHD);


  if (!sscanf(buf,SHD_HEADER,&l_SHDData.version) || l_SHDData.version < SHD_VER_MINIMUM)
  {
    // wrong header
    lprintf("ERROR shdload: invalid file format or version\n");
    FS_close(fSHD);
    return LUX_FALSE;
  }
  l_SHDData.cgmode = -1;
  shader->numStages = 0;

  l_SHDData.stagesColorInBuffer = 0;
  l_SHDData.stagesTexInBuffer = 0;
  l_SHDData.stagesTexGpuInBuffer = 0;
  l_SHDData.lastVColorStage = 0;
  l_SHDData.stagesGpuInBuffer = 0;
  l_SHDData.bumpStage     = -1;

  l_SHDData.tech        = VID_T_UNSET;

  clearArray(l_SHDData.stagesTex,BUFFERSTAGES);
  l_SHDData.stagesColor = NULL;

  FileParse_setAnnotationList(&l_SHDData.shader->annotationListHead);
  FileParse_start(fSHD,l_defSHD);


  if (!l_SHDData.stagesTexGpuInBuffer && !l_SHDData.stagesColorInBuffer){
    lprintf("WARNING shdload: no stages defined\n");
    FS_close (fSHD);
    return LUX_FALSE;
  }

  shader->tech = l_SHDData.tech;

  ShaderBuildFromBuffer(shader);
  dlprintf("\tColors: %d Textures: %d\n",l_SHDData.stagesColorInBuffer,l_SHDData.stagesTexGpuInBuffer);
  FS_close (fSHD);

  return LUX_TRUE;
}
//delete currrent array then allocate and fill new one
void Base::setArraySize(int rows, int cols)
{
    clearArray();
    numRows = rows >= 1? rows : 1;
    numCols = cols>=1 ? cols : 1;
    fillArray();
}
Exemple #7
0
int main (void) {
	/** Local Varibles */
	unsigned char temp;
	
	initialize();
	clearArray();
	
	PORTB = 0b11000000;

	eight_bit_glory( 50 );

	return 0;

}//main
Exemple #8
0
void main (void) {
	/** Local Varibles */
	unsigned char temp;
	
	initialize();
	clearArray();
	
	PORTB = 0b10000000;
	
	while(1){
		temp = 0b10101010;
		PORTC = temp;
		}

}//main
void MapManager::initMapping(int top, int bottom, int left, int right)
{
    map_data_.map_data_setting.top = top;
    map_data_.map_data_setting.bottom = bottom;
    map_data_.map_data_setting.left = left;
    map_data_.map_data_setting.right = right;
    
    assert(vaildateInit());
    
    clearCursor();
    clearMapItemArray(&map_data_.map_object_data_array);
    clearMapItemArray(&map_data_.map_drop_item_data_array);

    clearArray(&map_data_.mapping_array, false);
    
    map_data_.map_move_point_list.clear();
}
Exemple #10
0
int main (int argc , char* argv[], char* envp[]) {
    char my_cwd[PATH_MAX];
    char buffer[2048];
    cmdLog cLog;
    List* env= 0;
    intLog(&cLog);
    while(1) {
        getcwd(my_cwd, PATH_MAX);
        printf("%s$ ", my_cwd);
        fgets(buffer, 2048, stdin);
        if ((buffer[0] != '\n') && ((env= execString(&cLog, env, buffer)) == (List*)-1)) {
            break;
        }
    }
    clearArray(&cLog);
    return 0;
}
Exemple #11
0
//***************************************************************
void CToolCreateEntity::commitArray()
{
	//H_AUTO(R2_CToolCreateEntity_commitArray)
	for (uint k = 0; k < _ArrayElements.size(); ++k)
	{
		if (_ArrayElements[k])
		{
			cloneEntityIntoScenario(_ArrayElements[k]->getEntity(),
									_ArrayElements[k]->getWorldPos(),
									_ArrayElements[k]->getAngle(),
									k == 0, /*new action*/
									false /*create ghost*/);
		}
	}
	clearArray();
	getEditor().getDMC().flushActions();
}
	// totallength and N are number of complex samples
	void PeriodogramComponent::periodogram(int totallength,int N,float data[],float result[])
	{
		 int num_of_block = 2*totallength/N-1;
		 float datablock[2*N],PSDresult[N],PSDresultshift[N];
		 int offset;
		 clearArray(result,N);
		 for( int i= 1;i<=num_of_block;i++)
		 {
		     offset = N/2*(i-1);
		     copyblock(offset,N,data,datablock);
		     winHan(N,datablock);
		     FFT (datablock, N, 1);
		     PSD(datablock,PSDresult,N);
		     PSDshift(PSDresult,PSDresultshift,N);
		     addArray(result,PSDresultshift,N);
		 }
		 avgArray(result,N,num_of_block);
	}
void item_rectangles::drawRound(QGraphicsScene *scene, QRect bigRect, QSize smallRect)
{
    clearArray();

    long x = bigRect.x();
    long y = bigRect.y();
    long width = bigRect.width();
    long height = bigRect.height();
    int repWidth = width/smallRect.width();
    int repHeight = height/smallRect.height();
    QBrush brush = QBrush(Qt::darkYellow);

    int Cx = x+(width/2);
    int Cy = y+(height/2);
    int hRadius = width/2;
    int vRadius = height/2;

    for(int i = 0; i < repWidth; i++)
    {
        for(int j = 0; j < repHeight; j++)
        {
            int x1 = x + i * smallRect.width();
            int y1 = y + j * smallRect.height();
            int Px = x1+smallRect.width()/2;
            int Py = y1+smallRect.height()/2;

            if((hRadius <= 0.0) || (vRadius <= 0.0)) continue;

            if( ((pow(Px-Cx,2)/pow(hRadius, 2))+(pow(Py-Cy, 2)/pow(vRadius, 2))) > 1.0 ) continue;

            QGraphicsRectItem* r=scene->addRect(1, 1, smallRect.width()-2, smallRect.height()-2,
                                            QPen(Qt::yellow, 1),
                                            brush);
            r->setPos(x1, y1);
            r->setData(0, "YellowRectangle");
            r->setOpacity(0.7);
            r->setZValue(10000);
            rectArray.push_back(r);
        }
    }
}
Exemple #14
0
/* getline: read a line into  s, return length */
int getline(char s[], int lim)
{
    int c, i, total = 0;

    for (i = 0; (c = getchar()) != EOF && c!='\n'; ++i) {
        if (i > lim - 1) {
            clearArray(s);
            i = 0;
        }
        s[i] = c;
        ++total;
    }

    if (c == '\n') {
        s[i] = c;
        ++i;
        ++total;
    }
    s[i] = '\0';
    return total;
}
Exemple #15
0
//***************************************************************
void CToolCreateEntity::cancel()
{
	CToolChoosePos::cancel();
	clearArray();
}
Exemple #16
0
//***************************************************************
CToolCreateEntity::~CToolCreateEntity()
{
	clearArray();
}
Exemple #17
0
/* Main Function */
int main(void){
	
	enum states{
		setup,
		drawing,
		readusart,
	} currentstate = setup;

	unsigned char STRING1[]="YAY THIS";
	unsigned char STRING2[]="WORKS!!!";
	unsigned char STR1CMP[9];
	unsigned char STR2CMP[9];
	unsigned char x, i, j;
	unsigned char send[50];
				
	while(1){
	
		switch(currentstate){
			case setup:
				initialize();
				clearArray();
				PORTB = 0b10000000;
				PORTC |= 0b10000000;
				ht1632_initialize();
				PORTC |= 0b01000000;
				InitializeUART();
				PORTC |= 0b00100000;
				
				sprintf(send, "Initialized...\n");
				PORTC |= 0b00010000;
				SendStringUART(send);
				_delay_ms(200);
				PORTC = 0;
				strcpy(STRING1, "YAY THIS");
				strcpy(STRING2, "WORKS!!!");
				currentstate = drawing;
				break;
			case drawing:
				for(x=1;x<sizeof(STRING1);x++) {
					null_buffer();
					for(i=0;i<8;i++){
						for(j=0;j<8;j++){
							set_buffer(STRING1[x-1]);
							if (~buffer[i][j] & (1<<0)) {
                                ht1632_plot(j+(8*(x-1))-1,i,GREEN);
								PORTC = ~PORTC;
							} else {
								ht1632_plot(j+(8*(x-1))-1,i,BLACK);
								PORTC = ~PORTC;
							}
						}
					}
				}
				for(x=1;x<sizeof(STRING2);x++) {
					null_buffer();
					for(i=0;i<8;i++){
						for(j=0;j<8;j++){
							set_buffer(STRING2[x-1]);
							if (~buffer[i][j] & (1<<0)) {
                                ht1632_plot(j+(8*(x-1))-1,i+8,GREEN);
								PORTC = ~PORTC;
							} else {
								ht1632_plot(j+(8*(x-1))-1,i+8,BLACK);
								PORTC = ~PORTC;
							}
						}
					}
				}
				PORTC = 0;
				currentstate = readusart;
				break;
			case readusart:
				strcpy(STR1CMP, STRING1);
				strcpy(STR2CMP, STRING2);
				NewScreen(STRING1, STRING2);
				
				if((strcmp(STRING1, "RESETRES") == 0)){
					currentstate = setup;
				}else if((strcmp(STRING1, STR1CMP) != 0) | (strcmp(STRING2, STR2CMP) != 0)){
					currentstate = drawing;
				}
				
				break;
		}
	}
}
Exemple #18
0
//Jianmin :: NLSystemContext* -> Effect -> IO
void Jianmin(NLSystemContext* ctx) {
    uint32 i;
    unsigned long exponent;
    //Reactions:
    bigFloat r[78];     //temp-storage during calculations
    bigFloat r_f[78];   //forward reaction
    bigFloat r_b[78];   //backward reaction

    //Note: 'theta_H' is initialized in second bigFloat group below.
    bigFloat theta_A, theta_B, theta_C, theta_D, theta_E, theta_F, theta_G, theta_I, theta_J, theta_K,
             theta_L, theta_M, theta_N, theta_O, theta_P, theta_Q, theta_R, theta_S, theta_T, theta_U,
             theta_V, theta_W, theta_X, theta_Y, theta_Z, theta_Z1;
    bigFloat   free,   theta_H,   theta_OH,  theta_H2O,    theta_CH, theta_CH2, theta_CH3, theta_CH4,
           theta_CO, theta_CHO, theta_CH2O, theta_CH3O, theta_CH3OH;
    bigFloat K_H;
    bigFloat temp;
    bigFloat e;

    // define constants for forward and reverse rate constants.
    //NOTE: constants for k_f[55]-k_f[70] are not defined! (same for k_b[].)
    double in_k_f[78] = {
        6.249e7,  1.831e3,  9.567e2,  8.447e3, 1.863e5, 5.509e8,   5.982, 2.106e10,  7.139e4,  2.243e8,
        2.418e7,  1.247e8,  1.100e2, 5.791e12, 1.114e9, 9.955e3, 5.396e2,  3.706e3,  2.705e8,  7.040e9,
        5.501e8,  2.335e4, 1.630e10,  6.622e2, 6.464e2, 2.109e8,   8.910,  3.268e5,  1.890e5, 9.014e11,
        7.631e3,  6.303e2,  1.075e2,  9.362e7, 9.540e4, 2.636e8, 3.368e8, 1.615e10, 3.290e-3,  1.004e3,
        1.457e5,  2.380e2,  3.845e7,  3.778e7, 9.432e3, 1.666e3, 3.094e8,  1.557e7,  6.575e1,  1.372e2,
          3.003, 3.044e13, 1.047e16, 2.092e12, 1.020e3,       0,       0,        0,        0,        0,
              0,        0,        0,        0,       0,       0,       0,        0,        0,        0,
              0,  5.056e9,  1.396e9,  4.831e9, 9.712e6,   4.000, 2.403e6, 1.404e-1};

    double in_k_b[78] = {
         5.885e4, 3.070e6,  2.885e7, 8.560e1,    8.721,  3.131e5, 6.828e-12,  4.823e3,   1.020e4,    1.566,
         5.024e5, 3.056e6, 6.318e-1, 1.247e8, 8.518e-3, 6.388e10,   1.625e7,  1.514e5,   4.864e5,  1.941e2,
         1.750e6, 8.974e1, 5.505e-2, 1.555e1,  2.380e7,    1.986,   1.865e7,    1.668,   1.108e7,    1.962,
        1.902e11, 5.235e1,  1.311e7,   2.729,  2.606e8,  5.388e6,     4.689,  1.170e4, 2.457e-15, 1.833e-6,
        7.225e-5, 5.142e8, 4.046e12, 9.921e9,  3.620e7,  2.431e7,  1.802e13,  2.232e8,   7.117e7,  6.635e7,
         7.879e7, 1.230e8,  1.740e8, 1.640e8,  6.696e7,        0,         0,        0,         0,        0,
               0,       0,        0,       0,        0,        0,         0,        0,         0,        0,
               0, 2.126e8,    1.611, 1.848e6,  1.828e2,  3.558e8,   1.593e5, 1.336e10};

    bigFloat k_f[78];
    bigFloat k_b[78];
    
    // define partial pressures, Boltzman constant and temperature.
    //       guaiacol,    H2, catechol,  phenol, benzene, anisole.
    bigFloat      p_A,  p_H2,      p_M,     p_S,     p_X,     p_K, 
                 p_CO, p_H2O,    p_CH4, p_CH3OH,      KB,       T;

 
    double partialPressures[12] = {1.0, 1.0, 1.0e-5, 1.0e-5,       1.0e-5, 1.0e-5,
                                1.0e-6, 0.0,    0.0,    0.0, 8.6173324e-5,    573};


    //---------------------------------------------------------
    //INITIALIZATIONS:

    //init r[]:
    for(i = 0; i < 78; i++) {
        mpf_init(r[i]);
    }
    //init r_f[]:
    for(i = 0; i < 78; i++) {
        mpf_init(r_f[i]);
    }
    //init r_b[]:
    for(i = 0; i < 78; i++) {
        mpf_init(r_b[i]);
    }

    //init forward and reverse rate constants:
    initArray(k_f, in_k_f, 78);
    initArray(k_b, in_k_b, 78);

    //init the various thetas:
    mpf_init_set(theta_A     , ctx->state[0]);
    mpf_init_set(theta_E     , ctx->state[1]);
    mpf_init_set(theta_F     , ctx->state[2]);
    mpf_init_set(theta_G     , ctx->state[3]);
    mpf_init_set(theta_I     , ctx->state[4]);
    mpf_init_set(theta_L     , ctx->state[5]);
    mpf_init_set(theta_M     , ctx->state[6]);
    mpf_init_set(theta_N     , ctx->state[7]);
    mpf_init_set(theta_O     , ctx->state[8]);
    mpf_init_set(theta_R     , ctx->state[9]);
    mpf_init_set(theta_S     , ctx->state[10]);
    mpf_init_set(theta_U     , ctx->state[11]);
    mpf_init_set(theta_V     , ctx->state[12]);
    mpf_init_set(theta_X     , ctx->state[13]);
    mpf_init_set(free        , ctx->state[14]);
    mpf_init_set(theta_H     , ctx->state[15]);
    mpf_init_set(theta_OH    , ctx->state[16]);
    mpf_init_set(theta_H2O   , ctx->state[17]);
    mpf_init_set(theta_CH    , ctx->state[18]);
    mpf_init_set(theta_CH2   , ctx->state[19]);
    mpf_init_set(theta_CH3   , ctx->state[20]);
    mpf_init_set(theta_CH4   , ctx->state[21]);
    mpf_init_set(theta_CHO   , ctx->state[22]);
    mpf_init_set(theta_CH2O  , ctx->state[23]);
    mpf_init_set(theta_CH3O  , ctx->state[24]);
    mpf_init_set(theta_CH3OH , ctx->state[25]);
    mpf_init_set(theta_W     , ctx->state[26]);
    mpf_init_set(theta_T     , ctx->state[27]);
    mpf_init_set(theta_B     , ctx->state[28]);
    mpf_init_set(theta_J     , ctx->state[29]);
    mpf_init_set(theta_P     , ctx->state[30]);
    mpf_init_set(theta_C     , ctx->state[31]);
    mpf_init_set(theta_D     , ctx->state[32]);
    mpf_init_set(theta_K     , ctx->state[33]);
    mpf_init_set(theta_Q     , ctx->state[34]);
    mpf_init_set(theta_Y     , ctx->state[35]);
    mpf_init_set(theta_Z     , ctx->state[36]);
    mpf_init_set(theta_Z1    , ctx->state[37]);
    mpf_init_set(theta_CO    , ctx->state[38]);
    
    //init K_H, temp, and e:
    mpf_init(K_H);
    mpf_init(temp);
    mpf_init(e);
    //define e to 50 digits of precision:
    gmp_sscanf("2.71828182845904523536028747135266249775724709369995", "%F", e);
    
    //init partial pressures:
    mpf_init_set_d(p_A       , partialPressures[0]);
    mpf_init_set_d(p_H2      , partialPressures[1]);
    mpf_init_set_d(p_M       , partialPressures[2]);
    mpf_init_set_d(p_S       , partialPressures[3]);
    mpf_init_set_d(p_X       , partialPressures[4]);
    mpf_init_set_d(p_K       , partialPressures[5]); 
    mpf_init_set_d(p_CO      , partialPressures[6]);
    mpf_init_set_d(p_H2O     , partialPressures[7]);
    mpf_init_set_d(p_CH4     , partialPressures[8]);
    mpf_init_set_d(p_CH3OH   , partialPressures[9]);
    mpf_init_set_d(KB        , partialPressures[10]);
    mpf_init_set_d(T         , partialPressures[11]);


    //---------------------------------------------------------
    //MAIN MATH KERNEL:

    //FORWARD REACTION RATES:
    // calculate rates for all elementary steps.
    mpf_mul(    r_f[0],     k_f[0],        p_A);
    mpf_mul(    r_f[0],     r_f[0],       free);
    mpf_mul(    r_f[0],     r_f[0],       free);
    mpf_mul(    r_f[0],     r_f[0],       free);
    mpf_mul(    r_f[0],     r_f[0],       free);
    mpf_mul(    r_f[1],     k_f[1],    theta_A);
    mpf_mul(    r_f[1],     r_f[1],    theta_H);
    //r_f[2] and r_f[3] handled later on...
    mpf_mul(    r_f[4],     k_f[4],    theta_A);
    mpf_mul(    r_f[4],     r_f[4],       free);
    mpf_mul(    r_f[5],     k_f[5],    theta_A);
    mpf_mul(    r_f[5],     r_f[5],       free);
    mpf_mul(    r_f[6],     k_f[6],    theta_A);
    mpf_mul(    r_f[6],     r_f[6],       free);
    mpf_mul(    r_f[7],     k_f[7],    theta_A);
    mpf_mul(    r_f[7],     r_f[7],       free);
    mpf_mul(    r_f[8],     k_f[8],    theta_B);
    mpf_mul(    r_f[8],     r_f[8],       free);
    mpf_mul(    r_f[8],     r_f[8],       free);
    //r_f[9] and r_f[10] handled later on...
    mpf_mul(   r_f[11],    k_f[11],    theta_E);
    mpf_mul(   r_f[11],    r_f[11],    theta_H);
    mpf_mul(   r_f[12],    k_f[12],    theta_F);
    mpf_mul(   r_f[12],    r_f[12],       free);
    mpf_mul(   r_f[13],    k_f[13],    theta_F);
    mpf_mul(   r_f[13],    r_f[13],       free);
    mpf_mul(   r_f[14],    k_f[14],    theta_F);
    mpf_mul(   r_f[15],    k_f[15],    theta_G);
    mpf_mul(   r_f[15],    r_f[15],    theta_H);
    mpf_mul(   r_f[16],    k_f[16],    theta_G);
    mpf_mul(   r_f[16],    r_f[16],       free);
    mpf_mul(   r_f[17],    k_f[17],    theta_I);
    mpf_mul(   r_f[17],    r_f[17],       free);
    mpf_mul(   r_f[18],    k_f[18],    theta_I);
    mpf_mul(   r_f[18],    r_f[18],       free);
    mpf_mul(   r_f[18],    r_f[18],       free);
    mpf_mul(   r_f[19],    k_f[19],    theta_J);
    //r_f[20] handled later on...
    mpf_mul(   r_f[21],    k_f[21],    theta_L);
    mpf_mul(   r_f[21],    r_f[21],       free);
    mpf_mul(   r_f[22],    k_f[22],    theta_L);
    mpf_mul(   r_f[22],    r_f[22],       free);
    mpf_mul(   r_f[23],    k_f[23],    theta_M);
    mpf_mul(   r_f[23],    r_f[23],       free);
    mpf_mul(   r_f[24],    k_f[24],    theta_M);
    mpf_mul(   r_f[24],    r_f[24],    theta_H);
    mpf_mul(   r_f[25],    k_f[25],    theta_N);
    mpf_mul(   r_f[25],    r_f[25],    theta_H);
    mpf_mul(   r_f[26],    k_f[26],    theta_O);
    mpf_mul(   r_f[26],    r_f[26],       free);
    mpf_mul(   r_f[27],    k_f[27],    theta_O);
    mpf_mul(   r_f[27],    r_f[27],       free);
    mpf_mul(   r_f[28],    k_f[28],    theta_P);
    mpf_mul(   r_f[28],    r_f[28],    theta_H);
    //r[29] handled later on...
    mpf_mul(   r_f[30],    k_f[30],    theta_R);
    mpf_mul(   r_f[30],    r_f[30],    theta_H);
    mpf_mul(   r_f[31],    k_f[31],    theta_S);
    mpf_mul(   r_f[31],    r_f[31],       free);
    mpf_mul(   r_f[32],    k_f[32],    theta_S);
    mpf_mul(   r_f[32],    r_f[32],    theta_H);
    mpf_mul(   r_f[33],    k_f[33],    theta_T);
    mpf_mul(   r_f[33],    r_f[33],       free);
    mpf_mul(   r_f[34],    k_f[34],    theta_U);
    mpf_mul(   r_f[34],    r_f[34],    theta_H);
    mpf_mul(   r_f[35],    k_f[35],    theta_V);
    mpf_mul(   r_f[35],    r_f[35],    theta_H);
    mpf_mul(   r_f[36],    k_f[36],    theta_W);
    mpf_mul(   r_f[37],    k_f[37],    theta_F);
    mpf_mul(   r_f[37],    r_f[37],       free);
    //what happened to r_38?!
    mpf_mul(   r_f[39],    k_f[39],    theta_I);
    mpf_mul(   r_f[39],    r_f[39],       free);
    mpf_mul(   r_f[39],    r_f[39],       free);
    mpf_mul(   r_f[40],    k_f[40],    theta_B);
    mpf_mul(   r_f[40],    r_f[40],       free);
    mpf_mul(   r_f[40],    r_f[40],       free);
    mpf_mul(   r_f[41],    k_f[41], theta_CH3O);
    mpf_mul(   r_f[41],    r_f[41],    theta_H);
    mpf_mul(   r_f[42],    k_f[42],   theta_CH);
    mpf_mul(   r_f[42],    r_f[42],    theta_H);
    mpf_mul(   r_f[43],    k_f[43],  theta_CH2);
    mpf_mul(   r_f[43],    r_f[43],    theta_H);
    mpf_mul(   r_f[44],    k_f[44],  theta_CH3);
    mpf_mul(   r_f[44],    r_f[44],    theta_H);
    mpf_mul(   r_f[45],    k_f[45],   theta_OH);
    mpf_mul(   r_f[45],    r_f[45],    theta_H);
    mpf_mul(   r_f[46],    k_f[46],  theta_CHO);
    mpf_mul(   r_f[46],    r_f[46],    theta_H);
    mpf_mul(   r_f[47],    k_f[47], theta_CH2O);
    mpf_mul(   r_f[47],    r_f[47],    theta_H);
    mpf_mul(   r_f[48],    k_f[48],    theta_S);
    mpf_mul(   r_f[49],    k_f[49],    theta_M);
    mpf_mul(   r_f[50],    k_f[50],    theta_X);
    mpf_mul(   r_f[51],    k_f[51], theta_CH3OH);
    mpf_mul(   r_f[52],    k_f[52],  theta_CH4);
    mpf_mul(   r_f[53],    k_f[53],  theta_H2O);
    mpf_mul(   r_f[54],    k_f[54],    theta_K);
    //not using r_f[55] through r_f[74]?!
    //also, consider making below assignments in-order (might help optimizer).
    mpf_mul(   r_f[71],    k_f[71],    theta_O);
    mpf_mul(   r_f[71],    r_f[71],       free);
    mpf_mul(   r_f[72],    k_f[72],    theta_Z);
    mpf_mul(   r_f[72],    r_f[72],       free);
    mpf_mul(   r_f[73],    k_f[73],    theta_Z);
    mpf_mul(   r_f[73],    r_f[73],       free);
    mpf_mul(   r_f[74],    k_f[74],   theta_Z1);
    mpf_mul(   r_f[75],    k_f[75],    theta_G);
    mpf_mul(   r_f[75],    r_f[75],    theta_H);
    mpf_mul(   r_f[76],    k_f[76],    theta_Y);
    mpf_mul(   r_f[76],    r_f[76],       free);
    mpf_mul(   r_f[77],    k_f[77],   theta_CO);
    mpf_mul(   r_f[77],    r_f[77],    theta_H);
    //
    // steps including C, D, K, Q.
    mpf_mul(    r_f[2],     k_f[2],    theta_A);
    mpf_mul(    r_f[2],     r_f[2],    theta_H);
    mpf_mul(    r_f[3],     k_f[3],    theta_A);
    mpf_mul(    r_f[3],     r_f[3],       free);
    mpf_mul(    r_f[9],     k_f[9],    theta_C);
    mpf_mul(    r_f[9],     r_f[9],       free);
    mpf_mul(   r_f[10],    k_f[10],    theta_D);
    mpf_mul(   r_f[10],    r_f[10],    theta_H);
    mpf_mul(   r_f[20],    k_f[20],    theta_K);
    mpf_mul(   r_f[20],    r_f[20],       free);
    mpf_mul(   r_f[29],    k_f[29],    theta_Q);
    mpf_mul(   r_f[29],    r_f[29],       free);


    //REVERSE REACTION RATES:
    mpf_mul(    r_b[0],     k_b[0],    theta_A);
    mpf_mul(    r_b[1],     k_b[1],    theta_B);
    mpf_mul(    r_b[1],     r_b[1],       free);
    //r[2] and r[3] handled later on...
    mpf_mul(    r_b[4],     k_b[4],    theta_E);
    mpf_mul(    r_b[4],     r_b[4], theta_CH3O);
    mpf_mul(    r_b[5],     k_b[5],    theta_F);
    mpf_mul(    r_b[5],     r_b[5],    theta_H);
    mpf_mul(    r_b[6],     k_b[6],    theta_G);
    mpf_mul(    r_b[6],     r_b[6],  theta_CH3);
    mpf_mul(    r_b[7],     k_b[7],    theta_I);
    mpf_mul(    r_b[7],     r_b[7],    theta_H);
    mpf_mul(    r_b[8],     k_b[8],    theta_J);
    mpf_mul(    r_b[8],     r_b[8],    theta_H);
    //r[9] and r[10] handled later on...
    mpf_mul(   r_b[11],    k_b[11],    theta_S);
    mpf_mul(   r_b[11],    r_b[11],       free);
    mpf_mul(   r_b[12],    k_b[12],    theta_E);
    mpf_mul(   r_b[12],    r_b[12], theta_CH2O);
    mpf_mul(   r_b[13],    k_b[13],    theta_L);
    mpf_mul(   r_b[13],    r_b[13],    theta_H);
    mpf_mul(   r_b[14],    k_b[14],    theta_G);
    mpf_mul(   r_b[14],    r_b[14],  theta_CH2);
    mpf_mul(   r_b[15],    k_b[15],    theta_M);
    mpf_mul(   r_b[15],    r_b[15],       free);
    mpf_mul(   r_b[16],    k_b[16],    theta_N);
    mpf_mul(   r_b[16],    r_b[16],   theta_OH);
    mpf_mul(   r_b[17],    k_b[17],    theta_N);
    mpf_mul(   r_b[17],    r_b[17], theta_CH3O);
    mpf_mul(   r_b[18],    k_b[18],    theta_O);
    mpf_mul(   r_b[18],    r_b[18],    theta_H);
    mpf_mul(   r_b[19],    k_b[19],    theta_P);
    mpf_mul(   r_b[19],    r_b[19],  theta_CH2);
    //r[20] handled later on...
    mpf_mul(   r_b[21],    k_b[21],    theta_E);
    mpf_mul(   r_b[21],    r_b[21],  theta_CHO);
    mpf_mul(   r_b[22],    k_b[22],    theta_G);
    mpf_mul(   r_b[22],    r_b[22],   theta_CH);
    mpf_mul(   r_b[23],    k_b[23],    theta_E);
    mpf_mul(   r_b[23],    r_b[23],   theta_OH);
    mpf_mul(   r_b[24],    k_b[24],    theta_T);
    mpf_mul(   r_b[25],    k_b[25],    theta_R);
    mpf_mul(   r_b[25],    r_b[25],       free);
    mpf_mul(   r_b[26],    k_b[26],    theta_N);
    mpf_mul(   r_b[26],    r_b[26], theta_CH2O);
    mpf_mul(   r_b[27],    k_b[27],    theta_U);
    mpf_mul(   r_b[27],    r_b[27],  theta_CH2);
    mpf_mul(   r_b[28],    k_b[28],    theta_T);
    mpf_mul(   r_b[28],    r_b[28],       free);
    //r[29] handled later on...
    mpf_mul(   r_b[30],    k_b[30],    theta_S);
    mpf_mul(   r_b[30],    r_b[30],       free);
    mpf_mul(   r_b[31],    k_b[31],    theta_V);
    mpf_mul(   r_b[31],    r_b[31],   theta_OH);
    mpf_mul(   r_b[32],    k_b[32],    theta_W);
    mpf_mul(   r_b[32],    r_b[32],       free);
    mpf_mul(   r_b[33],    k_b[33],    theta_S);
    mpf_mul(   r_b[33],    r_b[33],   theta_OH);
    mpf_mul(   r_b[34],    k_b[34],    theta_G);
    mpf_mul(   r_b[34],    r_b[34],       free);
    mpf_mul(   r_b[34],    r_b[34],       free);
    mpf_mul(   r_b[35],    k_b[35],    theta_X);
    mpf_mul(   r_b[35],    r_b[35],       free);
    mpf_mul(   r_b[35],    r_b[35],       free);
    mpf_mul(   r_b[36],    k_b[36],    theta_X);
    mpf_mul(   r_b[36],    r_b[36],   theta_OH);
    mpf_mul(   r_b[37],    k_b[37],    theta_O);
    mpf_mul(   r_b[37],    r_b[37],    theta_H);
    //what happened to r_38?!
    mpf_mul(   r_b[39],    k_b[39],    theta_U);
    mpf_mul(   r_b[39],    r_b[39],  theta_CH3);
    mpf_mul(   r_b[40],    k_b[40],    theta_S);
    mpf_mul(   r_b[40],    r_b[40], theta_CH3O);
    mpf_mul(   r_b[41],    k_b[41], theta_CH3OH);
    mpf_mul(   r_b[41],    r_b[41],       free);
    mpf_mul(   r_b[42],    k_b[42],  theta_CH2);
    mpf_mul(   r_b[42],    r_b[42],       free);
    mpf_mul(   r_b[43],    k_b[43],  theta_CH3);
    mpf_mul(   r_b[43],    r_b[43],       free);
    mpf_mul(   r_b[44],    k_b[44],  theta_CH4);
    mpf_mul(   r_b[44],    r_b[44],       free);
    mpf_mul(   r_b[45],    k_b[45],  theta_H2O);
    mpf_mul(   r_b[45],    r_b[45],       free);
    mpf_mul(   r_b[46],    k_b[46], theta_CH2O);
    mpf_mul(   r_b[46],    r_b[46],       free);
    mpf_mul(   r_b[47],    k_b[47], theta_CH3O);
    mpf_mul(   r_b[47],    r_b[47],       free);
    mpf_mul(   r_b[47],    r_b[47],       free);
    mpf_mul(   r_b[48],    k_b[48],        p_S);
    mpf_mul(   r_b[48],    r_b[48],       free);
    mpf_mul(   r_b[48],    r_b[48],       free);
    mpf_mul(   r_b[48],    r_b[48],       free);
    mpf_mul(   r_b[48],    r_b[48],       free);
    mpf_mul(   r_b[49],    k_b[49],        p_M);
    mpf_mul(   r_b[49],    r_b[49],       free);
    mpf_mul(   r_b[49],    r_b[49],       free);
    mpf_mul(   r_b[49],    r_b[49],       free);
    mpf_mul(   r_b[49],    r_b[49],       free);
    mpf_mul(   r_b[50],    k_b[50],        p_X);
    mpf_mul(   r_b[50],    r_b[50],       free);
    mpf_mul(   r_b[50],    r_b[50],       free);
    mpf_mul(   r_b[50],    r_b[50],       free);
    mpf_mul(   r_b[51],    k_b[51],    p_CH3OH);
    mpf_mul(   r_b[51],    r_b[51],       free);
    mpf_mul(   r_b[52],    k_b[52],      p_CH4);
    mpf_mul(   r_b[52],    r_b[52],       free);
    mpf_mul(   r_b[53],    k_b[53],      p_H2O);
    mpf_mul(   r_b[53],    r_b[53],       free);
    mpf_mul(   r_b[54],    k_b[54],        p_K);
    mpf_mul(   r_b[54],    r_b[54],       free);
    mpf_mul(   r_b[54],    r_b[54],       free);
    mpf_mul(   r_b[54],    r_b[54],       free);
    mpf_mul(   r_b[54],    r_b[54],       free);
    //not using r[55] through r[74]?!
    //also, consider making below assignments in-order (might help optimizer).
    mpf_mul(   r_b[71],    k_b[71],    theta_Z);
    mpf_mul(   r_b[71],    r_b[71],    theta_H);
    mpf_mul(   r_b[72],    k_b[72],    theta_U);
    mpf_mul(   r_b[72],    r_b[72],   theta_CH);
    mpf_mul(   r_b[73],    k_b[73],   theta_Z1);
    mpf_mul(   r_b[73],    r_b[73],    theta_H);
    mpf_mul(   r_b[74],    k_b[74],    theta_N);
    mpf_mul(   r_b[74],    r_b[74],   theta_CO);
    mpf_mul(   r_b[75],    k_b[75],    theta_Y);
    mpf_mul(   r_b[75],    r_b[75],       free);
    mpf_mul(   r_b[76],    k_b[76],    theta_R);
    mpf_mul(   r_b[76],    r_b[76],   theta_OH);
    mpf_mul(   r_b[77],    k_b[77],  theta_CHO);
    //
    // steps including C, D, K, Q.
    mpf_mul(    r_b[2],     k_b[2],    theta_C);
    mpf_mul(    r_b[2],     r_b[2],       free);
    mpf_mul(    r_b[3],     k_b[3],    theta_D);
    mpf_mul(    r_b[3],     r_b[3],   theta_OH);
    mpf_mul(    r_b[9],     k_b[9],    theta_K);
    mpf_mul(    r_b[9],     r_b[9],   theta_OH);
    mpf_mul(   r_b[10],    k_b[10],    theta_K);
    mpf_mul(   r_b[10],    r_b[10],       free);
    mpf_mul(   r_b[20],    k_b[20],    theta_Q);
    mpf_mul(   r_b[20],    r_b[20],    theta_H);
    mpf_mul(   r_b[29],    k_b[29],    theta_R);
    mpf_mul(   r_b[29],    r_b[29],  theta_CH2);


    //OVERALL REACTION RATES:
    for(i = 0; i < 78; i++) {
        mpf_sub(      r[i],     r_f[i],     r_b[i]);
    }
    

    //---------------------------------------------------------


    // apply the steady state approximation for all thetas.
    //NOTE: need to put in GNU MP ops + rewrite to array accesses.
    /*out[0]  = r_04 + r_12 + r_21 + r_23 - r_11;     // d(theta_E)/dt=0
    out[1]  = r_05 - r_12 - r_13 - r_14 - r_37;     // d(theta_F)/dt=0
    out[2]  = r_06 + r_14 + r_22 + r_34 - r_15 - r_16 - r_75; // d(theta_G)/dt=0
    out[3]  = r_07 - r_17 - r_18 - r_39;            // d(theta_I)/dt=0
    out[4]  = r_13 - r_21 - r_22;                   // d(theta_L)/dt=0
    out[5]  = r_15 - r_23 - r_24 - r_49;            // d(theta_M)/dt=0 catechol
    out[6]  = r_16 + r_17 + r_26 + r_74 - r_25;     // d(theta_N)/dt=0
    out[7]  = r_18 + r_37 - r_26 - r_27 - r_71;     // d(theta_O)/dt=0
    out[8]  = r_25 + r_29 + r_76 - r_30;            // d(theta_R)/dt=0
    out[9] = r_11 + r_30 + r_33 + r_40 - r_31 - r_32 - r_48; // d(theta_S)/dt=0 phenol
    out[10] = r_27 + r_39 + r_72 - r_34;            // d(theta_U)/dt=0
    out[11] = r_31 - r_35;                          // d(theta_V)/dt=0
    out[12] = r_35 + r_36 - r_50;                   // d(theta_X)/dt=0 benzene

    out[13] = r_03 + r_09 + r_23 + r_31 + r_31 + r_33 - r_45; // d(theta_OH)/dt=0
    out[14] = r_45 - r_53;                          // d(theta_H2O)/dt=0
    out[15] = r_22 + r_72 - r_42;                   // d(theta_CH)/dt =0
    out[16] = r_14 + r_19 + r_27 + r_29 + r_42 - r_43; // d(theta_CH2)/dt=0    
    out[17] = r_06 + r_43 - r_44;                   // d(theta_CH3)/dt=0
    out[18] = r_44 - r_52;                          // d(theta_CH4)/dt=0
    out[19] = r_21 + r_77 - r_46;                   // d(theta_CHO)/dt=0
    out[20] = r_12 + r_26 + r_46 - r_47;            // d(theta_CH2O)/dt=0
    out[21] = r_04 + r_17 + r_47 - r_41;            // d(theta_CH3O)/dt=0
    out[22] = r_41 - r_51;                          // d(theta_CH3OH)/dt=0
    out[23] = r_00 - r_01 - r_04 - r_05 - r_06 - r_07; // d(theta_A)/dt=0
//    out[23] = theta_A - k_00_f/k_00_b*p_A*free*free*free*free; // d(theta_A)/dt=0 if step 0 is in equilibrium.
    out[24] = r_32 - r_36;                          // d(theta_W)/dt=0
    out[25] = r_24 + r_28 - r_33;                   // d(theta_T)/dt=0
    out[26] = r_01 - r_08 - r_40;                   // d(theta_B)/dt=0
    out[27] = r_08 - r_19;                          // d(theta_J)/dt=0
    out[28] = r_19 - r_28;                          // d(theta_P)/dt=0
    out[29] = theta_H - exp(-( (-1.374+0.076+0.683)/2 + 2*0.084*(theta_H-0.139))/KB/T)*pow(p_H2,0.5)*free; //theta_H
    out[30] = r_02 - r_09;                          // d(theta_C)/dt=0
    out[31] = r_03 - r_10;                          // d(theta_D)/dt=0
    out[32] = r_09 + r_10 - r_20 - r_54;            // d(theta_K)/dt=0
    out[33] = r_20 - r_29;                          // d(theta_Q)/dt=0
    out[34] = r_75 - r_76;                          // d(theta_Y)/dt=0
    out[35] = r_71 - r_72 - r_73;                   // d(theta_Z)/dt=0
    out[36] = r_73 - r_74;                          // d(theta_Z1)/dt=0
    out[37] = theta_CO - exp(-(-2.131+0.028+1.764)/KB/T)*p_CO*free; // d(theta_CO)/dt=0*/

    // finally the summation of all thetas should be 1.
    //NOTE: need to put in GNU MP ops.
    /*mpf_set(out[38], ( 4*ctx->state[0]  + 4*ctx->state[1]  + 4*ctx->state[2]  + 4*ctx->state[3]
                     + 4*ctx->state[4]  + 4*ctx->state[5]  + 4*ctx->state[6]  + 4*ctx->state[7]
                     + 4*ctx->state[8]  + 4*ctx->state[9]  + 4*ctx->state[10] + 5*ctx->state[11]
                     + 3*ctx->state[12] + 3*ctx->state[13] + ctx->state[14]   + ctx->state[15]
                     + ctx->state[16]   + ctx->state[17]   + ctx->state[18]   + 2*ctx->state[19]
                     + ctx->state[20]   + ctx->state[21]   + 2*ctx->state[22] + 2*ctx->state[23]
                     + ctx->state[24]   + ctx->state[25]   + 4*ctx->state[26] + 5*ctx->state[27]
                     + 4*ctx->state[28] + 4*ctx->state[29] + 5*ctx->state[30] + 4*ctx->state[31]
                     + 4*ctx->state[32] + 4*ctx->state[33] + 5*ctx->state[34] + 4*ctx->state[35]
                     + 4*ctx->state[36] + 4*ctx->state[37] + ctx->state[38]   - 1.00 )
             );*/

    //NOTE: need to put in GNU MP ops + rewrite to array accesses.
    /*K_H = exp(-( (-1.374+0.076+0.683)/2 + 2*0.084*(theta_H-0.139))/KB/T);*/


    //---------------------------------------------------------
    //OUTPUT:
    //To send output to a file, run this program like so:
    //`$ ./theta.exe > output.txt`
    printf("OVERALL REACTION RATES:\n");
    for(i = 0; i < 78; i++) {
        gmp_printf("r[%d] = %Fg\n", i, r[i]);
    }
    gmp_printf("K_H = %Fg\n", K_H);

    printf("\nFORWARD REACTION RATES:\n");
    for(i = 0; i < 78; i++) {
        gmp_printf("r_f[%d] = %Fg\n", i, r_f[i]);
    }

    printf("\nREVERSE REACTION RATES:\n");
    for(i = 0; i < 78; i++) {
        gmp_printf("r_b[%d] = %Fg\n", i, r_b[i]);
    }


    //---------------------------------------------------------
    //FREES:

    //free up the memory GNU MP allocated behind the scenes:

    //free r[]:
    for(i = 0; i < 78; i++) {
        mpf_clear(r[i]);
    }
    //free r_f[]:
    for(i = 0; i < 78; i++) {
        mpf_clear(r_f[i]);
    }
    //free r_b[]:
    for(i = 0; i < 78; i++) {
        mpf_clear(r_b[i]);
    }

    //free forward and reverse rate constants:
    clearArray(k_f, 78);
    clearArray(k_b, 78);

    //free the various thetas:
    mpf_clear(theta_A);
    mpf_clear(theta_E);
    mpf_clear(theta_F);
    mpf_clear(theta_G);
    mpf_clear(theta_I);
    mpf_clear(theta_L);
    mpf_clear(theta_M);
    mpf_clear(theta_N);
    mpf_clear(theta_O);
    mpf_clear(theta_R);
    mpf_clear(theta_S);
    mpf_clear(theta_U);
    mpf_clear(theta_V);
    mpf_clear(theta_X);
    mpf_clear(free);
    mpf_clear(theta_H);
    mpf_clear(theta_OH);
    mpf_clear(theta_H2O);
    mpf_clear(theta_CH);
    mpf_clear(theta_CH2);
    mpf_clear(theta_CH3);
    mpf_clear(theta_CH4);
    mpf_clear(theta_CHO);
    mpf_clear(theta_CH2O);
    mpf_clear(theta_CH3O);
    mpf_clear(theta_CH3OH);
    mpf_clear(theta_W);
    mpf_clear(theta_T);
    mpf_clear(theta_B);
    mpf_clear(theta_J);
    mpf_clear(theta_P);
    mpf_clear(theta_C);
    mpf_clear(theta_D);
    mpf_clear(theta_K);
    mpf_clear(theta_Q);
    mpf_clear(theta_Y);
    mpf_clear(theta_Z);
    mpf_clear(theta_Z1);
    mpf_clear(theta_CO);

    //free K_H, temp, and e:
    mpf_clear(K_H);
    mpf_clear(temp);
    mpf_clear(e);

    //free partial pressures:
    mpf_clear(p_A);
    mpf_clear(p_H2);
    mpf_clear(p_M);
    mpf_clear(p_S);
    mpf_clear(p_X);
    mpf_clear(p_K); 
    mpf_clear(p_CO);
    mpf_clear(p_H2O);
    mpf_clear(p_CH4);
    mpf_clear(p_CH3OH);
    mpf_clear(KB);
    mpf_clear(T);


    //---------------------------------------------------------

}
Exemple #19
0
AutoCluster::~AutoCluster() 
{
	clearArray();
	if ( old_sig_attrs ) free(old_sig_attrs);
	if ( significant_attrs ) delete significant_attrs;
}
void item_rectangles::drawLine(QGraphicsScene *scene, QLineF lineItem, QSize smallRect)
{
    clearArray();

    int h_dir=0;
    int v_dir=0;

    int angle = qRound(lineItem.angle());

    //Calculate direction
    switch(angle)
    {
        case 0:
            h_dir=1;
            break;
        case 90:
            v_dir=-1;
            break;
        case 180:
            h_dir=-1;
            break;
        case 270:
            v_dir=1;
            break;
        default:
            if((angle>0)&&(angle<90))
            {
                h_dir=1;
                v_dir=-1;
            }
            else if((angle>90)&&(angle<180))
            {
                h_dir=-1;
                v_dir=-1;
            }
            else if((angle>180)&&(angle<270))
            {
                h_dir=-1;
                v_dir=1;
            }
            else if((angle>270)&&(angle<360))
            {
                h_dir=1;
                v_dir=1;
            }
        break;
    }

    long x = lineItem.p1().x();
    long y = lineItem.p1().y();

    long tW = fabs(qRound(lineItem.dx())); //targetWidth
    long tH = fabs(qRound(lineItem.dy())); //targetHeight

        QBrush brush = QBrush(Qt::darkYellow);

    for(int k=0,l=0, i=0, j=0; (i<=tW)&&(j<=tH); i+=smallRect.width()*fabs(h_dir), j+=smallRect.height()*fabs(v_dir),k++,l++ )
    {
        long x1 = x + k * smallRect.width()*h_dir;
        long y1 = y + l * smallRect.height()*v_dir;
        rectArray.push_back(scene->addRect(1, 1, smallRect.width()-2,
                                           smallRect.height()-2,
                                           QPen(Qt::yellow, 2), brush));
        rectArray.last()->setPos(x1, y1);
        rectArray.last()->setData(0, "YellowRectangle");
        rectArray.last()->setOpacity(0.7);
        rectArray.last()->setZValue(10000);
    }
}
Exemple #21
0
bool AutoCluster::config(const char* significant_target_attrs)
{
	bool sig_attrs_changed = false;
	char *new_sig_attrs =  param ("SIGNIFICANT_ATTRIBUTES");

	dprintf(D_FULLDEBUG,
		"AutoCluster:config(%s) invoked\n",
		significant_target_attrs ? significant_target_attrs : "(null)" );

		// Handle the case where our significant attributes came from
		// the config file, and now the user removed them from the 
		// config file.  In this case, we want to wipe the slate clean.
	if ( sig_attrs_came_from_config_file && !new_sig_attrs ) {
		sig_attrs_changed = true;
		delete significant_attrs;
		significant_attrs = NULL;
		sig_attrs_came_from_config_file = false;
	}

	if ( new_sig_attrs ) {
		if ( sig_attrs_came_from_config_file == false ) {
			// in this case, we were autocomputing sig attrs, and now
			// they are set in the config file -- so wipe the slate clean.
			sig_attrs_changed = true;
			delete significant_attrs;
			significant_attrs = NULL;
		}
		sig_attrs_came_from_config_file = true;
	} 

		// Always use what the user specifies in the config file.
		// If the user did not specify anything, then we want to use
		// the significant attrs passed to us (that likely originated
		// from the matchmaker).
	if ( !new_sig_attrs && significant_target_attrs ) {
		new_sig_attrs = strdup(significant_target_attrs);
		sig_attrs_came_from_config_file = false;
	}

		// If we are in danger of running out of IDs, clear all auto clusters
		// and reset next_id so we can reclaim unused IDs.
	bool next_id_exhausted = next_id > INT_MAX/2;

		// If no new_sig_attrs, and sig_attrs_changed not flagged, then
		// nothing is new and we have nothing more to do.
	if ( !new_sig_attrs && !sig_attrs_changed && !next_id_exhausted ) {
		return false;
	}


	if ( significant_attrs && old_sig_attrs  && (strcasecmp(new_sig_attrs,old_sig_attrs)==0) && !next_id_exhausted )
	{
		/* 	Just compare new and old attr strings directly.
			If they match, then we already have dealt with the
			significant attributes listed in the new string, so
			we can keep all our state (i.e. our array) and just
			return.
			We do this direct comparison because it is a common
			case that will allow us to bail out early before
			we do the more expensive work below.
		*/
		free(new_sig_attrs);	// don't leak - param() calls malloc
		return false;
	}

	if ( ! significant_attrs ) {
			// Create significant_attrs from new_sig_attrs
		significant_attrs = new StringList(new_sig_attrs);
		sig_attrs_changed = true;
	} else {
			// Merge everythying in new_sig_attrs into our existing
			// significant_attrs.  Take note if significant_attrs changed,
			// since we need to return this info to our caller.
		StringList new_attrs(new_sig_attrs);
		sig_attrs_changed = significant_attrs->create_union(new_attrs,true);
	}
	
		// the SIGNIFICANT_ATTRIBUTES setting changed, purge our
		// state.
	if ( sig_attrs_changed || next_id_exhausted ) {
		clearArray();
	}

		// update old_sig_attrs
	if ( old_sig_attrs ) {
		free(old_sig_attrs);
		old_sig_attrs = NULL;

	}
	old_sig_attrs = new_sig_attrs;

	if ( sig_attrs_changed ) {
		dprintf(D_ALWAYS,
			"AutoCluster:config() significant attributes changed to %s\n",
			new_sig_attrs ? new_sig_attrs : "(null)");
	} else {
		dprintf(D_FULLDEBUG,
			"AutoCluster:config() significant attributes unchanged\n");
	}
		

	return sig_attrs_changed;
}
 //deconstructor method
 Base::~Base()
 {
     clearArray();
 }
Exemple #23
0
int main(void)
{
	lcd.clearMarkers();
	//init analog if needed
	init_analog();
	srand(adc_read(0));
	
	//pin 0 on portb output. 
	//led stays on if iterations between fields are the same (same number of cells)
	DDRB |= _BV(PB0);
	
	//clear the buffer.
	clearArray(buffer);
	
	//if house define insert that.
	#ifdef PATTERN
		insert_pattern(field, Glider, 0,0);
	#endif
	//else random field.
	#ifdef RANDOM
		createRandomField(field);
	#endif
	
	//set contrast.
	lcd.setContrast(17);
	//make sure to start at location 0,0
	lcd.setCursor(0,0);
	
	//position is field size, I refresh the screen Backwards.
	position = fieldSize;
	while(position--)
	{
		//display field with current position
		showField(field, fieldSize-position);
		//here the rules of the game of life are checked.
		//if a position has a cell (1),
		//then look how many around,
		//if 2 or 3 around it lives, else it dies.
		//if(field[position])
		//{
		//	if(totalAround(field, position)==surviveAbility)
		//	{
		//		buffer[position]=1;
		//	}
		//	else if(totalAround(field, position)==surviveAbility+1)
		//	{
		//		buffer[position]=1;
		//	}
		//	else
		//	{
		//		buffer[position]=0;
		//	}
		//}
		//else
		//{
			//but if a position in the field is empty
			//and it has 3 around, that position becomes alife.
			
		//	if(totalAround(field, position)==reproductiveNumber)
		//	{
		//		buffer[position] = 1;
		//	}
		//	else
		//	{
		//		buffer[position] = 0;
		//	}
		//}
		//position keeps position in the field array,
		//and at the same time drawing location on
		//screen.
		if(position == 0)
		{
			//insert changes into the field.
			copy_buffer(buffer, field);
			//reset position to 0
			position = fieldSize;
			//set frame rate with a blocking delay..
			delay(adc_read(1));
			//check wether we are in a steady state or just still evolving.
			currentState = checkField(field);
			//set contrast with pot meter on analog pin 1 (not 0)
			lcd.setContrast(32/2);
			//change field if field the same a while, or iterations goes above a certain number which meens it's probaly in a loop
			//check if button is pressed and create a new field.
			if(changeCount == holdingNumber || (iterations > 1000) || (PINB & (1<<PB2)))
			{
				//reset changeCount
				changeCount = 0;
				//reset iteration count.
				iterations = 0;
				//create a random playing field.
				#ifdef PATTERN
					insert_pattern(field, Glider, 0,0);
				#endif
					//createRandomField(field);
				//put a pattern we created onto the field.
				//insert_field(stable, field);
				
			}
			//if the field states stay the same.
			else if(currentState == previousState)
			{
				PORTB |= (1<<PB0);
				changeCount++;
			}
			//if the field states are different.
			else
			{
				PORTB &= ~(1<<PB0);
				previousState = currentState;
				//that is why setting it to zero.
				iterations++;
				//changeCount shouldn't change if the inbetween states happen te be the same.
				changeCount = 0;
			}
		//set location and nicely print something.
		lcd.setCursor(0,5);
		writeFormated(iterations,changeCount,"Game of Life:");
		}
	}
	return 0;
}
Exemple #24
0
void clearField(uint8_t *buffer)
{
	clearArray(buffer);
}