obj Map(obj vi){ if(type(vi)!=LIST) error("map: needs two arguments."); obj fn = em0(vi); obj v = em1(vi); if(!(type(fn)==tClosure || type(fn)==tInternalFn)) error("map: first arg must be a function"); switch(type(v)){ case LIST: case ARITH:{ list r = nil; for(list l=ul(v); l; l=rest(l)){ r = cons(eval_function(fn, retain(first(l))), r); } return render(type(v), reverse(r)); } case tDblArray: case tIntArr: case tArray: { int len = size(v); obj rr = aArray(len); for(int i=0; i<len; i++){ obj arg = ind(v,i); uar(rr).v[i] = eval_function(fn, arg); // release(arg); } return rr; } default: error("map: second arg must be a list or an array."); return nil; } }
float approx_with_square_function(sample_t* samples, int num_samples) { int loop; double stepsize, best, test_plus, test_minus, fac; loop = 1; stepsize = 1.0; fac = 10.0; best = eval_function(fac, samples, num_samples); while (loop && stepsize > EPSILON) { test_plus = eval_function(fac + stepsize, samples, num_samples); test_minus = eval_function(fac - stepsize, samples, num_samples); if (test_plus < best) { fac += stepsize; best = test_plus; } else if (test_minus < best) { best = test_minus; fac -= stepsize; } else { stepsize /= 2.0; } } return (fac); }
void CMPolynomial::level7(double& result) // functions, (), numbers, { // user functions, parameters if (token == LPar || token == LBracket) { get_token(); level1(result); } else if (token == If) result = eval_condition(); else if (token == Function) result = eval_function(); else if (token==Variable||token==VariableOrig) result = eval_variable(token==Variable); else if (token == Constant) result = constants[offset]; /* else if (token == Definition) { result = CMDefinitions::GetDefinitionValue(offset); sdebug << "Definition " << offset << result << ENDL; } */ else if (isspecialfunc(token)) result = eval_special_function(); get_token(); }
static value_object eval_aux(expr* node) { if (node == NULL) return make_null(); if (node->type == EXP_ASSIGN) return assign_value(node->left, node->right); value_object left = eval_aux(node->left); value_object right = eval_aux(node->right); switch (node->type) { case EXP_PLUS: return add_values(left, right); case EXP_MINUS: return sub_values(left, right); case EXP_TIMES: return mul_values(left, right); case EXP_DIV: return div_values(left, right); case EXP_INT: return make_int(atoi(node->text)); case EXP_FLOAT: return make_float(to_float64(node->text)); case EXP_NATIVE: return make_native(atof(node->text)); case EXP_CALL: return eval_function(node->text, node->args); case EXP_ID: return get_variable_value(node->text); case EXP_UNMINUS: return negate_value(left); } }
local double simple_eval_function(double x) { double ret; eval_function(&ret,save_vect,save_direction,x,save_len,save_pfunction); return(ret); }
static int eval_function(operator_t *op, stack_t **values, char *val_str, size_t size) { if (op == NULL || val_str == NULL || size <= 2) return -1; double val = 0.0; char *arg; char *op_name = (char *) op->name; size_t i, num_args = 0; int is_bad_formula = 0; operator_t *nested_op; stack_t *args = NULL; if (is_arg_arithmetic(op_name)) { num_args = 2; } else { char *arg_count = pop_copy(values); if (arg_count == NULL) goto error; num_args = strtol(arg_count, NULL, 10); free(arg_count); } for (i = 0; i < num_args; i++) { arg = pop_copy(values); //printf("arg[%d]==%s\n", i, arg); if (parsearg(arg) == FUNCTION) { nested_op = get_op(arg); free(arg); if (eval_function(nested_op, values, val_str, size) == 0) push_copy(&args, val_str, size); else goto error; } else if (push(&args, arg) != 0) { goto error; } } val = op->function(&args, &is_bad_formula); if (is_bad_formula) goto error; if (ftoa(val, val_str, size) == NULL) goto error; return 0; error: clear_stack(&args); return -1; }
/* * functions */ double ExpParser::parse_level9() { char fn_name[NAME_LEN_MAX+1]; double ans; if (token_type == FUNCTION) { strcpy(fn_name, token); getToken(); ans = eval_function(fn_name, parse_level10()); } else { ans = parse_level10(); } return ans; }
static int expand_function(AVFilterContext *ctx, AVBPrint *bp, char **rtext) { const char *text = *rtext; char *argv[16] = { NULL }; unsigned argc = 0, i; int ret; if (*text != '{') { av_log(ctx, AV_LOG_ERROR, "Stray %% near '%s'\n", text); return AVERROR(EINVAL); } text++; while (1) { if (!(argv[argc++] = av_get_token(&text, ":}"))) { ret = AVERROR(ENOMEM); goto end; } if (!*text) { av_log(ctx, AV_LOG_ERROR, "Unterminated %%{} near '%s'\n", *rtext); ret = AVERROR(EINVAL); goto end; } if (argc == FF_ARRAY_ELEMS(argv)) av_freep(&argv[--argc]); /* error will be caught later */ if (*text == '}') break; text++; } if ((ret = eval_function(ctx, bp, argv[0], argc - 1, argv + 1)) < 0) goto end; ret = 0; *rtext = (char *)text + 1; end: for (i = 0; i < argc; i++) av_freep(&argv[i]); return ret; }
static double eval_formula(char *formula, int *is_bad_formula, stack_t **cir_ref, int id) { char val_str[TMP_STR_SIZE]; char tmp_id_str[TMP_STR_SIZE]; size_t size = TMP_STR_SIZE; double val = 0.0; double result = 0.0; *is_bad_formula = 0; cell_type_e cell_type; char *arg; if(itoa(id, tmp_id_str, size) == NULL) goto error; push_copy(cir_ref, tmp_id_str, cgc_strlen(tmp_id_str) + 1); queue_t *rpn = infixtorpn(formula, cgc_strlen(formula) + 1); queue_t *args = NULL; stack_t *values = NULL; stack_t *tmp = NULL; operator_t *op = NULL; while (rpn != NULL) { arg = dequeue_copy(&rpn); cell_type = parsearg(arg); switch(cell_type) { case DOUBLE: push(&values, arg); break; case FUNCTION: op = get_op(arg); if (eval_function(op, &values, val_str, size) == -1) { goto error; } push_copy(&values, val_str, size); break; case CELL_ID: tmp = *cir_ref; cell_t *cell = get_cell(arg); if(cell == NULL) goto error; while (tmp != NULL) { if(itoa(cell->id, tmp_id_str, size) == NULL) goto error; if (memcmp(tmp->data, tmp_id_str, cgc_strlen(tmp->data) + 1) == 0) goto error; //Circular reference tmp = tmp->next; } if (cell->cell_type == UNUSED) { push_copy(&values, "0", sizeof("0")); } else if (cell->cell_type == DOUBLE) { push_copy(&values, cell->str, cgc_strlen(cell->str) + 1); } else if(cell->cell_type == FORMULA) { val = eval_formula(cell->formula, is_bad_formula, cir_ref, cell->id); if(*is_bad_formula) goto error; ftoa(val, val_str, size); push_copy(&values, val_str, size); } else { goto error; } break; default: goto error; } } char *result_str = pop_copy(&values); if (values != NULL) goto error; result = atof(result_str, size, is_bad_formula); if (*is_bad_formula) goto error; goto cleanup; error: *is_bad_formula = 1; val = 0.0; clear_queue(&rpn); clear_queue(&args); clear_stack(&values); cleanup: free(pop_copy(cir_ref)); return result; }
local void line_minimize ( int *pcode, bool *pfirst_parabolic_fit_succeeded, double *pval, double *pjump_len, double vect[], double direction[], double last_val, double last_g[], double last_jump_len, int len, double (*pfunction)(double vect[]) ) { double a,x0,y0,b,x1,y1,x2,y2; int code; *pcode = WN_SUCCESS; x1 = 0.0; y1 = last_val; dy1 = wn_dot_vects(direction,last_g,len); if(last_jump_len == 0.0) { last_jump_len = 1.0; } last_jump_len = -wn_sign(dy1)*wn_abs(last_jump_len); x2 = last_jump_len; eval_function(&y2,vect,direction,x2,len,pfunction); wn_fit_parabola_2pd(&code,&a,&x0,&b,x1,y1,dy1,x2,y2); /* look for excuses to say that parabolic fit is no good */ if(code != WN_SUCCESS) { /* printf("parabola fit failed - probably a line.\n"); */ x0 = x2+GOLDEN_RATIO*x2; /* project outward */ eval_function(&y0,vect,direction,x0,len,pfunction); goto parabolic_fit_failed; } if(!(a > 0)) { /* printf("downward facing parabola.\n"); */ x0 = x2+GOLDEN_RATIO*x2; /* project outward */ eval_function(&y0,vect,direction,x0,len,pfunction); goto parabolic_fit_failed; } if(!(wn_abs(x0) < 10000.0*wn_abs(x2))) { /* printf("x0 too far out.\n"); */ x0 = 10000.0*x2; /* project outward */ eval_function(&y0,vect,direction,x0,len,pfunction); goto parabolic_fit_failed; } if(!(wn_abs(x0) > (1.0/10000.0)*wn_abs(x2))) { /* printf("x0 too far in.\n"); */ x0 = (1.0/10000.0)*x2; /* project inward */ eval_function(&y0,vect,direction,x0,len,pfunction); goto parabolic_fit_failed; } if(!(b < y1)) /* no improvement expected,weird form for Nan problems */ { /* printf("no improvement expected.\n"); */ x0 = GOLDEN_SECTION*x2; eval_function(&y0,vect,direction,x0,len,pfunction); goto parabolic_fit_failed; } eval_function(&y0,vect,direction,x0,len,pfunction); if(parabola_fit_improvement_wrong(y1,y0,b,0.25)) { /* printf("poor parabola fit detected.\n"); */ goto parabolic_fit_failed; } /* parabolic fit succeeded */ if(y0 > y1) { x0 = x1; y0 = y1; } *pval = y0; *pjump_len = x0; wn_copy_vect(vect,buffer_vect,len); *pfirst_parabolic_fit_succeeded = TRUE; /* *pfirst_parabolic_fit_succeeded = !parabola_fit_improvement_wrong(y1,y0,b,0.25); */ return; parabolic_fit_failed: *pfirst_parabolic_fit_succeeded = FALSE; save_vect = vect; save_direction = direction; save_len = len; save_pfunction = pfunction; wn_minimize_1d_raw(pcode,&y1,&y0,&y2,&x1,&x0,&x2,y1,(simple_eval_function), 3,20); if(!((*pcode == WN_SUCCESS)||(*pcode == WN_SUBOPTIMAL))) { return; } *pcode = WN_SUCCESS; if(y0 <= last_val) { *pval = y0; *pjump_len = x0; wn_add_scaled_vect(vect,direction,x0,len); } else { *pval = last_val; *pjump_len = 0.0; } return; }
bool eval(string express) { filter_useless_char(express); trim(express); if (check_string("{",express.c_str()) && INVALID_VALUE!=express.find('}')) { // inside code block .. for (unsigned long code_block_end_index=get_matching_outside_right_brace(express.substr(1),0), code_block_start_index=express.find('{'); INVALID_VALUE!=code_block_start_index && INVALID_VALUE!=code_block_end_index; code_block_end_index=get_matching_outside_right_brace(express.substr(1),0), code_block_start_index=express.find('{')) { string code_block(express.substr(code_block_start_index+1,code_block_end_index-code_block_start_index)); while (INVALID_VALUE!=code_block.find(';')) { if (!eval(code_block.substr(0,code_block.find(';')))) return false; code_block=code_block.substr(code_block.find(';')+1); } if (!code_block_start_index) break; express=express.substr(0,code_block_start_index-1)+express.substr(code_block_end_index+1); } return true; } bool base_javascript_syntax_execute_result=true; if (check_string("for",express.c_str())) { // base JavaScript syntax .. base_javascript_syntax_execute_result=eval_for(express); } else if (check_string("if",express.c_str())) { base_javascript_syntax_execute_result=eval_if(express); } if (check_string("function",express.c_str())) { base_javascript_syntax_execute_result=eval_decleare_function(express); if (base_javascript_syntax_execute_result) return eval(express); } else if (check_string("return",express.c_str())) { return eval_function_return(express); } string next_express; if (INVALID_VALUE!=express.find(';')) { // put data .. next_express=express.substr(express.find(';')+1); express=express.substr(0,express.find(';')); } if (eval_function(express)) { } else if (INVALID_VALUE!=express.find('=')) { // var asd=123 or var4='asd' char calcu_flag=express[express.find('=')-1]; if ('+'==calcu_flag) { if (INVALID_VALUE!=express.find("+=")) { // asd+=123 -> asd=asd+123 string variant_name(express.substr(0,express.find("+="))); trim(variant_name); if (!eval(variant_name+"="+variant_name+"+"+express.substr(express.find("+=")+2))) return false; } } else if ('-'==calcu_flag) { if (INVALID_VALUE!=express.find("-=")) { // asd+=123 -> asd=asd+123 string variant_name(express.substr(0,express.find("-="))); trim(variant_name); if (!eval(variant_name+"="+variant_name+"-"+express.substr(express.find("-=")+2))) return false; } } else if ('*'==calcu_flag) { if (INVALID_VALUE!=express.find("*=")) { // asd+=123 -> asd=asd+123 string variant_name(express.substr(0,express.find("*="))); trim(variant_name); if (!eval(variant_name+"="+variant_name+"*"+express.substr(express.find("*=")+2))) return false; } } else if ('/'==calcu_flag) { if (INVALID_VALUE!=express.find("/=")) { // asd+=123 -> asd=asd+123 string variant_name(express.substr(0,express.find("/="))); trim(variant_name); if (!eval(variant_name+"="+variant_name+"/"+express.substr(express.find("/=")+2))) return false; } } else { string variant_name; // asd string calcu_express; if (check_string("var",express.c_str())) { if (INVALID_VALUE!=express.find('=')) { variant_name=express.substr(3,express.find('=')-3); calcu_express=express.substr(express.find('=')+1); } else { variant_name=express.substr(3,express.find(';')-3); } } else { if (INVALID_VALUE!=express.find('=')) { variant_name=express.substr(0,express.find('=')); calcu_express=express.substr(express.find('=')+1); } else { variant_name=express.substr(3,express.find(';')-3); } } trim(variant_name); if (!calcu_express.empty()) if (!express_calcu(calcu_express)) return false; if (EXPRESSION_ARRAY==get_express_type(variant_name)) { unsigned long calcu_result=0; support_javascript_variant_type calcu_result_type=NONE; get_variant(JAVASCRIPT_VARIANT_KEYNAME_CALCULATION_RESULT,(void*)&calcu_result,&calcu_result_type); string array_index_express(variant_name.substr(variant_name.find('[')+1,variant_name.find(']')-variant_name.find('[')-1)); if (!express_calcu(array_index_express)) return false; unsigned long array_index=0; support_javascript_variant_type array_index_type=NONE; get_variant(JAVASCRIPT_VARIANT_KEYNAME_CALCULATION_RESULT,(void*)&array_index,&array_index_type); variant_name=variant_name.substr(0,variant_name.find('[')); trim(variant_name); if (INT_ARRAY==get_variant_type(variant_name) && NUMBER!=calcu_result_type) return false; set_variant_array(variant_name,array_index,(void*)calcu_result,calcu_result_type); } else { copy_variant(variant_name,JAVASCRIPT_VARIANT_KEYNAME_CALCULATION_RESULT); } } } if (!next_express.empty()) return eval(next_express); return base_javascript_syntax_execute_result; }
static bool execute_function_call(string& express) { return eval_function(express); }
obj eval(obj exp){ ev: assert(!! exp); obj rr,lt, rt; switch (exp->type) { case tInd: return doInd(eval(ult(exp)), ul(eval(urt(exp)))); case LIST: return List2v(evalList(ul(exp))); case tArray: return map_obj(eval, exp); case tAnd: return prod_eval(ul(exp), mult); case MULT: return prod_eval(ul(exp), mult); case ARITH: return prod_eval(ul(exp), add); case POW: return prod_eval(ul(exp), power); case DIVIDE: return prod_eval(ul(exp), divide); case tRef: return retain(uref(exp)); case tSymbol: if( macromode) { if(obj rr = search_assoc(car(macro_env), exp)){ macromode = false; // macro lexical scope should be pushed to the stack here rr = exec(rr); macromode = true; return rr; } } return eval_symbol(exp); case tMinus: lt = eval(uref(exp)); rr = uMinus(lt); // releasing if(rr) {release(lt); return rr;} static obj symumn = Symbol("-"); rr = udef_op0(symumn, lt); if(rr) {release(lt); return rr;} error("uMinus: not defined to that type"); case tReturn: if(! uref(exp)) return encap(tSigRet, nil); return encap(tSigRet, eval(uref(exp))); case tBreak: return retain(exp); case CONDITION: return evalCond(exp); case tOp: if(type(ult(exp)) ==tSymbol) { lt = search_assoc(curr_interp->types, ult(exp)); if(lt) return encap((ValueType)vrInt(lt), eval(urt(exp)));} lt = eval(ult(exp)); push(lt); switch(lt->type){ case tCont: assert(0); case tSpecial: rr = ufn(lt)(urt(exp)); break; case tSyntaxLam: rr = macro_exec(lt, urt(exp)); break; case tInternalFn: case tClosure: rt = eval(urt(exp)); rr = eval_function(lt, rt); break; default: rt = eval(urt(exp)); rr = call_fn(mult, lt, rt); release(rt); } release(pop(&is)); return rr; case tClosure: assert(0); case tCurry: return eval_curry(exp, em0(exp)); /* obj vars = Assoc(); bind_vars(&vars, em0(exp), em2(exp)); rr = eval_curry(exp, vars); release(vars); return rr; */ case tArrow: // return enclose(exp); /* if(macromode){ if(obj rr = search_assoc(car(macro_env), exp)){ } } */ return render(tClosure, list3(retain(em0(exp)), retain(em1(exp)), retain(env))); case tDefine: return func_def(em0(exp), em1(exp), em2(exp)); case tSyntaxDef: let(lfind_var(em0(exp)), render(tSyntaxLam, list3(retain(em1(exp)), retain(em2(exp)), nil))); return nil; case tExec: return exec(exp); case tAssign: lt = car(exp); if(type(lt)==tOp){ return func_def(ult(lt), urt(lt), cdr(exp)); } else if(type(lt)==tMinus){ static obj symumn = Symbol("-"); return func_def(symumn, uref(lt), cdr(exp)); } else return do_assign(lt, eval(cdr(exp))); case tIf: rr = eval(em0(exp)); if (type(rr) != INT) error("if: Boolean Expected"); if (vrInt(rr)) { rr = em1(exp); } else { rr = em2(exp); } return eval(rr); case tWhile: for(;;) { rr = eval(car(exp)); if (type(rr) != INT) error("while: Boolean expected"); if(!vrInt(rr)) break; rr = exec(cdr(exp)); if(rr && type(rr)==tSigRet) return rr; if(rr && type(rr)==tBreak) {release(rr); break;} if(rr) release(rr); } return nil; default: return retain(exp); } }
/* * PROCEDURE : fcn * * ENTREES : * m Nombre d'equations. * n Nombre de variables. * xc Valeur courante des parametres. * fvecc Resultat de l'evaluation de la fonction. * ldfjac Plus grande dimension de la matrice jac. * iflag Choix du calcul de la fonction ou du jacobien. * * SORTIE : * jac Jacobien de la fonction. * * DESCRIPTION : * La procedure calcule la fonction et le jacobien. * Si iflag == 1, la procedure calcule la fonction en "xc" et le resultat est * stocke dans "fvecc" et "fjac" reste inchange. * Si iflag == 2, la procedure calcule le jacobien en "xc" et le resultat est * stocke dans "fjac" et "fvecc" reste inchange. * * HISTORIQUE : * 1.00 - xx/xx/xx - Original. * 1.01 - 06/07/95 - Modifications. * 2.00 - 24/10/95 - Tableau jac monodimensionnel. */ void fcn (int m, int n, double *xc, double *fvecc, double *jac, int ldfjac, int iflag) { double u[X3_SIZE];// rd[X3_SIZE][X3_SIZE], vpRotationMatrix rd ; int npt; if (m < n) printf("pas assez de points\n"); npt = m / 2; if (iflag == 1) eval_function (npt, xc, fvecc); else if (iflag == 2) { double u1, u2, u3; u[0] =xc[3]; u[1]= xc[4]; u[2]= xc[5]; rd.buildFrom(u[0],u[1],u[2]) ; /* a partir de l'axe de rotation, calcul de la matrice de rotation. */ // rot_mat(u, rd); double tt = sqrt (u[0] * u[0] + u[1] * u[1] + u[2] * u[2]); /* angle de rot */ if (tt >= MINIMUM) { u1 = u[0] / tt; u2 = u[1] / tt; /* axe de rotation unitaire */ u3 = u[2] / tt; } else u1 = u2 = u3 = 0.0; double co = cos(tt); double mco = 1.0 - co; double si = sin(tt); for (int i = 0; i < npt; i++) { double x = XO[i]; double y = YO[i]; /* coordonnees du point i */ double z = ZO[i]; /* coordonnees du point i dans le repere camera */ double rx = rd[0][0] * x + rd[0][1] * y + rd[0][2] * z + xc[0]; double ry = rd[1][0] * x + rd[1][1] * y + rd[1][2] * z + xc[1]; double rz = rd[2][0] * x + rd[2][1] * y + rd[2][2] * z + xc[2]; /* derive des fonctions rx, ry et rz par rapport * a tt, u1, u2, u3. */ double drxt = (si * u1 * u3 + co * u2) * z + (si * u1 * u2 - co * u3) * y + (si * u1 * u1 - si) * x; double drxu1 = mco * u3 * z + mco * u2 * y + 2 * mco * u1 * x; double drxu2 = si * z + mco * u1 * y; double drxu3 = mco * u1 * z - si * y; double dryt = (si * u2 * u3 - co * u1) * z + (si * u2 * u2 - si) * y + (co * u3 + si * u1 * u2) * x; double dryu1 = mco * u2 * x - si * z; double dryu2 = mco * u3 * z + 2 * mco * u2 * y + mco * u1 * x; double dryu3 = mco * u2 * z + si * x; double drzt = (si * u3 * u3 - si) * z + (si * u2 * u3 + co * u1) * y + (si * u1 * u3 - co * u2) * x; double drzu1 = si * y + mco * u3 * x; double drzu2 = mco * u3 * y - si * x; double drzu3 = 2 * mco * u3 * z + mco * u2 * y + mco * u1 * x; /* derive de la fonction representant le modele de la * camera (sans distortion) par rapport a tt, u1, u2 et u3. */ double dxit = drxt / rz - rx * drzt / (rz * rz); double dyit = dryt / rz - ry * drzt / (rz * rz); double dxiu1 = drxu1 / rz - drzu1 * rx / (rz * rz); double dyiu1 = dryu1 / rz - drzu1 * ry / (rz * rz); double dxiu2 = drxu2 / rz - drzu2 * rx / (rz * rz); double dyiu2 = dryu2 / rz - drzu2 * ry / (rz * rz); double dxiu3 = drxu3 / rz - drzu3 * rx / (rz * rz); double dyiu3 = dryu3 / rz - drzu3 * ry / (rz * rz); /* calcul du jacobien : le jacobien represente la * derivee de la fonction representant le modele de la * camera par rapport aux parametres. */ *MIJ(jac, 0, i, ldfjac) = 1 / rz; *MIJ(jac, 1, i, ldfjac) = 0.0; *MIJ(jac, 2, i, ldfjac) = - rx / (rz * rz); if (tt >= MINIMUM) { *MIJ(jac, 3, i, ldfjac) = u1 * dxit + (1 - u1 * u1) * dxiu1 / tt - u1 * u2 * dxiu2 / tt - u1 * u3 * dxiu3 / tt; *MIJ(jac, 4, i, ldfjac) = u2 * dxit - u1 * u2 * dxiu1 / tt + (1 - u2 * u2) * dxiu2 / tt- u2 * u3 * dxiu3 / tt; *MIJ(jac, 5, i, ldfjac) = u3 * dxit - u1 * u3 * dxiu1 / tt - u2 * u3 * dxiu2 / tt + (1 - u3 * u3) * dxiu3 / tt; } else { *MIJ(jac, 3, i, ldfjac) = 0.0; *MIJ(jac, 4, i, ldfjac) = 0.0; *MIJ(jac, 5, i, ldfjac) = 0.0; } *MIJ(jac, 0, npt + i, ldfjac) = 0.0; *MIJ(jac, 1, npt + i, ldfjac) = 1 / rz; *MIJ(jac, 2, npt + i, ldfjac) = - ry / (rz * rz); if (tt >= MINIMUM) { *MIJ(jac, 3, npt + i, ldfjac) = u1 * dyit + (1 - u1 * u1) * dyiu1 / tt - u1 * u2 * dyiu2 / tt - u1 * u3 * dyiu3 / tt; *MIJ(jac, 4, npt + i, ldfjac) = u2 * dyit - u1 * u2 * dyiu1 / tt + (1 - u2 * u2) * dyiu2 / tt- u2 * u3 * dyiu3 / tt; *MIJ(jac, 5, npt + i, ldfjac) = u3 * dyit - u1 * u3 * dyiu1 / tt - u2 * u3 * dyiu2 / tt + (1 - u3 * u3) * dyiu3 / tt; } else { *MIJ(jac, 3, npt + i, ldfjac) = 0.0; *MIJ(jac, 4, npt + i, ldfjac) = 0.0; *MIJ(jac, 5, npt + i, ldfjac) = 0.0; } } } /* fin else if iflag ==2 */ }
LObject * lipa_eval (LObject *obj) { gboolean found; LObject *tmp; if (!obj) return NULL; switch (obj->type) { case L_OBJ_LIST: tmp = eval_special_form (lipa_car (obj), lipa_cdr (obj), &found); if (found) { return tmp; } else { tmp = eval_function (lipa_car (obj), lipa_cdr (obj), &found); if (found) { return tmp; } else { fputs ("can't be evaluated as a function: ", stdout); lipa_print (obj); fputc ('\n', stdout); } } break; case L_OBJ_FUNCTION: fputs ("This should not be happning?!?!!?!?!\n", stderr); return NULL; break; case L_OBJ_SYMBOLNAME: return (lipa_eval(lipa_symbolname_lookup (L_SYMBOLNAME(obj)->str))); break; case L_OBJ_SYMBOL: return L_SYMBOL(obj).value; break; /* these evaluate to themselves */ case L_OBJ_STRING: case L_OBJ_INT: case L_OBJ_FLOAT: case L_OBJ_CHAR: case L_OBJ_TRUE: case L_OBJ_FALSE: case L_OBJ_USEROBJECT: return obj; break; } return NULL; }
/* Read in BSDF and interpolate as Klems matrix representation */ int main(int argc, char *argv[]) { int dofwd = 0, dobwd = 1; char buf[2048]; char *cp; int i, na; progname = argv[0]; esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; esupport &= ~(E_INCHAN|E_OUTCHAN); scompile("PI:3.14159265358979323846", NULL, 0); biggerlib(); for (i = 1; i < argc && (argv[i][0] == '-') | (argv[i][0] == '+'); i++) switch (argv[i][1]) { /* get options */ case 'n': npsamps = atoi(argv[++i]); if (npsamps <= 0) goto userr; break; case 'e': scompile(argv[++i], NULL, 0); single_plane_incident = 0; break; case 'f': if (!argv[i][2]) { if (strchr(argv[++i], '=') != NULL) { add_wbsdf("-f", 1); add_wbsdf(argv[i], 1); } else { char *fpath = getpath(argv[i], getrlibpath(), 0); if (fpath == NULL) { fprintf(stderr, "%s: cannot find file '%s'\n", argv[0], argv[i]); return(1); } fcompile(fpath); single_plane_incident = 0; } } else dofwd = (argv[i][0] == '+'); break; case 'b': dobwd = (argv[i][0] == '+'); break; case 'h': kbasis = klems_half; add_wbsdf("-a", 1); add_wbsdf("kh", 1); break; case 'q': kbasis = klems_quarter; add_wbsdf("-a", 1); add_wbsdf("kq", 1); break; case 'l': lobe_lim = atoi(argv[++i]); break; case 'p': do_prog = atoi(argv[i]+2); break; case 'C': add_wbsdf(argv[i], 1); add_wbsdf(argv[++i], 1); break; default: goto userr; } if (kbasis == klems_full) { /* default (full) basis? */ add_wbsdf("-a", 1); add_wbsdf("kf", 1); } strcpy(buf, "File produced by: "); if (convert_commandline(buf+18, sizeof(buf)-18, argv) != NULL) { add_wbsdf("-C", 1); add_wbsdf(buf, 0); } if (single_plane_incident >= 0) { /* function-based BSDF? */ if (i != argc-1 || fundefined(argv[i]) < 3) { fprintf(stderr, "%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n", progname); fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n"); goto userr; } ++eclock; if (dofwd) { input_orient = -1; output_orient = -1; prog_start("Evaluating outside reflectance"); eval_function(argv[i]); output_orient = 1; prog_start("Evaluating outside->inside transmission"); eval_function(argv[i]); } if (dobwd) { input_orient = 1; output_orient = 1; prog_start("Evaluating inside reflectance"); eval_function(argv[i]); output_orient = -1; prog_start("Evaluating inside->outside transmission"); eval_function(argv[i]); } return(wrap_up()); } /* XML input? */ if (i == argc-1 && (cp = argv[i]+strlen(argv[i])-4) > argv[i] && !strcasecmp(cp, ".xml")) { eval_bsdf(argv[i]); /* load & resample BSDF */ return(wrap_up()); } if (i < argc) { /* open input files if given */ int nbsdf = 0; for ( ; i < argc; i++) { /* interpolate each component */ char pbuf[256]; FILE *fpin = fopen(argv[i], "rb"); if (fpin == NULL) { fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", progname, argv[i]); return(1); } if (!load_bsdf_rep(fpin)) return(1); fclose(fpin); sprintf(pbuf, "Interpolating component '%s'", argv[i]); prog_start(pbuf); eval_rbf(); } return(wrap_up()); } SET_FILE_BINARY(stdin); /* load from stdin */ if (!load_bsdf_rep(stdin)) return(1); prog_start("Interpolating from standard input"); eval_rbf(); /* resample dist. */ return(wrap_up()); userr: fprintf(stderr, "Usage: %s [-n spp][-h|-q][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n", progname); fprintf(stderr, " or: %s [-n spp][-h|-q] bsdf_in.xml > bsdf_out.xml\n", progname); fprintf(stderr, " or: %s [-n spp][-h|-q][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n", progname); return(1); }
/* Read in BSDF and interpolate as Klems matrix representation */ int main(int argc, char *argv[]) { int dofwd = 0, dobwd = 1; char *cp; int i, na; progname = argv[0]; esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; esupport &= ~(E_INCHAN|E_OUTCHAN); scompile("PI:3.14159265358979323846", NULL, 0); biggerlib(); for (i = 1; i < argc && (argv[i][0] == '-') | (argv[i][0] == '+'); i++) switch (argv[i][1]) { /* get options */ case 'n': npsamps = atoi(argv[++i]); if (npsamps <= 0) goto userr; break; case 'e': scompile(argv[++i], NULL, 0); single_plane_incident = 0; break; case 'f': if (!argv[i][2]) { fcompile(argv[++i]); single_plane_incident = 0; } else dofwd = (argv[i][0] == '+'); break; case 'b': dobwd = (argv[i][0] == '+'); break; case 'h': kbasis = "LBNL/Klems Half"; break; case 'q': kbasis = "LBNL/Klems Quarter"; break; default: goto userr; } if (single_plane_incident >= 0) { /* function-based BSDF? */ if (i != argc-1 || fundefined(argv[i]) != 6) { fprintf(stderr, "%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n", progname); fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n", progname); goto userr; } ++eclock; xml_header(argc, argv); /* start XML output */ xml_prologue(NULL); if (dofwd) { input_orient = -1; output_orient = -1; eval_function(argv[i]); /* outside reflectance */ output_orient = 1; eval_function(argv[i]); /* outside -> inside */ } if (dobwd) { input_orient = 1; output_orient = 1; eval_function(argv[i]); /* inside reflectance */ output_orient = -1; eval_function(argv[i]); /* inside -> outside */ } xml_epilogue(); /* finish XML output & exit */ return(0); } /* XML input? */ if (i == argc-1 && (cp = argv[i]+strlen(argv[i])-4) > argv[i] && !strcasecmp(cp, ".xml")) { xml_header(argc, argv); /* start XML output */ eval_bsdf(argv[i]); /* load & resample BSDF */ xml_epilogue(); /* finish XML output & exit */ return(0); } if (i < argc) { /* open input files if given */ int nbsdf = 0; for ( ; i < argc; i++) { /* interpolate each component */ FILE *fpin = fopen(argv[i], "rb"); if (fpin == NULL) { fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", progname, argv[i]); return(1); } if (!load_bsdf_rep(fpin)) return(1); fclose(fpin); if (!nbsdf++) { /* start XML on first dist. */ xml_header(argc, argv); xml_prologue(NULL); } eval_rbf(); } xml_epilogue(); /* finish XML output & exit */ return(0); } SET_FILE_BINARY(stdin); /* load from stdin */ if (!load_bsdf_rep(stdin)) return(1); xml_header(argc, argv); /* start XML output */ xml_prologue(NULL); eval_rbf(); /* resample dist. */ xml_epilogue(); /* finish XML output & exit */ return(0); userr: fprintf(stderr, "Usage: %s [-n spp][-h|-q][bsdf.sir ..] > bsdf.xml\n", progname); fprintf(stderr, " or: %s [-n spp][-h|-q] bsdf_in.xml > bsdf_out.xml\n", progname); fprintf(stderr, " or: %s [-n spp][-h|-q][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n", progname); return(1); }