Skip to content

Commit 2d214b7

Browse files
authored
Merge pull request #1423 from lesserwhirls/bufr
Remove duplication of global metadata creation for BUFR
2 parents aaa267a + 0ae9b18 commit 2d214b7

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

bufr/src/main/java/ucar/nc2/iosp/bufr/BufrIospBuilder.java

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,11 @@ class BufrIospBuilder {
4242

4343
// global Attributes
4444
AttributeContainerMutable atts = root.getAttributeContainer();
45-
atts.addAttribute(CDM.HISTORY, "Read using CDM BufrIosp2");
45+
addCommonGlobalAttributes(atts, proto, location);
46+
4647
if (bufrConfig.getFeatureType() != null) {
4748
atts.addAttribute(CF.FEATURE_TYPE, bufrConfig.getFeatureType().toString());
4849
}
49-
atts.addAttribute("location", location);
50-
51-
atts.addAttribute("BUFR:categoryName", proto.getLookup().getCategoryName());
52-
atts.addAttribute("BUFR:subCategoryName", proto.getLookup().getSubCategoryName());
53-
atts.addAttribute("BUFR:centerName", proto.getLookup().getCenterName());
54-
atts.addAttribute("BUFR:category", proto.ids.getCategory());
55-
atts.addAttribute("BUFR:subCategory", proto.ids.getSubCategory());
56-
atts.addAttribute("BUFR:localSubCategory", proto.ids.getLocalSubCategory());
57-
atts.addAttribute(BufrIosp2.centerId, proto.ids.getCenterId());
58-
atts.addAttribute("BUFR:subCenter", proto.ids.getSubCenterId());
59-
atts.addAttribute("BUFR:table", proto.ids.getMasterTableId());
60-
atts.addAttribute("BUFR:tableVersion", proto.ids.getMasterTableVersion());
61-
atts.addAttribute("BUFR:localTableVersion", proto.ids.getLocalTableVersion());
62-
atts.addAttribute("Conventions", "BUFR/CDM");
63-
atts.addAttribute("BUFR:edition", proto.is.getBufrEdition());
64-
6550

6651
String header = proto.getHeader();
6752
if (header != null && !header.isEmpty()) {
@@ -80,12 +65,30 @@ class BufrIospBuilder {
8065

8166
// global Attributes
8267
AttributeContainerMutable atts = root.getAttributeContainer();
68+
addCommonGlobalAttributes(atts, proto, location);
69+
70+
for (BufrConfig bufrConfig : bufrConfigs) {
71+
String varName = proto.getLookup().getCategoryName(bufrConfig.getMessage().ids.getCategory());
72+
Sequence.Builder rs = Sequence.builder().setName(varName);
73+
this.rootGroup.addVariable(rs);
74+
makeObsRecord(bufrConfig, rs);
75+
String coordS = coordinates.toString();
76+
if (!coordS.isEmpty()) {
77+
rs.addAttribute(new Attribute("coordinates", coordS));
78+
}
79+
}
80+
}
81+
82+
private void addCommonGlobalAttributes(AttributeContainerMutable atts, Message proto, String location) {
8383
atts.addAttribute(CDM.HISTORY, "Read using CDM BufrIosp2");
8484
atts.addAttribute("location", location);
8585

8686
atts.addAttribute("BUFR:categoryName", proto.getLookup().getCategoryName());
8787
atts.addAttribute("BUFR:subCategoryName", proto.getLookup().getSubCategoryName());
8888
atts.addAttribute("BUFR:centerName", proto.getLookup().getCenterName());
89+
atts.addAttribute("BUFR:category", proto.ids.getCategory());
90+
atts.addAttribute("BUFR:subCategory", proto.ids.getSubCategory());
91+
atts.addAttribute("BUFR:localSubCategory", proto.ids.getLocalSubCategory());
8992
atts.addAttribute(BufrIosp2.centerId, proto.ids.getCenterId());
9093
atts.addAttribute("BUFR:subCenter", proto.ids.getSubCenterId());
9194
atts.addAttribute("BUFR:table", proto.ids.getMasterTableId());
@@ -98,17 +101,6 @@ class BufrIospBuilder {
98101
if (header != null && !header.isEmpty()) {
99102
atts.addAttribute("WMO Header", header);
100103
}
101-
102-
for (BufrConfig bufrConfig : bufrConfigs) {
103-
String varName = proto.getLookup().getCategoryName(bufrConfig.getMessage().ids.getCategory());
104-
Sequence.Builder rs = Sequence.builder().setName(varName);
105-
this.rootGroup.addVariable(rs);
106-
makeObsRecord(bufrConfig, rs);
107-
String coordS = coordinates.toString();
108-
if (!coordS.isEmpty()) {
109-
rs.addAttribute(new Attribute("coordinates", coordS));
110-
}
111-
}
112104
}
113105

114106
Sequence.Builder getObsStructure() {

cdm/gcdm/src/test/java/ucar/gcdm/TestGcdmNetcdfFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static List<Object[]> getTestParameters() {
3636
pathname -> pathname.getName().endsWith("nc") && !pathname.getName().startsWith("test_vlen3")
3737
&& !pathname.getName().startsWith("test_vlen4") && !pathname.getName().startsWith("test_vlen5")
3838
&& !pathname.getName().startsWith("test_vlen9") && !pathname.getName().startsWith("test_vlen10");
39-
String skipStructuresWithVlens2 = "vlen/IntTimSciSamp.nc vlen/cdm_sea_soundings.nc4";
39+
String skipStructuresWithVlens2 = "vlen/IntTimSciSamp.nc vlen/cdm_sea_soundings.nc4 2024060100_GTS_sn.0001.bufr";
4040

4141
TestDir.actOnAllParameterized("../../dap4/src/test/data/resources/nctestfiles/", skipStructuresWithVlens, result,
4242
false);

0 commit comments

Comments
 (0)