tests.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * @file tests/corsen/tests.cpp
  3. * @author The PARADEVS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * PARADEVS - the multimodeling and simulation environment
  8. * This file is a part of the PARADEVS environment
  9. *
  10. * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. #include <boost/timer.hpp>
  26. #include <common/RootCoordinator.hpp>
  27. #include "lib/Corsen.hpp"
  28. // #include <tests/boost_graph/models.hpp>
  29. // #include <tests/boost_graph/graph_builder.hpp>
  30. // #include <tests/boost_graph/graph_manager.hpp>
  31. // #include <tests/boost_graph/graph_partitioning.hpp>
  32. // using namespace paradevs::common;
  33. // using namespace paradevs::common::scheduler;
  34. // using namespace paradevs::pdevs;
  35. // using namespace paradevs::tests::boost_graph;
  36. /**
  37. * \fn void modifyFilesPath(string & absolutePath, vector<string *> & files)
  38. * \brief Modifie le chemin par défaut des fichiers.
  39. * \param absolutePath : chemin absolu ou sont stockés les fichiers
  40. * \param files : tableau contenant les chemins vers les fichiers .
  41. */
  42. void modifyFilesPath(std::string& absolutePath,
  43. std::vector < std::string* >& files)
  44. {
  45. for (std::vector < std::string* >::iterator it = files.begin();
  46. it != files.end(); it++) {
  47. (*it)->insert(0, absolutePath);
  48. }
  49. }
  50. int main(int argc, char** argv)
  51. {
  52. bool defaultFilePath = true;
  53. std::string absolutePath("");
  54. std::string modeFile(".mode"), parametersFile("par.txt"),
  55. elevationFile("alt"), outletFile("arbre"), layersFile("couche"),
  56. contextFile("contexte_agro_prairie.xml") ,slopeFile("pav");
  57. std::vector<std::string *> files;
  58. files.push_back(&parametersFile);
  59. files.push_back(&modeFile);
  60. files.push_back(&elevationFile);
  61. files.push_back(&outletFile);
  62. files.push_back(&slopeFile);
  63. files.push_back(&contextFile);
  64. files.push_back(&layersFile);
  65. /* Lecture des paramètres en ligne de commande */
  66. if(argc > 1) {
  67. int i = 1;
  68. char* option;
  69. while (i < argc) {
  70. option = argv[i++];
  71. if (strcmp(option,"-h") == 0) {
  72. std::cerr << "Utilisation : " << argv[0]
  73. << "[-h] [-a absolute path]" << std::endl;
  74. std::cerr << " -a : chemin absolu" << std::endl;
  75. std::cerr << " -c : nom du fichier xml" << std::endl;
  76. std::cerr << " -h : cette aide" << std::endl;
  77. exit(0);
  78. } else if (strcmp(option, "-a") == 0) {
  79. if (i == argc) {
  80. std::cerr << "il manque le chemin absolu" << std::endl;
  81. exit(0);
  82. }
  83. defaultFilePath = false;
  84. absolutePath.append(argv[i++]);
  85. if(absolutePath.c_str()[absolutePath.size()- 1] != '/') {
  86. absolutePath+="/";
  87. }
  88. modifyFilesPath(absolutePath,files);
  89. } else if (strcmp(option,"-c")==0) {
  90. if (i == argc) {
  91. std::cerr << "il manque le nom du fichier xml" << std::endl;
  92. exit(0);
  93. }
  94. contextFile.clear();
  95. //contextFile.append("data/");
  96. contextFile.append(argv[i++]);
  97. std::vector<std::string *>context;
  98. context.push_back(&contextFile);
  99. modifyFilesPath(absolutePath,context);
  100. } else {
  101. std::cerr << "Option non reconnue essayez -h" << std::endl;
  102. exit(0);
  103. }
  104. }
  105. }
  106. try {
  107. if(defaultFilePath) {
  108. std::string defaultFilePathStr("data/");
  109. modifyFilesPath(defaultFilePathStr,files);
  110. }
  111. Corsen c;
  112. c.read(files, absolutePath);
  113. c.buildGraph();
  114. // c.display();
  115. } catch(std::exception & e) {
  116. std::cout<<e.what()<<std::endl;
  117. }
  118. return 0;
  119. }