WSL/SLF GitLab Repository
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
snow-models
meteoio
Commits
398ad906
Commit
398ad906
authored
Apr 15, 2016
by
Mathias Bavay
Browse files
All the methods defined in FileUtils have been placed within a FileUtils namespace for clarity
parent
eed9efcd
Changes
31
Hide whitespace changes
Inline
Side-by-side
meteoio/Config.cc
View file @
398ad906
...
...
@@ -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
(
IO
Utils
::
getPath
(
i_filename
,
true
))
Config
::
Config
(
const
std
::
string
&
i_filename
)
:
properties
(),
imported
(),
sourcename
(
i_filename
),
configRootDir
(
File
Utils
::
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
=
IO
Utils
::
getPath
(
i_filename
,
true
);
if
(
configRootDir
.
empty
())
configRootDir
=
File
Utils
::
getPath
(
i_filename
,
true
);
sourcename
=
i_filename
;
parseFile
(
i_filename
);
}
void
Config
::
addCmdLine
(
const
std
::
string
&
cmd_line
)
{
if
(
configRootDir
.
empty
())
configRootDir
=
IO
Utils
::
getPath
(
IO
Utils
::
getCWD
(),
true
);
//resolve symlinks, etc
if
(
configRootDir
.
empty
())
configRootDir
=
File
Utils
::
getPath
(
File
Utils
::
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
(
!
IO
Utils
::
validFileAndPath
(
filename
))
throw
InvalidNameException
(
filename
,
AT
);
if
(
!
IO
Utils
::
fileExists
(
filename
))
throw
NotFoundException
(
filename
,
AT
);
if
(
!
File
Utils
::
validFileAndPath
(
filename
))
throw
InvalidNameException
(
filename
,
AT
);
if
(
!
File
Utils
::
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
=
IO
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
const
char
eoln
=
File
Utils
::
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
=
(
IO
Utils
::
isAbsolutePath
(
in_path
)
)
?
""
:
IO
Utils
::
getPath
(
sourcename
,
true
)
+
"/"
;
const
std
::
string
path
=
IO
Utils
::
getPath
(
prefix
+
in_path
,
true
);
//clean & resolve path
const
std
::
string
filename
=
IO
Utils
::
getFilename
(
in_path
);
const
std
::
string
prefix
=
(
File
Utils
::
isAbsolutePath
(
in_path
)
)
?
""
:
File
Utils
::
getPath
(
sourcename
,
true
)
+
"/"
;
const
std
::
string
path
=
File
Utils
::
getPath
(
prefix
+
in_path
,
true
);
//clean & resolve path
const
std
::
string
filename
=
File
Utils
::
getFilename
(
in_path
);
return
path
+
"/"
+
filename
;
}
void
Config
::
write
(
const
std
::
string
&
filename
)
const
{
if
(
!
IO
Utils
::
validFileAndPath
(
filename
))
throw
InvalidNameException
(
filename
,
AT
);
if
(
!
File
Utils
::
validFileAndPath
(
filename
))
throw
InvalidNameException
(
filename
,
AT
);
std
::
ofstream
fout
(
filename
.
c_str
(),
ios
::
out
);
if
(
fout
.
fail
())
throw
AccessException
(
filename
,
AT
);
...
...
meteoio/FileUtils.cc
View file @
398ad906
...
...
@@ -38,17 +38,17 @@
#include
<meteoio/IOUtils.h>
namespace
mio
{
namespace
IO
Utils
{
namespace
File
Utils
{
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
IO
Utils
}
//end namespace
File
Utils
}
//end namespace mio
meteoio/FileUtils.h
View file @
398ad906
...
...
@@ -26,7 +26,7 @@
#include
<meteoio/dataClasses/Date.h>
namespace
mio
{
namespace
IO
Utils
{
namespace
File
Utils
{
/**
* @brief Copies a files from one location to another
...
...
@@ -166,7 +166,7 @@ namespace IOUtils {
std
::
vector
<
struct
file_index
>
vecIndex
;
};
}
//end namespace
IO
Utils
}
//end namespace
File
Utils
}
//end namespace mio
#endif
meteoio/IOHandler.cmake.cc
View file @
398ad906
...
...
@@ -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
=
(
IO
Utils
::
isAbsolutePath
(
exclude_file
)
)
?
""
:
cfg
.
getConfigRootDir
()
+
"/"
;
const
std
::
string
path
=
IO
Utils
::
getPath
(
prefix
+
exclude_file
,
true
);
//clean & resolve path
const
std
::
string
filename
=
path
+
"/"
+
IO
Utils
::
getFilename
(
exclude_file
);
const
std
::
string
prefix
=
(
File
Utils
::
isAbsolutePath
(
exclude_file
)
)
?
""
:
cfg
.
getConfigRootDir
()
+
"/"
;
const
std
::
string
path
=
File
Utils
::
getPath
(
prefix
+
exclude_file
,
true
);
//clean & resolve path
const
std
::
string
filename
=
path
+
"/"
+
File
Utils
::
getFilename
(
exclude_file
);
if
(
!
IO
Utils
::
fileExists
(
filename
))
throw
AccessException
(
filename
,
AT
);
//prevent invalid filenames
if
(
!
File
Utils
::
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
=
IO
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
const
char
eoln
=
File
Utils
::
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
=
(
IO
Utils
::
isAbsolutePath
(
keep_file
)
)
?
""
:
cfg
.
getConfigRootDir
()
+
"/"
;
const
std
::
string
path
=
IO
Utils
::
getPath
(
prefix
+
keep_file
,
true
);
//clean & resolve path
const
std
::
string
filename
=
path
+
"/"
+
IO
Utils
::
getFilename
(
keep_file
);
const
std
::
string
prefix
=
(
File
Utils
::
isAbsolutePath
(
keep_file
)
)
?
""
:
cfg
.
getConfigRootDir
()
+
"/"
;
const
std
::
string
path
=
File
Utils
::
getPath
(
prefix
+
keep_file
,
true
);
//clean & resolve path
const
std
::
string
filename
=
path
+
"/"
+
File
Utils
::
getFilename
(
keep_file
);
if
(
!
IO
Utils
::
fileExists
(
filename
))
throw
AccessException
(
filename
,
AT
);
//prevent invalid filenames
if
(
!
File
Utils
::
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
=
IO
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
const
char
eoln
=
File
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
vector
<
string
>
tmpvec
;
string
line
;
...
...
meteoio/IOUtils.cc
View file @
398ad906
...
...
@@ -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
))
{
...
...
meteoio/InterpolationAlgorithms.cc
View file @
398ad906
...
...
@@ -1073,12 +1073,12 @@ double USERInterpolation::getQualityRating(const Date& i_date, const MeteoData::
cfg
.
getValue
(
"GRID2DPATH"
,
"Input"
,
grid2d_path
);
}
if
(
!
IO
Utils
::
validFileAndPath
(
grid2d_path
+
"/"
+
filename
))
{
if
(
!
File
Utils
::
validFileAndPath
(
grid2d_path
+
"/"
+
filename
))
{
cerr
<<
"[E] Invalid grid filename for "
+
algo
+
" interpolation algorithm: "
<<
grid2d_path
+
"/"
+
filename
<<
"
\n
"
;
return
0.0
;
}
return
(
IO
Utils
::
fileExists
(
grid2d_path
+
"/"
+
filename
))
?
1.
:
0.
;
return
(
File
Utils
::
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
<<
IO
Utils
::
getFilename
(
filename
);
info
<<
File
Utils
::
getFilename
(
filename
);
}
}
...
...
@@ -1120,7 +1120,7 @@ ALS_Interpolation::ALS_Interpolation(Meteo2DInterpolator& i_mi,
}
}
if
(
!
IO
Utils
::
validFileAndPath
(
grid2d_path
+
"/"
+
filename
))
{
if
(
!
File
Utils
::
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
(
IO
Utils
::
fileExists
(
grid2d_path
+
"/"
+
filename
))
?
1.
:
0.
;
return
(
File
Utils
::
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
<<
IO
Utils
::
getFilename
(
filename
)
<<
" - "
;
info
<<
File
Utils
::
getFilename
(
filename
)
<<
" - "
;
initGrid
(
dem
,
grid
);
const
size_t
nxy
=
grid
.
getNx
()
*
grid
.
getNy
();
...
...
meteoio/jnative/DEMLoader.cc
View file @
398ad906
...
...
@@ -38,7 +38,7 @@ IOInterface* DEMLoader::generateIOInterface(
IOInterface
*
io
=
NULL
;
try
{
cfg
.
addKey
(
"DEMFILE"
,
"Input"
,
IO
Utils
::
cleanPath
(
cDemFile
));
cfg
.
addKey
(
"DEMFILE"
,
"Input"
,
File
Utils
::
cleanPath
(
cDemFile
));
cfg
.
addKey
(
"COORDSYS"
,
"Input"
,
cDemCoordSystem
);
cfg
.
addKey
(
"COORDPARAM"
,
"Input"
,
""
);
...
...
meteoio/meteoFilters/FilterSuppr.cc
View file @
398ad906
...
...
@@ -72,8 +72,8 @@ void FilterSuppr::process(const unsigned int& param, const std::vector<MeteoData
void
FilterSuppr
::
fillSuppr_dates
(
const
std
::
string
&
filename
)
{
if
(
!
IO
Utils
::
validFileAndPath
(
filename
))
throw
InvalidNameException
(
filename
,
AT
);
if
(
!
IO
Utils
::
fileExists
(
filename
))
throw
NotFoundException
(
filename
,
AT
);
if
(
!
File
Utils
::
validFileAndPath
(
filename
))
throw
InvalidNameException
(
filename
,
AT
);
if
(
!
File
Utils
::
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
=
IO
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
const
char
eoln
=
File
Utils
::
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
=
(
IO
Utils
::
isAbsolutePath
(
in_filename
)
)
?
""
:
root_path
+
"/"
;
const
std
::
string
path
=
IO
Utils
::
getPath
(
prefix
+
in_filename
,
true
);
//clean & resolve path
const
std
::
string
filename
=
path
+
"/"
+
IO
Utils
::
getFilename
(
in_filename
);
const
std
::
string
prefix
=
(
File
Utils
::
isAbsolutePath
(
in_filename
)
)
?
""
:
root_path
+
"/"
;
const
std
::
string
path
=
File
Utils
::
getPath
(
prefix
+
in_filename
,
true
);
//clean & resolve path
const
std
::
string
filename
=
path
+
"/"
+
File
Utils
::
getFilename
(
in_filename
);
fillSuppr_dates
(
filename
);
}
...
...
meteoio/meteoFilters/ProcAdd.cc
View file @
398ad906
...
...
@@ -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
=
(
IO
Utils
::
isAbsolutePath
(
in_filename
)
)
?
""
:
root_path
+
"/"
;
const
std
::
string
path
=
IO
Utils
::
getPath
(
prefix
+
in_filename
,
true
);
//clean & resolve path
const
std
::
string
filename
=
path
+
"/"
+
IO
Utils
::
getFilename
(
in_filename
);
const
std
::
string
prefix
=
(
File
Utils
::
isAbsolutePath
(
in_filename
)
)
?
""
:
root_path
+
"/"
;
const
std
::
string
path
=
File
Utils
::
getPath
(
prefix
+
in_filename
,
true
);
//clean & resolve path
const
std
::
string
filename
=
path
+
"/"
+
File
Utils
::
getFilename
(
in_filename
);
ProcessingBlock
::
readCorrections
(
getName
(),
filename
,
type
,
0.
,
vecOffsets
);
}
else
throw
InvalidArgumentException
(
"Wrong number of arguments for filter "
+
getName
(),
AT
);
...
...
meteoio/meteoFilters/ProcMult.cc
View file @
398ad906
...
...
@@ -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
=
(
IO
Utils
::
isAbsolutePath
(
in_filename
)
)
?
""
:
root_path
+
"/"
;
const
std
::
string
path
=
IO
Utils
::
getPath
(
prefix
+
in_filename
,
true
);
//clean & resolve path
const
std
::
string
filename
=
path
+
"/"
+
IO
Utils
::
getFilename
(
in_filename
);
const
std
::
string
prefix
=
(
File
Utils
::
isAbsolutePath
(
in_filename
)
)
?
""
:
root_path
+
"/"
;
const
std
::
string
path
=
File
Utils
::
getPath
(
prefix
+
in_filename
,
true
);
//clean & resolve path
const
std
::
string
filename
=
path
+
"/"
+
File
Utils
::
getFilename
(
in_filename
);
ProcessingBlock
::
readCorrections
(
getName
(),
filename
,
type
,
1.
,
vecFactors
);
}
else
throw
InvalidArgumentException
(
"Wrong number of arguments for filter "
+
getName
(),
AT
);
...
...
meteoio/meteoFilters/ProcShade.cc
View file @
398ad906
...
...
@@ -159,7 +159,7 @@ void ProcShade::readMask(const std::string& filter, const std::string& filename,
throw
AccessException
(
ss
.
str
(),
AT
);
}
char
eoln
=
IO
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
char
eoln
=
File
Utils
::
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
=
(
IO
Utils
::
isAbsolutePath
(
in_filename
)
)
?
""
:
root_path
+
"/"
;
const
std
::
string
path
=
IO
Utils
::
getPath
(
prefix
+
in_filename
,
true
);
//clean & resolve path
const
std
::
string
filename
=
path
+
"/"
+
IO
Utils
::
getFilename
(
in_filename
);
const
std
::
string
prefix
=
(
File
Utils
::
isAbsolutePath
(
in_filename
)
)
?
""
:
root_path
+
"/"
;
const
std
::
string
path
=
File
Utils
::
getPath
(
prefix
+
in_filename
,
true
);
//clean & resolve path
const
std
::
string
filename
=
path
+
"/"
+
File
Utils
::
getFilename
(
in_filename
);
std
::
vector
<
std
::
pair
<
double
,
double
>
>
mask
;
readMask
(
getName
(),
filename
,
mask
);
masks
[
"*"
]
=
mask
;
//this mask is valid for ALL stations
...
...
meteoio/meteoFilters/ProcessingBlock.cc
View file @
398ad906
...
...
@@ -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
=
IO
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
const
char
eoln
=
File
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
try
{
size_t
index
,
lcount
=
0
;
...
...
meteoio/plugins/A3DIO.cc
View file @
398ad906
...
...
@@ -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
(
!
IO
Utils
::
fileExists
(
meteo1d
))
{
if
(
!
File
Utils
::
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
(
!
IO
Utils
::
fileExists
(
meteo1d
))
throw
AccessException
(
meteo1d
,
AT
);
//prevent invalid filenames
if
(
!
File
Utils
::
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
IO
Utils
::
readKeyValueHeader
(
header
,
fin
,
5
,
"="
);
//Read in 5 lines as header
File
Utils
::
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
(
!
IO
Utils
::
fileExists
(
meteo1d
))
{
if
(
!
File
Utils
::
fileExists
(
meteo1d
))
{
throw
NotFoundException
(
meteo1d
,
AT
);
}
if
(
!
IO
Utils
::
fileExists
(
meteo1d
))
throw
AccessException
(
meteo1d
,
AT
);
//prevent invalid filenames
if
(
!
File
Utils
::
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
=
IO
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
const
char
eoln
=
File
Utils
::
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
;
IO
Utils
::
skipLines
(
fin
,
6
,
eoln
);
//skip header lines
File
Utils
::
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
(
IO
Utils
::
fileExists
(
wdirFilename
))
//keeping wdir optional
if
(
File
Utils
::
fileExists
(
wdirFilename
))
//keeping wdir optional
filenames
.
push_back
(
wdirFilename
);
}
for
(
size_t
ii
=
0
;
ii
<
filenames
.
size
();
ii
++
)
{
if
(
!
IO
Utils
::
fileExists
(
filenames
[
ii
]))
{
if
(
!
File
Utils
::
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
(
!
IO
Utils
::
fileExists
(
filename
))
throw
AccessException
(
filename
,
AT
);
//prevent invalid filenames
if
(
!
File
Utils
::
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
=
IO
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
const
char
eoln
=
File
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
IO
Utils
::
skipLines
(
fin
,
4
,
eoln
);
File
Utils
::
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
(
!
IO
Utils
::
fileExists
(
filename
))
throw
AccessException
(
filename
,
AT
);
//prevent invalid filenames
if
(
!
File
Utils
::
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
=
IO
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
const
char
eoln
=
File
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
IO
Utils
::
skipLines
(
fin
,
4
,
eoln
);
//skip first 4 lines
File
Utils
::
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
(
!
IO
Utils
::
fileExists
(
filename
))
throw
AccessException
(
filename
,
AT
);
//prevent invalid filenames
if
(
!
File
Utils
::
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
=
IO
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
const
char
eoln
=
File
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
IO
Utils
::
skipLines
(
fin
,
1
,
eoln
);
File
Utils
::
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
(
!
IO
Utils
::
fileExists
(
filename
))
throw
AccessException
(
filename
,
AT
);
//prevent invalid filenames
if
(
!
File
Utils
::
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
=
IO
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
const
char
eoln
=
File
Utils
::
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
(
!
IO
Utils
::
validFileAndPath
(
filename
))
throw
InvalidNameException
(
filename
,
AT
);
if
(
!
File
Utils
::
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
(
!
IO
Utils
::
validFileAndPath
(
filename
))
throw
InvalidNameException
(
filename
,
AT
);
if
(
!
File
Utils
::
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
);
...
...
meteoio/plugins/ALPUG.cc
View file @
398ad906
...
...
@@ -134,7 +134,7 @@ void ALPUG::readMetaData()
const
string
filename
=
cfg
.
get
(
"METAFILE"
,
"Input"
);
const
string
metafile
=
inpath
+
"/"
+
filename
;
if
(
!
IO
Utils
::
fileExists
(
metafile
))
throw
AccessException
(
metafile
,
AT
);
//prevent invalid filenames
if
(
!
File
Utils
::
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
=
IO
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
const
char
eoln
=
File
Utils
::
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
=
IO
Utils
::
readDirectory
(
inpath
,
station_id
+
dflt_extension
);
list
<
string
>
dirlist
=
File
Utils
::
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
(
!
IO
Utils
::
fileExists
(
file_and_path
))
throw
AccessException
(
file_and_path
,
AT
);
//prevent invalid filenames
if
(
!
File
Utils
::
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
())
...
...
meteoio/plugins/ARCIO.cc
View file @
398ad906
...
...
@@ -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
(
!
IO
Utils
::
validFileAndPath
(
full_name
))
throw
InvalidNameException
(
full_name
,
AT
);
if
(
!
IO
Utils
::
fileExists
(
full_name
))
throw
NotFoundException
(
full_name
,
AT
);
if
(
!
File
Utils
::
validFileAndPath
(
full_name
))
throw
InvalidNameException
(
full_name
,
AT
);
if
(
!
File
Utils
::
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
=
IO
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
const
char
eoln
=
File
Utils
::
getEoln
(
fin
);
//get the end of line character for the file
//Go through file, save key value pairs
try
{
IO
Utils
::
readKeyValueHeader
(
header
,
fin
,
6
,
" "
);
File
Utils
::
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
(
!
IO
Utils
::
validFileAndPath
(
full_name
))
throw
InvalidNameException
(
full_name
,
AT
);
if
(
!
File
Utils
::
validFileAndPath
(
full_name
))
throw
InvalidNameException
(
full_name
,
AT
);
errno
=
0
;
std
::
ofstream
fout
;
fout
.
open
(
full_name
.
c_str
(),
ios
::
out
);
...
...
meteoio/plugins/ARPSIO.cc
View file @
398ad906
...
...
@@ -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
(
!
IO
Utils
::
fileExists
(
filename
))
throw
AccessException
(
filename
,
AT
);
//prevent invalid filenames
if
(
!
File
Utils
::
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
);
...
...
meteoio/plugins/BormaIO.cc
View file @
398ad906
...
...
@@ -114,7 +114,7 @@ void BormaIO::getFiles(const std::string& stationname, const Date& start_date, c
cfg
.
getValue
(
"METEOPATH"
,
"Input"
,
xmlpath
);
vecFiles
.
clear
();
IO
Utils
::
readDirectory
(
xmlpath
,
dirlist
,
"_"
+
stationname
+
dflt_extension
);
File
Utils
::
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
)