Dddb { public Family<MemberDescriptor> getMemberDescriptors(File hdrFile) throws IOException { final MemberDescriptors memberDescriptors = new MemberDescriptors(); final DataFormat dataFormat = getDataFormat(hdrFile); final CompoundType type = dataFormat.getType(); final Family<BandDescriptor> bandDescriptors = getBandDescriptors(dataFormat.getName()); final Map<String, BandDescriptor> uniqueMemberMap = extractUniqueMembers(bandDescriptors.asList()); extractMembers(type, memberDescriptors); final List<MemberDescriptor> memberDescriptorList = memberDescriptors.asList(); final ArrayList<MemberDescriptor> toRemoveList = new ArrayList<>(); for (MemberDescriptor memberDescriptor : memberDescriptorList) { if (!uniqueMemberMap.containsKey(memberDescriptor.getName())) { toRemoveList.add(memberDescriptor); } } for (MemberDescriptor toRemove : toRemoveList) { memberDescriptors.remove(toRemove.getName()); } final String formatName = extractFormatName(hdrFile); final Properties mappingProperties = getMappingProperties(formatName); for (final MemberDescriptor memberDescriptor : memberDescriptorList) { final String memberDescriptorName = memberDescriptor.getName(); memberDescriptor.setBinXName(memberDescriptorName); if (mappingProperties != null) { final String originalName = findOriginalName(mappingProperties, memberDescriptorName); if (originalName != null) { memberDescriptor.setName(originalName); } } final BandDescriptor bandDescriptor = uniqueMemberMap.get(memberDescriptorName); memberDescriptor.setGridPointData(bandDescriptor.isGridPointData()); memberDescriptor.setDimensionNames(bandDescriptor.getDimensionNames()); final Family<FlagDescriptor> flagDescriptors = bandDescriptor.getFlagDescriptors(); if (flagDescriptors != null) { final List<FlagDescriptor> flagDescriptorsList = flagDescriptors.asList(); final int size = flagDescriptorsList.size(); final short[] flagMasks = new short[size]; final String[] flagMeanings = new String[size]; int i = 0; for (final FlagDescriptor flagDescriptor : flagDescriptorsList) { flagMasks[i] = (short) flagDescriptor.getMask(); flagMeanings[i] = flagDescriptor.getFlagName(); ++i; } memberDescriptor.setFlagMasks(flagMasks); memberDescriptor.setFlagValues(flagMasks); memberDescriptor.setFlagMeanings(StringUtils.arrayToString(flagMeanings, " ")); } memberDescriptor.setUnit(bandDescriptor.getUnit()); memberDescriptor.setFillValue((float) bandDescriptor.getFillValue()); memberDescriptor.setScalingFactor((float) bandDescriptor.getScalingFactor()); memberDescriptor.setScalingOffset((float) bandDescriptor.getScalingOffset()); } return memberDescriptors; } private  Dddb(); static Dddb getInstance(); DataFormat getDataFormat(File hdrFile); BandDescriptor findBandDescriptorForMember(String formatName, String memberName); Family<BandDescriptor> getBandDescriptors(String formatName); Family<FlagDescriptor> getFlagDescriptors(String identifier); Family<MemberDescriptor> getMemberDescriptors(File hdrFile);  }
@Test public void testGetMemberDescriptors_BWLF1C() throws IOException { final File hdrFile = TestHelper.getResourceFile("SM_OPER_MIR_BWLF1C_20111026T143206_20111026T152520_503_001_1.HDR"); final Family<MemberDescriptor> memberDescriptors = dddb.getMemberDescriptors(hdrFile); assertNotNull(memberDescriptors); assertEquals(12, memberDescriptors.asList().size()); final MemberDescriptor flagsDescriptor = memberDescriptors.getMember("Flags"); assertNotNull(flagsDescriptor); assertTrue(flagsDescriptor.isGridPointData()); assertEquals("ushort", flagsDescriptor.getDataTypeName()); assertEquals("n_grid_points n_bt_data", flagsDescriptor.getDimensionNames()); assertEquals(0, flagsDescriptor.getMemberIndex()); final short[] flagMasks = flagsDescriptor.getFlagMasks(); assertNotNull(flagMasks); assertEquals(16, flagMasks.length); final short[] flagValues = flagsDescriptor.getFlagValues(); assertNotNull(flagValues); assertEquals(16, flagValues.length); assertEquals("POL_FLAG_1 POL_FLAG_2 SUN_FOV SUN_GLINT_FOV MOON_GLINT_FOV SINGLE_SNAPSHOT FTT SUN_POINT SUN_GLINT_AREA MOON_POINT AF_FOV EAF_FOV BORDER_FOV SUN_TAILS RFI_1 RFI_2", flagsDescriptor.getFlagMeanings()); assertEquals("", flagsDescriptor.getUnit()); assertEquals(0.0f, flagsDescriptor.getFillValue(), 1e-8); assertEquals(1.0f, flagsDescriptor.getScalingFactor(), 1e-8); assertEquals(0.0f, flagsDescriptor.getScalingOffset(), 1e-8); final MemberDescriptor btValueDescriptor = memberDescriptors.getMember("BT_Value"); assertNotNull(btValueDescriptor); assertTrue(btValueDescriptor.isGridPointData()); assertEquals("float", btValueDescriptor.getDataTypeName()); assertEquals("n_grid_points n_bt_data", btValueDescriptor.getDimensionNames()); assertEquals(1, btValueDescriptor.getMemberIndex()); assertNull(btValueDescriptor.getFlagMasks()); assertEquals("K", btValueDescriptor.getUnit()); assertEquals(-999.0f, btValueDescriptor.getFillValue(), 1e-8); assertEquals(1.0f, btValueDescriptor.getScalingFactor(), 1e-8); assertEquals(0.0f, btValueDescriptor.getScalingOffset(), 1e-8); final MemberDescriptor radiometricAccuracyOfPixelDescriptor = memberDescriptors.getMember("Radiometric_Accuracy_of_Pixel"); assertNotNull(radiometricAccuracyOfPixelDescriptor); assertTrue(radiometricAccuracyOfPixelDescriptor.isGridPointData()); assertEquals("ushort", radiometricAccuracyOfPixelDescriptor.getDataTypeName()); assertEquals("n_grid_points n_bt_data", radiometricAccuracyOfPixelDescriptor.getDimensionNames()); assertEquals(2, radiometricAccuracyOfPixelDescriptor.getMemberIndex()); assertNull(radiometricAccuracyOfPixelDescriptor.getFlagValues()); assertEquals("K", radiometricAccuracyOfPixelDescriptor.getUnit()); assertEquals(0.0f, radiometricAccuracyOfPixelDescriptor.getFillValue(), 1e-8); assertEquals(1.52587890625E-5f, radiometricAccuracyOfPixelDescriptor.getScalingFactor(), 1e-8); assertEquals(0.0f, radiometricAccuracyOfPixelDescriptor.getScalingOffset(), 1e-8); final MemberDescriptor azimuthAngleDescriptor = memberDescriptors.getMember("Azimuth_Angle"); assertNotNull(azimuthAngleDescriptor); assertTrue(azimuthAngleDescriptor.isGridPointData()); assertEquals("ushort", azimuthAngleDescriptor.getDataTypeName()); assertEquals("n_grid_points n_bt_data", azimuthAngleDescriptor.getDimensionNames()); assertEquals(3, azimuthAngleDescriptor.getMemberIndex()); assertEquals("deg", azimuthAngleDescriptor.getUnit()); assertEquals(0.0f, azimuthAngleDescriptor.getFillValue(), 1e-8); assertEquals(0.0054931640625f, azimuthAngleDescriptor.getScalingFactor(), 1e-8); assertEquals(0.0f, azimuthAngleDescriptor.getScalingOffset(), 1e-8); final MemberDescriptor footprintAxis1Descriptor = memberDescriptors.getMember("Footprint_Axis1"); assertNotNull(footprintAxis1Descriptor); assertTrue(footprintAxis1Descriptor.isGridPointData()); assertEquals("ushort", footprintAxis1Descriptor.getDataTypeName()); assertEquals("n_grid_points n_bt_data", footprintAxis1Descriptor.getDimensionNames()); assertEquals(4, footprintAxis1Descriptor.getMemberIndex()); assertEquals("km", footprintAxis1Descriptor.getUnit()); assertEquals(0.0f, footprintAxis1Descriptor.getFillValue(), 1e-8); assertEquals(1.52587890625E-5f, footprintAxis1Descriptor.getScalingFactor(), 1e-8); assertEquals(0.0f, footprintAxis1Descriptor.getScalingOffset(), 1e-8); final MemberDescriptor footprintAxis2Descriptor = memberDescriptors.getMember("Footprint_Axis2"); assertNotNull(footprintAxis2Descriptor); assertTrue(footprintAxis2Descriptor.isGridPointData()); assertEquals("ushort", footprintAxis2Descriptor.getDataTypeName()); assertEquals("n_grid_points n_bt_data", footprintAxis2Descriptor.getDimensionNames()); assertEquals(5, footprintAxis2Descriptor.getMemberIndex()); assertEquals("km", footprintAxis2Descriptor.getUnit()); assertEquals(0.0f, footprintAxis2Descriptor.getFillValue(), 1e-8); assertEquals(1.52587890625E-5f, footprintAxis2Descriptor.getScalingFactor(), 1e-8); assertEquals(0.0f, footprintAxis2Descriptor.getScalingOffset(), 1e-8); final MemberDescriptor gridPointIdDescriptor = memberDescriptors.getMember("Grid_Point_ID"); assertNotNull(gridPointIdDescriptor); assertTrue(gridPointIdDescriptor.isGridPointData()); assertEquals("uint", gridPointIdDescriptor.getDataTypeName()); assertEquals("n_grid_points", gridPointIdDescriptor.getDimensionNames()); assertEquals(0, gridPointIdDescriptor.getMemberIndex()); assertEquals("", gridPointIdDescriptor.getUnit()); assertEquals(Float.NaN, gridPointIdDescriptor.getFillValue(), 1e-8); assertEquals(1.0f, gridPointIdDescriptor.getScalingFactor(), 1e-8); assertEquals(0.0f, gridPointIdDescriptor.getScalingOffset(), 1e-8); final MemberDescriptor latitudeDescriptor = memberDescriptors.getMember("Grid_Point_Latitude"); assertNotNull(latitudeDescriptor); assertEquals("Latitude", latitudeDescriptor.getBinXName()); assertTrue(latitudeDescriptor.isGridPointData()); assertEquals("float", latitudeDescriptor.getDataTypeName()); assertEquals("n_grid_points", latitudeDescriptor.getDimensionNames()); assertEquals(1, latitudeDescriptor.getMemberIndex()); assertEquals("deg", latitudeDescriptor.getUnit()); assertEquals(Float.NaN, latitudeDescriptor.getFillValue(), 1e-8); assertEquals(1.0f, latitudeDescriptor.getScalingFactor(), 1e-8); assertEquals(0.0f, latitudeDescriptor.getScalingOffset(), 1e-8); final MemberDescriptor longitudeDescriptor = memberDescriptors.getMember("Grid_Point_Longitude"); assertNotNull(longitudeDescriptor); assertEquals("Longitude", longitudeDescriptor.getBinXName()); assertTrue(longitudeDescriptor.isGridPointData()); assertEquals("float", longitudeDescriptor.getDataTypeName()); assertEquals("n_grid_points", longitudeDescriptor.getDimensionNames()); assertEquals(2, longitudeDescriptor.getMemberIndex()); assertEquals("deg", longitudeDescriptor.getUnit()); assertEquals(Float.NaN, longitudeDescriptor.getFillValue(), 1e-8); assertEquals(1.0f, longitudeDescriptor.getScalingFactor(), 1e-8); assertEquals(0.0f, longitudeDescriptor.getScalingOffset(), 1e-8); final MemberDescriptor altitudeDescriptor = memberDescriptors.getMember("Grid_Point_Altitude"); assertNotNull(altitudeDescriptor); assertEquals("Altitude", altitudeDescriptor.getBinXName()); assertTrue(altitudeDescriptor.isGridPointData()); assertEquals("float", altitudeDescriptor.getDataTypeName()); assertEquals("n_grid_points", altitudeDescriptor.getDimensionNames()); assertEquals(3, altitudeDescriptor.getMemberIndex()); assertEquals("m", altitudeDescriptor.getUnit()); assertEquals(Float.NaN, altitudeDescriptor.getFillValue(), 1e-8); assertEquals(1.0f, altitudeDescriptor.getScalingFactor(), 1e-8); assertEquals(0.0f, altitudeDescriptor.getScalingOffset(), 1e-8); final MemberDescriptor maskDescriptor = memberDescriptors.getMember("Grid_Point_Mask"); assertNotNull(maskDescriptor); assertTrue(maskDescriptor.isGridPointData()); assertEquals("ubyte", maskDescriptor.getDataTypeName()); assertEquals("n_grid_points", maskDescriptor.getDimensionNames()); assertEquals(4, maskDescriptor.getMemberIndex()); assertEquals("", maskDescriptor.getUnit()); assertEquals(Float.NaN, maskDescriptor.getFillValue(), 1e-8); assertEquals(1.0f, maskDescriptor.getScalingFactor(), 1e-8); assertEquals(0.0f, maskDescriptor.getScalingOffset(), 1e-8); final MemberDescriptor btCountDescriptor = memberDescriptors.getMember("BT_Data_Counter"); assertNotNull(btCountDescriptor); assertTrue(btCountDescriptor.isGridPointData()); assertEquals("ubyte", btCountDescriptor.getDataTypeName()); assertEquals("n_grid_points", btCountDescriptor.getDimensionNames()); assertEquals(5, btCountDescriptor.getMemberIndex()); assertEquals("", btCountDescriptor.getUnit()); assertEquals(Float.NaN, btCountDescriptor.getFillValue(), 1e-8); assertEquals(1.0f, btCountDescriptor.getScalingFactor(), 1e-8); assertEquals(0.0f, btCountDescriptor.getScalingOffset(), 1e-8); }