001/*
002 * $Id: TrackAdapter.java,v 1.8 2011/03/24 16:06:33 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2011
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
031package edu.wisc.ssec.mcidasv.data.hydra;
032
033import java.rmi.RemoteException;
034import java.util.HashMap;
035
036import visad.FlatField;
037import visad.FunctionType;
038import visad.Gridded3DSet;
039import visad.RealTupleType;
040import visad.RealType;
041import visad.VisADException;
042
043public class TrackAdapter {
044   RealTupleType domainType;
045   ArrayAdapter lonAdapter;
046   ArrayAdapter latAdapter;
047   ArrayAdapter rngAdapter;
048
049   public TrackAdapter() {
050   }
051
052   public TrackAdapter(ArrayAdapter lonAdapter, ArrayAdapter latAdapter, ArrayAdapter rangeAdapter) throws VisADException {
053     this.lonAdapter = lonAdapter;
054     this.latAdapter = latAdapter;
055     this.rngAdapter = rangeAdapter;
056     if (rangeAdapter != null) {
057       domainType = RealTupleType.SpatialEarth3DTuple;
058     }
059     else {
060       domainType = RealTupleType.SpatialEarth3DTuple;
061     }
062   }
063
064   public FlatField getData(Object subset) throws VisADException, RemoteException {
065     
066     float[] lonValues = null;
067     float[] latValues = null;
068     float[] rngValues = null;
069
070     try {
071       lonValues = (lonAdapter.getData(subset).getFloats())[0];
072       latValues = (latAdapter.getData(subset).getFloats())[0];
073       if (rngAdapter != null) {
074         rngValues = (rngAdapter.getData(subset).getFloats())[0];
075       }
076     } 
077     catch (Exception e) {
078       e.printStackTrace();
079       return null;
080     }
081
082     FlatField field = null;
083     if (rngAdapter != null) {
084       for (int k=0; k< rngValues.length; k++) {
085         rngValues[k] *= 1000.0;
086       }
087       Gridded3DSet set = new Gridded3DSet(domainType, new float[][] {lonValues, latValues, rngValues}, lonValues.length);
088       field = new FlatField(new FunctionType(domainType, rngAdapter.getMathType().getRange()), set);
089       field.setSamples(new float[][] {rngValues}, false);
090     }
091     else {
092       rngValues = new float[lonValues.length];
093       for (int k=0; k< rngValues.length; k++) rngValues[k] = 0f;
094       Gridded3DSet set = new Gridded3DSet(domainType, new float[][] {lonValues, latValues, rngValues}, lonValues.length);
095       field = new FlatField(new FunctionType(domainType, RealType.Generic), set);
096       field.setSamples(new float[][] {rngValues}, false);
097     }
098     return field;
099   }
100
101   public HashMap getDefaultSubset() {
102     return lonAdapter.getDefaultSubset();
103   }
104}