Esempio n. 1
0
File: cs_supp.c Progetto: nasa/QuIP
static void cstepit_scr_funk(void)
{
	char str[128];
	float	err;
	Variable *vp;
	int i;
	List *lp;
	Node *np;
	double ans[MAX_OPT_PARAMS];
#ifdef THREAD_SAFE_QUERY
	Query_Stack *qsp;

	assert(cs_qsp != NULL );
	qsp = cs_qsp;
#endif // THREAD_SAFE_QUERY


	/* ooh, icky:  getvals fetches global vars from cstepit module... */

	getvals(ans,n_prms);

	if( opt_func_string==NULL ){
		warn("No optimization string defined");
		return;
	}

	lp=_opt_param_list(SGL_DEFAULT_QSP_ARG);
	if( lp == NULL ){
		warn("No optimization parameters to vary!?");
		err=0.0;
		setfobj((double)err);
		return;
	}
	np=QLIST_HEAD(lp);

	/* stepit has passed us params in the ans array -
	 * we want to get them into named variables...
	 */
	i=0;
	while(np!=NULL && i < n_prms ){
		Opt_Param *opp;

		opp = (Opt_Param *)( np->n_data);
		sprintf(str,"%g",ans[i]);	/* why add 1?  fortan? */
		_assign_var(DEFAULT_QSP_ARG  opp->op_name,str);
		i++;
		np=np->n_next;
	}

	/* We used to call pushtext here, but we like digest
	 * because it automatically pushes and pops the top menu.
	 *
	 * chew_text doesn't work, however, because it doesn't block
	 * the interpreter, which returns to the terminal...
	 *
	 * We have a problem - calling optimization from another callback
	 * function causes it to exit when done!?
	 * It turns out that that was because older scripts (written
	 * for the old version that didn't push the top menu automatically)
	 * didn't have a quit after the call to optimize - ???
	 */

	digest(opt_func_string, OPTIMIZER_FILENAME);
	
	vp=var__of("error");
	if( vp == NULL ) {
		warn(ERROR_STRING);
		sprintf(ERROR_STRING,
	"variable \"error\" not set by script fragment \"%s\"!?",
			opt_func_string);
		err=0.0;
	} else sscanf(VAR_VALUE(vp),"%g",&err);

	setfobj((double)err);
}
Esempio n. 2
0
int default_stim(QSP_ARG_DECL  Trial_Class *tc_p,int val,Staircase *stc_p)
{
	char stim_str[256], *s;
	int coin=0;	// initialize to quiet compiler, but not necessary!?
	int rsp;
	//struct var *vp;
	Variable *vp;
	float *xv_p;

	if( is_fc ){
		coin=(int)rn(1);
		sprintf(stim_str,"%d",coin);
		assign_var("coin",stim_str);
	}

	assert( CLASS_XVAL_OBJ(tc_p) != NULL );
	xv_p = indexed_data( CLASS_XVAL_OBJ(tc_p), val );
	sprintf(stim_str,"%f",*xv_p);

	/* clip trailing zeros if there is a decimal point */
	s=stim_str;
	while( *s ){
		if( *s == '.' ){
			s=stim_str+strlen(stim_str)-1;
			while( *s == '0' ) {
				*s=0;
				s--;
			}
			/*
			 * if ONLY 0's after the decimal pt.,
			 * remove the pt too!
			 */
			if( *s == '.' ){
				*s=0;
				s--;
			}
		}
		s++;
	}

	assign_var("xval",stim_str);
	sprintf(stim_str,"%d",val);
	assign_var("val",stim_str);
	sprintf(stim_str,"%d",CLASS_INDEX(tc_p));
	assign_var("class",stim_str);

	assert( tc_p != NULL );

	//sprintf(msg_str,"Text \"%s\"",(char *)(tc_p->cl_data));
	//PUSH_INPUT_FILE(msg_str);

	//interpret_text_fragment(QSP_ARG tc_p->cl_data);		/* use chew_text??? */
	chew_text(CLASS_CMD(tc_p), "(stimulus text)");
	vp=var_of("response_string");
	if( vp != NULL )
		rsp = collect_response(VAR_VALUE(vp));
	else {
		static int warned=0;

		if( !warned ){
			warn("default_stim:  script variable $response_string not defined");
			warned=1;
		}
		rsp = collect_response("Enter response: ");
	}

	if( is_fc ){
		/* stimulus routine may have changed value of coin */
		vp=var_of("coin");
		if( vp == NULL )
			warn("variable \"coin\" not set!!!");
		else {
			if( sscanf(VAR_VALUE(vp),"%d",&coin) != 1 )
			warn("error scanning integer from variable \"coin\"\n");
		}

		/*
		if( coin ){
			if( rsp == YES ) rsp = NO;
			else if( rsp == NO ) rsp = YES;
		}
		*/
		assert( stc_p != NULL );
        
        // analyzer complains coin is a garbage value??? BUG?
		if( coin ){
			SET_STAIR_CRCT_RSP(stc_p,NO);
		} else {
			SET_STAIR_CRCT_RSP(stc_p,YES);
		}
		if( verbose ){
			if( rsp == STAIR_CRCT_RSP(stc_p) )
				advise("correct");
			else
				advise("incorrect");
		}
	}
	return(rsp);
}