001 /* 002 * This file is part of McIDAS-V 003 * 004 * Copyright 2007-2013 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 029 package edu.wisc.ssec.mcidasv.data.hydra; 030 031 import ucar.unidata.data.DataSelection; 032 import java.util.HashMap; 033 import java.util.Hashtable; 034 import java.util.Iterator; 035 import java.util.Set; 036 037 038 public class MultiDimensionSubset extends DataSelection { 039 040 public static final MultiDimensionSubset key = new MultiDimensionSubset(); 041 042 private double[][] coords = null; 043 private String[] keys = null; 044 045 public MultiDimensionSubset() { 046 super(); 047 } 048 049 public MultiDimensionSubset(HashMap subset) { 050 super(); 051 coords = new double[subset.size()][]; 052 keys = new String[subset.size()]; 053 Iterator iter = subset.keySet().iterator(); 054 int cnt =0; 055 while (iter.hasNext()) { 056 String key = (String) iter.next(); 057 keys[cnt] = key; 058 coords[cnt] = (double[]) subset.get(key); 059 cnt++; 060 } 061 } 062 063 public MultiDimensionSubset(double[][] coords, String[] keys) { 064 super(); 065 /** 066 int num = keys.length; 067 this.keys = new String[num]; 068 this.coords = new double[num][]; 069 for (int i=0; i<num; i++) { 070 this.keys[i] = keys[i]; 071 this.coords[i] = new double[coords[i].length]; 072 for (int j=0; j<coords[i].length; j++) { 073 this.coords[i][j] = coords[i][j]; 074 } 075 } 076 **/ 077 this.coords = coords; 078 this.keys = keys; 079 } 080 081 public HashMap getSubset() { 082 HashMap hmap = new HashMap(); 083 for (int k=0; k<keys.length; k++) { 084 double[] new_coords = new double[coords[k].length]; 085 System.arraycopy(coords[k],0,new_coords,0,new_coords.length); 086 hmap.put(keys[k], new_coords); 087 } 088 return hmap; 089 } 090 091 public double[][] getCoords() { 092 return coords; 093 } 094 095 public void setCoords(double[][] coords) { 096 this.coords = coords; 097 } 098 099 public String[] getKeys() { 100 return keys; 101 } 102 103 public void setKeys(String[] keys) { 104 this.keys = keys; 105 } 106 107 public MultiDimensionSubset clone() { 108 MultiDimensionSubset subset = new MultiDimensionSubset(coords, keys); 109 Hashtable props = new Hashtable(); 110 props.put(MultiDimensionSubset.key, subset); 111 subset.setProperties(props); 112 return subset; 113 } 114 115 public String toString() { 116 StringBuffer sb = new StringBuffer(); 117 if (keys != null) { 118 for (int i = 0; i < keys.length; i++) { 119 sb.append(new String(keys[i] + ": " + coords[i][0] + ", " + coords[i][1] + ", " + coords[i][2] + "\n")); 120 } 121 } 122 return sb.toString(); 123 } 124 125 /*** 126 public boolean equals(Object obj) { 127 if (!(obj instanceof MultiDimensionSubset)) return false; 128 if ((keys == null) || (coords == null)) return false; 129 130 String[] keys_in = ((MultiDimensionSubset)obj).getKeys(); 131 if ((keys_in == null) || (keys_in.length != keys.length)) return false; 132 133 for (int k=0; k<keys.length; k++) { 134 if (keys_in[k] != keys[k]) return false; 135 } 136 137 double[][] coords_in = (double[][]) ((MultiDimensionSubset)obj).getCoords(); 138 if ((coords_in == null) || (coords.length != coords_in.length)) return false; 139 for (int k=0; k<coords.length; k++) { 140 for (int t=0; t<coords[k].length; t++) { 141 if (coords[k][t] != coords_in[k][t]) return false; 142 } 143 } 144 return true; 145 } 146 ***/ 147 }