$queryManager = new QueryManager($readOnly);
$contourDataStore = new ContourCacheHelper($useGzip, $bandHelper->getSchemeId());
// Check if $txnAt for $timestamp is older than specified right now,
// then only proceed. Otherwise just exit from here
// Honour force flag if is set
$lastTxnAt = $txnAt;
if ($txnAt >= 0) {
    $lastTxnAt = $queryManager->getGridUpdatedTime($timestamp, $param);
}
if ($txnAt >= 0 && $lastTxnAt >= $txnAt) {
    echo "Grid last updated with txn stamp [{$lastTxnAt}]," . " more recent than / equal to [{$txnAt}]\n";
    echo "Use force write if it was intended to forcefully update data";
    exit(0);
}
$queryStart = microtime(true);
$allData = $queryManager->getDataForWindBasedInterpolation($timestamp, 6, false, $param);
if (empty($allData["{$param}Values"])) {
    echo "No data available for interpolation algorithm for {$timestamp}\n";
    exit(0);
}
$queryTime += microtime(true) - $queryStart;
$writeToGridStatus = true;
// true if band scheme is non zero
if ($bandHelper->getSchemeId() == 0) {
    //echo "pre-r \n";
    //echo java_inspect($driver);
    //var_dump($allData);
    //print_r(java_values($driver->gridExtent));
    $r = $driver->getGridData($allData["{$param}Stations"], $allData['windStations'], $allData["{$param}Values"], $allData['windSpeed'], $allData['windDirection'], $stepSize);
    //var_dump(java_invoke(0, "getValues", array($r)));
    //var_dump($driver->__call("getValues",array($r)));
$phpTime = microtime(true) - $phpStart;
// Check if $txnAt for $timestamp is older than specified right now,
// then only proceed. Otherwise just exit from here
// Honour force flag if is set
$lastTxnAt = $txnAt;
if ($txnAt >= 0) {
    $lastTxnAt = $queryManager->getGridUpdatedTime($timestamp);
}
if ($txnAt >= 0 && $lastTxnAt >= $txnAt) {
    echo "Grid last updated with txn stamp [{$lastTxnAt}]," . " more recent than / equal to [{$txnAt}]\n";
    echo "Use force write if it was intended to forcefully update data";
    exit(0);
}
$midTime = microtime(true);
$queryStart = microtime(true);
$allData = $queryManager->getDataForWindBasedInterpolation($timestamp, 6);
if (empty($allData['ozoneValues'])) {
    echo "No data available for interpolation algorithm for {$timestamp}\n";
    exit(0);
}
$queryTime = microtime(true) - $queryStart;
$writeToGridStatus = true;
// true if band scheme is non zero
if ($bandHelper->getSchemeId() == 0) {
    $driverStart = microtime(true);
    $r = $driver->getGridData($allData['ozoneStations'], $allData['windStations'], $allData['ozoneValues'], $allData['windSpeed'], $allData['windDirection'], $stepSize);
    $driverTime += microtime(true) - $driverStart;
    $grid = java_values($r);
    $queryStart = microtime(true);
    $writeToGridStatus = $queryManager->writeGridToDB($grid, $timestamp, $gridReference, java_values($driver->gridExtent));
    if ($writeToGridStatus) {
$grid = array();
$bandHelper = new DiscreteBandHelper(DiscreteBandHelper::LABEL_TYPE_BAND, $bandScheme);
$ozoneBand = $bandHelper->getBand();
$bandHashMap = new Java("java.util.HashMap");
foreach ($ozoneBand as $key => $val) {
    $bandHashMap->put($key, doubleval($val));
}
$driver = new Java('LatLongInterpolation.LatLngDriver', $bandHashMap);
$driver->setWriteDebugImages(false);
$queryTime = 0;
// query based on timestamp
$readOnly = true;
$queryManager = new QueryManager($readOnly);
$queryStart = microtime(true);
$trailPoints = 6;
$allData = $queryManager->getDataForWindBasedInterpolation($timestamp, $trailPoints);
if (empty($allData['ozoneValues'])) {
    echo "No data available for interpolation algorithm for {$timestamp}\n";
    exit(0);
}
$queryTime += microtime(true) - $queryStart;
// Interpolate grid by skipping one station at a time and check for delta
$li = count($allData['ozoneValues']) - 1;
$diff = array();
for ($st = 0; $st < count($allData['ozoneStations']); $st++) {
    // copy data
    $omitStation = $allData['ozoneStations'][$st];
    $omitO3Value = $allData['ozoneValues'][$li][$st];
    // No point in comparing is station had no valid value for ozone
    if ($omitO3Value == -1) {
        continue;