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

Grib2 template 4.60 #1192

Merged
merged 4 commits into from
Jun 7, 2023
Merged
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
5 changes: 3 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,8 @@ 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 +194,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
18 changes: 16 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,16 @@
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, ensMember, 0);
}

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

public int getCode() {
Expand All @@ -23,9 +29,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 +53,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