def icoads_filename(icoads_dir, readyear, readmonth, version):
    """
    Build the filename for an ICOADS file

    :param icoads_dir: the base directory containing the ICOADS data
    :param readyear: the year to read in
    :param readmonth: the month to read in
    :param version: the version of ICOADS being used
    :return: full pathname for the ICOADS file for specified year and month
    """
    assert version in ['2.5', '3.0'], "name not 2.5 or 3.0"

    syr = str(readyear)
    smn = "{:02}".format(readmonth)

    filename = None

    if version == '2.5':
        filename = "{}/ICOADS.2.5.1/R2.5.1.{}.{}.gz".format(icoads_dir, syr, smn)
        if (readyear > 2007) & (readyear < 2015):
            filename = "{}/R2.5.2.{}.{}.gz".format(icoads_dir, syr, smn)

    if version == '3.0':
        if readyear <= 2014:
            filename = "{}/ICOADS.3.0.0/IMMA1_R3.0.0_{}-{}.gz".format(icoads_dir, syr, smn)
        if readyear >= 2015:
            filename = "{}/ICOADS.3.0.1/IMMA1_R3.0.1_{}-{}.gz".format(icoads_dir, syr, smn)

    return filename