WSL/SLF GitLab Repository

Commit 398ad906 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

All the methods defined in FileUtils have been placed within a FileUtils namespace for clarity

parent eed9efcd
......@@ -27,7 +27,7 @@ const char* Config::defaultSection = "GENERAL";
//Constructors
Config::Config() : properties(), imported(), sourcename(), configRootDir() {}
Config::Config(const std::string& i_filename) : properties(), imported(), sourcename(i_filename), configRootDir(IOUtils::getPath(i_filename, true))
Config::Config(const std::string& i_filename) : properties(), imported(), sourcename(i_filename), configRootDir(FileUtils::getPath(i_filename, true))
{
addFile(i_filename);
}
......@@ -40,14 +40,14 @@ ConfigProxy Config::get(const std::string& key, const std::string& section, cons
//Populating the property map
void Config::addFile(const std::string& i_filename)
{
if (configRootDir.empty()) configRootDir = IOUtils::getPath(i_filename, true);
if (configRootDir.empty()) configRootDir = FileUtils::getPath(i_filename, true);
sourcename = i_filename;
parseFile(i_filename);
}
void Config::addCmdLine(const std::string& cmd_line)
{
if (configRootDir.empty()) configRootDir = IOUtils::getPath(IOUtils::getCWD(), true); //resolve symlinks, etc
if (configRootDir.empty()) configRootDir = FileUtils::getPath(FileUtils::getCWD(), true); //resolve symlinks, etc
sourcename = std::string("Command line");
parseCmdLine(cmd_line);
}
......@@ -171,8 +171,8 @@ void Config::parseFile(const std::string& filename)
{
std::ifstream fin; //Input file streams
if (!IOUtils::validFileAndPath(filename)) throw InvalidNameException(filename,AT);
if (!IOUtils::fileExists(filename)) throw NotFoundException(filename, AT);
if (!FileUtils::validFileAndPath(filename)) throw InvalidNameException(filename,AT);
if (!FileUtils::fileExists(filename)) throw NotFoundException(filename, AT);
//Open file
fin.open (filename.c_str(), ifstream::in);
......@@ -181,7 +181,7 @@ void Config::parseFile(const std::string& filename)
}
std::string section( defaultSection );
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
const char eoln = FileUtils::getEoln(fin); //get the end of line character for the file
unsigned int linenr = 0;
std::vector<std::string> import_after; //files to import after the current one
bool accept_import_before = true;
......@@ -338,16 +338,16 @@ std::string Config::extract_section(std::string key) const
std::string Config::clean_import_path(const std::string& in_path) const
{
//if this is a relative path, prefix the import path with the current path
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);
const std::string prefix = ( FileUtils::isAbsolutePath(in_path) )? "" : FileUtils::getPath(sourcename, true)+"/";
const std::string path = FileUtils::getPath(prefix+in_path, true); //clean & resolve path
const std::string filename = FileUtils::getFilename(in_path);
return path + "/" + filename;
}
void Config::write(const std::string& filename) const
{
if (!IOUtils::validFileAndPath(filename)) throw InvalidNameException(filename,AT);
if (!FileUtils::validFileAndPath(filename)) throw InvalidNameException(filename,AT);
std::ofstream fout(filename.c_str(), ios::out);
if (fout.fail()) throw AccessException(filename, AT);
......
......@@ -38,17 +38,17 @@
#include <meteoio/IOUtils.h>
namespace mio {
namespace IOUtils {
namespace FileUtils {
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 NotFoundException(src, AT);
if (!fileExists(src)) throw NotFoundException(src, AT);
std::ifstream fin(src.c_str(), std::ios::binary);
if (fin.fail()) throw AccessException(src, AT);
if (!IOUtils::validFileAndPath(dest)) throw InvalidNameException(dest, AT);
if (!validFileAndPath(dest)) throw InvalidNameException(dest, AT);
std::ofstream fout(dest.c_str(), std::ios::binary);
if (fout.fail()) {
fin.close();
......@@ -341,7 +341,7 @@ void FileIndexer::setIndex(const Date& i_date, const std::streampos& i_pos)
void FileIndexer::setIndex(const std::string& i_date, const std::streampos& i_pos)
{
Date tmpdate;
convertString(tmpdate, i_date, 0.);
IOUtils::convertString(tmpdate, i_date, 0.);
setIndex(tmpdate, i_pos);
}
......@@ -361,7 +361,7 @@ std::streampos FileIndexer::getIndex(const Date& i_date) const
std::streampos FileIndexer::getIndex(const std::string& i_date) const
{
Date tmpdate;
convertString(tmpdate, i_date, 0.);
IOUtils::convertString(tmpdate, i_date, 0.);
return getIndex(tmpdate);
}
......@@ -394,5 +394,5 @@ const std::string FileIndexer::toString() const
return os.str();
}
} //end namespace IOUtils
} //end namespace FileUtils
} //end namespace mio
......@@ -26,7 +26,7 @@
#include <meteoio/dataClasses/Date.h>
namespace mio {
namespace IOUtils {
namespace FileUtils {
/**
* @brief Copies a files from one location to another
......@@ -166,7 +166,7 @@ namespace IOUtils {
std::vector< struct file_index > vecIndex;
};
} //end namespace IOUtils
} //end namespace FileUtils
} //end namespace mio
#endif
......@@ -605,16 +605,16 @@ void IOHandler::create_exclude_map()
if (!exclude_file.empty()) {
//if this is a relative path, prefix the path with the current path
const std::string prefix = ( IOUtils::isAbsolutePath(exclude_file) )? "" : cfg.getConfigRootDir()+"/";
const std::string path = IOUtils::getPath(prefix+exclude_file, true); //clean & resolve path
const std::string filename = path + "/" + IOUtils::getFilename(exclude_file);
const std::string prefix = ( FileUtils::isAbsolutePath(exclude_file) )? "" : cfg.getConfigRootDir()+"/";
const std::string path = FileUtils::getPath(prefix+exclude_file, true); //clean & resolve path
const std::string filename = path + "/" + FileUtils::getFilename(exclude_file);
if (!IOUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
if (!FileUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
std::ifstream fin(filename.c_str(), std::ifstream::in);
if (fin.fail()) throw AccessException(filename, AT);
try {
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
const char eoln = FileUtils::getEoln(fin); //get the end of line character for the file
vector<string> tmpvec;
string line;
......@@ -681,16 +681,16 @@ void IOHandler::create_keep_map()
if (!keep_file.empty()) {
//if this is a relative path, prefix the path with the current path
const std::string prefix = ( IOUtils::isAbsolutePath(keep_file) )? "" : cfg.getConfigRootDir()+"/";
const std::string path = IOUtils::getPath(prefix+keep_file, true); //clean & resolve path
const std::string filename = path + "/" + IOUtils::getFilename(keep_file);
const std::string prefix = ( FileUtils::isAbsolutePath(keep_file) )? "" : cfg.getConfigRootDir()+"/";
const std::string path = FileUtils::getPath(prefix+keep_file, true); //clean & resolve path
const std::string filename = path + "/" + FileUtils::getFilename(keep_file);
if (!IOUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
if (!FileUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
std::ifstream fin(filename.c_str(), std::ifstream::in);
if (fin.fail()) throw AccessException(filename, AT);
try {
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
const char eoln = FileUtils::getEoln(fin); //get the end of line character for the file
vector<string> tmpvec;
string line;
......
......@@ -250,7 +250,7 @@ void readKeyValueHeader(std::map<std::string,std::string>& headermap,
std::string line;
//make a test for end of line encoding:
const char eol = getEoln(fin);
const char eol = FileUtils::getEoln(fin);
for (size_t ii=0; ii< linecount; ii++){
if (std::getline(fin, line, eol)) {
......
......@@ -1073,12 +1073,12 @@ double USERInterpolation::getQualityRating(const Date& i_date, const MeteoData::
cfg.getValue("GRID2DPATH", "Input", grid2d_path);
}
if (!IOUtils::validFileAndPath(grid2d_path+"/"+filename)) {
if (!FileUtils::validFileAndPath(grid2d_path+"/"+filename)) {
cerr << "[E] Invalid grid filename for "+algo+" interpolation algorithm: " << grid2d_path+"/"+filename << "\n";
return 0.0;
}
return (IOUtils::fileExists(grid2d_path+"/"+filename))? 1. : 0.;
return (FileUtils::fileExists(grid2d_path+"/"+filename))? 1. : 0.;
}
void USERInterpolation::calculate(const DEMObject& dem, Grid2DObject& grid)
......@@ -1088,7 +1088,7 @@ void USERInterpolation::calculate(const DEMObject& dem, Grid2DObject& grid)
if (!grid.isSameGeolocalization(dem)) {
throw InvalidArgumentException("[E] trying to load a grid(" + filename + ") that does not have the same georeferencing as the DEM!", AT);
} else {
info << IOUtils::getFilename(filename);
info << FileUtils::getFilename(filename);
}
}
......@@ -1120,7 +1120,7 @@ ALS_Interpolation::ALS_Interpolation(Meteo2DInterpolator& i_mi,
}
}
if (!IOUtils::validFileAndPath(grid2d_path+"/"+filename)) {
if (!FileUtils::validFileAndPath(grid2d_path+"/"+filename)) {
throw InvalidNameException("[E] Invalid grid filename for "+algo+" interpolation algorithm: "+grid2d_path+"/"+filename, AT);
}
}
......@@ -1149,7 +1149,7 @@ double ALS_Interpolation::getQualityRating(const Date& i_date, const MeteoData::
base_algo = (nrOfMeasurments>1)? base_algo_user : "AVG";
return (IOUtils::fileExists(grid2d_path+"/"+filename))? 1. : 0.;
return (FileUtils::fileExists(grid2d_path+"/"+filename))? 1. : 0.;
}
void ALS_Interpolation::calculate(const DEMObject& dem, Grid2DObject& grid)
......@@ -1175,7 +1175,7 @@ void ALS_Interpolation::calculate(const DEMObject& dem, Grid2DObject& grid)
if (!ALS_scan.isSameGeolocalization(dem))
throw InvalidArgumentException("[E] trying to load a grid(" + filename + ") that does not have the same georeferencing as the DEM!", AT);
else
info << IOUtils::getFilename(filename) << " - ";
info << FileUtils::getFilename(filename) << " - ";
initGrid(dem, grid);
const size_t nxy = grid.getNx()*grid.getNy();
......
......@@ -38,7 +38,7 @@ IOInterface* DEMLoader::generateIOInterface(
IOInterface *io = NULL;
try {
cfg.addKey("DEMFILE", "Input", IOUtils::cleanPath(cDemFile));
cfg.addKey("DEMFILE", "Input", FileUtils::cleanPath(cDemFile));
cfg.addKey("COORDSYS", "Input", cDemCoordSystem);
cfg.addKey("COORDPARAM", "Input", "");
......
......@@ -72,8 +72,8 @@ void FilterSuppr::process(const unsigned int& param, const std::vector<MeteoData
void FilterSuppr::fillSuppr_dates(const std::string& filename)
{
if (!IOUtils::validFileAndPath(filename)) throw InvalidNameException(filename, AT);
if (!IOUtils::fileExists(filename)) throw NotFoundException(filename, AT);
if (!FileUtils::validFileAndPath(filename)) throw InvalidNameException(filename, AT);
if (!FileUtils::fileExists(filename)) throw NotFoundException(filename, AT);
std::ifstream fin(filename.c_str());
if (fin.fail()) {
......@@ -82,7 +82,7 @@ void FilterSuppr::fillSuppr_dates(const std::string& filename)
ss << "error opening file \"" << filename << "\", possible reason: " << std::strerror(errno);
throw AccessException(ss.str(), AT);
}
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
const char eoln = FileUtils::getEoln(fin); //get the end of line character for the file
try {
size_t lcount=0;
......@@ -133,9 +133,9 @@ void FilterSuppr::parse_args(std::vector<std::string> vec_args)
throw InvalidArgumentException("Wrong range for filter " + getName() + ", it should be between 0 and 1", AT);
} else {
const std::string in_filename( vec_args[0] );
const std::string prefix = ( IOUtils::isAbsolutePath(in_filename) )? "" : root_path+"/";
const std::string path = IOUtils::getPath(prefix+in_filename, true); //clean & resolve path
const std::string filename = path + "/" + IOUtils::getFilename(in_filename);
const std::string prefix = ( FileUtils::isAbsolutePath(in_filename) )? "" : root_path+"/";
const std::string path = FileUtils::getPath(prefix+in_filename, true); //clean & resolve path
const std::string filename = path + "/" + FileUtils::getFilename(in_filename);
fillSuppr_dates(filename);
}
......
......@@ -86,9 +86,9 @@ void ProcAdd::parse_args(const std::vector<std::string>& vec_args)
//if this is a relative path, prefix the path with the current path
const std::string in_filename( vec_args[1] );
const std::string prefix = ( IOUtils::isAbsolutePath(in_filename) )? "" : root_path+"/";
const std::string path = IOUtils::getPath(prefix+in_filename, true); //clean & resolve path
const std::string filename = path + "/" + IOUtils::getFilename(in_filename);
const std::string prefix = ( FileUtils::isAbsolutePath(in_filename) )? "" : root_path+"/";
const std::string path = FileUtils::getPath(prefix+in_filename, true); //clean & resolve path
const std::string filename = path + "/" + FileUtils::getFilename(in_filename);
ProcessingBlock::readCorrections(getName(), filename, type, 0., vecOffsets);
} else
throw InvalidArgumentException("Wrong number of arguments for filter " + getName(), AT);
......
......@@ -87,9 +87,9 @@ void ProcMult::parse_args(const std::vector<std::string>& vec_args)
//if this is a relative path, prefix the path with the current path
const std::string in_filename = vec_args[1];
const std::string prefix = ( IOUtils::isAbsolutePath(in_filename) )? "" : root_path+"/";
const std::string path = IOUtils::getPath(prefix+in_filename, true); //clean & resolve path
const std::string filename = path + "/" + IOUtils::getFilename(in_filename);
const std::string prefix = ( FileUtils::isAbsolutePath(in_filename) )? "" : root_path+"/";
const std::string path = FileUtils::getPath(prefix+in_filename, true); //clean & resolve path
const std::string filename = path + "/" + FileUtils::getFilename(in_filename);
ProcessingBlock::readCorrections(getName(), filename, type, 1., vecFactors);
} else
throw InvalidArgumentException("Wrong number of arguments for filter " + getName(), AT);
......
......@@ -159,7 +159,7 @@ void ProcShade::readMask(const std::string& filter, const std::string& filename,
throw AccessException(ss.str(), AT);
}
char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
char eoln = FileUtils::getEoln(fin); //get the end of line character for the file
try {
size_t lcount=0;
......@@ -231,9 +231,9 @@ void ProcShade::parse_args(const std::vector<std::string>& vec_args)
const std::string root_path( cfg.getConfigRootDir() );
//if this is a relative path, prefix the path with the current path
const std::string in_filename = vec_args[0];
const std::string prefix = ( IOUtils::isAbsolutePath(in_filename) )? "" : root_path+"/";
const std::string path = IOUtils::getPath(prefix+in_filename, true); //clean & resolve path
const std::string filename = path + "/" + IOUtils::getFilename(in_filename);
const std::string prefix = ( FileUtils::isAbsolutePath(in_filename) )? "" : root_path+"/";
const std::string path = FileUtils::getPath(prefix+in_filename, true); //clean & resolve path
const std::string filename = path + "/" + FileUtils::getFilename(in_filename);
std::vector< std::pair<double,double> > mask;
readMask(getName(), filename, mask);
masks["*"] = mask; //this mask is valid for ALL stations
......
......@@ -225,7 +225,7 @@ void ProcessingBlock::readCorrections(const std::string& filter, const std::stri
const size_t maxIndex = corrections.size();
const size_t minIndex = (c_type=='h')? 0 : 1;
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
const char eoln = FileUtils::getEoln(fin); //get the end of line character for the file
try {
size_t index, lcount=0;
......
......@@ -94,7 +94,7 @@ void A3DIO::readStationData(const Date& timestamp, std::vector<StationData>& vec
vecStation.clear();
//read 1D station and add it to vecStation
if (!IOUtils::fileExists(meteo1d)) {
if (!FileUtils::fileExists(meteo1d)) {
throw NotFoundException(meteo1d, AT);
}
StationData sd;
......@@ -154,7 +154,7 @@ 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 AccessException(meteo1d, AT); //prevent invalid filenames
if (!FileUtils::fileExists(meteo1d)) throw AccessException(meteo1d, AT); //prevent invalid filenames
std::ifstream fin(meteo1d.c_str(), std::ifstream::in);
if (fin.fail()) {
throw AccessException(meteo1d, AT);
......@@ -163,7 +163,7 @@ void A3DIO::read1DStation(StationData& sd)
//read and parse the header
try {
//Read in station meta data
IOUtils::readKeyValueHeader(header, fin, 5, "="); //Read in 5 lines as header
FileUtils::readKeyValueHeader(header, fin, 5, "="); //Read in 5 lines as header
IOUtils::getValueForKey(header, "latitude", latitude);
IOUtils::getValueForKey(header, "longitude", longitude);
IOUtils::getValueForKey(header, "x_coord", xcoord);
......@@ -199,17 +199,17 @@ void A3DIO::read1DStation(StationData& sd)
void A3DIO::read1DMeteo(const Date& dateStart, const Date& dateEnd, std::vector< std::vector<MeteoData> >& vecMeteo)
{
if (!IOUtils::fileExists(meteo1d)) {
if (!FileUtils::fileExists(meteo1d)) {
throw NotFoundException(meteo1d, AT);
}
if (!IOUtils::fileExists(meteo1d)) throw AccessException(meteo1d, AT); //prevent invalid filenames
if (!FileUtils::fileExists(meteo1d)) throw AccessException(meteo1d, AT); //prevent invalid filenames
std::ifstream fin(meteo1d.c_str(), std::ifstream::in);
if (fin.fail()) {
throw AccessException(meteo1d,AT);
}
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
const char eoln = FileUtils::getEoln(fin); //get the end of line character for the file
//get station metadata
MeteoData tmpdata;
......@@ -220,7 +220,7 @@ void A3DIO::read1DMeteo(const Date& dateStart, const Date& dateEnd, std::vector<
try {
//Read one line, construct Date object and see whether date is greater or equal than the date_in object
bool eof_reached = false;
IOUtils::skipLines(fin, 6, eoln); //skip header lines
FileUtils::skipLines(fin, 6, eoln); //skip header lines
//Loop going through the data sequentially until dateStart is found
do {
......@@ -427,12 +427,12 @@ void A3DIO::constructMeteo2DFilenames(const Date& startDate, const Date& endDate
filenames.push_back(taFilename);
filenames.push_back(wspdFilename);
if (IOUtils::fileExists(wdirFilename)) //keeping wdir optional
if (FileUtils::fileExists(wdirFilename)) //keeping wdir optional
filenames.push_back(wdirFilename);
}
for (size_t ii=0; ii<filenames.size(); ii++) {
if (!IOUtils::fileExists(filenames[ii])) {
if (!FileUtils::fileExists(filenames[ii])) {
throw NotFoundException(filenames[ii], AT);
}
}
......@@ -447,13 +447,13 @@ 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 AccessException(filename, AT); //prevent invalid filenames
if (!FileUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
std::ifstream fin(filename.c_str(), std::ifstream::in);
if (fin.fail()) throw AccessException(filename, AT);
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
const char eoln = FileUtils::getEoln(fin); //get the end of line character for the file
IOUtils::skipLines(fin, 4, eoln);
FileUtils::skipLines(fin, 4, eoln);
getline(fin, line_in, eoln); //5th line holds the names of the stations
const size_t cols = IOUtils::readLineToVec(line_in, tmpvec);
if ( cols > 4) { // if there are any stations
......@@ -475,15 +475,15 @@ 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 AccessException(filename, AT); //prevent invalid filenames
if (!FileUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
std::ifstream fin(filename.c_str(), std::ifstream::in);
if (fin.fail()) {
throw AccessException(filename, AT);
}
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
const char eoln = FileUtils::getEoln(fin); //get the end of line character for the file
IOUtils::skipLines(fin, 4, eoln); //skip first 4 lines
FileUtils::skipLines(fin, 4, eoln); //skip first 4 lines
std::string line_in;
getline(fin, line_in, eoln); //line containing UNIQUE station names
std::vector<std::string> vec_names;
......@@ -570,15 +570,15 @@ 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 AccessException(filename, AT); //prevent invalid filenames
if (!FileUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
std::ifstream fin(filename.c_str(), std::ifstream::in);
if (fin.fail()) {
throw AccessException(filename, AT);
}
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
const char eoln = FileUtils::getEoln(fin); //get the end of line character for the file
IOUtils::skipLines(fin, 1, eoln);
FileUtils::skipLines(fin, 1, eoln);
//Read all relevant lines in
std::vector<std::string> vec_altitude, vec_xcoord, vec_ycoord, vec_names;
......@@ -639,11 +639,11 @@ void A3DIO::readPOI(std::vector<Coords>& pts)
std::string filename;
cfg.getValue("POIFILE", "Input", filename);
if (!IOUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
if (!FileUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
std::ifstream fin(filename.c_str(), std::ifstream::in);
if (fin.fail()) throw AccessException(filename,AT);
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
const char eoln = FileUtils::getEoln(fin); //get the end of line character for the file
std::string line_in;
std::vector<std::string> tmpvec;
......@@ -682,7 +682,7 @@ 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 InvalidNameException(filename,AT);
if (!FileUtils::validFileAndPath(filename)) throw InvalidNameException(filename,AT);
std::ofstream file(filename.c_str(), std::ios::out | std::ios::trunc);
if (!file) {
throw AccessException("[E] Can not open file "+filename, AT);
......@@ -774,7 +774,7 @@ 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 InvalidNameException(filename,AT);
if (!FileUtils::validFileAndPath(filename)) throw InvalidNameException(filename,AT);
file.open(filename.c_str(), ios::out | ios::trunc);
if (!file) {
throw AccessException("Can not create file "+filename, AT);
......
......@@ -134,7 +134,7 @@ void ALPUG::readMetaData()
const string filename = cfg.get("METAFILE", "Input");
const string metafile = inpath + "/" + filename;
if (!IOUtils::fileExists(metafile)) throw AccessException(metafile, AT); //prevent invalid filenames
if (!FileUtils::fileExists(metafile)) throw AccessException(metafile, AT); //prevent invalid filenames
errno = 0;
std::ifstream fin(metafile.c_str(), std::ifstream::in);
if (fin.fail()) {
......@@ -144,7 +144,7 @@ void ALPUG::readMetaData()
}
try {
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
const char eoln = FileUtils::getEoln(fin); //get the end of line character for the file
size_t linenr = 0;
vector<string> vecLine;
......@@ -297,7 +297,7 @@ void ALPUG::readMetoFile(const size_t& station_index, const Date& dateStart, con
const string station_id = vecIDs[station_index];
Date prev_date(0., 0.);
list<string> dirlist = IOUtils::readDirectory( inpath, station_id+dflt_extension );
list<string> dirlist = FileUtils::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 NoDataException(msg, AT);
......@@ -311,7 +311,7 @@ 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 AccessException(file_and_path, AT); //prevent invalid filenames
if (!FileUtils::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())
......
......@@ -156,8 +156,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 InvalidNameException(full_name, AT);
if (!IOUtils::fileExists(full_name)) throw NotFoundException(full_name, AT);
if (!FileUtils::validFileAndPath(full_name)) throw InvalidNameException(full_name, AT);
if (!FileUtils::fileExists(full_name)) throw NotFoundException(full_name, AT);
std::ifstream fin;
errno = 0;
......@@ -168,11 +168,11 @@ void ARCIO::read2DGrid_internal(Grid2DObject& grid_out, const std::string& full_
throw AccessException(ss.str(), AT);
}
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
const char eoln = FileUtils::getEoln(fin); //get the end of line character for the file
//Go through file, save key value pairs
try {
IOUtils::readKeyValueHeader(header, fin, 6, " ");
FileUtils::readKeyValueHeader(header, fin, 6, " ");
IOUtils::getValueForKey(header, "ncols", i_ncols);
IOUtils::getValueForKey(header, "nrows", i_nrows);
IOUtils::getValueForKey(header, "xllcorner", xllcorner);
......@@ -291,7 +291,7 @@ void ARCIO::readAssimilationData(const Date& date_in, Grid2DObject& da_out)
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 InvalidNameException(full_name,AT);
if (!FileUtils::validFileAndPath(full_name)) throw InvalidNameException(full_name,AT);
errno = 0;
std::ofstream fout;
fout.open(full_name.c_str(), ios::out);
......
......@@ -415,7 +415,7 @@ void ARPSIO::initializeTrueARPS(FILE* &fin, const std::string& filename, const c
void ARPSIO::openGridFile(FILE* &fin, const std::string& filename)
{
if (!IOUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
if (!FileUtils::fileExists(filename)) throw AccessException(filename, AT); //prevent invalid filenames
if ((fin=fopen(filename.c_str(),"r")) == NULL) {
fclose(fin);
throw AccessException("Can not open file "+filename, AT);
......
......@@ -114,7 +114,7 @@ void BormaIO::getFiles(const std::string& stationname, const Date& start_date, c
cfg.getValue("METEOPATH", "Input", xmlpath);
vecFiles.clear();
IOUtils::readDirectory(xmlpath, dirlist, "_" + stationname + dflt_extension);
FileUtils::readDirectory(xmlpath, dirlist, "_" + stationname + dflt_extension);
dirlist.sort();
//Check date in every filename
......@@ -191,7 +191,7 @@ void BormaIO::checkForMeteoFiles(const std::string& xmlpath, const std::string&
std::string& filename_out, Date& date_out)