mdirectory.cpp
Go to the documentation of this file.
1 
2 
3 #include <iostream>
4 #include <string>
5 #include <vector>
6 
7 #include "modis_database.h"
8 
9 void mmain(std::string& rootpath)
10 {
11  if (!te::core::FileSystem::isDirectory(rootpath))
12  {
13  std::cout << "Enter with a valid root directory!" << std::endl;
14  return;
15  }
16 
17  MODISDatabase myDb(rootpath);
18 
19  std::cout << "There are " << myDb.size() << " file MODIS in " << rootpath << ":" << std::endl;
20 
21  if (myDb.size() == 0)
22  return;
23 
24  myDb.printAll();
25 
26  std::cout << std::endl << std::endl << "Search by product. Enter with a product name: " ;
27  std::string prod;
28  std::cin >> prod;
29 
30  if (!prod.empty())
31  {
32  std::vector<MODISRecord> result = myDb.findByProduct(prod);
33  if (result.empty())
34  std::cout << "None found!" << std::endl;
35  else
36  {
37  BOOST_FOREACH(MODISRecord& rec, result)
38  {
39  std::cout << "\t";
40  rec.printToCout();
41  }
42  }
43  }
44 
45  std::cout << std::endl << std::endl << "Search by year. Enter with a year (> 2000): " ;
46  unsigned int year = 0;
47  std::cin >> year;
48 
49  if (year > 2000)
50  {
51  std::vector<MODISRecord> result = myDb.findByYear(year);
52  if (result.empty())
53  std::cout << "None found!" << std::endl;
54  else
55  {
56  BOOST_FOREACH(MODISRecord& rec, result)
57  {
58  std::cout << "\t";
59  rec.printToCout();
60  }
61  }
62  }
63  else
64  std::cout << "Invalid year!" << std::endl;
65 
66 
67  std::cout << std::endl << std::endl << "Search by day. Enter with a day (1-365): " ;
68  unsigned int day = 0;
69  std::cin >> day;
70 
71  if (day <= 365 || day >=
72  1)
73  {
74  std::vector<MODISRecord> result = myDb.findByDay(day);
75  if (result.empty())
76  std::cout << "None found!" << std::endl;
77  else
78  {
79  BOOST_FOREACH(MODISRecord& rec, result)
80  {
81  std::cout << "\t";
82  rec.printToCout();
83  }
84  }
85  }
86 }
static bool isDirectory(const std::string &path)
Checks if a given path in UTF-8 is a directory.
Definition: FileSystem.cpp:87
std::vector< MODISRecord > findByDay(unsigned int day) const
void printToCout()
std::vector< MODISRecord > findByYear(unsigned int year) const
std::vector< MODISRecord > findByProduct(const std::string &product) const
size_t size() const
void mmain(std::string &rootpath)
Definition: mdirectory.cpp:9