Beispiel #1
0
/**
 * \fn int trajectory_open_xml (Trajectory *t, Air *a, xmlNode *node, \
 *   char *name)
 * \brief function to open a Trajectory struct on a XML node.
 * \param t
 * \brief Trajectory struct.
 * \param a
 * \brief Air struct.
 * \param node
 * \brief XML node.
 * \param name
 * \brief results base file name.
 * \return 1 on success, 0 on error.
 */
int
trajectory_open_xml (Trajectory * t, Air * a, xmlNode * node, char *name)
{
  char buffer2[512];
  xmlChar *buffer;
  int k;
#if DEBUG_TRAJECTORY
  fprintf (stderr, "trajectory_open_xml: start\n");
#endif
  if (xmlStrcmp (node->name, XML_TRAJECTORY))
    {
      trajectory_error (gettext ("bad label"));
      goto exit_on_error;
    }
  t->bed_level = xml_node_get_float_with_default (node, XML_BED_LEVEL, 0., &k);
  if (!k)
    {
      trajectory_error (gettext ("bad bed level"));
      goto exit_on_error;
    }
  t->dt = xml_node_get_float_with_default (node, XML_DT, DT, &k);
  if (!k)
    {
      trajectory_error (gettext ("bad time step size"));
      goto exit_on_error;
    }
  t->cfl = xml_node_get_float_with_default (node, XML_CFL, CFL, &k);
  if (!k)
    {
      trajectory_error (gettext ("bad CFL number"));
      goto exit_on_error;
    }
  t->jet_time = xml_node_get_float_with_default (node, XML_JET_TIME, 0., &k);
  if (!k)
    {
      trajectory_error (gettext ("bad jet time"));
      goto exit_on_error;
    }
  if (!xmlHasProp (node, XML_JET_MODEL))
    t->jet_model = 0;
  else
    {
      buffer = xmlGetProp (node, XML_JET_MODEL);
      if (!xmlStrcmp (buffer, XML_NULL_DRAG))
        t->jet_model = TRAJECTORY_JET_MODEL_NULL_DRAG;
      else if (!xmlStrcmp (buffer, XML_PROGRESSIVE))
        t->jet_model = TRAJECTORY_JET_MODEL_PROGRESSIVE;
      else if (!xmlStrcmp (buffer, XML_BIG_DROPS))
        {
          t->jet_model = TRAJECTORY_JET_MODEL_BIG_DROPS;
          t->drop_maximum_diameter
            = xml_node_get_float_with_default (node, XML_MAXIMUM_DROP_DIAMETER,
                                               MAXIMUM_DROP_DIAMETER, &k);
          if (!k)
            {
              trajectory_error (gettext ("bad maximum drop diameter"));
              goto exit_on_error;
            }
        }
      else
        {
          trajectory_error (gettext ("unknown jet model"));
          xmlFree (buffer);
          goto exit_on_error;
        }
      xmlFree (buffer);
    }
  buffer = xmlGetProp (node, XML_FILE);
  if (!buffer)
    {
      trajectory_error (gettext ("bad results file"));
      goto exit_on_error;
    }
  snprintf (buffer2, 512, "%s-%s", name, (char *) buffer);
  xmlFree (buffer);
  t->file = fopen (buffer2, "w");
  if (!t->file)
    {
      trajectory_error (gettext ("unable to open the results file"));
      goto exit_on_error;
    }
  t->filename = g_strdup (buffer2);
  if (!node->children)
    {
      trajectory_error (gettext ("no drop"));
      goto exit_on_error;
    }
  if (!drop_open_xml (t->drop, a, node->children))
    goto exit_on_error;
#if DEBUG_TRAJECTORY
  fprintf (stderr, "trajectory_open_xml: end\n");
#endif
  return 1;

exit_on_error:
#if DEBUG_TRAJECTORY
  fprintf (stderr, "trajectory_open_xml: end\n");
#endif
  return 0;
}
Beispiel #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;
}
Beispiel #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;
}