예제 #1
0
int main()
{
    int type;
    double op2;
    char s[MAXOP];

    while ((type = getop(s)) != EOF) {
        switch (type) {
            case NUMBER:
                push(atof(s));
                break;
            case LIBFUNC:
                push(dofunc(s));
                break;
            case GETVAR:
                // 1 a= a +
                push(get_var(s[0]));
                break;
            case SETVAR:
                // 1 a=
                op2 = pop();
                save_var(op2, s[0]);
                push(op2);
                break;
            case '+':
                push(pop() + pop());
                break;
            case '*':
                push(pop() * pop());
                break;
            case '-':
                op2 = pop();
                push(pop() - op2);
                break;
            case '/':
                op2 = pop();
                if (op2 != 0.0)
                    push(pop() / op2);
                else
                    printf("error: zero divisor\n");
                break;
            case '%':
                op2 = pop();
                if (op2 != 0.0)
                    push(fmod(pop(), op2));
                else
                    printf("error: zero divisor\n");
                break;
            case '\n':
                recent_result = pop();
                printf("\t = %.8g\n", recent_result);
                break;
            default:
                printf("error: unknown command %s\n", s);
                break;
        }
    }

    return 0;
}
예제 #2
0
파일: multvar.c 프로젝트: rforge/muste
static int max_var()    /* Stepwise_computation_of_Mvar() in pseudocode */
        {
        int i,j,k;
        char text[LLENGTH];
    //  double a;
        int ii;

        /* m is p in pseudocode */
        /* ii is i in pseudocode */
        /* indexing from 1 to p instead of from 0 to m-1 in pseudocode */

        tr_max=-1.0; /* Mvar in pseudocode */
        for (ii=0; ii<m; ++ii)
            {
            if (ii==0) for (i=0; i<m; ++i) p[i]=i;   /* p is q in pseudocode */
            else
                {
                k=0; p[0]=ii; j=0;
                for (i=1; i<m; ++i)
                    {
                    p[i]=j+k;
                    if (i==ii) k=1;
                    ++j;
                    }
                }

            k=sum2_Cholesky(rr,m); /* rr is S in pseudocode */
            if (k<0)
                {
                sprintf(sbuf,"\n %d gives the same value as %d",ii+1,-k);
                sur_print(sbuf);
                }
            else
                {
                sprintf(sbuf,"\n %d %g %g",ii+1,tr,tr_max); sur_print(sbuf);
                if (tr>tr_max)
                    {
                    tr_max=tr;
                    for (i=0; i<m; ++i) p_max[i]=p[i];
                    }
                }
            if (sur_kbhit()) { i=sur_getch(); if (i=='.') break; }

            }

        for (i=0; i<m; ++i) p[i]=p_max[i];
        for (i=0; i<m; ++i) for (j=0; j<m; ++j)
            rr11[i+m*j]=rr[p[i]+m*p[j]];
        save_var(rr11,m,text);

        output_open(eout);
        fnconv(tr_max,accuracy+2,text);
        sprintf(sbuf,"Mvar[%s]=%s (Total variability in a %d*%d matrix)",
                          word[1],sppois(text),m,m);
        print_line(sbuf);
        print_line("MAT LOAD COVVAR.M,END+2 / Optimally permuted covariance matrix");
        return(1);
        }
