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.control;
030    
031    import java.util.ArrayList;
032    import java.util.List;
033    
034    import edu.wisc.ssec.mcidasv.data.QualityFlag;
035    import edu.wisc.ssec.mcidasv.data.hydra.SuomiNPPDataSource;
036    
037    import org.slf4j.Logger;
038    import org.slf4j.LoggerFactory;
039    
040    import ucar.unidata.data.DataChoice;
041    import ucar.unidata.data.grid.GridUtil;
042    import ucar.unidata.idv.control.ReadoutInfo;
043    
044    import visad.Real;
045    import visad.georef.EarthLocation;
046    
047    public class SuomiNPPQfControl extends edu.wisc.ssec.mcidasv.control.ImagePlanViewControl {
048        
049        private static final Logger logger = LoggerFactory.getLogger(SuomiNPPQfControl.class);
050    
051        @Override protected List getCursorReadoutInner(EarthLocation el,
052                                                       Real animationValue,
053                                                       int animationStep,
054                                                       List<ReadoutInfo> samples) throws Exception {
055            try {
056            
057                if (currentSlice == null) {
058                    return null;
059                }
060                List result = new ArrayList();
061                Real r = GridUtil.sampleToReal(
062                             currentSlice, el, animationValue, getSamplingModeValue(NEAREST_NEIGHBOR));
063                if (r != null) {
064                    ReadoutInfo readoutInfo = new ReadoutInfo(this, r, el,
065                                                  animationValue);
066                    readoutInfo.setUnit(getDisplayUnit());
067                    readoutInfo.setRange(getRange());
068                    samples.add(readoutInfo);
069                }
070        
071                if ((r != null) && !r.isMissing()) {
072                    
073                    //logger.trace("cursor value: {}", r.getValue());
074                    DataChoice dc = getDataChoice();
075                    // TODO: why do we have to append All_Data anyway?
076                    String prod = ("All_Data/").concat(dc.toString());
077                    //logger.trace("prod: {}", prod);
078                    QualityFlag qf = ((SuomiNPPDataSource) getDataSource()).getQfMap().get(prod);
079                    //logger.trace("qf: {}", qf.toString());
080                    Integer intVal = (int) r.getValue();
081                    //logger.trace("intVal: {}", intVal.toString());
082                    // getNameForValue wants a STRING representation of an INTEGER
083                    String str = qf.getNameForValue(intVal.toString());
084                    //logger.trace("str: {}", str);
085                    
086                    result.add("<tr><td>" + getMenuLabel()
087                               + ":</td><td  align=\"right\">"
088                               + str + "</td></tr>");
089        
090                    return result;
091                }
092                } catch (Exception exc) {
093                    // Just catching the exception here so we can send it to logger,
094                    // otherwise it'll get caught in DisplayControlImpl.getCursorReadout,
095                    // get lost in LogUtil.consoleMessage (where do those go??...),
096                    // and "doCursorReadout" will be mysteriously shut off.
097                    logger.warn("Exception caught: {}", exc.getMessage());
098                    // re-throw it so DisplayControlImpl can still do its thing.
099                    throw exc;
100                }
101            return null;
102    
103        }
104    }