|
16 | 16 | import com.bc.fiduceo.reader.time.TimeLocator; |
17 | 17 | import com.bc.fiduceo.reader.time.TimeLocator_TAI1993Scan; |
18 | 18 | import com.bc.fiduceo.util.NetCDFUtils; |
19 | | -import com.bc.fiduceo.util.TimeUtils; |
20 | | -import ucar.ma2.Array; |
21 | | -import ucar.ma2.ArrayInt; |
22 | | -import ucar.ma2.InvalidRangeException; |
23 | | -import ucar.ma2.MAMath; |
| 19 | +import org.esa.snap.core.util.StringUtils; |
| 20 | +import ucar.ma2.*; |
| 21 | +import ucar.ma2.DataType; |
24 | 22 | import ucar.nc2.Attribute; |
| 23 | +import ucar.nc2.AttributeContainer; |
25 | 24 | import ucar.nc2.Structure; |
26 | 25 | import ucar.nc2.Variable; |
27 | 26 |
|
|
31 | 30 | import java.nio.file.Files; |
32 | 31 | import java.nio.file.Path; |
33 | 32 | import java.util.ArrayList; |
34 | | -import java.util.Calendar; |
35 | | -import java.util.Date; |
36 | 33 | import java.util.List; |
37 | 34 |
|
38 | 35 | import static com.bc.fiduceo.reader.modis.ModisConstants.LATITUDE_VAR_NAME; |
@@ -483,4 +480,44 @@ private void injectThermalNoiseVariables() throws IOException { |
483 | 480 | arrayCache.inject(new ThermalNoiseVariable(noiseVariable, i, productSize.getNy())); |
484 | 481 | } |
485 | 482 | } |
| 483 | + |
| 484 | + @SuppressWarnings("ConstantConditions") |
| 485 | + @Override |
| 486 | + protected void splitAttributes(Variable channelVariable, int index, int numChannels) { |
| 487 | + final ArrayList<Attribute> toRemove = new ArrayList<>(); |
| 488 | + final ArrayList<Attribute> toAdd = new ArrayList<>(); |
| 489 | + |
| 490 | + final AttributeContainer attributes = channelVariable.attributes(); |
| 491 | + for (Attribute attribute : attributes) { |
| 492 | + toRemove.add(attribute); |
| 493 | + |
| 494 | + final DataType dataType = attribute.getDataType(); |
| 495 | + if (dataType.isString()) { |
| 496 | + final String stringValue = attribute.getStringValue(); |
| 497 | + final String[] tokens = StringUtils.split(stringValue, new char[]{','}, true); |
| 498 | + if (tokens.length == numChannels) { |
| 499 | + final Attribute newAttribute = new Attribute(attribute.getShortName(), tokens[index]); |
| 500 | + toAdd.add(newAttribute); |
| 501 | + } else { |
| 502 | + toAdd.add(attribute); |
| 503 | + } |
| 504 | + } else if (dataType.isNumeric()) { |
| 505 | + final int length = attribute.getLength(); |
| 506 | + if (length == numChannels) { |
| 507 | + final Number numericValue = attribute.getNumericValue(index); |
| 508 | + final Attribute newAttribute = new Attribute(attribute.getShortName(), numericValue); |
| 509 | + toAdd.add(newAttribute); |
| 510 | + } else { |
| 511 | + toAdd.add(attribute); |
| 512 | + } |
| 513 | + } |
| 514 | + } |
| 515 | + |
| 516 | + for (Attribute attribute : toRemove) { |
| 517 | + attributes.remove(attribute); |
| 518 | + } |
| 519 | + for (Attribute attribute : toAdd) { |
| 520 | + attributes.addAttribute(attribute); |
| 521 | + } |
| 522 | + } |
486 | 523 | } |
0 commit comments