def METHOD_NAME(filename, name, waypoints):
    if not filename:
        raise ValueError("filename to save flight track cannot be None")
    max_loc_len, max_com_len = len("Location"), len("Comments")
    for wp in waypoints:
        if len(str(wp.location)) > max_loc_len:
            max_loc_len = len(str(wp.location))
        if len(str(wp.comments)) > max_com_len:
            max_com_len = len(str(wp.comments))
    with codecs.open(filename, "w", encoding="utf-8") as out_file:
        out_file.write(u"# Do not modify if you plan to import this file again!\n")
        out_file.write(f"Track name: {name:}\n")
        line = u"{0:5d}  {1:{2}}  {3:10.3f}  {4:11.3f}  {5:11.3f}  {6:14.3f}  {7:14.1f}  {8:15.1f}  {9:{10}}\n"
        header = f"Index  {'Location':{max_loc_len}}  Lat (+-90)  Lon (+-180)  Flightlevel  Pressure (hPa)  " \
                 f"Leg dist. (km)  Cum. dist. (km)  {'Comments':{max_com_len}}\n"
        out_file.write(header)
        for i, wp in enumerate(waypoints):
            # ToDo check str(str( .. ) and may be use csv write
            loc = str(wp.location)
            lat = wp.lat
            lon = wp.lon
            lvl = wp.flightlevel
            pre = wp.pressure / 100.
            leg = wp.distance_to_prev
            cum = wp.distance_total
            com = str(wp.comments)
            out_file.write(line.format(i, loc, max_loc_len, lat, lon, lvl, pre, leg, cum, com, max_com_len))