Skip to content

Commit

Permalink
Merge branch 'crms' of https://github.com/zcobell/MetOceanViewer into…
Browse files Browse the repository at this point in the history
… crms
  • Loading branch information
zcobell committed Jul 7, 2019
2 parents 6fd7565 + e5c5387 commit 66f1e74
Show file tree
Hide file tree
Showing 22 changed files with 533 additions and 248 deletions.
2 changes: 2 additions & 0 deletions MetOceanData/MetOceanData.pro
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ CONFIG += c++11 console
CONFIG -= app_bundle
TARGET = MetOceanData

INCLUDEPATH += $$PWD/../thirdparty/boost_1_67_0

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
Expand Down
11 changes: 8 additions & 3 deletions MetOceanData/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ int main(int argc, char *argv[]) {

option->processOptions();
Options::CommandLineOptions opt = option->getCommandLineOptions();
MetOceanData *d =
new MetOceanData(opt.service, opt.station, opt.product, opt.datum,
opt.startDate, opt.endDate, opt.outputFile, &a);
MetOceanData *d;
if (opt.doCrms) {
d = new MetOceanData(opt.crms, opt.outputFile, &a);
} else {
d = new MetOceanData(opt.service, opt.station, opt.product, opt.datum,
opt.startDate, opt.endDate, opt.outputFile, &a);
}
d->setLoggingActive();
QObject::connect(d, SIGNAL(finished()), &a, SLOT(quit()));
QTimer::singleShot(0, d, SLOT(run()));

return a.exec();
}
85 changes: 60 additions & 25 deletions MetOceanData/metoceandata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <algorithm>
#include <iostream>
#include "constants.h"
#include "crmsdatabase.h"
#include "generic.h"
#include "hmdf.h"
#include "ndbcdata.h"
Expand All @@ -34,16 +35,17 @@ static const QHash<int, QString> noaaProducts = {
{4, "air_temperature"}, {5, "water_temperature"}, {6, "wind:speed"},
{7, "humidity"}, {8, "air_pressure"}, {9, "wind:direction"},
{10, "wind:gusts"}};
static const QHash<int, QString> noaaProductLongName = {{1, "6 minute water level"},
{2, "Hourly water level"},
{3, "Tide predictoins"},
{4, "Air temperature"},
{5, "Water temperature"},
{6, "Wind speed"},
{7, "Humidity"},
{8, "Air pressure"},
{9, "Wind direction"},
{10, "Wind gusts"}};
static const QHash<int, QString> noaaProductLongName = {
{1, "6 minute water level"},
{2, "Hourly water level"},
{3, "Tide predictoins"},
{4, "Air temperature"},
{5, "Water temperature"},
{6, "Wind speed"},
{7, "Humidity"},
{8, "Air pressure"},
{9, "Wind direction"},
{10, "Wind gusts"}};
static const QHash<int, QString> noaaUnits = {
{1, "m"}, {2, "m"}, {3, "m"}, {4, "C"}, {5, "C"},
{6, "m/s"}, {7, "%"}, {8, "mb"}, {9, "deg"}, {10, "m/s"}};
Expand All @@ -59,6 +61,8 @@ MetOceanData::MetOceanData(QObject *parent) : QObject(parent) {
this->m_startDate = QDateTime();
this->m_endDate = QDateTime();
this->m_outputFile = QString();
this->m_doCrms = false;
this->m_crmsFile = QString();
}

