Skip to content

Commit

Permalink
Merge branch 'master' into 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
nwagenbrenner committed Aug 15, 2024
2 parents 2d9276e + 3160589 commit 3e2d701
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 127 deletions.
3 changes: 2 additions & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
### Special Thanks

- OpenFOAM Foundation
- MesoWest/SynopticLabs
- Synoptic Data PBC
- OpenTopography
- High Performance Computing Applications for Science and Engineering, Universitat Autònoma de Barcelona
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ WindNinja 3.11.0
- Added additional time zones from Python timezone finder

- Disabled automatic output buffering unless the FARSITE/FlamMap atmosphere file is written (#511)

- Re-enable server communications (#295, #450, #481)

WindNinja 3.10.0
---------------
- Update CLI documentation, example cfg files, and test data (#415, #434, #270, #252)
Expand Down
4 changes: 2 additions & 2 deletions data/cli_domainAverage.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
num_threads = 1

# data file location if using Windows
#elevation_file = ../etc/windninja/example-files/missoula_valley.tif
#data file location if using Linux (adjust as needed)
#elevation_file = ../etc/windninja/example-files/missoula_valley.tif
# data file location if using Linux (adjust as needed)
elevation_file = ../../../windninja/data/missoula_valley.tif
initialization_method = domainAverageInitialization
input_speed = 10.0
Expand Down
6 changes: 3 additions & 3 deletions data/cli_domainAverage_diurnal.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#

num_threads = 1
#data file location for Windows
#elevation_file = ../etc/windninja/example-files/missoula_valley.tif
#data file location for Linux (adjust as needed)
# data file location for Windows
#elevation_file = ../etc/windninja/example-files/missoula_valley.tif
# data file location for Linux (adjust as needed)
elevation_file = ../../../windninja/data/missoula_valley.tif
initialization_method = domainAverageInitialization
time_zone = America/Denver
Expand Down
7 changes: 4 additions & 3 deletions data/cli_momentumSolver_diurnal.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
#

num_threads = 1
#num_threads = 4
# data file location for Windows
# elevation_file = ../etc/windninja/example-files/missoula_valley.tif
#
#elevation_file = ../etc/windninja/example-files/missoula_valley.tif
# data file location for Linux (adjust as needed)
elevation_file = ../../../windninja/data/missoula_valley.tif
initialization_method = domainAverageInitialization
momentum_flag = true
number_of_iterations = 2000
mesh_choice = fine
mesh_choice = coarse
#mesh_choice = fine
time_zone = America/Denver
input_speed = 10.0
input_speed_units = mph
Expand Down
4 changes: 2 additions & 2 deletions data/cli_pointInitialization_diurnal.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#
num_threads = 1

#data file location if using Windows
# elevation_file = ../etc/windninja/example_files/missoula_valley.tif
# data file location if using Windows
#elevation_file = ../etc/windninja/example-files/missoula_valley.tif
# data file location if using Linux (adjust as needed)
elevation_file = ../../../windninja/data/missoula_valley.tif
initialization_method = pointInitialization
Expand Down
4 changes: 2 additions & 2 deletions data/cli_wxModelInitialization_diurnal.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#

num_threads = 1
#data file location if using Windows
# elevation_file = ../etc/windninja/example_files/missoula_valley.tif
# data file location if using Windows
#elevation_file = ../etc/windninja/example-files/missoula_valley.tif
# data file location if using Linux (adjust as needed)
elevation_file = ../../../windninja/data/missoula_valley.tif
initialization_method = wxModelInitialization
Expand Down
6 changes: 4 additions & 2 deletions src/gui/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,17 @@ void mainWindow::checkMessages(void) {
if (strcmp(papszMsg, "TRUE\n") == 0) {
mbox.setText("There is a fatal flaw in Windninja, it must close.");
mbox.exec();
delete[] papszMsg;
abort();
}

else {
char *papszMsg = NinjaQueryServerMessages(false);
if (papszMsg != NULL) {
mbox.setText(papszMsg);

mbox.exec();
delete[] papszMsg;
}
}
}
Expand Down Expand Up @@ -1224,7 +1226,7 @@ void mainWindow::aboutWindNinja()
aboutText.append("<p><h4>Developed by:</h4><p>Jason Forthofer<br/> " \
"Kyle Shannon<br/>" \
"Natalie Wagenbrenner<br/>" \
"Bret Butler<br/>" \
"Bret Butler<br/>"); \
aboutText.append("<p>Missoula Fire Sciences Laboratory<br />");
aboutText.append("Rocky Mountain Research Station<br />");
aboutText.append("USDA Forest Service<br />");
Expand Down
212 changes: 100 additions & 112 deletions src/ninja/ninja_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,68 +74,63 @@ bool NinjaCheckVersions(char * mostrecentversion, char * localversion) {

}

char * NinjaQueryServerMessages(bool checkAbort) {
char * NinjaQueryServerMessages(bool checkAbort)
{
CPLSetConfigOption( "GDAL_HTTP_TIMEOUT", "5" );
const char* url = "https://ninjastorm.firelab.org/sqlitetest/messages.txt";
CPLHTTPResult *poResult = NULL;
try{
CPLHTTPResult *poResult = CPLHTTPFetch(url, NULL);

if (poResult != NULL) {
const char* pszTextContent = reinterpret_cast<const char*>(poResult->pabyData);
std::vector<std::string> messages;
std::istringstream iss(pszTextContent);
std::string message;

// Read all lines into the vector
while (std::getline(iss, message)) {
messages.push_back(message);
}

// Process all lines except the last two
std::ostringstream oss;
if (checkAbort) {
for (size_t i = 0; i < messages.size(); ++i) {
if (i == messages.size()-1) { // check final line
oss << messages[i] << "\n";
}
}
}
else {
bool versionisuptodate = NinjaCheckVersions(const_cast<char*>(messages[1].c_str()), const_cast<char*>(NINJA_VERSION_STRING));
if (!versionisuptodate) {
oss << messages[0] << "\n";
oss << "You are using an outdated WindNinja version, please update to version: " << messages[1] << "\n" << "\n";
}
CPLSetConfigOption( "GDAL_HTTP_TIMEOUT", NULL );
CPLHTTPResult *poResult = CPLHTTPFetch(url, NULL);
if( !poResult || poResult->nStatus != 0 || poResult->nDataLen == 0 )
{
CPLDebug( "NINJA", "Failed to reach the ninjastorm server." );
return NULL;
}

if (messages[4].empty() == false) {
for (size_t i = 3; i < messages.size() - 2; ++i) {
if (!messages[i].empty()) {
oss << messages[i] << "\n";
}
}
}
if (messages[4].empty() && versionisuptodate) {
return NULL;
}
}
const char* pszTextContent = reinterpret_cast<const char*>(poResult->pabyData);
std::vector<std::string> messages;
std::istringstream iss(pszTextContent);
std::string message;

std::string resultingmessage = oss.str();
char* returnString = new char[resultingmessage.length() + 1];
std::strcpy(returnString, resultingmessage.c_str());
// Read all lines into the vector
while (std::getline(iss, message)) {
messages.push_back(message);
}

CPLHTTPDestroyResult(poResult);
return returnString;
// Process all lines except the last two
std::ostringstream oss;
if (checkAbort) {
for (size_t i = 0; i < messages.size(); ++i) {
if (i == messages.size()-1) { // check final line
oss << messages[i] << "\n";
}
}
}
catch (std::exception& e) {
std::cout << "can't fetch" << std::endl;
else {
bool versionisuptodate = NinjaCheckVersions(const_cast<char*>(messages[1].c_str()), const_cast<char*>(NINJA_VERSION_STRING));
if (!versionisuptodate) {
oss << messages[0] << "\n";
oss << "You are using an outdated WindNinja version, please update to version: " << messages[1] << "\n" << "\n";
}
if (messages[4].empty() == false) {
for (size_t i = 3; i < messages.size() - 2; ++i) {
if (!messages[i].empty()) {
oss << messages[i] << "\n";
}
}
}
if (messages[4].empty() && versionisuptodate) {
return NULL;
}
}
return NULL;

}


std::string resultingmessage = oss.str();
char* returnString = new char[resultingmessage.length() + 1];
std::strcpy(returnString, resultingmessage.c_str());
CPLHTTPDestroyResult(poResult);
return returnString;

return NULL;
}

void NinjaCheckThreddsData( void *rc )
{
Expand Down Expand Up @@ -183,7 +178,6 @@ int NinjaInitialize(const char *pszGdalData, const char *pszWindNinjaData)
GDALAllRegister();
OGRRegisterAll();


if(!CPLCheckForFile(CPLStrdup(CPLFormFilename(CPLStrdup(pszGdalData), "gdalicon.png", NULL)), NULL))
{
CPLDebug("WINDNINJA", "Invalid path for GDAL_DATA: %s", pszGdalData);
Expand All @@ -210,17 +204,18 @@ int NinjaInitialize(const char *pszGdalData, const char *pszWindNinjaData)
** Initialize global singletons and environments.
*/

int NinjaInitialize(const char* typeofrun) {


int NinjaInitialize(const char* typeofrun)
{
GDALAllRegister();
OGRRegisterAll();

/*
** Silence warnings and errors in initialize. Sometimes we can't dial out,
** but that doesn't mean we are in trouble.
*/
CPLPushErrorHandler(CPLQuietErrorHandler);
int rc = 0;
int rc = 0;

/*
** Setting the CURL_CA_BUNDLE variable through GDAL doesn't seem to work,
** but could be investigated in the future. CURL_CA_BUNDLE can only be set in GDAL
Expand All @@ -230,46 +225,6 @@ int NinjaInitialize(const char* typeofrun) {
*/
CPLSetConfigOption( "GDAL_HTTP_UNSAFESSL", "YES");

if (strcmp(typeofrun, "") != 0) {

time_t now = time(0);

// convert now to tm struct for UTC
tm *gmtm = gmtime(&now);
char* dt = asctime(gmtm);
std::string cpp_string(dt);


std::string url = "https://ninjastorm.firelab.org/sqlitetest/?time=";
cpp_string.erase(std::remove_if(cpp_string.begin(), cpp_string.end(), ::isspace),
cpp_string.end());


std::string full = url + cpp_string + "&runtype=" + typeofrun;


const char *charStr = full.data();

CPLHTTPResult *poResult;
CPLSetConfigOption("GDAL_HTTP_UNSAFESSL", "YES");
char **papszOptions = NULL;

// Fetch the URL with custom headers
try {
poResult = CPLHTTPFetch(charStr, papszOptions);
}
catch (std::exception& e) {
std::cout << "can't fetch" << std::endl;
}

if (poResult) {
CPLHTTPDestroyResult(poResult);

}
}



#ifdef WIN32
CPLDebug( "WINDNINJA", "Setting GDAL_DATA..." );
std::string osGdalData;
Expand All @@ -285,7 +240,6 @@ int NinjaInitialize(const char* typeofrun) {
CPLDebug("WINDNINJA", "Setting GDAL_DRIVER_PATH: %s", pszPlugins);

CPLSetConfigOption("GDAL_DRIVER_PATH", pszPlugins);

#endif /* defined(FIRELAB_PACKAGE) */

#if defined(NINJAFOAM) && defined(FIRELAB_PACKAGE)
Expand Down Expand Up @@ -313,25 +267,59 @@ int NinjaInitialize(const char* typeofrun) {
CPLFree( (void*)pszExecPath );
#endif /* defined(NINJAFOAM) && defined(FIRELAB_PACKAGE)*/

#endif /* defined(WIN32) */

#endif
/*
** Set windninja data if it isn't set.
*/
if (!CSLTestBoolean(CPLGetConfigOption("WINDNINJA_DATA", "FALSE"))) {
std::string osDataPath;
osDataPath = FindDataPath("tz_world.zip");
if (osDataPath != "") {
CPLSetConfigOption("WINDNINJA_DATA", CPLGetPath(osDataPath.c_str()));
}
}

globalTimeZoneDB.load_from_file(FindDataPath("date_time_zonespec.csv"));
CPLPopErrorHandler();

#ifdef PHONE_HOME_QUERIES_ENABLED
if (strcmp(typeofrun, "") != 0) {

time_t now = time(0);

/*
** Set windninja data if it isn't set.
*/
if (!CSLTestBoolean(CPLGetConfigOption("WINDNINJA_DATA", "FALSE"))) {
std::string osDataPath;
osDataPath = FindDataPath("tz_world.zip");
if (osDataPath != "") {
CPLSetConfigOption("WINDNINJA_DATA", CPLGetPath(osDataPath.c_str()));
}
}
// convert now to tm struct for UTC
tm *gmtm = gmtime(&now);
char* dt = asctime(gmtm);
std::string cpp_string(dt);

std::string url = "https://ninjastorm.firelab.org/sqlitetest/?time=";
cpp_string.erase(std::remove_if(cpp_string.begin(), cpp_string.end(), ::isspace),
cpp_string.end());

std::string full = url + cpp_string + "&runtype=" + typeofrun;

const char *charStr = full.data();

CPLHTTPResult *poResult;
char **papszOptions = NULL;

CPLSetConfigOption( "GDAL_HTTP_TIMEOUT", "5" );
// Fetch the URL with custom headers
poResult = CPLHTTPFetch(charStr, papszOptions);
CPLSetConfigOption( "GDAL_HTTP_TIMEOUT", NULL );
if( !poResult || poResult->nStatus != 0 || poResult->nDataLen == 0 )
{
CPLDebug( "NINJA", "Failed to reach the ninjastorm server." );
return 0;
}
else {
if (poResult) {
CPLHTTPDestroyResult(poResult);
}
}
}
#endif

globalTimeZoneDB.load_from_file(FindDataPath("date_time_zonespec.csv"));
CPLPopErrorHandler();
return 0;
}

0 comments on commit 3e2d701

Please sign in to comment.