#!/usr/bin/awk -f

function find_band(value, bands) {
    for (i in bands) {
        split(bands[i], parts, /[-:]/)
        if (value >= parts[1] && value <= parts[2]) {
            return parts[3]
        }
    }
    return ""
}

BEGIN {
    if (ARGC < 3) {
        print "Usage: " ARGV[0] " <MODE> <CHANNEL>"
        exit 1
    }

    mode = ARGV[1]
    value = ARGV[2]
    ARGC = 1

    # LTE Bands
    lte_bands[0] = "0-599:1"
    lte_bands[1] = "600-1199:2"
    lte_bands[2] = "1200-1949:3"
    lte_bands[3] = "1950-2399:4"
    lte_bands[4] = "2400-2469:5"
    lte_bands[5] = "2750-3449:7"
    lte_bands[6] = "3450-3799:8"
    lte_bands[7] = "6150-6449:20"
    lte_bands[8] = "9210-9659:28"
    lte_bands[9] = "9870-9919:31"
    lte_bands[10] = "37750-38249:38"
    lte_bands[11] = "38650-39649:40"
    lte_bands[12] = "39650-41589:41"

    # Other Bands
    other_bands[0] = "1-124:GSM900"
    other_bands[1] = "512-885:DCS1800"
    other_bands[2] = "955-1023:DCS900"
    other_bands[3] = "2937-3088:UMTS900"
    other_bands[4] = "10562-10838:IMT2100"

    if (mode ~ /^LTE/) {
        result = find_band(value, lte_bands)
        print (result != "" ? result : 0)
    } else {
        result = find_band(value, other_bands)
        print (result != "" ? result : "")
    }
}