예제 #3
0
파일: vars.c 프로젝트: Fluray/sbunix
/**
* Adds all the environment variables to the variable cache
*/
void setup_vars(char **argv, char **envp) {
    char *equals;
    int i = 0;
    while(*envp != NULL) {
        equals = strchr(*envp, '=');
        *equals = '\0';
        save_var(*envp, equals + 1);
        *equals = '=';
        envp++;
    }
    while(*argv != NULL && i < 10) {
        char var_name[2] = {0};
        var_name[0] = '0' + i;
        save_var(var_name, *argv);
        argv++;
        i++;
    }
    /* Initialize $? variable */
    save_var("?", "0");
}
예제 #4
0
void INISetInt( const char *key, int val, const char *comment /* = NULL */ ){
	char s[1000];

	if ( comment ) {
		sprintf( s, "%d        ; %s", val, comment );
	}
	else{
		sprintf( s, "%d", val );
	}
#if defined( __linux__ ) || defined( __APPLE__ )
	save_var( INIfn, CONFIG_SECTION, key, s );
#else
	WritePrivateProfileString( CONFIG_SECTION, key, s, INIfn );
#endif
}
예제 #5
0
//查询是否有接收数据,并进行处理。rebuf 为可供使用的缓冲区
//
nrf_result_e nrf_msg_rx(com_e  *com, uint8 *rebuf)
{
    com_e   comtmp;
    uint32  len;
    uint32  tmplen;
    uint32  relen;                              //接收到的数据长度
    uint8   *buftemp;

    uint32  totallen ;                          //总需要接收包的数目(包的整数倍)
    uint16  tmpcheck;

RE_LOOP:
    buftemp = rebuf;                            //加载起始地址

    relen = nrf_rx(buftemp, DATA_PACKET);       //接收 第一个包
    if(relen == 0)
    {
        //如果是 预校验 失败,那么 肯定可以接收到数据,不会进入此处

        //只有 一开始 进入函数 第一次接收的时候,才出现接收失败

        return NRF_RESULT_RX_NO;                //没接收到数据
    }

    comtmp = (com_e)buftemp[0];
    if(((uint8)comtmp < (uint8)COM_MAX) && (buftemp[1] ==  (uint8)~comtmp) && (comtmp != COM_RETRAN) )
    {
        //校验正确,继续接收剩余 的数据

        totallen = nrf_com_totalsize[comtmp];   //总接收参数

        if(totallen > relen )                   //数据长度 超过 已接收长度
        {
            //需要继续接收
            len = totallen - relen;             //剩余接收的 长度

            //等待接收FIFO里的数据校验正确才接收
            while( !nrf_rx_fifo_check(nrf_com_size[comtmp] + 2 * COM_LEN - relen,&tmpcheck)  );   //等待接收
            if( tmpcheck !=  (uint16)((uint8)~comtmp + (comtmp<<8)))
            {
                goto RE_LOOP;                   //校验失败 ,放弃刚才接收的 第一个 包 (重新接收数据)
            }

            tmplen = relen;
            do
            {
                buftemp += tmplen;              //移动到尚未接收数据的缓冲区
                tmplen = nrf_rx(buftemp, len);  //接收数据
                //relen += tmplen;
                len -= tmplen;
            }
            while(len);
        }

        //校验尾部数据是否正确
        if(
            (rebuf[nrf_com_size[comtmp] + 2 * COM_LEN - 2] ==   (uint8)~comtmp)
            &&  (rebuf[nrf_com_size[comtmp] + 2 * COM_LEN - 1] ==   (uint8) comtmp)   )
        {
            *com = comtmp;                          //存储命令

            //对 命令 数据进行 处理
            switch(*com)
            {
            case COM_VAR:
                last_tab = *((uint32 *)&rebuf[COM_LEN]);                                    //读取变量编号
                if(last_tab < VAR_MAX)
                {
                    save_var((var_tab_e)last_tab, *((uint32 *)&rebuf[COM_LEN + sizeof(uint32)]));          //存储 变量
                    var_display(last_tab);                                                  //显示 变量
                }
                else
                {
                    return NRF_RESULT_RX_NOVALID;
                }
                break;
            default:
                break;
            }

            return NRF_RESULT_RX_VALID;             //接收有效数据
        }
    }

    //有接收到数据,但接收数据无效
    return NRF_RESULT_RX_NOVALID;
}
예제 #6
0
bool profile_save_string (const char * filename, const char *section, const char *key, const char *value)
{
    return save_var (filename, section, key, value);
}
예제 #7
0
bool profile_save_float (const char *filename, const char *section, const char *key, float value)
{
    char buf[16];
    sprintf (buf, "%f", value);
    return save_var (filename, section, key, buf);
}
예제 #8
0
bool WINAPI profile_save_int (const char *filename, const char *section, const char *key, int value)
{
  char buf[16];
  sprintf (buf, "%d", value);
  return save_var (filename, section, key, buf);
}
예제 #9
0
파일: control.cpp 프로젝트: Glennzhjw/CCEMO
void run(char* func_name, int iRun)
{
	iter=0;
	iter_each=0;
	cnArch=0;

	char objsal[256];
	char varsal[256];
	char timesal[256];
	strcpy(testInstance,func_name);

	double start_time,end_time;
	double duration;

	sprintf(objsal,"results/FUN_%s_%d_%d",testInstance,nDim,iRun);
	sprintf(varsal,"results/VAR_%s_%d_%d",testInstance,nDim,iRun);
	sprintf(timesal,"results/TIME_%s_%d",testInstance,nDim);

	if(mpi_rank==0)
		start_time=clock();

	initializeProblem();
	initializePopulation();
// 	showPopulation();
	initializeIndex();
	if(mpi_color)
		evaluatePopInitial();
	MPI_Barrier(MPI_COMM_WORLD);
	if(master_flag)
		collection_initial();
	if(!mpi_color&&mpi_rank_master==mpi_rank_master_archive)
		refineRepertory_generateArchive();
	MPI_Barrier(MPI_COMM_WORLD);
	if(master_flag)
		SynchronizeArchive();
	SynchronizeArchive_one();
// 	refineRepertory_generateArchive_SDE();
// 	showArchive();
// 	showLimits();
	if(mpi_color)
	{
		update_xBest_initial();
		update_xBest_archive();
	}
	MPI_Barrier(MPI_COMM_WORLD);
	iter=nPop*nObj;

// 	for(int i=0;i<mpi_size;i++)
// 	{
// 		if(i==0&&mpi_rank==0)
// 			showArchive();
// 		if(i!=0&&mpi_rank==i)
// 		{
// 			showGlobalBest();
// 			showPopulation();
// 		}
// 		MPI_Barrier(MPI_COMM_WORLD);
// 	}

	while(iter<maxIteration)
	{
		iter_each=0;
		nRep=0;
		if(mpi_color)
		{
			update_objective();
			permIndexes();
		}
		else
		{
			update_archive();
			perm_archIndex();
		}
		MPI_Barrier(MPI_COMM_WORLD);
// 		showGlobalBest();
		if(master_flag)
		{
			collect2master_archive();
			if(mpi_rank_master==mpi_rank_master_archive)
				refineRepertory_generateArchive();
			SynchronizeArchive();
		}
		SynchronizeArchive_one();
		if(mpi_color)
			update_xBest_archive();
// 		showArchive();
		MPI_Barrier(MPI_COMM_WORLD);
		update_iteration();
	}

	if(mpi_rank==0)
	{
		end_time=clock();
		duration=(end_time-start_time)/CLOCKS_PER_SEC;
	}

	if(mpi_rank==0)
	{
		fpttime=fopen(timesal,"a");
		fprintf(fpttime, "%e\n", duration);

		get_nonDominateSize();

		fptobj=fopen(objsal,"w");
		save_obj(fptobj);

		fptvar=fopen(varsal,"w");
		save_var(fptvar);

		fclose(fpttime);
		fclose(fptobj);
		fclose(fptvar);
	}
}