IMP  2.1.0
The Integrative Modeling Platform
MRCReaderWriter.h
Go to the documentation of this file.
1 /**
2  * \file IMP/em/MRCReaderWriter.h
3  * \brief Classes to read or write MRC files.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPEM_MRC_READER_WRITER_H
10 #define IMPEM_MRC_READER_WRITER_H
11 
12 #include <IMP/em/em_config.h>
13 #include "MapReaderWriter.h"
14 #include "internal/MRCHeader.h"
15 #include <string>
16 
17 IMPEM_BEGIN_NAMESPACE
18 
19 /** A class to read and write MRC files. */
20 class IMPEMEXPORT MRCReaderWriter : public MapReaderWriter
21 {
22 public:
23  //! Empty constructor
25  //! Constructor
26  /**
27  * param[in] fn name of the file to open or write
28  */
29  MRCReaderWriter(std::string fn) {
30  filename=fn;
31  }
32 #if !defined(DOXYGEN) && !defined(SWIG)
33  //! Reads an MRC file and translates the header to the general DensityHeader
34  void read(const char *fn_in, float **data, DensityHeader &head);
35  //! Writes an MRC file from the data and the general DensityHeader
36  void write(const char *fn_out, const float *data, const DensityHeader &head);
37 #endif
38 
39 private:
40 
41 
42  //! By default the data are read into the grid of the class, but an external
43  //! pointer to another grid can be specified
44  void read() {
45  read(&grid);
46  }
47 
48  void read(float **pt);
49  //! reads the header
50  void read_header();
51  //! reads the data
52  void read_data(float *pt);
53  //! reads data of size 8-bit
54  void read_8_data(float *pt);
55  //! reads data of size 32-bit
56  void read_32_data(float *pt);
57  void read_grid(void *pt,size_t size,size_t n);
58  void seek_to_data();
59  //! Write function
60  /**
61  * param[in] fn name of the file to write
62  */
63  void write(const char *fn) {
64  return write(fn,grid);
65  }
66 
67  //! Write function
68  /**
69  * param[in] fn name of the file to write
70  * param[in] pt pointer to the data to write
71  */
72  void write(const char *fn,const float *pt);
73  //! Writes the header
74  /**
75  * param[in] s stream to write the header
76  */
77  void write_header(std::ofstream &s);
78  //! Writes data
79  /**
80  * param[in] s stream to write the data
81  * param[in] pt pointer to the data
82  */
83  void write_data(std::ofstream &s, const float *pt);
84 
85  //! Name of the file
86  std::string filename;
87  //! file stream for the file read
88  std::fstream fs;
89  //! The header of the file
90  internal::MRCHeader header;
91  //! The grid of data. The data is stored in the grid with the convention
92  //! that the order of indexes is z,y,x
93  float *grid;
94 
96 };
97 
98 IMPEM_END_NAMESPACE
99 
100 #endif /* IMPEM_MRC_READER_WRITER_H */
The base class to handle reading and writing of density maps.
MRCReaderWriter(std::string fn)
Constructor.
An abstract class for reading a map.
MRCReaderWriter()
Empty constructor.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.