001/*
002 * This file is part of McIDAS-V
003 *
004 * Copyright 2007-2024
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 https://www.gnu.org/licenses/.
027 */
028
029package edu.wisc.ssec.mcidasv.data.hydra;
030
031import java.rmi.RemoteException;
032
033import visad.FlatField;
034import visad.Gridded2DSet;
035import visad.RealTuple;
036import visad.RealTupleType;
037import visad.VisADException;
038
039public class CrIS_SDR_MultiSpectralData extends MultiSpectralData {
040
041  SwathNavigation swathNav = null;
042  private float[][] lonlat = null;
043   
044  public CrIS_SDR_MultiSpectralData(SwathAdapter swathAdapter, SpectrumAdapter spectrumAdapter) {
045     super(swathAdapter, spectrumAdapter, null, null);
046     try {
047        swathNav = swathAdapter.getNavigation();
048        swathNav.getVisADCoordinateSystem(null, swathAdapter.getDefaultSubset());
049        lonlat = ((CrIS_SDR_LonLatNavigation)swathNav).getInterpSet().getSamples(false);
050     }
051     catch (Exception e) {
052     }
053  }
054
055  void setSpectrumAdapterProcessor() {
056  }
057
058  public FlatField getSpectrum(int[] coords) 
059      throws Exception, VisADException, RemoteException {
060    if (coords == null) return null;
061
062    int ii = 0;
063    int jj = 0;
064    int kk = 0;
065
066    double[] scan = new double[] {jj, jj, 1.0};
067    double[] step = new double[] {ii, ii, 1.0};
068    double[] fov = new double[] {kk, kk, 1.0};
069
070    spectrumSelect.put(SpectrumAdapter.x_dim_name, step);
071    spectrumSelect.put(SpectrumAdapter.y_dim_name, scan);
072    spectrumSelect.put(SpectrumAdapter.FOVindex_name, fov);
073
074    FlatField spectrum = spectrumAdapter.getData(spectrumSelect);
075    return convertSpectrum(spectrum, paramName);
076  }
077
078  public FlatField getSpectrum(RealTuple location) 
079      throws Exception, VisADException, RemoteException {
080
081    double[] tmp = location.getValues();
082    float[][] loc = new float[][] {{(float)tmp[1]}, {(float)tmp[0]}};
083    if (loc[0][0] > 180) loc[0][0] -= 360;
084
085    int kk = -1;
086    int ii = 0;
087    int jj = 0;
088
089    float[][] lonlatFOV = new float[2][9];
090
091    scanloop: for (jj=0; jj<60; jj++) {
092       for (ii=0; ii<30; ii++) {
093           int start = jj*270 + ii*9;
094           System.arraycopy(lonlat[0], start, lonlatFOV[0], 0, 9);
095           System.arraycopy(lonlat[1], start, lonlatFOV[1], 0, 9);
096           Gridded2DSet gsetFOV = new Gridded2DSet(RealTupleType.SpatialEarth2DTuple, lonlatFOV, 3, 3);
097           int[] idx = gsetFOV.valueToIndex(loc);
098           kk = idx[0];
099           if (kk >= 0) {
100              break scanloop;
101           }
102       }
103    }
104
105    if (kk < 0) {
106      return null;
107    } 
108    else {
109       double[] scan = new double[] {jj, jj, 1.0};
110       double[] step = new double[] {ii, ii, 1.0};
111       double[] fov = new double[] {kk, kk, 1.0};
112
113       spectrumSelect.put(SpectrumAdapter.x_dim_name, step);
114       spectrumSelect.put(SpectrumAdapter.y_dim_name, scan);
115       spectrumSelect.put(SpectrumAdapter.FOVindex_name, fov);
116
117       FlatField spectrum = spectrumAdapter.getData(spectrumSelect);
118       return convertSpectrum(spectrum, paramName);
119    }
120  }
121}