Commit 2d17ce26 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

cleanups

parent f9d3bc20
......@@ -16,13 +16,13 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Copyright (C) 2019 Max-Planck-Society
/* Copyright (C) 2019-2020 Max-Planck-Society
Author: Martin Reinecke */
#ifndef MRUTIL_ERROR_HANDLING_H
#define MRUTIL_ERROR_HANDLING_H
#include <iostream>
#include <sstream>
#include <exception>
namespace mr {
......@@ -37,8 +37,9 @@ namespace detail_error_handling {
#define MR_fail(...) \
do { \
::mr::detail_error_handling::streamDump__(::std::cerr, MRUTIL_ERROR_HANDLING_LOC_, "\n", ##__VA_ARGS__, "\n"); \
throw ::std::runtime_error("error exit"); \
::std::ostringstream msg; \
::mr::detail_error_handling::streamDump__(msg, MRUTIL_ERROR_HANDLING_LOC_, "\n", ##__VA_ARGS__, "\n"); \
throw ::std::runtime_error(msg.str()); \
} while(0)
#define MR_assert(cond,...) \
......@@ -58,20 +59,18 @@ class CodeLocation
CodeLocation(const char *file_, int line_, const char *func_=nullptr)
: file(file_), func(func_), line(line_) {}
::std::ostream &print(::std::ostream &os) const;
inline ::std::ostream &print(::std::ostream &os) const
{
os << "\n" << file << ": " << line;
if (func) os << " (" << func << ")";
os << ":\n";
return os;
}
};
inline ::std::ostream &operator<<(::std::ostream &os, const CodeLocation &loc)
{ return loc.print(os); }
inline std::ostream &CodeLocation::print(std::ostream &os) const
{
os << file << ": " << line;
if (func) os << " (" << func << ")";
os << ":\n";
return os;
}
#if (__cplusplus>=201703L) // hyper-elegant C++2017 version
template<typename ...Args>
inline void streamDump__(::std::ostream &os, Args&&... args)
......
......@@ -26,7 +26,6 @@
#include <iostream>
#include <complex>
using std::complex;
#include "libsharp2/sharp.h"
#include "libsharp2/sharp_geomhelpers.h"
#include "libsharp2/sharp_almhelpers.h"
......@@ -472,13 +471,13 @@ static void sharp_test (int argc, const char **argv)
{
if (mytask==0) sharp_announce("sharp_test");
MR_assert(argc>=8,"usage: grid lmax mmax geom1 geom2 spin [ntrans]");
int lmax=atoi(argv[3]);
int mmax=atoi(argv[4]);
int gpar1=atoi(argv[5]);
int gpar2=atoi(argv[6]);
int spin=atoi(argv[7]);
auto lmax=stringToData<int>(argv[3]);
auto mmax=stringToData<int>(argv[4]);
auto gpar1=stringToData<int>(argv[5]);
auto gpar2=stringToData<int>(argv[6]);
auto spin=stringToData<int>(argv[7]);
int ntrans=1;
if (argc>=9) ntrans=atoi(argv[8]);
if (argc>=9) ntrans=stringToData<int>(argv[8]);
if (mytask==0) cout << "Testing map analysis accuracy.\n";
if (mytask==0) cout << "spin=" << spin << endl;
......
Markdown is supported
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