Example #1
0
/**
 * \fn double xml_node_get_float_with_default (xmlNode *node, \
 *   const xmlChar *prop, double default_value, int *error_code)
 * \brief Function to get a floating point number of a XML node property with a
 *   default value.
 * \param node
 * \brief XML node.
 * \param prop
 * \brief XML property.
 * \param default_value
 * \brief default value.
 * \param error_code
 * \brief Error code.
 * \return Floating point number value.
 */
double
xml_node_get_float_with_default (xmlNode * node, const xmlChar * prop,
                                 double default_value, int *error_code)
{
  double x;
  if (xmlHasProp (node, prop))
    x = xml_node_get_float (node, prop, error_code);
  else
    {
      x = default_value;
      *error_code = 0;
    }
  return x;
}
Example #2
0
/**
 * \fn int drop_open_xml (Drop * d, Air * a, xmlNode *node)
 * \brief function to input a Drop struct on a XML node.
 * \param d
 * \brief Drop struct.
 * \param a
 * \brief Air struct.
 * \param node
 * \brief XML node.
 * \return 1 on success, 0 on error.
 */
int
drop_open_xml (Drop * d, Air * a, xmlNode * node)
{
  xmlChar *buffer;
  double sh, ch, sv, cv;
  int k;
#if DEBUG_DROP
  fprintf (stderr, "drop_open_xml: start\n");
#endif
  buffer = NULL;
  if (xmlStrcmp (node->name, XML_DROP))
    {
      drop_error (gettext ("bad label"));
      goto exit_on_error;
    }
  drop_diameter = xml_node_get_float (node, XML_DIAMETER, &k);
  if (!k)
    {
      drop_error (gettext ("bad diameter"));
      goto exit_on_error;
    }
  d->r[0] = xml_node_get_float_with_default (node, XML_X, 0., &k);
  if (!k)
    {
      drop_error (gettext ("bad x"));
      goto exit_on_error;
    }
  d->r[1] = xml_node_get_float_with_default (node, XML_Y, 0., &k);
  if (!k)
    {
      drop_error (gettext ("bad y"));
      goto exit_on_error;
    }
  d->r[2] = xml_node_get_float_with_default (node, XML_Z, 0., &k);
  if (!k)
    {
      drop_error (gettext ("bad z"));
      goto exit_on_error;
    }
  drop_velocity = xml_node_get_float_with_default (node, XML_VELOCITY, 0., &k);
  if (!k)
    {
      drop_error (gettext ("bad velocity"));
      goto exit_on_error;
    }
  drop_horizontal_angle
    = xml_node_get_float_with_default (node, XML_HORIZONTAL_ANGLE, 0., &k);
  if (!k)
    {
      drop_error (gettext ("bad horizontal angle"));
      goto exit_on_error;
    }
  drop_vertical_angle
    = xml_node_get_float_with_default (node, XML_VERTICAL_ANGLE, 0., &k);
  if (!k)
    {
      drop_error (gettext ("bad vertical angle"));
      goto exit_on_error;
    }
  buffer = xmlGetProp (node, XML_DRAG_MODEL);
  if (!buffer)
    {
      drop_error (gettext ("no drag model"));
      goto exit_on_error;
    }
  if (!xmlStrcmp (buffer, XML_CONSTANT))
    {
      drop_drag_model = DROP_DRAG_MODEL_CONSTANT;
      drop_drag_coefficient
        = xml_node_get_float_with_default (node, XML_DRAG, 0., &k);
      if (!k)
        {
          drop_error (gettext ("bad drag value"));
          goto exit_on_error;
        }
    }
  else if (!xmlStrcmp (buffer, XML_SPHERE))
    drop_drag_model = DROP_DRAG_MODEL_SPHERE;
  else if (!xmlStrcmp (buffer, XML_OVOID))
    drop_drag_model = DROP_DRAG_MODEL_OVOID;
  else
    {
      drop_error (gettext ("unknown drag resistance model"));
      goto exit_on_error;
    }
  xmlFree (buffer);
  buffer = xmlGetProp (node, XML_DETACH_MODEL);
  if (!buffer || !xmlStrcmp (buffer, XML_TOTAL))
    drop_detach_model = DROP_DETACH_MODEL_TOTAL;
  else if (!xmlStrcmp (buffer, XML_RANDOM))
    drop_detach_model = DROP_DETACH_MODEL_RANDOM;
  else
    {
      drop_error (gettext ("unknown jet detach model"));
      goto exit_on_error;
    }
  sincos (M_PI / 180. * drop_horizontal_angle, &sh, &ch);
  sincos (M_PI / 180. * drop_vertical_angle, &sv, &cv);
  d->v[0] = drop_velocity * cv * ch;
  d->v[1] = drop_velocity * cv * sh;
  d->v[2] = drop_velocity * sv;
#if DEBUG_DROP
  fprintf (stderr, "drop_open_xml: end\n");
#endif
  return 1;

exit_on_error:
  xmlFree (buffer);
#if DEBUG_DROP
  fprintf (stderr, "drop_open_xml: end\n");
#endif
  return 0;
}
Example #3
0
/**
 * \fn int variable_open_xml (Variable * variable, xmlNode * node, \
 *   unsigned int algorithm, unsigned int nsteps)
 * \brief Function to open the variable file.
 * \param variable
 * \brief Variable struct.
 * \param node
 * \brief XML node.
 * \param algorithm
 * \brief Algorithm type.
 * \param nsteps
 * \brief Number of steps to do the direction search method.
 * \return 1 on success, 0 on error.
 */
