from osgeo import gdal
import os

def convert_dat_to_tiff(dat_file):
    """
    Converts a .dat raster file to a .tiff file.
    
    Args:
        dat_file (str): Path to the .dat file.
    
    Returns:
        str: Path to the generated .tiff file.
    """
    
    tiff_file = dat_file.replace(".dat", ".tiff")

    # Open the .dat file
    dataset = gdal.Open(dat_file, gdal.GA_ReadOnly)
    if dataset is None:
        raise Exception(f"Failed to open .dat file: {dat_file}")

    # Convert to GeoTIFF format
    gdal.Translate(tiff_file, dataset, format="GTiff")

    # Close dataset
    dataset = None

    return tiff_file
