From d76bea9cfdbf41bfe3e5c106eb96c0a7189209bf Mon Sep 17 00:00:00 2001 From: rogerfraser Date: Fri, 28 May 2021 17:54:09 +1000 Subject: [PATCH] Code changes and test script to complete the work address #15 --- dynadjust/CMakeLists.txt | 1 + dynadjust/dynadjust/dnaadjust/dnaadjust.cpp | 62 +++++++++++++++++-- dynadjust/dynadjust/dnaadjust/dnaadjust.hpp | 1 + .../dnaadjustwrapper/dnaadjustwrapper.cpp | 6 +- dynadjust/dynadjust/dnaimport/dnainterop.cpp | 1 + dynadjust/include/config/dnaprojectfile.cpp | 1 + dynadjust/include/config/dnatypes.hpp | 15 +++-- .../include/functions/dnatemplatefuncs.hpp | 28 +++++++++ dynadjust/include/io/dnaiosnx.hpp | 22 +++---- dynadjust/include/io/dnaiosnxread.cpp | 11 ++-- .../include/measurement_types/dnastation.cpp | 7 ++- .../include/measurement_types/dnastation.hpp | 5 ++ 12 files changed, 132 insertions(+), 28 deletions(-) diff --git a/dynadjust/CMakeLists.txt b/dynadjust/CMakeLists.txt index b5b35bad..e2cf57ad 100644 --- a/dynadjust/CMakeLists.txt +++ b/dynadjust/CMakeLists.txt @@ -298,6 +298,7 @@ if (BUILD_TESTING) add_test (NAME imp-discont-01 COMMAND $ -n discont -r itrf2005 ${CMAKE_SOURCE_DIR}/../sampleData/TEST_ITRF05.SNX --discontinuity-file ${CMAKE_SOURCE_DIR}/../sampleData/disconts20201205.snx --export-discont-file) add_test (NAME imp-discont-02 COMMAND $ -n discont -r itrf2005 ${CMAKE_SOURCE_DIR}/../sampleData/TEST_ITRF05.SNX --discontinuity-file ${CMAKE_SOURCE_DIR}/../sampleData/disconts20201205.snx --split-gnss --include-stn "ALIC" --export-dna) add_test (NAME imp-discont-03 COMMAND $ -n discont -r itrf2014 --override-input-ref-frame ${CMAKE_SOURCE_DIR}/../sampleData/TEST_ITRF05.SNX ${CMAKE_SOURCE_DIR}/../sampleData/sa-gnss-stn.xml ${CMAKE_SOURCE_DIR}/../sampleData/sa-gnss-msr.xml --prefer-single-x-as-g --flag-unused --discontinuity-file ${CMAKE_SOURCE_DIR}/../sampleData/disconts20201205.snx --remove-ignored-msr --split-gnss --include-stns-assoc-msrs "ALIC" --export-dna --export-xml) + add_test (NAME adj-discont-01 COMMAND $ discont --constraint "ALIC,CCC") add_test (NAME imp-discont-04 COMMAND $ -n discont -r itrf2005 ${CMAKE_SOURCE_DIR}/../sampleData/TEST_ITRF05.SNX --export-xml) add_test (NAME imp-discont-05 COMMAND $ -n discont -r itrf2000 --override-input-ref-frame ./discontstn.xml ./discontmsr.xml --discontinuity-file ${CMAKE_SOURCE_DIR}/../sampleData/disconts20201205.snx) diff --git a/dynadjust/dynadjust/dnaadjust/dnaadjust.cpp b/dynadjust/dynadjust/dnaadjust/dnaadjust.cpp index a26c3dba..e07560f5 100644 --- a/dynadjust/dynadjust/dnaadjust/dnaadjust.cpp +++ b/dynadjust/dynadjust/dnaadjust/dnaadjust.cpp @@ -14189,7 +14189,45 @@ void dna_adjust::LoadNetworkFiles() v_measurementParams_ = v_measurementCount_; } + +void dna_adjust::AddDiscontinuitySites(vstring& constraintStns) +{ + // sort on original name + sort(bstBinaryRecords_.begin(), bstBinaryRecords_.end(), CompareStnOriginalName()); + pair it_stn_range; + string constraint; + + _it_vstr const_it; + + vstring constraintDiscontStns; + + // for every constraint (note every second value will be the constraint code) + for (const_it=constraintStns.begin(); const_it!=constraintStns.end(); ++const_it) + { + // find this constraint station in the station map + it_stn_range = equal_range(bstBinaryRecords_.begin(), bstBinaryRecords_.end(), (*const_it), CompareStnOriginalName()); + if (it_stn_range.first == it_stn_range.second) + { + // Not in the map. Get the next one + continue; + } + + // this constraint station is one of the discontinuity sites. + // Add the "discontinuity name" + constraintDiscontStns.push_back(it_stn_range.first->stationName); + // Add the constraint + if (++const_it == constraintStns.end()) + break; + constraintDiscontStns.push_back(*const_it); + } + + // add the constraint discontinuity sites + constraintStns.insert(constraintStns.end(), constraintDiscontStns.begin(), constraintDiscontStns.end()); + + // restore original sort order + sort(bstBinaryRecords_.begin(), bstBinaryRecords_.end(), CompareStnName()); +} // Take any additional user-supplied constraints (CCC,CCF,etc) and // apply to binary station records @@ -14198,8 +14236,6 @@ void dna_adjust::ApplyAdditionalConstraints() if (projectSettings_.a.station_constraints.empty()) return; - it_pair_string_vUINT32 it_stnmap_range; - // load station map v_string_uint32_pair vStnsMap; if (projectSettings_.a.map_file.empty()) @@ -14221,21 +14257,39 @@ void dna_adjust::ApplyAdditionalConstraints() return; } + if (projectSettings_.i.apply_discontinuities) + { + // Test for whether stations have been renamed, in which case, the + // look for non empty values in stn.stationNameOrig + AddDiscontinuitySites(constraintStns); + } + + it_pair_string_vUINT32 it_stnmap_range; + for (const_it=constraintStns.begin(); const_it!=constraintStns.end(); ++const_it) { // find this station in the station map it_stnmap_range = equal_range(vStnsMap.begin(), vStnsMap.end(), (*const_it), StationNameIDCompareName()); if (it_stnmap_range.first == it_stnmap_range.second) { + if (projectSettings_.i.apply_discontinuities) + { + // It is likely that these stations were renamed during + // discontinuity processing, so continue + if (++const_it == constraintStns.end()) + break; + continue; + } + stringstream ss; ss << "The supplied constraint station " << (*const_it) << " is not in the stations map. Please ensure that " << (*const_it) << " is included in the list of stations." << endl; + SignalExceptionAdjustment(ss.str(), 0); } // get constraint - ++const_it; - if (const_it == constraintStns.end()) + if (++const_it == constraintStns.end()) break; constraint = *const_it; diff --git a/dynadjust/dynadjust/dnaadjust/dnaadjust.hpp b/dynadjust/dynadjust/dnaadjust/dnaadjust.hpp index b5de040d..373dcb50 100644 --- a/dynadjust/dynadjust/dnaadjust/dnaadjust.hpp +++ b/dynadjust/dynadjust/dnaadjust/dnaadjust.hpp @@ -460,6 +460,7 @@ class dna_adjust { // Adjustment helps void ApplyAdditionalConstraints(); + void AddDiscontinuitySites(vstring& constraintStns); void LoadStationMap(pv_string_uint32_pair stnsMap, const string& stnmap_file); void ResizeMatrixVectors(); void LoadPhasedBlocks(); diff --git a/dynadjust/dynadjust/dnaadjustwrapper/dnaadjustwrapper.cpp b/dynadjust/dynadjust/dnaadjustwrapper/dnaadjustwrapper.cpp index 6c0db300..0901c9c7 100644 --- a/dynadjust/dynadjust/dnaadjustwrapper/dnaadjustwrapper.cpp +++ b/dynadjust/dynadjust/dnaadjustwrapper/dnaadjustwrapper.cpp @@ -1085,8 +1085,12 @@ int main(int argc, char* argv[]) if (p.a.scale_normals_to_unity) cout << setw(PRINT_VAR_PAD) << left << " Scale normals to unity: " << "yes" << endl; if (!p.a.station_constraints.empty()) + { cout << setw(PRINT_VAR_PAD) << left << " Station constraints: " << p.a.station_constraints << endl; - + if (p.i.apply_discontinuities) + cout << setw(PRINT_VAR_PAD) << left << " Apply discontinuities: " << "yes" << endl; + } + switch (p.a.adjust_mode) { case Phased_Block_1Mode: diff --git a/dynadjust/dynadjust/dnaimport/dnainterop.cpp b/dynadjust/dynadjust/dnaimport/dnainterop.cpp index 1ef61541..26385abd 100644 --- a/dynadjust/dynadjust/dnaimport/dnainterop.cpp +++ b/dynadjust/dynadjust/dnaimport/dnainterop.cpp @@ -787,6 +787,7 @@ void dna_import::AddDiscontinuityStations(vdnaStnPtr* vStations) // the duplicate having a larger file order, via SetfileOrder(++station_index) below. stn_ptr.reset(vStations->at(i)->clone()); + stn_ptr->SetOriginalName(); stn_ptr->SetName(stn_renames_it->second); stn_ptr->SetfileOrder(++station_index); vStations->push_back(stn_ptr); diff --git a/dynadjust/include/config/dnaprojectfile.cpp b/dynadjust/include/config/dnaprojectfile.cpp index bfbba492..c603737c 100644 --- a/dynadjust/include/config/dnaprojectfile.cpp +++ b/dynadjust/include/config/dnaprojectfile.cpp @@ -924,6 +924,7 @@ void CDnaProjectFile::LoadSettingImport(const settingMode mSetting, const string if (val.empty()) return; settings_.i.stn_discontinuityfile = formPath(settings_.g.input_folder, val); + settings_.i.apply_discontinuities = true; } else if (iequals(var, TEST_NEARBY_STNS)) { diff --git a/dynadjust/include/config/dnatypes.hpp b/dynadjust/include/config/dnatypes.hpp index 7d789f43..afdf4509 100644 --- a/dynadjust/include/config/dnatypes.hpp +++ b/dynadjust/include/config/dnatypes.hpp @@ -517,6 +517,7 @@ typedef struct block_meta { } blockMeta_t; const UINT16 STN_NAME_WIDTH(31); +const UINT16 STN_NAME_ORIG_WIDTH(40); const UINT16 STN_DESC_WIDTH(129); const UINT16 STN_CONST_WIDTH(4); const UINT16 STN_TYPE_WIDTH(4); @@ -533,6 +534,7 @@ typedef struct stn_t { , fileOrder(0), nameOrder(0), clusterID(0), unusedStation(FALSE) { memset(stationName, '\0', sizeof(stationName)); + memset(stationNameOrig, '\0', sizeof(stationNameOrig)); memset(stationConst, '\0', sizeof(stationConst)); memset(stationType, '\0', sizeof(stationType)); memset(description, '\0', sizeof(description)); @@ -543,12 +545,13 @@ typedef struct stn_t { memset(plate, '\0', sizeof(plate)); } - char stationName[STN_NAME_WIDTH]; // 30 characters - char stationConst[STN_CONST_WIDTH]; // constraint: lat, long, height - char stationType[STN_TYPE_WIDTH]; // type: LLH, UTM, XYZ - UINT16 suppliedStationType; // type supplied by the user (required for adjust) - double initialLatitude; // initial estimate - double currentLatitude; // current estimate + char stationName[STN_NAME_WIDTH]; // 30 characters + char stationNameOrig[STN_NAME_ORIG_WIDTH]; // 39 characters: 30 (name) + 1 (_) + 8 (date) + char stationConst[STN_CONST_WIDTH]; // constraint: lat, long, height + char stationType[STN_TYPE_WIDTH]; // type: LLH, UTM, XYZ + UINT16 suppliedStationType; // type supplied by the user (required for adjust) + double initialLatitude; // initial estimate + double currentLatitude; // current estimate double initialLongitude; double currentLongitude; double initialHeight; // initialHeight and currentHeight are always assumed to be diff --git a/dynadjust/include/functions/dnatemplatefuncs.hpp b/dynadjust/include/functions/dnatemplatefuncs.hpp index 6aef829b..20a51009 100644 --- a/dynadjust/include/functions/dnatemplatefuncs.hpp +++ b/dynadjust/include/functions/dnatemplatefuncs.hpp @@ -1040,6 +1040,34 @@ class CompareStnOrder_StnBlockMap }; +// T = station_t, S = string +template +class CompareStnName +{ +public: + bool operator()(const T& lhs, const T& rhs) { + return string(lhs.stationName) < string(rhs.stationName); + } +}; + + +// T = station_t, S = string +template +class CompareStnOriginalName +{ +public: + bool operator()(const T& lhs, const T& rhs) { + return string(lhs.stationNameOrig) < string(rhs.stationNameOrig); + } + bool operator()(const T& lhs, const S& rhs) { + return string(lhs.stationNameOrig) < rhs; + } + bool operator()(const S& lhs, const T& rhs) { + return lhs < string(rhs.stationNameOrig); + } +}; + + // S = station_t, U = UINT32 template class CompareStnLongitude diff --git a/dynadjust/include/io/dnaiosnx.hpp b/dynadjust/include/io/dnaiosnx.hpp index 2e47af30..33d4ff28 100644 --- a/dynadjust/include/io/dnaiosnx.hpp +++ b/dynadjust/include/io/dnaiosnx.hpp @@ -177,21 +177,19 @@ bool rename_discont_station(T& begin, S& site_name, D& site_date, S& site_rename { // format using the start epoch // year - ss << dateYear(site_date); + year << dateYear(site_date); // doy - ss << dateDOY(site_date); - } - else - { - // format using the discontinuity date - ss << year; - if (doy < 10) - ss << "0"; - if (doy < 100) - ss << "0"; - ss << doy; + doy = dateDOY(site_date); + } + ss << year; + if (doy < 100) + ss << "0"; + if (doy < 10) + ss << "0"; + ss << doy; + site_renamed = ss.str(); return true; diff --git a/dynadjust/include/io/dnaiosnxread.cpp b/dynadjust/include/io/dnaiosnxread.cpp index 058a09f9..10ee6fd7 100644 --- a/dynadjust/include/io/dnaiosnxread.cpp +++ b/dynadjust/include/io/dnaiosnxread.cpp @@ -408,19 +408,19 @@ void dna_io_snx::format_station_names(v_discontinuity_tuple* stn_discontinuities if (year == DISCONT_TIME_IMMEMORIAL) { // format using the start epoch - // year + // year (4 chars) ss << siteOccurrence_.at(site).formatted_date.substr(4, 4); - // doy + // doy (3 chars) ss << siteOccurrence_.at(site).formatted_date.substr(0, 3); } else { // format using the discontinuity date ss << year; - if (doy < 10) - ss << "0"; if (doy < 100) ss << "0"; + if (doy < 10) + ss << "0"; ss << doy; } @@ -450,7 +450,10 @@ void dna_io_snx::format_station_names(v_discontinuity_tuple* stn_discontinuities for_each(vStations->begin(), vStations->end(), [&_it_site](const dnaStnPtr& stn) { if (!equals(_it_site->site_name, _it_site->formatted_name)) + { + stn->SetOriginalName(); stn->SetName(_it_site->formatted_name); + } _it_site++; }); diff --git a/dynadjust/include/measurement_types/dnastation.cpp b/dynadjust/include/measurement_types/dnastation.cpp index 09b7e273..49b17256 100644 --- a/dynadjust/include/measurement_types/dnastation.cpp +++ b/dynadjust/include/measurement_types/dnastation.cpp @@ -128,7 +128,7 @@ CAStationList& CAStationList::operator =(CAStationList&& rhs) //// CDnaStation::CDnaStation(const string& referenceframe, const string& epoch) - : m_strName("") + : m_strName(""), m_strOriginalName("") , m_dXAxis(0.), m_dYAxis(0.), m_dZAxis(0.), m_dHeight(0.) , m_dStdDevX(0.), m_dStdDevY(0.), m_dStdDevZ(0.), m_dStdDevHt(0.) , m_strConstraints("FFF"), m_strType(""), m_strHemisphereZone(""), m_strDescription(""), m_strComment("") @@ -151,6 +151,7 @@ CDnaStation::~CDnaStation() CDnaStation::CDnaStation(const CDnaStation& newStation) { m_strName = newStation.m_strName; + m_strOriginalName = newStation.m_strOriginalName; m_strConstraints = newStation.m_strConstraints; m_strType = newStation.m_strType; m_dXAxis = newStation.m_dXAxis; @@ -194,6 +195,8 @@ CDnaStation::CDnaStation(const string& strName, const string& strConstraints, const string& strComment) { m_strName = strName; + + m_strOriginalName = ""; SetConstraints(strConstraints); SetCoordType(strType); @@ -864,6 +867,7 @@ void CDnaStation::WriteBinaryStn(std::ofstream* binary_stream, const UINT16 bUnu { station_t stationRecord; strcpy(stationRecord.stationName, m_strName.substr(0, STN_NAME_WIDTH).c_str()); + strcpy(stationRecord.stationNameOrig, m_strOriginalName.substr(0, STN_NAME_WIDTH).c_str()); strcpy(stationRecord.stationConst, m_strConstraints.substr(0, STN_CONST_WIDTH).c_str()); strcpy(stationRecord.stationType, m_strType.substr(0, STN_TYPE_WIDTH).c_str()); @@ -1133,6 +1137,7 @@ void CDnaStation::WriteGeoidfile(std::ofstream* geo_ofstream) void CDnaStation::SetStationRec(const station_t& stationRecord) { SetName(stationRecord.stationName); + SetOriginalName(stationRecord.stationNameOrig); SetConstraints(stationRecord.stationConst); SetCoordType(stationRecord.stationType); diff --git a/dynadjust/include/measurement_types/dnastation.hpp b/dynadjust/include/measurement_types/dnastation.hpp index 1f3c0ae8..e3c256fc 100644 --- a/dynadjust/include/measurement_types/dnastation.hpp +++ b/dynadjust/include/measurement_types/dnastation.hpp @@ -171,6 +171,7 @@ class CDnaStation inline int CompareStationName(const string& s) { return m_strName.compare(s); } inline string GetName() const { return m_strName; } + inline string GetOriginalName() const { return m_strOriginalName; } inline string GetConstraints() const { return m_strConstraints; } inline string GetCoordType() const { return m_strType; } @@ -232,6 +233,8 @@ class CDnaStation inline void SetcurrentHeight_d(const double& dHeight) { m_dcurrentHeight = dHeight; } inline void SetName(const string& sName) { m_strName = trimstr(sName); } + inline void SetOriginalName(const string& sName) { m_strOriginalName = trimstr(sName); } + inline void SetOriginalName() { m_strOriginalName = m_strName; } void SetHemisphereZone(const string& sHemisphereZone); inline void SetDescription(const string& sDescription) { m_strDescription = trimstr(sDescription); } inline void SetComment(const string& sComment) { m_strComment = trimstr(sComment); } @@ -308,6 +311,8 @@ class CDnaStation protected: + string m_strOriginalName; + double m_dXAxis; double m_dYAxis; double m_dZAxis;