double startLat = gds.getDouble(GridDefRecord.LA1);
double endLat = gds.getDouble(GridDefRecord.LA2);
int nlats = (int) (2 * np);
GaussianLatitudes gaussLats = new GaussianLatitudes(nlats);
int bestStartIndex = 0, bestEndIndex = 0;
double bestStartDiff = Double.MAX_VALUE;
double bestEndDiff = Double.MAX_VALUE;
for (int i = 0; i < nlats; i++) {
double diff = Math.abs(gaussLats.latd[i] - startLat);
if (diff < bestStartDiff) {
bestStartDiff = diff;
bestStartIndex = i;
}
diff = Math.abs(gaussLats.latd[i] - endLat);
if (diff < bestEndDiff) {
bestEndDiff = diff;
bestEndIndex = i;
}
}
int ny = gds.getInt(GridDefRecord.NY);
if (Math.abs(bestEndIndex - bestStartIndex + 1) != ny) {
log.warn("GRIB gaussian lats: NP != NY, use NY"); // see email from Toussaint@dkrz.de datafil:
nlats = ny;
gaussLats = new GaussianLatitudes(nlats);
bestStartIndex = 0;
bestEndIndex = ny-1;
}
boolean goesUp = bestEndIndex > bestStartIndex;