| 1 |
|
|---|
| 2 | /* -------------------------------------------------------------------------
|
|---|
| 3 | * BKG NTRIP Server
|
|---|
| 4 | * -------------------------------------------------------------------------
|
|---|
| 5 | *
|
|---|
| 6 | * Class: bncoutf
|
|---|
| 7 | *
|
|---|
| 8 | * Purpose: Basis Class for File-Writers
|
|---|
| 9 | *
|
|---|
| 10 | * Author: L. Mervart
|
|---|
| 11 | *
|
|---|
| 12 | * Created: 25-Apr-2008
|
|---|
| 13 | *
|
|---|
| 14 | * Changes:
|
|---|
| 15 | *
|
|---|
| 16 | * -----------------------------------------------------------------------*/
|
|---|
| 17 |
|
|---|
| 18 | #include <math.h>
|
|---|
| 19 | #include <iomanip>
|
|---|
| 20 |
|
|---|
| 21 | #include "bncoutf.h"
|
|---|
| 22 | #include "bncsettings.h"
|
|---|
| 23 |
|
|---|
| 24 | using namespace std;
|
|---|
| 25 |
|
|---|
| 26 | // Constructor
|
|---|
| 27 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 28 | bncoutf::bncoutf(const QString& sklFileName, const QString& intr, int sampl) {
|
|---|
| 29 |
|
|---|
| 30 | bncSettings settings;
|
|---|
| 31 |
|
|---|
| 32 | _headerWritten = false;
|
|---|
| 33 | _sampl = sampl;
|
|---|
| 34 | _intr = intr;
|
|---|
| 35 | _numSec = 0;
|
|---|
| 36 |
|
|---|
| 37 | if (! sklFileName.isEmpty()) {
|
|---|
| 38 | QFileInfo fileInfo(sklFileName);
|
|---|
| 39 | _path = fileInfo.absolutePath() + QDir::separator();
|
|---|
| 40 | _sklBaseName = fileInfo.baseName();
|
|---|
| 41 | _extension = fileInfo.completeSuffix();
|
|---|
| 42 |
|
|---|
| 43 | expandEnvVar(_path);
|
|---|
| 44 | if (!_extension.isEmpty()) {
|
|---|
| 45 | _extension = "." + _extension;
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | _append = Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | // Destructor
|
|---|
| 53 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 54 | bncoutf::~bncoutf() {
|
|---|
| 55 | closeFile();
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | // Close the Old RINEX File
|
|---|
| 59 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 60 | void bncoutf::closeFile() {
|
|---|
| 61 | _out.close();
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | // Epoch String
|
|---|
| 65 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 66 | QString bncoutf::epochStr(const QDateTime& datTim, const QString& intStr,
|
|---|
| 67 | int sampl) {
|
|---|
| 68 |
|
|---|
| 69 | QString epoStr = "";
|
|---|
| 70 |
|
|---|
| 71 | int indHlp = intStr.indexOf("min");
|
|---|
| 72 | if (!sampl) {
|
|---|
| 73 | if (_sklBaseName.contains("V3PROD") &&
|
|---|
| 74 | (_extension.contains("BIA") ||
|
|---|
| 75 | _extension.contains("SP3") ||
|
|---|
| 76 | _extension.contains("CLK"))) {
|
|---|
| 77 | sampl +=5;
|
|---|
| 78 | } else {
|
|---|
| 79 | sampl++;
|
|---|
| 80 | }
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | if ( indHlp != -1) {
|
|---|
| 84 | int step = intStr.left(indHlp-1).toInt();
|
|---|
| 85 | epoStr += QString("%1").arg(datTim.time().hour(), 2, 10, QChar('0')); // H
|
|---|
| 86 |
|
|---|
| 87 | if (datTim.time().minute() >= 60-step) {
|
|---|
| 88 | epoStr += QString("%1").arg(60-step, 2, 10, QChar('0')); // M
|
|---|
| 89 | }
|
|---|
| 90 | else {
|
|---|
| 91 | for (int limit = step; limit <= 60-step; limit += step) {
|
|---|
| 92 | if (datTim.time().minute() < limit) {
|
|---|
| 93 | epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0')); // M
|
|---|
| 94 | break;
|
|---|
| 95 | }
|
|---|
| 96 | }
|
|---|
| 97 | }
|
|---|
| 98 | epoStr += QString("_%1M").arg(step, 2, 10, QChar('0')); // period
|
|---|
| 99 |
|
|---|
| 100 | _numSec = 60 * step;
|
|---|
| 101 | }
|
|---|
| 102 | else if (intStr == "1 hour") {
|
|---|
| 103 | int step = intStr.left(indHlp-1).toInt();
|
|---|
| 104 | epoStr += QString("%1").arg(datTim.time().hour(), 2, 10, QChar('0')); // H
|
|---|
| 105 | epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // M
|
|---|
| 106 | epoStr += QString("_%1H").arg(step+1, 2, 10, QChar('0')); // period
|
|---|
| 107 | _numSec = 3600;
|
|---|
| 108 | }
|
|---|
| 109 | else {
|
|---|
| 110 | int step = intStr.left(indHlp-1).toInt();
|
|---|
| 111 | epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // H
|
|---|
| 112 | epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // M
|
|---|
| 113 | epoStr += QString("_%1D").arg(step+1, 2, 10, QChar('0')); // period
|
|---|
| 114 | _numSec = 86400;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | if (sampl < 60) {
|
|---|
| 119 | epoStr += QString("_%1S").arg(sampl, 2, 10, QChar('0'));
|
|---|
| 120 | }
|
|---|
| 121 | else {
|
|---|
| 122 | sampl /= 60;
|
|---|
| 123 | epoStr += QString("_%1M").arg(sampl, 2, 10, QChar('0'));
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | return epoStr;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | // File Name according to RINEX Standards
|
|---|
| 130 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 131 | QString bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
|
|---|
| 132 |
|
|---|
| 133 | int dayOfWeek = datTim.date().dayOfWeek();
|
|---|
| 134 | if (dayOfWeek == 7) {
|
|---|
| 135 | dayOfWeek = 0;
|
|---|
| 136 | }
|
|---|
| 137 | int dayOfYear = datTim.date().dayOfYear();
|
|---|
| 138 |
|
|---|
| 139 | QString yyyy = QString::number(datTim.date().year());
|
|---|
| 140 | QString doy = QString("%1").arg(dayOfYear,3,10, QLatin1Char('0'));
|
|---|
| 141 | QString gpswd = QString("%1%2").arg(GPSweek).arg(dayOfWeek);
|
|---|
| 142 | QString epoStr = epochStr(datTim, _intr, _sampl);
|
|---|
| 143 | QString baseName = _sklBaseName;
|
|---|
| 144 | baseName.replace("${GPSWD}", gpswd);
|
|---|
| 145 | baseName.replace("${V3OBS}" , QString("_U_%1%2").arg(yyyy).arg(doy));
|
|---|
| 146 | baseName.replace("${V3PROD}", QString("_%1%2").arg(yyyy).arg(doy));
|
|---|
| 147 | QString addition = "";
|
|---|
| 148 | if (_extension.contains("SP3")) {
|
|---|
| 149 | addition = QString("_ORB");
|
|---|
| 150 | }
|
|---|
| 151 | if (_extension.contains("CLK")) {
|
|---|
| 152 | addition = QString("_CLK");
|
|---|
| 153 | }
|
|---|
| 154 | if (_extension.contains("BIA")) {
|
|---|
| 155 | addition = QString("_OSB");
|
|---|
| 156 | }
|
|---|
| 157 | if (_extension.contains("TRO")) {
|
|---|
| 158 | QString site = baseName.left(9);
|
|---|
| 159 | bncSettings settings;
|
|---|
| 160 | QString ac = settings.value("PPP/snxtroAc").toString();
|
|---|
| 161 | QString solId = settings.value("PPP/snxtroSolId").toString();
|
|---|
| 162 | QString solType = settings.value("PPP/snxtroSolType").toString();
|
|---|
| 163 | QString campId = settings.value("PPP/snxtroCampId").toString();
|
|---|
| 164 | baseName.replace(0,3,ac);
|
|---|
| 165 | baseName.replace(3,1,solId);
|
|---|
| 166 | baseName.replace(4,3,campId);
|
|---|
| 167 | baseName.replace(7,3,solType);
|
|---|
| 168 | addition = QString("_%1_TRO").arg(site);
|
|---|
| 169 | }
|
|---|
| 170 | if (_extension.count(".") == 2) {
|
|---|
| 171 | _extension.replace(0,1,"_");
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | return _path + baseName + epoStr + addition + _extension;
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | // Re-Open Output File
|
|---|
| 178 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 179 | t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
|
|---|
| 180 |
|
|---|
| 181 | if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
|
|---|
| 182 | return failure;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
|
|---|
| 186 |
|
|---|
| 187 | QString newFileName = resolveFileName(GPSweek, datTim);
|
|---|
| 188 |
|
|---|
| 189 | bool wait = false;
|
|---|
| 190 | if (isProductFile() &&
|
|---|
| 191 | datTim.time().hour() == 0 &&
|
|---|
| 192 | datTim.time().minute() == 0 &&
|
|---|
| 193 | (datTim.time().second() == 0.0 || datTim.time().second() == _sampl)) {
|
|---|
| 194 | wait = true;
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | // Close the file
|
|---|
| 198 | // --------------
|
|---|
| 199 | if (newFileName != _fName && !wait) {
|
|---|
| 200 | closeFile();
|
|---|
| 201 | _headerWritten = false;
|
|---|
| 202 | _fName = newFileName;
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | // Re-Open File, Write Header
|
|---|
| 206 | // --------------------------
|
|---|
| 207 | if (!_headerWritten) {
|
|---|
| 208 | _out.setf(ios::showpoint | ios::fixed);
|
|---|
| 209 | if (_append && QFile::exists(_fName)) {
|
|---|
| 210 | _out.open(_fName.toLatin1().data(), ios::out | ios::app);
|
|---|
| 211 | }
|
|---|
| 212 | else {
|
|---|
| 213 | _out.open(_fName.toLatin1().data());
|
|---|
| 214 | writeHeader(datTim);
|
|---|
| 215 | }
|
|---|
| 216 | if (_out.is_open()) {
|
|---|
| 217 | _headerWritten = true;
|
|---|
| 218 | }
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | return success;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | // Write String
|
|---|
| 225 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 226 | t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
|
|---|
| 227 | reopen(GPSweek, GPSweeks);
|
|---|
| 228 | _out << str.toLatin1().data();
|
|---|
| 229 | _out.flush();
|
|---|
| 230 | return success;
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | QString bncoutf::agencyFromFileName() {
|
|---|
| 234 | return QString("%1").arg(_sklBaseName.left(3));
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | // Files with epoch 00:00:00 at begin and end
|
|---|
| 238 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 239 | bool bncoutf::isProductFile() {
|
|---|
| 240 | bool isProduct = false;
|
|---|
| 241 |
|
|---|
| 242 | if (_extension.contains("SP3")) {
|
|---|
| 243 | isProduct = true;
|
|---|
| 244 | }
|
|---|
| 245 | if (_extension.contains("CLK")) {
|
|---|
| 246 | isProduct = true;
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | return isProduct;
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|