WSL/SLF GitLab Repository

Commit 03a05cad authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Several exceptions have been renamed in order to be more generic (ex: instead...

Several exceptions have been renamed in order to be more generic (ex: instead of FileNotFound -> NotFound) and their text has been modified accordingly. The GSN plugin now reports the errors with more relevant details (invalid sensor name, no permissions).
parent dbbebe47
......@@ -175,13 +175,13 @@ void Config::parseFile(const std::string& filename)
{
std::ifstream fin; //Input file streams
if (!IOUtils::validFileAndPath(filename)) throw InvalidFileNameException(filename,AT);
if (!IOUtils::fileExists(filename)) throw FileNotFoundException(filename, AT);
if (!IOUtils::validFileAndPath(filename)) throw InvalidNameException(filename,AT);
if (!IOUtils::fileExists(filename)) throw NotFoundException(filename, AT);
//Open file
fin.open (filename.c_str(), ifstream::in);
if (fin.fail()) {
throw FileAccessException(filename, AT);
throw AccessException(filename, AT);
}
std::string section( defaultSection );
......@@ -351,9 +351,9 @@ std::string Config::clean_import_path(const std::string& in_path) const
void Config::write(const std::string& filename) const
{
if (!IOUtils::validFileAndPath(filename)) throw InvalidFileNameException(filename,AT);
if (!IOUtils::validFileAndPath(filename)) throw InvalidNameException(filename,AT);
std::ofstream fout(filename.c_str(), ios::out);
if (fout.fail()) throw FileAccessException(filename, AT);
if (fout.fail()) throw AccessException(filename, AT);
try {
string current_section;
......
......@@ -44,15 +44,15 @@ void copy_file(const std::string& src, const std::string& dest)
{
if (src == dest) return; //copying to the same file doesn't make sense, but is no crime either
if (!IOUtils::fileExists(src)) throw FileNotFoundException(src, AT);
if (!IOUtils::fileExists(src)) throw NotFoundException(src, AT);
std::ifstream fin(src.c_str(), std::ios::binary);
if (fin.fail()) throw FileAccessException(src, AT);
if (fin.fail()) throw AccessException(src, AT);
if (!IOUtils::validFileAndPath(dest)) throw InvalidFileNameException(dest, AT);
if (!IOUtils::validFileAndPath(dest)) throw InvalidNameException(dest, AT);
std::ofstream fout(dest.c_str(), std::ios::binary);
if (fout.fail()) {
fin.close();
throw FileAccessException(dest, AT);
throw AccessException(dest, AT);
}
fout << fin.rdbuf();
......@@ -196,14 +196,14 @@ void readDirectory(const std::string& path, std::list<std::string>& dirlist, con
const size_t path_length = path.length();
if (path_length > (MAX_PATH - 1)) {
std::cerr << "Path " << path << "is too long (" << path_length << " characters)" << std::endl;
throw FileAccessException("Error opening directory " + path, AT);
throw AccessException("Error opening directory " + path, AT);
}
const std::string inpath = path+"\\\\*";
WIN32_FIND_DATA ffd;
const HANDLE hFind = FindFirstFileA(inpath.c_str(), &ffd);
if (INVALID_HANDLE_VALUE == hFind) {
throw FileAccessException("Error opening directory " + path, AT);
throw AccessException("Error opening directory " + path, AT);
}
do {
......@@ -221,7 +221,7 @@ void readDirectory(const std::string& path, std::list<std::string>& dirlist, con
const DWORD dwError = GetLastError();
if (dwError != ERROR_NO_MORE_FILES) {
throw FileAccessException("Error listing files in directory " + path, AT);
throw AccessException("Error listing files in directory " + path, AT);
}
FindClose(hFind);
......@@ -254,7 +254,7 @@ void readDirectory(const std::string& path, std::list<std::string>& dirlist, con
{
DIR *dp = opendir(path.c_str());
if (dp == NULL) {
throw FileAccessException("Error opening directory " + path, AT);
throw AccessException("Error opening directory " + path, AT);
}
struct dirent *dirp;
......
......@@ -52,39 +52,39 @@ class IOException : public std::exception {
};
/**
* @class FileNotFoundException
* @brief thrown when a there is an unsuccessful attempt to locate a file
* @class NotFoundException
* @brief thrown when a there is an unsuccessful attempt to locate a file/server/...
*
* @author Thomas Egger
*/
class MIO_API FileNotFoundException : public IOException {
class MIO_API NotFoundException : public IOException {
public:
FileNotFoundException(const std::string& filename="",
const std::string& position="") : IOException("FileNotFoundException: " + filename, position){}
NotFoundException(const std::string& filename="",
const std::string& position="") : IOException("NotFound: " + filename, position){}
};
/**
* @class FileAccessException
* @brief thrown when a there are insufficient rights to access the file in a certain way (e.g. read, write)
* @class AccessException
* @brief thrown when a there are insufficient rights to access a file/server/... in a certain way (e.g. read, write)
*
* @author Thomas Egger
*/
class MIO_API FileAccessException : public IOException {
class MIO_API AccessException : public IOException {
public:
FileAccessException(const std::string& filename="",
const std::string& position="") : IOException("FileAccessException: " + filename, position){}
AccessException(const std::string& filename="",
const std::string& position="") : IOException("InvalidAccess: " + filename, position){}
};
/**
* @class InvalidFileNameException
* @brief thrown when a filename given is not valid (e.g. "..", "." or empty)
* @class InvalidNameException
* @brief thrown when a given filename/servername/... is not valid (e.g. "..", "." or empty)
*
* @author Thomas Egger
*/
class MIO_API InvalidFileNameException : public IOException {
class MIO_API InvalidNameException : public IOException {
public:
InvalidFileNameException(const std::string& filename="",
const std::string& position="") : IOException("InvalidFileNameException: " + filename, position){}
InvalidNameException(const std::string& filename="",
const std::string& position="") : IOException("InvalidName: " + filename, position){}
};
/**
......@@ -96,7 +96,7 @@ class MIO_API InvalidFileNameException : public IOException {
class MIO_API InvalidFormatException : public IOException {
public:
InvalidFormatException(const std::string& message="",
const std::string& position="") : IOException("InvalidFormatException: " + message, position){}
const std::string& position="") : IOException("InvalidFormat: " + message, position){}
};
/**
......@@ -108,7 +108,7 @@ class MIO_API InvalidFormatException : public IOException {
class MIO_API IndexOutOfBoundsException : public IOException {
public:
IndexOutOfBoundsException(const std::string& message="",
const std::string& position="") : IOException("IndexOutOfBoundsException: " + message, position){}
const std::string& position="") : IOException("IndexOutOfBounds: " + message, position){}
};
/**
......@@ -120,7 +120,7 @@ class MIO_API IndexOutOfBoundsException : public IOException {
class MIO_API ConversionFailedException : public IOException {
public:
ConversionFailedException(const std::string& message="",
const std::string& position="") : IOException("ConversionFailedException: " + message, position){}
const std::string& position="") : IOException("ConversionFailed: " + message, position){}
};
/**
......@@ -132,7 +132,7 @@ class MIO_API ConversionFailedException : public IOException {
class MIO_API InvalidArgumentException : public IOException {
public:
InvalidArgumentException(const std::string& message="",
const std::string& position="") : IOException("InvalidArgumentException: " + message, position){}
const std::string& position="") : IOException("InvalidArgument: " + message, position){}
};
/**
......@@ -144,20 +144,20 @@ class MIO_API InvalidArgumentException : public IOException {
class MIO_API UnknownValueException : public IOException {
public:
UnknownValueException(const std::string& message="",
const std::string& position="") : IOException("UnknownValueException: " + message, position){}
const std::string& position="") : IOException("UnknownValue: " + message, position){}
};
/**
* @class NoAvailableDataException
* @class NoDataException
* @brief thrown when no data is available
*
* @author Florian Hof
*/
class MIO_API NoAvailableDataException : public IOException
class MIO_API NoDataException : public IOException
{
public:
NoAvailableDataException(const std::string& message="",
const std::string& position="") : IOException("NoAvailableDataException: " + message, position){}
NoDataException(const std::string& message="",
const std::string& position="") : IOException("NoData: " + message, position){}
};
} //end namespace
......
......@@ -546,9 +546,9 @@ void IOHandler::create_exclude_map()
const std::string path = IOUtils::getPath(prefix+exclude_file, true); //clean & resolve path
const std::string filename = path + "/" + IOUtils::getFilename(exclude_file);
if (!IOUtils::fileExists(filename)) throw FileAccessException(filename, AT); //prevent invalid filenames
if (!IOUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
std::ifstream fin(filename.c_str(), std::ifstream::in);
if (fin.fail()) throw FileAccessException(filename, AT);
if (fin.fail()) throw AccessException(filename, AT);
try {
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
......@@ -608,9 +608,9 @@ void IOHandler::create_keep_map()
const std::string path = IOUtils::getPath(prefix+keep_file, true); //clean & resolve path
const std::string filename = path + "/" + IOUtils::getFilename(keep_file);
if (!IOUtils::fileExists(filename)) throw FileAccessException(filename, AT); //prevent invalid filenames
if (!IOUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
std::ifstream fin(filename.c_str(), std::ifstream::in);
if (fin.fail()) throw FileAccessException(filename, AT);
if (fin.fail()) throw AccessException(filename, AT);
try {
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
......
......@@ -297,7 +297,7 @@ size_t Meteo2DInterpolator::getVirtualMeteoData(const vstations_policy& strategy
void Meteo2DInterpolator::initVirtualStations()
{
if (!cfg.keyExists("DEM", "Input"))
throw NoAvailableDataException("In order to use virtual stations, please provide a DEM!", AT);
throw NoDataException("In order to use virtual stations, please provide a DEM!", AT);
DEMObject dem;
gridsmanager.readDEM(dem);
......@@ -319,7 +319,7 @@ void Meteo2DInterpolator::initVirtualStations()
if (!dem.gridify(v_coords[ii])) {
ostringstream ss;
ss << "Virtual station \"" << vecStation[ii] << "\" is not contained is provided DEM";
throw NoAvailableDataException(ss.str(), AT);
throw NoDataException(ss.str(), AT);
}
const size_t i = v_coords[ii].getGridI(), j = v_coords[ii].getGridJ();
......
......@@ -55,7 +55,7 @@ void ProcPSUMDistribute::process(const unsigned int& param, const std::vector<Me
std::ostringstream ss;
ss << "Redistribution of precipitation before reaccumulation failed: precipitation value required ";
ss << "in the " << startDate.toString(Date::ISO) << " - " << endDate.toString(Date::ISO) << " interval!\n";
throw NoAvailableDataException(ss.str(), AT);
throw NoDataException(ss.str(), AT);
}
}
continue;
......
......@@ -205,14 +205,14 @@ std::string ProcessingBlock::getName() const {
void ProcessingBlock::readCorrections(const std::string& filter, const std::string& filename, const char& c_type, const double& init, std::vector<double> &corrections)
{
if (!IOUtils::fileExists(filename)) throw FileAccessException(filename, AT); //prevent invalid filenames
if (!IOUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
errno = 0;
std::ifstream fin(filename.c_str(), std::ifstream::in);
if (fin.fail()) {
std::ostringstream ss;
ss << "Filter " << filter << ": ";
ss << "error opening file \"" << filename << "\", possible reason: " << std::strerror(errno);
throw FileAccessException(ss.str(), AT);
throw AccessException(ss.str(), AT);
}
if (c_type=='m') corrections.resize(12, init);
......
......@@ -65,9 +65,9 @@ std::vector<double> Interpol1D::quantiles(const std::vector<double>& X, const st
const size_t Xsize = X.size();
const size_t Qsize = quartiles.size();
if (Xsize == 0)
throw NoAvailableDataException("Trying to calculate quantiles with no data points", AT);
throw NoDataException("Trying to calculate quantiles with no data points", AT);
if (Qsize == 0)
throw NoAvailableDataException("No quantiles specified", AT);
throw NoDataException("No quantiles specified", AT);
//in order to properly escape nodata points, we need to copy in a temporary vector
vector<double> vecTemp;
......@@ -541,7 +541,7 @@ void Interpol1D::LinRegression(const std::vector<double>& X, const std::vector<d
//check arguments
const size_t n = X.size();
if (n<2)
throw NoAvailableDataException("Trying to calculate linear regression with too few data points", AT);
throw NoDataException("Trying to calculate linear regression with too few data points", AT);
if (n!=Y.size())
throw IOException("Vectors should have the same size for linear regression!", AT);
......@@ -556,7 +556,7 @@ void Interpol1D::LinRegression(const std::vector<double>& X, const std::vector<d
}
}
if (count<2)
throw NoAvailableDataException("Trying to calculate linear regression with too few valid data points", AT);
throw NoDataException("Trying to calculate linear regression with too few valid data points", AT);
x_avg /= (double)count;
y_avg /= (double)count;
......@@ -605,7 +605,7 @@ void Interpol1D::LinRegressionFixedRate(const std::vector<double>& X, const std:
{ //check arguments
const size_t n = X.size();
if (n==0)
throw NoAvailableDataException("Trying to calculate linear regression with no data points", AT);
throw NoDataException("Trying to calculate linear regression with no data points", AT);
if (n!=Y.size())
throw IOException("Vectors should have the same size for linear regression!", AT);
......@@ -620,7 +620,7 @@ void Interpol1D::LinRegressionFixedRate(const std::vector<double>& X, const std:
}
}
if (count==0)
throw NoAvailableDataException("Trying to calculate linear regression with no valid data points", AT);
throw NoDataException("Trying to calculate linear regression with no valid data points", AT);
x_avg /= (double)count;
y_avg /= (double)count;
......
......@@ -137,7 +137,7 @@ void A3DIO::readStationData(const Date& timestamp, std::vector<StationData>& vec
//read 1D station and add it to vecStation
if (!IOUtils::fileExists(meteo1d)) {
throw FileNotFoundException(meteo1d, AT);
throw NotFoundException(meteo1d, AT);
}
StationData sd;
read1DStation(sd);
......@@ -196,10 +196,10 @@ void A3DIO::read1DStation(StationData& sd)
double xcoord=IOUtils::nodata, ycoord=IOUtils::nodata, altitude=IOUtils::nodata;
std::map<std::string, std::string> header; // A map to save key value pairs of the file header
if (!IOUtils::fileExists(meteo1d)) throw FileAccessException(meteo1d, AT); //prevent invalid filenames
if (!IOUtils::fileExists(meteo1d)) throw AccessException(meteo1d, AT); //prevent invalid filenames
std::ifstream fin(meteo1d.c_str(), std::ifstream::in);
if (fin.fail()) {
throw FileAccessException(meteo1d, AT);
throw AccessException(meteo1d, AT);
}
//read and parse the header
......@@ -242,13 +242,13 @@ void A3DIO::read1DStation(StationData& sd)
void A3DIO::read1DMeteo(const Date& dateStart, const Date& dateEnd, std::vector< std::vector<MeteoData> >& vecMeteo)
{
if (!IOUtils::fileExists(meteo1d)) {
throw FileNotFoundException(meteo1d, AT);
throw NotFoundException(meteo1d, AT);
}
if (!IOUtils::fileExists(meteo1d)) throw FileAccessException(meteo1d, AT); //prevent invalid filenames
if (!IOUtils::fileExists(meteo1d)) throw AccessException(meteo1d, AT); //prevent invalid filenames
std::ifstream fin(meteo1d.c_str(), std::ifstream::in);
if (fin.fail()) {
throw FileAccessException(meteo1d,AT);
throw AccessException(meteo1d,AT);
}
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
......@@ -371,7 +371,7 @@ void A3DIO::read2DMeteo(std::vector< std::vector<MeteoData> >& vecMeteo)
//1D and 2D data must correspond, that means that if there is 1D data
//for a certain date (e.g. 1.1.2006) then 2D data must exist (prec2006.txt etc),
//otherwise throw FileNotFoundException
//otherwise throw NotFoundException
const Date startDate(vecMeteo[0].front().date.getJulian(), in_tz, false); //so that the correct filenames for the TZ will be constructed
const Date endDate(vecMeteo[0].back().date.getJulian(), in_tz, false);
......@@ -475,7 +475,7 @@ void A3DIO::constructMeteo2DFilenames(const Date& startDate, const Date& endDate
for (size_t ii=0; ii<filenames.size(); ii++) {
if (!IOUtils::fileExists(filenames[ii])) {
throw FileNotFoundException(filenames[ii], AT);
throw NotFoundException(filenames[ii], AT);
}
}
}
......@@ -489,9 +489,9 @@ size_t A3DIO::getNrOfStations(std::vector<std::string>& filenames, std::map<std:
for (size_t ii=0; ii<filenames.size(); ii++) {
const std::string filename = filenames[ii];
if (!IOUtils::fileExists(filename)) throw FileAccessException(filename, AT); //prevent invalid filenames
if (!IOUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
std::ifstream fin(filename.c_str(), std::ifstream::in);
if (fin.fail()) throw FileAccessException(filename, AT);
if (fin.fail()) throw AccessException(filename, AT);
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
......@@ -517,10 +517,10 @@ void A3DIO::read2DMeteoData(const std::string& filename, const std::string& para
std::map<std::string,size_t>& hashStations,
std::vector< std::vector<MeteoData> >& vecM, size_t& bufferindex)
{
if (!IOUtils::fileExists(filename)) throw FileAccessException(filename, AT); //prevent invalid filenames
if (!IOUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
std::ifstream fin(filename.c_str(), std::ifstream::in);
if (fin.fail()) {
throw FileAccessException(filename, AT);
throw AccessException(filename, AT);
}
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
......@@ -612,10 +612,10 @@ void A3DIO::read2DMeteoData(const std::string& filename, const std::string& para
void A3DIO::read2DMeteoHeader(const std::string& filename, std::map<std::string,size_t>& hashStations,
std::vector<StationData>& vecS)
{
if (!IOUtils::fileExists(filename)) throw FileAccessException(filename, AT); //prevent invalid filenames
if (!IOUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
std::ifstream fin(filename.c_str(), std::ifstream::in);
if (fin.fail()) {
throw FileAccessException(filename, AT);
throw AccessException(filename, AT);
}
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
......@@ -681,9 +681,9 @@ void A3DIO::readPOI(std::vector<Coords>& pts)
std::string filename;
cfg.getValue("POIFILE", "Input", filename);
if (!IOUtils::fileExists(filename)) throw FileAccessException(filename, AT); //prevent invalid filenames
if (!IOUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
std::ifstream fin(filename.c_str(), std::ifstream::in);
if (fin.fail()) throw FileAccessException(filename,AT);
if (fin.fail()) throw AccessException(filename,AT);
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
......@@ -724,10 +724,10 @@ int A3DIO::create1DFile(const std::vector< std::vector<MeteoData> >& data)
const size_t size = data[ii].size();
if (size>0) {
const std::string filename = tmp_path+"/meteo1D_"+data[ii][0].meta.getStationID()+".txt";
if (!IOUtils::validFileAndPath(filename)) throw InvalidFileNameException(filename,AT);
if (!IOUtils::validFileAndPath(filename)) throw InvalidNameException(filename,AT);
std::ofstream file(filename.c_str(), std::ios::out | std::ios::trunc);
if (!file) {
throw FileAccessException("[E] Can not open file "+filename, AT);
throw AccessException("[E] Can not open file "+filename, AT);
}
file << "Name = " << data[ii][0].meta.getStationID() << endl;
......@@ -816,10 +816,10 @@ void A3DIO::open2DFile(const std::vector< std::vector<MeteoData> >& data,
out << year;
const std::string filename = fileprefix+out.str()+".txt";
if (!IOUtils::validFileAndPath(filename)) throw InvalidFileNameException(filename,AT);
if (!IOUtils::validFileAndPath(filename)) throw InvalidNameException(filename,AT);
file.open(filename.c_str(), ios::out | ios::trunc);
if (!file) {
throw FileAccessException("Can not create file "+filename, AT);
throw AccessException("Can not create file "+filename, AT);
}
writeHeader(file, data, label);
}
......
......@@ -134,13 +134,13 @@ void ALPUG::readMetaData()
const string filename = cfg.get("METAFILE", "Input");
const string metafile = inpath + "/" + filename;
if (!IOUtils::fileExists(metafile)) throw FileAccessException(metafile, AT); //prevent invalid filenames
if (!IOUtils::fileExists(metafile)) throw AccessException(metafile, AT); //prevent invalid filenames
errno = 0;
std::ifstream fin(metafile.c_str(), std::ifstream::in);
if (fin.fail()) {
ostringstream ss;
ss << "File \'" << metafile << "\' could not be opened. Possible reason: " << strerror(errno) << "\n";
throw FileAccessException(ss.str(), AT);
throw AccessException(ss.str(), AT);
}
try {
......@@ -202,7 +202,7 @@ void ALPUG::readMetaData()
}
}
if (!msg.empty())
throw NoAvailableDataException(msg+" do(es) not have metadata in \'"+metafile+"\'", AT);
throw NoDataException(msg+" do(es) not have metadata in \'"+metafile+"\'", AT);
}
void ALPUG::read2DGrid(Grid2DObject& /*grid_out*/, const std::string& /*name_in*/)
......@@ -330,7 +330,7 @@ void ALPUG::readMetoFile(const size_t& station_index, const Date& dateStart, con
list<string> dirlist = IOUtils::readDirectory( inpath, station_id+dflt_extension );
if (dirlist.empty()) {
const std::string msg = "No data file found for station "+station_id+" in \'"+inpath+"\'"+". Files should be named as {YY}{station_id}"+dflt_extension+" with {YY} the last two digits of the year.";
throw NoAvailableDataException(msg, AT);
throw NoDataException(msg, AT);
}
for (int year=start_year; year<=end_year; ++year) {
......@@ -341,11 +341,11 @@ void ALPUG::readMetoFile(const size_t& station_index, const Date& dateStart, con
continue;
const string file_and_path = inpath + "/" + filename;
if (!IOUtils::fileExists(file_and_path)) throw FileAccessException(file_and_path, AT); //prevent invalid filenames
if (!IOUtils::fileExists(file_and_path)) throw AccessException(file_and_path, AT); //prevent invalid filenames
errno = 0;
std::ifstream fin(file_and_path.c_str(), ios::in|ios::binary); //ascii does end of line translation, which messes up the pointer code
if (fin.fail())
throw FileAccessException("Could not open \'" + file_and_path +"\'. Possible reason: " + strerror(errno) + "\n", AT);
throw AccessException("Could not open \'" + file_and_path +"\'. Possible reason: " + strerror(errno) + "\n", AT);
const char eoln = smet::SMETCommon::getEoln(fin); //get the end of line character for the file
const size_t nr_of_data_fields = vecFields.size();
......
......@@ -170,8 +170,8 @@ void ARCIO::read2DGrid_internal(Grid2DObject& grid_out, const std::string& full_
std::string line;
std::map<std::string, std::string> header; // A map to save key value pairs of the file header
if (!IOUtils::validFileAndPath(full_name)) throw InvalidFileNameException(full_name, AT);
if (!IOUtils::fileExists(full_name)) throw FileNotFoundException(full_name, AT);
if (!IOUtils::validFileAndPath(full_name)) throw InvalidNameException(full_name, AT);
if (!IOUtils::fileExists(full_name)) throw NotFoundException(full_name, AT);
fin.clear();
errno = 0;
......@@ -179,7 +179,7 @@ void ARCIO::read2DGrid_internal(Grid2DObject& grid_out, const std::string& full_
if (fin.fail()) {
ostringstream ss;
ss << "Error opening file \"" << full_name << "\", possible reason: " << strerror(errno);
throw FileAccessException(ss.str(), AT);
throw AccessException(ss.str(), AT);
}
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
......@@ -330,13 +330,13 @@ void ARCIO::readPOI(std::vector<Coords>&)
void ARCIO::write2DGrid(const Grid2DObject& grid_in, const std::string& name)
{
const std::string full_name = grid2dpath_out+"/"+name;
if (!IOUtils::validFileAndPath(full_name)) throw InvalidFileNameException(full_name,AT);
if (!IOUtils::validFileAndPath(full_name)) throw InvalidNameException(full_name,AT);
errno = 0;
fout.open(full_name.c_str(), ios::out);
if (fout.fail()) {
ostringstream ss;
ss << "Error opening file \"" << full_name << "\", possible reason: " << strerror(errno);
throw FileAccessException(ss.str(), AT);
throw AccessException(ss.str(), AT);
}
try {
......
......@@ -217,7 +217,7 @@ void ARPSIO::read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& pa
ostringstream ss;
ss << "No suitable data found for parameter " << MeteoGrids::getParameterName(parameter) << " ";
ss << "at time step " << date.toString(Date::ISO) << " in file \"" << name << "\"";
throw NoAvailableDataException(ss.str(), AT);
throw NoDataException(ss.str(), AT);
}
rewind(fin);
......@@ -410,10 +410,10 @@ void ARPSIO::openGridFile(const std::string& in_filename)
unsigned int v1;
filename = in_filename;
if (!IOUtils::fileExists(filename)) throw FileAccessException(filename, AT); //prevent invalid filenames
if (!IOUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
if ((fin=fopen(filename.c_str(),"r")) == NULL) {
cleanup();
throw FileAccessException("Can not open file "+filename, AT);
throw AccessException("Can not open file "+filename, AT);
}
//identify if the file is an original arps file or a file modified by ARPSGRID
......
......@@ -198,7 +198,7 @@ void CNRMIO::read2DGrid_internal(Grid2DObject& grid_out, const std::string& file
vector<string> dimname;
vector<size_t> dimlen;
if (!IOUtils::fileExists(filename)) throw FileAccessException(filename, AT); //prevent invalid filenames
if (!IOUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
ncpp::open_file(filename, NC_NOWRITE, ncid);
ncpp::get_variable(ncid, varname, varid);
ncpp::get_dimension(ncid, varname, varid, dimid, dim_varid, dimname, dimlen);
......@@ -289,7 +289,7 @@ void CNRMIO::readStationData(const Date&, std::vector<StationData>& vecStation)
const string file_and_path = path + "/" + filename;
int ncid;
if (!IOUtils::fileExists(file_and_path)) throw FileAccessException(file_and_path, AT); //prevent invalid filenames
if (!IOUtils::fileExists(file_and_path)) throw AccessException(file_and_path, AT); //prevent invalid filenames
ncpp::open_file(file_and_path, NC_NOWRITE, ncid);
readMetaData(ncid, vecMetaData);
ncpp::close_file(file_and_path, ncid);
......@@ -353,7 +353,7 @@ void CNRMIO::readMeteoData(const Date& dateStart, const Date& dateEnd, std::vect
const string file_and_path = path + "/" + filename;
int ncid;
if (!IOUtils::fileExists(file_and_path)) throw FileAccessException(file_and_path, AT); //prevent invalid filenames
if (!IOUtils::fileExists(file_and_path)) throw AccessException(file_and_path, AT); //prevent invalid filenames
ncpp::open_file(file_and_path, NC_NOWRITE, ncid);
if (vecMetaData.empty()) readMetaData(ncid, vecMetaData);
......@@ -936,7 +936,7 @@ void CNRMIO::write2DGrid_internal(const Grid2DObject& grid_in, const std::string
ncpp::start_definitions(filename, ncid);
} else {
if (!IOUtils::validFileAndPath(filename)) throw InvalidFileNameException(filename,AT);
if (!IOUtils::validFileAndPath(filename)) throw InvalidNameException(filename,AT);
ncpp::create_file(filename, NC_CLASSIC_MODEL, ncid);
ncpp::add_attribute(ncid, NC_GLOBAL, "Conventions", "CF-1.3");
......
......@@ -243,7 +243,7 @@ void CosmoXMLIO::openIn_XML(const std::string& in_meteofile)
xmlInitParser();
xmlKeepBlanksDefault(0);