VLab Issue #4552 - Grid Resource to recognize sub-hourly forecasts
This commit fixes #4552 Change-Id: Ic7f456b03ac4d00e551d3012f5b7a6034af33266 Former-commit-id:cb4d6d07d0
[formerly6fac23e853
] [formerlyd62c732105
] [formerlyd62c732105
[formerly1a8f79820d
]] [formerlycb4d6d07d0
[formerly6fac23e853
] [formerlyd62c732105
] [formerlyd62c732105
[formerly1a8f79820d
]] [formerlye024656cc7
[formerlyd62c732105
[formerly1a8f79820d
] [formerlye024656cc7
[formerly 960e36e6fe39425be6e17b492dbf7bebf059db39]]]]] Former-commit-id:e024656cc7
Former-commit-id:b78fbf6272
[formerly1beed7d838
] [formerly0707e178ae
] [formerly 9277098276c5bb9bc035223b054efa8c2087803a [formerly b0ec5a0771beb6706a4633cb614f87d61edc9682] [formerly0707e178ae
[formerly006bbfb872
]]] Former-commit-id: 92528e2c67f4b2ddc21576c855941bdb59a9f685 [formerly c40365926a20dd3f09565ca805e204e510077e8c] [formerly19b0991d11
[formerlye87440a876
]] Former-commit-id:19b0991d11
Former-commit-id:1b32941799
This commit is contained in:
parent
a5faad6670
commit
fd60ce31cd
8 changed files with 2162 additions and 1716 deletions
|
@ -26,7 +26,8 @@ Export-Package: gov.noaa.nws.ncep.viz.common,
|
|||
gov.noaa.nws.ncep.viz.common.soundingQuery,
|
||||
gov.noaa.nws.ncep.viz.common.staticPointDataSource,
|
||||
gov.noaa.nws.ncep.viz.common.ui,
|
||||
gov.noaa.nws.ncep.viz.common.ui.color
|
||||
gov.noaa.nws.ncep.viz.common.ui.color,
|
||||
gov.noaa.nws.ncep.viz.common.util
|
||||
Import-Package: com.raytheon.uf.common.comm,
|
||||
com.raytheon.uf.viz.application,
|
||||
com.raytheon.viz.pointdata,
|
||||
|
|
|
@ -0,0 +1,209 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package gov.noaa.nws.ncep.viz.common.util;
|
||||
|
||||
/**
|
||||
* Static methods to convert between AWIPS2 Date strings to GEMPAK DATTIM
|
||||
* string. Also contains helper methods to convert forecast time between time
|
||||
* hours and minutes representation to time in seconds.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Aug 29, 2014 jbernier Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author jbernier
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class CommonDateFormatUtil {
|
||||
|
||||
public static final String AWIPS2_DATETIME_FORMAT = "YYYY-MM-dd HH:mm:ss.S",
|
||||
GEMPAK_DATTIM_FORMAT = "yyMMdd/HHmm";
|
||||
|
||||
/**
|
||||
*
|
||||
* Converts AWIPS2 date time string into GEMPAK DATTIM string
|
||||
*
|
||||
* @param dbTime
|
||||
* eg "2011-10-09 06:20:00.0 (1)"
|
||||
* @return eq "111009/0620f00100"
|
||||
*/
|
||||
public static String dbtimeToDattim(String dbTime) {
|
||||
StringBuilder aDattimBuilder = new StringBuilder(dbTime.substring(0,
|
||||
AWIPS2_DATETIME_FORMAT.length()));
|
||||
|
||||
aDattimBuilder.delete(0, 2);
|
||||
deleteAllChar(aDattimBuilder, "-");
|
||||
deleteAllChar(aDattimBuilder, ":");
|
||||
deleteAllChar(aDattimBuilder, ".0");
|
||||
int indexOfDateTimeDelimiter = (dbTime.contains("_") ? aDattimBuilder
|
||||
.indexOf("_") : aDattimBuilder.indexOf(" "));
|
||||
aDattimBuilder.replace(indexOfDateTimeDelimiter,
|
||||
indexOfDateTimeDelimiter + 1, "/");
|
||||
|
||||
if (dbTime.contains("(") && dbTime.contains(")")) {
|
||||
aDattimBuilder.append("f").append(getForecastTimeString(dbTime));
|
||||
}
|
||||
return aDattimBuilder.toString();
|
||||
}
|
||||
|
||||
private static void deleteAllChar(StringBuilder charSeq, String charToDelete) {
|
||||
int startIndex = charSeq.indexOf(charToDelete);
|
||||
while (startIndex >= 0 && startIndex < charSeq.length()) {
|
||||
int endIndex = startIndex + charToDelete.length();
|
||||
charSeq.delete(startIndex, endIndex);
|
||||
startIndex = charSeq.indexOf(charToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Converts GEMPAK DATTIM string into AWIPS2 date time string
|
||||
*
|
||||
* @param aDattim
|
||||
* eg "111009/0620f00100"
|
||||
* @return eq "2011-10-09 06:20:00.0 (1)"
|
||||
*/
|
||||
public static String dattimToDbtime(String aDattim) {
|
||||
StringBuilder dbTimeBuilder = new StringBuilder(
|
||||
AWIPS2_DATETIME_FORMAT.length() + 10);
|
||||
String[] dateTime = aDattim.substring(0, GEMPAK_DATTIM_FORMAT.length())
|
||||
.split("/");
|
||||
int date = Integer.parseInt(dateTime[0]), time = Integer
|
||||
.parseInt(dateTime[1]);
|
||||
|
||||
dbTimeBuilder.append(String.format("20%02d-%02d-%02d %02d:%02d:00.0",
|
||||
date / 10000, (date % 10000) / 100, date % 100, time / 100,
|
||||
time % 100));
|
||||
|
||||
if ((aDattim = aDattim.toUpperCase()).contains("F")) {
|
||||
int spaceIndex = dbTimeBuilder.indexOf(" ");
|
||||
dbTimeBuilder.replace(spaceIndex, spaceIndex + 1, "_");
|
||||
dbTimeBuilder.append("_(")
|
||||
.append(getForecastColonTimeString(aDattim)).append(")");
|
||||
}
|
||||
return dbTimeBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Utility method to return forecast time in seconds given either GEMPAK or
|
||||
* AWIPS2 date time strings
|
||||
*
|
||||
* @param anyTimeString
|
||||
* eg "140808/0620f00115" or "2014-08-08 06:20:00.0 (1:15)"
|
||||
* @return eg 4500
|
||||
*/
|
||||
public static int getForecastTimeInSec(String anyTimeString) {
|
||||
anyTimeString = anyTimeString.toUpperCase();
|
||||
int forecastHrs = 0, forecastMins = 0;
|
||||
|
||||
if (anyTimeString.contains("F")) {
|
||||
String forecastTime = anyTimeString.substring(anyTimeString
|
||||
.indexOf("F") + 1);
|
||||
forecastHrs = Integer.parseInt(forecastTime.substring(0,
|
||||
"000".length()));
|
||||
forecastMins = forecastTime.length() == 5 ? Integer
|
||||
.parseInt(forecastTime.substring("000".length())) : 0;
|
||||
} else if (anyTimeString.contains("(") && anyTimeString.contains(")")) {
|
||||
String[] forecastTime = anyTimeString.substring(
|
||||
anyTimeString.indexOf("(") + 1, anyTimeString.indexOf(")"))
|
||||
.split(":");
|
||||
forecastHrs = Integer.parseInt(forecastTime[0]);
|
||||
forecastMins = forecastTime.length == 2 ? Integer
|
||||
.parseInt(forecastTime[1]) : 0;
|
||||
} else {
|
||||
forecastHrs = 0;
|
||||
forecastMins = 0;
|
||||
}
|
||||
return forecastHrs * 3600 + forecastMins * 60;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Utility method to return forecast time string formatted to HHHmm given
|
||||
* either GEMPAK or AWIPS2 date time format string
|
||||
*
|
||||
* @param anyTimeFormat
|
||||
* eg "140808/0620f00115" or "2014-08-08 06:20:00.0 (1:15)"
|
||||
* @return eg "00115"
|
||||
*/
|
||||
public static String getForecastTimeString(String anyTimeFormat) {
|
||||
int forecastTimeInSec = getForecastTimeInSec(anyTimeFormat);
|
||||
|
||||
return getForecastTimeString(forecastTimeInSec);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Utility method to return forecast time string formatted to HHHmm given a
|
||||
* forecast time in seconds
|
||||
*
|
||||
* @param forecastTimeInSec
|
||||
* eg 4500
|
||||
* @return eg "00115"
|
||||
*/
|
||||
public static String getForecastTimeString(int forecastTimeInSec) {
|
||||
int forecastHrs = forecastTimeInSec / 3600;
|
||||
int forecastMins = forecastTimeInSec % 3600 / 60;
|
||||
|
||||
return String.format("%03d", forecastHrs)
|
||||
+ (forecastMins > 0 ? String.format("%02d", forecastMins) : "");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Utility method to return forecast time string formatted to HHH:mm given
|
||||
* either GEMPAK or AWIPS2 date time format string
|
||||
*
|
||||
* @param anyTimeFormat
|
||||
* eg "140808/0620f00115" or "2014-08-08 06:20:00.0 (1:15)"
|
||||
* @return eg "1:15"
|
||||
*/
|
||||
public static String getForecastColonTimeString(String anyTimeFormat) {
|
||||
int forecastTimeInSec = getForecastTimeInSec(anyTimeFormat);
|
||||
|
||||
return getForecastColonTimeString(forecastTimeInSec);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Utility method to return forecast time string formatted to HHH:mm given a
|
||||
* forecast time in seconds
|
||||
*
|
||||
* @param forecastTimeInSec
|
||||
* eg 4500
|
||||
* @return eg "1:15"
|
||||
*/
|
||||
public static String getForecastColonTimeString(int forecastTimeInSec) {
|
||||
int forecastHrs = forecastTimeInSec / 3600;
|
||||
int forecastMins = forecastTimeInSec % 3600 / 60;
|
||||
|
||||
return String.valueOf(forecastHrs)
|
||||
+ (forecastMins > 0 ? ":" + String.format("%02d", forecastMins)
|
||||
: "");
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ Export-Package: gov.noaa.nws.ncep.viz.gempak,
|
|||
gov.noaa.nws.ncep.viz.gempak.grid.units,
|
||||
gov.noaa.nws.ncep.viz.gempak.util
|
||||
Import-Package: com.raytheon.uf.common.derivparam.tree,
|
||||
gov.noaa.nws.ncep.edex.common.ncinventory,
|
||||
com.raytheon.uf.common.serialization,
|
||||
gov.noaa.nws.ncep.common.log.logger,
|
||||
com.raytheon.uf.common.serialization
|
||||
gov.noaa.nws.ncep.edex.common.ncinventory,
|
||||
gov.noaa.nws.ncep.viz.common.util
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package gov.noaa.nws.ncep.viz.gempak.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.raytheon.uf.common.gridcoverage.LambertConformalGridCoverage;
|
||||
import com.raytheon.uf.common.gridcoverage.LatLonGridCoverage;
|
||||
import com.raytheon.uf.common.gridcoverage.PolarStereoGridCoverage;
|
||||
import gov.noaa.nws.ncep.viz.common.util.CommonDateFormatUtil;
|
||||
import gov.noaa.nws.ncep.viz.gempak.grid.jna.GridDiag;
|
||||
|
||||
import javax.measure.converter.UnitConverter;
|
||||
|
@ -18,7 +14,9 @@ import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
|||
|
||||
import com.raytheon.uf.common.geospatial.ISpatialObject;
|
||||
import com.raytheon.uf.common.geospatial.MapUtil;
|
||||
import com.raytheon.uf.viz.core.comm.Connector;
|
||||
import com.raytheon.uf.common.gridcoverage.LambertConformalGridCoverage;
|
||||
import com.raytheon.uf.common.gridcoverage.LatLonGridCoverage;
|
||||
import com.raytheon.uf.common.gridcoverage.PolarStereoGridCoverage;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
|
@ -26,527 +24,404 @@ import com.vividsolutions.jts.geom.Polygon;
|
|||
|
||||
/**
|
||||
* @author gamaz
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @author gamaz
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class GempakGrid {
|
||||
|
||||
private static GridDiag gd = GridDiag.getInstance();
|
||||
|
||||
public final static String gempakPluginName = "gempak_gd"; // ghull added Dec 19, 2010
|
||||
|
||||
/**
|
||||
* Gets the cycle times for a GEMPAK dataLocation from uEngine in YYMMDD_HHMM format.
|
||||
*
|
||||
* @param aDataLocation
|
||||
* eg "$MODEL/gfs"
|
||||
* @return
|
||||
* @throws VizException
|
||||
*/
|
||||
public static String[] getGridCycleTimes( String aDataLocation,String gdFile ) throws VizException{
|
||||
byte[] cycles = new byte[1024];
|
||||
IntByReference iret = new IntByReference(0);
|
||||
gd.gem.in_bdta_(iret);
|
||||
gd.gem.gd_init_ (iret);
|
||||
gd.gem.gdc_gcyc_(gdFile, cycles, iret);
|
||||
if ( iret.getValue() == 0 ) {
|
||||
String cycleTime = Native.toString(cycles);
|
||||
String cycleTime1 = cycleTime.replaceAll("/", "_");
|
||||
String []cycleTimes = cycleTime1.trim().split(";");
|
||||
return cycleTimes;
|
||||
}
|
||||
else {
|
||||
throw new VizException();
|
||||
}
|
||||
// long st1 = System.currentTimeMillis();
|
||||
// StringBuilder query = new StringBuilder();
|
||||
// query.append("import NcModelCycleQuery\n");
|
||||
// query.append("req = NcModelCycleQuery.NcModelCycleQuery()\n");
|
||||
// query.append("req.setDataLocation('" + aDataLocation + "')\n");
|
||||
// query.append("req.setModelName('" + modelname + "')\n");
|
||||
// query.append("return req.execute()");
|
||||
//
|
||||
// String script = query.toString();
|
||||
// try {
|
||||
// String cycleListStr = (String) Connector.getInstance().connect(
|
||||
// script, null, 600000)[0];
|
||||
//
|
||||
// String[] cycleList = cycleListStr.split("\\|");
|
||||
// long st2 = System.currentTimeMillis();
|
||||
// System.out.println ("***get cycleTimes throught Connector took:" + (st2-st1));
|
||||
// return cycleList;
|
||||
// } catch (VizException e) {
|
||||
// throw new VizException(e);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the available times for a GEMPAK dataLocation and a current cycle
|
||||
* from uEngine in "YYYY-MM-DD HH:MM:SS.S (fHHH)" format.
|
||||
*
|
||||
* @param aDataLocation
|
||||
* eg "$MODEL/gfs"
|
||||
* @param aCurrentCycle
|
||||
* eg "2010-11-28 18:00:00.0"
|
||||
* @return
|
||||
* @throws VizException
|
||||
*/
|
||||
public static String[] getAvailableGridTimes( String aDataLocation, String aCurrentCycle, String gdFile )
|
||||
throws VizException{
|
||||
byte[] availables = new byte[10000];
|
||||
IntByReference iret = new IntByReference(0);
|
||||
gd.gem.in_bdta_(iret);
|
||||
gd.gem.gd_init_ (iret);
|
||||
String cycle="";
|
||||
if ( aCurrentCycle != null ){
|
||||
String []dtStr = aCurrentCycle.split(" ");
|
||||
cycle =dtStr[0].split("-")[1] + dtStr[0].split("-")[2] +"/" +dtStr[1].split(":")[0];
|
||||
}
|
||||
gd.gem.gdc_gtmf_(gdFile, cycle, availables, iret);
|
||||
if ( iret.getValue() == 0 ) {
|
||||
String availableTimes = Native.toString(availables);
|
||||
String [] avaTimeStr = availableTimes.trim().split("\\|");
|
||||
String [] avaTimesList = new String [avaTimeStr.length];
|
||||
int i = 0;
|
||||
for ( String ava:avaTimeStr) {
|
||||
if ( ava.contains("F")) {
|
||||
avaTimesList[i] = aCurrentCycle +" (" + Integer.parseInt(ava.split("F")[1]) + ")";
|
||||
}
|
||||
else {
|
||||
avaTimesList[i] = aCurrentCycle +" (0)";
|
||||
}
|
||||
i ++;
|
||||
}
|
||||
return avaTimesList;
|
||||
}
|
||||
else {
|
||||
throw new VizException();
|
||||
}
|
||||
// long st1 = System.currentTimeMillis();
|
||||
// StringBuilder query = new StringBuilder();
|
||||
// query.append("import NcModelAvailableTimesQuery\n");
|
||||
// query.append("req = NcModelAvailableTimesQuery.NcModelAvailableTimesQuery()\n");
|
||||
// query.append("req.setDataLocation('" + aDataLocation + "')\n");
|
||||
// query.append("req.setModelName('" + modelName + "')\n");
|
||||
// query.append("req.setCurrentCycle('" + aCurrentCycle + "')\n");
|
||||
// query.append("return req.execute()");
|
||||
//
|
||||
// String script = query.toString();
|
||||
// try {
|
||||
// String avTimesListStr = (String) Connector.getInstance().connect(
|
||||
// script, null, 600000)[0];
|
||||
// String[] avTimesList = avTimesListStr.split("\\|");
|
||||
// long st2 = System.currentTimeMillis();
|
||||
// System.out.println ("===get availableTimes throught connector took:" + (st2-st1));
|
||||
// return avTimesList;
|
||||
// } catch (VizException e) {
|
||||
// throw new VizException(e);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the navigation information from a GEMPAK grid file and returns the coverage object.
|
||||
*
|
||||
* @param aDataLocation
|
||||
* eg "$MODEL/gfs"
|
||||
* @param aCurrentCycle
|
||||
* eg "2010-11-28 18:00:00.0"
|
||||
* @return
|
||||
* @throws VizException
|
||||
*/
|
||||
public static ISpatialObject getGridNavigation (String anAlias, String aDataLocation, String aCurrentCycle)
|
||||
throws VizException{
|
||||
int numberOfLayers = aDataLocation.split("/").length;
|
||||
String model = aDataLocation.split("/")[numberOfLayers-1];
|
||||
String gdfile = constructGridFilename (anAlias, aDataLocation,aCurrentCycle);
|
||||
float[] rnav = getGridNavigationBlock (gdfile);
|
||||
String proj = getGridProjection (rnav);
|
||||
|
||||
DefaultGeographicCRS WGS84 = DefaultGeographicCRS.WGS84;
|
||||
CoordinateReferenceSystem crs;
|
||||
String crsWKT;
|
||||
Polygon geometry;
|
||||
|
||||
if (proj.equalsIgnoreCase("CED")) {
|
||||
double minLat = MapUtil.correctLat(rnav[6]);
|
||||
double maxLat = MapUtil.correctLat(rnav[8]);
|
||||
double minLon = MapUtil.correctLon(rnav[7]);
|
||||
double maxLon = MapUtil.correctLon(rnav[9]);
|
||||
if (maxLon < minLon) {
|
||||
maxLon += 360.0;
|
||||
}
|
||||
if (maxLon > 180) {
|
||||
crs = new DefaultGeographicCRS(new DefaultGeodeticDatum("WGS84",
|
||||
WGS84.getDatum().getEllipsoid(), new DefaultPrimeMeridian(
|
||||
"DateLine", 180.0)), WGS84.getCoordinateSystem());
|
||||
} else {
|
||||
crs = WGS84;
|
||||
}
|
||||
crsWKT = crs.toWKT();
|
||||
try {
|
||||
geometry = MapUtil.createGeometry(minLat, minLon, maxLat, maxLon);
|
||||
} catch (Exception e) {
|
||||
throw new VizException("Error creating geometry", e);
|
||||
}
|
||||
CharSequence spacingUnit = "degree";
|
||||
|
||||
LatLonGridCoverage cov = new LatLonGridCoverage();
|
||||
cov.setSpacingUnit(spacingUnit.toString());
|
||||
cov.setDx(rnav[2]);
|
||||
cov.setDy(rnav[3]);
|
||||
int nx = (int) rnav[4];
|
||||
cov.setNx(Integer.valueOf(nx));
|
||||
int ny = (int) rnav[5];
|
||||
cov.setNy(Integer.valueOf(ny));
|
||||
cov.setCrs(crs);
|
||||
cov.setCrsWKT(crsWKT);
|
||||
cov.setGeometry(geometry);
|
||||
cov.setLa1(minLat);
|
||||
cov.setLa2(maxLat);
|
||||
cov.setLo1(minLon);
|
||||
cov.setLo2(maxLon);
|
||||
cov.setName("GEMPAK " + model + rnav[2] + "x" + rnav[3]+ " " + spacingUnit + " grid");
|
||||
cov.setGridGeometry(MapUtil.getGridGeometry(cov));
|
||||
cov.setDescription("GEMPAK CED grid");
|
||||
return cov;
|
||||
}
|
||||
else if (proj.equalsIgnoreCase("STR")) {
|
||||
double majorAxis = 6371229.0;
|
||||
double minorAxis = 6371229.0;
|
||||
double lov = rnav[11];
|
||||
double la1 = rnav[6];
|
||||
double lo1 = rnav[7];
|
||||
int nx = (int) rnav[4];
|
||||
int ny = (int) rnav[5];
|
||||
/* TODO calculate dx, dx */
|
||||
double dx = 90.755;
|
||||
double dy = 90.755;
|
||||
crs = MapUtil.constructNorthPolarStereo(majorAxis, minorAxis, 60.0, lov);
|
||||
crsWKT = crs.toWKT();
|
||||
CharSequence spacingUnit = "km";
|
||||
try {
|
||||
Unit<?> spacingUnitObj = Unit.valueOf(spacingUnit);
|
||||
if (spacingUnitObj.isCompatible(SI.METRE)) {
|
||||
UnitConverter converter = spacingUnitObj
|
||||
.getConverterTo(SI.METRE);
|
||||
geometry = MapUtil.createGeometry(crs, la1, lo1, converter
|
||||
.convert(dx), converter.convert(dy), nx, ny);
|
||||
} else {
|
||||
throw new VizException("Unable to convert " + spacingUnit
|
||||
+ " to meters while creating geometry!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new VizException("Error creating geometry", e);
|
||||
}
|
||||
PolarStereoGridCoverage cov = new PolarStereoGridCoverage();
|
||||
cov.setCrs(crs);
|
||||
cov.setCrsWKT(crsWKT);
|
||||
cov.setGeometry(geometry);
|
||||
cov.setLa1(la1);
|
||||
cov.setLo1(lo1);
|
||||
cov.setLov(lov);
|
||||
cov.setNx(Integer.valueOf(nx));
|
||||
cov.setNy(Integer.valueOf(ny));
|
||||
cov.setGridGeometry(MapUtil.getGridGeometry(cov));
|
||||
cov.setName("GEMPAK " + model + rnav[2] + "x" + rnav[3]+ " " + spacingUnit + " grid");
|
||||
cov.setDescription("GEMPAK STR grid");
|
||||
return cov;
|
||||
}
|
||||
else if (proj.equalsIgnoreCase("LCC")) {
|
||||
/* TODO add code for LCC proj */
|
||||
double majorAxis = 6371229.0;
|
||||
double minorAxis = 6371229.0;
|
||||
double lov = rnav[11];
|
||||
double latin1 = rnav[10];
|
||||
double latin2 = rnav[12];
|
||||
double la1 = rnav[6];
|
||||
double lo1 = rnav[7];
|
||||
int nx = (int) rnav[4];
|
||||
int ny = (int) rnav[5];
|
||||
CharSequence spacingUnit = "km";
|
||||
double dx = 12.191;
|
||||
double dy = 12.191;
|
||||
crs = MapUtil.constructLambertConformal(majorAxis, minorAxis, latin1,
|
||||
latin2, lov);
|
||||
crsWKT = crs.toWKT();
|
||||
try {
|
||||
Unit<?> spacingUnitObj = Unit.valueOf(spacingUnit);
|
||||
if (spacingUnitObj.isCompatible(SI.METRE)) {
|
||||
UnitConverter converter = spacingUnitObj
|
||||
.getConverterTo(SI.METRE);
|
||||
geometry = MapUtil.createGeometry(crs, la1, lo1, converter
|
||||
.convert(dx), converter.convert(dy), nx, ny);
|
||||
} else {
|
||||
throw new VizException("Unable to convert " + spacingUnit
|
||||
+ " to meters while creating geometry!");
|
||||
}
|
||||
private static GridDiag gd = GridDiag.getInstance();
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new VizException("Error creating geometry", e);
|
||||
}
|
||||
LambertConformalGridCoverage cov = new LambertConformalGridCoverage();
|
||||
cov.setCrs(crs);
|
||||
cov.setCrsWKT(crsWKT);
|
||||
cov.setGeometry(geometry);
|
||||
cov.setLa1(la1);
|
||||
cov.setLo1(lo1);
|
||||
cov.setLov(lov);
|
||||
cov.setNx(Integer.valueOf(nx));
|
||||
cov.setNy(Integer.valueOf(ny));
|
||||
cov.setGridGeometry(MapUtil.getGridGeometry(cov));
|
||||
cov.setName("GEMPAK " + model + rnav[2] + "x" + rnav[3]+ " " + spacingUnit + " grid");
|
||||
cov.setDescription("GEMPAK LCC grid");
|
||||
return cov;
|
||||
}
|
||||
else if (proj.equalsIgnoreCase("MER")) {
|
||||
/* TODO add code for MER proj */
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a GEMPAK grid filename eg "gfs_2010112818f003"
|
||||
*
|
||||
* @param anAlias
|
||||
* eg "GFS"
|
||||
* @param aLocation
|
||||
* eg "$MODEL/gfs"
|
||||
* @param aTime
|
||||
* eg "2010-11-28 18:00:00.0 (3)"
|
||||
* @return
|
||||
*/
|
||||
private static String constructGridFilename(String anAlias, String aLocation, String aTime) {
|
||||
try {
|
||||
String fileNameTemplate = getGempakGridTemplate(anAlias);
|
||||
IntByReference iret = new IntByReference(0);
|
||||
byte[] theFileName = new byte[50];
|
||||
String gTime = dbtimeToDattim(aTime);
|
||||
String fullPath = aLocation+ "/" + fileNameTemplate;
|
||||
gd.gem.cfl_mnam_ ( gTime, fullPath, theFileName, iret);
|
||||
if ( iret.getValue () != 0 ) {
|
||||
return null;
|
||||
}
|
||||
return Native.toString(theFileName);
|
||||
} catch (VizException e) {
|
||||
// TODO Auto-generated catch block
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts navigation block from GEMPAK grid
|
||||
*
|
||||
* @param aGridFile
|
||||
* @return
|
||||
*/
|
||||
private static float [] getGridNavigationBlock(String aGridFile) {
|
||||
float[] rnav = new float[20];
|
||||
float[] anl = new float[20];
|
||||
IntByReference wrtflg = new IntByReference(-1);
|
||||
IntByReference mxanl = new IntByReference(1);
|
||||
IntByReference mxnav = new IntByReference(20);
|
||||
IntByReference iacss = new IntByReference(0);
|
||||
IntByReference msxgrd = new IntByReference(0);
|
||||
IntByReference iret = new IntByReference(0);
|
||||
IntByReference mode = new IntByReference(0);
|
||||
public final static String gempakPluginName = "gempak_gd"; // ghull added
|
||||
// Dec 19, 2010
|
||||
|
||||
gd.gem.in_bdta_(iret);
|
||||
gd.gem.gd_init_ (iret);
|
||||
gd.gem.gg_init_ (mode,iret);
|
||||
gd.gem.dg_intl_ (iret);
|
||||
/**
|
||||
* Gets the cycle times for a GEMPAK dataLocation from uEngine in
|
||||
* YYMMDD_HHMM format.
|
||||
*
|
||||
* @param aDataLocation
|
||||
* eg "$MODEL/gfs"
|
||||
* @return
|
||||
* @throws VizException
|
||||
*/
|
||||
public static String[] getGridCycleTimes(String aDataLocation, String gdFile)
|
||||
throws VizException {
|
||||
byte[] cycles = new byte[1024];
|
||||
IntByReference iret = new IntByReference(0);
|
||||
gd.gem.in_bdta_(iret);
|
||||
gd.gem.gd_init_(iret);
|
||||
gd.gem.gdc_gcyc_(gdFile, cycles, iret);
|
||||
if (iret.getValue() == 0) {
|
||||
String cycleTime = Native.toString(cycles);
|
||||
String cycleTime1 = cycleTime.replaceAll("/", "_");
|
||||
String[] cycleTimes = cycleTime1.trim().split(";");
|
||||
return cycleTimes;
|
||||
} else {
|
||||
throw new VizException();
|
||||
}
|
||||
// long st1 = System.currentTimeMillis();
|
||||
// StringBuilder query = new StringBuilder();
|
||||
// query.append("import NcModelCycleQuery\n");
|
||||
// query.append("req = NcModelCycleQuery.NcModelCycleQuery()\n");
|
||||
// query.append("req.setDataLocation('" + aDataLocation + "')\n");
|
||||
// query.append("req.setModelName('" + modelname + "')\n");
|
||||
// query.append("return req.execute()");
|
||||
//
|
||||
// String script = query.toString();
|
||||
// try {
|
||||
// String cycleListStr = (String) Connector.getInstance().connect(
|
||||
// script, null, 600000)[0];
|
||||
//
|
||||
// String[] cycleList = cycleListStr.split("\\|");
|
||||
// long st2 = System.currentTimeMillis();
|
||||
// System.out.println ("***get cycleTimes throught Connector took:" +
|
||||
// (st2-st1));
|
||||
// return cycleList;
|
||||
// } catch (VizException e) {
|
||||
// throw new VizException(e);
|
||||
// }
|
||||
}
|
||||
|
||||
gd.gem.gdc_open_ (aGridFile, wrtflg, mxanl, mxnav, iacss,
|
||||
anl, rnav, msxgrd, iret);
|
||||
|
||||
return rnav;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts grid projections from GEMPAK grid navigation block
|
||||
*
|
||||
* @param rnav
|
||||
* @return
|
||||
*/
|
||||
private static String getGridProjection (float[] rnav) {
|
||||
IntByReference iret = new IntByReference(0);
|
||||
byte[] cproj = new byte[5];
|
||||
IntByReference kx = new IntByReference(0);
|
||||
IntByReference ky = new IntByReference(0);
|
||||
gd.gem.grc_rnav_ (rnav, cproj, kx, ky, iret);
|
||||
return Native.toString(cproj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves as a wrapper for the legacy ctb_dtpath function
|
||||
*
|
||||
* @param anAlias
|
||||
* eg "GFS"
|
||||
* @return
|
||||
*/
|
||||
public static String getGempakGridPath ( String anAlias) throws VizException {
|
||||
IntByReference iret = new IntByReference(0);
|
||||
byte[] thePath = new byte[30];
|
||||
gd.gem.ctb_dtpath_ (anAlias, thePath, iret);
|
||||
if ( iret.getValue () != 0 ) {
|
||||
throw new VizException("Alias " + anAlias + " not found in legacy datatype.tbl");
|
||||
}
|
||||
return Native.toString(thePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves as a wrapper for the legacy ctb_dttmpl function
|
||||
*
|
||||
* @param anAlias
|
||||
* eg "GFS"
|
||||
* @return
|
||||
*/
|
||||
public static String getGempakGridTemplate ( String anAlias) throws VizException {
|
||||
IntByReference iret = new IntByReference(0);
|
||||
byte[] theTemplate = new byte[50];
|
||||
gd.gem.ctb_dttmpl_ (anAlias, theTemplate, iret);
|
||||
if ( iret.getValue () != 0 ) {
|
||||
throw new VizException("Alias " + anAlias + " not found in legacy datatype.tbl");
|
||||
}
|
||||
return Native.toString(theTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Converts AWIPS2 date time string into GEMPAK DATTIM string
|
||||
*
|
||||
* @param aTime
|
||||
* eg "2011-10-09 06:20:00.0 (1)"
|
||||
* @return
|
||||
* eq "111009/0620f001"
|
||||
*/
|
||||
private static String dbtimeToDattim(String aTime) {
|
||||
String aDattim = null;
|
||||
String[] inputStringArray = new String[2];
|
||||
|
||||
CharSequence char0 = "(";
|
||||
/*
|
||||
* Process time contains forecast hour info
|
||||
*/
|
||||
if ( aTime.contains(char0) ) {
|
||||
String zeroes = null;
|
||||
int ind1 = aTime.indexOf("(");
|
||||
int ind2 = aTime.indexOf(")");
|
||||
if ( ind2-ind1 == 2 ) {
|
||||
zeroes = "00";
|
||||
}
|
||||
else if ( ind2-ind1 == 3 ) {
|
||||
zeroes = "0";
|
||||
}
|
||||
String str1 = aTime.substring(0, ind1-1);
|
||||
String str2 = "";
|
||||
if ( zeroes != null) {
|
||||
str2 = "f"+zeroes+aTime.substring(ind1+1, ind2);
|
||||
}
|
||||
else {
|
||||
str2 = "f"+aTime.substring(ind1+1, ind2);
|
||||
}
|
||||
|
||||
if ( aTime.contains("_") ) {
|
||||
inputStringArray = str1.split("_");
|
||||
}
|
||||
else if ( ! aTime.contains("_") ) {
|
||||
inputStringArray = str1.split(" ");
|
||||
}
|
||||
/**
|
||||
* Gets the available times for a GEMPAK dataLocation and a current cycle
|
||||
* from uEngine in "YYYY-MM-DD HH:MM:SS.S (fHHH)" format.
|
||||
*
|
||||
* @param aDataLocation
|
||||
* eg "$MODEL/gfs"
|
||||
* @param aCurrentCycle
|
||||
* eg "2010-11-28 18:00:00.0"
|
||||
* @return
|
||||
* @throws VizException
|
||||
*/
|
||||
public static String[] getAvailableGridTimes(String aDataLocation,
|
||||
String aCurrentCycle, String gdFile) throws VizException {
|
||||
byte[] availables = new byte[10000];
|
||||
IntByReference iret = new IntByReference(0);
|
||||
gd.gem.in_bdta_(iret);
|
||||
gd.gem.gd_init_(iret);
|
||||
String cycle = "";
|
||||
if (aCurrentCycle != null) {
|
||||
String[] dtStr = aCurrentCycle.split(" ");
|
||||
cycle = dtStr[0].split("-")[1] + dtStr[0].split("-")[2] + "/"
|
||||
+ dtStr[1].split(":")[0];
|
||||
}
|
||||
gd.gem.gdc_gtmf_(gdFile, cycle, availables, iret);
|
||||
if (iret.getValue() == 0) {
|
||||
String availableTimes = Native.toString(availables);
|
||||
String[] avaTimeStr = availableTimes.trim().split("\\|");
|
||||
String[] avaTimesList = new String[avaTimeStr.length];
|
||||
int i = 0;
|
||||
for (String ava : avaTimeStr) {
|
||||
if (ava.contains("F")) {
|
||||
avaTimesList[i] = aCurrentCycle + " ("
|
||||
+ Integer.parseInt(ava.split("F")[1]) + ")";
|
||||
} else {
|
||||
avaTimesList[i] = aCurrentCycle + " (0)";
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return avaTimesList;
|
||||
} else {
|
||||
throw new VizException();
|
||||
}
|
||||
// long st1 = System.currentTimeMillis();
|
||||
// StringBuilder query = new StringBuilder();
|
||||
// query.append("import NcModelAvailableTimesQuery\n");
|
||||
// query.append("req = NcModelAvailableTimesQuery.NcModelAvailableTimesQuery()\n");
|
||||
// query.append("req.setDataLocation('" + aDataLocation + "')\n");
|
||||
// query.append("req.setModelName('" + modelName + "')\n");
|
||||
// query.append("req.setCurrentCycle('" + aCurrentCycle + "')\n");
|
||||
// query.append("return req.execute()");
|
||||
//
|
||||
// String script = query.toString();
|
||||
// try {
|
||||
// String avTimesListStr = (String) Connector.getInstance().connect(
|
||||
// script, null, 600000)[0];
|
||||
// String[] avTimesList = avTimesListStr.split("\\|");
|
||||
// long st2 = System.currentTimeMillis();
|
||||
// System.out.println ("===get availableTimes throught connector took:"
|
||||
// + (st2-st1));
|
||||
// return avTimesList;
|
||||
// } catch (VizException e) {
|
||||
// throw new VizException(e);
|
||||
// }
|
||||
}
|
||||
|
||||
/*
|
||||
* YYYY-MM-DD HH:MM:SS.S (HHH)-> YYMMDD/HHMMfHHH
|
||||
* 2009-10-22 16:00:00.0 (5)-> 091022/1600f005
|
||||
* 0123456789 0123456789
|
||||
*/
|
||||
aDattim = inputStringArray[0].substring(2, 4)
|
||||
+ inputStringArray[0].substring(5, 7)
|
||||
+ inputStringArray[0].substring(8, 10) + "/"
|
||||
+ inputStringArray[1].substring(0, 2)
|
||||
+ inputStringArray[1].substring(3, 5) + str2;
|
||||
}
|
||||
/*
|
||||
* Process time that does NOT contain forecast hour info
|
||||
*/
|
||||
else {
|
||||
inputStringArray = aTime.split(" ");
|
||||
/**
|
||||
* Gets the navigation information from a GEMPAK grid file and returns the
|
||||
* coverage object.
|
||||
*
|
||||
* @param aDataLocation
|
||||
* eg "$MODEL/gfs"
|
||||
* @param aCurrentCycle
|
||||
* eg "2010-11-28 18:00:00.0"
|
||||
* @return
|
||||
* @throws VizException
|
||||
*/
|
||||
public static ISpatialObject getGridNavigation(String anAlias,
|
||||
String aDataLocation, String aCurrentCycle) throws VizException {
|
||||
int numberOfLayers = aDataLocation.split("/").length;
|
||||
String model = aDataLocation.split("/")[numberOfLayers - 1];
|
||||
String gdfile = constructGridFilename(anAlias, aDataLocation,
|
||||
aCurrentCycle);
|
||||
float[] rnav = getGridNavigationBlock(gdfile);
|
||||
String proj = getGridProjection(rnav);
|
||||
|
||||
/*
|
||||
* YYYY-MM-DD HH:MM:SS.S -> YYMMDD/HHMM
|
||||
* 2009-01-20 02:25:00.0 -> 090120/0225
|
||||
* 0123456789 0123456789
|
||||
*/
|
||||
aDattim = inputStringArray[0].substring(2, 4)
|
||||
+ inputStringArray[0].substring(5, 7)
|
||||
+ inputStringArray[0].substring(8, 10) + "/"
|
||||
+ inputStringArray[1].substring(0, 2)
|
||||
+ inputStringArray[1].substring(3, 5);
|
||||
}
|
||||
return aDattim;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts GEMPAK DATTIM string into AWIPS2 date time string
|
||||
*/
|
||||
public static String dattimToDbtime(String aDattim) {
|
||||
aDattim = aDattim.toUpperCase();
|
||||
String retDateTime = null;
|
||||
String[] inputStringArray = new String[2];
|
||||
CharSequence char0 = "F";
|
||||
if ( aDattim.contains(char0) ) {
|
||||
|
||||
int ind1 = aDattim.indexOf("F00");
|
||||
int addChars = 3;
|
||||
if ( ind1 == -1 ) {
|
||||
ind1 = aDattim.indexOf("F0");
|
||||
addChars = 2;
|
||||
}
|
||||
if ( ind1 == -1 ) {
|
||||
ind1 = aDattim.indexOf("F");
|
||||
addChars = 1;
|
||||
}
|
||||
int ind2 = aDattim.length();
|
||||
|
||||
String str1 = aDattim.substring(0, ind1);
|
||||
String str2 = aDattim.substring(ind1+addChars,ind2 );
|
||||
inputStringArray = str1.split("/");
|
||||
DefaultGeographicCRS WGS84 = DefaultGeographicCRS.WGS84;
|
||||
CoordinateReferenceSystem crs;
|
||||
String crsWKT;
|
||||
Polygon geometry;
|
||||
|
||||
/*
|
||||
* YYMMDD/HHMMfHHH -> YYYY-MM-DD HH:MM:SS.S
|
||||
* 090120/0225f005 -> 2009-01-20 02:25:00.0
|
||||
* 012345 0123
|
||||
*/
|
||||
retDateTime = "20" + inputStringArray[0].substring(0, 2) + "-"
|
||||
+ inputStringArray[0].substring(2, 4) + "-"
|
||||
+ inputStringArray[0].substring(4, 6) + "_"
|
||||
+ inputStringArray[1].substring(0, 2) + ":"
|
||||
+ inputStringArray[1].substring(2, 4) + ":00.0_("+ str2 + ")";
|
||||
}
|
||||
/*
|
||||
* Process time that does NOT contain forecast hour info
|
||||
*/
|
||||
else {
|
||||
inputStringArray = aDattim.split("/");
|
||||
if (proj.equalsIgnoreCase("CED")) {
|
||||
double minLat = MapUtil.correctLat(rnav[6]);
|
||||
double maxLat = MapUtil.correctLat(rnav[8]);
|
||||
double minLon = MapUtil.correctLon(rnav[7]);
|
||||
double maxLon = MapUtil.correctLon(rnav[9]);
|
||||
if (maxLon < minLon) {
|
||||
maxLon += 360.0;
|
||||
}
|
||||
if (maxLon > 180) {
|
||||
crs = new DefaultGeographicCRS(new DefaultGeodeticDatum(
|
||||
"WGS84", WGS84.getDatum().getEllipsoid(),
|
||||
new DefaultPrimeMeridian("DateLine", 180.0)),
|
||||
WGS84.getCoordinateSystem());
|
||||
} else {
|
||||
crs = WGS84;
|
||||
}
|
||||
crsWKT = crs.toWKT();
|
||||
try {
|
||||
geometry = MapUtil.createGeometry(minLat, minLon, maxLat,
|
||||
maxLon);
|
||||
} catch (Exception e) {
|
||||
throw new VizException("Error creating geometry", e);
|
||||
}
|
||||
CharSequence spacingUnit = "degree";
|
||||
|
||||
/*
|
||||
* YYMMDD/HHMM -> YYYY-MM-DD HH:MM:SS.S
|
||||
* 090120/0225 -> 2009-01-2002:25:00.0
|
||||
* s012345 0123
|
||||
*/
|
||||
retDateTime = "20" + inputStringArray[0].substring(0, 2) + "-"
|
||||
+ inputStringArray[0].substring(2, 4) + "-"
|
||||
+ inputStringArray[0].substring(4, 6) + " "
|
||||
+ inputStringArray[1].substring(0, 2) + ":"
|
||||
+ inputStringArray[1].substring(2, 4) + ":00.0";
|
||||
}
|
||||
LatLonGridCoverage cov = new LatLonGridCoverage();
|
||||
cov.setSpacingUnit(spacingUnit.toString());
|
||||
cov.setDx(rnav[2]);
|
||||
cov.setDy(rnav[3]);
|
||||
int nx = (int) rnav[4];
|
||||
cov.setNx(Integer.valueOf(nx));
|
||||
int ny = (int) rnav[5];
|
||||
cov.setNy(Integer.valueOf(ny));
|
||||
cov.setCrs(crs);
|
||||
cov.setCrsWKT(crsWKT);
|
||||
cov.setGeometry(geometry);
|
||||
cov.setLa1(minLat);
|
||||
cov.setLa2(maxLat);
|
||||
cov.setLo1(minLon);
|
||||
cov.setLo2(maxLon);
|
||||
cov.setName("GEMPAK " + model + rnav[2] + "x" + rnav[3] + " "
|
||||
+ spacingUnit + " grid");
|
||||
cov.setGridGeometry(MapUtil.getGridGeometry(cov));
|
||||
cov.setDescription("GEMPAK CED grid");
|
||||
return cov;
|
||||
} else if (proj.equalsIgnoreCase("STR")) {
|
||||
double majorAxis = 6371229.0;
|
||||
double minorAxis = 6371229.0;
|
||||
double lov = rnav[11];
|
||||
double la1 = rnav[6];
|
||||
double lo1 = rnav[7];
|
||||
int nx = (int) rnav[4];
|
||||
int ny = (int) rnav[5];
|
||||
/* TODO calculate dx, dx */
|
||||
double dx = 90.755;
|
||||
double dy = 90.755;
|
||||
crs = MapUtil.constructNorthPolarStereo(majorAxis, minorAxis, 60.0,
|
||||
lov);
|
||||
crsWKT = crs.toWKT();
|
||||
CharSequence spacingUnit = "km";
|
||||
try {
|
||||
Unit<?> spacingUnitObj = Unit.valueOf(spacingUnit);
|
||||
if (spacingUnitObj.isCompatible(SI.METRE)) {
|
||||
UnitConverter converter = spacingUnitObj
|
||||
.getConverterTo(SI.METRE);
|
||||
geometry = MapUtil.createGeometry(crs, la1, lo1,
|
||||
converter.convert(dx), converter.convert(dy), nx,
|
||||
ny);
|
||||
} else {
|
||||
throw new VizException("Unable to convert " + spacingUnit
|
||||
+ " to meters while creating geometry!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new VizException("Error creating geometry", e);
|
||||
}
|
||||
PolarStereoGridCoverage cov = new PolarStereoGridCoverage();
|
||||
cov.setCrs(crs);
|
||||
cov.setCrsWKT(crsWKT);
|
||||
cov.setGeometry(geometry);
|
||||
cov.setLa1(la1);
|
||||
cov.setLo1(lo1);
|
||||
cov.setLov(lov);
|
||||
cov.setNx(Integer.valueOf(nx));
|
||||
cov.setNy(Integer.valueOf(ny));
|
||||
cov.setGridGeometry(MapUtil.getGridGeometry(cov));
|
||||
cov.setName("GEMPAK " + model + rnav[2] + "x" + rnav[3] + " "
|
||||
+ spacingUnit + " grid");
|
||||
cov.setDescription("GEMPAK STR grid");
|
||||
return cov;
|
||||
} else if (proj.equalsIgnoreCase("LCC")) {
|
||||
/* TODO add code for LCC proj */
|
||||
double majorAxis = 6371229.0;
|
||||
double minorAxis = 6371229.0;
|
||||
double lov = rnav[11];
|
||||
double latin1 = rnav[10];
|
||||
double latin2 = rnav[12];
|
||||
double la1 = rnav[6];
|
||||
double lo1 = rnav[7];
|
||||
int nx = (int) rnav[4];
|
||||
int ny = (int) rnav[5];
|
||||
CharSequence spacingUnit = "km";
|
||||
double dx = 12.191;
|
||||
double dy = 12.191;
|
||||
crs = MapUtil.constructLambertConformal(majorAxis, minorAxis,
|
||||
latin1, latin2, lov);
|
||||
crsWKT = crs.toWKT();
|
||||
try {
|
||||
Unit<?> spacingUnitObj = Unit.valueOf(spacingUnit);
|
||||
if (spacingUnitObj.isCompatible(SI.METRE)) {
|
||||
UnitConverter converter = spacingUnitObj
|
||||
.getConverterTo(SI.METRE);
|
||||
geometry = MapUtil.createGeometry(crs, la1, lo1,
|
||||
converter.convert(dx), converter.convert(dy), nx,
|
||||
ny);
|
||||
} else {
|
||||
throw new VizException("Unable to convert " + spacingUnit
|
||||
+ " to meters while creating geometry!");
|
||||
}
|
||||
|
||||
return retDateTime;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new VizException("Error creating geometry", e);
|
||||
}
|
||||
LambertConformalGridCoverage cov = new LambertConformalGridCoverage();
|
||||
cov.setCrs(crs);
|
||||
cov.setCrsWKT(crsWKT);
|
||||
cov.setGeometry(geometry);
|
||||
cov.setLa1(la1);
|
||||
cov.setLo1(lo1);
|
||||
cov.setLov(lov);
|
||||
cov.setNx(Integer.valueOf(nx));
|
||||
cov.setNy(Integer.valueOf(ny));
|
||||
cov.setGridGeometry(MapUtil.getGridGeometry(cov));
|
||||
cov.setName("GEMPAK " + model + rnav[2] + "x" + rnav[3] + " "
|
||||
+ spacingUnit + " grid");
|
||||
cov.setDescription("GEMPAK LCC grid");
|
||||
return cov;
|
||||
} else if (proj.equalsIgnoreCase("MER")) {
|
||||
/* TODO add code for MER proj */
|
||||
return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a GEMPAK grid filename eg "gfs_2010112818f003"
|
||||
*
|
||||
* @param anAlias
|
||||
* eg "GFS"
|
||||
* @param aLocation
|
||||
* eg "$MODEL/gfs"
|
||||
* @param aTime
|
||||
* eg "2010-11-28 18:00:00.0 (3)"
|
||||
* @return
|
||||
*/
|
||||
private static String constructGridFilename(String anAlias,
|
||||
String aLocation, String aTime) {
|
||||
try {
|
||||
String fileNameTemplate = getGempakGridTemplate(anAlias);
|
||||
IntByReference iret = new IntByReference(0);
|
||||
byte[] theFileName = new byte[50];
|
||||
String gTime = CommonDateFormatUtil.dbtimeToDattim(aTime);
|
||||
String fullPath = aLocation + "/" + fileNameTemplate;
|
||||
gd.gem.cfl_mnam_(gTime, fullPath, theFileName, iret);
|
||||
if (iret.getValue() != 0) {
|
||||
return null;
|
||||
}
|
||||
return Native.toString(theFileName);
|
||||
} catch (VizException e) {
|
||||
// TODO Auto-generated catch block
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts navigation block from GEMPAK grid
|
||||
*
|
||||
* @param aGridFile
|
||||
* @return
|
||||
*/
|
||||
private static float[] getGridNavigationBlock(String aGridFile) {
|
||||
float[] rnav = new float[20];
|
||||
float[] anl = new float[20];
|
||||
IntByReference wrtflg = new IntByReference(-1);
|
||||
IntByReference mxanl = new IntByReference(1);
|
||||
IntByReference mxnav = new IntByReference(20);
|
||||
IntByReference iacss = new IntByReference(0);
|
||||
IntByReference msxgrd = new IntByReference(0);
|
||||
IntByReference iret = new IntByReference(0);
|
||||
IntByReference mode = new IntByReference(0);
|
||||
|
||||
gd.gem.in_bdta_(iret);
|
||||
gd.gem.gd_init_(iret);
|
||||
gd.gem.gg_init_(mode, iret);
|
||||
gd.gem.dg_intl_(iret);
|
||||
|
||||
gd.gem.gdc_open_(aGridFile, wrtflg, mxanl, mxnav, iacss, anl, rnav,
|
||||
msxgrd, iret);
|
||||
|
||||
return rnav;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts grid projections from GEMPAK grid navigation block
|
||||
*
|
||||
* @param rnav
|
||||
* @return
|
||||
*/
|
||||
private static String getGridProjection(float[] rnav) {
|
||||
IntByReference iret = new IntByReference(0);
|
||||
byte[] cproj = new byte[5];
|
||||
IntByReference kx = new IntByReference(0);
|
||||
IntByReference ky = new IntByReference(0);
|
||||
gd.gem.grc_rnav_(rnav, cproj, kx, ky, iret);
|
||||
return Native.toString(cproj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves as a wrapper for the legacy ctb_dtpath function
|
||||
*
|
||||
* @param anAlias
|
||||
* eg "GFS"
|
||||
* @return
|
||||
*/
|
||||
public static String getGempakGridPath(String anAlias) throws VizException {
|
||||
IntByReference iret = new IntByReference(0);
|
||||
byte[] thePath = new byte[30];
|
||||
gd.gem.ctb_dtpath_(anAlias, thePath, iret);
|
||||
if (iret.getValue() != 0) {
|
||||
throw new VizException("Alias " + anAlias
|
||||
+ " not found in legacy datatype.tbl");
|
||||
}
|
||||
return Native.toString(thePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves as a wrapper for the legacy ctb_dttmpl function
|
||||
*
|
||||
* @param anAlias
|
||||
* eg "GFS"
|
||||
* @return
|
||||
*/
|
||||
public static String getGempakGridTemplate(String anAlias)
|
||||
throws VizException {
|
||||
IntByReference iret = new IntByReference(0);
|
||||
byte[] theTemplate = new byte[50];
|
||||
gd.gem.ctb_dttmpl_(anAlias, theTemplate, iret);
|
||||
if (iret.getValue() != 0) {
|
||||
throw new VizException("Alias " + anAlias
|
||||
+ " not found in legacy datatype.tbl");
|
||||
}
|
||||
return Native.toString(theTemplate);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@ package gov.noaa.nws.ncep.viz.rsc.ncgrid.dgdriv;
|
|||
import gov.noaa.nws.ncep.common.log.logger.NcepLogger;
|
||||
import gov.noaa.nws.ncep.common.log.logger.NcepLoggerManager;
|
||||
import gov.noaa.nws.ncep.edex.common.dataRecords.NcFloatDataRecord;
|
||||
import gov.noaa.nws.ncep.viz.common.util.CommonDateFormatUtil;
|
||||
import gov.noaa.nws.ncep.viz.gempak.grid.jna.GridDiag;
|
||||
import gov.noaa.nws.ncep.viz.gempak.grid.jna.GridDiag.gempak;
|
||||
import gov.noaa.nws.ncep.viz.gempak.grid.units.GempakGridParmInfoLookup;
|
||||
import gov.noaa.nws.ncep.viz.gempak.grid.units.GempakGridVcrdInfoLookup;
|
||||
import gov.noaa.nws.ncep.viz.gempak.util.GempakGrid;
|
||||
import gov.noaa.nws.ncep.viz.rsc.ncgrid.NcgribLogger;
|
||||
import gov.noaa.nws.ncep.viz.rsc.ncgrid.customCoverage.CustomLambertConformalCoverage;
|
||||
import gov.noaa.nws.ncep.viz.rsc.ncgrid.customCoverage.CustomLatLonCoverage;
|
||||
|
@ -22,7 +22,6 @@ import gov.noaa.nws.ncep.viz.rsc.ncgrid.rsc.NcEnsembleResourceData;
|
|||
import gov.noaa.nws.ncep.viz.rsc.ncgrid.rsc.NcgridResourceData;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -136,6 +135,8 @@ public class Dgdriv {
|
|||
private String gdfile, gdpfun, gdattim, glevel, gvcord, scale, garea,
|
||||
dataSource;
|
||||
|
||||
private String gempakTime;
|
||||
|
||||
private boolean scalar, arrowVector, flop, flip;
|
||||
|
||||
private String gdfileOriginal;
|
||||
|
@ -148,6 +149,8 @@ public class Dgdriv {
|
|||
|
||||
private ArrayList<DataTime> dataForecastTimes;
|
||||
|
||||
private int forecastTimeInSec;
|
||||
|
||||
private NcgridDataCache cacheData;
|
||||
|
||||
private static NcgribLogger ncgribLogger = NcgribLogger.getInstance();;
|
||||
|
@ -158,9 +161,6 @@ public class Dgdriv {
|
|||
* TODO Work around solution - need to find a way to set logging level
|
||||
* programmatically
|
||||
*/
|
||||
private static final DecimalFormat forecastHourFormat = new DecimalFormat(
|
||||
"000");
|
||||
|
||||
private static String[] nativeLogTypes = { "|critical", "|error", "|info",
|
||||
"|debug" };
|
||||
|
||||
|
@ -238,6 +238,9 @@ public class Dgdriv {
|
|||
|
||||
public void setGdattim(String gdattim) {
|
||||
this.gdattim = gdattim;
|
||||
this.gempakTime = CommonDateFormatUtil.dbtimeToDattim(gdattim);
|
||||
this.forecastTimeInSec = CommonDateFormatUtil
|
||||
.getForecastTimeInSec(gempakTime);
|
||||
}
|
||||
|
||||
public void setGlevel(String glevel) {
|
||||
|
@ -674,7 +677,7 @@ public class Dgdriv {
|
|||
"From db_init: error initializing DB common area");
|
||||
}
|
||||
|
||||
String currentTime = dbtimeToDattim(gdattim);
|
||||
String currentTime = gempakTime;
|
||||
gd.gem.db_wsetnavtime_(currentTime, iret);
|
||||
if (iret.getValue() != 0) {
|
||||
throw new DgdrivException(
|
||||
|
@ -730,7 +733,7 @@ public class Dgdriv {
|
|||
// else {
|
||||
// gd.gem.dgc_ndtm_ (dbtimeToDattim(gdattim), iret);
|
||||
// }
|
||||
gd.gem.dgc_ndtm_(dbtimeToDattim(gdattim), iret);
|
||||
gd.gem.dgc_ndtm_(gempakTime, iret);
|
||||
if (iret.getValue() != 0) {
|
||||
gd.gem.erc_wmsg("DG", iret, "", ier);
|
||||
proces = false;
|
||||
|
@ -1306,72 +1309,13 @@ public class Dgdriv {
|
|||
// TODO Auto-generated method stub
|
||||
StringBuilder resultsBuf = new StringBuilder();
|
||||
for (DataTime dt : dataForecastTimes) {
|
||||
resultsBuf.append(dbtimeToDattim(dt.toString()));
|
||||
resultsBuf
|
||||
.append(CommonDateFormatUtil.dbtimeToDattim(dt.toString()));
|
||||
resultsBuf.append("|");
|
||||
}
|
||||
return resultsBuf.substring(0, resultsBuf.length() - 1);
|
||||
}
|
||||
|
||||
private String dbtimeToDattim(String aTime) {
|
||||
String aDattim = null;
|
||||
String[] inputStringArray = new String[2];
|
||||
|
||||
CharSequence char0 = "(";
|
||||
/*
|
||||
* Process time contains forecast hour info
|
||||
*/
|
||||
if (aTime.contains(char0)) {
|
||||
String zeroes = null;
|
||||
int ind1 = aTime.indexOf("(");
|
||||
int ind2 = aTime.indexOf(")");
|
||||
if (ind2 - ind1 == 2) {
|
||||
zeroes = "00";
|
||||
} else if (ind2 - ind1 == 3) {
|
||||
zeroes = "0";
|
||||
}
|
||||
String str1 = aTime.substring(0, ind1 - 1);
|
||||
String str2 = "";
|
||||
if (zeroes != null) {
|
||||
str2 = "f" + zeroes + aTime.substring(ind1 + 1, ind2);
|
||||
} else {
|
||||
str2 = "f" + aTime.substring(ind1 + 1, ind2);
|
||||
}
|
||||
|
||||
if (aTime.contains("_")) {
|
||||
inputStringArray = str1.split("_");
|
||||
} else if (!aTime.contains("_")) {
|
||||
inputStringArray = str1.split(" ");
|
||||
}
|
||||
|
||||
/*
|
||||
* YYYY-MM-DD HH:MM:SS.S (HHH)-> YYMMDD/HHMMfHHH 2009-10-22
|
||||
* 16:00:00.0 (5)-> 091022/1600f005 0123456789 0123456789
|
||||
*/
|
||||
aDattim = inputStringArray[0].substring(2, 4)
|
||||
+ inputStringArray[0].substring(5, 7)
|
||||
+ inputStringArray[0].substring(8, 10) + "/"
|
||||
+ inputStringArray[1].substring(0, 2)
|
||||
+ inputStringArray[1].substring(3, 5) + str2;
|
||||
}
|
||||
/*
|
||||
* Process time that does NOT contain forecast hour info
|
||||
*/
|
||||
else {
|
||||
inputStringArray = aTime.split(" ");
|
||||
|
||||
/*
|
||||
* YYYY-MM-DD HH:MM:SS.S -> YYMMDD/HHMM 2009-01-20 02:25:00.0 ->
|
||||
* 090120/0225 0123456789 0123456789
|
||||
*/
|
||||
aDattim = inputStringArray[0].substring(2, 4)
|
||||
+ inputStringArray[0].substring(5, 7)
|
||||
+ inputStringArray[0].substring(8, 10) + "/"
|
||||
+ inputStringArray[1].substring(0, 2)
|
||||
+ inputStringArray[1].substring(3, 5);
|
||||
}
|
||||
return aDattim;
|
||||
}
|
||||
|
||||
/*
|
||||
* Flips the data from CAVE order and changes the missing data value from
|
||||
* CAVE -999999.0f to GEMPAK -9999.0f
|
||||
|
@ -1533,24 +1477,15 @@ public class Dgdriv {
|
|||
StringBuilder sb = new StringBuilder();
|
||||
String[] tmStr = uriStr[2].split("_");
|
||||
String dataDateStr = tmStr[0];
|
||||
String fhrs = tmStr[2].substring(tmStr[2].indexOf("(") + 1,
|
||||
tmStr[2].indexOf(")"));
|
||||
String fhStr;
|
||||
if (fhrs == null) {
|
||||
fhStr = "000";
|
||||
} else {
|
||||
int number = 0;
|
||||
try {
|
||||
number = Integer.parseInt(fhrs);
|
||||
} catch (NumberFormatException e) {
|
||||
//
|
||||
}
|
||||
fhStr = forecastHourFormat.format(number);
|
||||
}
|
||||
int fcstTimeInSec = CommonDateFormatUtil
|
||||
.getForecastTimeInSec(uriStr[2]);
|
||||
String fcstTimeStr = CommonDateFormatUtil
|
||||
.getForecastTimeString(fcstTimeInSec);
|
||||
|
||||
sb.append(path);
|
||||
sb.append("-");
|
||||
sb.append(dataDateStr);
|
||||
String dataTimeStr = tmStr[1].split(":")[0] + "-FH-" + fhStr;
|
||||
String dataTimeStr = tmStr[1].split(":")[0] + "-FH-" + fcstTimeStr;
|
||||
sb.append("-");
|
||||
sb.append(dataTimeStr);
|
||||
sb.append(".h5");
|
||||
|
@ -1855,13 +1790,13 @@ public class Dgdriv {
|
|||
|
||||
String prefix = modelName + "_" + dbTag + "_" + eventName + "_";
|
||||
for (int i = 0; i < responseList.size(); i++) {
|
||||
Object fhrValue = responseList.get(i).get(
|
||||
Object fSecValue = responseList.get(i).get(
|
||||
GridDBConstants.FORECAST_TIME_QUERY);
|
||||
Object refValue = responseList.get(i).get(
|
||||
GridDBConstants.REF_TIME_QUERY);
|
||||
if (fhrValue != null && fhrValue instanceof Integer
|
||||
if (fSecValue != null && fSecValue instanceof Integer
|
||||
&& refValue != null && refValue instanceof Date) {
|
||||
int fhr = ((Integer) fhrValue).intValue() / 3600;
|
||||
int fcstTimeInSec = ((Integer) fSecValue).intValue();
|
||||
DataTime refTime = new DataTime((Date) refValue);
|
||||
String[] dts = refTime.toString().split(" ");
|
||||
|
||||
|
@ -1872,8 +1807,13 @@ public class Dgdriv {
|
|||
retFileNames = retFileNames + "|";
|
||||
}
|
||||
|
||||
retFileNames = retFileNames + prefix + dt + hh + "f"
|
||||
+ forecastHourFormat.format(fhr);
|
||||
retFileNames = retFileNames
|
||||
+ prefix
|
||||
+ dt
|
||||
+ hh
|
||||
+ "f"
|
||||
+ CommonDateFormatUtil
|
||||
.getForecastTimeString(fcstTimeInSec);
|
||||
}
|
||||
}
|
||||
} catch (VizException e) {
|
||||
|
@ -1895,8 +1835,9 @@ public class Dgdriv {
|
|||
|
||||
try {
|
||||
Date date = sdf.parse(times[0]);
|
||||
int fhr = Integer.parseInt(times[1]) * 3600;
|
||||
dt = new DataTime(date, fhr);
|
||||
int fcstTimeInSec = CommonDateFormatUtil
|
||||
.getForecastTimeInSec(gempakTimeStr);
|
||||
dt = new DataTime(date, fcstTimeInSec);
|
||||
} catch (Exception e) {
|
||||
dt = null;
|
||||
}
|
||||
|
@ -1974,19 +1915,20 @@ public class Dgdriv {
|
|||
|
||||
long t1 = System.currentTimeMillis();
|
||||
if (ncgribLogger.enableDiagnosticLogs()) {
|
||||
String[] parmList = parameters.split("\\|");
|
||||
String refTimeg = parmList[5].toUpperCase().split("F")[0];
|
||||
String refTime = GempakGrid.dattimToDbtime(refTimeg);
|
||||
refTime = refTime.substring(0, refTime.length() - 2);
|
||||
String fcstTimeg = parmList[5].toUpperCase().split("F")[1];
|
||||
String refTime = rcMap.get(GridDBConstants.REF_TIME_QUERY)
|
||||
.getConstraintValue();
|
||||
int fcstTime = Integer.parseInt(rcMap.get(
|
||||
GridDBConstants.FORECAST_TIME_QUERY).getConstraintValue());
|
||||
String fcstTimeg = CommonDateFormatUtil
|
||||
.getForecastColonTimeString(fcstTime);
|
||||
if (datauri != null) {
|
||||
logger.info("### getDataURIFromAssembler(" + datauri + ") for("
|
||||
+ parameters + ") reftime:" + refTime + "("
|
||||
+ Integer.parseInt(fcstTimeg) + ") took: " + (t1 - t0));
|
||||
+ parameters + ") reftime:" + refTime + "(" + fcstTimeg
|
||||
+ ") took: " + (t1 - t0));
|
||||
} else {
|
||||
logger.info("??? getDataURIFromAssembler(null) for("
|
||||
+ parameters + ") reftime:" + refTime + "("
|
||||
+ Integer.parseInt(fcstTimeg) + ") took: " + (t1 - t0));
|
||||
+ parameters + ") reftime:" + refTime + "(" + fcstTimeg
|
||||
+ ") took: " + (t1 - t0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2251,16 +2193,13 @@ public class Dgdriv {
|
|||
return null;
|
||||
}
|
||||
String refTimeg = parmList[5].toUpperCase().split("F")[0];
|
||||
String refTime = GempakGrid.dattimToDbtime(refTimeg);
|
||||
refTime = refTime.substring(0, refTime.length() - 2);
|
||||
String fcstTimeg = parmList[5].toUpperCase().split("F")[1];
|
||||
String fcstTime = Integer
|
||||
.toString(((Integer.parseInt(fcstTimeg)) * 3600));
|
||||
String refTime = CommonDateFormatUtil.dattimToDbtime(refTimeg);
|
||||
String fcstTimeInSec = Integer.toString(forecastTimeInSec);
|
||||
|
||||
rcMap.put(GridDBConstants.REF_TIME_QUERY,
|
||||
new RequestConstraint(refTime));
|
||||
rcMap.put(GridDBConstants.FORECAST_TIME_QUERY, new RequestConstraint(
|
||||
fcstTime));
|
||||
fcstTimeInSec));
|
||||
if (ncgribLogger.enableDiagnosticLogs()) {
|
||||
logger.info("exit getRequestConstraint - rcMap:" + rcMap.toString());
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -15,6 +15,7 @@ import gov.noaa.nws.ncep.viz.common.preferences.GraphicsAreaPreferences;
|
|||
import gov.noaa.nws.ncep.viz.common.ui.HILORelativeMinAndMaxLocator;
|
||||
import gov.noaa.nws.ncep.viz.common.ui.ModelListInfo;
|
||||
import gov.noaa.nws.ncep.viz.common.ui.color.GempakColor;
|
||||
import gov.noaa.nws.ncep.viz.common.util.CommonDateFormatUtil;
|
||||
import gov.noaa.nws.ncep.viz.gempak.util.GempakGrid;
|
||||
import gov.noaa.nws.ncep.viz.resources.AbstractNatlCntrsResource;
|
||||
import gov.noaa.nws.ncep.viz.resources.INatlCntrsResource;
|
||||
|
@ -2970,7 +2971,7 @@ public class NcgridResource extends
|
|||
*/
|
||||
if (posF > posV && posV != 0) {
|
||||
cal = cTime.getRefTimeAsCalendar();
|
||||
timestampFormat = "%02d%02d%02d/%02d%02dF%03d";
|
||||
timestampFormat = "%02d%02d%02d/%02d%02dF%s";
|
||||
/*
|
||||
* Legacy behavior will put the forcast time at the next
|
||||
* position after the ^ when there is both ~ and ^ the ^ is
|
||||
|
@ -2985,9 +2986,11 @@ public class NcgridResource extends
|
|||
}
|
||||
} else {
|
||||
cal = currFrameTm.getValidTime();
|
||||
timestampFormat = "%02d%02d%02d/%02d%02dV%03d";
|
||||
timestampFormat = "%02d%02d%02d/%02d%02dV%s";
|
||||
}
|
||||
int vTm = cTime.getFcstTime() / 3600;
|
||||
String forecastTime = CommonDateFormatUtil
|
||||
.getForecastTimeString(cTime.getFcstTime());
|
||||
|
||||
/*
|
||||
* check '?' flag for day of week
|
||||
*/
|
||||
|
@ -3004,7 +3007,7 @@ public class NcgridResource extends
|
|||
(cal.get(Calendar.MONTH) + 1),
|
||||
cal.get(Calendar.DAY_OF_MONTH),
|
||||
cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE),
|
||||
vTm));
|
||||
forecastTime));
|
||||
|
||||
deleteWildcard(titleBuilder, "^");
|
||||
deleteWildcard(titleBuilder, "~");
|
||||
|
|
|
@ -0,0 +1,341 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package gov.noaa.nws.ncep.viz.common.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* TODO Add Description
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Aug 28, 2014 jbernier Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author jbernier
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class CommonDateFormatUtilTest {
|
||||
|
||||
private static final int MIN15_IN_SECONDS = 900;
|
||||
|
||||
private static final int HR6_IN_SECONDS = 21600;
|
||||
|
||||
private static final int HR6_15MIN_IN_SECONDS = 22500;
|
||||
|
||||
private static final int HR30_45MIN_IN_SECONDS = 110700;
|
||||
|
||||
private static final int HR36_30MIN_IN_SECONDS = 131400;
|
||||
|
||||
private static final int HR120_IN_SECONDS = 432000;
|
||||
|
||||
private static final int HR136_30MIN_IN_SECONDS = 491400;
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link gov.noaa.nws.ncep.viz.common.util.GempakGrid#dbtimeToDattim(java.lang.String)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testDbTimeToDattim() {
|
||||
System.out
|
||||
.println("------------------Test-case DbTimeToDattim----------------");
|
||||
String dbTime1 = "2014-07-24 12:00:00.0";
|
||||
String dattim1 = CommonDateFormatUtil.dbtimeToDattim(dbTime1);
|
||||
System.out.println("AWIPS: " + dbTime1 + " to GEMPAK: " + dattim1);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"140724/120000", dattim1);
|
||||
|
||||
String dbTime2 = "2014-07-25 12:00:00.0 (6)";
|
||||
String dattim2 = CommonDateFormatUtil.dbtimeToDattim(dbTime2);
|
||||
System.out.println("AWIPS: " + dbTime2 + " to GEMPAK: " + dattim2);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"140725/120000f006", dattim2);
|
||||
|
||||
String dbTime3 = "2014-07-26 12:00:00.0 (36)";
|
||||
String dattim3 = CommonDateFormatUtil.dbtimeToDattim(dbTime3);
|
||||
System.out.println("AWIPS: " + dbTime3 + " to GEMPAK: " + dattim3);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"140726/120000f036", dattim3);
|
||||
|
||||
String dbTime4 = "2014-07-27_12:00:00.0 (120)";
|
||||
String dattim4 = CommonDateFormatUtil.dbtimeToDattim(dbTime4);
|
||||
System.out.println("AWIPS: " + dbTime4 + " to GEMPAK: " + dattim4);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"140727/120000f120", dattim4);
|
||||
|
||||
String dbTime5 = "2014-07-30_12:00:00.0 (0:15)";
|
||||
String dattim5 = CommonDateFormatUtil.dbtimeToDattim(dbTime5);
|
||||
System.out.println("AWIPS: " + dbTime5 + " to GEMPAK: " + dattim5);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"140730/120000f00015", dattim5);
|
||||
|
||||
String dbTime6 = "2014-08-08 12:00:00.0 (30:45)";
|
||||
String dattim6 = CommonDateFormatUtil.dbtimeToDattim(dbTime6);
|
||||
System.out.println("AWIPS: " + dbTime6 + " to GEMPAK: " + dattim6);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"140808/120000f03045", dattim6);
|
||||
|
||||
String dbTime7 = "2014-08-07 12:00:00.0 (036:30)";
|
||||
String dattim7 = CommonDateFormatUtil.dbtimeToDattim(dbTime7);
|
||||
System.out.println("AWIPS: " + dbTime7 + " to GEMPAK: " + dattim7);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"140807/120000f03630", dattim7);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link gov.noaa.nws.ncep.viz.common.util.CommonDateFormatUtil#dattimToDbtime(java.lang.String)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testDattimToDbTime() {
|
||||
System.out
|
||||
.println("------------------Test-case DattimToDbTime----------------");
|
||||
String dattim1 = "140724/120000";
|
||||
String dbTime1 = CommonDateFormatUtil.dattimToDbtime(dattim1);
|
||||
System.out.println("GEMPAK: " + dattim1 + " to AWIPS: " + dbTime1);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"2014-07-24 12:00:00.0", dbTime1);
|
||||
// Note: if there is no forecast time the date time is separated with a
|
||||
// space and not an underscore!
|
||||
|
||||
String dattim2 = "140725/120000f006";
|
||||
String dbTime2 = CommonDateFormatUtil.dattimToDbtime(dattim2);
|
||||
System.out.println("GEMPAK: " + dattim2 + " to AWIPS: " + dbTime2);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"2014-07-25_12:00:00.0_(6)", dbTime2);
|
||||
|
||||
String dattim3 = "140726/120000f036";
|
||||
String dbTime3 = CommonDateFormatUtil.dattimToDbtime(dattim3);
|
||||
System.out.println("GEMPAK: " + dattim3 + " to AWIPS: " + dbTime3);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"2014-07-26_12:00:00.0_(36)", dbTime3);
|
||||
|
||||
String dattim4 = "140727/120000f120";
|
||||
String dbTime4 = CommonDateFormatUtil.dattimToDbtime(dattim4);
|
||||
System.out.println("GEMPAK: " + dattim4 + " to AWIPS: " + dbTime4);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"2014-07-27_12:00:00.0_(120)", dbTime4);
|
||||
|
||||
String dattim5 = "140730/120000f00615";
|
||||
String dbTime5 = CommonDateFormatUtil.dattimToDbtime(dattim5);
|
||||
System.out.println("GEMPAK: " + dattim5 + " to AWIPS: " + dbTime5);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"2014-07-30_12:00:00.0_(6:15)", dbTime5);
|
||||
|
||||
String dattim6 = "140808/120000f03045";
|
||||
String dbTime6 = CommonDateFormatUtil.dattimToDbtime(dattim6);
|
||||
System.out.println("GEMPAK: " + dattim6 + " to AWIPS: " + dbTime6);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"2014-08-08_12:00:00.0_(30:45)", dbTime6);
|
||||
|
||||
String dattim7 = "140807/120000f13630";
|
||||
String dbTime7 = CommonDateFormatUtil.dattimToDbtime(dattim7);
|
||||
System.out.println("GEMPAK: " + dattim7 + " to AWIPS: " + dbTime7);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"2014-08-07_12:00:00.0_(136:30)", dbTime7);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link gov.noaa.nws.ncep.viz.common.util.CommonDateFormatUtil#getForecastTimeInSec(java.lang.String)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testGetForecastTimeInSec() {
|
||||
System.out
|
||||
.println("------------------Test-case GetForecastTimeInSec----------------");
|
||||
String aTime1 = "140724/120000";
|
||||
int forecastTimeInSec1 = CommonDateFormatUtil
|
||||
.getForecastTimeInSec(aTime1);
|
||||
System.out.println("Forecast time: " + aTime1 + " in Seconds: "
|
||||
+ forecastTimeInSec1);
|
||||
assertEquals("Actual time in seconds did not equal expected time!", 0,
|
||||
forecastTimeInSec1);
|
||||
// Note: if there is no forecast time this method returns 0
|
||||
|
||||
String aTime2 = "2014-07-25_12:00:00.0_(6)";
|
||||
int forecastTimeInSec2 = CommonDateFormatUtil
|
||||
.getForecastTimeInSec(aTime2);
|
||||
System.out.println("Forecast time: " + aTime2 + " in Seconds: "
|
||||
+ forecastTimeInSec2);
|
||||
assertEquals("Actual time in seconds did not equal expected time!",
|
||||
HR6_IN_SECONDS, forecastTimeInSec2);
|
||||
|
||||
String aTime3 = "140730/120000f00615";
|
||||
int forecastTimeInSec3 = CommonDateFormatUtil
|
||||
.getForecastTimeInSec(aTime3);
|
||||
System.out.println("Forecast time: " + aTime3 + " in Seconds: "
|
||||
+ forecastTimeInSec3);
|
||||
assertEquals("Actual time in seconds did not equal expected time!",
|
||||
HR6_15MIN_IN_SECONDS, forecastTimeInSec3);
|
||||
|
||||
String aTime4 = "2014-08-08_12:00:00.0_(30:45)";
|
||||
int forecastTimeInSec4 = CommonDateFormatUtil
|
||||
.getForecastTimeInSec(aTime4);
|
||||
System.out.println("Forecast time: " + aTime4 + " in Seconds: "
|
||||
+ forecastTimeInSec4);
|
||||
assertEquals("Actual time in seconds did not equal expected time!",
|
||||
HR30_45MIN_IN_SECONDS, forecastTimeInSec4);
|
||||
|
||||
String aTime5 = "140807/120000f13630";
|
||||
int forecastTimeInSec5 = CommonDateFormatUtil
|
||||
.getForecastTimeInSec(aTime5);
|
||||
System.out.println("Forecast time: " + aTime5 + " in Seconds: "
|
||||
+ forecastTimeInSec5);
|
||||
assertEquals("Actual time in seconds did not equal expected time!",
|
||||
HR136_30MIN_IN_SECONDS, forecastTimeInSec5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link gov.noaa.nws.ncep.viz.common.util.CommonDateFormatUtil#getForecastTimeString(java.lang.String)}
|
||||
* {@link gov.noaa.nws.ncep.viz.common.util.CommonDateFormatUtil#getForecastTimeString(int)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testGetForecastTimeString() {
|
||||
System.out
|
||||
.println("------------------Test-case GetForecastTimeString----------------");
|
||||
String aTime = "140725/120000f006";
|
||||
int secTime = HR6_IN_SECONDS;
|
||||
String forecastTimeFromString = CommonDateFormatUtil
|
||||
.getForecastTimeString(aTime);
|
||||
String forecastTimeFromInt = CommonDateFormatUtil
|
||||
.getForecastTimeString(secTime);
|
||||
System.out.println("Time: " + aTime + " forecast in seconds: "
|
||||
+ secTime + " to time string: " + forecastTimeFromInt);
|
||||
assertEquals("Actual time did not equal expected time string!", "006",
|
||||
forecastTimeFromString);
|
||||
assertEquals("Actual time did not equal expected time string!", "006",
|
||||
forecastTimeFromInt);
|
||||
|
||||
aTime = "2014-07-27_12:00:00.0 (120)";
|
||||
secTime = HR120_IN_SECONDS;
|
||||
forecastTimeFromString = CommonDateFormatUtil
|
||||
.getForecastTimeString(aTime);
|
||||
forecastTimeFromInt = CommonDateFormatUtil
|
||||
.getForecastTimeString(secTime);
|
||||
System.out.println("Time: " + aTime + " forecast in seconds: "
|
||||
+ secTime + " to time string: " + forecastTimeFromInt);
|
||||
assertEquals("Actual time did not equal expected time string!", "120",
|
||||
forecastTimeFromString);
|
||||
assertEquals("Actual time did not equal expected time string!", "120",
|
||||
forecastTimeFromInt);
|
||||
|
||||
aTime = "140730/120000f00015";
|
||||
secTime = MIN15_IN_SECONDS;
|
||||
forecastTimeFromString = CommonDateFormatUtil
|
||||
.getForecastTimeString(aTime);
|
||||
forecastTimeFromInt = CommonDateFormatUtil
|
||||
.getForecastTimeString(secTime);
|
||||
System.out.println("Time: " + aTime + " forecast in seconds: "
|
||||
+ secTime + " to time string: " + forecastTimeFromInt);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"00015", forecastTimeFromString);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"00015", forecastTimeFromInt);
|
||||
|
||||
aTime = "2014-08-07 12:00:00.0 (036:30)";
|
||||
secTime = HR36_30MIN_IN_SECONDS;
|
||||
forecastTimeFromString = CommonDateFormatUtil
|
||||
.getForecastTimeString(aTime);
|
||||
forecastTimeFromInt = CommonDateFormatUtil
|
||||
.getForecastTimeString(secTime);
|
||||
System.out.println("Time: " + aTime + " forecast in seconds: "
|
||||
+ secTime + " to time string: " + forecastTimeFromInt);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"03630", forecastTimeFromString);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"03630", forecastTimeFromInt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link gov.noaa.nws.ncep.viz.common.util.CommonDateFormatUtil#getForecastColonTimeString(java.lang.String)}
|
||||
* {@link gov.noaa.nws.ncep.viz.common.util.CommonDateFormatUtil#getForecastColonTimeString(int)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testGetForecastColonTimeString() {
|
||||
System.out
|
||||
.println("------------------Test-case GetForecastColonTimeString----------------");
|
||||
String aTime = "140725/120000f006";
|
||||
int secTime = HR6_IN_SECONDS;
|
||||
String forecastTimeFromString = CommonDateFormatUtil
|
||||
.getForecastColonTimeString(aTime);
|
||||
String forecastTimeFromInt = CommonDateFormatUtil
|
||||
.getForecastColonTimeString(secTime);
|
||||
System.out.println("Time: " + aTime + " forecast in seconds: "
|
||||
+ secTime + " to time string: " + forecastTimeFromInt);
|
||||
assertEquals("Actual time did not equal expected time string!", "6",
|
||||
forecastTimeFromString);
|
||||
assertEquals("Actual time did not equal expected time string!", "6",
|
||||
forecastTimeFromInt);
|
||||
|
||||
aTime = "2014-07-27_12:00:00.0 (120)";
|
||||
secTime = HR120_IN_SECONDS;
|
||||
forecastTimeFromString = CommonDateFormatUtil
|
||||
.getForecastColonTimeString(aTime);
|
||||
forecastTimeFromInt = CommonDateFormatUtil
|
||||
.getForecastColonTimeString(secTime);
|
||||
System.out.println("Time: " + aTime + " forecast in seconds: "
|
||||
+ secTime + " to time string: " + forecastTimeFromInt);
|
||||
assertEquals("Actual time did not equal expected time string!", "120",
|
||||
forecastTimeFromString);
|
||||
assertEquals("Actual time did not equal expected time string!", "120",
|
||||
forecastTimeFromInt);
|
||||
|
||||
aTime = "140730/120000f00015";
|
||||
secTime = MIN15_IN_SECONDS;
|
||||
forecastTimeFromString = CommonDateFormatUtil
|
||||
.getForecastColonTimeString(aTime);
|
||||
forecastTimeFromInt = CommonDateFormatUtil
|
||||
.getForecastColonTimeString(secTime);
|
||||
System.out.println("Time: " + aTime + " forecast in seconds: "
|
||||
+ secTime + " to time string: " + forecastTimeFromInt);
|
||||
assertEquals("Actual time did not equal expected time string!", "0:15",
|
||||
forecastTimeFromString);
|
||||
assertEquals("Actual time did not equal expected time string!", "0:15",
|
||||
forecastTimeFromInt);
|
||||
|
||||
aTime = "2014-08-07 12:00:00.0 (036:30)";
|
||||
secTime = HR36_30MIN_IN_SECONDS;
|
||||
forecastTimeFromString = CommonDateFormatUtil
|
||||
.getForecastColonTimeString(aTime);
|
||||
forecastTimeFromInt = CommonDateFormatUtil
|
||||
.getForecastColonTimeString(secTime);
|
||||
System.out.println("Time: " + aTime + " forecast in seconds: "
|
||||
+ secTime + " to time string: " + forecastTimeFromInt);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"36:30", forecastTimeFromString);
|
||||
assertEquals("Actual time did not equal expected time string!",
|
||||
"36:30", forecastTimeFromInt);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue