private void convert(File source, NavigationFormat format, File target) throws IOException {
    NavigationFileParser parser = new NavigationFileParser();
    if (!parser.read(source)) {
      log.severe("Could not read source '" + source.getAbsolutePath() + "'");
      logFormatNames(NavigationFormats.getReadFormatsSortedByName());
      System.exit(20);
    }

    if (format.isSupportsMultipleRoutes()) {
      parser.write(parser.getAllRoutes(), (MultipleRoutesFormat) format, target);
    } else {
      int fileCount =
          NavigationFileParser.getNumberOfFilesToWriteFor(parser.getTheRoute(), format, false);
      File[] targets =
          Files.createTargetFiles(
              target, fileCount, format.getExtension(), format.getMaximumFileNameLength());
      for (File t : targets) {
        if (t.exists()) {
          log.severe("Target '" + t.getAbsolutePath() + "' already exists; stopping.");
          System.exit(13);
        }
      }
      parser.write(parser.getTheRoute(), format, false, false, targets);
    }
  }
  private NavigationFormat determineFormat(
      List<BaseRoute> routes, NavigationFormat preferredFormat) {
    NavigationFormat result = preferredFormat;
    for (BaseRoute route : routes) {
      // more than one route: the same result
      if (result.equals(route.getFormat())) continue;

      // result is capable of storing multiple routes
      if (result.isSupportsMultipleRoutes()) continue;

      // result from GPSBabel-based format which allows only one route but is represented by GPX 1.0
      if (result instanceof BabelFormat) continue;

      // default for multiple routes is GPX 1.1
      result = new Gpx11Format();
    }
    return result;
  }