MetOceanData::MetOceanData(serviceTypes service, QStringList station,
Expand All @@ -73,6 +77,22 @@ MetOceanData::MetOceanData(serviceTypes service, QStringList station,
this->m_startDate = startDate;
this->m_endDate = endDate;
this->m_outputFile = outputFile;
this->m_doCrms = false;
this->m_crmsFile = QString();
}

MetOceanData::MetOceanData(QString crmsFile, QString outputFile,
QObject *parent)
: QObject(parent) {
this->m_service = 0;
this->m_product = 0;
this->m_datum = 0;
this->m_station = QStringList();
this->m_startDate = QDateTime();
this->m_endDate = QDateTime();
this->m_outputFile = outputFile;
this->m_doCrms = true;
this->m_crmsFile = crmsFile;
}

int MetOceanData::service() const { return m_service; }
Expand Down Expand Up @@ -137,23 +157,27 @@ void MetOceanData::showStatus(QString message, int pct) {
}

void MetOceanData::run() {
if (this->service() == USGS && this->m_station.length() > 1) {
emit error(
"Beacuase each station has different characteristics, only one "
"USGS station may be selected at a time.");
emit finished();
if (this->m_doCrms) {
this->processCrmsData();
return;
}

if (this->service() == NOAA)
this->getNoaaData();
else if (this->service() == USGS)
this->getUsgsData();
else if (this->service() == NDBC)
this->getNdbcData();
else if (this->service() == XTIDE)
this->getXtideData();
} else {
if (this->service() == USGS && this->m_station.length() > 1) {
emit error(
"Beacuase each station has different characteristics, only one "
"USGS station may be selected at a time.");
emit finished();
return;
}

if (this->service() == NOAA)
this->getNoaaData();
else if (this->service() == USGS)
this->getUsgsData();
else if (this->service() == NDBC)
this->getNdbcData();
else if (this->service() == XTIDE)
this->getXtideData();
}
emit finished();
return;
}
Expand Down Expand Up @@ -502,3 +526,14 @@ QString MetOceanData::noaaIndexToUnits() { return noaaUnits[this->m_product]; }
int MetOceanData::getDatum() const { return m_datum; }

void MetOceanData::setDatum(int datum) { m_datum = datum; }

void MetOceanData::processCrmsData() {
CrmsDatabase *d = new CrmsDatabase(this->m_crmsFile.toStdString(),
this->m_outputFile.toStdString(), this);
connect(d, SIGNAL(error(QString)), this, SLOT(showError(QString)));
d->setShowProgressBar(true);
d->parse();
emit finished();
delete d;
return;
}
10 changes: 8 additions & 2 deletions MetOceanData/metoceandata.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class MetOceanData : public QObject {
explicit MetOceanData(serviceTypes service, QStringList station, int product,
int datum, QDateTime startDate, QDateTime endDate,
QString outputFile, QObject *parent = nullptr);
explicit MetOceanData(QString crmsFile, QString outputFile,
QObject *parent = nullptr);

static QStringList selectStations(serviceTypes service, double x1, double y1,
double x2, double y2);
Expand Down Expand Up @@ -62,9 +64,10 @@ class MetOceanData : public QObject {
int getDatum() const;
void setDatum(int datum);

static StationLocations::MarkerType serviceToMarkerType(MetOceanData::serviceTypes type);
static StationLocations::MarkerType serviceToMarkerType(
MetOceanData::serviceTypes type);
static bool findStation(QStringList name, StationLocations::MarkerType type,
QVector<Station> &s);
QVector<Station> &s);

signals:
void finished();
Expand All @@ -83,20 +86,23 @@ class MetOceanData : public QObject {
void getUsgsData();
void getNdbcData();
void getXtideData();
void processCrmsData();

QString noaaIndexToProduct();
QString noaaIndexToDatum();
QString noaaIndexToUnits();

int printAvailableProducts(Hmdf *data);

bool m_doCrms;
int m_service;
QStringList m_station;
int m_product;
int m_datum;
QDateTime m_startDate;
QDateTime m_endDate;
QString m_outputFile;
QString m_crmsFile;
};

#endif // DRIVER_H
23 changes: 20 additions & 3 deletions MetOceanData/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,25 @@ void Options::addOptions() {
<< m_serviceType << m_stationId << m_boundingBox
<< m_nearest << m_startDate << m_endDate
<< m_product << m_outputFile << m_datum << m_list
<< m_show);
<< m_show << m_crmsSourceFile);
}

