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 java.rmi.RemoteException;
032 import java.util.HashMap;
033
034 import visad.FlatField;
035 import visad.FunctionType;
036 import visad.Gridded3DSet;
037 import visad.RealTupleType;
038 import visad.RealType;
039 import visad.SetType;
040 import visad.VisADException;
041 import visad.Set;
042
043 public class TrackAdapter extends MultiDimensionAdapter {
044 RealTupleType domainType;
045 ArrayAdapter rngAdapter;
046 TrackDomain trackDomain;
047
048 int listIndex = 0;
049
050 String adapterName = null;
051
052 public TrackAdapter() {
053 }
054
055 public TrackAdapter(TrackDomain trackDomain, ArrayAdapter rangeAdapter) throws VisADException {
056 this.trackDomain = trackDomain;
057 this.rngAdapter = rangeAdapter;
058 }
059
060 public Set makeDomain(Object subset) throws Exception {
061 throw new Exception("Unimplemented");
062 }
063
064 public FlatField getData(Object subset) throws VisADException, RemoteException {
065
066 float[] rngValues = null;
067
068 Set set = trackDomain.makeDomain(subset);
069
070 domainType = ((SetType)set.getType()).getDomain();
071
072 try {
073 rngValues = (rngAdapter.getData(subset).getFloats())[0];
074 }
075 catch (Exception e) {
076 e.printStackTrace();
077 return null;
078 }
079
080 FlatField field = new FlatField(new FunctionType(domainType, rngAdapter.getMathType().getRange()), set);
081 field.setSamples(new float[][] {rngValues}, false);
082
083 return field;
084 }
085
086 public void setName(String name) {
087 adapterName = name;
088 }
089
090 public String getArrayName() {
091 if (adapterName != null) {
092 return adapterName;
093 }
094 else {
095 return rngAdapter.getArrayName();
096 }
097 }
098
099 void setListIndex(int idx) {
100 listIndex = idx;
101 }
102
103 public HashMap getDefaultSubset() {
104 HashMap subset = rngAdapter.getDefaultSubset();
105 if (subset.containsKey("VertDim")) {
106 double[] coords = (double[]) ((HashMap)subset).get("VertDim");
107 if (coords != null) {
108 coords[0] = listIndex;
109 coords[1] = listIndex;
110 coords[2] = 1;
111 }
112 }
113 return subset;
114 }
115
116 public HashMap getSubsetFromLonLatRect(double minLat, double maxLat,
117 double minLon, double maxLon) {
118 return trackDomain.getSubsetFromLonLatRect(getDefaultSubset(), minLat, maxLat, minLon, maxLon);
119 }
120
121 public HashMap getSubsetFromLonLatRect(double minLat, double maxLat,
122 double minLon, double maxLon,
123 int xStride, int yStride, int zStride) {
124 return trackDomain.getSubsetFromLonLatRect(getDefaultSubset(), minLat, maxLat, minLon, maxLon,
125 xStride, yStride, zStride);
126 }
127
128 }