001 /* 002 * $Id: TrackAdapter.java,v 1.11 2012/02/19 17:35:42 davep Exp $ 003 * 004 * This file is part of McIDAS-V 005 * 006 * Copyright 2007-2012 007 * Space Science and Engineering Center (SSEC) 008 * University of Wisconsin - Madison 009 * 1225 W. Dayton Street, Madison, WI 53706, USA 010 * https://www.ssec.wisc.edu/mcidas 011 * 012 * All Rights Reserved 013 * 014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and 015 * some McIDAS-V source code is based on IDV and VisAD source code. 016 * 017 * McIDAS-V is free software; you can redistribute it and/or modify 018 * it under the terms of the GNU Lesser Public License as published by 019 * the Free Software Foundation; either version 3 of the License, or 020 * (at your option) any later version. 021 * 022 * McIDAS-V is distributed in the hope that it will be useful, 023 * but WITHOUT ANY WARRANTY; without even the implied warranty of 024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 025 * GNU Lesser Public License for more details. 026 * 027 * You should have received a copy of the GNU Lesser Public License 028 * along with this program. If not, see http://www.gnu.org/licenses. 029 */ 030 031 package edu.wisc.ssec.mcidasv.data.hydra; 032 033 import java.rmi.RemoteException; 034 import java.util.HashMap; 035 036 import visad.FlatField; 037 import visad.FunctionType; 038 import visad.Gridded3DSet; 039 import visad.RealTupleType; 040 import visad.RealType; 041 import visad.SetType; 042 import visad.VisADException; 043 import visad.Set; 044 045 public class TrackAdapter extends MultiDimensionAdapter { 046 RealTupleType domainType; 047 ArrayAdapter rngAdapter; 048 TrackDomain trackDomain; 049 050 int listIndex = 0; 051 052 String adapterName = null; 053 054 public TrackAdapter() { 055 } 056 057 public TrackAdapter(TrackDomain trackDomain, ArrayAdapter rangeAdapter) throws VisADException { 058 this.trackDomain = trackDomain; 059 this.rngAdapter = rangeAdapter; 060 } 061 062 public Set makeDomain(Object subset) throws Exception { 063 throw new Exception("Unimplemented"); 064 } 065 066 public FlatField getData(Object subset) throws VisADException, RemoteException { 067 068 float[] rngValues = null; 069 070 Set set = trackDomain.makeDomain(subset); 071 072 domainType = ((SetType)set.getType()).getDomain(); 073 074 try { 075 rngValues = (rngAdapter.getData(subset).getFloats())[0]; 076 } 077 catch (Exception e) { 078 e.printStackTrace(); 079 return null; 080 } 081 082 FlatField field = new FlatField(new FunctionType(domainType, rngAdapter.getMathType().getRange()), set); 083 field.setSamples(new float[][] {rngValues}, false); 084 085 return field; 086 } 087 088 public void setName(String name) { 089 adapterName = name; 090 } 091 092 public String getArrayName() { 093 if (adapterName != null) { 094 return adapterName; 095 } 096 else { 097 return rngAdapter.getArrayName(); 098 } 099 } 100 101 void setListIndex(int idx) { 102 listIndex = idx; 103 } 104 105 public HashMap getDefaultSubset() { 106 HashMap subset = rngAdapter.getDefaultSubset(); 107 double[] coords = (double[]) ((HashMap)subset).get("VertDim"); 108 coords[0] = listIndex; 109 coords[1] = listIndex; 110 coords[2] = 1; 111 return subset; 112 } 113 114 public HashMap getSubsetFromLonLatRect(double minLat, double maxLat, 115 double minLon, double maxLon) { 116 return trackDomain.getSubsetFromLonLatRect(getDefaultSubset(), minLat, maxLat, minLon, maxLon); 117 } 118 119 public HashMap getSubsetFromLonLatRect(double minLat, double maxLat, 120 double minLon, double maxLon, 121 int xStride, int yStride, int zStride) { 122 return trackDomain.getSubsetFromLonLatRect(getDefaultSubset(), minLat, maxLat, minLon, maxLon, 123 xStride, yStride, zStride); 124 } 125 126 }