Options::CommandLineOptions Options::getCommandLineOptions() {
Options::CommandLineOptions opt;

opt.doCrms = false;

if (this->parser()->isSet(m_crmsSourceFile)) {
if (!this->parser()->isSet(m_outputFile)) {
std::cerr << "No output file set." << std::endl;
this->parser()->showHelp(1);
}
opt.crms = this->parser()->value(m_crmsSourceFile);
opt.outputFile = this->parser()->value(m_outputFile);
opt.doCrms = true;
return opt;
}

std::vector<bool> inputOptions;
inputOptions.push_back(this->parser()->isSet(m_stationId));
inputOptions.push_back(this->parser()->isSet(m_boundingBox));
Expand Down Expand Up @@ -238,8 +251,12 @@ void Options::printStationList(QStringList station,
MetOceanData::serviceToMarkerType(markerType), s);
for (size_t i = 0; i < station.size(); ++i) {
std::cout << s[i].id().toStdString() << ",'"
<< s[i].name().replace(" ", "_").replace(",","_").replace("__","_").toStdString() << "',"
<< s[i].coordinate().longitude() << ","
<< s[i].name()
.replace(" ", "_")
.replace(",", "_")
.replace("__", "_")
.toStdString()
<< "'," << s[i].coordinate().longitude() << ","
<< s[i].coordinate().latitude() << std::endl;
std::cout.flush();
}
Expand Down
2 changes: 2 additions & 0 deletions MetOceanData/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Options : public QObject {
QDateTime endDate;
QString outputFile;
QStringList station;
bool doCrms;
QString crms;
};

void processOptions();
Expand Down
7 changes: 6 additions & 1 deletion MetOceanData/optionslist.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ static const QCommandLineOption m_outputFile =
QCommandLineOption(QStringList() << "o"
<< "output",
"Name of the output file. Format will be guessed from "
"extension (.imeds or .nc)",
"extension (.imeds or .nc). Note if performing crms "
"processing, the output extension will always be *.nc",
"filename");

static const QCommandLineOption m_boundingBox =
Expand All @@ -96,4 +97,8 @@ static const QCommandLineOption m_show =
"Show the stations that would be selected given the "
"provided criteria and exit.");

static const QCommandLineOption m_crmsSourceFile = QCommandLineOption(
QStringList() << "crms", "Converts a CRMS database into netCDF format",
"filename");

#endif // OPTIONSLIST_H
Binary file added MetOceanViewer/.DS_Store
Binary file not shown.
6 changes: 2 additions & 4 deletions MetOceanViewer/MetOceanViewer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ SOURCES +=\
src/uixtidetab.cpp \
src/mapfunctions.cpp \
src/uindbctab.cpp \
src/ndbc.cpp \
src/crmsdatabase.cpp
src/ndbc.cpp

HEADERS += \
src/crms.h \
Expand All @@ -86,8 +85,7 @@ HEADERS += \
src/updatedialog.h \
src/usertimeseries.h \
src/mapfunctions.h \
src/ndbc.h \
src/crmsdatabase.h
src/ndbc.h

FORMS += \
ui/crmsdialog.ui \
Expand Down
19 changes: 19 additions & 0 deletions MetOceanViewer/src/crms.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*-------------------------------GPL-------------------------------------//
//
// MetOcean Viewer - A simple interface for viewing hydrodynamic model data
// Copyright (C) 2018 Zach Cobell
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------*/
#include "crms.h"
#include "crmsdata.h"

Expand Down
19 changes: 19 additions & 0 deletions MetOceanViewer/src/crms.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*-------------------------------GPL-------------------------------------//
//
// MetOcean Viewer - A simple interface for viewing hydrodynamic model data
// Copyright (C) 2018 Zach Cobell
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------*/
#ifndef CRMS_H
#define CRMS_H

Expand Down
19 changes: 19 additions & 0 deletions MetOceanViewer/src/crmsdialog.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*-------------------------------GPL-------------------------------------//
//
// MetOcean Viewer - A simple interface for viewing hydrodynamic model data
// Copyright (C) 2018 Zach Cobell
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------*/
#include "crmsdialog.h"
#include <QFileDialog>
#include <QMessageBox>
Expand Down
19 changes: 19 additions & 0 deletions MetOceanViewer/src/crmsdialog.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*-------------------------------GPL-------------------------------------//
//
// MetOcean Viewer - A simple interface for viewing hydrodynamic model data
// Copyright (C) 2018 Zach Cobell
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------*/
#ifndef CRMSDIALOG_H
#define CRMSDIALOG_H

Expand Down
Loading

0 comments on commit 66f1e74

Please sign in to comment.