readPartialFiles (int randomReadCount, const std::string & fn)
{
    Array2D<unsigned int> uData;
    Array2D<float> fData;
    Array2D<half> hData;

    cout << "Reading partial files " << flush;
    MultiPartInputFile file(fn.c_str());
    //const vector<Header>& headers = file.parts();
    for (int i = 0; i < randomReadCount; i++)
    {
        int partNumber = random_int(headers.size());
        int partType = partTypes[partNumber];
        int pixelType = pixelTypes[partNumber];
        int levelMode = levelModes[partNumber];

        if (partType == 0)
        {
            int l1, l2;
            l1 = random_int(height);
            l2 = random_int(height);
            if (l1 > l2) swap(l1, l2);

            InputPart part(file, partNumber);

            FrameBuffer frameBuffer;
            setInputFrameBuffer(frameBuffer, pixelType,
                                uData, fData, hData, width, height);

            part.setFrameBuffer(frameBuffer);
            part.readPixels(l1, l2);

            switch (pixelType)
            {
                case 0:
                    assert(checkPixels<unsigned int>(uData, 0, width - 1, l1, l2, width));
                    break;
                case 1:
                    assert(checkPixels<float>(fData, 0, width - 1, l1, l2, width));
                    break;
                case 2:
                    assert(checkPixels<half>(hData, 0, width - 1, l1, l2, width));
                    break;
            }
        }
        else
        {
            int tx1, tx2, ty1, ty2;
            int lx, ly;

            TiledInputPart part(file, partNumber);

            int numXLevels = part.numXLevels();
            int numYLevels = part.numYLevels();

            lx = random_int(numXLevels);
            ly = random_int(numYLevels);
            if (levelMode == 1) ly = lx;

            int w = part.levelWidth(lx);
            int h = part.levelHeight(ly);

            int numXTiles = part.numXTiles(lx);
            int numYTiles = part.numYTiles(ly);
            tx1 = random_int(numXTiles);
            tx2 = random_int(numXTiles);
            ty1 = random_int(numYTiles);
            ty2 = random_int(numYTiles);
            if (tx1 > tx2) swap(tx1, tx2);
            if (ty1 > ty2) swap(ty1, ty2);

            FrameBuffer frameBuffer;
            setInputFrameBuffer(frameBuffer, pixelType,
                                uData, fData, hData, w, h);

            part.setFrameBuffer(frameBuffer);
            part.readTiles(tx1, tx2, ty1, ty2, lx, ly);

            Box2i b1 = part.dataWindowForTile(tx1, ty1, lx, ly);
            Box2i b2 = part.dataWindowForTile(tx2, ty2, lx, ly);

            switch (pixelType)
            {
                case 0:
                    assert(checkPixels<unsigned int>(uData, b1.min.x, b2.max.x, b1.min.y, b2.max.y,
                                                     w));
                    break;
                case 1:
                    assert(checkPixels<float>(fData, b1.min.x, b2.max.x, b1.min.y, b2.max.y,
                                              w));
                    break;
                case 2:
                    assert(checkPixels<half>(hData, b1.min.x, b2.max.x, b1.min.y, b2.max.y,
                                             w));
                    break;
            }
        }
    }
}