Skip to content

Commit

Permalink
Merge pull request #109 from rogerfraser/master
Browse files Browse the repository at this point in the history
Code enhancements and bug fix for geoid
  • Loading branch information
rogerfraser committed May 1, 2021
2 parents 4555183 + 4ebaba7 commit ef25f70
Show file tree
Hide file tree
Showing 9 changed files with 356 additions and 201 deletions.
1 change: 1 addition & 0 deletions dynadjust/dynadjust/dnaadjustwrapper/dnaadjustwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void PrintSummaryMessage(dna_adjust* netAdjust, const project_settings* p, milli
if (p->a.report_mode)
{
cout << "+ Printing results of last adjustment only" << endl;
cout_mutex.unlock();
return;
}

Expand Down
411 changes: 250 additions & 161 deletions dynadjust/dynadjust/dnageoid/dnageoid.cpp

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions dynadjust/dynadjust/dnageoid/dnageoid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ using namespace dynadjust::measurements;
using namespace dynadjust::exception;
using namespace dynadjust::iostreams;

/* format identifiers for NTv2 grid file */
// grid node format identifiers for ASCII NTv2 grid file
const char* const SHIFTS = "%f%f%f%f";
// grid node line length for ASCII NTv2 grid file
const UINT32 ASCII_LINE_LENGTH = 40;

#define GSB "gsb"
#define ASC "asc"
Expand Down Expand Up @@ -165,10 +167,10 @@ class dna_geoid_interpolation {
void CreateNTv2File(const char* datFile, const n_file_par* grid);

// Exports an Binary grid file to a Ascii format
void ExportToAscii(const char* inputGrid, const char* gridtype, const char* outputGrid, int* IO_Status);
void ExportToAscii(const char* inputGrid, const char* gridType, const char* shiftType, const char* outputGrid, int* IO_Status);

// Exports an Ascii grid file to a Binary format
void ExportToBinary(const char* inputGrid, const char* gridtype, const char* outputGrid, int* IO_Status);
void ExportToBinary(const char* inputGrid, const char* gridType, const char* shiftType, const char* outputGrid, int* IO_Status);

// Prints the gridfile header information to a file_par struct
void ReportGridProperties(const char* fileName, const char* fileType, n_file_par* gridProperties);
Expand Down Expand Up @@ -204,8 +206,10 @@ class dna_geoid_interpolation {

// NTv2 File creation
void SetDefaultGridFileParametersTmp(n_file_par* ntv2_params);
void PrintDefaultGridHeaderInfo(std::ofstream* f_out, n_file_par* pGridfile, bool isBinary=true);
void PrintDefaultSubGridHeaderInfo(std::ofstream* f_out, n_gridfileindex* m_gfIndex, const char* chGs_type, bool isBinary=true);
void PrintGridHeaderInfoAscii(std::ofstream* f_out, n_file_par* pGridfile);
void PrintGridHeaderInfoBinary(std::ofstream* f_out, n_file_par* pGridfile);
void PrintSubGridHeaderInfoAscii(std::ofstream* f_out, n_gridfileindex* m_gfIndex, const string& shiftType);
void PrintSubGridHeaderInfoBinary(std::ofstream* f_out, n_gridfileindex* m_gfIndex, const string& shiftType);
void UpdateHeaderInfo(std::ofstream* f_out);
void ScanDatFileValues(char* szLine, float* n_value, char* c_northsouth, int* lat_deg, int* lat_min, float* lat_sec, char* c_eastwest, int* lon_deg, int* lon_min, float* lon_sec, float* defl_meridian, float* defl_primev);
void ScanNodeLocations(char* szLine, double* latitude, double* longitude, const UINT32& lNodeRead);
Expand Down Expand Up @@ -262,6 +266,10 @@ class dna_geoid_interpolation {
bool m_fileMode;

string m_inputCoordinates;

bool m_isRadians;

UINT32 m_lineLength;
};

} // namespace geoidinterpolation
Expand Down
8 changes: 4 additions & 4 deletions dynadjust/dynadjust/dnageoid/dnageoid_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ extern "C"
}

// Exports an Binary grid file to a Ascii format
bool DNAGEOID_CAPI DNAGEOID_ExporttoAscii(char* gridFile, char* gridType, char* outputGrid, int* status)
bool DNAGEOID_CAPI DNAGEOID_ExporttoAscii(char* gridFile, char* gridType, const char* shiftType, char* outputGrid, int* status)
{
try {
*status = 0;
theApp.ExportToAscii(gridFile, gridType, outputGrid, status);
theApp.ExportToAscii(gridFile, gridType, shiftType, outputGrid, status);
}
catch (const NetGeoidException& e) {
*status = e.error_no();
Expand All @@ -200,11 +200,11 @@ extern "C"
}

// Exports an Ascii grid file to a Binary format
bool DNAGEOID_CAPI DNAGEOID_ExporttoBinary(char *gridFile, char *gridType, char *outputGrid, int *status)
bool DNAGEOID_CAPI DNAGEOID_ExporttoBinary(char *gridFile, char *gridType, char* shiftType, char *outputGrid, int *status)
{
try {
*status = 0;
theApp.ExportToBinary(gridFile, gridType, outputGrid, status);
theApp.ExportToBinary(gridFile, gridType, shiftType, outputGrid, status);
}
catch (const NetGeoidException& e) {
*status = e.error_no();
Expand Down
4 changes: 2 additions & 2 deletions dynadjust/dynadjust/dnageoid/dnageoid_ext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ extern "C" {
bool DNAGEOID_CAPI DNAGEOID_FileTransformation(const char* fileIn, const char* fileOut, const int& method, const int& intEllipsoidtoOrtho, const int& intDmsFlag, bool exportDnaGeoidFile, int* status);

// Exports an Binary grid file to a Ascii format
bool DNAGEOID_CAPI DNAGEOID_ExporttoAscii(char *gridFile, char *gridType, char *outputGrid, int *status);
bool DNAGEOID_CAPI DNAGEOID_ExporttoAscii(char *gridFile, char *gridType, char* shiftType, char *outputGrid, int *status);

// Exports an Ascii grid file to a Binary format
bool DNAGEOID_CAPI DNAGEOID_ExporttoBinary(char *gridFile, char *gridType, char *outputGrid, int *status);
bool DNAGEOID_CAPI DNAGEOID_ExporttoBinary(char *gridFile, char *gridType, char* shiftType, char *outputGrid, int *status);

// Returns the file progress as a percentage
bool DNAGEOID_CAPI DNAGEOID_ReturnFileProgress(int *percentComplete, int *status);
Expand Down
87 changes: 58 additions & 29 deletions dynadjust/dynadjust/dnageoidwrapper/dnageoidwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ void PrintVersion()

bool CreateNTv2Grid(dna_geoid_interpolation* g, const char* dat_gridfilePath, const n_file_par* grid)
{
//cout << "+ Creating NTv2 grid file... ";
// example:
// geoid -d ausgeoid09_gda94_v1.01_clip_1x1.dat -c -g ausgeoid_clip_1.0.1.0.gsb --grid-shift radians --grid-version 1.0.1.0 --system-fr ___GDA94 --system-to ___AHD71 --sub-grid-n 1D-grid --creation 21.04.2021 --update 22.04.2021
//

cout << "+ Creating NTv2 geoid grid file from WINTER DAT file format..." << endl;

try {
g->CreateNTv2File(dat_gridfilePath, grid);
}
Expand All @@ -61,17 +66,21 @@ bool CreateNTv2Grid(dna_geoid_interpolation* g, const char* dat_gridfilePath, co
}


bool ExportNTv2GridToAscii(dna_geoid_interpolation* g, const char* dat_gridfilePath, const char* gridfileType, const char* exportfileType)
bool ExportNTv2GridToAscii(dna_geoid_interpolation* g, const char* dat_gridfilePath, const char* gridfileType, const char* gridshiftType, const char* exportfileType)
{
// example:
// geoid -g ausgeoid_clip_1.0.1.0.gsb --grid-shift radians --export-ntv2-asc
//

path asciiGridFile(dat_gridfilePath);
string outfile = asciiGridFile.filename().string() + "." + exportfileType;

int ioStatus;

cout << endl << "+ Exporting geoid file to " << leafStr<string>(outfile) << "... ";
cout << endl << "+ Exporting NTv2 geoid grid file to " << leafStr<string>(outfile) << "... ";

try {
g->ExportToAscii(dat_gridfilePath, gridfileType, outfile.c_str(), &ioStatus);
g->ExportToAscii(dat_gridfilePath, gridfileType, gridshiftType, outfile.c_str(), &ioStatus);
}
catch (const NetGeoidException& e) {
cout << endl << "- Error: " << e.what() << endl;
Expand All @@ -89,7 +98,7 @@ bool ExportNTv2GridToAscii(dna_geoid_interpolation* g, const char* dat_gridfileP



bool ExportNTv2GridToBinary(dna_geoid_interpolation* g, const char* dat_gridfilePath, const char* gridfileType, const char* exportfileType)
bool ExportNTv2GridToBinary(dna_geoid_interpolation* g, const char* dat_gridfilePath, const char* gridfileType, const char* gridshiftType, const char* exportfileType)
{
path asciiGridFile(dat_gridfilePath);
string outfile = asciiGridFile.filename().string() + "." + exportfileType;
Expand All @@ -99,7 +108,7 @@ bool ExportNTv2GridToBinary(dna_geoid_interpolation* g, const char* dat_gridfile
cout << endl << "+ Exporting geoid file to " << leafStr<string>(outfile) << "... ";

try {
g->ExportToBinary(dat_gridfilePath, gridfileType, outfile.c_str(), &ioStatus);
g->ExportToBinary(dat_gridfilePath, gridfileType, gridshiftType, outfile.c_str(), &ioStatus);
}
catch (const NetGeoidException& e) {
cout << endl << "- Error: " << e.what() << endl;
Expand Down Expand Up @@ -193,6 +202,11 @@ bool reportGridProperties(dna_geoid_interpolation* g, const char* gridfilePath,
return false;
}

bool isRadians(false);
string shiftType(grid_properties.chGs_type);
if (iequals(trimstr(shiftType), "radians"))
isRadians = true;

string formattedLimit;

cout << "+ Grid properties for " << gridfilePath << ":" << endl;
Expand All @@ -217,25 +231,32 @@ bool reportGridProperties(dna_geoid_interpolation* g, const char* gridfilePath,
cout << " - CREATED = " << grid_properties.ptrIndex[i].chCreated << endl; // date of creation (CREATED)
cout << " - UPDATED = " << grid_properties.ptrIndex[i].chUpdated << endl; // date of last file update (UPDATED)

cout << " - S_LAT = " << right << setw(REL) << grid_properties.ptrIndex[i].dSlat; // lower latitude (S_LAT)
// In ptrIndex, all values for the limits of a grid are held in seconds, despite
// whether the grid node records are in radians.

// lower latitude (S_LAT)
cout << " - S_LAT = " << right << setw(isRadians ? ZONE : REL) << grid_properties.ptrIndex[i].dSlat;
formattedLimit = "(" + FormatDmsString(DegtoDms(grid_properties.ptrIndex[i].dSlat / DEG_TO_SEC), 6, true, false) + ")";
cout << right << setw(MEASR) << formattedLimit << endl;

cout << " - N_LAT = " << setw(REL) << grid_properties.ptrIndex[i].dNlat; // upper latitude (N_LAT)
// upper latitude (N_LAT)
cout << " - N_LAT = " << right << setw(isRadians ? ZONE : REL) << grid_properties.ptrIndex[i].dNlat;
formattedLimit = "(" + FormatDmsString(DegtoDms(grid_properties.ptrIndex[i].dNlat / DEG_TO_SEC), 6, true, false) + ")";
cout << right << setw(MEASR) << formattedLimit << endl;

cout << " - E_LONG = " << setw(REL) << grid_properties.ptrIndex[i].dElong; // lower longitude (E_LONG)
// lower longitude (E_LONG)
cout << " - E_LONG = " << right << setw(isRadians ? ZONE : REL) << grid_properties.ptrIndex[i].dElong;
formattedLimit = "(" + FormatDmsString(DegtoDms(grid_properties.ptrIndex[i].dElong / DEG_TO_SEC), 6, true, false) + ")";
cout << right << setw(MEASR) << formattedLimit << endl;

cout << " - W_LONG = " << setw(REL) << grid_properties.ptrIndex[i].dWlong; // upper longitude (W_LONG)
// upper longitude (W_LONG)
cout << " - W_LONG = " << right << setw(isRadians ? ZONE : REL) << grid_properties.ptrIndex[i].dWlong;
formattedLimit = "(" + FormatDmsString(DegtoDms(grid_properties.ptrIndex[i].dWlong / DEG_TO_SEC), 6, true, false) + ")";
cout << right << setw(MEASR) << formattedLimit << endl;

cout << " - LAT_INC = " << grid_properties.ptrIndex[i].dLatinc << endl; // latitude interval (LAT_INC)
cout << " - LONG_INC = " << grid_properties.ptrIndex[i].dLonginc << endl; // longitude interval (LONG_INC)
cout << " - GS_COUNT = " << grid_properties.ptrIndex[i].lGscount << endl; // number of nodes (GS_COUNT)
cout << " - LAT_INC = " << fixed << grid_properties.ptrIndex[i].dLatinc << endl; // latitude interval (LAT_INC)
cout << " - LONG_INC = " << fixed << grid_properties.ptrIndex[i].dLonginc << endl; // longitude interval (LONG_INC)
cout << " - GS_COUNT = " << fixed << setprecision(0) << grid_properties.ptrIndex[i].lGscount; // number of nodes (GS_COUNT)
}
cout << endl;
return true;
Expand Down Expand Up @@ -755,6 +776,15 @@ int main(int argc, char* argv[])

if (vm.count(QUIET))
p.g.quiet = 1;

if (vm.count(NTV2_GS_TYPE))
{
gs_type = trimstr(gs_type);
// Unknown type?
if (!iequals(gs_type, "seconds") && !iequals(gs_type, "radians"))
gs_type = "seconds";
str_toupper<int>(gs_type);
}

if (!p.g.quiet)
{
Expand Down Expand Up @@ -792,14 +822,7 @@ int main(int argc, char* argv[])
cout << setw(PRINT_VAR_PAD) << left << " WINTER DAT file: " << leafStr<string>(p.n.rdat_geoid_file) << endl;

if (vm.count(NTV2_GS_TYPE))
{
gs_type = trimstr(gs_type);
// Unknown type?
if (!iequals(gs_type, "seconds") && !iequals(gs_type, "radians"))
gs_type = "seconds";
str_toupper<int>(gs_type);
cout << setw(PRINT_VAR_PAD) << left << " Grid shift type: " << gs_type.c_str() << endl;
}
if (vm.count(NTV2_VERSION))
cout << setw(PRINT_VAR_PAD) << left << " Grid file version: " << version.c_str() << endl;
if (vm.count(NTV2_SYSTEM_F))
Expand Down Expand Up @@ -843,11 +866,14 @@ int main(int argc, char* argv[])
if (vm.count(EXPORT_NTV2_ASCII_FILE) ||
vm.count(EXPORT_NTV2_BINARY_FILE))
{
cout << setw(PRINT_VAR_PAD) << left << " Export NTv2 file to: ";
cout << setw(PRINT_VAR_PAD) << left << " Export NTv2 grid file to: ";
if (vm.count(EXPORT_NTV2_ASCII_FILE))
cout << "ASCII (." << ASC << ")" << endl;
if (vm.count(EXPORT_NTV2_BINARY_FILE))
cout << "Binary (." << GSB << ")" << endl;

if (vm.count(NTV2_GS_TYPE))
cout << setw(PRINT_VAR_PAD) << left << " Grid shift type: " << gs_type.c_str() << endl;
}

if (p.n.file_mode || vm.count(INTERACTIVE))
Expand All @@ -870,17 +896,14 @@ int main(int argc, char* argv[])

cout << endl;

// File interpolation mode...
if (p.n.file_mode)
{
if (!p.n.bst_file.empty())
cout << "+ Binary station file interpolation mode." << endl << endl;
else
cout << "+ ASCII file interpolation mode." << endl << endl;
}

// Not applicable for project file use
else if (vm.count(CREATE_NTV2))
cout << "+ Creating NTv2 file from WINTER DAT file format:" << endl;
}
}

dna_geoid_interpolation g;
Expand Down Expand Up @@ -915,7 +938,7 @@ int main(int argc, char* argv[])
if (ntv2.ptrIndex)
delete [] ntv2.ptrIndex;

cout << "+ Geoid file creation completed successfully." << endl << endl;
cout << endl << "+ Geoid file creation completed successfully." << endl << endl;

return EXIT_SUCCESS;
}
Expand All @@ -927,7 +950,10 @@ int main(int argc, char* argv[])
return EXIT_FAILURE;
}

if (!ExportNTv2GridToAscii(&g, ntv2.filename, ntv2.filetype, ASC))
if (vm.count(NTV2_GS_TYPE))
strcpy(ntv2.chGs_type, gs_type.c_str());

if (!ExportNTv2GridToAscii(&g, ntv2.filename, ntv2.filetype, ntv2.chGs_type, ASC))
return EXIT_FAILURE;

cout << "+ Geoid file creation completed successfully." << endl << endl;
Expand All @@ -942,7 +968,10 @@ int main(int argc, char* argv[])
return EXIT_FAILURE;
}

if (!ExportNTv2GridToBinary(&g, ntv2.filename, ntv2.filetype, GSB))
if (vm.count(NTV2_GS_TYPE))
strcpy(ntv2.chGs_type, gs_type.c_str());

if (!ExportNTv2GridToBinary(&g, ntv2.filename, ntv2.filetype, ntv2.chGs_type, GSB))
return EXIT_FAILURE;

cout << "+ Geoid file creation completed successfully." << endl << endl;
Expand Down
7 changes: 7 additions & 0 deletions dynadjust/include/config/dnaoptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ enum inverseMethod
};


enum geoidConversion
{
Same = 0,
SecondsToRadians = 1,
RadiansToSeconds = 2
};

enum settingMode
{
unknownSetting = 0,
Expand Down
21 changes: 21 additions & 0 deletions dynadjust/include/functions/dnaiostreamfuncs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ using namespace boost::gregorian;
// return input;
//}

template <typename T>
T real_line_length_ascii(const T& line_length_ascii)
{
// return the real length of a line based on the system definition
// of a "new line". On Windows, a new line is comprised of two characters
// namely, carriage return (CR, '\r') and line feed (LF, '\n'). On Unix
// and Unix-like systems (Linux, mac OS, BSD, etc.), a new line is
// comprised of a line feed (LF, '\n') only.
//

#if defined(__linux) || defined(sun) || defined(__unix__) || defined(__APPLE__)
// "real" line length = line_length_ascii + "\n"
return line_length_ascii + 1;

#else // #if defined(_WIN32) || defined(__WIN32__)
// "real" line length = line_length_ascii + "\r\n"
return line_length_ascii + 2;

#endif
}


template <typename T>
void file_opener(
Expand Down
Binary file modified sampleData/gnss-network-geoid.gsb
Binary file not shown.

0 comments on commit ef25f70

Please sign in to comment.