modisClient: function for building a modisData object

def modisClient(client=None,
                product=None,
                band=None,
                lat=None,
                lon=None,
                startDate=None,
                endDate=None,
                chunkSize=8,
                kmAboveBelow=0,
                kmLeftRight=0):
    """
	modisClient: function for building a modisData object
	"""

    m = modisData()

    m.kmABoveBelow = kmAboveBelow
    m.kmLeftRight = kmLeftRight

    if client == None:
        client = setClient()

    m.server = client.wsdl.url

    if product == None:
        prodList = client.service.getproducts()
        return prodList

    m.product = product

    if band == None:
        bandList = client.service.getbands(product)
        return bandList

    m.band = band

    if lat == None or lon == None:
        latLonErr()

    m.latitude = lat
    m.longitude = lon

    # get the date list regardless so we can
    # process it into appropriately sized chunks

    dateList = client.service.getdates(lat, lon, product)

    if startDate == None or endDate == None:
        return dateList

    #count up the total number of dates
    i = -1
    nDates = 0
    while i < dateList.__len__() - 1:
        i = i + 1

        thisDate = mkIntDate(dateList[i])

        if thisDate < startDate:
            continue
        if thisDate > endDate:
            break

        nDates = nDates + 1

        m.dateInt.append(thisDate)
        m.dateStr.append(dateList[i])

    n = 0
    i = -1
    while i < dateList.__len__() - 1:
        i = i + 1

        thisDate = mkIntDate(dateList[i])

        if thisDate < startDate:
            continue
        if thisDate > endDate:
            break

        requestStart = dateList[i]

        j = min(chunkSize, dateList.__len__() - i)

        while mkIntDate(dateList[i + j - 1]) > endDate:
            j = j - 1

        requestEnd = dateList[i + j - 1]
        i = i + j - 1

        data = client.service.getsubset(lat, lon, product, band, requestStart,
                                        requestEnd, kmAboveBelow, kmLeftRight)

        # now fill up the data structure with the returned data...

        if n == 0:

            m.nrows = data.nrows
            m.ncols = data.ncols
            m.cellsize = data.cellsize
            m.scale = data.scale
            m.units = data.units
            m.yllcorner = data.yllcorner
            m.xllcorner = data.xllcorner

            m.data = np.zeros((nDates, m.nrows * m.ncols))

        for j in xrange(data.subset.__len__()):
            kn = 0

            for k in data.subset[j].split(",")[5:]:

                try:
                    m.data[n * chunkSize + j, kn] = int(k)
                except ValueError:
                    serverDataErr()

                kn = kn + 1

        n = n + 1

    return (m)