Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Grib2 template 4.60 #1164

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ else if (isRegular)
for (int i = 0; i < pc.getValuesCount(); i++) {
double val1 = pc.getValues(i);
double val2 = pc.getBound(i);
ecoords.add(new EnsCoordValue((int) val1, (int) val2));
ecoords.add(new EnsCoordValue((int) val1, (int) val2, i + 1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sort of a dummy coord, isn't it? Can we just leave out the i+1? Other than that I think this all looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is sort of a dummy coord. i + 1 was used because no better choice on my side.

}
return new CoordinateEns(code, ecoords);
}
Expand Down
4 changes: 2 additions & 2 deletions grib/src/main/java/ucar/nc2/grib/coord/CoordinateEns.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public Builder2(int code) {
public Object extract(Grib2Record gr) {
Grib2Pds pds = gr.getPDS();
Grib2Pds.PdsEnsemble pdse = (Grib2Pds.PdsEnsemble) pds;
return new EnsCoordValue(pdse.getPerturbationType(), pdse.getPerturbationNumber());
return new EnsCoordValue(pdse.getPerturbationType(), pdse.getPerturbationNumber(), pdse.getNumberEnsembleForecasts());
}

@Override
Expand All @@ -193,7 +193,7 @@ public Builder1(Grib1Customizer cust, int code) {
@Override
public Object extract(Grib1Record gr) {
Grib1SectionProductDefinition pds = gr.getPDSsection();
return new EnsCoordValue(pds.getPerturbationType(), pds.getPerturbationNumber());
return new EnsCoordValue(pds.getPerturbationType(), pds.getPerturbationNumber(), pds.getCenter());
}

@Override
Expand Down
20 changes: 18 additions & 2 deletions grib/src/main/java/ucar/nc2/grib/coord/EnsCoordValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@
public class EnsCoordValue implements Comparable<EnsCoordValue> {
private final int code;
private final int ensMember;
private final int ensNumber;

public EnsCoordValue(int code, int ensMember) {
this.code = code;
this.ensMember = ensMember;
this.ensNumber = 0;
}

public EnsCoordValue(int code, int ensMember, int ensNumber) {
haileyajohnson marked this conversation as resolved.
Show resolved Hide resolved
this.code = code;
this.ensMember = ensMember;
this.ensNumber = ensNumber;
}

public int getCode() {
Expand All @@ -23,9 +31,16 @@ public int getEnsMember() {
return ensMember;
}

public int getEnsNumber() {
return ensNumber;
}

@Override
public int compareTo(@Nonnull EnsCoordValue o) {
int r = Integer.compare(code, o.code);
if (r != 0)
return r;
r = Integer.compare(ensNumber, o.ensNumber);
if (r != 0)
return r;
return Integer.compare(ensMember, o.ensMember);
Expand All @@ -40,20 +55,21 @@ public boolean equals(Object o) {
return false;
}
EnsCoordValue that = (EnsCoordValue) o;
return code == that.code && ensMember == that.ensMember;
return code == that.code && ensMember == that.ensMember && ensNumber == that.ensNumber;
}

@Override
public int hashCode() {
int result = 17;
result += 31 * ensMember;
result += 31 * code;
result += 31 * ensNumber;
return result;
}

public String toString() {
try (Formatter out = new Formatter()) {
out.format("(%d %d)", code, ensMember);
out.format("(%d %d %d)", code, ensMember, ensNumber);
return out.toString();
}
}
Expand Down
31 changes: 31 additions & 0 deletions grib/src/main/java/ucar/nc2/grib/grib2/Grib2Pds.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public static Grib2Pds factory(int template, byte[] input) {
return new Grib2Pds32(input);
case 48:
return new Grib2Pds48(input);
case 60:
return new Grib2Pds60(input);
case 61:
return new Grib2Pds61(input);
default:
Expand Down Expand Up @@ -665,6 +667,35 @@ public void show(Formatter f) {

//////////////////////////////////////////////////////////////////////////////////////////////

/**
* Product definition template 4.60 -
* individual ensemble reforecast, control and perturbed, at a horizontal level or in a horizontal layer at a point
* in time
*/
private static class Grib2Pds60 extends Grib2Pds1 implements PdsEnsemble {

Grib2Pds60(byte[] input) {
super(input);
}

/**
* Model version date
*
* @return Model version date
*/
public CalendarDate getModelVersionDate() {
return calcTime(38);
}

@Override
public int templateLength() {
return 44;
}

}

//////////////////////////////////////////////////////////////////////////////////////////////

/**
* Product definition template 4.61 -
* individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer in a continuous
Expand Down