123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
-
-
-
-
-
-
- #include "Lemma"
- #ifdef TINYXMLSUPPORT
- #include "tinyxml2.h"
-
- #include <ctime>
- using namespace tinyxml2;
- using namespace Lemma;
-
- void ParseTEM( XMLElement* element );
-
- template <typename T>
- std::vector<T> ReadLine( const int& nr, const std::string& line ) ;
-
- int main(int argc, char **argv) {
-
- if ( argc > 1 ) {
- XMLDocument* doc = new XMLDocument();
- clock_t startTime = clock();
- doc->LoadFile( argv[1] );
- clock_t loadTime = clock();
- int errorID = doc->ErrorID();
-
-
-
-
-
- XMLElement* titleElement = doc->FirstChildElement( );
-
- const char* title = titleElement->Value();
-
- printf( "Test file '%s' loaded. ErrorID=%d\n", argv[1], errorID );
- printf( "Name of FirstChildElement: %s\n", title );
-
- if (strcmp ( titleElement->Value(), "NGXFile" ) != 0) {
- std::cout <<"NGX file was not detected!" << std::endl;
- exit(EXIT_FAILURE);
- } else {
-
-
- if (strcmp( titleElement->FindAttribute("type")->Value(),"tem") == 0) {
-
- ParseTEM( titleElement );
- } else {
- std::cout << "No parser for NGX filetype " << titleElement->FindAttribute("type")->Value() << std::endl;
- std::cout << "YOU should write one!\n";
- exit(EXIT_FAILURE);
- }
-
- }
-
- delete doc; doc = 0;
-
- clock_t deleteTime = clock();
- if ( !errorID ) {
- printf( "========================================================\n");
- printf( "Load time=%u\n", (unsigned)(loadTime - startTime) );
- printf( "Delete time=%u\n", (unsigned)(deleteTime - loadTime) );
- printf( "Total time=%u\n", (unsigned)(deleteTime - startTime) );
- }
-
-
- exit(0);
- } else {
- std::cout << "Enter NGX.x file to parse\n";
- }
- }
-
- void ParseTEM( XMLElement* element ) {
-
- std::cout << "This is a NGX.t file" << std::endl;
-
-
- if (strcmp( element->FindAttribute("version")->Value(),"0.1") == 0) {
- std::cout << "Version 0.1 detected" << std::endl;
- } else {
- std::cout << "Unsupported NGX.t version" << std::endl;
- }
-
-
- std::cout << "System description" << std::endl;
- std::cout << element->FirstChildElement("system")->FirstChildElement("name")->GetText() << std::endl;
- XMLElement* system = element->FirstChildElement("system");
- int ntx = atoi(system->FirstChildElement("transmitters")->FindAttribute("num")->Value());
- std::cout << "numTx = " << ntx << std::endl;
-
- XMLElement* tx = system->FirstChildElement("transmitters")->FirstChildElement("transmitter");
-
-
-
- for (int it=0; it<ntx; ++it) {
- std::cout << "\nTransmitter " << it << std::endl;
- if (it > 0) tx = tx->NextSiblingElement();
- int npoints = atoi(tx->FirstChildElement("loop.coordinates")->FindAttribute("npoint")->Value());
-
- std::cout << "points= " << npoints;
- std::vector<Real> LP = ReadLine<Real>( npoints, std::string(tx->FirstChildElement("loop.coordinates")->FirstChildElement("northing.points")->GetText()) );
- for (int ii=0; ii<npoints; ++ii) std::cout << "\t"<< LP[ii] ;
-
-
- }
- std::cout << "\nEND system description\n";
-
- }
-
-
- template <typename T>
- std::vector<T> ReadLine( const int& nr, const std::string& line ) {
-
- std::vector<T> lineData;
- std::stringstream lineStream(line);
-
- T value;
- while(lineStream >> value) {
- lineData.push_back(value);
- }
- return lineData;
- }
- #else
-
- int main() {
- std::cout << "you have to compile lemma with external tinyxml library to use this" << std::endl;
- }
-
- #endif
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|