tests.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 "lib/Corsen.hpp"
  26. /**
  27. * \fn void modifyFilesPath(string & absolutePath, vector<string *> & files)
  28. * \brief Modifie le chemin par défaut des fichiers.
  29. * \param absolutePath : chemin absolu ou sont stockés les fichiers
  30. * \param files : tableau contenant les chemins vers les fichiers .
  31. */
  32. void modifyFilesPath(std::string& absolutePath,
  33. std::vector < std::string* >& files)
  34. {
  35. for (std::vector < std::string* >::iterator it = files.begin();
  36. it != files.end(); it++) {
  37. (*it)->insert(0, absolutePath);
  38. }
  39. }
  40. int main(int argc, char** argv)
  41. {
  42. bool defaultFilePath = true;
  43. std::string absolutePath("");
  44. std::string modeFile(".mode"), parametersFile("par.txt"),
  45. elevationFile("alt"), outletFile("arbre"), layersFile("couche"),
  46. contextFile("contexte_agro_prairie.xml") ,slopeFile("pav");
  47. std::vector<std::string *> files;
  48. files.push_back(&parametersFile);
  49. files.push_back(&modeFile);
  50. files.push_back(&elevationFile);
  51. files.push_back(&outletFile);
  52. files.push_back(&slopeFile);
  53. files.push_back(&contextFile);
  54. files.push_back(&layersFile);
  55. /* Lecture des paramètres en ligne de commande */
  56. if(argc > 1) {
  57. int i = 1;
  58. char* option;
  59. while (i < argc) {
  60. option = argv[i++];
  61. if (strcmp(option,"-h") == 0) {
  62. std::cerr << "Utilisation : " << argv[0]
  63. << "[-h] [-a absolute path]" << std::endl;
  64. std::cerr << " -a : chemin absolu" << std::endl;
  65. std::cerr << " -c : nom du fichier xml" << std::endl;
  66. std::cerr << " -h : cette aide" << std::endl;
  67. exit(0);
  68. } else if (strcmp(option, "-a") == 0) {
  69. if (i == argc) {
  70. std::cerr << "il manque le chemin absolu" << std::endl;
  71. exit(0);
  72. }
  73. defaultFilePath = false;
  74. absolutePath.append(argv[i++]);
  75. if(absolutePath.c_str()[absolutePath.size()- 1] != '/') {
  76. absolutePath+="/";
  77. }
  78. modifyFilesPath(absolutePath,files);
  79. } else if (strcmp(option,"-c")==0) {
  80. if (i == argc) {
  81. std::cerr << "il manque le nom du fichier xml" << std::endl;
  82. exit(0);
  83. }
  84. contextFile.clear();
  85. contextFile.append(argv[i++]);
  86. std::vector<std::string *>context;
  87. context.push_back(&contextFile);
  88. modifyFilesPath(absolutePath,context);
  89. } else {
  90. std::cerr << "Option non reconnue essayez -h" << std::endl;
  91. exit(0);
  92. }
  93. }
  94. }
  95. try {
  96. if(defaultFilePath) {
  97. std::string defaultFilePathStr("data/");
  98. modifyFilesPath(defaultFilePathStr,files);
  99. }
  100. Corsen c;
  101. c.read(files, absolutePath);
  102. c.buildGraph();
  103. c.display();
  104. } catch(std::exception & e) {
  105. std::cout<<e.what()<<std::endl;
  106. }
  107. return 0;
  108. }