import f90nml

NAMELIST_FILE_NAME = 'namelist.amip'

def read_namelist():
    # Default settings, can be overwritten from namelist
    LInterpolate = False
    LDebug = True
    FixYear = 0
    # Read namelist
    nml = f90nml.read(NAMELIST_FILE_NAME)
    RunLengthSec = nml['NAMAMIP']['RunLengthSec']
    TimeStepSec = nml['NAMAMIP']['TimeStepSec']
    StartYear = nml['NAMAMIP']['StartYear']
    StartMonth = nml['NAMAMIP']['StartMonth']
    StartDay = nml['NAMAMIP']['StartDay']
    FixYear = nml['NAMAMIP']['FixYear']
    FileListSST = nml['NAMAMIP']['FileListSST']
    FileListSIC = nml['NAMAMIP']['FileListSIC']
    LDebug = nml['NAMAMIP']['LDebug']
    LInterpolate = nml['NAMAMIP']['LInterpolate']

    # Make sure we are dealing with arrays of files
    if isinstance(FileListSST, str):
        FileListSST = [FileListSST]
    if isinstance(FileListSIC, str):
        FileListSIC = [FileListSIC]

    return RunLengthSec, TimeStepSec, StartYear, StartMonth, StartDay, FixYear, FileListSST, FileListSIC, LDebug, LInterpolate
