IMP logo
IMP Reference Guide  2.10.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-2018 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  public:
22  //! Empty constructor
24  //! Constructor
25  /**
26  * \param[in] fn name of the file to open or write
27  */
28  MRCReaderWriter(std::string fn) { filename = fn; }
29 #if !defined(DOXYGEN) && !defined(SWIG)
30  //! Reads an MRC file and translates the header to the general DensityHeader
31  void read(const char *fn_in, float **data, DensityHeader &head);
32  //! Writes an MRC file from the data and the general DensityHeader
33  void write(const char *fn_out, const float *data, const DensityHeader &head);
34 #endif
35 
36  private:
37  //! By default the data are read into the grid of the class, but an external
38  //! pointer to another grid can be specified
39  void read() { read(&grid); }
40 
41  void read(float **pt);
42  //! reads the header
43  void read_header();
44  //! reads the data
45  void read_data(float *pt);
46  //! reads data of size 8-bit
47  void read_8_data(float *pt);
48  //! reads data of size 32-bit
49  void read_32_data(float *pt);
50  void read_grid(void *pt, size_t size, size_t n);
51  void seek_to_data();
52  //! Write function
53  /**
54  * \param[in] fn name of the file to write
55  */
56  void write(const char *fn) { return write(fn, grid); }
57 
58  //! Write function
59  /**
60  * \param[in] fn name of the file to write
61  * \param[in] pt pointer to the data to write
62  */
63  void write(const char *fn, const float *pt);
64  //! Writes the header
65  /**
66  * \param[in] s stream to write the header
67  */
68  void write_header(std::ofstream &s);
69  //! Writes data
70  /**
71  * \param[in] s stream to write the data
72  * \param[in] pt pointer to the data
73  */
74  void write_data(std::ofstream &s, const float *pt);
75 
76  //! Name of the file
77  std::string filename;
78  //! file stream for the file read
79  std::fstream fs;
80  //! The header of the file
81  internal::MRCHeader header;
82  //! The grid of data. The data is stored in the grid with the convention
83  //! that the order of indexes is z,y,x
84  float *grid;
85 
87 };
88 
89 IMPEM_END_NAMESPACE
90 
91 #endif /* IMPEM_MRC_READER_WRITER_H */
The base class to handle reading and writing of density maps.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
MRCReaderWriter(std::string fn)
Constructor.
An abstract class for reading a map.
MRCReaderWriter()
Empty constructor.