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

Use radix commandline for arguments. Add location as option for start time source.

parent ea157239
Pipeline #112383 failed with stages
in 5 minutes and 54 seconds
......@@ -6,20 +6,55 @@
#include <stdlib.h>
#include <iostream>
#include "radixcommand/commandline.hh"
#include "haemmodel/concutil.hh"
int main(int argc, char **argv)
{
if (argc != 4)
std::cout << "************************" << std::endl;
std::cout << "****** concnormal ******" << std::endl;
std::cout << "************************" << std::endl;
// Set up command line options
CommandLine commandLine(argc, argv);
commandLine.addOption("i", "Input cdump file containing exposure rate.",
true);
commandLine.addOption("o", "Output cdump file. (normalDump)", false);
commandLine.addOption("h", "Post event hour to normalize to. (12)", false);
commandLine.addOption("s",
"Source start time from:"
"\n\t\t(0) first start time."
"\n\t\t 1 first location time.",
false);
// Ensure required options present
std::vector<std::string> commandErrors;
if (!commandLine.validate(commandErrors))
{
std::cerr << "Usage: " << argv[0]
<< " <cdump_input> <cdump_output> <normalize_time>" << std::endl;
return 1;
std::cout << "Error in arguments..." << std::endl;
for (std::string error : commandErrors)
{
std::cout << "\t" << error << std::endl;
}
std::cout << std::endl;
commandLine.printParsedLine(std::cout);
return -1;
}
const char *inputFile = argv[1];
const char *outputFile = argv[2];
double time = atof(argv[3]);
// Get command line options
std::string inputFile = commandLine.get<std::string>("i");
std::string outputFile = commandLine.get<std::string>("o", "normalDump");
float time = commandLine.get<float>("h", 12.f);
haem::StartSource startSource =
haem::StartSource(commandLine.get<int>("s", 0));
if (time <= 0.f)
{
std::cerr << "ERROR: time to normalize to should be positive" << std::endl;
return 1;
}
// read input cdump
HysplitCDump::SP cdump = std::make_shared<HysplitCDump>();
......@@ -29,15 +64,9 @@ int main(int argc, char **argv)
std::cerr << "ERROR: Could not open file: " << inputFile << std::endl;
return 1;
}
if (time <= 0.f)
{
std::cerr << "ERROR: time to normalize to should be positive" << std::endl;
return 1;
}
std::cout << "hi";
// normalize cdump
haem::cnormal(cdump, float(time));
haem::cnormal(cdump, time, startSource);
// write cdump to output
if (!stream.write_to(outputFile))
......
......@@ -7,34 +7,57 @@
#include <stdlib.h>
#include <iostream>
#include "radixcommand/commandline.hh"
#include "haemmodel/concutil.hh"
int main(int argc, char **argv)
{
if (argc != 4)
std::cout << "************************" << std::endl;
std::cout << "** concspeciesselect ***" << std::endl;
std::cout << "************************" << std::endl;
// Set up command line options
CommandLine commandLine(argc, argv);
commandLine.addOption(
"i", "Input cdump file containing multiple species / pollutants.", true);
commandLine.addOption("o", "Output cdump file. (speciesDump)", false);
commandLine.addOption("s", "Species index to isolate. (0)", false);
// Ensure required options present
std::vector<std::string> commandErrors;
if (!commandLine.validate(commandErrors))
{
std::cerr << "Usage: " << argv[0]
<< " <cdump_input> <cdump_output> <species_to_copy>" << std::endl;
return 1;
std::cout << "Error in arguments..." << std::endl;
for (std::string error : commandErrors)
{
std::cout << "\t" << error << std::endl;
}
std::cout << std::endl;
commandLine.printParsedLine(std::cout);
return -1;
}
const char *inputfile = argv[1];
const char *outputfile = argv[2];
int species = atoi(argv[3]);
// Get command line options
std::string inputFile = commandLine.get<std::string>("i");
std::string outputFile = commandLine.get<std::string>("o", "speciesDump");
int species = commandLine.get<int>("s", 0);
HysplitCDump::SP cdumpin, cdumpout;
// read in source dump
cdumpin = std::make_shared<HysplitCDump>();
HysplitCDumpStream<HysplitCDump::SP> streamin(cdumpin);
if (!streamin.read_from(inputfile))
if (species < 0)
{
std::cerr << "ERROR: Could not open file: " << inputfile << std::endl;
std::cerr << "ERROR: selected species should be non-negative" << std::endl;
return 1;
}
if (species < 0)
// read in source dump
cdumpin = std::make_shared<HysplitCDump>();
HysplitCDumpStream<HysplitCDump::SP> streamin(cdumpin);
if (!streamin.read_from(inputFile))
{
std::cerr << "ERROR: selected species should be non-negative" << std::endl;
std::cerr << "ERROR: Could not open file: " << inputFile << std::endl;
return 1;
}
......@@ -43,9 +66,9 @@ int main(int argc, char **argv)
// write output dump
HysplitCDumpStream<HysplitCDump::SP> streamout(cdumpout);
if (!streamout.write_to(outputfile))
if (!streamout.write_to(outputFile))
{
std::cerr << "ERROR: Could not write file: " << outputfile << std::endl;
std::cerr << "ERROR: Could not write file: " << outputFile << std::endl;
return 1;
}
......
......@@ -7,12 +7,21 @@ static time_t hourDiff(struct tm *laterTime, struct tm *earlierTime)
return (later - earlier) / 60 / 60;
}
void haem::cnormal(HysplitCDump::SP cdump, float normalTime)
void haem::cnormal(HysplitCDump::SP cdump, float normalTime,
StartSource startSource)
{
struct tm st = {};
int forecast;
cdump->startTime(0, st.tm_year, st.tm_mon, st.tm_mday, st.tm_hour, st.tm_min,
forecast);
{
float lat, lon, z;
if (startSource == StartSource::START_TIME)
cdump->startTime(0, st.tm_year, st.tm_mon, st.tm_mday, st.tm_hour,
st.tm_min, forecast);
else
cdump->location(0, st.tm_year, st.tm_mon, st.tm_mday, st.tm_hour, lat,
lon, z, st.tm_min);
}
#ifdef _WIN32
// Windows doesn't like anything less than 1970
......
......@@ -7,7 +7,14 @@
using namespace radix;
namespace haem
{
RADIX_PUBLIC void cnormal(HysplitCDump::SP cdump, float normalTime);
enum StartSource
{
START_TIME,
LOCATION_TIME
};
RADIX_PUBLIC void cnormal(HysplitCDump::SP cdump, float normalTime,
StartSource startSource);
RADIX_PUBLIC HysplitCDump::SP speciesSelect(HysplitCDump::SP cdumpin,
int species);
......
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