6
6
7
7
package ucar .nc2 .iosp .nexrad2 ;
8
8
9
+ import java .util .ArrayList ;
10
+ import java .util .List ;
9
11
import ucar .unidata .io .RandomAccessFile ;
10
12
import ucar .ma2 .IndexIterator ;
11
13
import ucar .ma2 .Range ;
@@ -179,9 +181,9 @@ public static String getDatatypeUnits(int datatype) {
179
181
switch (datatype ) {
180
182
case REFLECTIVITY :
181
183
case REFLECTIVITY_HIGH :
182
- case DIFF_REFLECTIVITY_HIGH :
183
184
return "dBz" ;
184
-
185
+ case DIFF_REFLECTIVITY_HIGH :
186
+ return "dB" ;
185
187
case VELOCITY_HI :
186
188
case VELOCITY_LOW :
187
189
case SPECTRUM_WIDTH :
@@ -506,6 +508,10 @@ public static java.util.Date getDate(int julianDays, int msecs) {
506
508
short phiHR_first_gate ;
507
509
short rhoHR_first_gate ;
508
510
511
+ byte reflectHR_data_word_size , velocityHR_data_word_size , spectrumHR_data_word_size ;
512
+ byte zdrHR_data_word_size , phiHR_data_word_size , rhoHR_data_word_size ;
513
+
514
+ private static List <String > missingProductWarned = new ArrayList <>();
509
515
510
516
public static Level2Record factory (RandomAccessFile din , int record , long message_offset31 ) throws IOException {
511
517
long offset = record * RADAR_DATA_SIZE + FILE_HEADER_SIZE + message_offset31 ;
@@ -604,6 +610,10 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
604
610
int dbpp8 = 0 ;
605
611
int dbpp9 = 0 ;
606
612
613
+ int missingPointerNumber = -999 ;
614
+ int missingPointerValue = -999 ;
615
+ String missingName = "" ;
616
+
607
617
if (dbp4 > 0 ) {
608
618
String tname = getDataBlockStringValue (din , (short ) dbp4 , 1 , 3 );
609
619
if (tname .startsWith ("REF" )) {
@@ -625,7 +635,9 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
625
635
hasHighResRHOData = true ;
626
636
dbpp9 = dbp4 ;
627
637
} else {
628
- logger .warn ("Missing radial product dbp4={} tname={}" , dbp4 , tname );
638
+ missingName = tname ;
639
+ missingPointerNumber = 4 ;
640
+ missingPointerValue = dbp4 ;
629
641
}
630
642
631
643
}
@@ -651,7 +663,9 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
651
663
hasHighResRHOData = true ;
652
664
dbpp9 = dbp5 ;
653
665
} else {
654
- logger .warn ("Missing radial product dbp5={} tname={}" , dbp5 , tname );
666
+ missingName = tname ;
667
+ missingPointerNumber = 5 ;
668
+ missingPointerValue = dbp5 ;
655
669
}
656
670
}
657
671
if (dbp6 > 0 ) {
@@ -676,7 +690,9 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
676
690
hasHighResRHOData = true ;
677
691
dbpp9 = dbp6 ;
678
692
} else {
679
- logger .warn ("Missing radial product dbp6={} tname={}" , dbp6 , tname );
693
+ missingName = tname ;
694
+ missingPointerNumber = 6 ;
695
+ missingPointerValue = dbp6 ;
680
696
}
681
697
}
682
698
@@ -702,7 +718,9 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
702
718
hasHighResRHOData = true ;
703
719
dbpp9 = dbp7 ;
704
720
} else {
705
- logger .warn ("Missing radial product dbp7={} tname={}" , dbp7 , tname );
721
+ missingName = tname ;
722
+ missingPointerNumber = 7 ;
723
+ missingPointerValue = dbp7 ;
706
724
}
707
725
}
708
726
@@ -728,7 +746,9 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
728
746
hasHighResRHOData = true ;
729
747
dbpp9 = dbp8 ;
730
748
} else {
731
- logger .warn ("Missing radial product dbp8={} tname={}" , dbp8 , tname );
749
+ missingName = tname ;
750
+ missingPointerNumber = 8 ;
751
+ missingPointerValue = dbp8 ;
732
752
}
733
753
}
734
754
@@ -754,17 +774,31 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
754
774
hasHighResRHOData = true ;
755
775
dbpp9 = dbp9 ;
756
776
} else {
757
- logger .warn ("Missing radial product dbp9={} tname={}" , dbp9 , tname );
777
+ missingName = tname ;
778
+ missingPointerNumber = 9 ;
779
+ missingPointerValue = dbp9 ;
780
+ }
781
+ }
782
+
783
+ if (missingPointerNumber != -999 ) {
784
+ // warn once per type per pointer location
785
+ String missingKey = String .format ("%s%d" , missingName , missingPointerNumber );
786
+ if (!missingProductWarned .contains (missingKey )) {
787
+ String msg = String .format (
788
+ "Unknown radial product dbp%d=%d tname=%s " + "(this is the only message you will see about this.)" ,
789
+ missingPointerNumber , missingPointerValue , missingName );
790
+ logger .warn (msg );
791
+ missingProductWarned .add (missingKey );
758
792
}
759
793
}
760
- // hasHighResREFData = (dbp4 > 0);
761
794
762
795
if (hasHighResREFData ) {
763
796
reflectHR_gate_count = getDataBlockValue (din , (short ) dbpp4 , 8 );
764
797
reflectHR_first_gate = getDataBlockValue (din , (short ) dbpp4 , 10 );
765
798
reflectHR_gate_size = getDataBlockValue (din , (short ) dbpp4 , 12 );
766
799
ref_rf_threshold = getDataBlockValue (din , (short ) dbpp4 , 14 );
767
800
ref_snr_threshold = getDataBlockValue (din , (short ) dbpp4 , 16 );
801
+ reflectHR_data_word_size = getDataBlockByte (din , (short ) dbpp4 , 19 );
768
802
reflectHR_scale = getDataBlockValue1 (din , (short ) dbpp4 , 20 );
769
803
reflectHR_addoffset = getDataBlockValue1 (din , (short ) dbpp4 , 24 );
770
804
reflectHR_offset = (short ) (dbpp4 + 28 );
@@ -777,6 +811,7 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
777
811
velocityHR_gate_size = getDataBlockValue (din , (short ) dbpp5 , 12 );
778
812
vel_rf_threshold = getDataBlockValue (din , (short ) dbpp5 , 14 );
779
813
vel_snr_threshold = getDataBlockValue (din , (short ) dbpp5 , 16 );
814
+ velocityHR_data_word_size = getDataBlockByte (din , (short ) dbpp5 , 19 );
780
815
velocityHR_scale = getDataBlockValue1 (din , (short ) dbpp5 , 20 );
781
816
velocityHR_addoffset = getDataBlockValue1 (din , (short ) dbpp5 , 24 );
782
817
velocityHR_offset = (short ) (dbpp5 + 28 );
@@ -789,6 +824,7 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
789
824
spectrumHR_gate_size = getDataBlockValue (din , (short ) dbpp6 , 12 );
790
825
sw_rf_threshold = getDataBlockValue (din , (short ) dbpp6 , 14 );
791
826
sw_snr_threshold = getDataBlockValue (din , (short ) dbpp6 , 16 );
827
+ spectrumHR_data_word_size = getDataBlockByte (din , (short ) dbpp6 , 19 );
792
828
spectrumHR_scale = getDataBlockValue1 (din , (short ) dbpp6 , 20 );
793
829
spectrumHR_addoffset = getDataBlockValue1 (din , (short ) dbpp6 , 24 );
794
830
spectrumHR_offset = (short ) (dbpp6 + 28 );
@@ -801,6 +837,7 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
801
837
zdrHR_gate_size = getDataBlockValue (din , (short ) dbpp7 , 12 );
802
838
zdrHR_rf_threshold = getDataBlockValue (din , (short ) dbpp7 , 14 );
803
839
zdrHR_snr_threshold = getDataBlockValue (din , (short ) dbpp7 , 16 );
840
+ zdrHR_data_word_size = getDataBlockByte (din , (short ) dbpp7 , 19 );
804
841
zdrHR_scale = getDataBlockValue1 (din , (short ) dbpp7 , 20 );
805
842
zdrHR_addoffset = getDataBlockValue1 (din , (short ) dbpp7 , 24 );
806
843
zdrHR_offset = (short ) (dbpp7 + 28 );
@@ -812,6 +849,7 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
812
849
phiHR_gate_size = getDataBlockValue (din , (short ) dbpp8 , 12 );
813
850
phiHR_rf_threshold = getDataBlockValue (din , (short ) dbpp8 , 14 );
814
851
phiHR_snr_threshold = getDataBlockValue (din , (short ) dbpp8 , 16 );
852
+ phiHR_data_word_size = getDataBlockByte (din , (short ) dbpp8 , 19 );
815
853
phiHR_scale = getDataBlockValue1 (din , (short ) dbpp8 , 20 );
816
854
phiHR_addoffset = getDataBlockValue1 (din , (short ) dbpp8 , 24 );
817
855
phiHR_offset = (short ) (dbpp8 + 28 );
@@ -823,6 +861,7 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
823
861
rhoHR_gate_size = getDataBlockValue (din , (short ) dbpp9 , 12 );
824
862
rhoHR_rf_threshold = getDataBlockValue (din , (short ) dbpp9 , 14 );
825
863
rhoHR_snr_threshold = getDataBlockValue (din , (short ) dbpp9 , 16 );
864
+ rhoHR_data_word_size = getDataBlockByte (din , (short ) dbpp9 , 19 );
826
865
rhoHR_scale = getDataBlockValue1 (din , (short ) dbpp9 , 20 );
827
866
rhoHR_addoffset = getDataBlockValue1 (din , (short ) dbpp9 , 24 );
828
867
rhoHR_offset = (short ) (dbpp9 + 28 );
@@ -1069,6 +1108,24 @@ private short getDataOffset(int datatype) {
1069
1108
return Short .MIN_VALUE ;
1070
1109
}
1071
1110
1111
+ byte getDataWordSize (int datatype ) {
1112
+ switch (datatype ) {
1113
+ case REFLECTIVITY_HIGH :
1114
+ return reflectHR_data_word_size ;
1115
+ case VELOCITY_HIGH :
1116
+ return velocityHR_data_word_size ;
1117
+ case SPECTRUM_WIDTH_HIGH :
1118
+ return spectrumHR_data_word_size ;
1119
+ case DIFF_REFLECTIVITY_HIGH :
1120
+ return zdrHR_data_word_size ;
1121
+ case DIFF_PHASE :
1122
+ return phiHR_data_word_size ;
1123
+ case CORRELATION_COEFFICIENT :
1124
+ return rhoHR_data_word_size ;
1125
+ }
1126
+ return 8 ;
1127
+ }
1128
+
1072
1129
private short getDataBlockValue (RandomAccessFile raf , short offset , int skip ) throws IOException {
1073
1130
long off = offset + message_offset + MESSAGE_HEADER_SIZE ;
1074
1131
raf .seek (off );
@@ -1090,6 +1147,13 @@ private float getDataBlockValue1(RandomAccessFile raf, short offset, int skip) t
1090
1147
return raf .readFloat ();
1091
1148
}
1092
1149
1150
+ private byte getDataBlockByte (RandomAccessFile raf , short offset , int skip ) throws IOException {
1151
+ long off = offset + message_offset + MESSAGE_HEADER_SIZE ;
1152
+ raf .seek (off );
1153
+ raf .skipBytes (skip );
1154
+ return raf .readByte ();
1155
+ }
1156
+
1093
1157
public java .util .Date getDate () {
1094
1158
return getDate (data_julian_date , data_msecs );
1095
1159
}
@@ -1115,7 +1179,9 @@ public void readData(RandomAccessFile raf, int datatype, Range gateRange, IndexI
1115
1179
}
1116
1180
1117
1181
int dataCount = getGateCount (datatype );
1118
- if (datatype == DIFF_PHASE ) {
1182
+ byte wordSize = getDataWordSize (datatype );
1183
+
1184
+ if (wordSize == 16 ) {
1119
1185
short [] data = new short [dataCount ];
1120
1186
raf .readShort (data , 0 , dataCount );
1121
1187
@@ -1125,8 +1191,7 @@ public void readData(RandomAccessFile raf, int datatype, Range gateRange, IndexI
1125
1191
else
1126
1192
ii .setShortNext (data [gateIdx ]);
1127
1193
}
1128
- } else {
1129
-
1194
+ } else if (wordSize == 8 ) {
1130
1195
byte [] data = new byte [dataCount ];
1131
1196
raf .readFully (data );
1132
1197
// short [] ds = convertunsignedByte2Short(data);
@@ -1136,7 +1201,10 @@ public void readData(RandomAccessFile raf, int datatype, Range gateRange, IndexI
1136
1201
else
1137
1202
ii .setByteNext (data [gateIdx ]);
1138
1203
}
1139
-
1204
+ } else {
1205
+ String message = String .format ("Data word size of %i bits not understood for data type %i (%s)." , wordSize ,
1206
+ datatype , getDatatypeName (datatype ));
1207
+ throw new IOException (message );
1140
1208
}
1141
1209
}
1142
1210
0 commit comments