WSL/SLF GitLab Repository

Commit fd9e9cda authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Since we leave some file descriptors behind, this commit tries to close...

Since we leave some file descriptors behind, this commit tries to close potential loop holes. A possible source of arithmetic exceptions in Coords has been fixed (calculating the distance between two identical points).
parent c9dc6179
......@@ -3557,7 +3557,7 @@ if test "$COLORGCC" == "yes"
then
{ $as_echo "$as_me:${as_lineno-$LINENO}: Compiling using colorgcc" >&5
$as_echo "$as_me: Compiling using colorgcc" >&6;}
CC=colorgcc
#CC=colorgcc
#CXX=colorgcc
fi
......@@ -3947,69 +3947,7 @@ case ".$ax_cv_cflags_gcc_option__O3" in
;;
esac
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking OPTIM for gcc -ftree-vectorize" >&5
$as_echo_n "checking OPTIM for gcc -ftree-vectorize... " >&6; }
if test "${ax_cv_cflags_gcc_option__ftree_vectorize+set}" = set; then :
$as_echo_n "(cached) " >&6
else
ax_cv_cflags_gcc_option__ftree_vectorize="no, unknown"
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
ac_save_CFLAGS="$CFLAGS"
for ac_arg in "-pedantic -Werror % -ftree-vectorize" "-pedantic % -ftree-vectorize %% no, obsolete" #
do CFLAGS="$ac_save_CFLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
return 0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ax_cv_cflags_gcc_option__ftree_vectorize=`echo $ac_arg | sed -e 's,.*% *,,'` ; break
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
done
CFLAGS="$ac_save_CFLAGS"
ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_cflags_gcc_option__ftree_vectorize" >&5
$as_echo "$ax_cv_cflags_gcc_option__ftree_vectorize" >&6; }
case ".$ax_cv_cflags_gcc_option__ftree_vectorize" in
.ok|.ok,*) ;;
.|.no|.no,*) ;;
*)
if echo " $OPTIM " | grep " $ax_cv_cflags_gcc_option__ftree_vectorize " 2>&1 >/dev/null
then { { $as_echo "$as_me:${as_lineno-$LINENO}: : OPTIM does contain \$ax_cv_cflags_gcc_option__ftree_vectorize"; } >&5
(: OPTIM does contain $ax_cv_cflags_gcc_option__ftree_vectorize) 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }
else { { $as_echo "$as_me:${as_lineno-$LINENO}: : OPTIM=\"\$OPTIM \$ax_cv_cflags_gcc_option__ftree_vectorize\""; } >&5
(: OPTIM="$OPTIM $ax_cv_cflags_gcc_option__ftree_vectorize") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }
OPTIM="$OPTIM $ax_cv_cflags_gcc_option__ftree_vectorize"
fi
;;
esac
#AX_CFLAGS_GCC_OPTION(-ftree-vectorize, OPTIM)
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking MAKE_OPTIM for gcc -combine" >&5
......
......@@ -174,8 +174,8 @@ void A3DIO::readStationData(const Date& timestamp, std::vector<StationData>& vec
}
void A3DIO::readMeteoData(const Date& dateStart, const Date& dateEnd,
std::vector< std::vector<MeteoData> >& vecMeteo,
const unsigned int& /*stationindex*/)
std::vector< std::vector<MeteoData> >& vecMeteo,
const unsigned int& /*stationindex*/)
{
//if dateStart and dateEnd are the same: return exact match for date
//if dateStart > dateEnd: return first data set with date > dateStart
......@@ -217,7 +217,7 @@ void A3DIO::read1DStation(std::string& file_1d, StationData& sd)
double latitude=IOUtils::nodata, longitude=IOUtils::nodata,
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
//read and parse the header
try {
//Read in station meta data
......@@ -260,7 +260,7 @@ void A3DIO::read1DMeteo(const Date& dateStart, const Date& dateEnd, std::vector<
{
std::string file_1d="", line="";
Date tmp_date;
MeteoData tmpdata;
StationData sd;
bool eofreached = false;
......@@ -369,7 +369,7 @@ void A3DIO::read2DStations(const Date& timestamp, std::vector<StationData>& vecS
unsigned int stations=0;
std::vector<std::string> filenames = std::vector<std::string>();
std::map<std::string, unsigned int> hashStations = std::map<std::string, unsigned int>();
constructMeteo2DFilenames(timestamp, timestamp, filenames);
stations = getNrOfStations(filenames, hashStations);
vecStation.resize(stations); //we receive an empty vector, so we need to allocate the room it needs
......@@ -577,6 +577,7 @@ void A3DIO::read2DMeteoData(const std::string& filename, const std::string& para
getline(fin, line_in, eoln); //line containing UNIQUE station names
columns = IOUtils::readLineToVec(line_in, vec_names);
if (columns < 4) {
cleanup();
throw InvalidFormatException("[E] Premature end of line in file " + filename, AT);
}
......@@ -592,6 +593,7 @@ void A3DIO::read2DMeteoData(const std::string& filename, const std::string& para
}
if (IOUtils::readLineToVec(line_in, tmpvec)!=columns) { //Every station has to have its own column
cleanup();
throw InvalidFormatException("[E] Premature End of Line or no data for date "
+ vecM[0][bufferindex].date.toString(Date::FULL) + " found in File "
+ filename, AT);
......@@ -599,6 +601,7 @@ void A3DIO::read2DMeteoData(const std::string& filename, const std::string& para
for (unsigned int ii=0; ii<4; ii++) {
if (!IOUtils::convertString(tmp_ymdh[ii], tmpvec[ii], std::dec)) {
cleanup();
throw InvalidFormatException("[E] Check date columns in " + filename, AT);
}
}
......@@ -614,24 +617,30 @@ void A3DIO::read2DMeteoData(const std::string& filename, const std::string& para
if (parameter == "nswc") {
if (!IOUtils::convertString(tmpmd.hnw, tmpvec[ii], std::dec)) {
cleanup();
throw ConversionFailedException("For hnw value in " + filename + " for date " + tmpmd.date.toString(Date::FULL), AT);
}
} else if (parameter == "rh") {
if (!IOUtils::convertString(tmpmd.rh, tmpvec[ii], std::dec)) {
cleanup();
throw ConversionFailedException("For rh value in " + filename + " for date " + tmpmd.date.toString(Date::FULL), AT);
}
} else if (parameter == "ta") {
if (!IOUtils::convertString(tmpmd.ta, tmpvec[ii], std::dec))
if (!IOUtils::convertString(tmpmd.ta, tmpvec[ii], std::dec)) {
cleanup();
throw ConversionFailedException("For ta value in " + filename + " for date " + tmpmd.date.toString(Date::FULL), AT);
}
} else if (parameter == "vw") {
if (!IOUtils::convertString(tmpmd.vw, tmpvec[ii], std::dec)) {
cleanup();
throw ConversionFailedException("For vw value in " + filename + " for date " + tmpmd.date.toString(Date::FULL), AT);
}
} else if (parameter == "dw") {
if (!IOUtils::convertString(tmpmd.dw, tmpvec[ii], std::dec)) {
cleanup();
throw ConversionFailedException("For dw value in " + filename + " for date " + tmpmd.date.toString(Date::FULL), AT);
}
}
......@@ -667,16 +676,19 @@ void A3DIO::read2DMeteoHeader(const std::string& filename, std::map<std::string,
getline(fin, line_in, eoln); //xcoord
if (IOUtils::readLineToVec(line_in, vec_xcoord) != columns) {
cleanup();
throw InvalidFormatException("Column count doesn't match from line to line in " + filename, AT);
}
getline(fin, line_in, eoln); //ycoord
if (IOUtils::readLineToVec(line_in, vec_ycoord) != columns) {
cleanup();
throw InvalidFormatException("Column count doesn't match from line to line in " + filename, AT);
}
getline(fin, line_in, eoln); //names
if (IOUtils::readLineToVec(line_in, vec_names) != columns) {
cleanup();
throw InvalidFormatException("Column count doesn't match from line to line in " + filename, AT);
}
......@@ -684,12 +696,14 @@ void A3DIO::read2DMeteoHeader(const std::string& filename, std::map<std::string,
//Check for duplicate station names within one file ... station names need to be unique!
vector<string> vec_dup = vec_names;
for (unsigned int ii=0; ii<vec_names.size(); ii++){
for (unsigned int ii=0; ii<vec_names.size(); ii++) {
const string& tmp = vec_names[ii];
for (unsigned int jj=0; jj<vec_dup.size(); jj++){
if (jj != ii){
if (vec_dup[jj] == tmp)
for (unsigned int jj=0; jj<vec_dup.size(); jj++) {
if (jj != ii) {
if (vec_dup[jj] == tmp) {
cleanup();
throw IOException("Duplicate station names detected in " + filename, AT);
}
}
}
}
......@@ -705,6 +719,7 @@ void A3DIO::read2DMeteoHeader(const std::string& filename, std::map<std::string,
|| (!IOUtils::convertString(easting, vec_xcoord.at(ii), std::dec))
|| (!IOUtils::convertString(northing, vec_ycoord.at(ii), std::dec))
|| (!IOUtils::convertString(stationName, vec_names.at(ii), std::dec))) {
cleanup();
throw ConversionFailedException("Conversion of station description failed in " + filename, AT);
}
coordinate.setXY(easting, northing, altitude);
......@@ -737,10 +752,12 @@ void A3DIO::readSpecialPoints(std::vector<Coords>& pts)
if (IOUtils::readLineToVec(line_in, tmpvec)==2) { //Try to convert
int x, y;
if (!IOUtils::convertString(x, tmpvec.at(0), std::dec)) {
cleanup();
throw ConversionFailedException("Conversion of a value failed in " + filename + " line: " + line_in, AT);
}
if (!IOUtils::convertString(y, tmpvec.at(1), std::dec)) {
cleanup();
throw ConversionFailedException("Conversion of a value failed in " + filename + " line: " + line_in, AT);
}
......@@ -828,7 +845,7 @@ int A3DIO::writeHeader(std::ofstream &file, const std::vector< std::vector<Meteo
std::ostringstream str_northings;
const unsigned int sta_nr = data.size();
if(sta_nr==0) return EXIT_FAILURE;
file << "X:\\filepath " << parameter_name <<endl;
for(unsigned int ii=0; ii<sta_nr; ii++) {
if(data[ii].size() > 0) {
......@@ -852,7 +869,7 @@ int A3DIO::writeHeader(std::ofstream &file, const std::vector< std::vector<Meteo
}
void A3DIO::open2DFile(const std::vector< std::vector<MeteoData> >& data,
const std::string& fileprefix, const std::string& label, const double& year,
const std::string& fileprefix, const std::string& label, const double& year,
std::ofstream& file)
{//creates a meteo2D file according to the specifications
//the header is also written
......
......@@ -442,7 +442,7 @@ void Coords::setGridIndex(const int in_grid_i, const int in_grid_j, const int in
}
/**
* @brief Set altitude at a given value.
* @brief Set altitude at a given value.
* If the i,j,k indices were set, reset them to inodata,
* except if specified otherwise with in_update=false.
* @param[in] in_altitude altitude above sea level, in meters
......@@ -1294,10 +1294,17 @@ void Coords::cosineInverse(const double& lat_ref, const double& lon_ref, const d
const double lat_ref_rad = lat_ref*to_rad;
const double bearing_rad = bearing*to_rad;
if(IOUtils::checkEpsilonEquality(distance, 0., .01)) {
//distance is too small, it could create numerical problems
lat = lat_ref;
lon = lon_ref;
return;
}
lat = asin( sin(lat_ref_rad)*cos(distance/Rearth) +
cos(lat_ref_rad)*sin(distance/Rearth)*cos(bearing_rad) );
cos(lat_ref_rad)*sin(distance/Rearth)*cos(bearing_rad) );
lon = lon_ref*to_rad + atan2( sin(bearing_rad)*sin(distance/Rearth)*cos(lat_ref_rad) ,
cos(distance/Rearth) - sin(lat_ref_rad)*sin(lat) );
cos(distance/Rearth) - sin(lat_ref_rad)*sin(lat) );
lon = fmod(lon+M_PI, 2.*M_PI) - M_PI;
lat *= to_deg;
......@@ -1316,6 +1323,12 @@ void Coords::cosineInverse(const double& lat_ref, const double& lon_ref, const d
*/
double Coords::cosineDistance(const double& lat1, const double& lon1, const double& lat2, const double& lon2, double& alpha) const
{
if(lat1==lat2 && lon1==lon2) {
//distance is zero, it creates numerical problems -> skip calculation
alpha = 0.;
return 0.;
}
const double Rearth = 6371.e3;
const double to_rad = M_PI / 180.0;
const double d = acos(
......
......@@ -127,7 +127,7 @@ void IOUtils::toUpper(std::string& str){
}
bool IOUtils::readKeyValuePair(const std::string& in_line, const std::string& delimiter,
std::map<std::string,std::string>& out_map, const std::string& keyprefix, const bool& setToUpperCase)
std::map<std::string,std::string>& out_map, const std::string& keyprefix, const bool& setToUpperCase)
{
//size_t pos = in_line.find(delimiter); //first occurence of '='
......
......@@ -98,7 +98,7 @@ The format is the following:
0.000000000000 (rotation term for column)
-5.000000000000 (size of pixel in y direction)
492169.690845528910 (x coordinate of centre of upper left pixel in map units)
5426523.318065105000 (y coordinate of centre of upper left pixel in map units)
5426523.318065105000 (y coordinate of centre of upper left pixel in map units)
*/
ARCIO::ARCIO(void (*delObj)(void*), const Config& i_cfg) : IOInterface(delObj), cfg(i_cfg)
......@@ -279,14 +279,13 @@ void ARCIO::write2DGrid(const Grid2DObject& grid_in, const std::string& name)
throw FileAccessException(name, AT);
}
Coords llcorner=grid_in.llcorner;
//we want to make sure that we are using the provided projection parameters
//so that we output is done in the same system as the inputs
llcorner.setProj(coordout, coordoutparam);
fout << fixed << showpoint << setprecision(6);
try {
Coords llcorner=grid_in.llcorner;
//we want to make sure that we are using the provided projection parameters
//so that we output is done in the same system as the inputs
llcorner.setProj(coordout, coordoutparam);
fout << fixed << showpoint << setprecision(6);
fout << "ncols " << setw(23-6) << grid_in.ncols << endl;
fout << "nrows " << setw(23-6) << grid_in.nrows << endl;
fout << "xllcorner " << setw(23-10) << setprecision(3) << llcorner.getEasting() << endl;
......
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