void parameter_print_on(value_t self, print_on_context_t *context) { CHECK_FAMILY(ofParameter, self); string_buffer_printf(context->buf, "#<parameter: gd@"); // We know the guard is a guard, not a parameter, so this can't cause a cycle. value_print_inner_on(get_parameter_guard(self), context, -1); string_buffer_printf(context->buf, ", op@%i, ix@%i>", get_parameter_is_optional(self), get_parameter_index(self)); }
static void read_parameter_file (param_t *params, FILE *file) /* * Read parameter settings from 'file'. * * No return value. * * Side effects: * 'params [].value' are changed if specified in 'file' */ { char buffer [MAXSTRLEN]; int n = 0; assert (params && file); while (fgets (buffer, MAXSTRLEN, file) != NULL) { char *b; /* temporary variable */ char *name; /* parameter name */ char *value; /* parameter value */ int pind; /* current argument number */ b = strchr (buffer, '#'); if (b != NULL) /* Strip comments. */ *b = '\0'; b = strchr (buffer, '='); if (b == NULL) /* Strip lines that contain no '=' */ continue; *b = '\0'; /* Replace '=' by string terminator */ /* * Extract value of parameter */ for (value = b + 1; ISSPACE (*value); value++) ; /* Delete leading spaces */ for (b = value + strlen (value) - 1; b >= value && ISSPACE (*b); b--) *b = '\0'; /* Delete trailing spaces. */ /* * Extract parameter name */ for (name = buffer; ISSPACE (*name); name++) ; /* Delete leading spaces */ for (b = name + strlen (name) - 1; b >= name && ISSPACE (*b); b--) *b = '\0'; /* Delete trailing spaces. */ pind = get_parameter_index (params, name); if (pind >= 0) set_parameter (¶ms [pind], value); n++; } }
void * parameter_value (const param_t *params, const char *name) /* * Extract value of parameter 'name.' of the given parameters 'params'. * * Return value: * value of given parameter */ { int pind = get_parameter_index (params, name); if (pind < 0) error ("Invalid parameter `%s'.", name); if (params [pind].type == PSTR || params [pind].type == POSTR) return (void *) params [pind].value.s; return (void *) &(params [pind].value); }
void ask_and_set (param_t *params, const char *name, const char *msg) /* * Ask user (print given message 'msg') for missing mandatory * parameter 'name' of the given parameters 'params'. * * No return value. * * Side effects: * 'params ['name'].value' is changed */ { char answer [MAXSTRLEN]; int index = get_parameter_index (params, name); if (index < 0) error ("Invalid parameter %s.", name); if (msg) fprintf (stderr, "%s\n", msg); switch (params [index].type) { case PFLAG: /* Unusual, at least. */ warning ("Flags should be initialized and set on demand, " "not request"); case PINT: case PSTR: case POSTR: case PFLOAT: scanf (MAXSTRLEN_SCANF, answer); set_parameter (¶ms [index], answer); break; default: error ("Invalid parameter type for %s", name); } }
// Internal function to do the actual calculations, make this a wrapped function so // that error bubbling can be done properly double _PropsSI(const std::string &Output, const std::string &Name1, double Prop1, const std::string &Name2, double Prop2, const std::string &backend, const std::string &Ref, const std::vector<double> &z) { parameters iOutput = iundefined_parameter; parameters iOf = iundefined_parameter, iWrt = iundefined_parameter, iConstant = iundefined_parameter, iOf1 = iundefined_parameter, iWrt1 = iundefined_parameter, iConstant1 = iundefined_parameter, iWrt2 = iundefined_parameter, iConstant2 = iundefined_parameter; double x1, x2; if (get_debug_level()>5){ std::cout << format("%s:%d: _PropsSI(%s,%s,%g,%s,%g,%s,%s)\n",__FILE__,__LINE__,Output.c_str(),Name1.c_str(),Prop1,Name2.c_str(),Prop2,backend.c_str(),Ref.c_str(), vec_to_string(z).c_str()).c_str(); } // The state we are going to use shared_ptr<AbstractState> State; // If the fractions of the components have been encoded in the string, extract them // If they have not, this function does nothing std::vector<double> fractions; if (z.empty()) { // Make a one-element vector fractions = std::vector<double>(1, 1); } else{ // Make a copy fractions = z; } std::string fluid_string = extract_fractions(Ref, fractions); // We are going to let the factory function load the state State.reset(AbstractState::factory(backend, fluid_string)); // First check if it is a trivial input (critical/max parameters for instance) if (is_valid_parameter(Output, iOutput) && is_trivial_parameter(iOutput)) { double val = State->trivial_keyed_output(iOutput); return val; } long iName1 = get_parameter_index(Name1); long iName2 = get_parameter_index(Name2); if (State->using_mole_fractions()){ State->set_mole_fractions(fractions); } else if (State->using_mass_fractions()){ State->set_mass_fractions(fractions); } else if (State->using_volu_fractions()){ State->set_volu_fractions(fractions); } else { if (get_debug_level()>50) std::cout << format("%s:%d: _PropsSI, could not set composition to %s, defaulting to mole fraction.\n",__FILE__,__LINE__, vec_to_string(z).c_str()).c_str(); } // Obtain the input pair CoolProp::input_pairs pair = generate_update_pair(iName1, Prop1, iName2, Prop2, x1, x2); // Update the state State->update(pair, x1, x2); if (iOutput != iundefined_parameter){ // Get the desired output double val = State->keyed_output(iOutput); // Return the value return val; } else if (is_valid_first_derivative(Output, iOf, iWrt, iConstant)){ // Return the desired output double val = State->first_partial_deriv(iOf, iWrt, iConstant); // Return the value return val; } else if (is_valid_second_derivative(Output, iOf1, iWrt1, iConstant1, iWrt2, iConstant2)){ // Return the desired output double val = State->second_partial_deriv(iOf1, iWrt1, iConstant1, iWrt2, iConstant2); // Return the value return val; } else{ throw ValueError(format("Output [%s] is not a parameter or a string representation of a derivative",Output.c_str()).c_str()); } }