Debug swcsa
[SXSI/TextCollection.git] / incbwt / extract_sequence.cpp
1 #include <algorithm>
2 #include <cstdlib>
3 #include <ctime>
4 #include <fstream>
5 #include <iostream>
6
7 #include "rlcsa.h"
8 #include "misc/utils.h"
9
10 #ifdef MULTITHREAD_SUPPORT
11 #include <omp.h>
12 const int MAX_THREADS = 64;
13 #endif
14
15
16 using namespace CSA;
17
18
19 int main(int argc, char** argv)
20 {
21   std::cout << "RLCSA display test" << std::endl;
22   if(argc < 4)
23   {
24     std::cout << "Usage: extract_sequence base_name sequence_number output" << std::endl;
25     return 1;
26   }
27
28   std::cout << "Base name: " << argv[1] << std::endl;
29   usint sequence = atoi(argv[2]);
30   std::cout << "Sequence number: " << sequence << std::endl;
31   std::cout << "Output: " << argv[3] << std::endl;
32   std::cout << std::endl;
33
34   RLCSA rlcsa(argv[1]);
35   if(!rlcsa.supportsDisplay())
36   {
37     std::cerr << "Error: Display is not supported!" << std::endl;
38     return 2;
39   }
40   rlcsa.printInfo();
41   rlcsa.reportSize(true);
42   if(sequence >= rlcsa.getNumberOfSequences())
43   {
44     std::cerr << "Error: Invalid sequence number!" << std::endl;
45     return 3;
46   }
47
48   std::ofstream output(argv[3], std::ios_base::binary);
49   if(!output)
50   {
51     std::cerr << "Error: Cannot open output file!" << std::endl;
52     return 4;
53   }
54
55   double start = readTimer();
56   uchar* buffer = rlcsa.display(sequence);
57   usint bytes = length(rlcsa.getSequenceRange(sequence));
58   output.write((char*)buffer, bytes);
59   delete[] buffer;
60   output.close();
61
62   double time = readTimer() - start;
63   double megabytes = bytes / (double)MEGABYTE;
64   std::cout << megabytes << " megabytes in " << time << " seconds (" << (megabytes / time) << " MB/s)" << std::endl;
65   std::cout << std::endl;
66
67   return 0;
68 }