Пример #1
0
novatel_gps_msgs::InscovPtr
novatel_gps_driver::InscovParser::ParseBinary(const BinaryMessage& bin_msg) throw(ParseException)
{
  if (bin_msg.data_.size() != BINARY_LENGTH)
  {
    std::stringstream error;
    error << "Unexpected inscov message size: " << bin_msg.data_.size();
    throw ParseException(error.str());
  }
  novatel_gps_msgs::InscovPtr ros_msg = boost::make_shared<novatel_gps_msgs::Inscov>();
  HeaderParser h_parser;
  ros_msg->novatel_msg_header = h_parser.ParseBinary(bin_msg);
  ros_msg->novatel_msg_header.message_name = GetMessageName();

  ros_msg->week = ParseUInt32(&bin_msg.data_[0]);
  ros_msg->seconds = ParseDouble(&bin_msg.data_[4]);
  int offset = 12;
  for (int i = 0; i < 9; i++, offset += 8)
  {
    ros_msg->position_covariance[i] = ParseDouble(&bin_msg.data_[offset]);
  }
  for (int i = 0; i < 9; i++, offset += 8)
  {
    ros_msg->attitude_covariance[i] = ParseDouble(&bin_msg.data_[offset]);
  }
  for (int i = 0; i < 9; i++, offset += 8)
  {
    ros_msg->velocity_covariance[i] = ParseDouble(&bin_msg.data_[offset]);
  }
  return ros_msg;
}
Пример #2
0
void Beatmap::readDifficulty()
{
    if(Error != 0)
        return;

    int FoundCount = 0;

    for(auto &i : BeatmapFile)
    {
        if(i.find("CircleSize") != std::string::npos)
        {
            MapCircleSize = ParseDouble(i);
            FoundCount++;
        }
        else if (i.find("OverallDifficulty") != std::string::npos)
        {
            MapOverallDifficulty = ParseDouble(i);
            FoundCount++;
        }
        else if (i.find("ApproachRate") != std::string::npos)
        {
            MapApproachRate = ParseDouble(i);
            FoundCount++;
        }
        else if (i.find("SliderMultiplier") != std::string::npos)
        {
            MapSliderMultiplier = ParseDouble(i);
            FoundCount++;
        }
        if(FoundCount >= 4)
            return;
    }
}
Пример #3
0
void Parser::ParseTripleDouble(double * x, double * y, double * z)
{
	*x = ParseDouble();
	++index;
	*y = ParseDouble();
	++index;
	*z = ParseDouble();
}
Пример #4
0
bool
ParsePolar(PolarInfo &polar_r, const char *s)
{
  PolarInfo polar;
  // Example:
  // *LS-3  WinPilot POLAR file: MassDryGross[kg], MaxWaterBallast[liters], Speed1[km/h], Sink1[m/s], Speed2, Sink2, Speed3, Sink3
  // 403, 101, 115.03, -0.86, 174.04, -1.76, 212.72,  -3.4

  if (s[0] == _T('*'))
    /* a comment */
    return false;

  char *p;
  polar.reference_mass = fixed(ParseDouble(s, &p));
  if (*p != _T(','))
    return false;

  polar.max_ballast = fixed(ParseDouble(p + 1, &p));
  if (*p != _T(','))
    return false;

  polar.shape[0].v = Units::ToSysUnit(fixed(ParseDouble(p + 1, &p)), Unit::KILOMETER_PER_HOUR);
  if (*p != _T(','))
    return false;

  polar.shape[0].w = fixed(ParseDouble(p + 1, &p));
  if (*p != _T(','))
    return false;

  polar.shape[1].v = Units::ToSysUnit(fixed(ParseDouble(p + 1, &p)), Unit::KILOMETER_PER_HOUR);
  if (*p != _T(','))
    return false;

  polar.shape[1].w = fixed(ParseDouble(p + 1, &p));
  if (*p != _T(','))
    return false;

  polar.shape[2].v = Units::ToSysUnit(fixed(ParseDouble(p + 1, &p)), Unit::KILOMETER_PER_HOUR);
  if (*p != _T(','))
    return false;

  polar.shape[2].w = fixed(ParseDouble(p + 1, &p));
  polar.wing_area = (*p != _T(',')) ? fixed(0) : fixed(ParseDouble(p + 1, &p));
  polar.v_no = (*p != _T(',')) ? fixed(0) : fixed(ParseDouble(p + 1, &p));

  polar_r = polar;
  return true;
}
Пример #5
0
F32 StringToF32( const char* s, F32 minValue, F32 maxValue )
{
	F32 v = ParseDouble(s);
	Assert(v >= minValue);
	Assert(v <= maxValue);
	return v;
}
Пример #6
0
/** @brief Strictly read a num value */
int CliGetNum(num *Value, const char *String, const char *Param)
{
    double DoubleValue;
    int i;

    if(!Value)
    {
        fprintf(stderr, "Null pointer.\n");
        return 0;
    }
    else if(!String)
    {
        fprintf(stderr, "Expected a number for %s.\n", Param);
        return 0;
    }

    i = ParseDouble(&DoubleValue, String);

    if(!i || String[i])   /* No number read, or ends with non-null character */
    {
        *Value = 0;
        fprintf(stderr, "Invalid syntax \"%s\".\n", String);
        return 0;
    }
    else
    {
        *Value = (num)DoubleValue;
        return 1;
    }
}
Пример #7
0
void
ServerTimingParser::Parse()
{
  // https://w3c.github.io/server-timing/#the-server-timing-header-field
  // Server-Timing             = #server-timing-metric
  // server-timing-metric      = metric-name *( OWS ";" OWS server-timing-param )
  // metric-name               = token
  // server-timing-param       = server-timing-param-name OWS "=" OWS server-timing-param-value
  // server-timing-param-name  = token
  // server-timing-param-value = token / quoted-string

  ParsedHeaderValueListList parsedHeader(mValue, false);
  for (uint32_t index = 0; index < parsedHeader.mValues.Length(); ++index) {
    if (parsedHeader.mValues[index].mValues.IsEmpty()) {
      continue;
    }

    // According to spec, the first ParsedHeaderPair's name is metric-name.
    RefPtr<nsServerTiming> timingHeader = new nsServerTiming();
    mServerTimingHeaders.AppendElement(timingHeader);
    timingHeader->SetName(parsedHeader.mValues[index].mValues[0].mName);

    if (parsedHeader.mValues[index].mValues.Length() == 1) {
      continue;
    }

    // Try to find duration and description from the rest ParsedHeaderPairs.
    bool foundDuration = false;
    bool foundDescription = false;
    for (uint32_t pairIndex = 1;
         pairIndex < parsedHeader.mValues[index].mValues.Length();
         ++pairIndex) {
      nsDependentCSubstring &currentName =
        parsedHeader.mValues[index].mValues[pairIndex].mName;
      nsDependentCSubstring &currentValue =
        parsedHeader.mValues[index].mValues[pairIndex].mValue;

      // We should only take the value from the first
      // occurrence of server-timing-param-name ("dur" and "desc").
      if (currentName.LowerCaseEqualsASCII("dur") &&
          currentValue.BeginReading() &&
          !foundDuration) {
        timingHeader->SetDuration(ParseDouble(currentValue));
        foundDuration = true;
      } else if (currentName.LowerCaseEqualsASCII("desc") &&
                 !currentValue.IsEmpty() &&
                 !foundDescription) {
        timingHeader->SetDescription(currentValue);
        foundDescription = true;
      }

      if (foundDuration && foundDescription) {
        break;
      }
    }
  }
}
Пример #8
0
double UniValue::get_real() const
{
    if (typ != VNUM)
        throw std::runtime_error("JSON value is not a number as expected");
    double retval;
    if (!ParseDouble(getValStr(), &retval))
        throw std::runtime_error("JSON double out of range");
    return retval;
}
Пример #9
0
bool
ConstDataNode::GetAttribute(const TCHAR *name, fixed &value) const
{
  const TCHAR *val = GetAttribute(name);
  if (val == nullptr)
    return false;

  value = (fixed)ParseDouble(val);
  return true;
}
Пример #10
0
static bool
ReadFixed(const char *string, fixed &out)
{
  char *endptr;
  double tmp = ParseDouble(string, &endptr);
  if (endptr == string)
    return false;

  out = fixed(tmp);
  return true;
}
Пример #11
0
    double ExpectNextDouble() {
        const char *p = ExpectNext();
        assert(p != NULL);

        char *endptr;
        double result = ParseDouble(p, &endptr);
        if (p == endptr)
            UsageError();

        return result;
    }
