Esempio n. 1
0
 static String getAsString(SequenceData valueSequence) throws IOException {
   byte[] data = new byte[valueSequence.getElementCount()];
   for (int i = 0; i < data.length; i++) {
     data[i] = valueSequence.getByte(i);
   }
   return new String(data).trim();
 }
Esempio n. 2
0
 private void readCalibrationCoefficients(int rawY, int[] calibCoeff) throws IOException {
   CompoundData dataRecord = noaaFile.getDataRecord(rawY);
   SequenceData calibration_coefficients = dataRecord.getSequence("CALIBRATION_COEFFICIENTS");
   for (int i = 0; i < calibCoeff.length; i++) {
     calibCoeff[i] = calibration_coefficients.getInt(i);
   }
 }
Esempio n. 3
0
  @Override
  public final Calibrator createCalibrator(int i) throws IOException {
    final SequenceData coefficientsSequence = provider.getCalibrationCoefficients(i);
    final CompoundData coefficients = coefficientsSequence.getCompound(channelIndex);
    final double slope = coefficients.getInt(0) * slopeScaleFactor;
    final double intercept = coefficients.getInt(1) * interceptScaleFactor;

    return new CoefficientCalibrator(this, slope, intercept);
  }
Esempio n. 4
0
 public MetadataElement getAsMetadataElement(CompoundData compoundData) throws IOException {
   CompoundType type = compoundData.getType();
   final int memberCount = type.getMemberCount();
   MetadataElement metadataElement = new MetadataElement(type.getName());
   for (int i = 0; i < memberCount; i++) {
     String typeName = type.getMemberName(i);
     CompoundMember member = type.getMember(i);
     FormatMetadata formatMetadata = (FormatMetadata) member.getMetadata();
     if (typeName.equals("fill")) {
       // ignore
     } else if (formatMetadata != null && formatMetadata.getType().equals("string")) {
       String stringValue = getAsString(compoundData.getSequence(i));
       Map<Object, String> map = getMetaData(member).getItemMap();
       if (map != null) {
         stringValue = map.get(stringValue);
       }
       ProductData data = ProductData.createInstance(stringValue);
       MetadataAttribute attribute = new MetadataAttribute(typeName, data, true);
       attribute.setDescription(getDescription(member));
       attribute.setUnit(getUnits(member));
       metadataElement.addAttribute(attribute);
     } else if (member.getType().getName().equals("DATE")) {
       CompoundData dateCompound = compoundData.getCompound(i);
       ProductData data = createDate(dateCompound);
       MetadataAttribute attribute = new MetadataAttribute(typeName, data, true);
       attribute.setDescription(getDescription(member));
       attribute.setUnit(getUnits(member));
       metadataElement.addAttribute(attribute);
     } else if (member.getType().isSequenceType()) {
       SequenceData sequence = compoundData.getSequence(i);
       for (int j = 0; j < sequence.getType().getElementCount(); j++) {
         CompoundData compound = sequence.getCompound(j);
         metadataElement.addElement(getAsMetadataElement(compound));
       }
     } else if (member.getType().isCompoundType()) {
       metadataElement.addElement(getAsMetadataElement(compoundData.getCompound(i)));
     } else if (member.getType().isSimpleType()) {
       int intValue = compoundData.getInt(i);
       Map<Object, String> map = getMetaData(member).getItemMap();
       ProductData data;
       if (map != null) {
         String stringValue = map.get(intValue);
         data = ProductData.createInstance(stringValue);
       } else {
         double scalingFactor = getMetaData(member).getScalingFactor();
         if (scalingFactor == 1.0) {
           data = ProductData.createInstance(new int[] {intValue});
         } else {
           data = ProductData.createInstance(new double[] {intValue * scalingFactor});
         }
       }
       MetadataAttribute attribute = new MetadataAttribute(typeName, data, true);
       attribute.setDescription(getDescription(member));
       attribute.setUnit(getUnits(member));
       metadataElement.addAttribute(attribute);
     } else {
       System.out.println("not handled: name=" + typeName);
       System.out.println("member = " + member.getType());
     }
   }
   return metadataElement;
 }