WSL/SLF GitLab Repository

Commit 7a94dc73 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

An invalid C to K conversion was fixed (it used the water triple point...

An invalid C to K conversion was fixed (it used the water triple point temperature instead of melt/freeze). A much improved smet_extract that processes one file at a time has been committed. The config object now is much more verbose when reporting an invalid key and does not write out invalid key/values (basically, key with empty values). This makes it possible for example in Snowpack to re-run a simulation using the backed up ini file (without any changes).
parent 8841f453
......@@ -239,7 +239,7 @@ void Config::parseLine(const unsigned int& linenr, std::vector<std::string> &imp
return;
//if this is a section header, read it
if(line[0] == '[') {
if (line[0] == '[') {
const size_t endpos = line.find_last_of(']');
if ((endpos == string::npos) || (endpos < 2) || (endpos != (line.length()-1))) {
ostringstream tmp;
......@@ -254,19 +254,19 @@ void Config::parseLine(const unsigned int& linenr, std::vector<std::string> &imp
//this can only be a key value pair...
string key, value;
if(IOUtils::readKeyValuePair(line, "=", key, value, true)) {
if(key=="IMPORT_BEFORE") {
if (IOUtils::readKeyValuePair(line, "=", key, value, true)) {
if (key=="IMPORT_BEFORE") {
const std::string file_and_path = clean_import_path(value);
if(!accept_import_before)
if (!accept_import_before)
throw IOException("Error in \""+sourcename+"\": IMPORT_BEFORE key MUST occur before any other key!", AT);
if(std::find(imported.begin(), imported.end(), file_and_path)!=imported.end())
if (std::find(imported.begin(), imported.end(), file_and_path)!=imported.end())
throw IOException("Can not import \"" + value + "\" again: it has already been imported!", AT);
parseFile(file_and_path);
return;
}
if(key=="IMPORT_AFTER") {
if (key=="IMPORT_AFTER") {
const std::string file_and_path = clean_import_path(value);
if(std::find(imported.begin(), imported.end(), file_and_path)!=imported.end())
if (std::find(imported.begin(), imported.end(), file_and_path)!=imported.end())
throw IOException("Can not import \"" + value + "\" again: it has already been imported!", AT);
import_after.push_back(file_and_path);
return;
......@@ -277,7 +277,15 @@ void Config::parseLine(const unsigned int& linenr, std::vector<std::string> &imp
} else {
ostringstream tmp;
tmp << linenr;
throw InvalidFormatException("Error reading key value pair in \"" + sourcename + "\" at line " + tmp.str(), AT);
const string key_msg = (key.empty())? "" : "key "+key+" ";
const string key_value_link = (key.empty() && !value.empty())? "value " : "";
const string value_msg = (value.empty())? "" : value+" " ;
const string keyvalue_msg = (key.empty() && value.empty())? "key/value " : key_msg+key_value_link+value_msg;
const string section_msg = (section.empty())? "" : "in section "+section+" ";
const string source_msg = (sourcename.empty())? "" : "from \""+sourcename+"\" at line "+tmp.str();
throw InvalidFormatException("Error reading "+keyvalue_msg+section_msg+source_msg, AT);
}
}
......@@ -375,10 +383,13 @@ void Config::write(const std::string& filename) const
}
const size_t key_start = key_full.find_first_of(":");
if(key_start!=string::npos) //start after the "::" marking the section prefix
fout << key_full.substr(key_start+2) << " = " << it->second << endl;
const string value = it->second;
if (value.empty()) continue;
if (key_start!=string::npos) //start after the "::" marking the section prefix
fout << key_full.substr(key_start+2) << " = " << value << endl;
else //every key should have a section prefix, but just in case...
fout << key_full << " = " << it->second << endl;
fout << key_full << " = " << value << endl;
}
} catch(...) {
if (fout.is_open()) //close fout if open
......
......@@ -97,6 +97,15 @@ class Config {
* @param[in] value string representing the matching value to be added
*/
void addKey(const std::string& key, const std::string& value);
/**
* @brief Add a specific key/value pair to the internal key/value map object.
* key and section are case insensitive
* @param[in] key string representing the key to be added
* @param[in] section std::string representing a section name; the key has to be part of this section
* @param[in] value string representing the matching value to be added
*/
void addKey(const std::string& key, const std::string& section, const std::string& value);
/**
* @brief Delete a specific key/value pair from the internal map object, key/section are case insensitive
......@@ -117,15 +126,6 @@ class Config {
*/
void deleteKeys(const std::string& keymatch, const std::string& section=Config::defaultSection, const bool& anywhere=false);
/**
* @brief Add a specific key/value pair to the internal key/value map object.
* key and section are case insensitive
* @param[in] key string representing the key to be added
* @param[in] section std::string representing a section name; the key has to be part of this section
* @param[in] value string representing the matching value to be added
*/
void addKey(const std::string& key, const std::string& section, const std::string& value);
/**
* @brief Returns the filename that the Config object was constructed with.
* @return The absolute filename of the key/value file.
......
......@@ -32,10 +32,10 @@
#include <meteoio/meteoLaws/Meteoconst.h>
#ifndef C_TO_K
#define C_TO_K( T ) ( T + Cst::t_water_triple_pt ) // degree Celsius to kelvin
#define C_TO_K( T ) ( T + Cst::t_water_freezing_pt ) // degree Celsius to kelvin
#endif
#ifndef K_TO_C
#define K_TO_C( T ) ( T - Cst::t_water_triple_pt ) // kelvin to degree Celsius
#define K_TO_C( T ) ( T - Cst::t_water_freezing_pt ) // kelvin to degree Celsius
#endif
namespace mio {
......
#!/bin/bash
#extract given measurements from a bunch a SMET files
#!/bin/sh
#extract a given column from a smet file
unalias ls
extension="smet"
file_list=$(ls *.${extension})
param=$1
INPUT=$1
FIELD=$2
for fichier in ${file_list}; do
printf "Processing ${fichier}\n"
output=$(basename ${fichier} .${extension})
output="${output}_${param}.dat"
awk '
/fields/ {
param="'${param}'"
parindex=-1
for(i=1; i<=NF; i++) {
if($(i)==param)
parindex = i-2
}
#printf("Index of %s is %d\n", param, parindex)
if(parindex==-1) exit
next
}
/DATA/ {
read=1
next
}
{
if(read!=1) next
printf("%s %s\n", $1, $(parindex))
#get generic info
stat_id=`head -20 ${INPUT} | grep "station_id" | tr -s '\t' ' ' | cut -d' ' -f 3-`
stat_name=`head -20 ${INPUT} | grep "station_name" | tr -s '\t' ' ' | cut -d' ' -f 3-`
lat=`head -20 ${INPUT} | grep "latitude" | tr -s '\t' ' ' | cut -d' ' -f 3-`
lon=`head -20 ${INPUT} | grep "longitude" | tr -s '\t' ' ' | cut -d' ' -f 3-`
alt=`head -20 ${INPUT} | grep "altitude" | tr -s '\t' ' ' | cut -d' ' -f 3-`
#create data sets metadata
field_nr=$(head -20 ${INPUT} | grep "fields" | awk '
/fields/ {
found=3
for(i=1; i<=NF; i++) {
if($(i)=="'${FIELD}'") found=i
}
' ${fichier} > ${output}
done
printf("%d\n", found-2)
}
')
if [ ${field_nr} -eq 1 ]; then
exit
fi
#out_name="${stat_id}_${FIELD}.dat"
out_name="${stat_id}_${alt}.dat"
printf "#${stat_id} - ${stat_name}\n#lat=${lat} - lon=${lon} - alt=${alt}\n" > ${out_name}
grep -E "^[0-9]{4}-[0-9]{2}-[0-9]{2}" ${INPUT} | tr -s ' ' | cut -d' ' -f1,${field_nr} >> ${out_name}
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