version 1.4, 2000/02/09 22:10:24
|
version 1.5, 2000/02/22 18:19:02
|
Line 37 int
|
Line 37 int
|
match_function(func, argc) char *func; int argc; |
match_function(func, argc) char *func; int argc; |
{ |
{ |
if( !strcmp(func,"random") ) return (((argc==2 || argc==3)? RANDOM_F : MIS_ARG_COUNT)); |
if( !strcmp(func,"random") ) return (((argc==2 || argc==3)? RANDOM_F : MIS_ARG_COUNT)); |
if( !strcmp(func,"random_normal") ) return (((argc==2 || argc==3)? RANDOM_NORMAL_F : MIS_ARG_COUNT)); |
if( !strcmp(func,"random_normal") ) return ((argc==5)? RANDOM_NORMAL_F : MIS_ARG_COUNT); |
if( !strcmp(func,"random_exponential") ) return (((argc==2 || argc==3)? RANDOM_EXPONENTIAL_F : MIS_ARG_COUNT)); |
if( !strcmp(func,"random_beta") ) return ((argc==5)? RANDOM_BETA_F : MIS_ARG_COUNT); |
if( !strcmp(func,"random_beta") ) return (((argc==2 || argc==3)? RANDOM_BETA_F : MIS_ARG_COUNT)); |
if( !strcmp(func,"random_gamma") ) return ((argc==5)? RANDOM_GAMMA_F : MIS_ARG_COUNT); |
|
if( !strcmp(func,"random_poisson") ) return ((argc==4)? RANDOM_POISSON_F : MIS_ARG_COUNT); |
|
if( !strcmp(func,"random_exponential") ) return ((argc==4)? RANDOM_EXPONENTIAL_F : MIS_ARG_COUNT); |
|
if( !strcmp(func,"random_chi") ) return ((argc==4)? RANDOM_CHI_F : MIS_ARG_COUNT); |
|
if( !strcmp(func,"random_noncentral_chi") ) return ((argc==4)? RANDOM_NONCENTRAL_CHI_F : MIS_ARG_COUNT); |
if( !strcmp(func,"choose") ) return (CHOOSE_F); |
if( !strcmp(func,"choose") ) return (CHOOSE_F); |
if( !strcmp(func,"tex") ) return (((argc==2)? TEX_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"tex") ) return (((argc==2)? TEX_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"var_in_tex") ) return (VAR_IN_TEX_F); |
if( !strcmp(func,"var_in_tex") ) return (VAR_IN_TEX_F); |
Line 62 match_function(func, argc) char *func; i
|
Line 66 match_function(func, argc) char *func; i
|
if( !strcmp(func,"strlen") ) return (((argc==1)? STRLEN_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"strlen") ) return (((argc==1)? STRLEN_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"get_seed") ) return (((argc==0)? GET_SEED_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"get_seed") ) return (((argc==0)? GET_SEED_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"set_seed") ) return (((argc==1)? SET_SEED_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"set_seed") ) return (((argc==1)? SET_SEED_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"init_array") ) return (((argc==1)? INIT_ARRAY_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"init_array") ) return (((argc==1)? INIT_ARRAY_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"array_index") ) return (((argc==1)? ARRAY_INDEX_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"array_index") ) return (((argc==1)? ARRAY_INDEX_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"array_sorted_index") ) return (((argc==2)? ARRAY_SORTED_INDEX_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"array_sorted_index") ) return (((argc==2)? ARRAY_SORTED_INDEX_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"array_max") ) return (((argc==1)? ARRAY_MAX_F: MIS_ARG_COUNT)); |
if( !strcmp(func,"array_max") ) return (((argc==1)? ARRAY_MAX_F: MIS_ARG_COUNT)); |
Line 278 ArgNode_t *argp;
|
Line 282 ArgNode_t *argp;
|
capa_msg(MESSAGE_ERROR,tmpS); |
capa_msg(MESSAGE_ERROR,tmpS); |
} |
} |
} break; |
} break; |
|
|
case CHOOSE_F: { int ii, pick=1; |
case CHOOSE_F: { int ii, pick=1; |
ArgNode_t *tmpArgp; |
ArgNode_t *tmpArgp; |
|
|
Line 749 ArgNode_t *argp;
|
Line 754 ArgNode_t *argp;
|
resultp->s_type = I_CONSTANT; |
resultp->s_type = I_CONSTANT; |
resultp->s_int = 0; |
resultp->s_int = 0; |
} break; |
} break; |
case ARRAY_MOMENTS_F: /* it */ |
/* generate random numbers according to a pre-defined distributions and a seed */ |
|
case RANDOM_NORMAL_F: /* random_normal(return_array,item_cnt,seed,av,std_dev) */ |
|
case RANDOM_BETA_F: /* random_beta(return_array,item_cnt,seed,aa,bb) */ |
|
case RANDOM_GAMMA_F: /* random_gamma(return_array,item_cnt,seed,a,r) */ |
|
case RANDOM_POISSON_F: /* random_poisson(return_array,item_cnt,seed,mu) */ |
|
case RANDOM_EXPONENTIAL_F: |
|
/* random_exponential(return_array,item_cnt,seed,av) */ |
|
case RANDOM_CHI_F: /* random_chi(return_array,item_cnt,seed,df) */ |
|
case RANDOM_NONCENTRAL_CHI_F: |
|
/* random_noncentral_chi(return_array,item_cnt,seed,df,xnonc) */ |
|
/* gen_random_by_selector(output_p,sel,seed,item_cnt,p1,p2) */ |
|
{ int sel, item_cnt, tmp_int; |
|
float para1, para2; |
|
char *tmp_str; |
|
long tmp_long; |
|
Symbol *r_p; |
|
|
|
switch(func) { /* assigns the function selector */ |
|
case RANDOM_NORMAL_F: sel = NORMAL_DIS; break; |
|
case RANDOM_BETA_F: sel = BETA_DIS; break; |
|
case RANDOM_GAMMA_F: sel = GAMMA_DIS; break; |
|
case RANDOM_POISSON_F: sel = POISSON_DIS; break; |
|
case RANDOM_EXPONENTIAL_F: sel = EXPONENTIAL_DIS; break; |
|
case RANDOM_CHI_F: sel = CHI_DIS; break; |
|
case RANDOM_NONCENTRAL_CHI_F: sel = NONCENTRAL_CHI_DIS; break; |
|
} |
|
switch(func) { |
|
case RANDOM_NORMAL_F: |
|
case RANDOM_BETA_F: |
|
case RANDOM_GAMMA_F: /* two-parameter functions */ |
|
{ errCode = 0; |
|
switch( FIRST_ARGTYPE(argp) ) { /* parameter two */ |
|
case I_VAR: case I_CONSTANT: |
|
para2 = (float)FIRST_ARGINT(argp); |
|
break; |
|
case R_VAR: case R_CONSTANT: |
|
para2 = (float)FIRST_ARGREAL(argp); |
|
break; |
|
case S_VAR: case S_CONSTANT: |
|
case IDENTIFIER: |
|
resultp->s_type = S_CONSTANT; |
|
resultp->s_str = strsave("<<LAST ARG. OF THIS FUNCTION MUST BE A NUMBER>>"); |
|
sprintf(tmpS,"%s()'s last arg. must be a number.\n",FuncStack[Func_idx].s_name); |
|
capa_msg(MESSAGE_ERROR,tmpS); |
|
errCode = 1; |
|
break; |
|
} |
|
if(errCode == 0 ) { |
|
switch( SECOND_ARGTYPE(argp) ) { /* parameter one */ |
|
case I_VAR: case I_CONSTANT: |
|
para1 = (float)SECOND_ARGINT(argp); |
|
break; |
|
case R_VAR: case R_CONSTANT: |
|
para1 = (float)SECOND_ARGREAL(argp); |
|
break; |
|
case S_VAR: case S_CONSTANT: |
|
case IDENTIFIER: |
|
resultp->s_type = S_CONSTANT; |
|
resultp->s_str = strsave("<<FOURTH ARG. OF THIS FUNCTION MUST BE A NUMBER>>"); |
|
sprintf(tmpS,"%s()'s fourth arg. must be a number.\n",FuncStack[Func_idx].s_name); |
|
capa_msg(MESSAGE_ERROR,tmpS); |
|
errCode = 1; |
|
break; |
|
} |
|
if(errCode == 0 ) { |
|
switch( THIRD_ARGTYPE(argp) ) { /* seed */ |
|
case I_VAR: case I_CONSTANT: |
|
tmp_str = (char *)capa_malloc(32,1); |
|
sprintf(tmp_str,"%ld",THIRD_ARGINT(argp) ); |
|
break; |
|
case R_VAR: case R_CONSTANT: |
|
tmp_long = (long)THIRD_ARGREAL(argp); |
|
tmp_str = (char *)capa_malloc(32,1); |
|
sprintf(tmp_str,"%ld",tmp_long); |
|
break; |
|
case S_VAR: case S_CONSTANT: |
|
tmp_str = strsave(THIRD_ARGSTR(argp)); |
|
break; |
|
case IDENTIFIER: |
|
resultp->s_type = S_CONSTANT; |
|
resultp->s_str = strsave("<<THIRD ARG. OF THIS FUNCTION MUST BE A NUMBER>>"); |
|
sprintf(tmpS,"%s()'s third arg. must be a number.\n",FuncStack[Func_idx].s_name); |
|
capa_msg(MESSAGE_ERROR,tmpS); |
|
errCode = 1; |
|
break; |
|
} |
|
if(errCode == 0 ) { |
|
switch( FOURTH_ARGTYPE(argp) ) { /* item_cnt */ |
|
case I_VAR: case I_CONSTANT: |
|
item_cnt = FOURTH_ARGINT(argp); |
|
break; |
|
case R_VAR: case R_CONSTANT: |
|
item_cnt = (int)FOURTH_ARGREAL(argp); |
|
break; |
|
case S_VAR: case S_CONSTANT: |
|
case IDENTIFIER: |
|
resultp->s_type = S_CONSTANT; |
|
resultp->s_str = strsave("<<SECOND ARG. OF THIS FUNCTION MUST BE A NUMBER>>"); |
|
sprintf(tmpS,"%s()'s second arg. must be a number.\n",FuncStack[Func_idx].s_name); |
|
capa_msg(MESSAGE_ERROR,tmpS); |
|
errCode = 1; |
|
break; |
|
} |
|
if(errCode == 0 ) { |
|
switch( FIFTH_ARGTYPE(argp) ) { /* array_name, clear the content of this array first */ |
|
case I_VAR: case I_CONSTANT: |
|
case R_VAR: case R_CONSTANT: |
|
resultp->s_type = S_CONSTANT; |
|
resultp->s_str = strsave("<<FIRST ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>"); |
|
sprintf(tmpS,"%s()'s first arg. must be a name of an array.\n",FuncStack[Func_idx].s_name); |
|
capa_msg(MESSAGE_ERROR,tmpS); |
|
errCode = 1; |
|
break; |
|
case S_VAR: case S_CONSTANT: |
|
tmp_int = free_array(FIFTH_ARGSTR(argp)); |
|
r_p = gen_random_by_selector(FIFTH_ARGSTR(argp),sel,tmp_str,item_cnt,para1,para2); |
|
capa_mfree((char *)resultp); |
|
resultp = r_p; |
|
break; |
|
case IDENTIFIER: |
|
tmp_int = free_array(FIFTH_ARGNAME(argp)); |
|
r_p = gen_random_by_selector(FIFTH_ARGSTR(argp),sel,tmp_str,item_cnt,para1,para2); |
|
capa_mfree((char *)resultp); |
|
resultp = r_p; |
|
break; |
|
} |
|
} /* the fourth argument of this function (item_cnt) */ |
|
} /* the third argument of this function (seed) */ |
|
} /* the second argument of this function (paramenter one) */ |
|
} /* the first argument of this function (parameter two) */ |
|
|
|
} |
|
break; |
|
case RANDOM_POISSON_F: |
|
case RANDOM_EXPONENTIAL_F: |
|
case RANDOM_CHI_F: |
|
case RANDOM_NONCENTRAL_CHI_F: /* one parameter functions */ |
|
{ errCode = 0; |
|
switch( FIRST_ARGTYPE(argp) ) { /* parameter one */ |
|
case I_VAR: case I_CONSTANT: |
|
para2 = (float)FIRST_ARGINT(argp); |
|
break; |
|
case R_VAR: case R_CONSTANT: |
|
para2 = (float)FIRST_ARGREAL(argp); |
|
break; |
|
case S_VAR: case S_CONSTANT: |
|
case IDENTIFIER: |
|
resultp->s_type = S_CONSTANT; |
|
resultp->s_str = strsave("<<LAST ARG. OF THIS FUNCTION MUST BE A NUMBER>>"); |
|
sprintf(tmpS,"%s()'s last arg. must be a number.\n",FuncStack[Func_idx].s_name); |
|
capa_msg(MESSAGE_ERROR,tmpS); |
|
errCode = 1; |
|
break; |
|
} |
|
if(errCode == 0 ) { |
|
switch( SECOND_ARGTYPE(argp) ) { /* seed */ |
|
case I_VAR: case I_CONSTANT: |
|
tmp_str = (char *)capa_malloc(32,1); |
|
sprintf(tmp_str,"%ld",SECOND_ARGINT(argp) ); |
|
break; |
|
case R_VAR: case R_CONSTANT: |
|
tmp_long = (long)SECOND_ARGREAL(argp); |
|
tmp_str = (char *)capa_malloc(32,1); |
|
sprintf(tmp_str,"%ld",tmp_long); |
|
break; |
|
case S_VAR: case S_CONSTANT: |
|
tmp_str = strsave(SECOND_ARGSTR(argp)); |
|
break; |
|
case IDENTIFIER: |
|
resultp->s_type = S_CONSTANT; |
|
resultp->s_str = strsave("<<THIRD ARG. OF THIS FUNCTION MUST BE A NUMBER>>"); |
|
sprintf(tmpS,"%s()'s third arg. must be a number.\n",FuncStack[Func_idx].s_name); |
|
capa_msg(MESSAGE_ERROR,tmpS); |
|
errCode = 1; |
|
break; |
|
} |
|
if(errCode == 0 ) { |
|
switch( THIRD_ARGTYPE(argp) ) { /* item_cnt */ |
|
case I_VAR: case I_CONSTANT: |
|
item_cnt = THIRD_ARGINT(argp); |
|
break; |
|
case R_VAR: case R_CONSTANT: |
|
item_cnt = (int)THIRD_ARGREAL(argp); |
|
break; |
|
case S_VAR: case S_CONSTANT: |
|
case IDENTIFIER: |
|
resultp->s_type = S_CONSTANT; |
|
resultp->s_str = strsave("<<SECOND ARG. OF THIS FUNCTION MUST BE A NUMBER>>"); |
|
sprintf(tmpS,"%s()'s second arg. must be a number.\n",FuncStack[Func_idx].s_name); |
|
capa_msg(MESSAGE_ERROR,tmpS); |
|
errCode = 1; |
|
break; |
|
} |
|
if(errCode == 0 ) { |
|
switch( FOURTH_ARGTYPE(argp) ) { /* array_name, clear the content of this array first */ |
|
case I_VAR: case I_CONSTANT: |
|
case R_VAR: case R_CONSTANT: |
|
resultp->s_type = S_CONSTANT; |
|
resultp->s_str = strsave("<<FIRST ARG. OF THIS FUNCTION MUST BE AN ARRAY NAME>>"); |
|
sprintf(tmpS,"%s()'s first arg. must be a name of an array.\n",FuncStack[Func_idx].s_name); |
|
capa_msg(MESSAGE_ERROR,tmpS); |
|
errCode = 1; |
|
break; |
|
case S_VAR: case S_CONSTANT: |
|
tmp_int = free_array(FOURTH_ARGSTR(argp)); |
|
r_p = gen_random_by_selector(FOURTH_ARGSTR(argp),sel,tmp_str,item_cnt,para1,para2); |
|
capa_mfree((char *)resultp); |
|
resultp = r_p; |
|
break; |
|
case IDENTIFIER: |
|
tmp_int = free_array(FOURTH_ARGNAME(argp)); |
|
r_p = gen_random_by_selector(FOURTH_ARGSTR(argp),sel,tmp_str,item_cnt,para1,para2); |
|
capa_mfree((char *)resultp); |
|
resultp = r_p; |
|
break; |
|
} |
|
|
|
} /* the third argument of this function (seed) */ |
|
} /* the second argument of this function (paramenter one) */ |
|
} /* the first argument of this function (parameter two) */ |
|
} |
|
break; |
|
} /* end second switch */ |
|
} break; |
|
case ARRAY_MOMENTS_F: /* */ |
{ |
{ |
char *tmp_input; |
char *tmp_input; |
Symbol *r_p; |
Symbol *r_p; |