int vary_parameter( struct file_content *pfc, struct precision * ppr, struct background * pba, struct thermo * pth, struct perturbs * ppt, struct bessels * pbs, struct transfers * ptr, struct primordial * ppm, struct spectra * psp, struct nonlinear * pnl, struct lensing * ple, struct output * pop, double z, double * psCl1, double * psCl0, int lmin, int lmax, int ipara, double * idCldPara, ErrorMsg errmsg) { int l; int flag1; /* used in read_double, so must be double */ double param1, param2; /* proportional change of each parameter; so the fiducial parameter value should not be 0 */ double delta = 0.1; parser_read_double(pfc,pfc->name[ipara],¶m1,&flag1,errmsg); param2 = param1 * (1.+delta); sprintf(pfc->value[ipara],"%e", param2); printf("<=================================>"); printf("%s: %e --> %e; z: %f\n", pfc->name[ipara], param1, param2, z); /* calls class again for *renewed* fc and return the P(k)'s*/ class_assuming_bessels_computed(pfc,ppr,pba,pth,ppt,pbs,ptr,ppm,psp,pnl,ple,pop,z,psCl1,lmin,lmax,errmsg); for(l=lmin; l<=lmax; l++) idCldPara[l] = (psCl1[l]-psCl0[l])/(param1*delta); /* reset fc to fiducial values */ if (set_fiducial(pfc,errmsg) == _FAILURE_) { printf("\n\nError set fiducial parameters \n=>%s\n",errmsg); return _FAILURE_; } }
double parser_read_builtin( parser_data *pd ){ double v0, v1; char c, token[PARSER_MAX_TOKEN_SIZE]; int pos=0; c = parser_peek( pd ); if( isalpha(c) || c == '_' ){ while( isalpha(c) || isdigit(c) || c == '-' ){ token[pos++] = parser_eat( pd ); c = parser_peek( pd ); } token[pos] = '\0'; // eat opening bracket if( parser_eat(pd) != '(' ) parser_error( pd, "Expected '(' in builtin call!" ); // start handling the specific builtin functions if( strcmp( token, "pow" ) == 0 ){ v0 = parser_read_argument( pd ); v1 = parser_read_argument( pd ); v0 = pow( v0, v1 ); } else if( strcmp( token, "sqrt" ) == 0 ){ v0 = parser_read_argument( pd ); if( v0 < 0.0 ) parser_error( pd, "sqrt(x) undefined for x < 0!" ); v0 = sqrt( v0 ); } else if( strcmp( token, "log" ) == 0 ){ v0 = parser_read_argument( pd ); if( v0 <= 0 ) parser_error( pd, "log(x) undefined for x <= 0!" ); v0 = log( v0 ); } else if( strcmp( token, "exp" ) == 0 ){ v0 = parser_read_argument( pd ); v0 = exp( v0 ); } else if( strcmp( token, "sin" ) == 0 ){ v0 = parser_read_argument( pd ); v0 = sin( v0 ); } else if( strcmp( token, "asin" ) == 0 ){ v0 = parser_read_argument( pd ); if( fabs(v0) > 1.0 ) parser_error( pd, "asin(x) undefined for |x| > 1!" ); v0 = asin( v0 ); } else if( strcmp( token, "cos" ) == 0 ){ v0 = parser_read_argument( pd ); if( fabs(v0 ) > 1.0 ) parser_error( pd, "acos(x) undefined for |x| > 1!" ); v0 = cos( v0 ); } else if( strcmp( token, "acos" ) == 0 ){ v0 = parser_read_argument( pd ); v0 = acos( v0 ); } else if( strcmp( token, "tan" ) == 0 ){ v0 = parser_read_argument( pd ); v0 = tan( v0 ); } else if( strcmp( token, "atan" ) == 0 ){ v0 = parser_read_argument( pd ); v0 = atan( v0 ); } else if( strcmp( token, "atan2" ) == 0 ){ v0 = parser_read_argument( pd ); v1 = parser_read_argument( pd ); v0 = atan2( v0, v1 ); } else if( strcmp( token, "abs" ) == 0 ){ v0 = parser_read_argument( pd ); v0 = abs( v0 ); } else if( strcmp( token, "fabs" ) == 0 ){ v0 = parser_read_argument( pd ); v0 = fabs( v0 ); } else if( strcmp( token, "floor" ) == 0 ){ v0 = parser_read_argument( pd ); v0 = floor( v0 ); } else if( strcmp( token, "ceil" ) == 0 ){ v0 = parser_read_argument( pd ); v0 = floor( v0 ); } else if( strcmp( token, "round" ) == 0 ){ v0 = parser_read_argument( pd ); v0 = round( v0 ); } else { parser_error( pd, "Tried to call unknown builtin function!" ); } // eat closing bracket of function call if( parser_eat( pd ) != ')' ) parser_error( pd, "Expected ')' in builtin call!" ); } else { // not a builtin function call, just read a literal double v0 = parser_read_double( pd ); } // consume whitespace parser_eat_whitespace( pd ); // return the value return v0; }