boolean passOne = true;
for (int i = 0; i < products.size(); i++) {
Grib2Product product = products.get(i);
raf.seek(product.getGdsOffset());
GdsReader2 gds = new GdsReader2(raf, true);
Grib2GDSVariables gpv = gds.gdsVars;
if (passOne) {
System.out.println(" Section = " + gpv.getSection());
System.out.println(" Length = " + gpv.getLength());
System.out.println(" Grid Template Number = " + gpv.getGdtn());
passOne = false;
}
assert (gds.length == gpv.getLength());
assert (gds.section == gpv.getSection());
assert (gds.numberPoints == gpv.getNumberPoints());
assert (gds.source == gpv.getSource());
assert (gds.olon == gpv.getOlon());
assert (gds.gdtn == gpv.getGdtn());
int gdtn = gpv.getGdtn();
switch (gdtn) { // Grid Definition Template Number
case 0:
case 1:
case 2:
case 3: // Latitude/Longitude Grid
assert (gds.shape == gpv.getShape());
assert (gds.nx == gpv.getNx());
//System.out.println( "nx=" + nx);
assert (gds.ny == gpv.getNy());
//System.out.println( "ny=" + ny);
assert (gds.basicAngle == gpv.getBasicAngle());
assert (gds.subdivisionsangle == gpv.getSubDivisions());
assert (gds.la1 == gpv.getLa1());
assert (gds.lo1 == gpv.getLo1());
assert (gds.resolution == gpv.getResolution());
assert (gds.la2 == gpv.getLa2());
assert (gds.lo2 == gpv.getLo2());
assert (gds.dx == gpv.getDx());
assert (gds.dy == gpv.getDy());
assert (gds.grid_units.equals(gpv.getGridUnits()));
assert (gds.scanMode == gpv.getScanMode());
assert (gds.angle == gpv.getAngle());
// 1, 2, and 3 needs checked
if (gdtn == 1) { //Rotated Latitude/longitude
assert (gds.spLat == gpv.getSpLat());
assert (gds.spLon == gpv.getSpLon());
assert (gds.rotationangle == gpv.getRotationAngle());
} else if (gdtn == 2) { //Stretched Latitude/longitude
assert (gds.poleLat == gpv.getPoleLat());
assert (gds.poleLon == gpv.getPoleLon());
assert (gds.factor == gpv.getStretchingFactor());
} else if (gdtn == 3) { //Stretched and Rotated
// Latitude/longitude
assert (gds.spLat == gpv.getSpLat());
assert (gds.spLon == gpv.getSpLon());
assert (gds.rotationangle == gpv.getRotationAngle());
assert (gds.poleLat == gpv.getPoleLat());
assert (gds.poleLon == gpv.getPoleLon());
assert (gds.factor == gpv.getStretchingFactor());
}
break;
case 10: // Mercator
// la1, lo1, lad, la2, and lo2 need checked
assert (gds.shape == gpv.getShape());
;
//System.out.println( "shape=" + shape );
assert (gds.nx == gpv.getNx());
//System.out.println( "nx=" + nx);
assert (gds.ny == gpv.getNy());
//System.out.println( "ny=" + ny);
assert (gds.la1 == gpv.getLa1());
assert (gds.lo1 == gpv.getLo1());
assert (gds.resolution == gpv.getResolution());
assert (gds.lad == gpv.getLaD());
assert (gds.la2 == gpv.getLa2());
assert (gds.lo2 == gpv.getLo2());
assert (gds.scanMode == gpv.getScanMode());
assert (gds.angle == gpv.getAngle());
assert (gds.dx == gpv.getDx());
assert (gds.dy == gpv.getDy());
assert (gds.grid_units.equals(gpv.getGridUnits()));
break;
case 20: // Polar stereographic projection
// la1, lo1, lad, and lov need checked
assert (gds.shape == gpv.getShape());
;
//System.out.println( "shape=" + shape );
assert (gds.nx == gpv.getNx());
//System.out.println( "nx=" + nx);
assert (gds.ny == gpv.getNy());
//System.out.println( "ny=" + ny);
assert (gds.la1 == gpv.getLa1());
assert (gds.lo1 == gpv.getLo1());
assert (gds.resolution == gpv.getResolution());
assert (gds.lad == gpv.getLaD());
assert (gds.lov == gpv.getLoV());
assert (gds.dx == gpv.getDx());
assert (gds.dy == gpv.getDy());
assert (gds.grid_units.equals(gpv.getGridUnits()));
assert (gds.projectionCenter == gpv.getProjectionFlag());
assert (gds.scanMode == gpv.getScanMode());
break;
case 30: // Lambert Conformal
assert (gds.shape == gpv.getShape());
;
//System.out.println( "shape=" + shape );
assert (gds.nx == gpv.getNx());
//System.out.println( "nx=" + nx);
assert (gds.ny == gpv.getNy());
//System.out.println( "ny=" + ny);
assert (gds.la1 == gpv.getLa1());
//System.out.println( "la1=" + la1 );
assert (gds.lo1 == gpv.getLo1());
//System.out.println( "lo1=" + lo1);
assert (gds.resolution == gpv.getResolution());
assert (gds.lad == gpv.getLaD());
assert (gds.lov == gpv.getLoV());
assert (gds.dx == gpv.getDx());
assert (gds.dy == gpv.getDy());
assert (gds.grid_units.equals(gpv.getGridUnits()));
assert (gds.projectionCenter == gpv.getProjectionFlag());
assert (gds.scanMode == gpv.getScanMode());
assert (gds.latin1 == gpv.getLatin1());
assert (gds.latin2 == gpv.getLatin2());
//System.out.println( "latin1=" + latin1);
//System.out.println( "latin2=" + latin2);
assert (gds.spLat == gpv.getSpLat());
assert (gds.spLon == gpv.getSpLon());
//System.out.println( "spLat=" + spLat);
//System.out.println( "spLon=" + spLon);
break;
case 31: // Albers Equal Area
// la1, lo1, lad, and lov need checked
assert (gds.shape == gpv.getShape());
//System.out.println( "shape=" + shape );
assert (gds.nx == gpv.getNx());
//System.out.println( "nx=" + nx);
assert (gds.ny == gpv.getNy());
//System.out.println( "ny=" + ny);
assert (gds.la1 == gpv.getLa1());
//System.out.println( "la1=" + la1 );
assert (gds.lo1 == gpv.getLo1());
//System.out.println( "lo1=" + lo1);
assert (gds.resolution == gpv.getResolution());
assert (gds.lad == gpv.getLaD());
assert (gds.lov == gpv.getLoV());
assert (gds.dx == gpv.getDx());
assert (gds.dy == gpv.getDy());
assert (gds.grid_units.equals(gpv.getGridUnits()));
assert (gds.projectionCenter == gpv.getProjectionFlag());
assert (gds.scanMode == gpv.getScanMode());
assert (gds.latin1 == gpv.getLatin1());
assert (gds.latin2 == gpv.getLatin2());
//System.out.println( "latin1=" + latin1);
//System.out.println( "latin2=" + latin2);
assert (gds.spLat == gpv.getSpLat());
assert (gds.spLon == gpv.getSpLon());
//System.out.println( "spLat=" + spLat);
//System.out.println( "spLon=" + spLon);
break;
case 40:
case 41:
case 42:
case 43: // Gaussian latitude/longitude
// octet 15
assert (gds.shape == gpv.getShape());
//System.out.println( "shape=" + shape );
// octets 31-34
assert (gds.nx == gpv.getNx());
//System.out.println( "nx=" + nx);
// octets 35-38
assert (gds.ny == gpv.getNy());
//System.out.println( "ny=" + ny);
// octets 39-42
assert (gds.angle == gpv.getBasicAngle());
// octets 43-46
assert (gds.subdivisionsangle == gpv.getSubDivisions());
//System.out.println( "ratio =" + ratio );
// octets 47-50
assert (gds.la1 == gpv.getLa1());
// octets 51-54
assert (gds.lo1 == gpv.getLo1());
// octet 55
assert (gds.resolution == gpv.getResolution());
// octets 56-59
assert (gds.la2 == gpv.getLa2());
// octets 60-63
assert (gds.lo2 == gpv.getLo2());
// octets 64-67
assert (gds.dx == gpv.getDx());
assert (gds.grid_units.equals(gpv.getGridUnits()));
// octet 68-71
assert (gds.np == gpv.getNp());
// octet 72
assert (gds.scanMode == gpv.getScanMode());
if (gdtn == 41) { //Rotated Gaussian Latitude/longitude
// octets 73-76
assert (gds.spLat == gpv.getSpLat());
// octets 77-80
assert (gds.spLon == gpv.getSpLon());
// octets 81-84
assert (gds.rotationangle == gpv.getRotationAngle());
} else if (gdtn == 42) { //Stretched Gaussian
// Latitude/longitude
// octets 73-76
assert (gds.poleLat == gpv.getPoleLat());
// octets 77-80
assert (gds.poleLon == gpv.getPoleLon());
// octets 81-84
assert (gds.factor == gpv.getStretchingFactor());
} else if (gdtn == 43) { //Stretched and Rotated Gaussian
// Latitude/longitude
// octets 73-76
assert (gds.spLat == gpv.getSpLat());
// octets 77-80
assert (gds.spLon == gpv.getSpLon());
// octets 81-84
assert (gds.rotationangle == gpv.getRotationAngle());
// octets 85-88
assert (gds.poleLat == gpv.getPoleLat());
// octets 89-92
assert (gds.poleLon == gpv.getPoleLon());
// octets 93-96
assert (gds.factor == gpv.getStretchingFactor());
}
break;
case 50:
case 51:
case 52:
case 53: // Spherical harmonic coefficients
gds.j = raf.readFloat();
gds.k = raf.readFloat();
gds.m = raf.readFloat();
gds.method = raf.read();
gds.mode = raf.read();
assert (gds.grid_units.equals(gpv.getGridUnits()));
if (gdtn == 51) { //Rotated Spherical harmonic coefficients
assert (gds.spLat == gpv.getSpLat());
assert (gds.spLon == gpv.getSpLon());
assert (gds.rotationangle == gpv.getRotationAngle());
} else if (gdtn == 52) { //Stretched Spherical
// harmonic coefficients
assert (gds.poleLat == gpv.getPoleLat());
assert (gds.poleLon == gpv.getPoleLon());
assert (gds.factor == gpv.getStretchingFactor());
} else if (gdtn == 53) { //Stretched and Rotated
// Spherical harmonic coefficients
assert (gds.spLat == gpv.getSpLat());
assert (gds.spLon == gpv.getSpLon());
assert (gds.rotationangle == gpv.getRotationAngle());
assert (gds.poleLat == gpv.getPoleLat());
assert (gds.poleLon == gpv.getPoleLon());
assert (gds.factor == gpv.getStretchingFactor());
}
break;
case 90: // Space view perspective or orthographic
assert (gds.shape == gpv.getShape());
//System.out.println( "shape=" + shape );
assert (gds.nx == gpv.getNx());
//System.out.println( "nx=" + nx);
assert (gds.ny == gpv.getNy());
//System.out.println( "ny=" + ny);
assert (gds.lap == gpv.getLap());
assert (gds.lop == gpv.getLop());
assert (gds.resolution == gpv.getResolution());
assert (gds.dx == gpv.getDx());
assert (gds.dy == gpv.getDy());
assert (gds.grid_units.equals(gpv.getGridUnits()));
assert (gds.xp == gpv.getXp());
assert (gds.yp == gpv.getYp());
assert (gds.scanMode == gpv.getScanMode());
assert (gds.angle == gpv.getAngle());
//altitude = GribNumbers.int4( raf ) * 1000000;
assert (gds.altitude == gpv.getNr());
assert (gds.xo == gpv.getXo());
assert (gds.yo == gpv.getYo());
break;
/*
case 100 : // Triangular grid based on an icosahedron
n2 = raf.read();
checkSum = 7 * checkSum + n2;
n3 = raf.read();
checkSum = 7 * checkSum + n3;
ni = GribNumbers.int2(raf);
checkSum = 7 * checkSum + ni;
nd = raf.read();
checkSum = 7 * checkSum + nd;
poleLat = GribNumbers.int4(raf) / tenToSix;
checkSum = 7 * checkSum + poleLat;
poleLon = GribNumbers.int4(raf) / tenToSix;
checkSum = 7 * checkSum + poleLon;
lonofcenter = GribNumbers.int4(raf);
position = raf.read();
order = raf.read();
scanMode = raf.read();
n = GribNumbers.int4(raf);
grid_units = "";
break;
case 110 : // Equatorial azimuthal equidistant projection
shape = raf.read();
//System.out.println( "shape=" + shape );
scalefactorradius = raf.read();
scaledvalueradius = GribNumbers.int4(raf);
scalefactormajor = raf.read();
scaledvaluemajor = GribNumbers.int4(raf);
scalefactorminor = raf.read();
scaledvalueminor = GribNumbers.int4(raf);
nx = GribNumbers.int4(raf);
//System.out.println( "nx=" + nx);
ny = GribNumbers.int4(raf);
//System.out.println( "ny=" + ny);
la1 = GribNumbers.int4(raf) / tenToSix;
checkSum = 7 * checkSum + la1;
lo1 = GribNumbers.int4(raf) / tenToSix;
checkSum = 7 * checkSum + lo1;
resolution = raf.read();
dx = (float) (GribNumbers.int4(raf) / tenToThree);
//checkSum = 7 * checkSum + dx;
dy = (float) (GribNumbers.int4(raf) / tenToThree);
//checkSum = 7 * checkSum + dy;
grid_units = "";
projectionCenter = raf.read();
scanMode = raf.read();
break;
case 120 : // Azimuth-range Projection
nb = GribNumbers.int4(raf);
checkSum = 7 * checkSum + nb;
nr = GribNumbers.int4(raf);
checkSum = 7 * checkSum + nr;
la1 = GribNumbers.int4(raf);
checkSum = 7 * checkSum + la1;
lo1 = GribNumbers.int4(raf);
checkSum = 7 * checkSum + lo1;
dx = GribNumbers.int4(raf);
//checkSum = 7 * checkSum + dx;
grid_units = "";
dstart = raf.readFloat();
scanMode = raf.read();
for (int i = 0; i < nr; i++) {
// get azi (33+4(Nr-1))-(34+4(Nr-1))
// get adelta (35+4(Nr-1))-(36+4(Nr-1))
}
System.out.println("need code to get azi and adelta");
break;
*/
case 204: // Curvilinear orthographic
assert (gds.shape == gpv.getShape());
//System.out.println( "shape=" + shape );
assert (gds.nx == gpv.getNx());
//System.out.println( "nx=" + nx);
assert (gds.ny == gpv.getNy());
//System.out.println( "ny=" + ny);
// octets 39 - 54 not used, set to 0
assert (gds.resolution == gpv.getResolution());
// octets 56 - 71 not used
assert (gds.scanMode == gpv.getScanMode());
assert (gds.grid_units.equals(gpv.getGridUnits()));
break;
default:
System.out.println("Unknown Grid Type "
+ Integer.toString(gdtn));
} // end switch
// calculate earth radius
if (((gdtn < 50) || (gdtn > 53)) && (gdtn != 100) && (gdtn != 120)) {
if (gds.shape == 0) {
assert (gds.earthRadius == gpv.getEarthRadius());
} else if (gds.shape == 1) {
assert (gds.earthRadius == gpv.getEarthRadius());
} else if (gds.shape == 2) {
assert (gds.majorAxis == gpv.getMajorAxis());
assert (gds.minorAxis == gpv.getMinorAxis());
} else if (gds.shape == 3) {
//System.out.println( "majorAxisScale =" + scalefactormajor );
//System.out.println( "majorAxisiValue =" + scaledvaluemajor );
assert (gds.majorAxis == gpv.getMajorAxis());
//System.out.println( "minorAxisScale =" + scalefactorminor );
//System.out.println( "minorAxisValue =" + scaledvalueminor );
assert (gds.minorAxis == gpv.getMinorAxis());
} else if (gds.shape == 4) {
assert (gds.majorAxis == gpv.getMajorAxis());
assert (gds.minorAxis == gpv.getMinorAxis());
} else if (gds.shape == 6) {
assert (gds.earthRadius == gpv.getEarthRadius());
}
}
// This is a quasi-regular grid, save the number of pts in each parallel
if (gds.olon != 0) {
//System.out.println( "olon ="+ olon +" iolon ="+ iolon );
int numPts;
if ((gds.scanMode & 32) == 0) {
numPts = gds.ny;
} else {
numPts = gds.nx;
}
gds.olonPts = new int[numPts];
//int count = 0;
gds.maxPts = 0;
if (gds.olon == 1) {
for (int ii = 0; i < numPts; i++) {
gds.olonPts[ii] = raf.read();
if (gds.maxPts < gds.olonPts[ii]) {
gds.maxPts = gds.olonPts[ii];
}
//count += olonPts[ i ];
//System.out.println( "parallel =" + i +" number pts ="+ latPts );
}
} else if (gds.olon == 2) {
for (int ii = 0; i < numPts; i++) {
gds.olonPts[ii] = raf.readUnsignedShort();
if (gds.maxPts < gds.olonPts[ii]) {
gds.maxPts = gds.olonPts[ii];
}
//count += olonPts[ i ];
//System.out.println( "parallel =" + i +" number pts ="+ latPts );
}
}
if ((gds.scanMode & 32) == 0) {
gds.nx = gds.maxPts;
} else {
gds.ny = gds.maxPts;
}
//double lodiff = gds.getLo2() - gds.getLo1();
gds.dx = (float) (gds.lo2 - gds.lo1) / (gds.nx - 0);
//System.out.println( "total number pts ="+ count );
}
assert (gds.gdskey == gpv.getGdsKey());
gds = null;
}
products = null;
}