mbd.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /***************************************************************
  2. *
  3. * the class IO provides all the functionality to access a
  4. * binary mcell3 reaction data output file.
  5. *
  6. * (c) 2008 Markus Dittrich
  7. *
  8. * This program is free software; you can redistribute it
  9. * and/or modify it under the terms of the GNU General Public
  10. * License Version 3 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License Version 3 for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with this program; if not, write to the Free
  19. * Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. *
  22. ****************************************************************/
  23. #ifndef IO_H
  24. #define IO_H
  25. /* C header */
  26. #include <stdint.h>
  27. /* output types */
  28. const int STEP = 1;
  29. const int TIME_LIST = 2;
  30. const int ITERATION_LIST = 3;
  31. /* data types */
  32. const int INT_DATA = 0;
  33. const int DOUBLE_DATA = 1;
  34. /*
  35. * C++ interface
  36. */
  37. #ifdef __cplusplus
  38. /* STL headers */
  39. #include <vector>
  40. #include <string>
  41. #include <map>
  42. /** global macros */
  43. const std::string NL("\n");
  44. const std::string PRE("reader> ");
  45. const std::string VERSION("0.2");
  46. const std::string AUTHOR("Markus Dittrich");
  47. const std::string DATE("2013");
  48. /**********************************************************
  49. * struct entryType keeps track of the type (int/double)
  50. * in each data block as well as the start and end of
  51. * the data in the binary file
  52. **********************************************************/
  53. struct EntryType
  54. {
  55. std::string name;
  56. uint64_t num_cols;
  57. uint64_t offset;
  58. std::vector<uint16_t> data_type;
  59. };
  60. /**********************************************************
  61. * class IO
  62. *********************************************************/
  63. struct IO
  64. {
  65. public:
  66. explicit IO(std::string file_name);
  67. ~IO();
  68. /* initialize data (parse headers, etc.) */
  69. bool initialize();
  70. /* getter functions for data properties */
  71. uint64_t get_num_datablocks() const;
  72. double get_stepsize() const;
  73. uint64_t get_blocksize() const;
  74. uint64_t get_num_columns(int id) const;
  75. uint16_t get_output_type() const;
  76. std::vector<std::string> get_blocknames() const;
  77. std::vector<double> get_iteration_list() const;
  78. int get_id_from_name(std::string data_name) const;
  79. bool get_data(std::vector<std::vector<double> >& data_list,
  80. std::vector<uint16_t>& data_types,
  81. int id) const;
  82. bool get_data(std::vector<std::vector<double> >& data_list,
  83. std::vector<uint16_t>& data_types,
  84. std::string name) const;
  85. /** print basic file info extracted from header */
  86. void info() const;
  87. private:
  88. /** member functions */
  89. bool open_gz_file_(FILE* inputFile);
  90. bool open_bz_file_(FILE* inputFile);
  91. bool open_binary_file_(FILE* inputFile);
  92. bool open_();
  93. bool parse_header_();
  94. uint64_t parse_api_tag_(uint64_t charCounter);
  95. uint64_t parse_block_information_(uint64_t charCounter);
  96. uint64_t parse_block_names_(uint64_t charCounter);
  97. /** member data */
  98. char* buffer_; // main data buffer
  99. std::string file_name_;
  100. uint64_t num_blocks_;
  101. uint16_t output_type_;
  102. uint64_t blocksize_;
  103. double stepsize_;
  104. uint64_t buffer_size_;
  105. uint64_t total_columns_;
  106. uint64_t fileoffset_to_data_;
  107. std::vector<double> time_it_list_;
  108. std::vector<std::string> block_names_;
  109. std::map<std::string,int> block_names_map_;
  110. std::vector<EntryType> block_info_;
  111. std::string needed_api_tag_;
  112. };
  113. #else
  114. struct IO;
  115. #endif
  116. /*
  117. * C interface
  118. */
  119. typedef struct IO* MBDIO;
  120. #ifdef __cplusplus
  121. extern "C"
  122. {
  123. #endif
  124. MBDIO mbd_new(const char* file_name);
  125. void mbd_delete(MBDIO obj);
  126. int mbd_initialize(MBDIO obj);
  127. /* getter functions for data properties */
  128. uint64_t mbd_get_num_datablocks(MBDIO obj);
  129. double mbd_get_stepsize(MBDIO obj);
  130. uint64_t mbd_get_blocksize(MBDIO obj);
  131. uint16_t mbd_get_output_type(MBDIO obj);
  132. int mbd_get_id_from_name(MBDIO obj, char* name);
  133. /* getter functions for metadata */
  134. void mbd_get_blocknames(MBDIO obj, char** block_names, size_t length);
  135. void mbd_get_iteration_list(MBDIO obj, double* iteration_list);
  136. uint64_t mbd_get_num_columns_by_id(MBDIO obj, int id);
  137. /* getter functions for data */
  138. int mbd_get_data_by_id(MBDIO obj, double** data_list, uint16_t* data_types,
  139. int id);
  140. int mbd_get_data_by_name(MBDIO obj, double** data_list, uint16_t* data_types,
  141. char* name);
  142. /** print basic file info extracted from header */
  143. void mbd_info(MBDIO obj);
  144. #ifdef __cplusplus
  145. }
  146. #endif
  147. #endif