001/* 002 * This file is part of McIDAS-V 003 * 004 * Copyright 2007-2015 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 http://www.gnu.org/licenses. 027 */ 028 029package edu.wisc.ssec.mcidasv.data.hydra; 030 031import java.util.ArrayList; 032import java.util.HashMap; 033 034public class AggregationRangeProcessor extends RangeProcessor { 035 036 ArrayList<RangeProcessor> rangeProcessors = new ArrayList<RangeProcessor>(); 037 038 int rngIdx = 0; 039 040 public AggregationRangeProcessor(GranuleAggregation aggrReader, 041 HashMap metadata) throws Exception { 042 super(); 043 044 ArrayList readers = aggrReader.getReaders(); 045 046 int num = 0; 047 048 for (int rdrIdx = 0; rdrIdx < readers.size(); rdrIdx++) { 049 RangeProcessor rngProcessor = RangeProcessor.createRangeProcessor( 050 (MultiDimensionReader) readers.get(rdrIdx), metadata); 051 052 if (rngProcessor.hasMultiDimensionScale()) { 053 num++; 054 } 055 056 rangeProcessors.add(rngProcessor); 057 } 058 059 if (num > 0 && num != readers.size()) { 060 throw new Exception( 061 "AggregationRangeProcessor: all or none can define a multiDimensionScale"); 062 } else if (num == readers.size()) { 063 setHasMultiDimensionScale(true); 064 } 065 066 aggrReader.addRangeProcessor( 067 (String) metadata.get(SwathAdapter.array_name), this); 068 } 069 070 public synchronized void setWhichRangeProcessor(int index) { 071 rngIdx = index; 072 } 073 074 public synchronized void setMultiScaleIndex(int idx) { 075 rangeProcessors.get(rngIdx).setMultiScaleIndex(idx); 076 } 077 078 public synchronized float[] processRange(byte[] values, HashMap subset) { 079 return rangeProcessors.get(rngIdx).processRange(values, subset); 080 } 081 082 public synchronized float[] processRange(short[] values, HashMap subset) { 083 return rangeProcessors.get(rngIdx).processRange(values, subset); 084 } 085 086 public synchronized float[] processRange(float[] values, HashMap subset) { 087 return rangeProcessors.get(rngIdx).processRange(values, subset); 088 } 089 090 public synchronized double[] processRange(double[] values, HashMap subset) { 091 return rangeProcessors.get(rngIdx).processRange(values, subset); 092 } 093 094 public synchronized float[] processAlongMultiScaleDim(short[] values) { 095 return rangeProcessors.get(rngIdx).processAlongMultiScaleDim(values); 096 } 097 098 public synchronized float[] processAlongMultiScaleDim(byte[] values) { 099 return rangeProcessors.get(rngIdx).processAlongMultiScaleDim(values); 100 } 101}