Skip to content

Commit

Permalink
Merge pull request #147 from rogerfraser/master
Browse files Browse the repository at this point in the history
Final code changes to close #15
  • Loading branch information
rogerfraser authored May 28, 2021
2 parents fda5e8f + d76bea9 commit f5e13cb
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 28 deletions.
1 change: 1 addition & 0 deletions dynadjust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ if (BUILD_TESTING)
add_test (NAME imp-discont-01 COMMAND $<TARGET_FILE:dnaimportwrapper> -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 $<TARGET_FILE:dnaimportwrapper> -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 $<TARGET_FILE:dnaimportwrapper> -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 $<TARGET_FILE:dnaadjustwrapper> discont --constraint "ALIC,CCC")
add_test (NAME imp-discont-04 COMMAND $<TARGET_FILE:dnaimportwrapper> -n discont -r itrf2005 ${CMAKE_SOURCE_DIR}/../sampleData/TEST_ITRF05.SNX --export-xml)
add_test (NAME imp-discont-05 COMMAND $<TARGET_FILE:dnaimportwrapper> -n discont -r itrf2000 --override-input-ref-frame ./discontstn.xml ./discontmsr.xml --discontinuity-file ${CMAKE_SOURCE_DIR}/../sampleData/disconts20201205.snx)

Expand Down
62 changes: 58 additions & 4 deletions dynadjust/dynadjust/dnaadjust/dnaadjust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<station_t, string>());

pair<it_vstn_t, it_vstn_t> 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<station_t, string>());
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<station_t>());
}

// Take any additional user-supplied constraints (CCC,CCF,etc) and
// apply to binary station records
Expand All @@ -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())
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions dynadjust/dynadjust/dnaadjust/dnaadjust.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion dynadjust/dynadjust/dnaadjustwrapper/dnaadjustwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions dynadjust/dynadjust/dnaimport/dnainterop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions dynadjust/include/config/dnaprojectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ void CDnaProjectFile::LoadSettingImport(const settingMode mSetting, const string
if (val.empty())
return;
settings_.i.stn_discontinuityfile = formPath<string>(settings_.g.input_folder, val);
settings_.i.apply_discontinuities = true;
}
else if (iequals(var, TEST_NEARBY_STNS))
{
Expand Down
15 changes: 9 additions & 6 deletions dynadjust/include/config/dnatypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions dynadjust/include/functions/dnatemplatefuncs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,34 @@ class CompareStnOrder_StnBlockMap
};


// T = station_t, S = string
template<typename T>
class CompareStnName
{
public:
bool operator()(const T& lhs, const T& rhs) {
return string(lhs.stationName) < string(rhs.stationName);
}
};


// T = station_t, S = string
template<typename T, typename S>
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<typename S, typename U>
class CompareStnLongitude
Expand Down
22 changes: 10 additions & 12 deletions dynadjust/include/io/dnaiosnx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UINT32>(site_date);
year << dateYear<UINT32>(site_date);
// doy
ss << dateDOY<UINT32>(site_date);
}
else
{
// format using the discontinuity date
ss << year;
if (doy < 10)
ss << "0";
if (doy < 100)
ss << "0";
ss << doy;
doy = dateDOY<UINT32>(site_date);

}

ss << year;
if (doy < 100)
ss << "0";
if (doy < 10)
ss << "0";
ss << doy;

site_renamed = ss.str();

return true;
Expand Down
11 changes: 7 additions & 4 deletions dynadjust/include/io/dnaiosnxread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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++;
});

Expand Down
7 changes: 6 additions & 1 deletion dynadjust/include/measurement_types/dnastation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ CAStationList& CAStationList::operator =(CAStationList&& rhs)

//<CDnaStation>//
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("")
Expand All @@ -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;
Expand Down Expand Up @@ -194,6 +195,8 @@ CDnaStation::CDnaStation(const string& strName, const string& strConstraints,
const string& strComment)
{
m_strName = strName;

m_strOriginalName = "";

SetConstraints(strConstraints);
SetCoordType(strType);
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions dynadjust/include/measurement_types/dnastation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -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); }
Expand Down Expand Up @@ -308,6 +311,8 @@ class CDnaStation

protected:

string m_strOriginalName;

double m_dXAxis;
double m_dYAxis;
double m_dZAxis;
Expand Down

0 comments on commit f5e13cb

Please sign in to comment.