WSL/SLF GitLab Repository

Commit 6f392bea authored by Mathias Bavay's avatar Mathias Bavay
Browse files

The WIN32 pre-processor variable has been renamed in MSWIN since this is more...

The WIN32 pre-processor variable has been renamed in MSWIN since this is more logical on Win64 (and to avoid potential conflicts). Some headers have been cleaned up in the process (in Timer.h/.cc). A new method has been moved from Config to FileUtils: isAbsolutePath. Some extra features (support for offset in hours) added to NetCDFIO.
parent b612fab4
......@@ -89,9 +89,9 @@ IF(UNIX)
ELSE(UNIX)
IF(WIN32)
IF(MINGW)
SET(PLATFORM "-DWIN32 -DMINGW")
SET(PLATFORM "-DMSWIN -DMINGW")
ELSE(MINGW)
SET(PLATFORM "-DWIN32")
SET(PLATFORM "-DMSWIN")
ENDIF(MINGW)
SET(DLL_EXT "dll")
SET(STAT_EXT "a")
......
......@@ -307,13 +307,8 @@ std::string Config::extract_section(std::string key) const
std::string Config::clean_import_path(const std::string& in_path) const
{
#ifdef WIN32
const bool is_absolute = (in_path.size()>=2 && in_path[1]==':');
#else
const bool is_absolute = (in_path.size()>=1 && in_path[0]=='/');
#endif
//if this is a relative path, prefix the import path with the current path
const std::string prefix = (!is_absolute)? IOUtils::getPath(sourcename, true)+"/" : "";
const std::string prefix = ( IOUtils::isAbsolutePath(in_path) )? "" : IOUtils::getPath(sourcename, true)+"/";
const std::string path = IOUtils::getPath(prefix+in_path, true); //clean & resolve path
const std::string filename = IOUtils::getFilename(in_path);
......
......@@ -20,7 +20,7 @@
#include <cstdio>
#include <fstream>
#ifdef WIN32
#ifdef MSWIN
#include <windows.h>
#include "Shlwapi.h"
//removing two macros defined in windows.h
......@@ -62,7 +62,7 @@ std::string cleanPath(std::string in_path, const bool& resolve)
std::replace(in_path.begin(), in_path.end(), '\\', '/');
return in_path;
} else {
#ifdef WIN32
#ifdef MSWIN
//if this would not suffice, see http://pdh11.blogspot.ch/2009/05/pathcanonicalize-versus-what-it-says-on.html
char **ptr = NULL;
char *out_buff = (char*)calloc(MAX_PATH, sizeof(char));
......@@ -139,7 +139,12 @@ bool validFileName(const std::string& filename)
return true;
}
#ifdef WIN32
#ifdef MSWIN
bool isAbsolutePath(const std::string& in_path)
{
return (in_path.size()>=2 && in_path[1]==':');
}
bool fileExists(const std::string& filename)
{
return ( GetFileAttributes( filename.c_str() ) != INVALID_FILE_ATTRIBUTES );
......@@ -178,6 +183,11 @@ void readDirectory(const std::string& path, std::list<std::string>& dirlist, con
FindClose(hFind);
}
#else
bool isAbsolutePath(const std::string& in_path)
{
return (in_path.size()>=1 && in_path[0]=='/');
}
bool fileExists(const std::string& filename)
{
struct stat buffer ;
......
......@@ -84,6 +84,13 @@ namespace IOUtils {
*/
std::string getPath(const std::string& filename, const bool& resolve=false);
/**
* @brief checks if a path is an absolute path
* @param in_path string containing the path to check
* @return true if the given string represents an absolute path
*/
bool isAbsolutePath(const std::string& in_path);
/**
* @brief extract the file name from a path+filename string.
* @param path path to extract the true filename from
......
......@@ -25,7 +25,7 @@
#include <set>
#include <string>
#ifdef WIN32
#ifdef MSWIN
#pragma warning(disable:4512) //we don't need any = operator!
#endif
......
......@@ -28,7 +28,7 @@
#include <meteoio/MessageBoxX11.h>
#endif
#endif
#if defined(WIN32)
#if defined(MSWIN)
#include <windows.h>
#undef max
#undef min
......@@ -47,7 +47,7 @@ namespace mio {
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)
#if defined(MSWIN)
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
......@@ -71,7 +71,7 @@ IOException::IOException(const std::string& message, const std::string& position
IOException::IOException(const std::string& message, const std::string& position) : msg(), full_output()
#endif
{
#if defined(WIN32)
#if defined(MSWIN)
const char *delim = strrchr(position.c_str(), '\\');
#else
const char *delim = strrchr(position.c_str(), '/');
......
......@@ -27,7 +27,7 @@
#include <vector>
#include <map>
#ifdef WIN32
#ifdef MSWIN
#pragma warning(disable:4512) //we don't need any = operator!
#endif
......
......@@ -16,11 +16,9 @@
You should have received a copy of the GNU Lesser General Public License
along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
*/
//AUTHORS: Tuan Anh Nguyen (original implementation in popc)
// Mathias Bavay (port and rewrite for Alpine3D, then MeteoIO)
#include <stdio.h>
#ifdef WIN32
#ifdef MSWIN
#include <windows.h>
#undef max
#undef min
......@@ -88,7 +86,7 @@ double Timer::getElapsed() const {
return elapsed;
}
#ifdef WIN32
#ifdef MSWIN
long double Timer::getCurrentTime() const {
SYSTEMTIME systemTime;
GetSystemTime( &systemTime );
......@@ -115,7 +113,7 @@ long double Timer::getCurrentTime() const {
#endif
#ifndef WIN32
#ifndef MSWIN
const int UsageTimer::who = RUSAGE_SELF;
UsageTimer::UsageTimer() : start_usage(), current_usage(), user_time(0.), sys_time(0.), elapsed(0.), is_running(false) {}
......
......@@ -22,18 +22,9 @@
#ifndef __TIMER_H__
#define __TIMER_H__
#include <meteoio/IOExceptions.h>
#include <string>
#include <sstream>
#include <utility>
#include <iomanip>
#include <iostream>
#include <ctime>
#include <sys/resource.h>
#ifndef WIN32
#include <sys/resource.h>
#endif
#include <meteoio/IOExceptions.h>
namespace mio {
......@@ -61,7 +52,7 @@ protected:
bool isRunning;
};
#ifndef WIN32
#ifndef MSWIN
/**
* @class UsageTimer
* @author Thomas Egger
......
......@@ -20,7 +20,7 @@
#define __EXPORTS_H__
// Generic helper definitions for shared library support
#if defined WIN32 || defined __CYGWIN__
#if defined MSWIN || defined __CYGWIN__
#define MIO_HELPER_DLL_IMPORT __declspec(dllimport)
#define MIO_HELPER_DLL_EXPORT __declspec(dllexport)
#define MIO_HELPER_DLL_LOCAL
......
......@@ -23,7 +23,7 @@
#include <string>
#include <set>
#ifdef WIN32
#ifdef MSWIN
#pragma warning(disable:4512) //we don't need any = operator!
#endif
......
......@@ -81,6 +81,7 @@ const double NetCDFIO::plugin_nodata = -9999999.; //CNRM-GAME nodata value
const std::string NetCDFIO::cf_time = "time";
const std::string NetCDFIO::cf_units = "units";
const std::string NetCDFIO::cf_days = "days since ";
const std::string NetCDFIO::cf_hours = "hours since ";
const std::string NetCDFIO::cf_seconds = "seconds since ";
const std::string NetCDFIO::cf_latitude = "lat";
const std::string NetCDFIO::cf_longitude = "lon";
......@@ -111,6 +112,15 @@ const std::string NetCDFIO::cnrm_p = "PSurf";
const std::string NetCDFIO::cnrm_ilwr = "LWdown";
const std::string NetCDFIO::cnrm_timestep = "FRC_TIME_STP";
const std::string NetCDFIO::ecmwf_ta = "t2m";
const std::string NetCDFIO::ecmwf_p = "sp";
const std::string NetCDFIO::ecmwf_iswr = "ssrd";
const std::string NetCDFIO::ecmwf_ilwr = "strd";
const std::string NetCDFIO::ecmwf_hnw = "tp";
const std::string NetCDFIO::ecmwf_td = "d2m";
const std::string NetCDFIO::ecmwf_u10 = "u10";
const std::string NetCDFIO::ecmwf_v10 = "v10";
std::map<std::string, size_t> NetCDFIO::paramname;
std::map<std::string, std::string> NetCDFIO::map_name;
const bool NetCDFIO::__init = NetCDFIO::initStaticData();
......@@ -644,6 +654,10 @@ void NetCDFIO::get_indices(const int& ncid, const Date& dateStart, const Date& d
start /= 86400;
end /= 86400;
}
if (unit_type == hours) {
start /= 24;
end /= 24;
}
time_start += Date(start, 0.0);
time_end += Date(end, 0.0);
......@@ -658,6 +672,9 @@ void NetCDFIO::get_indices(const int& ncid, const Date& dateStart, const Date& d
if (unit_type == seconds) {
time[ii] /= 86400;
}
if (unit_type == hours) {
time[ii] /= 24;
}
const Date tmp_date = offset + Date(time[ii], 0.0);
......@@ -686,14 +703,18 @@ void NetCDFIO::calculate_offset(const std::string& units, NetCDFIO::TimeUnit& ti
{
string tmp(units);
const size_t found_sec = units.find(NetCDFIO::cf_seconds);
const size_t found_hour = units.find(NetCDFIO::cf_hours);
const size_t found_day = units.find(NetCDFIO::cf_days);
if (found_sec != string::npos) {
time_unit = seconds;
tmp = tmp.substr(found_sec + NetCDFIO::cf_seconds.size());
} else if (found_hour != string::npos) {
time_unit = hours;
tmp = tmp.substr(found_hour + NetCDFIO::cf_hours.size());
} else if (found_day != string::npos) {
time_unit = days;
tmp = tmp.substr(found_day+ + NetCDFIO::cf_days.size());
tmp = tmp.substr(found_day + NetCDFIO::cf_days.size());
} else {
throw InvalidFormatException("Variable '"+NetCDFIO::cf_time+"' has no valid attribute '" + cf_units + "'" , AT);
}
......@@ -1077,12 +1098,36 @@ std::string NetCDFIO::get_varname(const MeteoGrids::Parameters& parameter)
{
string varname = MeteoGrids::getParameterName(parameter);
if (parameter == MeteoGrids::TA) varname = cf_ta;
else if (parameter == MeteoGrids::RH) varname = cf_rh;
else if (parameter == MeteoGrids::DEM) varname = cf_altitude;
else if (parameter == MeteoGrids::P) varname = cf_p;
//TODO: complete mapping
const Naming naming_scheme=full;
if (naming_scheme==full) {
if (parameter == MeteoGrids::TA) varname = cf_ta;
else if (parameter == MeteoGrids::RH) varname = cf_rh;
else if (parameter == MeteoGrids::DEM) varname = cf_altitude;
else if (parameter == MeteoGrids::P) varname = cf_p;
} else if (naming_scheme==cnrm) {
if (parameter == MeteoGrids::TA) varname = cnrm_ta;
else if (parameter == MeteoGrids::RH) varname = cnrm_rh;
else if (parameter == MeteoGrids::DEM) varname = cnrm_altitude;
else if (parameter == MeteoGrids::P) varname = cnrm_p;
else if (parameter == MeteoGrids::VW) varname = cnrm_vw;
else if (parameter == MeteoGrids::DW) varname = cnrm_dw;
else if (parameter == MeteoGrids::ILWR) varname = cnrm_ilwr;
else if (parameter == MeteoGrids::HNW) varname = cnrm_hnw; //HACK this should add snowf!
else if (parameter == MeteoGrids::SLOPE) varname = cnrm_slope;
else if (parameter == MeteoGrids::AZI) varname = cnrm_aspect;
//HACK: iswr=dir+diff
//HACK: U, V from vw, dw
} else if (naming_scheme==ecmwf) {
if (parameter == MeteoGrids::TA) varname = ecmwf_ta;
else if (parameter == MeteoGrids::P) varname = ecmwf_p;
else if (parameter == MeteoGrids::ISWR) varname = ecmwf_iswr;
else if (parameter == MeteoGrids::ILWR) varname = ecmwf_ilwr;
else if (parameter == MeteoGrids::HNW) varname = ecmwf_hnw;
else if (parameter == MeteoGrids::U) varname = ecmwf_u10; //HACK: height correction
else if (parameter == MeteoGrids::V) varname = ecmwf_v10; //HACK: height correction
//HACK RH from Td, VW, DW from U, V
}
return varname;
}
......
......@@ -35,8 +35,6 @@ namespace mio {
*/
class NetCDFIO : public IOInterface {
public:
enum TimeUnit { seconds, hours, days };
NetCDFIO(const std::string& configfile);
NetCDFIO(const NetCDFIO&);
NetCDFIO(const Config& cfgreader);
......@@ -61,6 +59,9 @@ class NetCDFIO : public IOInterface {
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
private:
enum TimeUnit { seconds, hours, days };
enum Naming { full, cnrm, ecmwf };
void parseInputOutputSection();
void create_parameters(const int& ncid, const int& did_time, const int& did_points, const size_t& number_of_records,
const size_t& number_of_stations, std::map<size_t, std::string>& map_param_name,
......@@ -97,9 +98,10 @@ class NetCDFIO : public IOInterface {
// Private variables
static const double plugin_nodata; //plugin specific nodata value, e.g. -999
static const std::string cf_time, cf_units, cf_days, cf_seconds, cf_latitude, cf_longitude, cf_altitude, cf_ta, cf_rh, cf_p;
static const std::string cf_time, cf_units, cf_days, cf_hours, cf_seconds, cf_latitude, cf_longitude, cf_altitude, cf_ta, cf_rh, cf_p;
static const std::string cnrm_points, cnrm_latitude, cnrm_longitude, cnrm_altitude, cnrm_aspect, cnrm_slope, cnrm_ta, cnrm_rh, cnrm_vw, cnrm_dw, cnrm_qair;
static const std::string cnrm_co2air, cnrm_theorsw, cnrm_neb, cnrm_hnw, cnrm_snowf, cnrm_swr_direct, cnrm_swr_diffuse, cnrm_p, cnrm_ilwr, cnrm_timestep;
static const std::string ecmwf_ta, ecmwf_p, ecmwf_iswr, ecmwf_ilwr, ecmwf_hnw, ecmwf_u10, ecmwf_v10, ecmwf_td;
static std::map<std::string, size_t> paramname; ///<Associate a name with meteo parameters in Parameters
static std::map<std::string, std::string> map_name; ///Associate MeteoIO parameter names with CNRM parameter names
......
......@@ -341,7 +341,7 @@ void PNGIO::setFile(const std::string& filename, png_structp& png_ptr, png_infop
}
// Setup Exception handling
#ifdef WIN32
#ifdef MSWIN
#pragma warning(disable:4611) //the setjmp of libpng has been set up so that it can safely be called from c++
#endif
if (setjmp(png_jmpbuf(png_ptr))) {
......
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