r"""
Add CHEMKIN transport data to a Cantera YAML file.
==================================================

This example shows how to convert CHEMKIN transport data into Cantera YAML format
and combine it with existing thermodynamic data.

.. tags:: kinetics, transport, cantera, mechanism generation
"""  # noqa: D205

from rizer.kin.convert_chemkin_transport_data_to_cantera import (
    combine_thermo_transport_data,
    get_thermo_data,
    get_transport_data,
)
from rizer.misc.utils import get_path_to_data

transport_data_file = get_path_to_data("mechanisms/transport/transport.csv")
transport_data = get_transport_data(transport_data_file)
for trans_data in transport_data:
    print(trans_data.to_cantera_format())

thermo_data_file = get_path_to_data("mechanisms/thermo/grc_nasa9_C_H.yaml")
thermo_data = get_thermo_data(thermo_data_file)
for therm_data in thermo_data:
    print(therm_data.to_cantera_format())

# Write the combined data to a file.
output_file = get_path_to_data(
    "mechanisms/thermo/grc_nasa9_C_H_transport.yaml", force_return=True
)
header = ""
# Load the header from the original thermo data file.
# It goes from the start up to the "species" key.
with open(thermo_data_file, "r", encoding="utf-8") as f:
    for line in f:
        header += line
        if line.startswith("species:"):
            break

combined_data = combine_thermo_transport_data(thermo_data_file, transport_data_file)
output_file.write_text(header + "".join(combined_data))
