@@ -80,6 +80,46 @@ class Construct2 {
8080 ncfile .finish ();
8181 }
8282
83+ Construct2 (Message proto , List <BufrConfig > bufrConfigs , ucar .nc2 .NetcdfFile nc ) throws IOException {
84+ this .ncfile = nc ;
85+
86+ // global Attributes
87+ ncfile .addAttribute (null , new Attribute (CDM .HISTORY , "Read using CDM BufrIosp2" ));
88+ ncfile .addAttribute (null , "location" , nc .getLocation ());
89+
90+ ncfile .addAttribute (null , "BUFR:categoryName" , proto .getLookup ().getCategoryName ());
91+ ncfile .addAttribute (null , "BUFR:subCategoryName" , proto .getLookup ().getSubCategoryName ());
92+ ncfile .addAttribute (null , "BUFR:centerName" , proto .getLookup ().getCenterName ());
93+ ncfile .addAttribute (null , new Attribute ("BUFR:category" , proto .ids .getCategory ()));
94+ ncfile .addAttribute (null , new Attribute ("BUFR:subCategory" , proto .ids .getSubCategory ()));
95+ ncfile .addAttribute (null , new Attribute ("BUFR:localSubCategory" , proto .ids .getLocalSubCategory ()));
96+ ncfile .addAttribute (null , new Attribute (BufrIosp2 .centerId , proto .ids .getCenterId ()));
97+ ncfile .addAttribute (null , new Attribute ("BUFR:subCenter" , proto .ids .getSubCenterId ()));
98+ // ncfile.addAttribute(null, "BUFR:tableName", proto.ids.getMasterTableFilename()));
99+ ncfile .addAttribute (null , new Attribute ("BUFR:table" , proto .ids .getMasterTableId ()));
100+ ncfile .addAttribute (null , new Attribute ("BUFR:tableVersion" , proto .ids .getMasterTableVersion ()));
101+ ncfile .addAttribute (null , new Attribute ("BUFR:localTableVersion" , proto .ids .getLocalTableVersion ()));
102+ ncfile .addAttribute (null , "Conventions" , "BUFR/CDM" );
103+ ncfile .addAttribute (null , new Attribute ("BUFR:edition" , proto .is .getBufrEdition ()));
104+
105+ centerId = proto .ids .getCenterId ();
106+
107+ String header = proto .getHeader ();
108+ if (header != null && !header .isEmpty ())
109+ ncfile .addAttribute (null , new Attribute ("WMO Header" , header ));
110+
111+ for (BufrConfig bufrConfig : bufrConfigs ) {
112+ String varName = proto .getLookup ().getCategoryName (bufrConfig .getMessage ().ids .getCategory ());
113+ Sequence rs = new Sequence (ncfile , null , null , varName );
114+ makeObsRecord (bufrConfig , rs );
115+ String coordS = coordinates .toString ();
116+ if (!coordS .isEmpty ())
117+ rs .addAttribute (new Attribute ("coordinates" , coordS ));
118+ }
119+
120+ ncfile .finish ();
121+ }
122+
83123 Sequence getObsStructure () {
84124 return recordStructure ;
85125 }
@@ -124,6 +164,45 @@ private void makeObsRecord(BufrConfig bufrConfig) {
124164 }
125165 }
126166
167+ private void makeObsRecord (BufrConfig bufrConfig , Sequence rs ) {
168+ ncfile .addVariable (null , rs );
169+
170+ BufrConfig .FieldConverter root = bufrConfig .getRootConverter ();
171+ for (BufrConfig .FieldConverter fld : root .flds ) {
172+ DataDescriptor dkey = fld .dds ;
173+ if (!dkey .isOkForVariable ())
174+ continue ;
175+
176+ if (dkey .replication == 0 ) {
177+ addSequence (rs , fld );
178+
179+ } else if (dkey .replication > 1 ) {
180+
181+ List <BufrConfig .FieldConverter > subFlds = fld .flds ;
182+ List <DataDescriptor > subKeys = dkey .subKeys ;
183+ if (subKeys .size () == 1 ) { // only one member
184+ DataDescriptor subDds = dkey .subKeys .get (0 );
185+ BufrConfig .FieldConverter subFld = subFlds .get (0 );
186+ if (subDds .dpi != null ) {
187+ addDpiStructure (rs , fld , subFld );
188+
189+ } else if (subDds .replication == 1 ) { // one member not a replication
190+ Variable v = addVariable (rs , subFld , dkey .replication );
191+ v .setSPobject (fld ); // set the replicating field as SPI object
192+
193+ } else { // one member is a replication (two replications in a row)
194+ addStructure (rs , fld , dkey .replication );
195+ }
196+ } else if (subKeys .size () > 1 ) {
197+ addStructure (rs , fld , dkey .replication );
198+ }
199+
200+ } else { // replication == 1
201+ addVariable (rs , fld , dkey .replication );
202+ }
203+ }
204+ }
205+
127206 private void addStructure (Structure parent , BufrConfig .FieldConverter fld , int count ) {
128207 DataDescriptor dkey = fld .dds ;
129208 String uname = findUniqueName (parent , fld .getName (), "struct" );
0 commit comments