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

Add concspeciesselect executable to isolate a single species into its own cdump.

parent cf8c9e46
Pipeline #111582 failed with stages
in 5 minutes and 56 seconds
......@@ -5,6 +5,7 @@ TRIBITS_SUBPACKAGE(exe)
SET(SOURCE
concnormal.cc
concspeciesselect.cc
conprob.cc
fmsscoreex.cc
radixsnd2arl.cc
......@@ -20,6 +21,13 @@ TRIBITS_ADD_EXECUTABLE(concnormal
INSTALLABLE
)
TRIBITS_ADD_EXECUTABLE(concspeciesselect
NOEXEPREFIX
NOEXESUFFIX
SOURCES concspeciesselect.cc
INSTALLABLE
)
TRIBITS_ADD_EXECUTABLE(haemsnd2arl
NOEXEPREFIX
NOEXESUFFIX
......
......@@ -6,7 +6,7 @@
#include <stdlib.h>
#include <iostream>
#include "haemmodel/cnormal.hh"
#include "haemmodel/concutil.hh"
int main(int argc, char **argv)
{
......
/*
* Utility to copy a single pollutant/species from one cdump file into an
* output.
*/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "haemmodel/concutil.hh"
int main(int argc, char **argv)
{
if (argc != 4)
{
std::cerr << "Usage: " << argv[0]
<< " <cdump_input> <cdump_output> <species_to_copy>" << std::endl;
return 1;
}
const char *fi[2] = {argv[1], argv[2]};
int species = atoi(argv[3]);
bool success = haem::speciesSelect(fi[0], fi[1], species);
if (!success)
{
std::cerr << "ERROR occured in speciesSelect()" << std::endl;
return 1;
}
std::cout << "Species written to output" << std::endl;
return 0;
}
......@@ -12,7 +12,7 @@ ascdata.hh
concentrationcontrol.hh
concentrationworkflow.hh
control.hh
cnormal.hh
concutil.hh
emission.hh
fmsscore.hh
meteorology.hh
......@@ -34,7 +34,7 @@ ascdata.cc
concentrationcontrol.cc
concentrationworkflow.cc
control.cc
cnormal.cc
concutil.cc
emission.cc
fmsscore.cc
meteorology.cc
......
#include "radixio/hysplitcdump.hh"
#include "haemmodel/cnormal.hh"
#include "haemmodel/concutil.hh"
static double hourDiff(struct tm *laterTime, struct tm *earlierTime)
static time_t hourDiff(struct tm *laterTime, struct tm *earlierTime)
{
time_t later = mktime(laterTime);
time_t earlier = mktime(earlierTime);
......@@ -40,7 +40,7 @@ bool haem::cnormal(const char *inputfile, const char *outputfile,
st.tm_year += INTGT70;
#endif // _WIN32
for (size_t ti = 0; ti < cdump->numEndTimes(); ++ti)
for (int ti = 0; ti < cdump->numEndTimes(); ++ti)
{
float postEvent;
{
......@@ -51,16 +51,16 @@ bool haem::cnormal(const char *inputfile, const char *outputfile,
et.tm_year += INTGT70;
#endif // _WIN32
postEvent = hourDiff(&et, &st);
postEvent = float(hourDiff(&et, &st));
std::cout << "H+" << postEvent << std::endl;
}
for (size_t pi = 0; pi < cdump->numPollutants(); ++pi)
for (int pi = 0; pi < cdump->numPollutants(); ++pi)
{
for (size_t li = 0; li < cdump->numLevels(); ++li)
for (int li = 0; li < cdump->numLevels(); ++li)
{
size_t nnzp = size_t(cdump->numNonZeroPoints(ti, pi, li));
for (size_t nzi = 0; nzi < nnzp; nzi++)
int nnzp = cdump->numNonZeroPoints(ti, pi, li);
for (int nzi = 0; nzi < nnzp; nzi++)
{
float conc;
short xi, yi;
......@@ -80,3 +80,80 @@ bool haem::cnormal(const char *inputfile, const char *outputfile,
return true;
}
bool haem::speciesSelect(const char *inputfile, const char *outputfile,
int speciesSelect)
{
radix::HysplitCDump::SP cdumpin, cdumpout;
cdumpin = std::make_shared<radix::HysplitCDump>();
radix::HysplitCDumpStream<radix::HysplitCDump::SP> streamin(cdumpin);
if (!streamin.read_from(inputfile))
{
std::cerr << "ERROR: Could not open file: " << inputfile << std::endl;
return false;
}
if (speciesSelect < 0)
{
std::cerr << "ERROR: selected species should be non-negative" << std::endl;
return false;
}
cdumpout = std::make_shared<radix::HysplitCDump>();
{
cdumpout->setId(cdumpin->id());
cdumpout->setNumLat(cdumpin->numLat());
cdumpout->setNumLon(cdumpin->numLon());
cdumpout->setDeltaLat(cdumpin->deltaLat());
cdumpout->setDeltaLon(cdumpin->deltaLon());
cdumpout->setCornerLat(cdumpin->cornerLat());
cdumpout->setCornerLon(cdumpin->cornerLon());
cdumpout->setForecastHour(cdumpin->forecastHour());
for (int loc = 0; loc < cdumpin->numLocations(); ++loc)
{
int y, mo, d, h, min;
float lat, lon, z;
cdumpin->location(loc, y, mo, d, h, lat, lon, z, min);
cdumpout->addLocation(y, mo, d, h, lat, lon, z, min);
}
for (int ti = 0; ti < cdumpin->numEndTimes(); ++ti)
{
int y, mo, d, h, min, forecast;
cdumpin->startTime(ti, y, mo, d, h, min, forecast);
cdumpout->addStartTime(y, mo, d, h, min, forecast);
cdumpin->endTime(ti, y, mo, d, h, min, forecast);
cdumpout->addEndTime(y, mo, d, h, min, forecast);
}
for (int li = 0; li < cdumpin->numLevels(); ++li)
{
cdumpout->addLevel(cdumpin->level(li));
}
cdumpout->addPollutant(cdumpin->pollutant(speciesSelect));
} // prepare cdumpout - especially for setNumNonZeroPoints()
for (int ti = 0; ti < cdumpin->numEndTimes(); ++ti)
{
for (int li = 0; li < cdumpin->numLevels(); ++li)
{
int nnzp = cdumpin->numNonZeroPoints(ti, speciesSelect, li);
cdumpout->setNumNonZeroPoints(ti, 0, li, nnzp);
for (int nzi = 0; nzi < nnzp; nzi++)
{
float conc;
short xi, yi;
cdumpin->point(ti, speciesSelect, li, nzi, xi, yi, conc);
cdumpout->setPoint(ti, 0, li, nzi, xi, yi, conc);
} // for each non zero point
} // for each altitude
} // for each time
radix::HysplitCDumpStream<radix::HysplitCDump::SP> streamout(cdumpout);
if (!streamout.write_to(outputfile))
{
std::cerr << "ERROR: Could not write file: " << outputfile << std::endl;
return false;
}
return true;
}
......@@ -7,6 +7,9 @@ namespace haem
{
RADIX_PUBLIC bool cnormal(const char *inputfile, const char *outputfile,
float normalTime);
};
RADIX_PUBLIC bool speciesSelect(const char *inputfile, const char *outputfile,
int speciesSelect);
}; // namespace haem
#endif // HAEM_HAEMMODEL_CNORMAL_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