WSL/SLF GitLab Repository

Commit 459d2395 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

The DataGenerators handling of missing meteo fields has been changed: if a...

The DataGenerators handling of missing meteo fields has been changed: if a generator is defined for a field that is not found in the vecMeteo, it will silently be skipped.

Since some grumpy people seem not to appreciate the graphical message box for exception messages, the ability to turn them off when compiling has been added to cmake. The code for generating such message boxes on Linux purely relying on libX11 is also committed (the boxes are ugly but they don't require more than libX11 and its headers).

We still have to make sure that enabling it by default (that would be the goal) does not make it more difficult to compile meteoio...
parent 2daffd0a
......@@ -36,6 +36,9 @@ IF(MSVC)
IF(BUILD_SHARED_LIBS)
ADD_DEFINITIONS(/DMIO_DLL)
ENDIF(BUILD_SHARED_LIBS)
IF(GUI_EXCEPTIONS)
SET(MSG_BOX "/DMESG_BOX")
ENDIF(GUI_EXCEPTIONS)
ELSE(MSVC)
#we consider that all other compilers support "-" options and silently ignore what they don't know
SET(WARNINGS "-Wall")
......@@ -119,12 +122,16 @@ ENDIF(DEST STREQUAL "optimized")
#build for use with POPC in parallel objects
SET(POPC OFF CACHE BOOL "Compile for POPC ON or OFF")
#build for use with POPC in parallel objects
SET(GUI_EXCEPTIONS ON CACHE BOOL "Show a message box with exceptions texts ON or OFF")
###########################################################
#finally, SET compile flags
IF(POPC)
#SET(POPC_FLAGS "-cxxmain -Dcerr=\\\"cout\\\"")
SET(POPC_FLAGS "-cxxmain")
ENDIF(POPC)
SET(CMAKE_CXX_FLAGS "${POPC_FLAGS} ${_VERSION} ${ARCH} ${CFLAGS} ${PLATFORM}" CACHE STRING "" FORCE)
SET(CMAKE_CXX_FLAGS_RELEASE "${OPTIM}" CACHE STRING "" FORCE)
SET(CMAKE_CXX_FLAGS_DEBUG "${DEBUG} ${WARNINGS} ${EXTRA_WARNINGS}" CACHE STRING "" FORCE)
......
[General]
BUFF_CHUNK_SIZE = 370
BUFF_BEFORE = 1.5
;BUFF_GRIDS = 0
[Input]
COORDSYS = CH1903
......@@ -13,7 +14,9 @@ GRID2DPATH = ./input/surface-grids
#reading ARC dem
DEM = ARC
DEMFILE = ./input/surface-grids/Switzerland_1000m.asc
;DEMFILE = ./input/surface-grids/Switzerland_1000m.asc
DEMFILE = ./input/surface-grids/dischma.asc
;DEMFILE = ./input/surface-grids/test.asc
#reading ARPS dem
; DEM = ARPS
......@@ -50,21 +53,22 @@ DEMFILE = ./input/surface-grids/Switzerland_1000m.asc
#SMET meteorological file format
METEO = SMET
METEOPATH = ./input/meteo
STATION1 = FLU2.smet
STATION2 = FIR2.smet
STATION3 = FRA2.smet
STATION4 = GLA2.smet
STATION5 = ILI2.smet
STATION6 = OTT2.smet
STATION7 = TUJ3.smet
METEOPATH = ./input/
STATION1 = *WFJ
; STATION1 = FLU2.smet
; STATION2 = FIR2.smet
; STATION3 = FRA2.smet
; STATION4 = GLA2.smet
; STATION5 = ILI2.smet
; STATION6 = OTT2.smet
; STATION7 = TUJ3.smet
#IMIS network database input -> IMIS plugin
; METEO = IMIS
; DBNAME = sdbo
; DBUSER = XXX
; DBPASS = XXX
; STATION1 = MORN2
; DBUSER = slf
; DBPASS = sdb+4u
; STATION1 = *WFJ
; STATION2 = DAV3
; STATION3 = KLO2
; STATION4 = *SAM0
......@@ -75,21 +79,26 @@ STATION7 = TUJ3.smet
; METEOPREFIX = _meteo
#GSN direct input -> GSN plugin
; ENDPOINT = http://montblanc.slf.ch:22002/services/GSNWebService
; METEO = GSN
; ENDPOINT = http://montblanc.slf.ch:22001/services/A3DWebService
; STATION1 = wan_sen14_2008
; STATION2 = wan2
; ;ENDPOINT = http://gc3:swissex@montblanc.slf.ch:22002/services/GSNWebService
; STATION1 = imis_flu_2
; STATION2 = imis_slf_2
COPY::ISWR_POT = ISWR
[Output]
COORDSYS = CH1903
TIME_ZONE = 1
GRID2D = PNG
;GRID2D = ARC
GRID2DPATH = ./
;png_legend = false
png_autoscale = false
;png_min_size = 400x400
png_max_size = 1366*768
PNG_SCALING = nearest
METEO = SMET
METEOPATH = ./
......@@ -108,10 +117,19 @@ HNW::arg1 = -0.1
HNW::filter2 = min
HNW::arg2 = soft 0.
ISWR::filter1 = min_max
ISWR::arg1 = -10. 1500.
ISWR::filter2 = min
ISWR::arg2 = soft 0.
; ISWR::filter1 = min_max
; ISWR::arg1 = -10. 1500.
; ISWR::filter2 = min
; ISWR::arg2 = soft 0.
; ISWR::filter1 = mult
; ISWR::arg1 = 0
; ISWR::filter2 = add
; ISWR::arg2 = -999
ISWR_POT::filter1 = mult
ISWR_POT::arg1 = 0
ISWR_POT::filter2 = add
ISWR_POT::arg2 = -999
RSWR::filter1 = min_max
RSWR::arg1 = -10 1500
......@@ -119,10 +137,14 @@ RSWR::filter2 = min
RSWR::arg2 = soft 0
#for TA between 240 and 320 K
ILWR::filter1 = min_max
ILWR::arg1 = 188 600
ILWR::filter2 = min_max
ILWR::arg2 = soft 200 400
; ILWR::filter1 = min_max
; ILWR::arg1 = 188 600
; ILWR::filter2 = min_max
; ILWR::arg2 = soft 200 400
ILWR::filter1 = mult
ILWR::arg1 = 0
ILWR::filter2 = add
ILWR::arg2 = -999
#we need to consider time with no snow -> TSS>0
#min(TSS) in db since 1998: -50C
......@@ -158,6 +180,8 @@ VW::args = extrapolate
HNW::resample = accumulate
HNW::args = 3600
ISWR_POT::resample = no
[Interpolations2D]
TA::algorithms = IDW_LAPSE CST_LAPSE
TA::cst_lapse = -0.008
......@@ -176,3 +200,15 @@ ILWR::algorithms = CST_LAPSE
ILWR::cst_lapse = -0.03125
RSWR::algorithms = IDW CST
[Generators]
TA::generators = CST
TA::Cst = 300.
P::generators = STD_PRESS
ILWR::generators = UNSWORTH
ISWR_POT::generators = POT_RADIATION
......@@ -72,17 +72,34 @@ SET(meteoio_sources
${meteofilters_sources}
${popc_sources}
)
IF(GUI_EXCEPTIONS)
IF(MSVC)
ADD_DEFINITIONS(/DMSG_BOX)
ELSE(MSVC)
ADD_DEFINITIONS(-DMSG_BOX)
ENDIF(MSVC)
IF(UNIX AND NOT APPLE AND NOT CYGWIN)
FIND_PACKAGE(X11)
IF(X11_FOUND)
INCLUDE_DIRECTORIES(SYSTEM ${X11_INCLUDE_DIR})
SET(GUI_LIBS ${X11_LIBRARIES})
LIST(APPEND meteoio_sources MessageBoxX11.cc)
ELSE(X11_FOUND)
SET(GUI_EXCEPTIONS) #unsets the variable
ENDIF(X11_FOUND)
ENDIF(UNIX AND NOT APPLE AND NOT CYGWIN)
ENDIF(GUI_EXCEPTIONS)
IF(BUILD_STATIC_LIBS)
SET(STATICNAME ${PROJECT_NAME}_STATIC)
SET(STATICLIBNAME ${PROJECT_NAME}${POPC_EXT})
ADD_LIBRARY(${STATICNAME} STATIC ${meteoio_sources})
TARGET_LINK_LIBRARIES(${STATICNAME} ${plugin_libs} ${LIBPROJ} ${Popc_LIBRARIES} ${EXTRA_LINK_FLAGS})
TARGET_LINK_LIBRARIES(${STATICNAME} ${plugin_libs} ${LIBPROJ} ${Popc_LIBRARIES} ${EXTRA_LINK_FLAGS} ${GUI_LIBS})
ENDIF(BUILD_STATIC_LIBS)
SET(SHAREDNAME ${PROJECT_NAME}${POPC_EXT})
ADD_LIBRARY(${SHAREDNAME} ${meteoio_sources})
TARGET_LINK_LIBRARIES(${SHAREDNAME} ${plugin_libs} ${LIBPROJ} ${Popc_LIBRARIES} ${EXTRA_LINK_FLAGS})
TARGET_LINK_LIBRARIES(${SHAREDNAME} ${plugin_libs} ${LIBPROJ} ${Popc_LIBRARIES} ${EXTRA_LINK_FLAGS} ${GUI_LIBS})
SET_TARGET_PROPERTIES(${SHAREDNAME} PROPERTIES
PREFIX "${LIBPREFIX}"
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/lib"
......
......@@ -67,8 +67,7 @@ void DataGenerator::fillMissing(METEO_SET& vecMeteo) const
const std::vector<GeneratorAlgorithm*> vecGenerators = it->second;
for(size_t station=0; station<vecMeteo.size(); station++) { //process this parameter on all stations
const size_t param = vecMeteo[station].getParameterIndex(it->first);
if(param>=vecMeteo[station].getNrOfParameters())
throw InvalidArgumentException("Parameter \""+it->first+"\" not defined for station \""+vecMeteo[station].meta.getStationID()+"\"", AT);
if(param==IOUtils::npos) continue;
size_t jj=0;
while (jj<vecGenerators.size() && vecGenerators[jj]->generate(param, vecMeteo[station]) != true) jj++;
......@@ -93,8 +92,7 @@ void DataGenerator::fillMissing(std::vector<METEO_SET>& vecVecMeteo) const
for(size_t station=0; station<vecVecMeteo.size(); station++) { //process this parameter on all stations
const size_t param = vecVecMeteo[station][0].getParameterIndex(it->first);
if(param>=vecVecMeteo[station][0].getNrOfParameters())
throw InvalidArgumentException("Parameter \""+it->first+"\" not defined for station \""+vecVecMeteo[station][0].meta.getStationID()+"\"", AT);
if(param==IOUtils::npos) continue;
size_t jj=0;
while (jj<vecGenerators.size() && vecGenerators[jj]->generate(param, vecVecMeteo[station]) != true) jj++;
......
......@@ -24,13 +24,16 @@
#include <sstream>
#include <cxxabi.h>
#endif
#if defined(MSG_BOX)
#include <meteoio/MessageBoxX11.h>
#endif
#endif
#if defined(WIN32)
#include <windows.h>
#undef max
#undef min
#endif
#if defined(APPLE)
#if defined(APPLE) && defined(MSG_BOX)
#include <CoreFoundation/CoreFoundation.h>
#endif
......@@ -38,30 +41,29 @@ using namespace std;
namespace mio {
#if defined(LINUX) && !defined(ANDROID) && !defined(CYGWIN)
void messageBox(const std::string& /*msg*/) {
//const string box_msg = msg + "\n\nPlease check the terminal for more information!";
//MessageBoxX11("Oops, something went wrong!", box_msg.c_str());
#else
void messageBox(const std::string& msg) {
#if defined(WIN32)
const string box_msg = msg + "\n\nPlease check the terminal for more information!";
//MessageBox( NULL, box_msg.c_str(), TEXT("Oops, something went wrong!"), MB_OK | MB_ICONERROR );
#endif
#if defined(APPLE)
const string box_msg = msg + "\n\nPlease check the terminal for more information!";
const void* keys[] = { kCFUserNotificationAlertHeaderKey,
kCFUserNotificationAlertMessageKey };
const void* values[] = { CFSTR("Oops, something went wrong!"),
CFStringCreateWithCString(NULL, box_msg.c_str(), kCFStringEncodingMacRoman) };
CFDictionaryRef dict = CFDictionaryCreate(0, keys, values,
sizeof(keys)/sizeof(*keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
SInt32 error = 0;
//CFUserNotificationCreate(NULL, 0, kCFUserNotificationStopAlertLevel, &error, dict);
#endif
#if defined(MSG_BOX)
void messageBox(const std::string& msg) {
#if defined(LINUX) && !defined(ANDROID) && !defined(CYGWIN)
const string box_msg = msg + "\n\nPlease check the terminal for more information!";
MessageBoxX11("Oops, something went wrong!", box_msg.c_str());
#endif
#if defined(WIN32)
const string box_msg = msg + "\n\nPlease check the terminal for more information!";
MessageBox( NULL, box_msg.c_str(), TEXT("Oops, something went wrong!"), MB_OK | MB_ICONERROR );
#endif
#if defined(APPLE)
const string box_msg = msg + "\n\nPlease check the terminal for more information!";
const void* keys[] = { kCFUserNotificationAlertHeaderKey,
kCFUserNotificationAlertMessageKey };
const void* values[] = { CFSTR("Oops, something went wrong!"),
CFStringCreateWithCString(NULL, box_msg.c_str(), kCFStringEncodingMacRoman) };
CFDictionaryRef dict = CFDictionaryCreate(0, keys, values,
sizeof(keys)/sizeof(*keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
SInt32 error = 0;
CFUserNotificationCreate(NULL, 0, kCFUserNotificationStopAlertLevel, &error, dict);
#endif
}
#endif
}
#ifdef _POPC_
IOException::IOException(const std::string& message, const std::string& position) : POPException(STD_EXCEPTION)
......@@ -132,7 +134,9 @@ IOException::~IOException() throw() {}
const char* IOException::what() const throw()
{
#if defined(MSG_BOX)
messageBox(msg);
#endif
return full_output.c_str();
}
......
/*
I, David Oberhollenzer, author of this file hereby place the contents of
this file into the public domain. Please feel free to use this file in any
way you wish.
I want to do this, because a lot of people are in the need of a simple X11
message box function.
The original version was written in C++ and has been ported to C. This
version is entirely leak proof! (According to valgrind)
*/
#ifdef LINUX
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <string.h>
#include <stdlib.h>
/**************************************************************************
* A "small" and "simple" function that creates a message box with an OK *
* button, using ONLY Xlib. *
* The function does not return until the user closes the message box, *
* using the OK button, the escape key, or the close button what means *
* that you can't do anything in the mean time(in the same thread). *
* The code may look very ugly, because I pieced it together from *
* tutorials and manuals and I use an awfull lot of magic values and *
* unexplained calculations. *
* *
* title: The title of the message box. *
* text: The contents of the message box. Use '\n' as a line terminator. *
**************************************************************************/
void MessageBoxX11( const char* title, const char* text ) {
const char* wmDeleteWindow = "WM_DELETE_WINDOW";
/* Open a display */
Display* dpy;
if( !(dpy = XOpenDisplay( 0 )) ) return;
/* Get us a white and black color */
const int black = BlackPixel( dpy, DefaultScreen(dpy) );
const int white = WhitePixel( dpy, DefaultScreen(dpy) );
char grey[] = "#dcdad5";
Colormap colormap = DefaultColormap(dpy, 0);
XColor color;
XParseColor(dpy, colormap, grey, &color);
XAllocColor(dpy, colormap, &color);
/* Create a window with the specified title */
Window w = XCreateSimpleWindow( dpy, DefaultRootWindow(dpy), 0, 0, 100, 100,
0, black, color.pixel );
XSelectInput( dpy, w, ExposureMask | StructureNotifyMask |
KeyReleaseMask | PointerMotionMask |
ButtonPressMask | ButtonReleaseMask );
XMapWindow( dpy, w );
XStoreName( dpy, w, title );
Atom wmDelete = XInternAtom( dpy, wmDeleteWindow, True );
XSetWMProtocols( dpy, w, &wmDelete, 1 );
/* Create a graphics context for the window */
GC gc = XCreateGC( dpy, w, 0, 0 );
XSetForeground( dpy, gc, black );
XSetBackground( dpy, gc, white );
/* Split the text down into a list of lines */
char **strvec = NULL;
size_t strvec_size = 0;
char *temp = (char *)malloc( strlen(text)+1 );
strcpy( temp, text );
char *pch = strtok( temp, "\n" );
while( pch!=NULL ) {
strvec = (char **)realloc( strvec, (strvec_size+1)*sizeof(char**) );
strvec[ strvec_size ] = (char *)malloc( strlen(pch)+1 );
strcpy( strvec[ strvec_size ], pch );
++strvec_size;
pch = strtok( NULL, "\n" );
}
free( temp );
/* Compute the printed length and height of the longest and the tallest line */
XFontStruct* font;
if( !(font = XQueryFont( dpy, XGContextFromGC(gc) )) )
return;
int length=0, height=0, direction, ascent, descent;
XCharStruct overall;
for( size_t i=0; i<strvec_size; ++i ) {
XTextExtents( font, strvec[ i ], strlen(strvec[ i ]), &direction, &ascent, &descent, &overall );
length = overall.width >length ? overall.width : length;
height = (ascent+descent)>height ? (ascent+descent) : height;
}
/* Compute the shape of the window, needed to display the text and adjust the window accordingly */
const int X = DisplayWidth ( dpy, DefaultScreen(dpy) )/2 - length/2-10;
const int Y = DisplayHeight( dpy, DefaultScreen(dpy) )/2 - strvec_size*height/2 - height - 10;
const int W = length + 20;
const int H = strvec_size*height + height + 40;
XMoveResizeWindow( dpy, w, X, Y, W, H );
/* Compute the shape of the OK button */
XTextExtents( font, "OK", 2, &direction, &ascent, &descent, &overall );
const int okWidth = overall.width;
const int okHeight = ascent + descent;
const int okX1 = W/2 - okWidth/2 - 15;
const int okY1 = (strvec_size*height + 20) + 5;
const int okX2 = W/2 + okWidth/2 + 15;
const int okY2 = okY1 + 4 + okHeight;
const int okBaseX = okX1 + 15;
const int okBaseY = okY1 + 2 + okHeight;
//XFreeFontInfo( NULL, font, 1 ); /* We don't need that anymore */
/* Make the window non resizeable */
XUnmapWindow( dpy, w );
XSizeHints* hints = XAllocSizeHints( );
hints->flags = PSize | PMinSize | PMaxSize;
hints->min_width = hints->max_width = hints->base_width = W;
hints->min_height = hints->max_height = hints->base_height = H;
XSetWMNormalHints( dpy, w, hints );
XFree( hints );
XMapRaised( dpy, w );
XFlush( dpy );
/* Event loop */
int run = 1, buttonFocus = 0;
do {
XEvent e;
XNextEvent( dpy, &e );
int offset = 0;
if( e.type == MotionNotify ) {
if( e.xmotion.x>=okX1 && e.xmotion.x<=okX2 && e.xmotion.y>=okY1 && e.xmotion.y<=okY2 ) {
if( !buttonFocus ) e.type = Expose;
buttonFocus = 1;
} else {
if( buttonFocus ) e.type = Expose;
buttonFocus = 0;
offset = 0;
}
}
switch( e.type ) {
case ButtonPress:
case ButtonRelease:
if( e.xbutton.button!=Button1 ) break;
if( buttonFocus ) {
offset = e.type==ButtonPress ? 1 : 0;
if( !offset ) run = 0;
} else {
offset = 0;
}
case Expose:
case MapNotify:
XClearWindow( dpy, w );
/* Draw text lines */
for( size_t i=0; i<strvec_size; ++i )
XDrawString( dpy, w, gc, 10, 10+height + height*i, strvec[i], strlen(strvec[i]) );
/* Draw OK button */
if( buttonFocus ) {
XFillRectangle( dpy, w, gc, offset+okX1, offset+okY1, okX2-okX1, okY2-okY1 );
XSetForeground( dpy, gc, white );
} else {
XDrawLine( dpy, w, gc, okX1, okY1, okX2, okY1 );
XDrawLine( dpy, w, gc, okX1, okY2, okX2, okY2 );
XDrawLine( dpy, w, gc, okX1, okY1, okX1, okY2 );
XDrawLine( dpy, w, gc, okX2, okY1, okX2, okY2 );
}
XDrawString( dpy, w, gc, offset+okBaseX, offset+okBaseY, "OK", 2 );
if( buttonFocus ) {
XSetForeground( dpy, gc, black );
}
XFlush(dpy);
break;
case KeyRelease:
if( XLookupKeysym( &e.xkey, 0 ) == XK_Escape ) run = 0;
break;
case ClientMessage:
char *atom = XGetAtomName( dpy, e.xclient.message_type );
if( *atom == *wmDeleteWindow ) run = 0;
XFree(atom);
break;
};
} while( run );
/* Clean up */
for( size_t i=0; i<strvec_size; ++i ) free( strvec[i] );
free( strvec );
XFreeGC( dpy, gc );
XDestroyWindow( dpy, w );
XCloseDisplay( dpy );
}
#endif
#ifndef MESSAGEBOXX11_H
#define MESSAGEBOXX11_H
#ifdef LINUX
void MessageBoxX11( const char* title, const char* text );
#endif
#endif
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment