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