Пример #12
0
static void
ParseArcBearings(const TCHAR *buffer, TempAirspaceType &temp_area)
{
  // Determine radius and start/end bearing
  TCHAR *endptr;
  temp_area.radius = Units::ToSysUnit(fixed(ParseDouble(&buffer[2], &endptr)),
                                      Unit::NAUTICAL_MILES);
  Angle start_bearing = ParseBearingDegrees(&endptr[1], &endptr);
  Angle end_bearing = ParseBearingDegrees(&endptr[1], &endptr);

  temp_area.AppendArc(start_bearing, end_bearing);
}
Пример #13
0
RadioFrequency
RadioFrequency::Parse(const TCHAR *p)
{
  TCHAR *endptr;
  double mhz = ParseDouble(p, &endptr);

  RadioFrequency frequency;
  if (mhz < 100 || *endptr != _T('\0'))
    frequency.Clear();
  else
    frequency.SetKiloHertz((unsigned)(mhz * 1000 + 0.5));
  return frequency;
}
Пример #14
0
novatel_gps_msgs::InscovPtr
novatel_gps_driver::InscovParser::ParseAscii(const NovatelSentence& sentence) throw(ParseException)
{
  if (sentence.body.size() != ASCII_FIELDS)
  {
    std::stringstream error;
    error << "Unexpected number of fields in INSCOV log: " << sentence.body.size();
    throw ParseException(error.str());
  }
  novatel_gps_msgs::InscovPtr ros_msg = boost::make_shared<novatel_gps_msgs::Inscov>();
  HeaderParser h_parser;
  ros_msg->novatel_msg_header = h_parser.ParseAscii(sentence);

  bool valid = true;

  valid &= ParseUInt32(sentence.body[0], ros_msg->week);
  valid &= ParseDouble(sentence.body[1], ros_msg->seconds);

  int offset = 2;
  for (int i = 0; i < 9; i++, offset++)
  {
    valid &= ParseDouble(sentence.body[offset], ros_msg->position_covariance[i]);
  }
  for (int i = 0; i < 9; i++, offset++)
  {
    valid &= ParseDouble(sentence.body[offset], ros_msg->attitude_covariance[i]);
  }
  for (int i = 0; i < 9; i++, offset++)
  {
    valid &= ParseDouble(sentence.body[offset], ros_msg->velocity_covariance[i]);
  }

  if (!valid)
  {
    throw ParseException("Error parsing INSCOV log.");
  }

  return ros_msg;
}
Пример #15
0
novatel_gps_msgs::TrackstatPtr
novatel_gps_driver::TrackstatParser::ParseAscii(const novatel_gps_driver::NovatelSentence& sentence) throw(ParseException)
{
  if (sentence.body.size() < ASCII_BODY_FIELDS)
  {
    std::stringstream error;
    error << "Unexpected number of body fields in TRACKSTAT log: " << sentence.body.size();
    throw ParseException(error.str());
  }

  uint32_t n_channels = 0;
  ParseUInt32(sentence.body[3], n_channels, 10);

  if (sentence.body.size() != ASCII_BODY_FIELDS + n_channels * ASCII_CHANNEL_FIELDS)
  {
    std::stringstream error;
    error << "Size of TRACKSTAT log did not match expected size.";
    throw ParseException(error.str());
  }

  bool valid = true;
  novatel_gps_msgs::TrackstatPtr msg = boost::make_shared<novatel_gps_msgs::Trackstat>();
  msg->solution_status = sentence.body[0];
  msg->position_type = sentence.body[1];
  valid &= ParseFloat(sentence.body[2], msg->cutoff);

  msg->channels.resize(n_channels);
  for (size_t i = 0; i < static_cast<size_t>(n_channels); ++i)
  {
    size_t offset = 4 + i * ASCII_CHANNEL_FIELDS;
    novatel_gps_msgs::TrackstatChannel& channel = msg->channels[i];
    valid &= ParseInt16(sentence.body[offset], channel.prn);
    valid &= ParseInt16(sentence.body[offset+1], channel.glofreq);
    valid &= ParseUInt32(sentence.body[offset+2], channel.ch_tr_status, 16);
    valid &= ParseDouble(sentence.body[offset+3], channel.psr);
    valid &= ParseFloat(sentence.body[offset+4], channel.doppler);
    valid &= ParseFloat(sentence.body[offset+5], channel.c_no);
    valid &= ParseFloat(sentence.body[offset+6], channel.locktime);
    valid &= ParseFloat(sentence.body[offset+7], channel.psr_res);
    channel.reject = sentence.body[offset+8];
    valid &= ParseFloat(sentence.body[offset+9], channel.psr_weight);
  }

  if (!valid)
  {
    std::stringstream error;
    error << "Error parsing TRACKSTAT log.";
    throw ParseException(error.str());
  }
  return msg;
}
int main(int argc, char** argv)
{
    SetupBenchArgs();
    std::string error;
    if (!gArgs.ParseParameters(argc, argv, error)) {
        fprintf(stderr, "Error parsing command line arguments: %s\n", error.c_str());
        return EXIT_FAILURE;
    }

    if (HelpRequested(gArgs)) {
        std::cout << gArgs.GetHelpMessage();

        return EXIT_SUCCESS;
    }

    // Set the datadir after parsing the bench options
    const fs::path bench_datadir{SetDataDir()};

    SHA256AutoDetect();
    RandomInit();
    ECC_Start();
    SetupEnvironment();

    int64_t evaluations = gArgs.GetArg("-evals", DEFAULT_BENCH_EVALUATIONS);
    std::string regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER);
    std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING);
    bool is_list_only = gArgs.GetBoolArg("-list", false);

    double scaling_factor;
    if (!ParseDouble(scaling_str, &scaling_factor)) {
        fprintf(stderr, "Error parsing scaling factor as double: %s\n", scaling_str.c_str());
        return EXIT_FAILURE;
    }

    std::unique_ptr<benchmark::Printer> printer(new benchmark::ConsolePrinter());
    std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER);
    if ("plot" == printer_arg) {
        printer.reset(new benchmark::PlotlyPrinter(
            gArgs.GetArg("-plot-plotlyurl", DEFAULT_PLOT_PLOTLYURL),
            gArgs.GetArg("-plot-width", DEFAULT_PLOT_WIDTH),
            gArgs.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT)));
    }

    benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only);

    fs::remove_all(bench_datadir);

    ECC_Stop();

    return EXIT_SUCCESS;
}
Пример #17
0
bool
LX16xxConfigWidget::SaveFixedSetting(LX1600::Setting key, unsigned idx,
                                     LX1600::SettingsMap &settings)
{
  const std::string old_value = device.GetLX16xxSetting(key);
  fixed value = fixed(ParseDouble(old_value.c_str()));
  if (!SaveValue(idx, value))
    return false;

  NarrowString<32> buffer;
  buffer.UnsafeFormat("%.2f", (double)value);
  settings[key] = std::string(buffer.c_str(), buffer.end());
  return true;
}
Пример #18
0
static fixed
WaitFixedValue(LXDevice &device, LX1600::Setting key, fixed default_value)
{
  PopupOperationEnvironment env;
  const auto x = device.WaitLX16xxSetting(key, env, TIMEOUT);
  if (!x.empty()) {
    char *endptr;
    double y = ParseDouble(x.c_str(), &endptr);
    if (endptr > x.c_str() && *endptr == 0)
      return fixed(y);
  }

  return default_value;
}
Пример #19
0
bool
Profile::GetGeoPoint(const char *key, GeoPoint &value)
{
  const char *p = Get(key);
  if (p == nullptr)
    return false;

  char *endptr;
  double longitude = ParseDouble(p, &endptr);
  if (endptr == p || *endptr != _T(' ') ||
      longitude < -180.0 || longitude > 180.0)
    return false;

  p = endptr + 1;
  double latitude = ParseDouble(p, &endptr);
  if (endptr == p || *endptr != _T('\0') ||
      latitude < -90.0 || latitude > 90.0)
    return false;

  value.longitude = Angle::Degrees(longitude);
  value.latitude = Angle::Degrees(latitude);
  return true;
}
Пример #20
0
bool json::Reader::ParseNumber(ConfigValue& value)
{
	bool integer = true; // Number is either integer or float
	for(const char* c = _cur; c != _end; ++c)
	{
		if((*c >= '0' && *c <= '9') || ((*c == '-' || *c == '+') && (c == _cur))) // Allow a negative sign at the start for integers
			continue;
		else if(*c == '.' || *c == 'e' || *c == 'E' || *c == '+') 
		{
			integer = false;
			break;
		}
		else
			break;
	}
	if(!integer)
		return ParseDouble(value);


	bool negative = (*_cur == '-');
	if(negative)
		_cur++;

	uint64_t number = 0;
	while(_cur != _end)
	{
		if(*_cur >= '0' && *_cur <= '9')
		{
			uint32_t digit = *_cur - '0';
			number = number * 10 + digit;
			_cur++;
		}
		else
			break;
	}
	if(negative)
	{
		value.SetInt(-int64_t(number));
	}
	else if(number <= INT64_MAX)
	{
		value.SetInt(int64_t(number));
	}
	else
	{
		value.SetUInt(number);
	}

	return true;
}
Пример #21
0
static bool
ReadLine(NLineReader &reader, double &value_r)
{
  const char *line = reader.ReadLine(); // x scale
  if (line == nullptr)
    return false;

  char *endptr;
  double value = ParseDouble(line, &endptr);
  if (endptr == line)
    return false;

  value_r = value;
  return true;
}
double CInfixExpressionCalculator::ParseExprMul(boost::string_ref &ref)
{
    double value = ParseDouble(ref);
    while (true)
    {
        SkipSpaces(ref);
        if (!ref.empty() && ref[0] == '*')
        {
            ref.remove_prefix(1);
            value *= ParseDouble(ref);
        }
        else if (!ref.empty() && ref[0] == '/')
        {
            ref.remove_prefix(1);
            value /= ParseDouble(ref);
        }
        else
        {
            break;
        }
    }

    return value;
}
Пример #23
0
void Parser::ParseCamera()
{
	Point position, focus;
	Vector up;
	double filedOfView;
	int xResolution, yResolution;
	while (HasNextTag())
	{
		std::string tag = NextTag();
		if (tag == "position")
		{
			SkipSpace();
			ParseTripleDouble(&position.x, &position.y, &position.z);
		}
		else if (tag == "up")
		{
			SkipSpace();
			ParseTripleDouble(&up.x, &up.y, &up.z);
		}
		else if (tag == "focus")
		{
			SkipSpace();
			ParseTripleDouble(&focus.x, &focus.y, &focus.z);
		}
		else if (tag == "fov")
		{
			SkipSpace();
			filedOfView = ParseDouble();
		}
		else if (tag == "resolution")
		{
			SkipSpace();
			xResolution = ParseInteger();
			++index;
			yResolution = ParseInteger();
		}
		else if (tag == "/camera")
		{
			double aspect = static_cast<double>(xResolution) / static_cast<double>(yResolution);
			camera = new Camera(position, focus, up, filedOfView, aspect);
			image = new Image(xResolution,yResolution);
			break;
		}
	}
}
Пример #24
0
static bool
ParseCircleTNP(const TCHAR *buffer, TempAirspaceType &temp_area)
{
  // CIRCLE RADIUS=17.00 CENTRE=N533813 E0095943

  const TCHAR* parameter;
  if ((parameter = StringAfterPrefixCI(buffer, _T("RADIUS="))) == nullptr)
    return false;
  temp_area.radius = Units::ToSysUnit(fixed(ParseDouble(parameter)),
                                      Unit::NAUTICAL_MILES);

  if ((parameter = _tcsstr(parameter, _T(" "))) == nullptr)
    return false;
  if ((parameter = StringAfterPrefixCI(parameter, _T(" CENTRE="))) == nullptr)
    return false;
  ParseCoordsTNP(parameter, temp_area.center);

  return true;
}
Пример #25
0
// static
status_t M3UParser::parseMetaDataDuration(
        const AString &line, sp<AMessage> *meta, const char *key) {
    ssize_t colonPos = line.find(":");

    if (colonPos < 0) {
        return ERROR_MALFORMED;
    }

    double x;
    status_t err = ParseDouble(line.c_str() + colonPos + 1, &x);

    if (err != OK) {
        return err;
    }

    if (meta->get() == NULL) {
        *meta = new AMessage;
    }
    (*meta)->setInt64(key, (int64_t)(x * 1E6));

    return OK;
}
Пример #26
0
        //top level parse function
        sgdm::StackGuard<JsonValue>&& JsonParser::ParsePrimary(){
        	switch(currentTok){
        		case tok_endl:
        		    return std::move(Error("primary fail"));
        		case tok_identifier:
        		    return std::move(ParseName());
        		case tok_integer:
        		    return std::move(ParseInteger());
        		case tok_double:
        		    return std::move(ParseDouble());
        		case '[':
        			return std::move(ParseArray(alloc));
        		case '{':
        		    return std::move(ParseObject(alloc));
        		default:
        		    return std::move(Error("unknown token found near place" + std::to_string(indexCount)));
		
		}

		sgdm::StackGuard<JsonValue>&& JsonParser::Parse(){
			getNextTok();
			return std::move(ParsePrimary(alloc));
		}
Пример #27
0
bool
ParsePolarShape(PolarShape &shape, const char *s)
{
  char *p;
  fixed v1 = Units::ToSysUnit(fixed(ParseDouble(s, &p)), Unit::KILOMETER_PER_HOUR);
  if (*p != _T(','))
    return false;

  fixed w1 = fixed(ParseDouble(p + 1, &p));
  if (*p != _T(','))
    return false;

  fixed v2 = Units::ToSysUnit(fixed(ParseDouble(p + 1, &p)), Unit::KILOMETER_PER_HOUR);
  if (*p != _T(','))
    return false;

  fixed w2 = fixed(ParseDouble(p + 1, &p));
  if (*p != _T(','))
    return false;

  fixed v3 = Units::ToSysUnit(fixed(ParseDouble(p + 1, &p)), Unit::KILOMETER_PER_HOUR);
  if (*p != _T(','))
    return false;

  fixed w3 = fixed(ParseDouble(p + 1, &p));
  if (*p != '\0')
    return false;

  shape[0].v = v1;
  shape[0].w = w1;
  shape[1].v = v2;
  shape[1].w = w2;
  shape[2].v = v3;
  shape[2].w = w3;
  return true;
}
Пример #28
0
void
AngleDataField::SetAsString(const TCHAR *_value)
{
  ModifyValue(Angle::Degrees(ParseDouble(_value, nullptr)));
}
Пример #29
0
void Network::classify_from_file ( char *name , double thresh )
{
   int i, maxlin, did_any, best ;
   double *inputs, *iptr, maxact ;
   char msg[81], *line, *lptr ;
   FILE *fp ;

/*
   Open the file which contains the data to be classified
*/

   if ((fp = fopen ( name , "rt" )) == NULL) {
      strcpy ( msg , "Cannot open " ) ;
      strcat ( msg , name ) ;
      error_message ( msg ) ;
      return ;
      }

/*
   Allocate for the file lines as read. Conservatively guess length.
   Also allocate for network input vector.
*/

   maxlin = nin * 20 + 100 ;
   if (maxlin < 1024)
      maxlin = 1024 ;

   MEMTEXT ( "CONFUSE:line, inputs" ) ;
   line = (char *) MALLOC ( maxlin ) ;
   inputs = (double *) MALLOC ( nin * sizeof(double) ) ;

   if ((line == NULL)  ||  (inputs == NULL)) {
      memory_message ( "to classify" ) ;
      fclose ( fp ) ;
      if (line != NULL)
         FREE ( line ) ;
      if (inputs != NULL)
         FREE ( inputs ) ;
      return ;
      }

/*
   Read the file.
*/

   did_any = 0 ;  /* If file runs out on first try, ERROR! */

   for (;;) {  // Endless loop reads until file exhausted

      if ((fgets ( line , maxlin , fp ) == NULL) || (strlen ( line ) < 2)) {
         if ((! did_any)  ||  ferror ( fp )) {
            strcpy ( msg , "Problem reading file " ) ;
            strcat ( msg , name ) ;
            error_message ( msg ) ;
            }
         break ;
         }

      lptr = line ;              // Parse the data from this line
      iptr = inputs ;            // This will be the network inputs
      for (i=0 ; i<nin ; i++)
         *iptr++ = ParseDouble ( &lptr ) ;

      did_any = 1 ;              // Flag that at least one found
      trial ( inputs ) ;         // Compute network's outputs

      maxact = -1.e30 ;          // Will keep highest activity here
      best = 0 ;                 // Insurance only (good habit)
      for (i=0 ; i<nout ; i++) { // Find winning output
         if (out[i] > maxact) {
            maxact = out[i] ;
            best = i ;
            }
         }

      if (maxact >= thresh)   // If winner has enough activation
         ++confusion[best] ;  // count it in confusion
      else                    // If too little, throw it
         ++confusion[nout] ;  // in the reject category

      while ((! feof ( fp ))  &&  (line[strlen(line)-1] != '\n'))
         fgets ( line , maxlin , fp ) ; // Line length may exceed maxlin

      if (feof ( fp ))
         break ;
      }  /* Endless loop until a file runs out */

   fclose ( fp ) ;
   MEMTEXT ( "CONFUSE:line, inputs" ) ;
   FREE ( line ) ;
   FREE ( inputs ) ;
}
Пример #30
0
void GraphDat::LoadDat(wxString data, int version)                    // Not in use, see GraphBase::BaseLoad - now in use
{
	wxString readline, numstring, stringdat;
	long numdat;
	long red, green, blue;
	//int version;

	//if(diagbox) diagbox->Write(data + '\n');

	readline = data.AfterFirst('f');
	readline.Trim(false);
	numstring = readline.BeforeFirst(' ');
	numstring.ToDouble(&xfrom);

	readline = readline.AfterFirst('t');
	readline.Trim(false);
	numstring = readline.BeforeFirst(' ');
	numstring.ToDouble(&xto);

	readline = readline.AfterFirst('f');
	readline.Trim(false);
	numstring = readline.BeforeFirst(' ');
	numstring.ToDouble(&yfrom);

	readline = readline.AfterFirst('t');
	readline.Trim(false);
	numstring = readline.BeforeFirst(' ');
	numstring.ToDouble(&yto);

	readline = readline.AfterFirst('l');
	readline.Trim(false);
	numstring = readline.BeforeFirst(' ');
	numstring.ToLong(&numdat);
	xlabels = numdat;

	readline = readline.AfterFirst('s');
	readline.Trim(false);
	numstring = readline.BeforeFirst(' ');
	numstring.ToDouble(&xstep);

	readline = readline.AfterFirst('m');
	readline.Trim(false);
	numstring = readline.BeforeFirst(' ');
	numstring.ToLong(&numdat);
	xtickmode = numdat;

	readline = readline.AfterFirst('l');
	readline.Trim(false);
	numstring = readline.BeforeFirst(' ');
	numstring.ToLong(&numdat);
	ylabels = numdat;

	readline = readline.AfterFirst('s');
	readline.Trim(false);
	numstring = readline.BeforeFirst(' ');
	numstring.ToDouble(&ystep);

	readline = readline.AfterFirst('m');
	readline.Trim(false);
	numstring = readline.BeforeFirst(' ');
	numstring.ToLong(&numdat);
	ytickmode = numdat;

	readline = readline.AfterFirst('c');
	readline.Trim(false);
	numstring = readline.BeforeFirst(' ');
	numstring.ToLong(&numdat);
	colour = numdat;

	readline = readline.AfterFirst('b');
	readline.Trim(false);
	numstring = readline.BeforeFirst(' ');
	numstring.ToLong(&red);
	readline = readline.AfterFirst(' ');
	numstring = readline.BeforeFirst(' ');
	numstring.ToLong(&green);
	readline = readline.AfterFirst(' ');
	numstring = readline.BeforeFirst(' ');
	numstring.ToLong(&blue);
	strokecolour = wxColour(red, green, blue);

	if(version > 0) {
		xshift = ParseDouble(&readline, 's');
		xunitscale = ParseDouble(&readline, 'u');
		plotstroke = ParseDouble(&readline, 's');

		//if(diagbox) diagbox->Write(readline + '\n');
		
		gname = ParseString(&readline, 'e');
		gname.Replace("_", " ");

		xtag = ParseString(&readline, 'g');
		xtag.Replace("_", " ");

		ytag = ParseString(&readline, 'g');
		ytag.Replace("_", " ");
	}	

	if(version > 2) {
		xplot = ParseDouble(&readline, 'p');
		yplot = ParseDouble(&readline, 'p');
		labelfontsize = ParseDouble(&readline, 'f');
		clipmode = ParseLong(&readline, 'm');
	}

	if(version > 3) type = ParseLong(&readline, 'e');

	if(version > 4) {
		xunitdscale = ParseDouble(&readline, 'd');
		xsample = ParseDouble(&readline, 'm');
	}
}