001/* 002 * This file is part of McIDAS-V 003 * 004 * Copyright 2007-2025 005 * Space Science and Engineering Center (SSEC) 006 * University of Wisconsin - Madison 007 * 1225 W. Dayton Street, Madison, WI 53706, USA 008 * https://www.ssec.wisc.edu/mcidas/ 009 * 010 * All Rights Reserved 011 * 012 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and 013 * some McIDAS-V source code is based on IDV and VisAD source code. 014 * 015 * McIDAS-V is free software; you can redistribute it and/or modify 016 * it under the terms of the GNU Lesser Public License as published by 017 * the Free Software Foundation; either version 3 of the License, or 018 * (at your option) any later version. 019 * 020 * McIDAS-V is distributed in the hope that it will be useful, 021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 023 * GNU Lesser Public License for more details. 024 * 025 * You should have received a copy of the GNU Lesser Public License 026 * along with this program. If not, see https://www.gnu.org/licenses/. 027 */ 028 029package edu.wisc.ssec.mcidasv.data.hydra; 030 031import java.util.ArrayList; 032import java.util.HashMap; 033import java.util.List; 034import java.util.Map; 035 036public class AggregationRangeProcessor extends RangeProcessor { 037 038 List<RangeProcessor> rangeProcessors = new ArrayList<>(); 039 040 int rngIdx = 0; 041 042 public AggregationRangeProcessor(GranuleAggregation aggrReader, 043 Map<String, Object> metadata) throws Exception { 044 super(); 045 046 List<NetCDFFile> readers = aggrReader.getReaders(); 047 048 int num = 0; 049 050 for (int rdrIdx = 0; rdrIdx < readers.size(); rdrIdx++) { 051 RangeProcessor rngProcessor = RangeProcessor.createRangeProcessor( 052 readers.get(rdrIdx), metadata); 053 054 if (rngProcessor.hasMultiDimensionScale()) { 055 num++; 056 } 057 058 rangeProcessors.add(rngProcessor); 059 } 060 061 if (num > 0 && num != readers.size()) { 062 throw new Exception( 063 "AggregationRangeProcessor: all or none can define a multiDimensionScale"); 064 } else if (num == readers.size()) { 065 setHasMultiDimensionScale(true); 066 } 067 068 aggrReader.addRangeProcessor( 069 (String) metadata.get(SwathAdapter.array_name), this); 070 } 071 072 public synchronized void setWhichRangeProcessor(int index) { 073 rngIdx = index; 074 } 075 076 public synchronized void setMultiScaleIndex(int idx) { 077 rangeProcessors.get(rngIdx).setMultiScaleIndex(idx); 078 } 079 080 public synchronized float[] processRange(byte[] values, Map<String, double[]> subset) { 081 return rangeProcessors.get(rngIdx).processRange(values, subset); 082 } 083 084 public synchronized float[] processRange(short[] values, Map<String, double[]> subset) { 085 return rangeProcessors.get(rngIdx).processRange(values, subset); 086 } 087 088 public synchronized float[] processRange(float[] values, Map<String, double[]> subset) { 089 return rangeProcessors.get(rngIdx).processRange(values, subset); 090 } 091 092 public synchronized double[] processRange(double[] values, Map<String, double[]> subset) { 093 return rangeProcessors.get(rngIdx).processRange(values, subset); 094 } 095 096 public synchronized float[] processRangeUshort(int[] values, Map<String, double[]> subset) { 097 return rangeProcessors.get(rngIdx).processRangeUshorts(values, subset); 098 } 099}