Skip to content

Commit b324cce

Browse files
committed
Merge branch 'broken-ucar-models'
2 parents a6f9889 + ddb17a5 commit b324cce

4 files changed

Lines changed: 76 additions & 40 deletions

File tree

src/ninja/KmlVector.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ void KmlVector::setSpeedGrid(AsciiGrid<double> &s, velocityUnits::eVelocityUnits
6767
{
6868
speedUnits = units;
6969
spd = s;
70+
for (int i = 0; i < spd.get_nRows(); ++i) {
71+
for (int j = 0; j < spd.get_nCols(); ++j) {
72+
if (spd(i, j) > 1e36) {
73+
spd(i, j) = spd.get_noDataValue();
74+
}
75+
}
76+
}
7077
}
7178

7279
void KmlVector::setDirGrid(AsciiGrid<double> &d)
@@ -1717,14 +1724,13 @@ bool KmlVector::writeVectors(VSILFILE *fileOut)
17171724
nR = spd.get_nRows();
17181725
nC = spd.get_nCols();
17191726

1720-
17211727
//double PI = acos(-1.0);
17221728
geTheta = 0;
17231729
for(int i = 0;i < nR;i++)
17241730
{
17251731
for(int j = 0;j < nC;j++)
17261732
{
1727-
yScale = 0.5;
1733+
yScale = 0.5;
17281734
s = spd(i,j);
17291735
geTheta = dir(i,j);
17301736
theta = dir(i,j) + 180.0;
@@ -1801,7 +1807,7 @@ bool KmlVector::writeVectors(VSILFILE *fileOut)
18011807
coordTransform->Transform(1, &xHeadRight, &yHeadRight);
18021808
coordTransform->Transform(1, &xHeadLeft, &yHeadLeft);
18031809

1804-
if(s != spd.get_noDataValue() && theta != dir.get_noDataValue())
1810+
if(s != spd.get_noDataValue() && theta != dir.get_noDataValue())
18051811
{
18061812
VSIFPrintfL(fileOut, "<Placemark>");
18071813
//fprintf(fileOut, "\n<Icon><href>ffs_icon.ico</href></Icon>");

src/ninja/ncepRapSurfInitialization.cpp

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ void ncepRapSurfInitialization::checkForValidData()
246246
}
247247
else if( varList[i] == "Geopotential_height_cloud_tops" ) //units are meters
248248
{
249-
if(padfScanline[k] != -99999.0) //means there are clouds
249+
if(padfScanline[k] != dfNoData) //means there are clouds
250250
{
251-
if(padfScanline[k] < -500.0 || padfScanline[k] > 30000.0)
251+
if(padfScanline[k] < -500.0)
252252
throw badForecastFile("Geopotential_height_cloud_tops is out of range in forecast file.");
253253
}
254254
}
@@ -458,14 +458,17 @@ void ncepRapSurfInitialization::setSurfaceGrids( WindNinjaInputs &input,
458458
(double*) CPLMalloc( sizeof( double ) * nBandCount );
459459

460460
for( int b = 0;b < srcDS->GetRasterCount();b++ ) {
461-
psWarpOptions->padfDstNoDataReal[b] = dfNoData;
462-
psWarpOptions->padfDstNoDataImag[b] = dfNoData;
463-
psWarpOptions->panSrcBands[b] = b + 1;
464-
psWarpOptions->panDstBands[b] = b + 1;
461+
psWarpOptions->padfDstNoDataReal[b] = dfNoData;
462+
psWarpOptions->padfDstNoDataImag[b] = dfNoData;
463+
psWarpOptions->panSrcBands[b] = b + 1;
464+
psWarpOptions->panDstBands[b] = b + 1;
465465
}
466466

467-
if( pbSuccess == false )
468-
dfNoData = -9999.0;
467+
if( pbSuccess == false)
468+
dfNoData = -9999.0;
469+
470+
if( dfNoData > 1e10)
471+
dfNoData = std::numeric_limits<double>::quiet_NaN();
469472

470473
psWarpOptions->papszWarpOptions =
471474
CSLSetNameValue( psWarpOptions->papszWarpOptions,
@@ -482,32 +485,32 @@ void ncepRapSurfInitialization::setSurfaceGrids( WindNinjaInputs &input,
482485
}
483486

484487
if( varList[i] == "Temperature_height_above_ground" ) {
485-
GDAL2AsciiGrid( wrpDS, bandNum, airGrid );
486-
if( CPLIsNan( dfNoData ) ) {
487-
airGrid.set_noDataValue(-9999.0);
488-
airGrid.replaceNan( -9999.0 );
489-
}
490-
}
491-
else if( varList[i] == "v-component_of_wind_height_above_ground" ) {
492-
GDAL2AsciiGrid( wrpDS, bandNum, vGrid );
493-
if( CPLIsNan( dfNoData ) ) {
494-
vGrid.set_noDataValue(-9999.0);
495-
vGrid.replaceNan( -9999.0 );
496-
}
497-
}
498-
else if( varList[i] == "u-component_of_wind_height_above_ground" ) {
499-
GDAL2AsciiGrid( wrpDS, bandNum, uGrid );
500-
if( CPLIsNan( dfNoData ) ) {
501-
uGrid.set_noDataValue(-9999.0);
502-
uGrid.replaceNan( -9999.0 );
488+
GDAL2AsciiGrid( wrpDS, bandNum, airGrid );
489+
if( CPLIsNan( dfNoData ) ) {
490+
airGrid.set_noDataValue(-9999.0);
491+
airGrid.replaceNan( -9999.0 );
492+
}
503493
}
494+
else if( varList[i] == "v-component_of_wind_height_above_ground" ) {
495+
GDAL2AsciiGrid( wrpDS, bandNum, vGrid );
496+
if( CPLIsNan( dfNoData ) ) {
497+
vGrid.set_noDataValue(-9999.0);
498+
vGrid.replaceNan( -9999.0 );
499+
}
504500
}
505-
else if( varList[i] == "Geopotential_height_cloud_tops" ) {
506-
GDAL2AsciiGrid( wrpDS, bandNum, cloudGrid );
507-
if( CPLIsNan( dfNoData ) ) {
508-
cloudGrid.set_noDataValue(-9999.0);
509-
cloudGrid.replaceNan( -99999.0 );
501+
else if( varList[i] == "u-component_of_wind_height_above_ground" ) {
502+
GDAL2AsciiGrid( wrpDS, bandNum, uGrid );
503+
if( CPLIsNan( dfNoData ) ) {
504+
uGrid.set_noDataValue(-9999.0);
505+
uGrid.replaceNan( -9999.0 );
506+
}
510507
}
508+
else if( varList[i] == "Geopotential_height_cloud_tops" ) {
509+
GDAL2AsciiGrid( wrpDS, bandNum, cloudGrid );
510+
if( CPLIsNan( dfNoData ) ) {
511+
cloudGrid.set_noDataValue(-9999.0);
512+
cloudGrid.replaceNan( -99999.0 );
513+
}
511514
}
512515

513516
GDALDestroyWarpOptions( psWarpOptions );

src/ninja/ncepRapSurfInitialization.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define NCEP_RAP_SURFACE_INITIALIZATION_H
3232

3333
#include "wxModelInitialization.h"
34+
#include <cmath>
3435

3536
/**
3637
* Class to initialize a WindNinja run from an NCEP RUC Surface forecast file.

src/ninja/wxModelInitialization.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,21 +422,47 @@ std::string wxModelInitialization::fetchForecast( std::string demFile,
422422
CPLDebug( "WINDNINJA", "Forecast URL: %s", urlAddress.c_str() );
423423
if( poResult == NULL )
424424
{
425-
CPLHTTPDestroyResult( poResult );
426-
throw ( badForecastFile( "CPLHTTPResult is NULL!" ) );
425+
CPLHTTPDestroyResult( poResult );
426+
throw ( badForecastFile( "CPLHTTPResult is NULL!" ) );
427427
}
428428

429429
if( poResult->nStatus != 0 )
430430
{
431-
CPLHTTPDestroyResult( poResult );
432-
throw ( badForecastFile( poResult->pszErrBuf ) );
431+
CPLHTTPDestroyResult( poResult );
432+
throw ( badForecastFile( poResult->pszErrBuf ) );
433+
}
434+
435+
if (poResult->pszErrBuf && urlAddress.find("NDFD") != std::string::npos)
436+
{
437+
CPLDebug("WINDNINJA", "Received 404, retrying with new URL.");
438+
std::string toReplace = "Best";
439+
std::string replacement = "Best/LambertConformal_1377X2145-38p23N-95p44W-2";
440+
441+
size_t pos = urlAddress.find(toReplace);
442+
if (pos != std::string::npos) {
443+
urlAddress.replace(pos, toReplace.length(), replacement);
444+
}
445+
446+
CPLDebug("WINDNINJA", "New Forecast URL: %s", urlAddress.c_str());
447+
poResult = CPLHTTPFetch(urlAddress.c_str(), NULL);
448+
449+
if (poResult == NULL)
450+
{
451+
throw badForecastFile("CPLHTTPResult is NULL!");
452+
}
453+
454+
if (poResult->nStatus != 0)
455+
{
456+
CPLHTTPDestroyResult(poResult);
457+
throw badForecastFile(poResult->pszErrBuf);
458+
}
433459
}
434460

435461
fout = VSIFOpenL( tempFileName.c_str(), "w" );
436462
if( fout == NULL )
437463
{
438-
CPLHTTPDestroyResult( poResult );
439-
throw ( badForecastFile( "Failed to download forecast." ) );
464+
CPLHTTPDestroyResult( poResult );
465+
throw ( badForecastFile( "Failed to download forecast." ) );
440466
}
441467
VSIFWriteL( poResult->pabyData, poResult->nDataLen, 1, fout );
442468
CPLHTTPDestroyResult( poResult );

0 commit comments

Comments
 (0)