int
variable_open_xml (Variable * variable, xmlNode * node, unsigned int algorithm,
                   unsigned int nsteps)
{
  int error_code;

#if DEBUG_VARIABLE
  fprintf (stderr, "variable_open_xml: start\n");
#endif

  variable->name = (char *) xmlGetProp (node, (const xmlChar *) LABEL_NAME);
  if (!variable->name)
    {
      variable_error (variable, gettext ("no name"));
      goto exit_on_error;
    }
  if (xmlHasProp (node, (const xmlChar *) LABEL_MINIMUM))
    {
      variable->rangemin
        = xml_node_get_float (node, (const xmlChar *) LABEL_MINIMUM,
                              &error_code);
      if (error_code)
        {
          variable_error (variable, gettext ("bad minimum"));
          goto exit_on_error;
        }
      variable->rangeminabs = xml_node_get_float_with_default
        (node, (const xmlChar *) LABEL_ABSOLUTE_MINIMUM, -G_MAXDOUBLE,
         &error_code);
      if (error_code)
        {
          variable_error (variable, gettext ("bad absolute minimum"));
          goto exit_on_error;
        }
      if (variable->rangemin < variable->rangeminabs)
        {
          variable_error (variable, gettext ("minimum range not allowed"));
          goto exit_on_error;
        }
    }
  else
    {
      variable_error (variable, gettext ("no minimum range"));
      goto exit_on_error;
    }
  if (xmlHasProp (node, (const xmlChar *) LABEL_MAXIMUM))
    {
      variable->rangemax
        = xml_node_get_float (node, (const xmlChar *) LABEL_MAXIMUM,
                              &error_code);
      if (error_code)
        {
          variable_error (variable, gettext ("bad maximum"));
          goto exit_on_error;
        }
      variable->rangemaxabs = xml_node_get_float_with_default
        (node, (const xmlChar *) LABEL_ABSOLUTE_MAXIMUM, G_MAXDOUBLE,
         &error_code);
      if (error_code)
        {
          variable_error (variable, gettext ("bad absolute maximum"));
          goto exit_on_error;
        }
      if (variable->rangemax > variable->rangemaxabs)
        {
          variable_error (variable, gettext ("maximum range not allowed"));
          goto exit_on_error;
        }
      if (variable->rangemax < variable->rangemin)
        {
          variable_error (variable, gettext ("bad range"));
          goto exit_on_error;
        }
    }
  else
    {
      variable_error (variable, gettext ("no maximum range"));
      goto exit_on_error;
    }
  variable->precision
    = xml_node_get_uint_with_default (node, (const xmlChar *) LABEL_PRECISION,
                                      DEFAULT_PRECISION, &error_code);
  if (error_code || variable->precision >= NPRECISIONS)
    {
      variable_error (variable, gettext ("bad precision"));
      goto exit_on_error;
    }
  if (algorithm == ALGORITHM_SWEEP)
    {
      if (xmlHasProp (node, (const xmlChar *) LABEL_NSWEEPS))
        {
          variable->nsweeps
            = xml_node_get_uint (node, (const xmlChar *) LABEL_NSWEEPS,
                                 &error_code);
          if (error_code || !variable->nsweeps)
            {
              variable_error (variable, gettext ("bad sweeps"));
              goto exit_on_error;
            }
        }
      else
        {
          variable_error (variable, gettext ("no sweeps number"));
          goto exit_on_error;
        }
#if DEBUG_VARIABLE
      fprintf (stderr, "variable_open_xml: nsweeps=%u\n", variable->nsweeps);
#endif
    }
  if (algorithm == ALGORITHM_GENETIC)
    {
      // Obtaining bits representing each variable
      if (xmlHasProp (node, (const xmlChar *) LABEL_NBITS))
        {
          variable->nbits
            = xml_node_get_uint (node, (const xmlChar *) LABEL_NBITS,
                                 &error_code);
          if (error_code || !variable->nbits)
            {
              variable_error (variable, gettext ("invalid bits number"));
              goto exit_on_error;
            }
        }
      else
        {
          variable_error (variable, gettext ("no bits number"));
          goto exit_on_error;
        }
    }
  else if (nsteps)
    {
      variable->step
        = xml_node_get_float (node, (const xmlChar *) LABEL_STEP, &error_code);
      if (error_code || variable->step < 0.)
        {
          variable_error (variable, gettext ("bad step size"));
          goto exit_on_error;
        }
    }

#if DEBUG_VARIABLE
  fprintf (stderr, "variable_open_xml: end\n");
#endif
  return 1;
exit_on_error:
  variable_free (variable, INPUT_TYPE_XML);
#if DEBUG_VARIABLE
  fprintf (stderr, "variable_open_xml: end\n");
#endif
  return 0;
}