Commit cf8c9e46 authored by Norby, Tom's avatar Norby, Tom

Add connormal executable to normalize concentration to a post event time.

parent 8bdcf826
Pipeline #111561 canceled with stages
in 5 minutes and 40 seconds
......@@ -4,13 +4,22 @@ TRIBITS_SUBPACKAGE(exe)
#SET(PROGRAM_VERSION "${haem_FULL_VERSION}")
SET(SOURCE
concnormal.cc
conprob.cc
fmsscoreex.cc
radixsnd2arl.cc
)
#SET(HEADERS
#)
TRIBITS_ADD_EXECUTABLE(concnormal
NOEXEPREFIX
NOEXESUFFIX
SOURCES concnormal.cc
INSTALLABLE
)
TRIBITS_ADD_EXECUTABLE(haemsnd2arl
NOEXEPREFIX
NOEXESUFFIX
......
TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
LIB_REQUIRED_PACKAGES haemmodel
LIB_REQUIRED_PACKAGES haemmodel radixcommand radixmath
)
/*
* Utility to normalize dose rate in cdump file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "haemmodel/cnormal.hh"
int main(int argc, char **argv)
{
if (argc != 4)
{
std::cerr << "Usage: " << argv[0]
<< " <cdump_input> <cdump_output> <normalize_time>" << std::endl;
return 1;
}
const char *fi[2] = {argv[1], argv[2]};
double time = atof(argv[3]);
bool success = haem::cnormal(fi[0], fi[1], float(time));
if (!success)
{
std::cerr << "ERROR occured in cnormal()" << std::endl;
return 1;
}
std::cout << "cdump normalized" << std::endl;
return 0;
}
......@@ -10,7 +10,7 @@
#include <string>
#include <vector>
#include "radixio/fmsscore.hh"
#include "haemmodel/fmsscore.hh"
using namespace radix;
......@@ -49,8 +49,8 @@ int main(int argc, char **argv)
}
}
float score =
fmsscore(cd, polIndex0, polIndex1, levelIndex, timeIndex, scaleFactor);
float score = haem::fmsscore(cd, polIndex0, polIndex1, levelIndex, timeIndex,
scaleFactor);
if (score < 0.f)
{
std::cerr << "ERROR occured in fmsscore()" << std::endl;
......
......@@ -321,7 +321,7 @@ void write_conc_file(int fp_idx, const char *PTYPE, int LEVEL, float *data,
}
// ----------------------------------------------------------------------------
main(int argc, char **argv)
int main(int argc, char **argv)
{
// ------------------------------------------------------------------------
// command line argument list
......
......@@ -12,6 +12,7 @@ ascdata.hh
concentrationcontrol.hh
concentrationworkflow.hh
control.hh
cnormal.hh
emission.hh
fmsscore.hh
meteorology.hh
......@@ -33,6 +34,7 @@ ascdata.cc
concentrationcontrol.cc
concentrationworkflow.cc
control.cc
cnormal.cc
emission.cc
fmsscore.cc
meteorology.cc
......
#include "radixio/hysplitcdump.hh"
#include "haemmodel/cnormal.hh"
static double hourDiff(struct tm *laterTime, struct tm *earlierTime)
{
time_t later = mktime(laterTime);
time_t earlier = mktime(earlierTime);
return (later - earlier) / 60 / 60;
}
bool haem::cnormal(const char *inputfile, const char *outputfile,
float normalTime)
{
radix::HysplitCDump::SP cdump;
cdump = std::make_shared<radix::HysplitCDump>();
radix::HysplitCDumpStream<radix::HysplitCDump::SP> stream(cdump);
if (!stream.read_from(inputfile))
{
std::cerr << "ERROR: Could not open file: " << inputfile << std::endl;
return false;
}
if (normalTime <= 0.f)
{
std::cerr << "ERROR: time to normalize to should be positive" << std::endl;
return false;
}
struct tm st = {};
int forecast;
cdump->startTime(0, st.tm_year, st.tm_mon, st.tm_mday, st.tm_hour, st.tm_min,
forecast);
#ifdef _WIN32
// Windows doesn't like anything less than 1970
const int INTGT70 = 400;
st.tm_year += INTGT70;
#endif // _WIN32
for (size_t ti = 0; ti < cdump->numEndTimes(); ++ti)
{
float postEvent;
{
struct tm et = {};
cdump->endTime(ti, et.tm_year, et.tm_mon, et.tm_mday, et.tm_hour,
et.tm_min, forecast);
#ifdef _WIN32
et.tm_year += INTGT70;
#endif // _WIN32
postEvent = hourDiff(&et, &st);
std::cout << "H+" << postEvent << std::endl;
}
for (size_t pi = 0; pi < cdump->numPollutants(); ++pi)
{
for (size_t li = 0; li < cdump->numLevels(); ++li)
{
size_t nnzp = size_t(cdump->numNonZeroPoints(ti, pi, li));
for (size_t nzi = 0; nzi < nnzp; nzi++)
{
float conc;
short xi, yi;
cdump->point(ti, pi, li, nzi, xi, yi, conc);
conc *= std::pow(postEvent, 1.2f) / std::pow(normalTime, 1.2f);
cdump->setPoint(ti, pi, li, nzi, xi, yi, conc);
} // for each non zero point
} // for each altitude
} // for each pollutant
} // for each time
if (!stream.write_to(outputfile))
{
std::cerr << "ERROR: Could not write file: " << outputfile << std::endl;
return false;
}
return true;
}
#ifndef HAEM_HAEMMODEL_CNORMAL_HH
#define HAEM_HAEMMODEL_CNORMAL_HH
#include "radixcore/visibility.hh"
namespace haem
{
RADIX_PUBLIC bool cnormal(const char *inputfile, const char *outputfile,
float normalTime);
};
#endif // HAEM_HAEMMODEL_CNORMAL_HH
......@@ -11,7 +11,7 @@ namespace haem
// levelIndex = time index into cdump files
// scale = scale factor by which to multiply concentrations from calculated
// cdump file (fi[1])
float fmsscore(HysplitCDump::SP *cd, int polIndex0, int polIndex1,
float fmsscore(radix::HysplitCDump::SP *cd, int polIndex0, int polIndex1,
int timeIndex, int levelIndex, float scale)
{
// int numLocs = cd[0]->numLocations();
......
......@@ -6,8 +6,9 @@
namespace haem
{
RADIX_PUBLIC float fmsscore(HysplitCDump::SP *cd, int polIndex0, int polIndex1,
int timeIndex, int levelIndex, float scale);
RADIX_PUBLIC float fmsscore(radix::HysplitCDump::SP *cd, int polIndex0,
int polIndex1, int timeIndex, int levelIndex,
float scale);
}
#endif /** HAEM_HAEMMODEL_FMSSCORE_HH_ */
Markdown is supported
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