34
34
35
35
package ucar .nc2 .iosp .nexrad2 ;
36
36
37
+ import java .util .ArrayList ;
38
+ import java .util .List ;
37
39
import ucar .unidata .io .RandomAccessFile ;
38
40
import ucar .ma2 .IndexIterator ;
39
41
import ucar .ma2 .Range ;
@@ -541,6 +543,10 @@ static public java.util.Date getDate(int julianDays, int msecs) {
541
543
short phiHR_first_gate = 0 ;
542
544
short rhoHR_first_gate = 0 ;
543
545
546
+ byte reflectHR_data_word_size , velocityHR_data_word_size , spectrumHR_data_word_size ;
547
+ byte zdrHR_data_word_size , phiHR_data_word_size , rhoHR_data_word_size ;
548
+
549
+ private static List <String > missingProductWarned = new ArrayList <>();
544
550
545
551
public static Level2Record factory (RandomAccessFile din , int record , long message_offset31 ) throws IOException {
546
552
long offset = record * RADAR_DATA_SIZE + FILE_HEADER_SIZE + message_offset31 ;
@@ -639,6 +645,10 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
639
645
int dbpp8 = 0 ;
640
646
int dbpp9 = 0 ;
641
647
648
+ int missingPointerNumber = -999 ;
649
+ int missingPointerValue = -999 ;
650
+ String missingName = "" ;
651
+
642
652
if (dbp4 > 0 ) {
643
653
String tname = getDataBlockStringValue (din , (short ) dbp4 , 1 , 3 );
644
654
if (tname .startsWith ("REF" )) {
@@ -660,7 +670,9 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
660
670
hasHighResRHOData = true ;
661
671
dbpp9 = dbp4 ;
662
672
} else {
663
- logger .warn ("Missing radial product dbp4={} tname={}" , dbp4 , tname );
673
+ missingName = tname ;
674
+ missingPointerNumber = 4 ;
675
+ missingPointerValue = dbp4 ;
664
676
}
665
677
666
678
}
@@ -686,7 +698,9 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
686
698
hasHighResRHOData = true ;
687
699
dbpp9 = dbp5 ;
688
700
} else {
689
- logger .warn ("Missing radial product dbp5={} tname={}" , dbp5 , tname );
701
+ missingName = tname ;
702
+ missingPointerNumber = 5 ;
703
+ missingPointerValue = dbp5 ;
690
704
}
691
705
}
692
706
if (dbp6 > 0 ) {
@@ -711,7 +725,9 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
711
725
hasHighResRHOData = true ;
712
726
dbpp9 = dbp6 ;
713
727
} else {
714
- logger .warn ("Missing radial product dbp6={} tname={}" , dbp6 , tname );
728
+ missingName = tname ;
729
+ missingPointerNumber = 6 ;
730
+ missingPointerValue = dbp6 ;
715
731
}
716
732
}
717
733
@@ -737,7 +753,9 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
737
753
hasHighResRHOData = true ;
738
754
dbpp9 = dbp7 ;
739
755
} else {
740
- logger .warn ("Missing radial product dbp7={} tname={}" , dbp7 , tname );
756
+ missingName = tname ;
757
+ missingPointerNumber = 7 ;
758
+ missingPointerValue = dbp7 ;
741
759
}
742
760
}
743
761
@@ -763,7 +781,9 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
763
781
hasHighResRHOData = true ;
764
782
dbpp9 = dbp8 ;
765
783
} else {
766
- logger .warn ("Missing radial product dbp8={} tname={}" , dbp8 , tname );
784
+ missingName = tname ;
785
+ missingPointerNumber = 8 ;
786
+ missingPointerValue = dbp8 ;
767
787
}
768
788
}
769
789
@@ -789,17 +809,31 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
789
809
hasHighResRHOData = true ;
790
810
dbpp9 = dbp9 ;
791
811
} else {
792
- logger .warn ("Missing radial product dbp9={} tname={}" , dbp9 , tname );
812
+ missingName = tname ;
813
+ missingPointerNumber = 9 ;
814
+ missingPointerValue = dbp9 ;
815
+ }
816
+ }
817
+
818
+ if (missingPointerNumber != -999 ) {
819
+ // warn once per type per pointer location
820
+ String missingKey = String .format ("%s%d" , missingName , missingPointerNumber );
821
+ if (!missingProductWarned .contains (missingKey )) {
822
+ String msg = String .format ("Unknown radial product dbp%d=%d tname=%s "
823
+ + "(this is the only message you will see about this.)" , missingPointerNumber , missingPointerValue ,
824
+ missingName );
825
+ logger .warn (msg );
826
+ missingProductWarned .add (missingKey );
793
827
}
794
828
}
795
- //hasHighResREFData = (dbp4 > 0);
796
829
797
830
if (hasHighResREFData ) {
798
831
reflectHR_gate_count = getDataBlockValue (din , (short ) dbpp4 , 8 );
799
832
reflectHR_first_gate = getDataBlockValue (din , (short ) dbpp4 , 10 );
800
833
reflectHR_gate_size = getDataBlockValue (din , (short ) dbpp4 , 12 );
801
834
ref_rf_threshold = getDataBlockValue (din , (short ) dbpp4 , 14 );
802
835
ref_snr_threshold = getDataBlockValue (din , (short ) dbpp4 , 16 );
836
+ reflectHR_data_word_size = getDataBlockByte (din , (short ) dbpp4 , 19 );
803
837
reflectHR_scale = getDataBlockValue1 (din , (short ) dbpp4 , 20 );
804
838
reflectHR_addoffset = getDataBlockValue1 (din , (short ) dbpp4 , 24 );
805
839
reflectHR_offset = (short ) (dbpp4 + 28 );
@@ -812,6 +846,7 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
812
846
velocityHR_gate_size = getDataBlockValue (din , (short ) dbpp5 , 12 );
813
847
vel_rf_threshold = getDataBlockValue (din , (short ) dbpp5 , 14 );
814
848
vel_snr_threshold = getDataBlockValue (din , (short ) dbpp5 , 16 );
849
+ velocityHR_data_word_size = getDataBlockByte (din , (short ) dbpp5 , 19 );
815
850
velocityHR_scale = getDataBlockValue1 (din , (short ) dbpp5 , 20 );
816
851
velocityHR_addoffset = getDataBlockValue1 (din , (short ) dbpp5 , 24 );
817
852
velocityHR_offset = (short ) (dbpp5 + 28 );
@@ -824,6 +859,7 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
824
859
spectrumHR_gate_size = getDataBlockValue (din , (short ) dbpp6 , 12 );
825
860
sw_rf_threshold = getDataBlockValue (din , (short ) dbpp6 , 14 );
826
861
sw_snr_threshold = getDataBlockValue (din , (short ) dbpp6 , 16 );
862
+ spectrumHR_data_word_size = getDataBlockByte (din , (short ) dbpp6 , 19 );
827
863
spectrumHR_scale = getDataBlockValue1 (din , (short ) dbpp6 , 20 );
828
864
spectrumHR_addoffset = getDataBlockValue1 (din , (short ) dbpp6 , 24 );
829
865
spectrumHR_offset = (short ) (dbpp6 + 28 );
@@ -836,6 +872,7 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
836
872
zdrHR_gate_size = getDataBlockValue (din , (short ) dbpp7 , 12 );
837
873
zdrHR_rf_threshold = getDataBlockValue (din , (short ) dbpp7 , 14 );
838
874
zdrHR_snr_threshold = getDataBlockValue (din , (short ) dbpp7 , 16 );
875
+ zdrHR_data_word_size = getDataBlockByte (din , (short ) dbpp7 , 19 );
839
876
zdrHR_scale = getDataBlockValue1 (din , (short ) dbpp7 , 20 );
840
877
zdrHR_addoffset = getDataBlockValue1 (din , (short ) dbpp7 , 24 );
841
878
zdrHR_offset = (short ) (dbpp7 + 28 );
@@ -847,6 +884,7 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
847
884
phiHR_gate_size = getDataBlockValue (din , (short ) dbpp8 , 12 );
848
885
phiHR_rf_threshold = getDataBlockValue (din , (short ) dbpp8 , 14 );
849
886
phiHR_snr_threshold = getDataBlockValue (din , (short ) dbpp8 , 16 );
887
+ phiHR_data_word_size = getDataBlockByte (din , (short ) dbpp8 , 19 );
850
888
phiHR_scale = getDataBlockValue1 (din , (short ) dbpp8 , 20 );
851
889
phiHR_addoffset = getDataBlockValue1 (din , (short ) dbpp8 , 24 );
852
890
phiHR_offset = (short ) (dbpp8 + 28 );
@@ -858,6 +896,7 @@ public Level2Record(RandomAccessFile din, int record, long message_offset31) thr
858
896
rhoHR_gate_size = getDataBlockValue (din , (short ) dbpp9 , 12 );
859
897
rhoHR_rf_threshold = getDataBlockValue (din , (short ) dbpp9 , 14 );
860
898
rhoHR_snr_threshold = getDataBlockValue (din , (short ) dbpp9 , 16 );
899
+ rhoHR_data_word_size = getDataBlockByte (din , (short ) dbpp9 , 19 );
861
900
rhoHR_scale = getDataBlockValue1 (din , (short ) dbpp9 , 20 );
862
901
rhoHR_addoffset = getDataBlockValue1 (din , (short ) dbpp9 , 24 );
863
902
rhoHR_offset = (short ) (dbpp9 + 28 );
@@ -1101,6 +1140,24 @@ private short getDataOffset(int datatype) {
1101
1140
return Short .MIN_VALUE ;
1102
1141
}
1103
1142
1143
+ byte getDataWordSize (int datatype ) {
1144
+ switch (datatype ) {
1145
+ case REFLECTIVITY_HIGH :
1146
+ return reflectHR_data_word_size ;
1147
+ case VELOCITY_HIGH :
1148
+ return velocityHR_data_word_size ;
1149
+ case SPECTRUM_WIDTH_HIGH :
1150
+ return spectrumHR_data_word_size ;
1151
+ case DIFF_REFLECTIVITY_HIGH :
1152
+ return zdrHR_data_word_size ;
1153
+ case DIFF_PHASE :
1154
+ return phiHR_data_word_size ;
1155
+ case CORRELATION_COEFFICIENT :
1156
+ return rhoHR_data_word_size ;
1157
+ }
1158
+ return 8 ;
1159
+ }
1160
+
1104
1161
private short getDataBlockValue (RandomAccessFile raf , short offset , int skip ) throws IOException {
1105
1162
long off = offset + message_offset + MESSAGE_HEADER_SIZE ;
1106
1163
raf .seek (off );
@@ -1122,6 +1179,13 @@ private float getDataBlockValue1(RandomAccessFile raf, short offset, int skip) t
1122
1179
return raf .readFloat ();
1123
1180
}
1124
1181
1182
+ private byte getDataBlockByte (RandomAccessFile raf , short offset , int skip ) throws IOException {
1183
+ long off = offset + message_offset + MESSAGE_HEADER_SIZE ;
1184
+ raf .seek (off );
1185
+ raf .skipBytes (skip );
1186
+ return raf .readByte ();
1187
+ }
1188
+
1125
1189
public java .util .Date getDate () {
1126
1190
return getDate (data_julian_date , data_msecs );
1127
1191
}
@@ -1146,7 +1210,9 @@ public void readData(RandomAccessFile raf, int datatype, Range gateRange, IndexI
1146
1210
}
1147
1211
1148
1212
int dataCount = getGateCount (datatype );
1149
- if (datatype == DIFF_PHASE ) {
1213
+ byte wordSize = getDataWordSize (datatype );
1214
+
1215
+ if (wordSize == 16 ) {
1150
1216
short [] data = new short [dataCount ];
1151
1217
raf .readShort (data , 0 , dataCount );
1152
1218
@@ -1156,7 +1222,7 @@ public void readData(RandomAccessFile raf, int datatype, Range gateRange, IndexI
1156
1222
else
1157
1223
ii .setShortNext (data [i ]);
1158
1224
}
1159
- } else {
1225
+ } else if ( wordSize == 8 ) {
1160
1226
byte [] data = new byte [dataCount ];
1161
1227
raf .readFully (data );
1162
1228
//short [] ds = convertunsignedByte2Short(data);
@@ -1166,7 +1232,10 @@ public void readData(RandomAccessFile raf, int datatype, Range gateRange, IndexI
1166
1232
else
1167
1233
ii .setByteNext (data [i ]);
1168
1234
}
1169
-
1235
+ } else {
1236
+ String message = String .format ("Data word size of %d bits not understood for data type %d (%s)." , wordSize ,
1237
+ datatype , getDatatypeName (datatype ));
1238
+ throw new IOException (message );
1170
1239
}
1171
1240
}
1172
1241
0 commit comments