Skip to content

Commit

Permalink
Merge pull request #1192 from haileyajohnson/grib2-template-4.60
Browse files Browse the repository at this point in the history
Grib2 template 4.60
  • Loading branch information
tdrwenski authored Jun 7, 2023
2 parents cb4a056 + 72fca80 commit 4f08d33
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
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

0 comments on commit 4f08d33

Please sign in to comment.